You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 140 kB

Support unicode emojis and remove emojify.js (#11032) * Support unicode emojis and remove emojify.js This PR replaces all use of emojify.js and adds unicode emoji support to various areas of gitea. This works in a few ways: First it adds emoji parsing support into gitea itself. This allows us to * Render emojis from valid alias (:smile:) * Detect unicode emojis and let us put them in their own class with proper aria-labels and styling * Easily allow for custom "emoji" * Support all emoji rendering and features without javascript * Uses plain unicode and lets the system render in appropriate emoji font * Doesn't leave us relying on external sources for updates/fixes/features That same list of emoji is also used to create a json file which replaces the part of emojify.js that populates the emoji search tribute. This file is about 35KB with GZIP turned on and I've set it to load after the page renders to not hinder page load time (and this removes loading emojify.js also) For custom "emoji" it uses a pretty simple scheme of just looking for /emojis/img/name.png where name is something a user has put in the "allowed reactions" setting we already have. The gitea reaction that was previously hard coded into a forked copy of emojify.js is included and works as a custom reaction under this method. The emoji data sourced here is from https://github.com/github/gemoji which is the gem library Github uses for their emoji rendering (and a data source for other sites). So we should be able to easily render any emoji and :alias: that Github can, removing any errors from migrated content. They also update it as well, so we can sync when there are new unicode emoji lists released. I've included a slimmed down and slightly modified forked copy of https://github.com/knq/emoji to make up our own emoji module. The code is pretty straight forward and again allows us to have a lot of flexibility in what happens. I had seen a few comments about performance in some of the other threads if we render this ourselves, but there doesn't seem to be any issue here. In a test it can parse, convert, and render 1,000 emojis inside of a large markdown table in about 100ms on my laptop (which is many more emojis than will ever be in any normal issue). This also prevents any flickering and other weirdness from using javascript to render some things while using go for others. Not included here are image fall back URLS. I don't really think they are necessary for anything new being written in 2020. However, managing the emoji ourselves would allow us to add these as a feature later on if it seems necessary. Fixes: https://github.com/go-gitea/gitea/issues/9182 Fixes: https://github.com/go-gitea/gitea/issues/8974 Fixes: https://github.com/go-gitea/gitea/issues/8953 Fixes: https://github.com/go-gitea/gitea/issues/6628 Fixes: https://github.com/go-gitea/gitea/issues/5130 * add new shared function emojiHTML * don't increase emoji size in issue title * Update templates/repo/issue/view_content/add_reaction.tmpl Co-Authored-By: 6543 <6543@obermui.de> * Support for emoji rendering in various templates * Render code and review comments as they should be * Better way to handle mail subjects * insert unicode from tribute selection * Add template helper for plain text when needed * Use existing replace function I forgot about * Don't include emoji greater than Unicode Version 12 Only include emoji and aliases in JSON * Update build/generate-emoji.go * Tweak regex slightly to really match everything including random invisible characters. Run tests for every emoji we have * final updates * code review * code review * hard code gitea custom emoji to match previous behavior * Update .eslintrc Co-Authored-By: silverwind <me@silverwind.io> * disable preempt Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
5 years ago
4 years ago
3 years ago
3 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
5 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
Use AJAX for notifications table (#10961) * Use AJAX for notifications table Signed-off-by: Andrew Thornton <art27@cantab.net> * move to separate js Signed-off-by: Andrew Thornton <art27@cantab.net> * placate golangci-lint Signed-off-by: Andrew Thornton <art27@cantab.net> * Add autoupdating notification count Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix wipeall Signed-off-by: Andrew Thornton <art27@cantab.net> * placate tests Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hide and hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * More auto-update improvements Only run checker on pages that have a count Change starting checker to 10s with a back-off to 60s if there is no change Signed-off-by: Andrew Thornton <art27@cantab.net> * string comparison! Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * add configurability as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add documentation as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Use CSRF header not query Signed-off-by: Andrew Thornton <art27@cantab.net> * Further JS improvements Fix @etzelia update notification table request Fix @silverwind comments Co-Authored-By: silverwind <me@silverwind.io> Signed-off-by: Andrew Thornton <art27@cantab.net> * Simplify the notification count fns Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io>
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
Use AJAX for notifications table (#10961) * Use AJAX for notifications table Signed-off-by: Andrew Thornton <art27@cantab.net> * move to separate js Signed-off-by: Andrew Thornton <art27@cantab.net> * placate golangci-lint Signed-off-by: Andrew Thornton <art27@cantab.net> * Add autoupdating notification count Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix wipeall Signed-off-by: Andrew Thornton <art27@cantab.net> * placate tests Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * Try hide and hidden Signed-off-by: Andrew Thornton <art27@cantab.net> * More auto-update improvements Only run checker on pages that have a count Change starting checker to 10s with a back-off to 60s if there is no change Signed-off-by: Andrew Thornton <art27@cantab.net> * string comparison! Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * add configurability as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add documentation as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * Use CSRF header not query Signed-off-by: Andrew Thornton <art27@cantab.net> * Further JS improvements Fix @etzelia update notification table request Fix @silverwind comments Co-Authored-By: silverwind <me@silverwind.io> Signed-off-by: Andrew Thornton <art27@cantab.net> * Simplify the notification count fns Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io>
5 years ago
Support unicode emojis and remove emojify.js (#11032) * Support unicode emojis and remove emojify.js This PR replaces all use of emojify.js and adds unicode emoji support to various areas of gitea. This works in a few ways: First it adds emoji parsing support into gitea itself. This allows us to * Render emojis from valid alias (:smile:) * Detect unicode emojis and let us put them in their own class with proper aria-labels and styling * Easily allow for custom "emoji" * Support all emoji rendering and features without javascript * Uses plain unicode and lets the system render in appropriate emoji font * Doesn't leave us relying on external sources for updates/fixes/features That same list of emoji is also used to create a json file which replaces the part of emojify.js that populates the emoji search tribute. This file is about 35KB with GZIP turned on and I've set it to load after the page renders to not hinder page load time (and this removes loading emojify.js also) For custom "emoji" it uses a pretty simple scheme of just looking for /emojis/img/name.png where name is something a user has put in the "allowed reactions" setting we already have. The gitea reaction that was previously hard coded into a forked copy of emojify.js is included and works as a custom reaction under this method. The emoji data sourced here is from https://github.com/github/gemoji which is the gem library Github uses for their emoji rendering (and a data source for other sites). So we should be able to easily render any emoji and :alias: that Github can, removing any errors from migrated content. They also update it as well, so we can sync when there are new unicode emoji lists released. I've included a slimmed down and slightly modified forked copy of https://github.com/knq/emoji to make up our own emoji module. The code is pretty straight forward and again allows us to have a lot of flexibility in what happens. I had seen a few comments about performance in some of the other threads if we render this ourselves, but there doesn't seem to be any issue here. In a test it can parse, convert, and render 1,000 emojis inside of a large markdown table in about 100ms on my laptop (which is many more emojis than will ever be in any normal issue). This also prevents any flickering and other weirdness from using javascript to render some things while using go for others. Not included here are image fall back URLS. I don't really think they are necessary for anything new being written in 2020. However, managing the emoji ourselves would allow us to add these as a feature later on if it seems necessary. Fixes: https://github.com/go-gitea/gitea/issues/9182 Fixes: https://github.com/go-gitea/gitea/issues/8974 Fixes: https://github.com/go-gitea/gitea/issues/8953 Fixes: https://github.com/go-gitea/gitea/issues/6628 Fixes: https://github.com/go-gitea/gitea/issues/5130 * add new shared function emojiHTML * don't increase emoji size in issue title * Update templates/repo/issue/view_content/add_reaction.tmpl Co-Authored-By: 6543 <6543@obermui.de> * Support for emoji rendering in various templates * Render code and review comments as they should be * Better way to handle mail subjects * insert unicode from tribute selection * Add template helper for plain text when needed * Use existing replace function I forgot about * Don't include emoji greater than Unicode Version 12 Only include emoji and aliases in JSON * Update build/generate-emoji.go * Tweak regex slightly to really match everything including random invisible characters. Run tests for every emoji we have * final updates * code review * code review * hard code gitea custom emoji to match previous behavior * Update .eslintrc Co-Authored-By: silverwind <me@silverwind.io> * disable preempt Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
5 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
5 years ago
5 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
5 years ago
5 years ago
5 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
5 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904
  1. /* globals wipPrefixes */
  2. /* exported timeAddManual, toggleStopwatch, cancelStopwatch */
  3. /* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
  4. import './publicpath.js';
  5. import './polyfills.js';
  6. import './features/letteravatar.js'
  7. import Vue from 'vue';
  8. import ElementUI from 'element-ui';
  9. import 'element-ui/lib/theme-chalk/index.css';
  10. import VueI18n from 'vue-i18n'
  11. import axios from 'axios';
  12. import qs from 'qs';
  13. import Cookies from 'js-cookie'
  14. import 'jquery.are-you-sure';
  15. import './vendor/semanticdropdown.js';
  16. import {svg} from './utils.js';
  17. import echarts from 'echarts'
  18. import initContextPopups from './features/contextpopup.js';
  19. import initGitGraph from './features/gitgraph.js';
  20. import initClipboard from './features/clipboard.js';
  21. import initUserHeatmap from './features/userheatmap.js';
  22. import initDateTimePicker from './features/datetimepicker.js';
  23. import {
  24. initTribute,
  25. issuesTribute,
  26. emojiTribute
  27. } from './features/tribute.js';
  28. import createDropzone from './features/dropzone.js';
  29. import highlight from './features/highlight.js';
  30. import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
  31. import {
  32. initNotificationsTable,
  33. initNotificationCount
  34. } from './features/notification.js';
  35. import {createCodeEditor} from './features/codeeditor.js';
  36. import MinioUploader from './components/MinioUploader.vue';
  37. import ObsUploader from './components/ObsUploader.vue';
  38. import EditAboutInfo from './components/EditAboutInfo.vue';
  39. import Images from './components/Images.vue';
  40. import EditTopics from './components/EditTopics.vue';
  41. import DataAnalysis from './components/DataAnalysis.vue'
  42. import Contributors from './components/Contributors.vue'
  43. import Model from './components/Model.vue';
  44. import WxAutorize from './components/WxAutorize.vue'
  45. import initCloudrain from './features/cloudrbanin.js'
  46. // import $ from 'jquery.js'
  47. //import VueI18n from 'vue-i18n'
  48. import enLocale from 'element-ui/lib/locale/lang/en'
  49. import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
  50. import locale from 'element-ui/lib/locale'
  51. import Element from 'element-ui'
  52. import cn from './components/i18n/lang/zh.js'
  53. import en from './components/i18n/lang/en.js'
  54. Vue.use(ElementUI);
  55. Vue.prototype.$axios = axios;
  56. Vue.prototype.$Cookies = Cookies;
  57. Vue.prototype.qs = qs;
  58. const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
  59. Vue.use(VueI18n)
  60. const messages = {
  61. 'en':{...en,...enLocale} ,
  62. 'zh': {...cn,...zhLocale},
  63. }
  64. // Create VueI18n instance with options
  65. const i18n = new VueI18n({
  66. locale: 'zh', // set locale
  67. messages, // set locale messages
  68. })
  69. Vue.use(Element, {
  70. i18n: (key, value) => i18n.t(key, value)
  71. })
  72. function initGetlang(){
  73. var text_langName = document.getElementById("langName").innerText
  74. if (text_langName == '简体中文'){
  75. i18n.locale = 'zh'
  76. locale.use(zhLocale)
  77. }
  78. else if (text_langName == 'English'){
  79. i18n.locale = 'en'
  80. locale.use(enLocale)
  81. }
  82. }
  83. initGetlang()
  84. Object.defineProperty(Vue.prototype, '$echarts', {
  85. value: echarts
  86. })
  87. function htmlEncode(text) {
  88. return jQuery('<div />')
  89. .text(text)
  90. .html();
  91. }
  92. let previewFileModes;
  93. const commentMDEditors = {};
  94. // Silence fomantic's error logging when tabs are used without a target content element
  95. $.fn.tab.settings.silent = true;
  96. function initCommentPreviewTab($form) {
  97. const $tabMenu = $form.find('.tabular.menu');
  98. $tabMenu.find('.item').tab();
  99. $tabMenu
  100. .find(`.item[data-tab="${$tabMenu.data('preview')}"]`)
  101. .on('click', function () {
  102. const $this = $(this);
  103. $.post(
  104. $this.data('url'),
  105. {
  106. _csrf: csrf,
  107. mode: 'gfm',
  108. context: $this.data('context'),
  109. text: $form
  110. .find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`)
  111. .val()
  112. },
  113. (data) => {
  114. const $previewPanel = $form.find(
  115. `.tab[data-tab="${$tabMenu.data('preview')}"]`
  116. );
  117. $previewPanel.html(data);
  118. $('pre code', $previewPanel[0]).each(function () {
  119. highlight(this);
  120. });
  121. }
  122. );
  123. });
  124. buttonsClickOnEnter();
  125. }
  126. function initEditPreviewTab($form) {
  127. const $tabMenu = $form.find('.tabular.menu');
  128. $tabMenu.find('.item').tab();
  129. const $previewTab = $tabMenu.find(
  130. `.item[data-tab="${$tabMenu.data('preview')}"]`
  131. );
  132. if ($previewTab.length) {
  133. previewFileModes = $previewTab.data('preview-file-modes').split(',');
  134. $previewTab.on('click', function () {
  135. const $this = $(this);
  136. let context = `${$this.data('context')}/`;
  137. const treePathEl = $form.find('input#tree_path');
  138. if (treePathEl.length > 0) {
  139. context += treePathEl.val();
  140. }
  141. context = context.substring(0, context.lastIndexOf('/'));
  142. $.post(
  143. $this.data('url'),
  144. {
  145. _csrf: csrf,
  146. mode: 'gfm',
  147. context,
  148. text: $form
  149. .find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`)
  150. .val()
  151. },
  152. (data) => {
  153. const $previewPanel = $form.find(
  154. `.tab[data-tab="${$tabMenu.data('preview')}"]`
  155. );
  156. $previewPanel.html(data);
  157. $('pre code', $previewPanel[0]).each(function () {
  158. highlight(this);
  159. });
  160. }
  161. );
  162. });
  163. }
  164. }
  165. function initEditDiffTab($form) {
  166. const $tabMenu = $form.find('.tabular.menu');
  167. $tabMenu.find('.item').tab();
  168. $tabMenu
  169. .find(`.item[data-tab="${$tabMenu.data('diff')}"]`)
  170. .on('click', function () {
  171. const $this = $(this);
  172. $.post(
  173. $this.data('url'),
  174. {
  175. _csrf: csrf,
  176. context: $this.data('context'),
  177. content: $form
  178. .find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`)
  179. .val()
  180. },
  181. (data) => {
  182. const $diffPreviewPanel = $form.find(
  183. `.tab[data-tab="${$tabMenu.data('diff')}"]`
  184. );
  185. $diffPreviewPanel.html(data);
  186. }
  187. );
  188. });
  189. }
  190. function initEditForm() {
  191. if ($('.edit.form').length === 0) {
  192. return;
  193. }
  194. initEditPreviewTab($('.edit.form'));
  195. initEditDiffTab($('.edit.form'));
  196. }
  197. function initBranchSelector() {
  198. const $selectBranch = $('.ui.select-branch');
  199. const $branchMenu = $selectBranch.find('.reference-list-menu');
  200. $branchMenu.find('.item:not(.no-select)').click(function () {
  201. $($(this).data('id-selector')).val($(this).data('id'));
  202. $selectBranch.find('.ui .branch-name').text($(this).data('name'));
  203. });
  204. $selectBranch.find('.reference.column').on('click', function () {
  205. $selectBranch.find('.scrolling.reference-list-menu').css('display', 'none');
  206. $selectBranch.find('.reference .text').removeClass('black');
  207. $($(this).data('target')).css('display', 'block');
  208. $(this)
  209. .find('.text')
  210. .addClass('black');
  211. return false;
  212. });
  213. }
  214. function initLabelEdit() {
  215. // Create label
  216. const $newLabelPanel = $('.new-label.segment');
  217. $('.new-label.button').on('click', () => {
  218. $newLabelPanel.show();
  219. });
  220. $('.new-label.segment .cancel').on('click', () => {
  221. $newLabelPanel.hide();
  222. });
  223. $('.color-picker').each(function () {
  224. $(this).minicolors();
  225. });
  226. $('.precolors .color').on('click', function () {
  227. const color_hex = $(this).data('color-hex');
  228. $('.color-picker').val(color_hex);
  229. $('.minicolors-swatch-color').css('background-color', color_hex);
  230. });
  231. $('.edit-label-button').on('click', function () {
  232. $('#label-modal-id').val($(this).data('id'));
  233. $('.edit-label .new-label-input').val($(this).data('title'));
  234. $('.edit-label .new-label-desc-input').val($(this).data('description'));
  235. $('.edit-label .color-picker').val($(this).data('color'));
  236. $('.minicolors-swatch-color').css(
  237. 'background-color',
  238. $(this).data('color')
  239. );
  240. $('.edit-label.modal')
  241. .modal({
  242. onApprove() {
  243. $('.edit-label.form').trigger('submit');
  244. }
  245. })
  246. .modal('show');
  247. return false;
  248. });
  249. }
  250. function updateIssuesMeta(url, action, issueIds, elementId, isAdd) {
  251. return new Promise((resolve) => {
  252. $.ajax({
  253. type: 'POST',
  254. url,
  255. data: {
  256. _csrf: csrf,
  257. action,
  258. issue_ids: issueIds,
  259. id: elementId,
  260. is_add: isAdd
  261. },
  262. success: resolve
  263. });
  264. });
  265. }
  266. function initRepoStatusChecker() {
  267. const migrating = $('#repo_migrating');
  268. $('#repo_migrating_failed').hide();
  269. if (migrating) {
  270. const repo_name = migrating.attr('repo');
  271. if (typeof repo_name === 'undefined') {
  272. return;
  273. }
  274. $.ajax({
  275. type: 'GET',
  276. url: `${AppSubUrl}/${repo_name}/status`,
  277. data: {
  278. _csrf: csrf
  279. },
  280. complete(xhr) {
  281. if (xhr.status === 200) {
  282. if (xhr.responseJSON) {
  283. if (xhr.responseJSON.status === 0) {
  284. window.location.reload();
  285. return;
  286. }
  287. setTimeout(() => {
  288. initRepoStatusChecker();
  289. }, 2000);
  290. return;
  291. }
  292. }
  293. $('#repo_migrating_progress').hide();
  294. $('#repo_migrating_failed').show();
  295. }
  296. });
  297. }
  298. }
  299. function initReactionSelector(parent) {
  300. let reactions = '';
  301. if (!parent) {
  302. parent = $(document);
  303. reactions = '.reactions > ';
  304. }
  305. parent.find(`${reactions}a.label`).popup({
  306. position: 'bottom left',
  307. metadata: {content: 'title', title: 'none'}
  308. });
  309. parent
  310. .find(`.select-reaction > .menu > .item, ${reactions}a.label`)
  311. .on('click', function (e) {
  312. const vm = this;
  313. e.preventDefault();
  314. if ($(this).hasClass('disabled')) return;
  315. const actionURL = $(this).hasClass('item') ?
  316. $(this)
  317. .closest('.select-reaction')
  318. .data('action-url') :
  319. $(this).data('action-url');
  320. const url = `${actionURL}/${
  321. $(this).hasClass('blue') ? 'unreact' : 'react'
  322. }`;
  323. $.ajax({
  324. type: 'POST',
  325. url,
  326. data: {
  327. _csrf: csrf,
  328. content: $(this).data('content')
  329. }
  330. }).done((resp) => {
  331. if (resp && (resp.html || resp.empty)) {
  332. const content = $(vm).closest('.content');
  333. let react = content.find('.segment.reactions');
  334. if (!resp.empty && react.length > 0) {
  335. react.remove();
  336. }
  337. if (!resp.empty) {
  338. react = $('<div class="ui attached segment reactions"></div>');
  339. const attachments = content.find('.segment.bottom:first');
  340. if (attachments.length > 0) {
  341. react.insertBefore(attachments);
  342. } else {
  343. react.appendTo(content);
  344. }
  345. react.html(resp.html);
  346. react.find('.dropdown').dropdown();
  347. initReactionSelector(react);
  348. }
  349. }
  350. });
  351. });
  352. }
  353. function insertAtCursor(field, value) {
  354. if (field.selectionStart || field.selectionStart === 0) {
  355. const startPos = field.selectionStart;
  356. const endPos = field.selectionEnd;
  357. field.value =
  358. field.value.substring(0, startPos) +
  359. value +
  360. field.value.substring(endPos, field.value.length);
  361. field.selectionStart = startPos + value.length;
  362. field.selectionEnd = startPos + value.length;
  363. } else {
  364. field.value += value;
  365. }
  366. }
  367. function replaceAndKeepCursor(field, oldval, newval) {
  368. if (field.selectionStart || field.selectionStart === 0) {
  369. const startPos = field.selectionStart;
  370. const endPos = field.selectionEnd;
  371. field.value = field.value.replace(oldval, newval);
  372. field.selectionStart = startPos + newval.length - oldval.length;
  373. field.selectionEnd = endPos + newval.length - oldval.length;
  374. } else {
  375. field.value = field.value.replace(oldval, newval);
  376. }
  377. }
  378. function retrieveImageFromClipboardAsBlob(pasteEvent, callback) {
  379. if (!pasteEvent.clipboardData) {
  380. return;
  381. }
  382. const {items} = pasteEvent.clipboardData;
  383. if (typeof items === 'undefined') {
  384. return;
  385. }
  386. for (let i = 0; i < items.length; i++) {
  387. if (!items[i].type.includes('image')) continue;
  388. const blob = items[i].getAsFile();
  389. if (typeof callback === 'function') {
  390. pasteEvent.preventDefault();
  391. pasteEvent.stopPropagation();
  392. callback(blob);
  393. }
  394. }
  395. }
  396. function uploadFile(file, callback) {
  397. const xhr = new XMLHttpRequest();
  398. xhr.addEventListener('load', () => {
  399. if (xhr.status === 200) {
  400. callback(xhr.responseText);
  401. }
  402. });
  403. xhr.open('post', `${AppSubUrl}/attachments`, true);
  404. xhr.setRequestHeader('X-Csrf-Token', csrf);
  405. const formData = new FormData();
  406. formData.append('file', file, file.name);
  407. xhr.send(formData);
  408. }
  409. function reload() {
  410. window.location.reload();
  411. }
  412. function initImagePaste(target) {
  413. target.each(function () {
  414. const field = this;
  415. field.addEventListener(
  416. 'paste',
  417. (event) => {
  418. retrieveImageFromClipboardAsBlob(event, (img) => {
  419. const name = img.name.substr(0, img.name.lastIndexOf('.'));
  420. insertAtCursor(field, `![${name}]()`);
  421. uploadFile(img, (res) => {
  422. const data = JSON.parse(res);
  423. replaceAndKeepCursor(
  424. field,
  425. `![${name}]()`,
  426. `![${name}](${AppSubUrl}/attachments/${data.uuid})`
  427. );
  428. const input = $(
  429. `<input id="${data.uuid}" name="files" type="hidden">`
  430. ).val(data.uuid);
  431. $('.files').append(input);
  432. });
  433. });
  434. },
  435. false
  436. );
  437. });
  438. }
  439. function initSimpleMDEImagePaste(simplemde, files) {
  440. simplemde.codemirror.on('paste', (_, event) => {
  441. retrieveImageFromClipboardAsBlob(event, (img) => {
  442. const name = img.name.substr(0, img.name.lastIndexOf('.'));
  443. uploadFile(img, (res) => {
  444. const data = JSON.parse(res);
  445. const pos = simplemde.codemirror.getCursor();
  446. simplemde.codemirror.replaceRange(
  447. `![${name}](${AppSubUrl}/attachments/${data.uuid})`,
  448. pos
  449. );
  450. const input = $(
  451. `<input id="${data.uuid}" name="files" type="hidden">`
  452. ).val(data.uuid);
  453. files.append(input);
  454. });
  455. });
  456. });
  457. }
  458. let autoSimpleMDE;
  459. function initCommentForm() {
  460. if ($('.comment.form').length === 0) {
  461. return;
  462. }
  463. autoSimpleMDE = setCommentSimpleMDE(
  464. $('.comment.form textarea:not(.review-textarea)')
  465. );
  466. initBranchSelector();
  467. initCommentPreviewTab($('.comment.form'));
  468. initImagePaste($('.comment.form textarea'));
  469. // Listsubmit
  470. function initListSubmits(selector, outerSelector) {
  471. const $list = $(`.ui.${outerSelector}.list`);
  472. const $noSelect = $list.find('.no-select');
  473. const $listMenu = $(`.${selector} .menu`);
  474. let hasLabelUpdateAction = $listMenu.data('action') === 'update';
  475. const labels = {};
  476. $(`.${selector}`).dropdown('setting', 'onHide', () => {
  477. hasLabelUpdateAction = $listMenu.data('action') === 'update'; // Update the var
  478. if (hasLabelUpdateAction) {
  479. const promises = [];
  480. Object.keys(labels).forEach((elementId) => {
  481. const label = labels[elementId];
  482. const promise = updateIssuesMeta(
  483. label['update-url'],
  484. label.action,
  485. label['issue-id'],
  486. elementId,
  487. label['is-checked']
  488. );
  489. promises.push(promise);
  490. });
  491. Promise.all(promises).then(reload);
  492. }
  493. });
  494. $listMenu.find('.item:not(.no-select)').on('click', function () {
  495. // we don't need the action attribute when updating assignees
  496. if (
  497. selector === 'select-assignees-modify' ||
  498. selector === 'select-reviewers-modify'
  499. ) {
  500. // UI magic. We need to do this here, otherwise it would destroy the functionality of
  501. // adding/removing labels
  502. if ($(this).data('can-change') === 'block') {
  503. return false;
  504. }
  505. if ($(this).hasClass('checked')) {
  506. $(this).removeClass('checked');
  507. $(this)
  508. .find('.octicon-check')
  509. .addClass('invisible');
  510. $(this).data('is-checked', 'remove');
  511. } else {
  512. $(this).addClass('checked');
  513. $(this)
  514. .find('.octicon-check')
  515. .removeClass('invisible');
  516. $(this).data('is-checked', 'add');
  517. }
  518. updateIssuesMeta(
  519. $listMenu.data('update-url'),
  520. '',
  521. $listMenu.data('issue-id'),
  522. $(this).data('id'),
  523. $(this).data('is-checked')
  524. );
  525. $listMenu.data('action', 'update'); // Update to reload the page when we updated items
  526. return false;
  527. }
  528. if ($(this).hasClass('checked')) {
  529. $(this).removeClass('checked');
  530. $(this)
  531. .find('.octicon-check')
  532. .addClass('invisible');
  533. if (hasLabelUpdateAction) {
  534. if (!($(this).data('id') in labels)) {
  535. labels[$(this).data('id')] = {
  536. 'update-url': $listMenu.data('update-url'),
  537. action: 'detach',
  538. 'issue-id': $listMenu.data('issue-id')
  539. };
  540. } else {
  541. delete labels[$(this).data('id')];
  542. }
  543. }
  544. } else {
  545. $(this).addClass('checked');
  546. $(this)
  547. .find('.octicon-check')
  548. .removeClass('invisible');
  549. if (hasLabelUpdateAction) {
  550. if (!($(this).data('id') in labels)) {
  551. labels[$(this).data('id')] = {
  552. 'update-url': $listMenu.data('update-url'),
  553. action: 'attach',
  554. 'issue-id': $listMenu.data('issue-id')
  555. };
  556. } else {
  557. delete labels[$(this).data('id')];
  558. }
  559. }
  560. }
  561. const listIds = [];
  562. $(this)
  563. .parent()
  564. .find('.item')
  565. .each(function () {
  566. if ($(this).hasClass('checked')) {
  567. listIds.push($(this).data('id'));
  568. $($(this).data('id-selector')).removeClass('hide');
  569. } else {
  570. $($(this).data('id-selector')).addClass('hide');
  571. }
  572. });
  573. if (listIds.length === 0) {
  574. $noSelect.removeClass('hide');
  575. } else {
  576. $noSelect.addClass('hide');
  577. }
  578. $(
  579. $(this)
  580. .parent()
  581. .data('id')
  582. ).val(listIds.join(','));
  583. return false;
  584. });
  585. $listMenu.find('.no-select.item').on('click', function () {
  586. if (hasLabelUpdateAction || selector === 'select-assignees-modify') {
  587. updateIssuesMeta(
  588. $listMenu.data('update-url'),
  589. 'clear',
  590. $listMenu.data('issue-id'),
  591. '',
  592. ''
  593. ).then(reload);
  594. }
  595. $(this)
  596. .parent()
  597. .find('.item')
  598. .each(function () {
  599. $(this).removeClass('checked');
  600. $(this)
  601. .find('.octicon')
  602. .addClass('invisible');
  603. $(this).data('is-checked', 'remove');
  604. });
  605. $list.find('.item').each(function () {
  606. $(this).addClass('hide');
  607. });
  608. $noSelect.removeClass('hide');
  609. $(
  610. $(this)
  611. .parent()
  612. .data('id')
  613. ).val('');
  614. });
  615. }
  616. // Init labels and assignees
  617. initListSubmits('select-label', 'labels');
  618. initListSubmits('select-assignees', 'assignees');
  619. initListSubmits('select-assignees-modify', 'assignees');
  620. initListSubmits('select-reviewers-modify', 'assignees');
  621. function selectItem(select_id, input_id) {
  622. const $menu = $(`${select_id} .menu`);
  623. const $list = $(`.ui${select_id}.list`);
  624. const hasUpdateAction = $menu.data('action') === 'update';
  625. $menu.find('.item:not(.no-select)').on('click', function () {
  626. $(this)
  627. .parent()
  628. .find('.item')
  629. .each(function () {
  630. $(this).removeClass('selected active');
  631. });
  632. $(this).addClass('selected active');
  633. if (hasUpdateAction) {
  634. updateIssuesMeta(
  635. $menu.data('update-url'),
  636. '',
  637. $menu.data('issue-id'),
  638. $(this).data('id'),
  639. $(this).data('is-checked')
  640. ).then(reload);
  641. }
  642. switch (input_id) {
  643. case '#milestone_id':
  644. $list
  645. .find('.selected')
  646. .html(
  647. `<a class="item" href=${$(this).data('href')}>${htmlEncode(
  648. $(this).text()
  649. )}</a>`
  650. );
  651. break;
  652. case '#assignee_id':
  653. $list
  654. .find('.selected')
  655. .html(
  656. `<a class="item" href=${$(this).data('href')}>` +
  657. `<img class="ui avatar image" src=${$(this).data(
  658. 'avatar'
  659. )}>${htmlEncode($(this).text())}</a>`
  660. );
  661. }
  662. $(`.ui${select_id}.list .no-select`).addClass('hide');
  663. $(input_id).val($(this).data('id'));
  664. });
  665. $menu.find('.no-select.item').on('click', function () {
  666. $(this)
  667. .parent()
  668. .find('.item:not(.no-select)')
  669. .each(function () {
  670. $(this).removeClass('selected active');
  671. });
  672. if (hasUpdateAction) {
  673. updateIssuesMeta(
  674. $menu.data('update-url'),
  675. '',
  676. $menu.data('issue-id'),
  677. $(this).data('id'),
  678. $(this).data('is-checked')
  679. ).then(reload);
  680. }
  681. $list.find('.selected').html('');
  682. $list.find('.no-select').removeClass('hide');
  683. $(input_id).val('');
  684. });
  685. }
  686. // Milestone and assignee
  687. selectItem('.select-milestone', '#milestone_id');
  688. selectItem('.select-assignee', '#assignee_id');
  689. }
  690. function initInstall() {
  691. if ($('.install').length === 0) {
  692. return;
  693. }
  694. if ($('#db_host').val() === '') {
  695. $('#db_host').val('127.0.0.1:3306');
  696. $('#db_user').val('gitea');
  697. $('#db_name').val('gitea');
  698. }
  699. // Database type change detection.
  700. $('#db_type').on('change', function () {
  701. const sqliteDefault = 'data/gitea.db';
  702. const tidbDefault = 'data/gitea_tidb';
  703. const dbType = $(this).val();
  704. if (dbType === 'SQLite3') {
  705. $('#sql_settings').hide();
  706. $('#pgsql_settings').hide();
  707. $('#mysql_settings').hide();
  708. $('#sqlite_settings').show();
  709. if (dbType === 'SQLite3' && $('#db_path').val() === tidbDefault) {
  710. $('#db_path').val(sqliteDefault);
  711. }
  712. return;
  713. }
  714. const dbDefaults = {
  715. MySQL: '127.0.0.1:3306',
  716. PostgreSQL: '127.0.0.1:5432',
  717. MSSQL: '127.0.0.1:1433'
  718. };
  719. $('#sqlite_settings').hide();
  720. $('#sql_settings').show();
  721. $('#pgsql_settings').toggle(dbType === 'PostgreSQL');
  722. $('#mysql_settings').toggle(dbType === 'MySQL');
  723. $.each(dbDefaults, (_type, defaultHost) => {
  724. if ($('#db_host').val() === defaultHost) {
  725. $('#db_host').val(dbDefaults[dbType]);
  726. return false;
  727. }
  728. });
  729. });
  730. // TODO: better handling of exclusive relations.
  731. $('#offline-mode input').on('change', function () {
  732. if ($(this).is(':checked')) {
  733. $('#disable-gravatar').checkbox('check');
  734. $('#federated-avatar-lookup').checkbox('uncheck');
  735. }
  736. });
  737. $('#disable-gravatar input').on('change', function () {
  738. if ($(this).is(':checked')) {
  739. $('#federated-avatar-lookup').checkbox('uncheck');
  740. } else {
  741. $('#offline-mode').checkbox('uncheck');
  742. }
  743. });
  744. $('#federated-avatar-lookup input').on('change', function () {
  745. if ($(this).is(':checked')) {
  746. $('#disable-gravatar').checkbox('uncheck');
  747. $('#offline-mode').checkbox('uncheck');
  748. }
  749. });
  750. $('#enable-openid-signin input').on('change', function () {
  751. if ($(this).is(':checked')) {
  752. if (!$('#disable-registration input').is(':checked')) {
  753. $('#enable-openid-signup').checkbox('check');
  754. }
  755. } else {
  756. $('#enable-openid-signup').checkbox('uncheck');
  757. }
  758. });
  759. $('#disable-registration input').on('change', function () {
  760. if ($(this).is(':checked')) {
  761. $('#enable-captcha').checkbox('uncheck');
  762. $('#enable-openid-signup').checkbox('uncheck');
  763. } else {
  764. $('#enable-openid-signup').checkbox('check');
  765. }
  766. });
  767. $('#enable-captcha input').on('change', function () {
  768. if ($(this).is(':checked')) {
  769. $('#disable-registration').checkbox('uncheck');
  770. }
  771. });
  772. }
  773. function initIssueComments() {
  774. if ($('.repository.view.issue .timeline').length === 0) return;
  775. $('.re-request-review').on('click', function (event) {
  776. const url = $(this).data('update-url');
  777. const issueId = $(this).data('issue-id');
  778. const id = $(this).data('id');
  779. const isChecked = $(this).data('is-checked');
  780. event.preventDefault();
  781. updateIssuesMeta(url, '', issueId, id, isChecked).then(reload);
  782. });
  783. $(document).on('click', (event) => {
  784. const urlTarget = $(':target');
  785. if (urlTarget.length === 0) return;
  786. const urlTargetId = urlTarget.attr('id');
  787. if (!urlTargetId) return;
  788. if (!/^(issue|pull)(comment)?-\d+$/.test(urlTargetId)) return;
  789. const $target = $(event.target);
  790. if ($target.closest(`#${urlTargetId}`).length === 0) {
  791. const scrollPosition = $(window).scrollTop();
  792. window.location.hash = '';
  793. $(window).scrollTop(scrollPosition);
  794. window.history.pushState(null, null, ' ');
  795. }
  796. });
  797. }
  798. async function initRepository() {
  799. if ($('.repository').length === 0) {
  800. return;
  801. }
  802. function initFilterSearchDropdown(selector) {
  803. const $dropdown = $(selector);
  804. $dropdown.dropdown({
  805. fullTextSearch: true,
  806. selectOnKeydown: false,
  807. onChange(_text, _value, $choice) {
  808. if ($choice.data('url')) {
  809. window.location.href = $choice.data('url');
  810. }
  811. },
  812. message: {noResults: $dropdown.data('no-results')}
  813. });
  814. }
  815. // File list and commits
  816. if (
  817. $('.repository.file.list').length > 0 ||
  818. '.repository.commits'.length > 0
  819. ) {
  820. initFilterBranchTagDropdown('.choose.reference .dropdown');
  821. }
  822. // Wiki
  823. if ($('.repository.wiki.view').length > 0) {
  824. initFilterSearchDropdown('.choose.page .dropdown');
  825. }
  826. // Options
  827. if ($('.repository.settings.options').length > 0) {
  828. // Enable or select internal/external wiki system and issue tracker.
  829. $('.enable-system').on('change', function () {
  830. if (this.checked) {
  831. $($(this).data('target')).removeClass('disabled');
  832. if (!$(this).data('context')) {
  833. $($(this).data('context')).addClass('disabled');
  834. }
  835. } else {
  836. $($(this).data('target')).addClass('disabled');
  837. if (!$(this).data('context')) {
  838. $($(this).data('context')).removeClass('disabled');
  839. }
  840. }
  841. });
  842. $('.enable-system-radio').on('change', function () {
  843. if (this.value === 'false') {
  844. $($(this).data('target')).addClass('disabled');
  845. if (typeof $(this).data('context') !== 'undefined') {
  846. $($(this).data('context')).removeClass('disabled');
  847. }
  848. } else if (this.value === 'true') {
  849. $($(this).data('target')).removeClass('disabled');
  850. if (typeof $(this).data('context') !== 'undefined') {
  851. $($(this).data('context')).addClass('disabled');
  852. }
  853. }
  854. });
  855. }
  856. // Labels
  857. if ($('.repository.labels').length > 0) {
  858. initLabelEdit();
  859. }
  860. // Milestones
  861. if ($('.repository.new.milestone').length > 0) {
  862. const $datepicker = $('.milestone.datepicker');
  863. await initDateTimePicker($datepicker.data('lang'));
  864. $datepicker.datetimepicker({
  865. inline: true,
  866. timepicker: false,
  867. startDate: $datepicker.data('start-date'),
  868. onSelectDate(date) {
  869. $('#deadline').val(date.toISOString().substring(0, 10));
  870. }
  871. });
  872. $('#clear-date').on('click', () => {
  873. $('#deadline').val('');
  874. return false;
  875. });
  876. }
  877. // Issues
  878. if ($('.repository.view.issue').length > 0) {
  879. // Edit issue title
  880. const $issueTitle = $('#issue-title');
  881. const $editInput = $('#edit-title-input input');
  882. const editTitleToggle = function () {
  883. $issueTitle.toggle();
  884. $('.not-in-edit').toggle();
  885. $('#edit-title-input').toggle();
  886. $('#pull-desc').toggle();
  887. $('#pull-desc-edit').toggle();
  888. $('.in-edit').toggle();
  889. $editInput.focus();
  890. return false;
  891. };
  892. const changeBranchSelect = function () {
  893. const selectionTextField = $('#pull-target-branch');
  894. const baseName = selectionTextField.data('basename');
  895. const branchNameNew = $(this).data('branch');
  896. const branchNameOld = selectionTextField.data('branch');
  897. // Replace branch name to keep translation from HTML template
  898. selectionTextField.html(
  899. selectionTextField
  900. .html()
  901. .replace(
  902. `${baseName}:${branchNameOld}`,
  903. `${baseName}:${branchNameNew}`
  904. )
  905. );
  906. selectionTextField.data('branch', branchNameNew); // update branch name in setting
  907. };
  908. $('#branch-select > .item').on('click', changeBranchSelect);
  909. $('#edit-title').on('click', editTitleToggle);
  910. $('#cancel-edit-title').on('click', editTitleToggle);
  911. $('#save-edit-title')
  912. .on('click', editTitleToggle)
  913. .on('click', function () {
  914. const pullrequest_targetbranch_change = function (update_url) {
  915. const targetBranch = $('#pull-target-branch').data('branch');
  916. const $branchTarget = $('#branch_target');
  917. if (targetBranch === $branchTarget.text()) {
  918. return false;
  919. }
  920. $.post(update_url, {
  921. _csrf: csrf,
  922. target_branch: targetBranch
  923. })
  924. .done((data) => {
  925. $branchTarget.text(data.base_branch);
  926. })
  927. .always(() => {
  928. reload();
  929. });
  930. };
  931. const pullrequest_target_update_url = $(this).data('target-update-url');
  932. if (
  933. $editInput.val().length === 0 ||
  934. $editInput.val() === $issueTitle.text()
  935. ) {
  936. $editInput.val($issueTitle.text());
  937. pullrequest_targetbranch_change(pullrequest_target_update_url);
  938. } else {
  939. $.post(
  940. $(this).data('update-url'),
  941. {
  942. _csrf: csrf,
  943. title: $editInput.val()
  944. },
  945. (data) => {
  946. $editInput.val(data.title);
  947. $issueTitle.text(data.title);
  948. pullrequest_targetbranch_change(pullrequest_target_update_url);
  949. reload();
  950. }
  951. );
  952. }
  953. return false;
  954. });
  955. // Issue Comments
  956. initIssueComments();
  957. // Issue/PR Context Menus
  958. $('.context-dropdown').dropdown({
  959. action: 'hide'
  960. });
  961. // Quote reply
  962. $('.quote-reply').on('click', function (event) {
  963. $(this)
  964. .closest('.dropdown')
  965. .find('.menu')
  966. .toggle('visible');
  967. const target = $(this).data('target');
  968. const quote = $(`#comment-${target}`)
  969. .text()
  970. .replace(/\n/g, '\n> ');
  971. const content = `> ${quote}\n\n`;
  972. let $content;
  973. if ($(this).hasClass('quote-reply-diff')) {
  974. const $parent = $(this).closest('.comment-code-cloud');
  975. $parent.find('button.comment-form-reply').trigger('click');
  976. $content = $parent.find('[name="content"]');
  977. if ($content.val() !== '') {
  978. $content.val(`${$content.val()}\n\n${content}`);
  979. } else {
  980. $content.val(`${content}`);
  981. }
  982. $content.focus();
  983. } else if (autoSimpleMDE !== null) {
  984. if (autoSimpleMDE.value() !== '') {
  985. autoSimpleMDE.value(`${autoSimpleMDE.value()}\n\n${content}`);
  986. } else {
  987. autoSimpleMDE.value(`${content}`);
  988. }
  989. }
  990. event.preventDefault();
  991. });
  992. // Edit issue or comment content
  993. $('.edit-content').on('click', async function (event) {
  994. $(this)
  995. .closest('.dropdown')
  996. .find('.menu')
  997. .toggle('visible');
  998. const $segment = $(this)
  999. .closest('.header')
  1000. .next();
  1001. const $editContentZone = $segment.find('.edit-content-zone');
  1002. const $renderContent = $segment.find('.render-content');
  1003. const $rawContent = $segment.find('.raw-content');
  1004. let $textarea;
  1005. let $simplemde;
  1006. // Setup new form
  1007. if ($editContentZone.html().length === 0) {
  1008. $editContentZone.html($('#edit-content-form').html());
  1009. $textarea = $editContentZone.find('textarea');
  1010. issuesTribute.attach($textarea.get());
  1011. emojiTribute.attach($textarea.get());
  1012. let dz;
  1013. const $dropzone = $editContentZone.find('.dropzone');
  1014. const $files = $editContentZone.find('.comment-files');
  1015. if ($dropzone.length > 0) {
  1016. $dropzone.data('saved', false);
  1017. const filenameDict = {};
  1018. dz = await createDropzone($dropzone[0], {
  1019. url: $dropzone.data('upload-url'),
  1020. headers: {'X-Csrf-Token': csrf},
  1021. maxFiles: $dropzone.data('max-file'),
  1022. maxFilesize: $dropzone.data('max-size'),
  1023. acceptedFiles:
  1024. $dropzone.data('accepts') === '*/*' ?
  1025. null :
  1026. $dropzone.data('accepts'),
  1027. addRemoveLinks: true,
  1028. dictDefaultMessage: $dropzone.data('default-message'),
  1029. dictInvalidFileType: $dropzone.data('invalid-input-type'),
  1030. dictFileTooBig: $dropzone.data('file-too-big'),
  1031. dictRemoveFile: $dropzone.data('remove-file'),
  1032. init() {
  1033. this.on('success', (file, data) => {
  1034. filenameDict[file.name] = {
  1035. uuid: data.uuid,
  1036. submitted: false
  1037. };
  1038. const input = $(
  1039. `<input id="${data.uuid}" name="files" type="hidden">`
  1040. ).val(data.uuid);
  1041. $files.append(input);
  1042. });
  1043. this.on('removedfile', (file) => {
  1044. if (!(file.name in filenameDict)) {
  1045. return;
  1046. }
  1047. $(`#${filenameDict[file.name].uuid}`).remove();
  1048. if (
  1049. $dropzone.data('remove-url') &&
  1050. $dropzone.data('csrf') &&
  1051. !filenameDict[file.name].submitted
  1052. ) {
  1053. $.post($dropzone.data('remove-url'), {
  1054. file: filenameDict[file.name].uuid,
  1055. _csrf: $dropzone.data('csrf')
  1056. });
  1057. }
  1058. });
  1059. this.on('submit', () => {
  1060. $.each(filenameDict, (name) => {
  1061. filenameDict[name].submitted = true;
  1062. });
  1063. });
  1064. this.on('reload', () => {
  1065. $.getJSON($editContentZone.data('attachment-url'), (data) => {
  1066. dz.removeAllFiles(true);
  1067. $files.empty();
  1068. $.each(data, function () {
  1069. const imgSrc = `${$dropzone.data('upload-url')}/${
  1070. this.uuid
  1071. }`;
  1072. dz.emit('addedfile', this);
  1073. dz.emit('thumbnail', this, imgSrc);
  1074. dz.emit('complete', this);
  1075. dz.files.push(this);
  1076. filenameDict[this.name] = {
  1077. submitted: true,
  1078. uuid: this.uuid
  1079. };
  1080. $dropzone
  1081. .find(`img[src='${imgSrc}']`)
  1082. .css('max-width', '100%');
  1083. const input = $(
  1084. `<input id="${this.uuid}" name="files" type="hidden">`
  1085. ).val(this.uuid);
  1086. $files.append(input);
  1087. });
  1088. });
  1089. });
  1090. }
  1091. });
  1092. dz.emit('reload');
  1093. }
  1094. // Give new write/preview data-tab name to distinguish from others
  1095. const $editContentForm = $editContentZone.find('.ui.comment.form');
  1096. const $tabMenu = $editContentForm.find('.tabular.menu');
  1097. $tabMenu.attr('data-write', $editContentZone.data('write'));
  1098. $tabMenu.attr('data-preview', $editContentZone.data('preview'));
  1099. $tabMenu
  1100. .find('.write.item')
  1101. .attr('data-tab', $editContentZone.data('write'));
  1102. $tabMenu
  1103. .find('.preview.item')
  1104. .attr('data-tab', $editContentZone.data('preview'));
  1105. $editContentForm
  1106. .find('.write')
  1107. .attr('data-tab', $editContentZone.data('write'));
  1108. $editContentForm
  1109. .find('.preview')
  1110. .attr('data-tab', $editContentZone.data('preview'));
  1111. $simplemde = setCommentSimpleMDE($textarea);
  1112. commentMDEditors[$editContentZone.data('write')] = $simplemde;
  1113. initCommentPreviewTab($editContentForm);
  1114. initSimpleMDEImagePaste($simplemde, $files);
  1115. $editContentZone.find('.cancel.button').on('click', () => {
  1116. $renderContent.show();
  1117. $editContentZone.hide();
  1118. dz.emit('reload');
  1119. });
  1120. $editContentZone.find('.save.button').on('click', () => {
  1121. $renderContent.show();
  1122. $editContentZone.hide();
  1123. const $attachments = $files
  1124. .find('[name=files]')
  1125. .map(function () {
  1126. return $(this).val();
  1127. })
  1128. .get();
  1129. $.post(
  1130. $editContentZone.data('update-url'),
  1131. {
  1132. _csrf: csrf,
  1133. content: $textarea.val(),
  1134. context: $editContentZone.data('context'),
  1135. files: $attachments
  1136. },
  1137. (data) => {
  1138. if (data.length === 0) {
  1139. $renderContent.html($('#no-content').html());
  1140. } else {
  1141. $renderContent.html(data.content);
  1142. $('pre code', $renderContent[0]).each(function () {
  1143. highlight(this);
  1144. });
  1145. }
  1146. const $content = $segment.parent();
  1147. if (!$content.find('.ui.small.images').length) {
  1148. if (data.attachments !== '') {
  1149. $content.append(
  1150. '<div class="ui bottom attached segment"><div class="ui small images"></div></div>'
  1151. );
  1152. $content.find('.ui.small.images').html(data.attachments);
  1153. }
  1154. } else if (data.attachments === '') {
  1155. $content
  1156. .find('.ui.small.images')
  1157. .parent()
  1158. .remove();
  1159. } else {
  1160. $content.find('.ui.small.images').html(data.attachments);
  1161. }
  1162. dz.emit('submit');
  1163. dz.emit('reload');
  1164. }
  1165. );
  1166. });
  1167. } else {
  1168. $textarea = $segment.find('textarea');
  1169. $simplemde = commentMDEditors[$editContentZone.data('write')];
  1170. }
  1171. // Show write/preview tab and copy raw content as needed
  1172. $editContentZone.show();
  1173. $renderContent.hide();
  1174. if ($textarea.val().length === 0) {
  1175. $textarea.val($rawContent.text());
  1176. $simplemde.value($rawContent.text());
  1177. }
  1178. $textarea.focus();
  1179. $simplemde.codemirror.focus();
  1180. event.preventDefault();
  1181. });
  1182. // Delete comment
  1183. $('.delete-comment').on('click', function () {
  1184. const $this = $(this);
  1185. if (window.confirm($this.data('locale'))) {
  1186. $.post($this.data('url'), {
  1187. _csrf: csrf
  1188. }).done(() => {
  1189. $(`#${$this.data('comment-id')}`).remove();
  1190. });
  1191. }
  1192. return false;
  1193. });
  1194. // Change status
  1195. const $statusButton = $('#status-button');
  1196. $('#comment-form .edit_area').on('keyup', function () {
  1197. if ($(this).val().length === 0) {
  1198. $statusButton.text($statusButton.data('status'));
  1199. } else {
  1200. $statusButton.text($statusButton.data('status-and-comment'));
  1201. }
  1202. });
  1203. $statusButton.on('click', () => {
  1204. $('#status').val($statusButton.data('status-val'));
  1205. $('#comment-form').trigger('submit');
  1206. });
  1207. // Pull Request merge button
  1208. const $mergeButton = $('.merge-button > button');
  1209. $mergeButton.on('click', function (e) {
  1210. e.preventDefault();
  1211. $(`.${$(this).data('do')}-fields`).show();
  1212. $(this)
  1213. .parent()
  1214. .hide();
  1215. });
  1216. $('.merge-button > .dropdown').dropdown({
  1217. onChange(_text, _value, $choice) {
  1218. if ($choice.data('do')) {
  1219. $mergeButton.find('.button-text').text($choice.text());
  1220. $mergeButton.data('do', $choice.data('do'));
  1221. }
  1222. }
  1223. });
  1224. $('.merge-cancel').on('click', function (e) {
  1225. e.preventDefault();
  1226. $(this)
  1227. .closest('.form')
  1228. .hide();
  1229. $mergeButton.parent().show();
  1230. });
  1231. initReactionSelector();
  1232. }
  1233. // Datasets
  1234. if ($('.repository.dataset-list.view').length > 0) {
  1235. const editContentToggle = function () {
  1236. $('#dataset-content').toggle();
  1237. $('#dataset-content-edit').toggle();
  1238. $('#dataset-content input').focus();
  1239. return false;
  1240. };
  1241. $('[data-dataset-status]').on('click', function () {
  1242. const $this = $(this);
  1243. const $private = $this.data('private');
  1244. const $is_private = $this.data('is-private');
  1245. if ($is_private === $private) {
  1246. return;
  1247. }
  1248. const $uuid = $this.data('uuid');
  1249. $.post($this.data('url'), {
  1250. _csrf: $this.data('csrf'),
  1251. file: $uuid,
  1252. is_private: $private
  1253. })
  1254. .done((_data) => {
  1255. $(`[data-uuid='${$uuid}']`).removeClass('positive active');
  1256. $(`[data-uuid='${$uuid}']`).data('is-private', $private);
  1257. $this.addClass('positive active');
  1258. })
  1259. .fail(() => {
  1260. window.location.reload();
  1261. });
  1262. });
  1263. $('[data-dataset-delete]').on('click', function () {
  1264. const $this = $(this);
  1265. $('#data-dataset-delete-modal')
  1266. .modal({
  1267. closable: false,
  1268. onApprove() {
  1269. $.post($this.data('remove-url'), {
  1270. _csrf: $this.data('csrf'),
  1271. file: $this.data('uuid')
  1272. })
  1273. .done((_data) => {
  1274. $(`#${$this.data('uuid')}`).hide();
  1275. })
  1276. .fail(() => {
  1277. window.location.reload();
  1278. });
  1279. }
  1280. })
  1281. .modal('show');
  1282. });
  1283. $('[data-category-id]').on('click', function () {
  1284. const category = $(this).data('category-id');
  1285. $('#category').val(category);
  1286. $('#submit').click();
  1287. });
  1288. $('[data-task-id]').on('click', function () {
  1289. const task = $(this).data('task-id');
  1290. $('#task').val(task);
  1291. $('#submit').click();
  1292. });
  1293. $('[data-license-id]').on('click', function () {
  1294. const license = $(this).data('license-id');
  1295. $('#license').val(license);
  1296. $('#submit').click();
  1297. });
  1298. $('#dataset-edit').on('click', editContentToggle);
  1299. $('#cancel').on('click', editContentToggle);
  1300. }
  1301. // Diff
  1302. if ($('.repository.diff').length > 0) {
  1303. $('.diff-counter').each(function () {
  1304. const $item = $(this);
  1305. const addLine = $item.find('span[data-line].add').data('line');
  1306. const delLine = $item.find('span[data-line].del').data('line');
  1307. const addPercent =
  1308. (parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine))) *
  1309. 100;
  1310. $item.find('.bar .add').css('width', `${addPercent}%`);
  1311. });
  1312. }
  1313. // Quick start and repository home
  1314. $('#repo-clone-ssh').on('click', function () {
  1315. $('.clone-url').text($(this).data('link'));
  1316. $('#repo-clone-url').val($(this).data('link'));
  1317. $(this).addClass('blue');
  1318. $('#repo-clone-https').removeClass('blue');
  1319. localStorage.setItem('repo-clone-protocol', 'ssh');
  1320. });
  1321. $('#repo-clone-https').on('click', function () {
  1322. $('.clone-url').text($(this).data('link'));
  1323. $('#repo-clone-url').val($(this).data('link'));
  1324. $(this).addClass('blue');
  1325. $('#repo-clone-ssh').removeClass('blue');
  1326. localStorage.setItem('repo-clone-protocol', 'https');
  1327. });
  1328. $('#repo-clone-url').on('click', function () {
  1329. $(this).select();
  1330. });
  1331. // Pull request
  1332. const $repoComparePull = $('.repository.compare.pull');
  1333. if ($repoComparePull.length > 0) {
  1334. initFilterSearchDropdown('.choose.branch .dropdown');
  1335. // show pull request form
  1336. $repoComparePull.find('button.show-form').on('click', function (e) {
  1337. e.preventDefault();
  1338. $repoComparePull.find('.pullrequest-form').show();
  1339. autoSimpleMDE.codemirror.refresh();
  1340. $(this)
  1341. .parent()
  1342. .hide();
  1343. });
  1344. }
  1345. // Branches
  1346. if ($('.repository.settings.branches').length > 0) {
  1347. initFilterSearchDropdown('.protected-branches .dropdown');
  1348. $('.enable-protection, .enable-whitelist, .enable-statuscheck').on(
  1349. 'change',
  1350. function () {
  1351. if (this.checked) {
  1352. $($(this).data('target')).removeClass('disabled');
  1353. } else {
  1354. $($(this).data('target')).addClass('disabled');
  1355. }
  1356. }
  1357. );
  1358. $('.disable-whitelist').on('change', function () {
  1359. if (this.checked) {
  1360. $($(this).data('target')).addClass('disabled');
  1361. }
  1362. });
  1363. }
  1364. // Language stats
  1365. if ($('.language-stats').length > 0) {
  1366. $('.language-stats').on('click', (e) => {
  1367. e.preventDefault();
  1368. $('.language-stats-details, .repository-menu').slideToggle();
  1369. });
  1370. }
  1371. }
  1372. function initMigration() {
  1373. const toggleMigrations = function () {
  1374. const authUserName = $('#auth_username').val();
  1375. const cloneAddr = $('#clone_addr').val();
  1376. if (
  1377. !$('#mirror').is(':checked') &&
  1378. authUserName &&
  1379. authUserName.length > 0 &&
  1380. cloneAddr !== undefined &&
  1381. (cloneAddr.startsWith('https://github.com') ||
  1382. cloneAddr.startsWith('http://github.com') ||
  1383. cloneAddr.startsWith('http://gitlab.com') ||
  1384. cloneAddr.startsWith('https://gitlab.com'))
  1385. ) {
  1386. $('#migrate_items').show();
  1387. } else {
  1388. $('#migrate_items').hide();
  1389. }
  1390. };
  1391. toggleMigrations();
  1392. $('#clone_addr').on('input', toggleMigrations);
  1393. $('#auth_username').on('input', toggleMigrations);
  1394. $('#mirror').on('change', toggleMigrations);
  1395. }
  1396. function initPullRequestReview() {
  1397. $('.show-outdated').on('click', function (e) {
  1398. e.preventDefault();
  1399. const id = $(this).data('comment');
  1400. $(this).addClass('hide');
  1401. $(`#code-comments-${id}`).removeClass('hide');
  1402. $(`#code-preview-${id}`).removeClass('hide');
  1403. $(`#hide-outdated-${id}`).removeClass('hide');
  1404. });
  1405. $('.hide-outdated').on('click', function (e) {
  1406. e.preventDefault();
  1407. const id = $(this).data('comment');
  1408. $(this).addClass('hide');
  1409. $(`#code-comments-${id}`).addClass('hide');
  1410. $(`#code-preview-${id}`).addClass('hide');
  1411. $(`#show-outdated-${id}`).removeClass('hide');
  1412. });
  1413. $('button.comment-form-reply').on('click', function (e) {
  1414. e.preventDefault();
  1415. $(this).hide();
  1416. const form = $(this)
  1417. .parent()
  1418. .find('.comment-form');
  1419. form.removeClass('hide');
  1420. assingMenuAttributes(form.find('.menu'));
  1421. });
  1422. // The following part is only for diff views
  1423. if ($('.repository.pull.diff').length === 0) {
  1424. return;
  1425. }
  1426. $('.diff-detail-box.ui.sticky').sticky();
  1427. $('.btn-review')
  1428. .on('click', function (e) {
  1429. e.preventDefault();
  1430. $(this)
  1431. .closest('.dropdown')
  1432. .find('.menu')
  1433. .toggle('visible');
  1434. })
  1435. .closest('.dropdown')
  1436. .find('.link.close')
  1437. .on('click', function (e) {
  1438. e.preventDefault();
  1439. $(this)
  1440. .closest('.menu')
  1441. .toggle('visible');
  1442. });
  1443. $('.code-view .lines-code,.code-view .lines-num')
  1444. .on('mouseenter', function () {
  1445. const parent = $(this).closest('td');
  1446. $(this)
  1447. .closest('tr')
  1448. .addClass(
  1449. parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old') ?
  1450. 'focus-lines-old' :
  1451. 'focus-lines-new'
  1452. );
  1453. })
  1454. .on('mouseleave', function () {
  1455. $(this)
  1456. .closest('tr')
  1457. .removeClass('focus-lines-new focus-lines-old');
  1458. });
  1459. $('.add-code-comment').on('click', function (e) {
  1460. // https://github.com/go-gitea/gitea/issues/4745
  1461. if ($(e.target).hasClass('btn-add-single')) {
  1462. return;
  1463. }
  1464. e.preventDefault();
  1465. const isSplit = $(this)
  1466. .closest('.code-diff')
  1467. .hasClass('code-diff-split');
  1468. const side = $(this).data('side');
  1469. const idx = $(this).data('idx');
  1470. const path = $(this).data('path');
  1471. const form = $('#pull_review_add_comment').html();
  1472. const tr = $(this).closest('tr');
  1473. let ntr = tr.next();
  1474. if (!ntr.hasClass('add-comment')) {
  1475. ntr = $(
  1476. `<tr class="add-comment">${
  1477. isSplit ?
  1478. '<td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-right"></td>' :
  1479. '<td class="lines-num"></td><td class="lines-num"></td><td class="add-comment-left add-comment-right" colspan="2"></td>'
  1480. }</tr>`
  1481. );
  1482. tr.after(ntr);
  1483. }
  1484. const td = ntr.find(`.add-comment-${side}`);
  1485. let commentCloud = td.find('.comment-code-cloud');
  1486. if (commentCloud.length === 0) {
  1487. td.html(form);
  1488. commentCloud = td.find('.comment-code-cloud');
  1489. assingMenuAttributes(commentCloud.find('.menu'));
  1490. td.find("input[name='line']").val(idx);
  1491. td.find("input[name='side']").val(
  1492. side === 'left' ? 'previous' : 'proposed'
  1493. );
  1494. td.find("input[name='path']").val(path);
  1495. }
  1496. commentCloud.find('textarea').focus();
  1497. });
  1498. }
  1499. function assingMenuAttributes(menu) {
  1500. const id = Math.floor(Math.random() * Math.floor(1000000));
  1501. menu.attr('data-write', menu.attr('data-write') + id);
  1502. menu.attr('data-preview', menu.attr('data-preview') + id);
  1503. menu.find('.item').each(function () {
  1504. const tab = $(this).attr('data-tab') + id;
  1505. $(this).attr('data-tab', tab);
  1506. });
  1507. menu
  1508. .parent()
  1509. .find("*[data-tab='write']")
  1510. .attr('data-tab', `write${id}`);
  1511. menu
  1512. .parent()
  1513. .find("*[data-tab='preview']")
  1514. .attr('data-tab', `preview${id}`);
  1515. initCommentPreviewTab(menu.parent('.form'));
  1516. return id;
  1517. }
  1518. function initRepositoryCollaboration() {
  1519. // Change collaborator access mode
  1520. $('.access-mode.menu .item').on('click', function () {
  1521. const $menu = $(this).parent();
  1522. $.post($menu.data('url'), {
  1523. _csrf: csrf,
  1524. uid: $menu.data('uid'),
  1525. mode: $(this).data('value')
  1526. });
  1527. });
  1528. }
  1529. function initTeamSettings() {
  1530. // Change team access mode
  1531. $('.organization.new.team input[name=permission]').on('change', () => {
  1532. const val = $(
  1533. 'input[name=permission]:checked',
  1534. '.organization.new.team'
  1535. ).val();
  1536. if (val === 'admin') {
  1537. $('.organization.new.team .team-units').hide();
  1538. } else {
  1539. $('.organization.new.team .team-units').show();
  1540. }
  1541. });
  1542. }
  1543. function initWikiForm() {
  1544. const $editArea = $('.repository.wiki textarea#edit_area');
  1545. let sideBySideChanges = 0;
  1546. let sideBySideTimeout = null;
  1547. if ($editArea.length > 0) {
  1548. const simplemde = new SimpleMDE({
  1549. autoDownloadFontAwesome: false,
  1550. element: $editArea[0],
  1551. forceSync: true,
  1552. previewRender(plainText, preview) {
  1553. // Async method
  1554. setTimeout(() => {
  1555. // FIXME: still send render request when return back to edit mode
  1556. const render = function () {
  1557. sideBySideChanges = 0;
  1558. if (sideBySideTimeout !== null) {
  1559. clearTimeout(sideBySideTimeout);
  1560. sideBySideTimeout = null;
  1561. }
  1562. $.post(
  1563. $editArea.data('url'),
  1564. {
  1565. _csrf: csrf,
  1566. mode: 'gfm',
  1567. context: $editArea.data('context'),
  1568. text: plainText
  1569. },
  1570. (data) => {
  1571. preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
  1572. $(preview)
  1573. .find('pre code')
  1574. .each((_, e) => {
  1575. highlight(e);
  1576. });
  1577. }
  1578. );
  1579. };
  1580. if (!simplemde.isSideBySideActive()) {
  1581. render();
  1582. } else {
  1583. // delay preview by keystroke counting
  1584. sideBySideChanges++;
  1585. if (sideBySideChanges > 10) {
  1586. render();
  1587. }
  1588. // or delay preview by timeout
  1589. if (sideBySideTimeout !== null) {
  1590. clearTimeout(sideBySideTimeout);
  1591. sideBySideTimeout = null;
  1592. }
  1593. sideBySideTimeout = setTimeout(render, 600);
  1594. }
  1595. }, 0);
  1596. if (!simplemde.isSideBySideActive()) {
  1597. return 'Loading...';
  1598. }
  1599. return preview.innerHTML;
  1600. },
  1601. renderingConfig: {
  1602. singleLineBreaks: false
  1603. },
  1604. indentWithTabs: false,
  1605. tabSize: 4,
  1606. spellChecker: false,
  1607. toolbar: [
  1608. 'bold',
  1609. 'italic',
  1610. 'strikethrough',
  1611. '|',
  1612. 'heading-1',
  1613. 'heading-2',
  1614. 'heading-3',
  1615. 'heading-bigger',
  1616. 'heading-smaller',
  1617. '|',
  1618. {
  1619. name: 'code-inline',
  1620. action(e) {
  1621. const cm = e.codemirror;
  1622. const selection = cm.getSelection();
  1623. cm.replaceSelection(`\`${selection}\``);
  1624. if (!selection) {
  1625. const cursorPos = cm.getCursor();
  1626. cm.setCursor(cursorPos.line, cursorPos.ch - 1);
  1627. }
  1628. cm.focus();
  1629. },
  1630. className: 'fa fa-angle-right',
  1631. title: 'Add Inline Code'
  1632. },
  1633. 'code',
  1634. 'quote',
  1635. '|',
  1636. {
  1637. name: 'checkbox-empty',
  1638. action(e) {
  1639. const cm = e.codemirror;
  1640. cm.replaceSelection(`\n- [ ] ${cm.getSelection()}`);
  1641. cm.focus();
  1642. },
  1643. className: 'fa fa-square-o',
  1644. title: 'Add Checkbox (empty)'
  1645. },
  1646. {
  1647. name: 'checkbox-checked',
  1648. action(e) {
  1649. const cm = e.codemirror;
  1650. cm.replaceSelection(`\n- [x] ${cm.getSelection()}`);
  1651. cm.focus();
  1652. },
  1653. className: 'fa fa-check-square-o',
  1654. title: 'Add Checkbox (checked)'
  1655. },
  1656. '|',
  1657. 'unordered-list',
  1658. 'ordered-list',
  1659. '|',
  1660. 'link',
  1661. 'image',
  1662. 'table',
  1663. 'horizontal-rule',
  1664. '|',
  1665. 'clean-block',
  1666. 'preview',
  1667. 'fullscreen',
  1668. 'side-by-side',
  1669. '|',
  1670. {
  1671. name: 'revert-to-textarea',
  1672. action(e) {
  1673. e.toTextArea();
  1674. },
  1675. className: 'fa fa-file',
  1676. title: 'Revert to simple textarea'
  1677. }
  1678. ]
  1679. });
  1680. $(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
  1681. setTimeout(() => {
  1682. const $bEdit = $('.repository.wiki.new .previewtabs a[data-tab="write"]');
  1683. const $bPrev = $(
  1684. '.repository.wiki.new .previewtabs a[data-tab="preview"]'
  1685. );
  1686. const $toolbar = $('.editor-toolbar');
  1687. const $bPreview = $('.editor-toolbar a.fa-eye');
  1688. const $bSideBySide = $('.editor-toolbar a.fa-columns');
  1689. $bEdit.on('click', () => {
  1690. if ($toolbar.hasClass('disabled-for-preview')) {
  1691. $bPreview.trigger('click');
  1692. }
  1693. });
  1694. $bPrev.on('click', () => {
  1695. if (!$toolbar.hasClass('disabled-for-preview')) {
  1696. $bPreview.trigger('click');
  1697. }
  1698. });
  1699. $bPreview.on('click', () => {
  1700. setTimeout(() => {
  1701. if ($toolbar.hasClass('disabled-for-preview')) {
  1702. if ($bEdit.hasClass('active')) {
  1703. $bEdit.removeClass('active');
  1704. }
  1705. if (!$bPrev.hasClass('active')) {
  1706. $bPrev.addClass('active');
  1707. }
  1708. } else {
  1709. if (!$bEdit.hasClass('active')) {
  1710. $bEdit.addClass('active');
  1711. }
  1712. if ($bPrev.hasClass('active')) {
  1713. $bPrev.removeClass('active');
  1714. }
  1715. }
  1716. }, 0);
  1717. });
  1718. $bSideBySide.on('click', () => {
  1719. sideBySideChanges = 10;
  1720. });
  1721. }, 0);
  1722. }
  1723. }
  1724. // Adding function to get the cursor position in a text field to jQuery object.
  1725. $.fn.getCursorPosition = function () {
  1726. const el = $(this).get(0);
  1727. let pos = 0;
  1728. if ('selectionStart' in el) {
  1729. pos = el.selectionStart;
  1730. } else if ('selection' in document) {
  1731. el.focus();
  1732. const Sel = document.selection.createRange();
  1733. const SelLength = document.selection.createRange().text.length;
  1734. Sel.moveStart('character', -el.value.length);
  1735. pos = Sel.text.length - SelLength;
  1736. }
  1737. return pos;
  1738. };
  1739. function setCommentSimpleMDE($editArea) {
  1740. const simplemde = new SimpleMDE({
  1741. autoDownloadFontAwesome: false,
  1742. element: $editArea[0],
  1743. forceSync: true,
  1744. renderingConfig: {
  1745. singleLineBreaks: false
  1746. },
  1747. indentWithTabs: false,
  1748. tabSize: 4,
  1749. spellChecker: false,
  1750. toolbar: [
  1751. 'bold',
  1752. 'italic',
  1753. 'strikethrough',
  1754. '|',
  1755. 'heading-1',
  1756. 'heading-2',
  1757. 'heading-3',
  1758. 'heading-bigger',
  1759. 'heading-smaller',
  1760. '|',
  1761. 'code',
  1762. 'quote',
  1763. '|',
  1764. 'unordered-list',
  1765. 'ordered-list',
  1766. '|',
  1767. 'link',
  1768. 'image',
  1769. 'table',
  1770. 'horizontal-rule',
  1771. '|',
  1772. 'clean-block',
  1773. '|',
  1774. {
  1775. name: 'revert-to-textarea',
  1776. action(e) {
  1777. e.toTextArea();
  1778. },
  1779. className: 'fa fa-file',
  1780. title: 'Revert to simple textarea'
  1781. }
  1782. ]
  1783. });
  1784. $(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
  1785. simplemde.codemirror.setOption('extraKeys', {
  1786. Enter: () => {
  1787. if (!(issuesTribute.isActive || emojiTribute.isActive)) {
  1788. return CodeMirror.Pass;
  1789. }
  1790. },
  1791. Backspace: (cm) => {
  1792. if (cm.getInputField().trigger) {
  1793. cm.getInputField().trigger('input');
  1794. }
  1795. cm.execCommand('delCharBefore');
  1796. }
  1797. });
  1798. issuesTribute.attach(simplemde.codemirror.getInputField());
  1799. emojiTribute.attach(simplemde.codemirror.getInputField());
  1800. return simplemde;
  1801. }
  1802. async function initEditor() {
  1803. $('.js-quick-pull-choice-option').on('change', function () {
  1804. if ($(this).val() === 'commit-to-new-branch') {
  1805. $('.quick-pull-branch-name').show();
  1806. $('.quick-pull-branch-name input').prop('required', true);
  1807. } else {
  1808. $('.quick-pull-branch-name').hide();
  1809. $('.quick-pull-branch-name input').prop('required', false);
  1810. }
  1811. $('#commit-button').text($(this).attr('button_text'));
  1812. });
  1813. const $editFilename = $('#file-name');
  1814. $editFilename
  1815. .on('keyup', function (e) {
  1816. const $section = $('.breadcrumb span.section');
  1817. const $divider = $('.breadcrumb div.divider');
  1818. let value;
  1819. let parts;
  1820. if (e.keyCode === 8) {
  1821. if ($(this).getCursorPosition() === 0) {
  1822. if ($section.length > 0) {
  1823. value = $section
  1824. .last()
  1825. .find('a')
  1826. .text();
  1827. $(this).val(value + $(this).val());
  1828. $(this)[0].setSelectionRange(value.length, value.length);
  1829. $section.last().remove();
  1830. $divider.last().remove();
  1831. }
  1832. }
  1833. }
  1834. if (e.keyCode === 191) {
  1835. parts = $(this)
  1836. .val()
  1837. .split('/');
  1838. for (let i = 0; i < parts.length; ++i) {
  1839. value = parts[i];
  1840. if (i < parts.length - 1) {
  1841. if (value.length) {
  1842. $(
  1843. `<span class="section"><a href="#">${value}</a></span>`
  1844. ).insertBefore($(this));
  1845. $('<div class="divider"> / </div>').insertBefore($(this));
  1846. }
  1847. } else {
  1848. $(this).val(value);
  1849. }
  1850. $(this)[0].setSelectionRange(0, 0);
  1851. }
  1852. }
  1853. parts = [];
  1854. $('.breadcrumb span.section').each(function () {
  1855. const element = $(this);
  1856. if (element.find('a').length) {
  1857. parts.push(element.find('a').text());
  1858. } else {
  1859. parts.push(element.text());
  1860. }
  1861. });
  1862. if ($(this).val()) parts.push($(this).val());
  1863. $('#tree_path').val(parts.join('/'));
  1864. })
  1865. .trigger('keyup');
  1866. const $editArea = $('.repository.editor textarea#edit_area');
  1867. if (!$editArea.length) return;
  1868. await createCodeEditor($editArea[0], $editFilename[0], previewFileModes);
  1869. // Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
  1870. // to enable or disable the commit button
  1871. const $commitButton = $('#commit-button');
  1872. const $editForm = $('.ui.edit.form');
  1873. const dirtyFileClass = 'dirty-file';
  1874. // Disabling the button at the start
  1875. $commitButton.prop('disabled', true);
  1876. // Registering a custom listener for the file path and the file content
  1877. $editForm.areYouSure({
  1878. silent: true,
  1879. dirtyClass: dirtyFileClass,
  1880. fieldSelector: ':input:not(.commit-form-wrapper :input)',
  1881. change() {
  1882. const dirty = $(this).hasClass(dirtyFileClass);
  1883. $commitButton.prop('disabled', !dirty);
  1884. }
  1885. });
  1886. $commitButton.on('click', (event) => {
  1887. // A modal which asks if an empty file should be committed
  1888. if ($editArea.val().length === 0) {
  1889. $('#edit-empty-content-modal')
  1890. .modal({
  1891. onApprove() {
  1892. $('.edit.form').trigger('submit');
  1893. }
  1894. })
  1895. .modal('show');
  1896. event.preventDefault();
  1897. }
  1898. });
  1899. }
  1900. function initOrganization() {
  1901. if ($('.organization').length === 0) {
  1902. return;
  1903. }
  1904. // Options
  1905. if ($('.organization.settings.options').length > 0) {
  1906. $('#org_name').on('keyup', function () {
  1907. const $prompt = $('#org-name-change-prompt');
  1908. if (
  1909. $(this)
  1910. .val()
  1911. .toString()
  1912. .toLowerCase() !==
  1913. $(this)
  1914. .data('org-name')
  1915. .toString()
  1916. .toLowerCase()
  1917. ) {
  1918. $prompt.show();
  1919. } else {
  1920. $prompt.hide();
  1921. }
  1922. });
  1923. }
  1924. // Labels
  1925. if ($('.organization.settings.labels').length > 0) {
  1926. initLabelEdit();
  1927. }
  1928. }
  1929. function initUserSettings() {
  1930. // Options
  1931. if ($('.user.settings.profile').length > 0) {
  1932. $('#username').on('keyup', function () {
  1933. const $prompt = $('#name-change-prompt');
  1934. if (
  1935. $(this)
  1936. .val()
  1937. .toString()
  1938. .toLowerCase() !==
  1939. $(this)
  1940. .data('name')
  1941. .toString()
  1942. .toLowerCase()
  1943. ) {
  1944. $prompt.show();
  1945. } else {
  1946. $prompt.hide();
  1947. }
  1948. });
  1949. }
  1950. }
  1951. function initGithook() {
  1952. if ($('.edit.githook').length === 0) {
  1953. return;
  1954. }
  1955. CodeMirror.autoLoadMode(
  1956. CodeMirror.fromTextArea($('#content')[0], {
  1957. lineNumbers: true,
  1958. mode: 'shell'
  1959. }),
  1960. 'shell'
  1961. );
  1962. }
  1963. function initWebhook() {
  1964. if ($('.new.webhook').length === 0) {
  1965. return;
  1966. }
  1967. $('.events.checkbox input').on('change', function () {
  1968. if ($(this).is(':checked')) {
  1969. $('.events.fields').show();
  1970. }
  1971. });
  1972. $('.non-events.checkbox input').on('change', function () {
  1973. if ($(this).is(':checked')) {
  1974. $('.events.fields').hide();
  1975. }
  1976. });
  1977. const updateContentType = function () {
  1978. const visible = $('#http_method').val() === 'POST';
  1979. $('#content_type')
  1980. .parent()
  1981. .parent()
  1982. [visible ? 'show' : 'hide']();
  1983. };
  1984. updateContentType();
  1985. $('#http_method').on('change', () => {
  1986. updateContentType();
  1987. });
  1988. // Test delivery
  1989. $('#test-delivery').on('click', function () {
  1990. const $this = $(this);
  1991. $this.addClass('loading disabled');
  1992. $.post($this.data('link'), {
  1993. _csrf: csrf
  1994. }).done(
  1995. setTimeout(() => {
  1996. window.location.href = $this.data('redirect');
  1997. }, 5000)
  1998. );
  1999. });
  2000. }
  2001. function initAdmin() {
  2002. if ($('.admin').length === 0) {
  2003. return;
  2004. }
  2005. // New user
  2006. if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) {
  2007. $('#login_type').on('change', function () {
  2008. if (
  2009. $(this)
  2010. .val()
  2011. .substring(0, 1) === '0'
  2012. ) {
  2013. $('#login_name').removeAttr('required');
  2014. $('.non-local').hide();
  2015. $('.local').show();
  2016. $('#user_name').focus();
  2017. if ($(this).data('password') === 'required') {
  2018. $('#password').attr('required', 'required');
  2019. }
  2020. } else {
  2021. $('#login_name').attr('required', 'required');
  2022. $('.non-local').show();
  2023. $('.local').hide();
  2024. $('#login_name').focus();
  2025. $('#password').removeAttr('required');
  2026. }
  2027. });
  2028. }
  2029. function onSecurityProtocolChange() {
  2030. if ($('#security_protocol').val() > 0) {
  2031. $('.has-tls').show();
  2032. } else {
  2033. $('.has-tls').hide();
  2034. }
  2035. }
  2036. function onUsePagedSearchChange() {
  2037. if ($('#use_paged_search').prop('checked')) {
  2038. $('.search-page-size')
  2039. .show()
  2040. .find('input')
  2041. .attr('required', 'required');
  2042. } else {
  2043. $('.search-page-size')
  2044. .hide()
  2045. .find('input')
  2046. .removeAttr('required');
  2047. }
  2048. }
  2049. function onOAuth2Change() {
  2050. $('.open_id_connect_auto_discovery_url, .oauth2_use_custom_url').hide();
  2051. $('.open_id_connect_auto_discovery_url input[required]').removeAttr(
  2052. 'required'
  2053. );
  2054. const provider = $('#oauth2_provider').val();
  2055. switch (provider) {
  2056. case 'github':
  2057. case 'gitlab':
  2058. case 'gitea':
  2059. case 'nextcloud':
  2060. $('.oauth2_use_custom_url').show();
  2061. break;
  2062. case 'openidConnect':
  2063. $('.open_id_connect_auto_discovery_url input').attr(
  2064. 'required',
  2065. 'required'
  2066. );
  2067. $('.open_id_connect_auto_discovery_url').show();
  2068. break;
  2069. }
  2070. onOAuth2UseCustomURLChange();
  2071. }
  2072. function onOAuth2UseCustomURLChange() {
  2073. const provider = $('#oauth2_provider').val();
  2074. $('.oauth2_use_custom_url_field').hide();
  2075. $('.oauth2_use_custom_url_field input[required]').removeAttr('required');
  2076. if ($('#oauth2_use_custom_url').is(':checked')) {
  2077. $('#oauth2_token_url').val($(`#${provider}_token_url`).val());
  2078. $('#oauth2_auth_url').val($(`#${provider}_auth_url`).val());
  2079. $('#oauth2_profile_url').val($(`#${provider}_profile_url`).val());
  2080. $('#oauth2_email_url').val($(`#${provider}_email_url`).val());
  2081. switch (provider) {
  2082. case 'github':
  2083. $(
  2084. '.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input, .oauth2_email_url input'
  2085. ).attr('required', 'required');
  2086. $(
  2087. '.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url, .oauth2_email_url'
  2088. ).show();
  2089. break;
  2090. case 'nextcloud':
  2091. case 'gitea':
  2092. case 'gitlab':
  2093. $(
  2094. '.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input'
  2095. ).attr('required', 'required');
  2096. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url').show();
  2097. $('#oauth2_email_url').val('');
  2098. break;
  2099. }
  2100. }
  2101. }
  2102. // New authentication
  2103. if ($('.admin.new.authentication').length > 0) {
  2104. $('#auth_type').on('change', function () {
  2105. $(
  2106. '.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls, .search-page-size, .sspi'
  2107. ).hide();
  2108. $(
  2109. '.ldap input[required], .binddnrequired input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required], .sspi input[required]'
  2110. ).removeAttr('required');
  2111. $('.binddnrequired').removeClass('required');
  2112. const authType = $(this).val();
  2113. switch (authType) {
  2114. case '2': // LDAP
  2115. $('.ldap').show();
  2116. $('.binddnrequired input, .ldap div.required:not(.dldap) input').attr(
  2117. 'required',
  2118. 'required'
  2119. );
  2120. $('.binddnrequired').addClass('required');
  2121. break;
  2122. case '3': // SMTP
  2123. $('.smtp').show();
  2124. $('.has-tls').show();
  2125. $('.smtp div.required input, .has-tls').attr('required', 'required');
  2126. break;
  2127. case '4': // PAM
  2128. $('.pam').show();
  2129. $('.pam input').attr('required', 'required');
  2130. break;
  2131. case '5': // LDAP
  2132. $('.dldap').show();
  2133. $('.dldap div.required:not(.ldap) input').attr(
  2134. 'required',
  2135. 'required'
  2136. );
  2137. break;
  2138. case '6': // OAuth2
  2139. $('.oauth2').show();
  2140. $(
  2141. '.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input'
  2142. ).attr('required', 'required');
  2143. onOAuth2Change();
  2144. break;
  2145. case '7': // SSPI
  2146. $('.sspi').show();
  2147. $('.sspi div.required input').attr('required', 'required');
  2148. break;
  2149. }
  2150. if (authType === '2' || authType === '5') {
  2151. onSecurityProtocolChange();
  2152. }
  2153. if (authType === '2') {
  2154. onUsePagedSearchChange();
  2155. }
  2156. });
  2157. $('#auth_type').trigger('change');
  2158. $('#security_protocol').on('change', onSecurityProtocolChange);
  2159. $('#use_paged_search').on('change', onUsePagedSearchChange);
  2160. $('#oauth2_provider').on('change', onOAuth2Change);
  2161. $('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
  2162. }
  2163. // Edit authentication
  2164. if ($('.admin.edit.authentication').length > 0) {
  2165. const authType = $('#auth_type').val();
  2166. if (authType === '2' || authType === '5') {
  2167. $('#security_protocol').on('change', onSecurityProtocolChange);
  2168. if (authType === '2') {
  2169. $('#use_paged_search').on('change', onUsePagedSearchChange);
  2170. }
  2171. } else if (authType === '6') {
  2172. $('#oauth2_provider').on('change', onOAuth2Change);
  2173. $('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
  2174. onOAuth2Change();
  2175. }
  2176. }
  2177. // Notice
  2178. if ($('.admin.notice')) {
  2179. const $detailModal = $('#detail-modal');
  2180. // Attach view detail modals
  2181. $('.view-detail').on('click', function () {
  2182. $detailModal.find('.content pre').text($(this).data('content'));
  2183. $detailModal.modal('show');
  2184. return false;
  2185. });
  2186. // Select actions
  2187. const $checkboxes = $('.select.table .ui.checkbox');
  2188. $('.select.action').on('click', function () {
  2189. switch ($(this).data('action')) {
  2190. case 'select-all':
  2191. $checkboxes.checkbox('check');
  2192. break;
  2193. case 'deselect-all':
  2194. $checkboxes.checkbox('uncheck');
  2195. break;
  2196. case 'inverse':
  2197. $checkboxes.checkbox('toggle');
  2198. break;
  2199. }
  2200. });
  2201. $('#delete-selection').on('click', function () {
  2202. const $this = $(this);
  2203. $this.addClass('loading disabled');
  2204. const ids = [];
  2205. $checkboxes.each(function () {
  2206. if ($(this).checkbox('is checked')) {
  2207. ids.push($(this).data('id'));
  2208. }
  2209. });
  2210. $.post($this.data('link'), {
  2211. _csrf: csrf,
  2212. ids
  2213. }).done(() => {
  2214. window.location.href = $this.data('redirect');
  2215. });
  2216. });
  2217. }
  2218. }
  2219. function buttonsClickOnEnter() {
  2220. $('.ui.button').on('keypress', function (e) {
  2221. if (e.keyCode === 13 || e.keyCode === 32) {
  2222. // enter key or space bar
  2223. $(this).trigger('click');
  2224. }
  2225. });
  2226. }
  2227. function searchUsers() {
  2228. const $searchUserBox = $('#search-user-box');
  2229. $searchUserBox.search({
  2230. minCharacters: 2,
  2231. apiSettings: {
  2232. url: `${AppSubUrl}/api/v1/users/search?q={query}`,
  2233. onResponse(response) {
  2234. const items = [];
  2235. $.each(response.data, (_i, item) => {
  2236. let title = item.login;
  2237. if (item.full_name && item.full_name.length > 0) {
  2238. title += ` (${htmlEncode(item.full_name)})`;
  2239. }
  2240. items.push({
  2241. title,
  2242. image: item.avatar_url
  2243. });
  2244. });
  2245. return {results: items};
  2246. }
  2247. },
  2248. searchFields: ['login', 'full_name'],
  2249. showNoResults: false
  2250. });
  2251. }
  2252. function searchTeams() {
  2253. const $searchTeamBox = $('#search-team-box');
  2254. $searchTeamBox.search({
  2255. minCharacters: 2,
  2256. apiSettings: {
  2257. url: `${AppSubUrl}/api/v1/orgs/${$searchTeamBox.data(
  2258. 'org'
  2259. )}/teams/search?q={query}`,
  2260. headers: {'X-Csrf-Token': csrf},
  2261. onResponse(response) {
  2262. const items = [];
  2263. $.each(response.data, (_i, item) => {
  2264. const title = `${item.name} (${item.permission} access)`;
  2265. items.push({
  2266. title
  2267. });
  2268. });
  2269. return {results: items};
  2270. }
  2271. },
  2272. searchFields: ['name', 'description'],
  2273. showNoResults: false
  2274. });
  2275. }
  2276. function searchRepositories() {
  2277. const $searchRepoBox = $('#search-repo-box');
  2278. $searchRepoBox.search({
  2279. minCharacters: 2,
  2280. apiSettings: {
  2281. url: `${AppSubUrl}/api/v1/repos/search?q={query}&uid=${$searchRepoBox.data(
  2282. 'uid'
  2283. )}`,
  2284. onResponse(response) {
  2285. const items = [];
  2286. $.each(response.data, (_i, item) => {
  2287. items.push({
  2288. title: item.full_display_name.split('/')[1],
  2289. description: item.full_display_name
  2290. });
  2291. });
  2292. return {results: items};
  2293. }
  2294. },
  2295. searchFields: ['full_name'],
  2296. showNoResults: false
  2297. });
  2298. }
  2299. function initCodeView() {
  2300. if ($('.code-view .linenums').length > 0) {
  2301. $(document).on('click', '.lines-num span', function (e) {
  2302. const $select = $(this);
  2303. const $list = $select
  2304. .parent()
  2305. .siblings('.lines-code')
  2306. .find('ol.linenums > li');
  2307. selectRange(
  2308. $list,
  2309. $list.filter(`[rel=${$select.attr('id')}]`),
  2310. e.shiftKey ? $list.filter('.active').eq(0) : null
  2311. );
  2312. deSelect();
  2313. });
  2314. $(window)
  2315. .on('hashchange', () => {
  2316. let m = window.location.hash.match(/^#(L\d+)-(L\d+)$/);
  2317. const $list = $('.code-view ol.linenums > li');
  2318. let $first;
  2319. if (m) {
  2320. $first = $list.filter(`.${m[1]}`);
  2321. selectRange($list, $first, $list.filter(`.${m[2]}`));
  2322. $('html, body').scrollTop($first.offset().top - 200);
  2323. return;
  2324. }
  2325. m = window.location.hash.match(/^#(L|n)(\d+)$/);
  2326. if (m) {
  2327. $first = $list.filter(`.L${m[2]}`);
  2328. selectRange($list, $first);
  2329. $('html, body').scrollTop($first.offset().top - 200);
  2330. }
  2331. })
  2332. .trigger('hashchange');
  2333. }
  2334. $('.fold-code').on('click', ({target}) => {
  2335. const box = target.closest('.file-content');
  2336. const folded = box.dataset.folded !== 'true';
  2337. target.classList.add(`fa-chevron-${folded ? 'right' : 'down'}`);
  2338. target.classList.remove(`fa-chevron-${folded ? 'down' : 'right'}`);
  2339. box.dataset.folded = String(folded);
  2340. });
  2341. function insertBlobExcerpt(e) {
  2342. const $blob = $(e.target);
  2343. const $row = $blob.parent().parent();
  2344. $.get(
  2345. `${$blob.data('url')}?${$blob.data('query')}&anchor=${$blob.data(
  2346. 'anchor'
  2347. )}`,
  2348. (blob) => {
  2349. $row.replaceWith(blob);
  2350. $(`[data-anchor="${$blob.data('anchor')}"]`).on('click', (e) => {
  2351. insertBlobExcerpt(e);
  2352. });
  2353. $('.diff-detail-box.ui.sticky').sticky();
  2354. }
  2355. );
  2356. }
  2357. $('.ui.blob-excerpt').on('click', (e) => {
  2358. insertBlobExcerpt(e);
  2359. });
  2360. }
  2361. function initU2FAuth() {
  2362. if ($('#wait-for-key').length === 0) {
  2363. return;
  2364. }
  2365. u2fApi
  2366. .ensureSupport()
  2367. .then(() => {
  2368. $.getJSON(`${AppSubUrl}/user/u2f/challenge`).done((req) => {
  2369. u2fApi
  2370. .sign(req.appId, req.challenge, req.registeredKeys, 30)
  2371. .then(u2fSigned)
  2372. .catch((err) => {
  2373. if (err === undefined) {
  2374. u2fError(1);
  2375. return;
  2376. }
  2377. u2fError(err.metaData.code);
  2378. });
  2379. });
  2380. })
  2381. .catch(() => {
  2382. // Fallback in case browser do not support U2F
  2383. window.location.href = `${AppSubUrl}/user/two_factor`;
  2384. });
  2385. }
  2386. function u2fSigned(resp) {
  2387. $.ajax({
  2388. url: `${AppSubUrl}/user/u2f/sign`,
  2389. type: 'POST',
  2390. headers: {'X-Csrf-Token': csrf},
  2391. data: JSON.stringify(resp),
  2392. contentType: 'application/json; charset=utf-8'
  2393. })
  2394. .done((res) => {
  2395. window.location.replace(res);
  2396. })
  2397. .fail(() => {
  2398. u2fError(1);
  2399. });
  2400. }
  2401. function u2fRegistered(resp) {
  2402. if (checkError(resp)) {
  2403. return;
  2404. }
  2405. $.ajax({
  2406. url: `${AppSubUrl}/user/settings/security/u2f/register`,
  2407. type: 'POST',
  2408. headers: {'X-Csrf-Token': csrf},
  2409. data: JSON.stringify(resp),
  2410. contentType: 'application/json; charset=utf-8',
  2411. success() {
  2412. reload();
  2413. },
  2414. fail() {
  2415. u2fError(1);
  2416. }
  2417. });
  2418. }
  2419. function checkError(resp) {
  2420. if (!('errorCode' in resp)) {
  2421. return false;
  2422. }
  2423. if (resp.errorCode === 0) {
  2424. return false;
  2425. }
  2426. u2fError(resp.errorCode);
  2427. return true;
  2428. }
  2429. function u2fError(errorType) {
  2430. const u2fErrors = {
  2431. browser: $('#unsupported-browser'),
  2432. 1: $('#u2f-error-1'),
  2433. 2: $('#u2f-error-2'),
  2434. 3: $('#u2f-error-3'),
  2435. 4: $('#u2f-error-4'),
  2436. 5: $('.u2f-error-5')
  2437. };
  2438. u2fErrors[errorType].removeClass('hide');
  2439. Object.keys(u2fErrors).forEach((type) => {
  2440. if (type !== errorType) {
  2441. u2fErrors[type].addClass('hide');
  2442. }
  2443. });
  2444. $('#u2f-error').modal('show');
  2445. }
  2446. function initU2FRegister() {
  2447. $('#register-device').modal({allowMultiple: false});
  2448. $('#u2f-error').modal({allowMultiple: false});
  2449. $('#register-security-key').on('click', (e) => {
  2450. e.preventDefault();
  2451. u2fApi
  2452. .ensureSupport()
  2453. .then(u2fRegisterRequest)
  2454. .catch(() => {
  2455. u2fError('browser');
  2456. });
  2457. });
  2458. }
  2459. function u2fRegisterRequest() {
  2460. $.post(`${AppSubUrl}/user/settings/security/u2f/request_register`, {
  2461. _csrf: csrf,
  2462. name: $('#nickname').val()
  2463. })
  2464. .done((req) => {
  2465. $('#nickname')
  2466. .closest('div.field')
  2467. .removeClass('error');
  2468. $('#register-device').modal('show');
  2469. if (req.registeredKeys === null) {
  2470. req.registeredKeys = [];
  2471. }
  2472. u2fApi
  2473. .register(req.appId, req.registerRequests, req.registeredKeys, 30)
  2474. .then(u2fRegistered)
  2475. .catch((reason) => {
  2476. if (reason === undefined) {
  2477. u2fError(1);
  2478. return;
  2479. }
  2480. u2fError(reason.metaData.code);
  2481. });
  2482. })
  2483. .fail((xhr) => {
  2484. if (xhr.status === 409) {
  2485. $('#nickname')
  2486. .closest('div.field')
  2487. .addClass('error');
  2488. }
  2489. });
  2490. }
  2491. function initWipTitle() {
  2492. $('.title_wip_desc > a').on('click', (e) => {
  2493. e.preventDefault();
  2494. const $issueTitle = $('#issue_title');
  2495. $issueTitle.focus();
  2496. const value = $issueTitle
  2497. .val()
  2498. .trim()
  2499. .toUpperCase();
  2500. for (const i in wipPrefixes) {
  2501. if (value.startsWith(wipPrefixes[i].toUpperCase())) {
  2502. return;
  2503. }
  2504. }
  2505. $issueTitle.val(`${wipPrefixes[0]} ${$issueTitle.val()}`);
  2506. });
  2507. }
  2508. function initTemplateSearch() {
  2509. const $repoTemplate = $('#repo_template');
  2510. const checkTemplate = function () {
  2511. const $templateUnits = $('#template_units');
  2512. const $nonTemplate = $('#non_template');
  2513. if ($repoTemplate.val() !== '' && $repoTemplate.val() !== '0') {
  2514. $templateUnits.show();
  2515. $nonTemplate.hide();
  2516. } else {
  2517. $templateUnits.hide();
  2518. $nonTemplate.show();
  2519. }
  2520. };
  2521. $repoTemplate.on('change', checkTemplate);
  2522. checkTemplate();
  2523. const changeOwner = function () {
  2524. $('#repo_template_search').dropdown({
  2525. apiSettings: {
  2526. url: `${AppSubUrl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$(
  2527. '#uid'
  2528. ).val()}`,
  2529. onResponse(response) {
  2530. const filteredResponse = {success: true, results: []};
  2531. filteredResponse.results.push({
  2532. name: '',
  2533. value: ''
  2534. });
  2535. // Parse the response from the api to work with our dropdown
  2536. $.each(response.data, (_r, repo) => {
  2537. filteredResponse.results.push({
  2538. name: htmlEncode(repo.full_display_name),
  2539. value: repo.id
  2540. });
  2541. });
  2542. return filteredResponse;
  2543. },
  2544. cache: false
  2545. },
  2546. fullTextSearch: true
  2547. });
  2548. };
  2549. $('#uid').on('change', changeOwner);
  2550. changeOwner();
  2551. }
  2552. $(document).ready(async () => {
  2553. // Show exact time
  2554. $('.time-since').each(function () {
  2555. $(this)
  2556. .addClass('poping up')
  2557. .attr('data-content', $(this).attr('title'))
  2558. .attr('data-variation', 'inverted tiny')
  2559. .attr('title', '');
  2560. });
  2561. // Semantic UI modules.
  2562. $('.dropdown:not(.custom)').dropdown();
  2563. $('.jump.dropdown').dropdown({
  2564. action: 'hide',
  2565. onShow() {
  2566. $('.poping.up').popup('hide');
  2567. }
  2568. });
  2569. $('.slide.up.dropdown').dropdown({
  2570. transition: 'slide up'
  2571. });
  2572. $('.upward.dropdown').dropdown({
  2573. direction: 'upward'
  2574. });
  2575. $('.ui.accordion').accordion();
  2576. $('.ui.checkbox').checkbox();
  2577. $('.ui.progress').progress({
  2578. showActivity: false
  2579. });
  2580. $('.poping.up').popup();
  2581. $('.top.menu .poping.up').popup({
  2582. onShow() {
  2583. if ($('.top.menu .menu.transition').hasClass('visible')) {
  2584. return false;
  2585. }
  2586. }
  2587. });
  2588. $('.tabular.menu .item').tab();
  2589. $('.tabable.menu .item').tab();
  2590. $('.toggle.button').on('click', function () {
  2591. $($(this).data('target')).slideToggle(100);
  2592. });
  2593. // make table <tr> element clickable like a link
  2594. $('tr[data-href]').on('click', function () {
  2595. window.location = $(this).data('href');
  2596. });
  2597. // make table <td> element clickable like a link
  2598. $('td[data-href]').click(function () {
  2599. window.location = $(this).data('href');
  2600. });
  2601. // Dropzone
  2602. const $dropzone = $('#dropzone');
  2603. if ($dropzone.length > 0) {
  2604. const filenameDict = {};
  2605. await createDropzone('#dropzone', {
  2606. url: $dropzone.data('upload-url'),
  2607. headers: {'X-Csrf-Token': csrf},
  2608. maxFiles: $dropzone.data('max-file'),
  2609. maxFilesize: $dropzone.data('max-size'),
  2610. acceptedFiles:
  2611. $dropzone.data('accepts') === '*/*' ? null : $dropzone.data('accepts'),
  2612. addRemoveLinks: true,
  2613. dictDefaultMessage: $dropzone.data('default-message'),
  2614. dictInvalidFileType: $dropzone.data('invalid-input-type'),
  2615. dictFileTooBig: $dropzone.data('file-too-big'),
  2616. dictRemoveFile: $dropzone.data('remove-file'),
  2617. init() {
  2618. this.on('success', (file, data) => {
  2619. filenameDict[file.name] = data.uuid;
  2620. const input = $(
  2621. `<input id="${data.uuid}" name="files" type="hidden">`
  2622. ).val(data.uuid);
  2623. $('.files').append(input);
  2624. });
  2625. this.on('removedfile', (file) => {
  2626. if (file.name in filenameDict) {
  2627. $(`#${filenameDict[file.name]}`).remove();
  2628. }
  2629. if ($dropzone.data('remove-url') && $dropzone.data('csrf')) {
  2630. $.post($dropzone.data('remove-url'), {
  2631. file: filenameDict[file.name],
  2632. _csrf: $dropzone.data('csrf')
  2633. });
  2634. }
  2635. });
  2636. }
  2637. });
  2638. }
  2639. // Helpers.
  2640. $('.delete-button').on('click', showDeletePopup);
  2641. $('.add-all-button').on('click', showAddAllPopup);
  2642. $('.link-action').on('click', linkAction);
  2643. $('.link-email-action').on('click', linkEmailAction);
  2644. $('.delete-branch-button').on('click', showDeletePopup);
  2645. $('.undo-button').on('click', function () {
  2646. const $this = $(this);
  2647. $.post($this.data('url'), {
  2648. _csrf: csrf,
  2649. id: $this.data('id')
  2650. }).done((data) => {
  2651. window.location.href = data.redirect;
  2652. });
  2653. });
  2654. $('.show-panel.button').on('click', function () {
  2655. $($(this).data('panel')).show();
  2656. });
  2657. $('.show-modal.button').on('click', function () {
  2658. $($(this).data('modal')).modal('show');
  2659. });
  2660. $('.delete-post.button').on('click', function () {
  2661. const $this = $(this);
  2662. $.post($this.data('request-url'), {
  2663. _csrf: csrf
  2664. }).done(() => {
  2665. window.location.href = $this.data('done-url');
  2666. });
  2667. });
  2668. // Set anchor.
  2669. $('.markdown').each(function () {
  2670. $(this)
  2671. .find('h1, h2, h3, h4, h5, h6')
  2672. .each(function () {
  2673. let node = $(this);
  2674. node = node.wrap('<div class="anchor-wrap"></div>');
  2675. node.append(
  2676. `<a class="anchor" href="#${encodeURIComponent(
  2677. node.attr('id')
  2678. )}">${svg('octicon-link', 16)}</a>`
  2679. );
  2680. });
  2681. });
  2682. $('.issue-checkbox').on('click', () => {
  2683. const numChecked = $('.issue-checkbox').children('input:checked').length;
  2684. if (numChecked > 0) {
  2685. $('#issue-filters').addClass('hide');
  2686. $('#issue-actions').removeClass('hide');
  2687. } else {
  2688. $('#issue-filters').removeClass('hide');
  2689. $('#issue-actions').addClass('hide');
  2690. }
  2691. });
  2692. $('.issue-action').on('click', function () {
  2693. let {action} = this.dataset;
  2694. let {elementId} = this.dataset;
  2695. const issueIDs = $('.issue-checkbox')
  2696. .children('input:checked')
  2697. .map(function () {
  2698. return this.dataset.issueId;
  2699. })
  2700. .get()
  2701. .join();
  2702. const {url} = this.dataset;
  2703. if (elementId === '0' && url.substr(-9) === '/assignee') {
  2704. elementId = '';
  2705. action = 'clear';
  2706. }
  2707. updateIssuesMeta(url, action, issueIDs, elementId, '').then(() => {
  2708. // NOTICE: This reset of checkbox state targets Firefox caching behaviour, as the checkboxes stay checked after reload
  2709. if (action === 'close' || action === 'open') {
  2710. // uncheck all checkboxes
  2711. $('.issue-checkbox input[type="checkbox"]').each((_, e) => {
  2712. e.checked = false;
  2713. });
  2714. }
  2715. reload();
  2716. });
  2717. });
  2718. // NOTICE: This event trigger targets Firefox caching behaviour, as the checkboxes stay checked after reload
  2719. // trigger ckecked event, if checkboxes are checked on load
  2720. $('.issue-checkbox input[type="checkbox"]:checked')
  2721. .first()
  2722. .each((_, e) => {
  2723. e.checked = false;
  2724. $(e).trigger('click');
  2725. });
  2726. $('.resolve-conversation').on('click', function (e) {
  2727. e.preventDefault();
  2728. const id = $(this).data('comment-id');
  2729. const action = $(this).data('action');
  2730. const url = $(this).data('update-url');
  2731. $.post(url, {
  2732. _csrf: csrf,
  2733. action,
  2734. comment_id: id
  2735. }).then(reload);
  2736. });
  2737. buttonsClickOnEnter();
  2738. searchUsers();
  2739. searchTeams();
  2740. searchRepositories();
  2741. initCommentForm();
  2742. initInstall();
  2743. initRepository();
  2744. initMigration();
  2745. initWikiForm();
  2746. initEditForm();
  2747. initEditor();
  2748. initOrganization();
  2749. initGithook();
  2750. initWebhook();
  2751. initAdmin();
  2752. initCodeView();
  2753. initVueApp();
  2754. initVueUploader();
  2755. initObsUploader();
  2756. initVueDataset();
  2757. initVueEditAbout();
  2758. initVueEditTopic();
  2759. initVueContributors();
  2760. initVueImages();
  2761. initVueModel();
  2762. initVueDataAnalysis();
  2763. initVueWxAutorize();
  2764. initTeamSettings();
  2765. initCtrlEnterSubmit();
  2766. initNavbarContentToggle();
  2767. // initTopicbar();vim
  2768. // closeTopicbar();
  2769. initU2FAuth();
  2770. initU2FRegister();
  2771. initIssueList();
  2772. initWipTitle();
  2773. initPullRequestReview();
  2774. initRepoStatusChecker();
  2775. initTemplateSearch();
  2776. initContextPopups();
  2777. initNotificationsTable();
  2778. initNotificationCount();
  2779. initTribute();
  2780. initDropDown();
  2781. initCloudrain();
  2782. // Repo clone url.
  2783. if ($('#repo-clone-url').length > 0) {
  2784. switch (localStorage.getItem('repo-clone-protocol')) {
  2785. case 'ssh':
  2786. if ($('#repo-clone-ssh').length === 0) {
  2787. $('#repo-clone-https').trigger('click');
  2788. }
  2789. break;
  2790. default:
  2791. $('#repo-clone-https').trigger('click');
  2792. break;
  2793. }
  2794. }
  2795. const routes = {
  2796. 'div.user.settings': initUserSettings,
  2797. 'div.repository.settings.collaboration': initRepositoryCollaboration
  2798. };
  2799. let selector;
  2800. for (selector in routes) {
  2801. if ($(selector).length > 0) {
  2802. routes[selector]();
  2803. break;
  2804. }
  2805. }
  2806. const $cloneAddr = $('#clone_addr');
  2807. $cloneAddr.on('change', () => {
  2808. const $repoName = $('#alias');
  2809. const $owner = $('#ownerDropdown div.text').attr("title")
  2810. const $urlAdd = location.href.split('/')[0] + '//' + location.href.split('/')[2]
  2811. if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) {
  2812. // Only modify if repo_name input is blank
  2813. const repoValue = $cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]
  2814. $repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
  2815. $.get(`${window.config.AppSubUrl}/repo/check_name?q=${repoValue}&owner=${$owner}`,(data)=>{
  2816. const repo_name = data.name
  2817. $('#repo_name').val(repo_name)
  2818. repo_name && $('#repo_name').parent().removeClass('error')
  2819. $('#repoAdress').css("display","flex")
  2820. $('#repoAdress span').text($urlAdd+'/'+$owner+'/'+$('#repo_name').val()+'.git')
  2821. $('#repo_name').attr("placeholder","")
  2822. })
  2823. }
  2824. });
  2825. // parallel init of lazy-loaded features
  2826. await Promise.all([
  2827. highlight(document.querySelectorAll('pre code')),
  2828. initGitGraph(),
  2829. initClipboard(),
  2830. initUserHeatmap()
  2831. ]);
  2832. });
  2833. function changeHash(hash) {
  2834. if (window.history.pushState) {
  2835. window.history.pushState(null, null, hash);
  2836. } else {
  2837. window.location.hash = hash;
  2838. }
  2839. }
  2840. function deSelect() {
  2841. if (window.getSelection) {
  2842. window.getSelection().removeAllRanges();
  2843. } else {
  2844. document.selection.empty();
  2845. }
  2846. }
  2847. function selectRange($list, $select, $from) {
  2848. $list.removeClass('active');
  2849. if ($from) {
  2850. let a = parseInt($select.attr('rel').substr(1));
  2851. let b = parseInt($from.attr('rel').substr(1));
  2852. let c;
  2853. if (a !== b) {
  2854. if (a > b) {
  2855. c = a;
  2856. a = b;
  2857. b = c;
  2858. }
  2859. const classes = [];
  2860. for (let i = a; i <= b; i++) {
  2861. classes.push(`.L${i}`);
  2862. }
  2863. $list.filter(classes.join(',')).addClass('active');
  2864. changeHash(`#L${a}-L${b}`);
  2865. return;
  2866. }
  2867. }
  2868. $select.addClass('active');
  2869. changeHash(`#${$select.attr('rel')}`);
  2870. }
  2871. $(() => {
  2872. // Warn users that try to leave a page after entering data into a form.
  2873. // Except on sign-in pages, and for forms marked as 'ignore-dirty'.
  2874. if ($('.user.signin').length === 0) {
  2875. $('form:not(.ignore-dirty)').areYouSure();
  2876. }
  2877. // Parse SSH Key
  2878. $('#ssh-key-content').on('change paste keyup', function () {
  2879. const arrays = $(this)
  2880. .val()
  2881. .split(' ');
  2882. const $title = $('#ssh-key-title');
  2883. if ($title.val() === '' && arrays.length === 3 && arrays[2] !== '') {
  2884. $title.val(arrays[2]);
  2885. }
  2886. });
  2887. });
  2888. function showDeletePopup() {
  2889. const $this = $(this);
  2890. let filter = '';
  2891. if ($this.attr('id')) {
  2892. filter += `#${$this.attr('id')}`;
  2893. }
  2894. const dialog = $(`.delete.modal${filter}`);
  2895. dialog.find('.name').text($this.data('name'));
  2896. dialog
  2897. .modal({
  2898. closable: false,
  2899. onApprove() {
  2900. if ($this.data('type') === 'form') {
  2901. $($this.data('form')).trigger('submit');
  2902. return;
  2903. }
  2904. $.post($this.data('url'), {
  2905. _csrf: csrf,
  2906. id: $this.data('id')
  2907. }).done((data) => {
  2908. window.location.href = data.redirect;
  2909. });
  2910. }
  2911. })
  2912. .modal('show');
  2913. return false;
  2914. }
  2915. function showAddAllPopup() {
  2916. const $this = $(this);
  2917. let filter = '';
  2918. if ($this.attr('id')) {
  2919. filter += `#${$this.attr('id')}`;
  2920. }
  2921. const dialog = $(`.addall.modal${filter}`);
  2922. dialog.find('.name').text($this.data('name'));
  2923. dialog
  2924. .modal({
  2925. closable: false,
  2926. onApprove() {
  2927. if ($this.data('type') === 'form') {
  2928. $($this.data('form')).trigger('submit');
  2929. return;
  2930. }
  2931. $.post($this.data('url'), {
  2932. _csrf: csrf,
  2933. id: $this.data('id')
  2934. }).done((data) => {
  2935. window.location.href = data.redirect;
  2936. });
  2937. }
  2938. })
  2939. .modal('show');
  2940. return false;
  2941. }
  2942. function linkAction(e) {
  2943. e.preventDefault();
  2944. const $this = $(this);
  2945. const redirect = $this.data('redirect');
  2946. $.post($this.data('url'), {
  2947. _csrf: csrf
  2948. }).done((data) => {
  2949. if (data.redirect) {
  2950. window.location.href = data.redirect;
  2951. } else if (redirect) {
  2952. window.location.href = redirect;
  2953. } else {
  2954. window.location.reload();
  2955. }
  2956. });
  2957. }
  2958. function linkEmailAction(e) {
  2959. const $this = $(this);
  2960. $('#form-uid').val($this.data('uid'));
  2961. $('#form-email').val($this.data('email'));
  2962. $('#form-primary').val($this.data('primary'));
  2963. $('#form-activate').val($this.data('activate'));
  2964. $('#form-uid').val($this.data('uid'));
  2965. $('#change-email-modal').modal('show');
  2966. e.preventDefault();
  2967. }
  2968. function initVueComponents() {
  2969. const vueDelimeters = ['${', '}'];
  2970. Vue.component('repo-search', {
  2971. delimiters: vueDelimeters,
  2972. props: {
  2973. searchLimit: {
  2974. type: Number,
  2975. default: 10
  2976. },
  2977. suburl: {
  2978. type: String,
  2979. required: true
  2980. },
  2981. uid: {
  2982. type: Number,
  2983. required: true
  2984. },
  2985. organizations: {
  2986. type: Array,
  2987. default: []
  2988. },
  2989. isOrganization: {
  2990. type: Boolean,
  2991. default: true
  2992. },
  2993. canCreateOrganization: {
  2994. type: Boolean,
  2995. default: false
  2996. },
  2997. organizationsTotalCount: {
  2998. type: Number,
  2999. default: 0
  3000. },
  3001. moreReposLink: {
  3002. type: String,
  3003. default: ''
  3004. }
  3005. },
  3006. data() {
  3007. const params = new URLSearchParams(window.location.search);
  3008. let tab = params.get('repo-search-tab');
  3009. if (!tab) {
  3010. tab = 'repos';
  3011. }
  3012. let reposFilter = params.get('repo-search-filter');
  3013. if (!reposFilter) {
  3014. reposFilter = 'all';
  3015. }
  3016. let privateFilter = params.get('repo-search-private');
  3017. if (!privateFilter) {
  3018. privateFilter = 'both';
  3019. }
  3020. let archivedFilter = params.get('repo-search-archived');
  3021. if (!archivedFilter) {
  3022. archivedFilter = 'unarchived';
  3023. }
  3024. let searchQuery = params.get('repo-search-query');
  3025. if (!searchQuery) {
  3026. searchQuery = '';
  3027. }
  3028. let page = 1;
  3029. try {
  3030. page = parseInt(params.get('repo-search-page'));
  3031. } catch {
  3032. // noop
  3033. }
  3034. if (!page) {
  3035. page = 1;
  3036. }
  3037. return {
  3038. tab,
  3039. repos: [],
  3040. reposTotalCount: 0,
  3041. reposFilter,
  3042. archivedFilter,
  3043. privateFilter,
  3044. page,
  3045. finalPage: 1,
  3046. searchQuery,
  3047. isLoading: false,
  3048. staticPrefix: StaticUrlPrefix,
  3049. counts: {},
  3050. repoTypes: {
  3051. all: {
  3052. searchMode: ''
  3053. },
  3054. forks: {
  3055. searchMode: 'fork'
  3056. },
  3057. mirrors: {
  3058. searchMode: 'mirror'
  3059. },
  3060. sources: {
  3061. searchMode: 'source'
  3062. },
  3063. collaborative: {
  3064. searchMode: 'collaborative'
  3065. }
  3066. }
  3067. };
  3068. },
  3069. computed: {
  3070. showMoreReposLink() {
  3071. return (
  3072. this.repos.length > 0 &&
  3073. this.repos.length <
  3074. this.counts[
  3075. `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`
  3076. ]
  3077. );
  3078. },
  3079. searchURL() {
  3080. return `${
  3081. this.suburl
  3082. }/api/v1/repos/search?sort=updated&order=desc&uid=${this.uid}&q=${
  3083. this.searchQuery
  3084. }&page=${this.page}&limit=${this.searchLimit}&mode=${
  3085. this.repoTypes[this.reposFilter].searchMode
  3086. }${this.reposFilter !== 'all' ? '&exclusive=1' : ''}${
  3087. this.archivedFilter === 'archived' ? '&archived=true' : ''
  3088. }${this.archivedFilter === 'unarchived' ? '&archived=false' : ''}${
  3089. this.privateFilter === 'private' ? '&onlyPrivate=true' : ''
  3090. }${this.privateFilter === 'public' ? '&private=false' : ''}`;
  3091. },
  3092. repoTypeCount() {
  3093. return this.counts[
  3094. `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`
  3095. ];
  3096. }
  3097. },
  3098. mounted() {
  3099. this.searchRepos(this.reposFilter);
  3100. $(this.$el)
  3101. .find('.poping.up')
  3102. .popup();
  3103. $(this.$el)
  3104. .find('.dropdown')
  3105. .dropdown();
  3106. this.setCheckboxes();
  3107. const self = this;
  3108. Vue.nextTick(() => {
  3109. self.$refs.search.focus();
  3110. });
  3111. },
  3112. methods: {
  3113. changeTab(t) {
  3114. this.tab = t;
  3115. this.updateHistory();
  3116. },
  3117. setCheckboxes() {
  3118. switch (this.archivedFilter) {
  3119. case 'unarchived':
  3120. $('#archivedFilterCheckbox').checkbox('set unchecked');
  3121. break;
  3122. case 'archived':
  3123. $('#archivedFilterCheckbox').checkbox('set checked');
  3124. break;
  3125. case 'both':
  3126. $('#archivedFilterCheckbox').checkbox('set indeterminate');
  3127. break;
  3128. default:
  3129. this.archivedFilter = 'unarchived';
  3130. $('#archivedFilterCheckbox').checkbox('set unchecked');
  3131. break;
  3132. }
  3133. switch (this.privateFilter) {
  3134. case 'public':
  3135. $('#privateFilterCheckbox').checkbox('set unchecked');
  3136. break;
  3137. case 'private':
  3138. $('#privateFilterCheckbox').checkbox('set checked');
  3139. break;
  3140. case 'both':
  3141. $('#privateFilterCheckbox').checkbox('set indeterminate');
  3142. break;
  3143. default:
  3144. this.privateFilter = 'both';
  3145. $('#privateFilterCheckbox').checkbox('set indeterminate');
  3146. break;
  3147. }
  3148. },
  3149. changeReposFilter(filter) {
  3150. this.reposFilter = filter;
  3151. this.repos = [];
  3152. this.page = 1;
  3153. Vue.set(
  3154. this.counts,
  3155. `${filter}:${this.archivedFilter}:${this.privateFilter}`,
  3156. 0
  3157. );
  3158. this.searchRepos();
  3159. },
  3160. updateHistory() {
  3161. const params = new URLSearchParams(window.location.search);
  3162. if (this.tab === 'repos') {
  3163. params.delete('repo-search-tab');
  3164. } else {
  3165. params.set('repo-search-tab', this.tab);
  3166. }
  3167. if (this.reposFilter === 'all') {
  3168. params.delete('repo-search-filter');
  3169. } else {
  3170. params.set('repo-search-filter', this.reposFilter);
  3171. }
  3172. if (this.privateFilter === 'both') {
  3173. params.delete('repo-search-private');
  3174. } else {
  3175. params.set('repo-search-private', this.privateFilter);
  3176. }
  3177. if (this.archivedFilter === 'unarchived') {
  3178. params.delete('repo-search-archived');
  3179. } else {
  3180. params.set('repo-search-archived', this.archivedFilter);
  3181. }
  3182. if (this.searchQuery === '') {
  3183. params.delete('repo-search-query');
  3184. } else {
  3185. params.set('repo-search-query', this.searchQuery);
  3186. }
  3187. if (this.page === 1) {
  3188. params.delete('repo-search-page');
  3189. } else {
  3190. params.set('repo-search-page', `${this.page}`);
  3191. }
  3192. window.history.replaceState({}, '', `?${params.toString()}`);
  3193. },
  3194. toggleArchivedFilter() {
  3195. switch (this.archivedFilter) {
  3196. case 'both':
  3197. this.archivedFilter = 'unarchived';
  3198. break;
  3199. case 'unarchived':
  3200. this.archivedFilter = 'archived';
  3201. break;
  3202. case 'archived':
  3203. this.archivedFilter = 'both';
  3204. break;
  3205. default:
  3206. this.archivedFilter = 'unarchived';
  3207. break;
  3208. }
  3209. this.page = 1;
  3210. this.repos = [];
  3211. this.setCheckboxes();
  3212. Vue.set(
  3213. this.counts,
  3214. `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`,
  3215. 0
  3216. );
  3217. this.searchRepos();
  3218. },
  3219. togglePrivateFilter() {
  3220. switch (this.privateFilter) {
  3221. case 'both':
  3222. this.privateFilter = 'public';
  3223. break;
  3224. case 'public':
  3225. this.privateFilter = 'private';
  3226. break;
  3227. case 'private':
  3228. this.privateFilter = 'both';
  3229. break;
  3230. default:
  3231. this.privateFilter = 'both';
  3232. break;
  3233. }
  3234. this.page = 1;
  3235. this.repos = [];
  3236. this.setCheckboxes();
  3237. Vue.set(
  3238. this.counts,
  3239. `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`,
  3240. 0
  3241. );
  3242. this.searchRepos();
  3243. },
  3244. changePage(page) {
  3245. this.page = page;
  3246. if (this.page > this.finalPage) {
  3247. this.page = this.finalPage;
  3248. }
  3249. if (this.page < 1) {
  3250. this.page = 1;
  3251. }
  3252. this.repos = [];
  3253. Vue.set(
  3254. this.counts,
  3255. `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`,
  3256. 0
  3257. );
  3258. this.searchRepos();
  3259. },
  3260. showArchivedRepo(repo) {
  3261. switch (this.archivedFilter) {
  3262. case 'both':
  3263. return true;
  3264. case 'unarchived':
  3265. return !repo.archived;
  3266. case 'archived':
  3267. return repo.archived;
  3268. default:
  3269. return !repo.archived;
  3270. }
  3271. },
  3272. showPrivateRepo(repo) {
  3273. switch (this.privateFilter) {
  3274. case 'both':
  3275. return true;
  3276. case 'public':
  3277. return !repo.private;
  3278. case 'private':
  3279. return repo.private;
  3280. default:
  3281. return true;
  3282. }
  3283. },
  3284. showFilteredRepo(repo) {
  3285. switch (this.reposFilter) {
  3286. case 'sources':
  3287. return repo.owner.id === this.uid && !repo.mirror && !repo.fork;
  3288. case 'forks':
  3289. return repo.owner.id === this.uid && !repo.mirror && repo.fork;
  3290. case 'mirrors':
  3291. return repo.mirror;
  3292. case 'collaborative':
  3293. return repo.owner.id !== this.uid && !repo.mirror;
  3294. default:
  3295. return true;
  3296. }
  3297. },
  3298. showRepo(repo) {
  3299. return (
  3300. this.showArchivedRepo(repo) &&
  3301. this.showPrivateRepo(repo) &&
  3302. this.showFilteredRepo(repo)
  3303. );
  3304. },
  3305. searchRepos() {
  3306. const self = this;
  3307. this.isLoading = true;
  3308. const searchedMode = this.repoTypes[this.reposFilter].searchMode;
  3309. const searchedURL = this.searchURL;
  3310. const searchedQuery = this.searchQuery;
  3311. $.getJSON(searchedURL, (result, _textStatus, request) => {
  3312. if (searchedURL === self.searchURL) {
  3313. self.repos = result.data;
  3314. const count = request.getResponseHeader('X-Total-Count');
  3315. if (
  3316. searchedQuery === '' &&
  3317. searchedMode === '' &&
  3318. self.archivedFilter === 'both'
  3319. ) {
  3320. self.reposTotalCount = count;
  3321. }
  3322. Vue.set(
  3323. self.counts,
  3324. `${self.reposFilter}:${self.archivedFilter}:${self.privateFilter}`,
  3325. count
  3326. );
  3327. self.finalPage = Math.floor(count / self.searchLimit) + 1;
  3328. self.updateHistory();
  3329. }
  3330. }).always(() => {
  3331. if (searchedURL === self.searchURL) {
  3332. self.isLoading = false;
  3333. }
  3334. });
  3335. },
  3336. repoClass(repo) {
  3337. if (repo.fork) {
  3338. return 'octicon-repo-forked';
  3339. }
  3340. if (repo.mirror) {
  3341. return 'octicon-repo-clone';
  3342. }
  3343. if (repo.template) {
  3344. return `octicon-repo-template${repo.private ? '-private' : ''}`;
  3345. }
  3346. if (repo.private) {
  3347. return 'octicon-lock';
  3348. }
  3349. return 'octicon-repo';
  3350. }
  3351. }
  3352. });
  3353. }
  3354. function initCtrlEnterSubmit() {
  3355. $('.js-quick-submit').on('keydown', function (e) {
  3356. if (
  3357. ((e.ctrlKey && !e.altKey) || e.metaKey) &&
  3358. (e.keyCode === 13 || e.keyCode === 10)
  3359. ) {
  3360. $(this)
  3361. .closest('form')
  3362. .trigger('submit');
  3363. }
  3364. });
  3365. }
  3366. function initVueApp() {
  3367. const el = document.getElementById('app');
  3368. if (!el) {
  3369. return;
  3370. }
  3371. initVueComponents();
  3372. new Vue({
  3373. delimiters: ['${', '}'],
  3374. el,
  3375. i18n,
  3376. data: {
  3377. page:parseInt(new URLSearchParams(window.location.search).get('page')),
  3378. searchLimit: Number(
  3379. (document.querySelector('meta[name=_search_limit]') || {}).content
  3380. ),
  3381. page:1,
  3382. suburl: AppSubUrl,
  3383. uid: Number(
  3384. (document.querySelector('meta[name=_context_uid]') || {}).content
  3385. ),
  3386. activityTopAuthors: window.ActivityTopAuthors || [],
  3387. localHref:''
  3388. },
  3389. components: {
  3390. ActivityTopAuthors
  3391. },
  3392. mounted(){
  3393. this.page = parseInt(new URLSearchParams(window.location.search).get('page'))
  3394. this.localHref = location.href
  3395. },
  3396. methods:{
  3397. handleCurrentChange:function (val) {
  3398. const searchParams = new URLSearchParams(window.location.search)
  3399. if (!window.location.search) {
  3400. window.location.href = this.localHref + '?page='+val
  3401. } else if (searchParams.has('page')) {
  3402. window.location.href = this.localHref.replace(/page=[0-9]+/g,'page='+val)
  3403. } else {
  3404. window.location.href=location.href+'&page='+val
  3405. }
  3406. this.page = val
  3407. }
  3408. }
  3409. });
  3410. }
  3411. function initVueUploader() {
  3412. const el = document.getElementById('minioUploader');
  3413. if (!el) {
  3414. return;
  3415. }
  3416. new Vue({
  3417. el: '#minioUploader',
  3418. i18n,
  3419. components: {MinioUploader},
  3420. template: '<MinioUploader />'
  3421. });
  3422. }
  3423. function initVueEditAbout() {
  3424. const el = document.getElementById('about-desc');
  3425. if (!el) {
  3426. return;
  3427. }
  3428. new Vue({
  3429. el: '#about-desc',
  3430. i18n,
  3431. render: h => h(EditAboutInfo)
  3432. });
  3433. }
  3434. function initVueDataset() {
  3435. const el = document.getElementById('dataset-base');
  3436. if (!el) {
  3437. return;
  3438. }
  3439. let link=$('#square-link').data('link')
  3440. let repolink = $('.dataset-repolink').data('repolink')
  3441. let cloudbrainType = $('.dataset-repolink').data('cloudranin-type')
  3442. const clearBtn = document.getElementsByClassName("clear_dataset_value");
  3443. const params = new URLSearchParams(location.search)
  3444. for (let i = 0; i < clearBtn.length; i++) {
  3445. clearBtn[i].addEventListener('click',function(e){
  3446. let searchType=e.target.getAttribute("data-clear-value")
  3447. if(params.has(searchType)){
  3448. params.delete(searchType)
  3449. let clearSearch = params.toString()
  3450. location.href = link + '?' + clearSearch
  3451. }
  3452. })
  3453. }
  3454. const items = []
  3455. const zipStatus = []
  3456. $('#dataset-range-value').find('.item').each(function(){
  3457. items.push($(this).data('private'))
  3458. zipStatus.push($(this).data('decompress-state'))
  3459. })
  3460. let num_stars = $('#dataset-range-value').data('num-stars')
  3461. let star_active = $('#dataset-range-value').data('star-active')
  3462. const ruleForm = {}
  3463. if(document.getElementById('dataset-edit-value')){
  3464. let $this = $('#dataset-edit-value')
  3465. ruleForm.title = $this.data('edit-title') || ''
  3466. ruleForm.description = $this.data('edit-description') || ''
  3467. ruleForm.category = $this.data('edit-category') || ''
  3468. ruleForm.task = $this.data('edit-task') || ''
  3469. ruleForm.license = $this.data('edit-license') || ''
  3470. ruleForm.id = $this.data('edit-id')|| ''
  3471. ruleForm._csrf = csrf
  3472. }
  3473. const starItems = []
  3474. const starActives = []
  3475. $('#datasets-square-range-value').find('.item').each(function(){
  3476. starItems.push($(this).data('num-stars'))
  3477. starActives.push($(this).data('star-active'))
  3478. })
  3479. const taskLists = []
  3480. const licenseLists = []
  3481. $('#task-square-range-value').find('.item').each(function(){
  3482. taskLists.push($(this).data('task'))
  3483. })
  3484. $('#task-square-range-value').find('.item').each(function(){
  3485. licenseLists.push($(this).data('license'))
  3486. })
  3487. let dataset_file_desc
  3488. if(document.getElementById('dataset-file-desc')){
  3489. dataset_file_desc = document.getElementById('dataset-file-desc').value
  3490. }
  3491. // getEditInit(){
  3492. // if($('#dataset-edit-value')){
  3493. // $this = $('#dataset-edit-value')
  3494. // this.ruleForm.title = $this.data('edit-title') || ''
  3495. // this.ruleForm.description = $this.data('edit-description') || ''
  3496. // this.ruleForm.category = $this.data('edit-category') || ''
  3497. // this.ruleForm.task = $this.data('edit-task') || ''
  3498. // this.ruleForm.license = $this.data('edit-license') || ''
  3499. // this.ruleForm.id = $this.data('edit-id')|| ''
  3500. // }
  3501. // },
  3502. new Vue({
  3503. delimiters: ['${', '}'],
  3504. el,
  3505. i18n,
  3506. data: {
  3507. suburl: AppSubUrl,
  3508. url:'',
  3509. type:0,
  3510. desc:'',
  3511. descfile:'',
  3512. datasetType:'',
  3513. privates:[],
  3514. zipStatus:[],
  3515. starItems:[],
  3516. starActives:[],
  3517. taskLists:[],
  3518. taskShow:[],
  3519. licenseLists:[],
  3520. licenseShow:[],
  3521. hasMoreBthHis: false,
  3522. showMoreHis:false,
  3523. star_active:false,
  3524. num_stars:0,
  3525. dialogVisible:false,
  3526. activeName: 'first',
  3527. searchDataItem:'',
  3528. currentRepoDataset:[],
  3529. myDataset:[],
  3530. publicDataset:[],
  3531. myFavoriteDataset:[],
  3532. page:1,
  3533. totalnums:0,
  3534. repolink:'',
  3535. cloudbrainType:0,
  3536. dataset_uuid:'',
  3537. dataset_name:'',
  3538. loadingDataIndex:true,
  3539. timer:null,
  3540. ruleForm:{
  3541. title:'',
  3542. description:'',
  3543. category:'',
  3544. task:'',
  3545. license:'',
  3546. _csrf:csrf,
  3547. },
  3548. ruleForm1:{
  3549. title:'',
  3550. description:'',
  3551. category:'',
  3552. task:'',
  3553. license:'',
  3554. _csrf:'',
  3555. id:''
  3556. },
  3557. rules: {
  3558. title: [
  3559. { required: true, message: '请输入数据集名称', trigger: 'blur' },
  3560. { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' },
  3561. // {required:true,message:'test',pattern:'/^[a-zA-Z0-9-_]{1,100}[^-]$/',trigger:'blur'},
  3562. { validator: (rule, value, callback) => {
  3563. if (/^[a-zA-Z0-9-_.]{0,100}$/.test(value) == false) {
  3564. callback(new Error("输入不符合数据集名称规则"));
  3565. } else {
  3566. callback();
  3567. }
  3568. }, trigger: 'blur'}
  3569. ],
  3570. description: [
  3571. { required: true, message: '请输入数据集描述详情', trigger: 'blur' }
  3572. ],
  3573. category: [
  3574. { required: true, message: '请选择分类', trigger: 'change' }
  3575. ],
  3576. task: [
  3577. { required: true, message: '请选择研究方向/应用领域', trigger: 'change' }
  3578. ],
  3579. // license: [
  3580. // { required: true, message: '请选择活动区域', trigger: 'change' }
  3581. // ]
  3582. },
  3583. },
  3584. components: {
  3585. MinioUploader,
  3586. ObsUploader
  3587. },
  3588. mounted(){
  3589. // if(document.getElementById('postPath')){
  3590. // this.url = document.getElementById('postPath').value
  3591. // }
  3592. // this.privates = items
  3593. // this.num_stars = num_stars
  3594. // this.star_active = star_active
  3595. // this.ruleForm1 = ruleForm
  3596. // // this.getEditInit()
  3597. // this.getTypeList()
  3598. this.getTypeList()
  3599. if(!!document.getElementById('dataset-repolink-init')){
  3600. this.getCurrentRepoDataset(this.repolink,this.cloudbrainType)
  3601. }
  3602. },
  3603. created(){
  3604. if(document.getElementById('postPath')){
  3605. this.url = document.getElementById('postPath').value
  3606. }
  3607. this.privates = items
  3608. this.zipStatus = zipStatus
  3609. this.num_stars = num_stars
  3610. this.star_active = star_active
  3611. this.ruleForm1 = ruleForm
  3612. // this.getEditInit()
  3613. this.starItems = starItems
  3614. this.starActives = starActives
  3615. this.taskLists = taskLists
  3616. this.licenseLists = licenseLists
  3617. this.descfile = dataset_file_desc
  3618. this.repolink = repolink
  3619. this.cloudbrainType = cloudbrainType
  3620. },
  3621. methods:{
  3622. handleCurrentChange(val) {
  3623. this.page = val
  3624. switch(this.activeName){
  3625. case 'first':
  3626. this.getCurrentRepoDataset(this.repolink,this.cloudbrainType)
  3627. break
  3628. case 'second':
  3629. this.getMyDataset(this.repolink,this.cloudbrainType)
  3630. break
  3631. case 'third':
  3632. this.getPublicDataset(this.repolink,this.cloudbrainType)
  3633. break
  3634. case 'fourth':
  3635. this.getStarDataset(this.repolink,this.cloudbrainType)
  3636. break
  3637. }
  3638. },
  3639. createDataset(formName){
  3640. let _this = this
  3641. this.$refs[formName].validate((valid)=>{
  3642. if(valid){
  3643. document.getElementById("mask").style.display = "block"
  3644. _this.$axios.post(_this.url,_this.qs.stringify(_this.ruleForm)).then((res)=>{
  3645. if(res.data.Code===0){
  3646. document.getElementById("mask").style.display = "none"
  3647. location.href = _this.url.split('/create')[0]+'?type=-1'
  3648. }else{
  3649. console.log(res.data.Message)
  3650. }
  3651. document.getElementById("mask").style.display = "none"
  3652. }).catch(error=>{
  3653. console.log(error)
  3654. })
  3655. }
  3656. else{
  3657. return false
  3658. }
  3659. })
  3660. },
  3661. cancelDataset(getpage,attachment){
  3662. if(getpage && !attachment){
  3663. if(getpage==='create'){
  3664. location.href = this.url.split('/create')[0]+'?type=-1'
  3665. }else if(getpage==='edit'){
  3666. location.href = this.url.split('/edit')[0]+'?type=-1'
  3667. }else{
  3668. location.href='/'
  3669. }
  3670. }
  3671. else{
  3672. location.href = `${AppSubUrl}${attachment}/datasets`
  3673. }
  3674. },
  3675. gotoUpload(repolink,datsetId){
  3676. location.href = `${AppSubUrl}${repolink}/datasets/attachments/upload?datasetId=${datsetId}`
  3677. },
  3678. gotoDataset(datsetUrl){
  3679. location.href = datsetUrl
  3680. },
  3681. gotoAnnotate(repolink,uuid,type){
  3682. location.href = `${AppSubUrl}${repolink}/datasets/label/${uuid}?type=${type}`
  3683. },
  3684. uploadGpu(){
  3685. this.type=0
  3686. },
  3687. uploadNpu(){
  3688. this.type=1
  3689. },
  3690. setPrivate(uuid,privateFlag,index){
  3691. const params = {_csrf:csrf,file:uuid,is_private:privateFlag}
  3692. this.$axios.post('/attachments/private',this.qs.stringify(params)).then((res)=>{
  3693. this.$set(this.privates,index,privateFlag)
  3694. }).catch(error=>{
  3695. console.log(error)
  3696. })
  3697. },
  3698. delDataset(uuid){
  3699. let _this = this
  3700. const params = {_csrf:csrf,file:uuid}
  3701. $('#data-dataset-delete-modal')
  3702. .modal({
  3703. closable: false,
  3704. onApprove() {
  3705. _this.$axios.post('/attachments/delete',_this.qs.stringify(params)).then((res)=>{
  3706. // $('#'+uuid).hide()
  3707. location.reload()
  3708. }).catch(error=>{
  3709. console.log(error)
  3710. })
  3711. }
  3712. })
  3713. .modal('show');
  3714. },
  3715. // getEditInit(){
  3716. // if($('#dataset-edit-value')){
  3717. // $this = $('#dataset-edit-value')
  3718. // this.ruleForm.title = $this.data('edit-title') || ''
  3719. // this.ruleForm.description = $this.data('edit-description') || ''
  3720. // this.ruleForm.category = $this.data('edit-category') || ''
  3721. // this.ruleForm.task = $this.data('edit-task') || ''
  3722. // this.ruleForm.license = $this.data('edit-license') || ''
  3723. // this.ruleForm.id = $this.data('edit-id')|| ''
  3724. // }
  3725. // },
  3726. editDataset(formName,id){
  3727. let _this = this
  3728. this.url = this.url.split(`/${id}`)[0]
  3729. this.$refs[formName].validate((valid)=>{
  3730. if(valid){
  3731. document.getElementById("mask").style.display = "block"
  3732. _this.$axios.post(_this.url,_this.qs.stringify(_this.ruleForm1)).then((res)=>{
  3733. if(res.data.Code===0){
  3734. document.getElementById("mask").style.display = "none"
  3735. location.href = _this.url.split('/edit')[0]+'?type=-1'
  3736. }else{
  3737. console.log(res.data.Message)
  3738. }
  3739. document.getElementById("mask").style.display = "none"
  3740. }).catch((err)=>{
  3741. console.log(err)
  3742. })
  3743. }
  3744. else{
  3745. return false
  3746. }
  3747. })
  3748. },
  3749. editDatasetFile(id,backurl){
  3750. let url = '/attachments/edit'
  3751. const params={id:id,description:this.descfile,_csrf:csrf}
  3752. // document.getElementById("mask").style.display = "block"
  3753. this.$axios.post(url,this.qs.stringify(params)).then((res)=>{
  3754. if(res.data.Code===0){
  3755. location.href = `${AppSubUrl}${backurl}/datasets`
  3756. }else{
  3757. console.log(res.data.Message)
  3758. }
  3759. }).catch((err)=>{
  3760. console.log(err)
  3761. })
  3762. },
  3763. postStar(id,link){
  3764. if(this.star_active){
  3765. let url = link+'/'+ id + '/unstar'
  3766. this.$axios.put(url).then((res)=>{
  3767. if(res.data.Code===0){
  3768. this.star_active = false
  3769. this.num_stars = this.num_stars -1
  3770. }
  3771. })
  3772. }else{
  3773. let url = link+'/'+ id + '/star'
  3774. this.$axios.put(url).then((res)=>{
  3775. if(res.data.Code===0){
  3776. this.star_active = true
  3777. this.num_stars = this.num_stars + 1
  3778. }
  3779. })
  3780. }
  3781. },
  3782. postSquareStar(id,link,index){
  3783. if(this.starActives[index]){
  3784. let url = link+'/'+ id + '/unstar'
  3785. this.$axios.put(url).then((res)=>{
  3786. if(res.data.Code===0){
  3787. this.$set(this.starActives,index,false)
  3788. this.$set(this.starItems,index,this.starItems[index]-1)
  3789. }
  3790. })
  3791. }else{
  3792. let url = link+'/'+ id + '/star'
  3793. this.$axios.put(url).then((res)=>{
  3794. if(res.data.Code===0){
  3795. this.$set(this.starActives,index,true)
  3796. this.$set(this.starItems,index,this.starItems[index]+1)
  3797. }
  3798. })
  3799. }
  3800. },
  3801. getTypeList(){
  3802. const params = new URLSearchParams(window.location.search)
  3803. if( window.location.search && params.has('type')){
  3804. if(params.get('type')==0){
  3805. this.datasetType = '0'
  3806. }
  3807. if(params.get('type')==1){
  3808. this.datasetType = '1'
  3809. }
  3810. if(params.get('type')==-1){
  3811. this.datasetType = '-1'
  3812. }
  3813. }else {
  3814. this.datasetType = '-1'
  3815. }
  3816. },
  3817. changeDatasetType(val){
  3818. const searchParams = new URLSearchParams(window.location.search)
  3819. if (!window.location.search) {
  3820. window.location.href = window.location.href + '?type='+val
  3821. } else if (searchParams.has('type')) {
  3822. window.location.href = window.location.href.replace(/type=([0-9]|-[0-9])/g,'type='+val)
  3823. } else {
  3824. window.location.href=window.location.href+'&type='+val
  3825. }
  3826. },
  3827. gotoDatasetEidt(repolink,id){
  3828. location.href = `${repolink}/datasets/attachments/edit/${id}`
  3829. },
  3830. handleClick(repoLink, tabName,type) {
  3831. if(tabName=="first"){
  3832. this.page=1
  3833. this.searchDataItem=''
  3834. this.getCurrentRepoDataset(repoLink,type)
  3835. }
  3836. if(tabName=="second"){
  3837. this.page=1
  3838. this.searchDataItem=''
  3839. this.getMyDataset(repoLink,type)
  3840. }
  3841. if(tabName=="third"){
  3842. this.page=1
  3843. this.searchDataItem=''
  3844. this.getPublicDataset(repoLink,type)
  3845. }
  3846. if(tabName=="fourth"){
  3847. this.page=1
  3848. this.searchDataItem=''
  3849. this.getStarDataset(repoLink,type)
  3850. }
  3851. },
  3852. polling (checkStatuDataset,repoLink) {
  3853. this.timer = window.setInterval(() => {
  3854. setTimeout(() => {
  3855. this.getDatasetStatus(checkStatuDataset,repoLink)
  3856. },0)
  3857. },15000)
  3858. },
  3859. getDatasetStatus(checkStatuDataset,repoLink){
  3860. const getmap = checkStatuDataset.map((item)=>{
  3861. let url = `${AppSubUrl}${repolink}/datasets/status/${item.UUID}`
  3862. return this.$axios.get(url)
  3863. })
  3864. this.$axios.all(getmap)
  3865. .then((res)=>{
  3866. let flag = res.some((item)=>{
  3867. return item.data.AttachmentStatus == 1
  3868. })
  3869. flag && clearInterval(this.timer)
  3870. flag && this.refreshStatusDataset()
  3871. }
  3872. )
  3873. },
  3874. refreshStatusDataset(){
  3875. switch(this.activeName){
  3876. case 'first':
  3877. this.getCurrentRepoDataset(this.repolink,this.cloudbrainType)
  3878. break
  3879. case 'second':
  3880. this.getMyDataset(this.repolink,this.cloudbrainType)
  3881. break
  3882. case 'third':
  3883. this.getPublicDataset(this.repolink,this.cloudbrainType)
  3884. break
  3885. case 'fourth':
  3886. this.getStarDataset(this.repolink,this.cloudbrainType)
  3887. break
  3888. }
  3889. },
  3890. getCurrentRepoDataset(repoLink,type){
  3891. clearInterval(this.timer)
  3892. this.loadingDataIndex = true
  3893. let url = repoLink + '/datasets/current_repo'
  3894. this.$axios.get(url,{
  3895. params:{
  3896. type:type,
  3897. page:this.page,
  3898. q:this.searchDataItem
  3899. }
  3900. }).then((res)=>{
  3901. this.currentRepoDataset = JSON.parse(res.data.data)
  3902. const checkStatuDataset = this.currentRepoDataset.filter(item=>item.DecompressState===2)
  3903. if(checkStatuDataset.length>0){
  3904. this.polling(checkStatuDataset,repoLink)
  3905. }
  3906. this.totalnums = parseInt(res.data.count)
  3907. this.loadingDataIndex = false
  3908. })
  3909. },
  3910. getMyDataset(repoLink,type){
  3911. clearInterval(this.timer)
  3912. this.loadingDataIndex = true
  3913. let url = repoLink + '/datasets/my_datasets'
  3914. this.$axios.get(url,{
  3915. params:{
  3916. type:type,
  3917. page:this.page,
  3918. q:this.searchDataItem
  3919. }
  3920. }).then((res)=>{
  3921. this.myDataset = JSON.parse(res.data.data)
  3922. const checkStatuDataset = this.myDataset.filter(item=>item.DecompressState===2)
  3923. if(checkStatuDataset.length>0){
  3924. this.polling(checkStatuDataset,repoLink)
  3925. }
  3926. this.totalnums = parseInt(res.data.count)
  3927. this.loadingDataIndex = false
  3928. })
  3929. },
  3930. getPublicDataset(repoLink,type){
  3931. clearInterval(this.timer)
  3932. this.loadingDataIndex = true
  3933. let url = repoLink + '/datasets/public_datasets'
  3934. this.$axios.get(url,{
  3935. params:{
  3936. type:type,
  3937. page:this.page,
  3938. q:this.searchDataItem
  3939. }
  3940. }).then((res)=>{
  3941. this.publicDataset = JSON.parse(res.data.data)
  3942. const checkStatuDataset = this.publicDataset.filter(item=>item.DecompressState===2)
  3943. if(checkStatuDataset.length>0){
  3944. this.polling(checkStatuDataset,repoLink)
  3945. }
  3946. this.totalnums = parseInt(res.data.count)
  3947. this.loadingDataIndex = false
  3948. })
  3949. },
  3950. getStarDataset(repoLink,type){
  3951. clearInterval(this.timer)
  3952. this.loadingDataIndex = true
  3953. let url = repoLink + '/datasets/my_favorite'
  3954. this.$axios.get(url,{
  3955. params:{
  3956. type:type,
  3957. page:this.page,
  3958. q:this.searchDataItem
  3959. }
  3960. }).then((res)=>{
  3961. this.myFavoriteDataset = JSON.parse(res.data.data)
  3962. const checkStatuDataset = this.myFavoriteDataset.filter(item=>item.DecompressState===2)
  3963. if(checkStatuDataset.length>0){
  3964. this.polling(checkStatuDataset,repoLink)
  3965. }
  3966. this.totalnums= parseInt(res.data.count)
  3967. this.loadingDataIndex = false
  3968. })
  3969. },
  3970. selectDataset(uuid,name){
  3971. this.dataset_uuid = uuid
  3972. this.dataset_name = name
  3973. this.dialogVisible = false
  3974. },
  3975. searchDataset(){
  3976. switch(this.activeName){
  3977. case 'first':
  3978. this.page = 1
  3979. this.getCurrentRepoDataset(this.repolink,this.cloudbrainType)
  3980. break
  3981. case 'second':
  3982. this.page = 1
  3983. this.getMyDataset(this.repolink,this.cloudbrainType)
  3984. break
  3985. case 'third':
  3986. this.page = 1
  3987. this.getPublicDataset(this.repolink,this.cloudbrainType)
  3988. break
  3989. case 'fourth':
  3990. this.page = 1
  3991. this.getStarDataset(this.repolink,this.cloudbrainType)
  3992. break
  3993. }
  3994. }
  3995. },
  3996. });
  3997. }
  3998. function initVueEditTopic() {
  3999. const el = document.getElementById('topic_edit1');
  4000. if (!el) {
  4001. return;
  4002. }
  4003. new Vue({
  4004. el:'#topic_edit1',
  4005. i18n,
  4006. render:h=>h(EditTopics)
  4007. })
  4008. }
  4009. function initVueContributors() {
  4010. const el = document.getElementById('Contributors');
  4011. if (!el) {
  4012. return;
  4013. }
  4014. new Vue({
  4015. el:'#Contributors',
  4016. i18n,
  4017. render:h=>h(Contributors)
  4018. })
  4019. }
  4020. function initVueImages() {
  4021. const el = document.getElementById('images');
  4022. if (!el) {
  4023. return;
  4024. }
  4025. new Vue({
  4026. el: '#images',
  4027. i18n,
  4028. render: h => h(Images)
  4029. });
  4030. }
  4031. function initVueModel() {
  4032. const el = document.getElementById('model_list');
  4033. if (!el) {
  4034. return;
  4035. }
  4036. new Vue({
  4037. el: el,
  4038. i18n,
  4039. render: h => h(Model)
  4040. });
  4041. }
  4042. function initVueDataAnalysis() {
  4043. const el = document.getElementById('data_analysis');
  4044. if (!el) {
  4045. return;
  4046. }
  4047. new Vue({
  4048. el: '#data_analysis',
  4049. i18n,
  4050. render: h => h(DataAnalysis)
  4051. });
  4052. }
  4053. // 新增
  4054. function initObsUploader() {
  4055. const el = document.getElementById('obsUploader');
  4056. if (!el) {
  4057. return;
  4058. }
  4059. new Vue({
  4060. el: '#obsUploader',
  4061. i18n,
  4062. components: {ObsUploader},
  4063. template: '<ObsUploader />'
  4064. });
  4065. }
  4066. function initVueWxAutorize() {
  4067. const el = document.getElementById('WxAutorize');
  4068. if (!el) {
  4069. return;
  4070. }
  4071. new Vue({
  4072. el:el,
  4073. i18n,
  4074. render: h => h(WxAutorize)
  4075. });
  4076. }
  4077. window.timeAddManual = function () {
  4078. $('.mini.modal')
  4079. .modal({
  4080. duration: 200,
  4081. onApprove() {
  4082. $('#add_time_manual_form').trigger('submit');
  4083. }
  4084. })
  4085. .modal('show');
  4086. };
  4087. window.toggleStopwatch = function () {
  4088. $('#toggle_stopwatch_form').trigger('submit');
  4089. };
  4090. window.cancelStopwatch = function () {
  4091. $('#cancel_stopwatch_form').trigger('submit');
  4092. };
  4093. function initFilterBranchTagDropdown(selector) {
  4094. $(selector).each(function () {
  4095. const $dropdown = $(this);
  4096. const $data = $dropdown.find('.data');
  4097. const data = {
  4098. items: [],
  4099. mode: $data.data('mode'),
  4100. searchTerm: '',
  4101. noResults: '',
  4102. canCreateBranch: false,
  4103. menuVisible: false,
  4104. active: 0
  4105. };
  4106. $data.find('.item').each(function () {
  4107. data.items.push({
  4108. name: $(this).text(),
  4109. url: $(this).data('url'),
  4110. branch: $(this).hasClass('branch'),
  4111. tag: $(this).hasClass('tag'),
  4112. selected: $(this).hasClass('selected')
  4113. });
  4114. });
  4115. $data.remove();
  4116. new Vue({
  4117. delimiters: ['${', '}'],
  4118. el: this,
  4119. i18n,
  4120. data,
  4121. beforeMount() {
  4122. const vm = this;
  4123. this.noResults = vm.$el.getAttribute('data-no-results');
  4124. this.canCreateBranch =
  4125. vm.$el.getAttribute('data-can-create-branch') === 'true';
  4126. document.body.addEventListener('click', (event) => {
  4127. if (vm.$el.contains(event.target)) {
  4128. return;
  4129. }
  4130. if (vm.menuVisible) {
  4131. Vue.set(vm, 'menuVisible', false);
  4132. }
  4133. });
  4134. },
  4135. watch: {
  4136. menuVisible(visible) {
  4137. if (visible) {
  4138. this.focusSearchField();
  4139. }
  4140. }
  4141. },
  4142. computed: {
  4143. filteredItems() {
  4144. const vm = this;
  4145. const items = vm.items.filter((item) => {
  4146. return (
  4147. ((vm.mode === 'branches' && item.branch) ||
  4148. (vm.mode === 'tags' && item.tag)) &&
  4149. (!vm.searchTerm ||
  4150. item.name.toLowerCase().includes(vm.searchTerm.toLowerCase()))
  4151. );
  4152. });
  4153. vm.active = items.length === 0 && vm.showCreateNewBranch ? 0 : -1;
  4154. return items;
  4155. },
  4156. showNoResults() {
  4157. return this.filteredItems.length === 0 && !this.showCreateNewBranch;
  4158. },
  4159. showCreateNewBranch() {
  4160. const vm = this;
  4161. if (!this.canCreateBranch || !vm.searchTerm || vm.mode === 'tags') {
  4162. return false;
  4163. }
  4164. return (
  4165. vm.items.filter(
  4166. (item) => item.name.toLowerCase() === vm.searchTerm.toLowerCase()
  4167. ).length === 0
  4168. );
  4169. }
  4170. },
  4171. methods: {
  4172. selectItem(item) {
  4173. const prev = this.getSelected();
  4174. if (prev !== null) {
  4175. prev.selected = false;
  4176. }
  4177. item.selected = true;
  4178. window.location.href = item.url;
  4179. },
  4180. createNewBranch() {
  4181. if (!this.showCreateNewBranch) {
  4182. return;
  4183. }
  4184. $(this.$refs.newBranchForm).trigger('submit');
  4185. },
  4186. focusSearchField() {
  4187. const vm = this;
  4188. Vue.nextTick(() => {
  4189. vm.$refs.searchField.focus();
  4190. });
  4191. },
  4192. getSelected() {
  4193. for (let i = 0, j = this.items.length; i < j; ++i) {
  4194. if (this.items[i].selected) return this.items[i];
  4195. }
  4196. return null;
  4197. },
  4198. getSelectedIndexInFiltered() {
  4199. for (let i = 0, j = this.filteredItems.length; i < j; ++i) {
  4200. if (this.filteredItems[i].selected) return i;
  4201. }
  4202. return -1;
  4203. },
  4204. scrollToActive() {
  4205. let el = this.$refs[`listItem${this.active}`];
  4206. if (!el || el.length === 0) {
  4207. return;
  4208. }
  4209. if (Array.isArray(el)) {
  4210. el = el[0];
  4211. }
  4212. const cont = this.$refs.scrollContainer;
  4213. if (el.offsetTop < cont.scrollTop) {
  4214. cont.scrollTop = el.offsetTop;
  4215. } else if (
  4216. el.offsetTop + el.clientHeight >
  4217. cont.scrollTop + cont.clientHeight
  4218. ) {
  4219. cont.scrollTop = el.offsetTop + el.clientHeight - cont.clientHeight;
  4220. }
  4221. },
  4222. keydown(event) {
  4223. const vm = this;
  4224. if (event.keyCode === 40) {
  4225. // arrow down
  4226. event.preventDefault();
  4227. if (vm.active === -1) {
  4228. vm.active = vm.getSelectedIndexInFiltered();
  4229. }
  4230. if (
  4231. vm.active + (vm.showCreateNewBranch ? 0 : 1) >=
  4232. vm.filteredItems.length
  4233. ) {
  4234. return;
  4235. }
  4236. vm.active++;
  4237. vm.scrollToActive();
  4238. }
  4239. if (event.keyCode === 38) {
  4240. // arrow up
  4241. event.preventDefault();
  4242. if (vm.active === -1) {
  4243. vm.active = vm.getSelectedIndexInFiltered();
  4244. }
  4245. if (vm.active <= 0) {
  4246. return;
  4247. }
  4248. vm.active--;
  4249. vm.scrollToActive();
  4250. }
  4251. if (event.keyCode === 13) {
  4252. // enter
  4253. event.preventDefault();
  4254. if (vm.active >= vm.filteredItems.length) {
  4255. vm.createNewBranch();
  4256. } else if (vm.active >= 0) {
  4257. vm.selectItem(vm.filteredItems[vm.active]);
  4258. }
  4259. }
  4260. if (event.keyCode === 27) {
  4261. // escape
  4262. event.preventDefault();
  4263. vm.menuVisible = false;
  4264. }
  4265. }
  4266. }
  4267. });
  4268. });
  4269. }
  4270. $('.commit-button').on('click', function (e) {
  4271. e.preventDefault();
  4272. $(this)
  4273. .parent()
  4274. .find('.commit-body')
  4275. .toggle();
  4276. });
  4277. function initNavbarContentToggle() {
  4278. const content = $('#navbar');
  4279. const toggle = $('#navbar-expand-toggle');
  4280. let isExpanded = false;
  4281. toggle.on('click', () => {
  4282. isExpanded = !isExpanded;
  4283. if (isExpanded) {
  4284. content.addClass('shown');
  4285. toggle.addClass('active');
  4286. } else {
  4287. content.removeClass('shown');
  4288. toggle.removeClass('active');
  4289. }
  4290. });
  4291. }
  4292. window.toggleDeadlineForm = function () {
  4293. $('#deadlineForm').fadeToggle(150);
  4294. };
  4295. window.setDeadline = function () {
  4296. const deadline = $('#deadlineDate').val();
  4297. window.updateDeadline(deadline);
  4298. };
  4299. window.updateDeadline = function (deadlineString) {
  4300. $('#deadline-err-invalid-date').hide();
  4301. $('#deadline-loader').addClass('loading');
  4302. let realDeadline = null;
  4303. if (deadlineString !== '') {
  4304. const newDate = Date.parse(deadlineString);
  4305. if (Number.isNaN(newDate)) {
  4306. $('#deadline-loader').removeClass('loading');
  4307. $('#deadline-err-invalid-date').show();
  4308. return false;
  4309. }
  4310. realDeadline = new Date(newDate);
  4311. }
  4312. $.ajax(`${$('#update-issue-deadline-form').attr('action')}/deadline`, {
  4313. data: JSON.stringify({
  4314. due_date: realDeadline
  4315. }),
  4316. headers: {
  4317. 'X-Csrf-Token': csrf,
  4318. 'X-Remote': true
  4319. },
  4320. contentType: 'application/json',
  4321. type: 'POST',
  4322. success() {
  4323. reload();
  4324. },
  4325. error() {
  4326. $('#deadline-loader').removeClass('loading');
  4327. $('#deadline-err-invalid-date').show();
  4328. }
  4329. });
  4330. };
  4331. window.deleteDependencyModal = function (id, type) {
  4332. $('.remove-dependency')
  4333. .modal({
  4334. closable: false,
  4335. duration: 200,
  4336. onApprove() {
  4337. $('#removeDependencyID').val(id);
  4338. $('#dependencyType').val(type);
  4339. $('#removeDependencyForm').trigger('submit');
  4340. }
  4341. })
  4342. .modal('show');
  4343. };
  4344. function initIssueList() {
  4345. const repolink = $('#repolink').val();
  4346. const repoId = $('#repoId').val();
  4347. const crossRepoSearch = $('#crossRepoSearch').val();
  4348. const tp = $('#type').val();
  4349. let issueSearchUrl = `${AppSubUrl}/api/v1/repos/${repolink}/issues?q={query}&type=${tp}`;
  4350. if (crossRepoSearch === 'true') {
  4351. issueSearchUrl = `${AppSubUrl}/api/v1/repos/issues/search?q={query}&priority_repo_id=${repoId}&type=${tp}`;
  4352. }
  4353. $('#new-dependency-drop-list').dropdown({
  4354. apiSettings: {
  4355. url: issueSearchUrl,
  4356. onResponse(response) {
  4357. const filteredResponse = {success: true, results: []};
  4358. const currIssueId = $('#new-dependency-drop-list').data('issue-id');
  4359. // Parse the response from the api to work with our dropdown
  4360. $.each(response, (_i, issue) => {
  4361. // Don't list current issue in the dependency list.
  4362. if (issue.id === currIssueId) {
  4363. return;
  4364. }
  4365. filteredResponse.results.push({
  4366. name: `#${issue.number} ${htmlEncode(
  4367. issue.title
  4368. )}<div class="text small dont-break-out">${htmlEncode(
  4369. issue.repository.full_name
  4370. )}</div>`,
  4371. value: issue.id
  4372. });
  4373. });
  4374. return filteredResponse;
  4375. },
  4376. cache: false
  4377. },
  4378. fullTextSearch: true
  4379. });
  4380. $('.menu a.label-filter-item').each(function () {
  4381. $(this).on('click', function (e) {
  4382. if (e.altKey) {
  4383. e.preventDefault();
  4384. const href = $(this).attr('href');
  4385. const id = $(this).data('label-id');
  4386. const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`;
  4387. const newStr = 'labels=$1-$2$3&';
  4388. window.location = href.replace(new RegExp(regStr), newStr);
  4389. }
  4390. });
  4391. });
  4392. $('.menu .ui.dropdown.label-filter').on('keydown', (e) => {
  4393. if (e.altKey && e.keyCode === 13) {
  4394. const selectedItems = $(
  4395. '.menu .ui.dropdown.label-filter .menu .item.selected'
  4396. );
  4397. if (selectedItems.length > 0) {
  4398. const item = $(selectedItems[0]);
  4399. const href = item.attr('href');
  4400. const id = item.data('label-id');
  4401. const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`;
  4402. const newStr = 'labels=$1-$2$3&';
  4403. window.location = href.replace(new RegExp(regStr), newStr);
  4404. }
  4405. }
  4406. });
  4407. }
  4408. window.cancelCodeComment = function (btn) {
  4409. const form = $(btn).closest('form');
  4410. if (form.length > 0 && form.hasClass('comment-form')) {
  4411. form.addClass('hide');
  4412. form
  4413. .parent()
  4414. .find('button.comment-form-reply')
  4415. .show();
  4416. } else {
  4417. form.closest('.comment-code-cloud').remove();
  4418. }
  4419. };
  4420. window.submitReply = function (btn) {
  4421. const form = $(btn).closest('form');
  4422. if (form.length > 0 && form.hasClass('comment-form')) {
  4423. form.trigger('submit');
  4424. }
  4425. };
  4426. window.onOAuthLoginClick = function () {
  4427. const oauthLoader = $('#oauth2-login-loader');
  4428. const oauthNav = $('#oauth2-login-navigator');
  4429. oauthNav.hide();
  4430. oauthLoader.removeClass('disabled');
  4431. setTimeout(() => {
  4432. // recover previous content to let user try again
  4433. // usually redirection will be performed before this action
  4434. oauthLoader.addClass('disabled');
  4435. oauthNav.show();
  4436. }, 5000);
  4437. };
  4438. // Pull SVGs via AJAX to workaround CORS issues with <use> tags
  4439. // https://css-tricks.com/ajaxing-svg-sprite/
  4440. $.get(`${window.config.StaticUrlPrefix}/img/svg/icons.svg`, (data) => {
  4441. const div = document.createElement('div');
  4442. div.style.display = 'none';
  4443. div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
  4444. document.body.insertBefore(div, document.body.childNodes[0]);
  4445. });
  4446. function initDropDown() {
  4447. $("#dropdown_PageHome").dropdown({
  4448. on:'hover' ,//鼠标悬浮显示,默认值是click
  4449. });
  4450. $("#dropdown_explore").dropdown({
  4451. on:'hover' ,//鼠标悬浮显示,默认值是click
  4452. });
  4453. }
  4454. //云脑提示
  4455. $('.question.circle.icon.cloudbrain-question').hover(function(){
  4456. $(this).popup('show')
  4457. $('.ui.popup.mini.top.center').css({"border-color":'rgba(50, 145, 248, 100)',"color":"rgba(3, 102, 214, 100)","border-radius":"5px","border-shadow":"none"})
  4458. });
  4459. //云脑详情页面跳转回上一个页面
  4460. // $(".section.backTodeBug").attr("href",localStorage.getItem('all'))
  4461. //新建调试取消跳转
  4462. // $(".ui.button.cancel").attr("href",localStorage.getItem('all'))
  4463. function initcreateRepo(){
  4464. let timeout;
  4465. let keydown_flag = false
  4466. const urlAdd = location.href.split('/')[0] + '//' + location.href.split('/')[2]
  4467. let owner = $('#ownerDropdown div.text').attr("title")
  4468. $(document).ready(function(){
  4469. $('#ownerDropdown').dropdown({
  4470. onChange:function(value,text,$choice){
  4471. owner = $choice[0].getAttribute("title")
  4472. $('#repoAdress').css("display","flex")
  4473. $('#repoAdress span').text(urlAdd+'/'+owner+'/'+$('#repo_name').val()+'.git')
  4474. }
  4475. });
  4476. })
  4477. $('#repo_name').keyup(function(){
  4478. keydown_flag = $('#repo_name').val() ? true : false
  4479. if(keydown_flag){
  4480. $('#repoAdress').css("display","flex")
  4481. $('#repoAdress span').text(urlAdd+'/'+owner+'/'+$('#repo_name').val()+'.git')
  4482. }
  4483. else{
  4484. $('#repoAdress').css("display","none")
  4485. $('#repo_name').attr("placeholder","")
  4486. }
  4487. })
  4488. $("#create_repo_form")
  4489. .form({
  4490. on: 'blur',
  4491. // inline:true,
  4492. fields: {
  4493. alias: {
  4494. identifier : 'alias',
  4495. rules: [
  4496. {
  4497. type: 'regExp[/^[\u4E00-\u9FA5A-Za-z0-9_.-]{1,100}$/]',
  4498. }
  4499. ]
  4500. },
  4501. repo_name:{
  4502. identifier : 'repo_name',
  4503. rules: [
  4504. {
  4505. type: 'regExp[/^[A-Za-z0-9_.-]{1,100}$/]',
  4506. }
  4507. ]
  4508. },
  4509. },
  4510. onFailure: function(e){
  4511. return false;
  4512. }
  4513. })
  4514. $('#alias').bind('input propertychange', function (event) {
  4515. clearTimeout(timeout)
  4516. timeout = setTimeout(() => {
  4517. //在此处写调用的方法,可以实现仅最后一次操作生效
  4518. const aliasValue = $('#alias').val()
  4519. if(keydown_flag){
  4520. $('#repo_name').attr("placeholder","")
  4521. }
  4522. else if(aliasValue){
  4523. $('#repo_name').attr("placeholder","正在获取路径...")
  4524. $.get(`${window.config.AppSubUrl}/repo/check_name?q=${aliasValue}&owner=${owner}`,(data)=>{
  4525. const repo_name = data.name
  4526. $('#repo_name').val(repo_name)
  4527. repo_name && $('#repo_name').parent().removeClass('error')
  4528. $('#repoAdress').css("display","flex")
  4529. $('#repoAdress span').text(urlAdd+'/'+owner+'/'+$('#repo_name').val()+'.git')
  4530. $('#repo_name').attr("placeholder","")
  4531. })
  4532. }else{
  4533. $('#repo_name').val('')
  4534. $('#repo_name').attr("placeholder","")
  4535. $('#repoAdress').css("display","none")
  4536. }
  4537. }, 500)
  4538. });
  4539. }
  4540. initcreateRepo()