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 109 kB

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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
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
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
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
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
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>
6 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
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
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>
6 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>
6 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>
6 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>
6 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>
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553
  1. /* globals wipPrefixes, issuesTribute, emojiTribute */
  2. /* exported timeAddManual, toggleStopwatch, cancelStopwatch */
  3. /* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
  4. import './publicpath.js';
  5. import './polyfills.js';
  6. import Vue from 'vue';
  7. import 'jquery.are-you-sure';
  8. import './vendor/semanticdropdown.js';
  9. import {svg} from './utils.js';
  10. import initContextPopups from './features/contextpopup.js';
  11. import initGitGraph from './features/gitgraph.js';
  12. import initClipboard from './features/clipboard.js';
  13. import initUserHeatmap from './features/userheatmap.js';
  14. import initDateTimePicker from './features/datetimepicker.js';
  15. import createDropzone from './features/dropzone.js';
  16. import highlight from './features/highlight.js';
  17. import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
  18. const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
  19. function htmlEncode(text) {
  20. return jQuery('<div />').text(text).html();
  21. }
  22. let previewFileModes;
  23. let simpleMDEditor;
  24. const commentMDEditors = {};
  25. let codeMirrorEditor;
  26. // Silence fomantic's error logging when tabs are used without a target content element
  27. $.fn.tab.settings.silent = true;
  28. function initCommentPreviewTab($form) {
  29. const $tabMenu = $form.find('.tabular.menu');
  30. $tabMenu.find('.item').tab();
  31. $tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`).on('click', function () {
  32. const $this = $(this);
  33. $.post($this.data('url'), {
  34. _csrf: csrf,
  35. mode: 'gfm',
  36. context: $this.data('context'),
  37. text: $form.find(`.tab.segment[data-tab="${$tabMenu.data('write')}"] textarea`).val()
  38. }, (data) => {
  39. const $previewPanel = $form.find(`.tab.segment[data-tab="${$tabMenu.data('preview')}"]`);
  40. $previewPanel.html(data);
  41. emojify.run($previewPanel[0]);
  42. $('pre code', $previewPanel[0]).each(function () {
  43. highlight(this);
  44. });
  45. });
  46. });
  47. buttonsClickOnEnter();
  48. }
  49. function initEditPreviewTab($form) {
  50. const $tabMenu = $form.find('.tabular.menu');
  51. $tabMenu.find('.item').tab();
  52. const $previewTab = $tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`);
  53. if ($previewTab.length) {
  54. previewFileModes = $previewTab.data('preview-file-modes').split(',');
  55. $previewTab.on('click', function () {
  56. const $this = $(this);
  57. $.post($this.data('url'), {
  58. _csrf: csrf,
  59. mode: 'gfm',
  60. context: $this.data('context'),
  61. text: $form.find(`.tab.segment[data-tab="${$tabMenu.data('write')}"] textarea`).val()
  62. }, (data) => {
  63. const $previewPanel = $form.find(`.tab.segment[data-tab="${$tabMenu.data('preview')}"]`);
  64. $previewPanel.html(data);
  65. emojify.run($previewPanel[0]);
  66. $('pre code', $previewPanel[0]).each(function () {
  67. highlight(this);
  68. });
  69. });
  70. });
  71. }
  72. }
  73. function initEditDiffTab($form) {
  74. const $tabMenu = $form.find('.tabular.menu');
  75. $tabMenu.find('.item').tab();
  76. $tabMenu.find(`.item[data-tab="${$tabMenu.data('diff')}"]`).on('click', function () {
  77. const $this = $(this);
  78. $.post($this.data('url'), {
  79. _csrf: csrf,
  80. context: $this.data('context'),
  81. content: $form.find(`.tab.segment[data-tab="${$tabMenu.data('write')}"] textarea`).val()
  82. }, (data) => {
  83. const $diffPreviewPanel = $form.find(`.tab.segment[data-tab="${$tabMenu.data('diff')}"]`);
  84. $diffPreviewPanel.html(data);
  85. emojify.run($diffPreviewPanel[0]);
  86. });
  87. });
  88. }
  89. function initEditForm() {
  90. if ($('.edit.form').length === 0) {
  91. return;
  92. }
  93. initEditPreviewTab($('.edit.form'));
  94. initEditDiffTab($('.edit.form'));
  95. }
  96. function initBranchSelector() {
  97. const $selectBranch = $('.ui.select-branch');
  98. const $branchMenu = $selectBranch.find('.reference-list-menu');
  99. $branchMenu.find('.item:not(.no-select)').on('click', function () {
  100. const selectedValue = $(this).data('id');
  101. $($(this).data('id-selector')).val(selectedValue);
  102. $selectBranch.find('.ui .branch-name').text(selectedValue);
  103. });
  104. $selectBranch.find('.reference.column').on('click', function () {
  105. $selectBranch.find('.scrolling.reference-list-menu').css('display', 'none');
  106. $selectBranch.find('.reference .text').removeClass('black');
  107. $($(this).data('target')).css('display', 'block');
  108. $(this).find('.text').addClass('black');
  109. return false;
  110. });
  111. }
  112. function initLabelEdit() {
  113. // Create label
  114. const $newLabelPanel = $('.new-label.segment');
  115. $('.new-label.button').on('click', () => {
  116. $newLabelPanel.show();
  117. });
  118. $('.new-label.segment .cancel').on('click', () => {
  119. $newLabelPanel.hide();
  120. });
  121. $('.color-picker').each(function () {
  122. $(this).minicolors();
  123. });
  124. $('.precolors .color').on('click', function () {
  125. const color_hex = $(this).data('color-hex');
  126. $('.color-picker').val(color_hex);
  127. $('.minicolors-swatch-color').css('background-color', color_hex);
  128. });
  129. $('.edit-label-button').on('click', function () {
  130. $('#label-modal-id').val($(this).data('id'));
  131. $('.edit-label .new-label-input').val($(this).data('title'));
  132. $('.edit-label .new-label-desc-input').val($(this).data('description'));
  133. $('.edit-label .color-picker').val($(this).data('color'));
  134. $('.minicolors-swatch-color').css('background-color', $(this).data('color'));
  135. $('.edit-label.modal').modal({
  136. onApprove() {
  137. $('.edit-label.form').trigger('submit');
  138. }
  139. }).modal('show');
  140. return false;
  141. });
  142. }
  143. function updateIssuesMeta(url, action, issueIds, elementId, isAdd) {
  144. return new Promise(((resolve) => {
  145. $.ajax({
  146. type: 'POST',
  147. url,
  148. data: {
  149. _csrf: csrf,
  150. action,
  151. issue_ids: issueIds,
  152. id: elementId,
  153. is_add: isAdd
  154. },
  155. success: resolve
  156. });
  157. }));
  158. }
  159. function initRepoStatusChecker() {
  160. const migrating = $('#repo_migrating');
  161. $('#repo_migrating_failed').hide();
  162. if (migrating) {
  163. const repo_name = migrating.attr('repo');
  164. if (typeof repo_name === 'undefined') {
  165. return;
  166. }
  167. $.ajax({
  168. type: 'GET',
  169. url: `${AppSubUrl}/${repo_name}/status`,
  170. data: {
  171. _csrf: csrf,
  172. },
  173. complete(xhr) {
  174. if (xhr.status === 200) {
  175. if (xhr.responseJSON) {
  176. if (xhr.responseJSON.status === 0) {
  177. window.location.reload();
  178. return;
  179. }
  180. setTimeout(() => {
  181. initRepoStatusChecker();
  182. }, 2000);
  183. return;
  184. }
  185. }
  186. $('#repo_migrating_progress').hide();
  187. $('#repo_migrating_failed').show();
  188. }
  189. });
  190. }
  191. }
  192. function initReactionSelector(parent) {
  193. let reactions = '';
  194. if (!parent) {
  195. parent = $(document);
  196. reactions = '.reactions > ';
  197. }
  198. parent.find(`${reactions}a.label`).popup({position: 'bottom left', metadata: {content: 'title', title: 'none'}});
  199. parent.find(`.select-reaction > .menu > .item, ${reactions}a.label`).on('click', function (e) {
  200. const vm = this;
  201. e.preventDefault();
  202. if ($(this).hasClass('disabled')) return;
  203. const actionURL = $(this).hasClass('item') ? $(this).closest('.select-reaction').data('action-url') : $(this).data('action-url');
  204. const url = `${actionURL}/${$(this).hasClass('blue') ? 'unreact' : 'react'}`;
  205. $.ajax({
  206. type: 'POST',
  207. url,
  208. data: {
  209. _csrf: csrf,
  210. content: $(this).data('content')
  211. }
  212. }).done((resp) => {
  213. if (resp && (resp.html || resp.empty)) {
  214. const content = $(vm).closest('.content');
  215. let react = content.find('.segment.reactions');
  216. if (!resp.empty && react.length > 0) {
  217. react.remove();
  218. }
  219. if (!resp.empty) {
  220. react = $('<div class="ui attached segment reactions"></div>');
  221. const attachments = content.find('.segment.bottom:first');
  222. if (attachments.length > 0) {
  223. react.insertBefore(attachments);
  224. } else {
  225. react.appendTo(content);
  226. }
  227. react.html(resp.html);
  228. const hasEmoji = react.find('.has-emoji');
  229. for (let i = 0; i < hasEmoji.length; i++) {
  230. emojify.run(hasEmoji.get(i));
  231. }
  232. react.find('.dropdown').dropdown();
  233. initReactionSelector(react);
  234. }
  235. }
  236. });
  237. });
  238. }
  239. function insertAtCursor(field, value) {
  240. if (field.selectionStart || field.selectionStart === 0) {
  241. const startPos = field.selectionStart;
  242. const endPos = field.selectionEnd;
  243. field.value = field.value.substring(0, startPos) + value + field.value.substring(endPos, field.value.length);
  244. field.selectionStart = startPos + value.length;
  245. field.selectionEnd = startPos + value.length;
  246. } else {
  247. field.value += value;
  248. }
  249. }
  250. function replaceAndKeepCursor(field, oldval, newval) {
  251. if (field.selectionStart || field.selectionStart === 0) {
  252. const startPos = field.selectionStart;
  253. const endPos = field.selectionEnd;
  254. field.value = field.value.replace(oldval, newval);
  255. field.selectionStart = startPos + newval.length - oldval.length;
  256. field.selectionEnd = endPos + newval.length - oldval.length;
  257. } else {
  258. field.value = field.value.replace(oldval, newval);
  259. }
  260. }
  261. function retrieveImageFromClipboardAsBlob(pasteEvent, callback) {
  262. if (!pasteEvent.clipboardData) {
  263. return;
  264. }
  265. const {items} = pasteEvent.clipboardData;
  266. if (typeof items === 'undefined') {
  267. return;
  268. }
  269. for (let i = 0; i < items.length; i++) {
  270. if (!items[i].type.includes('image')) continue;
  271. const blob = items[i].getAsFile();
  272. if (typeof (callback) === 'function') {
  273. pasteEvent.preventDefault();
  274. pasteEvent.stopPropagation();
  275. callback(blob);
  276. }
  277. }
  278. }
  279. function uploadFile(file, callback) {
  280. const xhr = new XMLHttpRequest();
  281. xhr.addEventListener('load', () => {
  282. if (xhr.status === 200) {
  283. callback(xhr.responseText);
  284. }
  285. });
  286. xhr.open('post', `${AppSubUrl}/attachments`, true);
  287. xhr.setRequestHeader('X-Csrf-Token', csrf);
  288. const formData = new FormData();
  289. formData.append('file', file, file.name);
  290. xhr.send(formData);
  291. }
  292. function reload() {
  293. window.location.reload();
  294. }
  295. function initImagePaste(target) {
  296. target.each(function () {
  297. const field = this;
  298. field.addEventListener('paste', (event) => {
  299. retrieveImageFromClipboardAsBlob(event, (img) => {
  300. const name = img.name.substr(0, img.name.lastIndexOf('.'));
  301. insertAtCursor(field, `![${name}]()`);
  302. uploadFile(img, (res) => {
  303. const data = JSON.parse(res);
  304. replaceAndKeepCursor(field, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
  305. const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
  306. $('.files').append(input);
  307. });
  308. });
  309. }, false);
  310. });
  311. }
  312. function initSimpleMDEImagePaste(simplemde, files) {
  313. simplemde.codemirror.on('paste', (_, event) => {
  314. retrieveImageFromClipboardAsBlob(event, (img) => {
  315. const name = img.name.substr(0, img.name.lastIndexOf('.'));
  316. uploadFile(img, (res) => {
  317. const data = JSON.parse(res);
  318. const pos = simplemde.codemirror.getCursor();
  319. simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos);
  320. const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
  321. files.append(input);
  322. });
  323. });
  324. });
  325. }
  326. let autoSimpleMDE;
  327. function initCommentForm() {
  328. if ($('.comment.form').length === 0) {
  329. return;
  330. }
  331. autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
  332. initBranchSelector();
  333. initCommentPreviewTab($('.comment.form'));
  334. initImagePaste($('.comment.form textarea'));
  335. // Listsubmit
  336. function initListSubmits(selector, outerSelector) {
  337. const $list = $(`.ui.${outerSelector}.list`);
  338. const $noSelect = $list.find('.no-select');
  339. const $listMenu = $(`.${selector} .menu`);
  340. let hasLabelUpdateAction = $listMenu.data('action') === 'update';
  341. const labels = {};
  342. $(`.${selector}`).dropdown('setting', 'onHide', () => {
  343. hasLabelUpdateAction = $listMenu.data('action') === 'update'; // Update the var
  344. if (hasLabelUpdateAction) {
  345. const promises = [];
  346. Object.keys(labels).forEach((elementId) => {
  347. const label = labels[elementId];
  348. const promise = updateIssuesMeta(
  349. label['update-url'],
  350. label.action,
  351. label['issue-id'],
  352. elementId,
  353. label['is-checked']
  354. );
  355. promises.push(promise);
  356. });
  357. Promise.all(promises).then(reload);
  358. }
  359. });
  360. $listMenu.find('.item:not(.no-select)').on('click', function () {
  361. // we don't need the action attribute when updating assignees
  362. if (selector === 'select-assignees-modify' || selector === 'select-reviewers-modify') {
  363. // UI magic. We need to do this here, otherwise it would destroy the functionality of
  364. // adding/removing labels
  365. if ($(this).data('can-change') === 'block') {
  366. return false;
  367. }
  368. if ($(this).hasClass('checked')) {
  369. $(this).removeClass('checked');
  370. $(this).find('.octicon-check').addClass('invisible');
  371. $(this).data('is-checked', 'remove');
  372. } else {
  373. $(this).addClass('checked');
  374. $(this).find('.octicon-check').removeClass('invisible');
  375. $(this).data('is-checked', 'add');
  376. }
  377. updateIssuesMeta(
  378. $listMenu.data('update-url'),
  379. '',
  380. $listMenu.data('issue-id'),
  381. $(this).data('id'),
  382. $(this).data('is-checked')
  383. );
  384. $listMenu.data('action', 'update'); // Update to reload the page when we updated items
  385. return false;
  386. }
  387. if ($(this).hasClass('checked')) {
  388. $(this).removeClass('checked');
  389. $(this).find('.octicon-check').addClass('invisible');
  390. if (hasLabelUpdateAction) {
  391. if (!($(this).data('id') in labels)) {
  392. labels[$(this).data('id')] = {
  393. 'update-url': $listMenu.data('update-url'),
  394. action: 'detach',
  395. 'issue-id': $listMenu.data('issue-id'),
  396. };
  397. } else {
  398. delete labels[$(this).data('id')];
  399. }
  400. }
  401. } else {
  402. $(this).addClass('checked');
  403. $(this).find('.octicon-check').removeClass('invisible');
  404. if (hasLabelUpdateAction) {
  405. if (!($(this).data('id') in labels)) {
  406. labels[$(this).data('id')] = {
  407. 'update-url': $listMenu.data('update-url'),
  408. action: 'attach',
  409. 'issue-id': $listMenu.data('issue-id'),
  410. };
  411. } else {
  412. delete labels[$(this).data('id')];
  413. }
  414. }
  415. }
  416. const listIds = [];
  417. $(this).parent().find('.item').each(function () {
  418. if ($(this).hasClass('checked')) {
  419. listIds.push($(this).data('id'));
  420. $($(this).data('id-selector')).removeClass('hide');
  421. } else {
  422. $($(this).data('id-selector')).addClass('hide');
  423. }
  424. });
  425. if (listIds.length === 0) {
  426. $noSelect.removeClass('hide');
  427. } else {
  428. $noSelect.addClass('hide');
  429. }
  430. $($(this).parent().data('id')).val(listIds.join(','));
  431. return false;
  432. });
  433. $listMenu.find('.no-select.item').on('click', function () {
  434. if (hasLabelUpdateAction || selector === 'select-assignees-modify') {
  435. updateIssuesMeta(
  436. $listMenu.data('update-url'),
  437. 'clear',
  438. $listMenu.data('issue-id'),
  439. '',
  440. ''
  441. ).then(reload);
  442. }
  443. $(this).parent().find('.item').each(function () {
  444. $(this).removeClass('checked');
  445. $(this).find('.octicon').addClass('invisible');
  446. $(this).data('is-checked', 'remove');
  447. });
  448. $list.find('.item').each(function () {
  449. $(this).addClass('hide');
  450. });
  451. $noSelect.removeClass('hide');
  452. $($(this).parent().data('id')).val('');
  453. });
  454. }
  455. // Init labels and assignees
  456. initListSubmits('select-label', 'labels');
  457. initListSubmits('select-assignees', 'assignees');
  458. initListSubmits('select-assignees-modify', 'assignees');
  459. initListSubmits('select-reviewers-modify', 'assignees');
  460. function selectItem(select_id, input_id) {
  461. const $menu = $(`${select_id} .menu`);
  462. const $list = $(`.ui${select_id}.list`);
  463. const hasUpdateAction = $menu.data('action') === 'update';
  464. $menu.find('.item:not(.no-select)').on('click', function () {
  465. $(this).parent().find('.item').each(function () {
  466. $(this).removeClass('selected active');
  467. });
  468. $(this).addClass('selected active');
  469. if (hasUpdateAction) {
  470. updateIssuesMeta(
  471. $menu.data('update-url'),
  472. '',
  473. $menu.data('issue-id'),
  474. $(this).data('id'),
  475. $(this).data('is-checked')
  476. ).then(reload);
  477. }
  478. switch (input_id) {
  479. case '#milestone_id':
  480. $list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>${
  481. htmlEncode($(this).text())}</a>`);
  482. break;
  483. case '#assignee_id':
  484. $list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>` +
  485. `<img class="ui avatar image" src=${$(this).data('avatar')}>${
  486. htmlEncode($(this).text())}</a>`);
  487. }
  488. $(`.ui${select_id}.list .no-select`).addClass('hide');
  489. $(input_id).val($(this).data('id'));
  490. });
  491. $menu.find('.no-select.item').on('click', function () {
  492. $(this).parent().find('.item:not(.no-select)').each(function () {
  493. $(this).removeClass('selected active');
  494. });
  495. if (hasUpdateAction) {
  496. updateIssuesMeta(
  497. $menu.data('update-url'),
  498. '',
  499. $menu.data('issue-id'),
  500. $(this).data('id'),
  501. $(this).data('is-checked')
  502. ).then(reload);
  503. }
  504. $list.find('.selected').html('');
  505. $list.find('.no-select').removeClass('hide');
  506. $(input_id).val('');
  507. });
  508. }
  509. // Milestone and assignee
  510. selectItem('.select-milestone', '#milestone_id');
  511. selectItem('.select-assignee', '#assignee_id');
  512. }
  513. function initInstall() {
  514. if ($('.install').length === 0) {
  515. return;
  516. }
  517. if ($('#db_host').val() === '') {
  518. $('#db_host').val('127.0.0.1:3306');
  519. $('#db_user').val('gitea');
  520. $('#db_name').val('gitea');
  521. }
  522. // Database type change detection.
  523. $('#db_type').on('change', function () {
  524. const sqliteDefault = 'data/gitea.db';
  525. const tidbDefault = 'data/gitea_tidb';
  526. const dbType = $(this).val();
  527. if (dbType === 'SQLite3') {
  528. $('#sql_settings').hide();
  529. $('#pgsql_settings').hide();
  530. $('#mysql_settings').hide();
  531. $('#sqlite_settings').show();
  532. if (dbType === 'SQLite3' && $('#db_path').val() === tidbDefault) {
  533. $('#db_path').val(sqliteDefault);
  534. }
  535. return;
  536. }
  537. const dbDefaults = {
  538. MySQL: '127.0.0.1:3306',
  539. PostgreSQL: '127.0.0.1:5432',
  540. MSSQL: '127.0.0.1:1433'
  541. };
  542. $('#sqlite_settings').hide();
  543. $('#sql_settings').show();
  544. $('#pgsql_settings').toggle(dbType === 'PostgreSQL');
  545. $('#mysql_settings').toggle(dbType === 'MySQL');
  546. $.each(dbDefaults, (_type, defaultHost) => {
  547. if ($('#db_host').val() === defaultHost) {
  548. $('#db_host').val(dbDefaults[dbType]);
  549. return false;
  550. }
  551. });
  552. });
  553. // TODO: better handling of exclusive relations.
  554. $('#offline-mode input').on('change', function () {
  555. if ($(this).is(':checked')) {
  556. $('#disable-gravatar').checkbox('check');
  557. $('#federated-avatar-lookup').checkbox('uncheck');
  558. }
  559. });
  560. $('#disable-gravatar input').on('change', function () {
  561. if ($(this).is(':checked')) {
  562. $('#federated-avatar-lookup').checkbox('uncheck');
  563. } else {
  564. $('#offline-mode').checkbox('uncheck');
  565. }
  566. });
  567. $('#federated-avatar-lookup input').on('change', function () {
  568. if ($(this).is(':checked')) {
  569. $('#disable-gravatar').checkbox('uncheck');
  570. $('#offline-mode').checkbox('uncheck');
  571. }
  572. });
  573. $('#enable-openid-signin input').on('change', function () {
  574. if ($(this).is(':checked')) {
  575. if (!$('#disable-registration input').is(':checked')) {
  576. $('#enable-openid-signup').checkbox('check');
  577. }
  578. } else {
  579. $('#enable-openid-signup').checkbox('uncheck');
  580. }
  581. });
  582. $('#disable-registration input').on('change', function () {
  583. if ($(this).is(':checked')) {
  584. $('#enable-captcha').checkbox('uncheck');
  585. $('#enable-openid-signup').checkbox('uncheck');
  586. } else {
  587. $('#enable-openid-signup').checkbox('check');
  588. }
  589. });
  590. $('#enable-captcha input').on('change', function () {
  591. if ($(this).is(':checked')) {
  592. $('#disable-registration').checkbox('uncheck');
  593. }
  594. });
  595. }
  596. function initIssueComments() {
  597. if ($('.repository.view.issue .timeline').length === 0) return;
  598. $('.re-request-review').on('click', function (event) {
  599. const url = $(this).data('update-url');
  600. const issueId = $(this).data('issue-id');
  601. const id = $(this).data('id');
  602. const isChecked = $(this).data('is-checked');
  603. event.preventDefault();
  604. updateIssuesMeta(
  605. url,
  606. '',
  607. issueId,
  608. id,
  609. isChecked
  610. ).then(reload);
  611. });
  612. $(document).on('click', (event) => {
  613. const urlTarget = $(':target');
  614. if (urlTarget.length === 0) return;
  615. const urlTargetId = urlTarget.attr('id');
  616. if (!urlTargetId) return;
  617. if (!/^(issue|pull)(comment)?-\d+$/.test(urlTargetId)) return;
  618. const $target = $(event.target);
  619. if ($target.closest(`#${urlTargetId}`).length === 0) {
  620. const scrollPosition = $(window).scrollTop();
  621. window.location.hash = '';
  622. $(window).scrollTop(scrollPosition);
  623. window.history.pushState(null, null, ' ');
  624. }
  625. });
  626. }
  627. async function initRepository() {
  628. if ($('.repository').length === 0) {
  629. return;
  630. }
  631. function initFilterSearchDropdown(selector) {
  632. const $dropdown = $(selector);
  633. $dropdown.dropdown({
  634. fullTextSearch: true,
  635. selectOnKeydown: false,
  636. onChange(_text, _value, $choice) {
  637. if ($choice.data('url')) {
  638. window.location.href = $choice.data('url');
  639. }
  640. },
  641. message: {noResults: $dropdown.data('no-results')}
  642. });
  643. }
  644. // File list and commits
  645. if ($('.repository.file.list').length > 0 || ('.repository.commits').length > 0) {
  646. initFilterBranchTagDropdown('.choose.reference .dropdown');
  647. }
  648. // Wiki
  649. if ($('.repository.wiki.view').length > 0) {
  650. initFilterSearchDropdown('.choose.page .dropdown');
  651. }
  652. // Options
  653. if ($('.repository.settings.options').length > 0) {
  654. // Enable or select internal/external wiki system and issue tracker.
  655. $('.enable-system').on('change', function () {
  656. if (this.checked) {
  657. $($(this).data('target')).removeClass('disabled');
  658. if (!$(this).data('context')) $($(this).data('context')).addClass('disabled');
  659. } else {
  660. $($(this).data('target')).addClass('disabled');
  661. if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled');
  662. }
  663. });
  664. $('.enable-system-radio').on('change', function () {
  665. if (this.value === 'false') {
  666. $($(this).data('target')).addClass('disabled');
  667. if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).removeClass('disabled');
  668. } else if (this.value === 'true') {
  669. $($(this).data('target')).removeClass('disabled');
  670. if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).addClass('disabled');
  671. }
  672. });
  673. }
  674. // Labels
  675. if ($('.repository.labels').length > 0) {
  676. initLabelEdit();
  677. }
  678. // Milestones
  679. if ($('.repository.new.milestone').length > 0) {
  680. const $datepicker = $('.milestone.datepicker');
  681. await initDateTimePicker($datepicker.data('lang'));
  682. $datepicker.datetimepicker({
  683. inline: true,
  684. timepicker: false,
  685. startDate: $datepicker.data('start-date'),
  686. onSelectDate(date) {
  687. $('#deadline').val(date.toISOString().substring(0, 10));
  688. },
  689. });
  690. $('#clear-date').on('click', () => {
  691. $('#deadline').val('');
  692. return false;
  693. });
  694. }
  695. // Issues
  696. if ($('.repository.view.issue').length > 0) {
  697. // Edit issue title
  698. const $issueTitle = $('#issue-title');
  699. const $editInput = $('#edit-title-input input');
  700. const editTitleToggle = function () {
  701. $issueTitle.toggle();
  702. $('.not-in-edit').toggle();
  703. $('#edit-title-input').toggle();
  704. $('#pull-desc').toggle();
  705. $('#pull-desc-edit').toggle();
  706. $('.in-edit').toggle();
  707. $editInput.focus();
  708. return false;
  709. };
  710. const changeBranchSelect = function () {
  711. const selectionTextField = $('#pull-target-branch');
  712. const baseName = selectionTextField.data('basename');
  713. const branchNameNew = $(this).data('branch');
  714. const branchNameOld = selectionTextField.data('branch');
  715. // Replace branch name to keep translation from HTML template
  716. selectionTextField.html(selectionTextField.html().replace(
  717. `${baseName}:${branchNameOld}`,
  718. `${baseName}:${branchNameNew}`
  719. ));
  720. selectionTextField.data('branch', branchNameNew); // update branch name in setting
  721. };
  722. $('#branch-select > .item').on('click', changeBranchSelect);
  723. $('#edit-title').on('click', editTitleToggle);
  724. $('#cancel-edit-title').on('click', editTitleToggle);
  725. $('#save-edit-title').on('click', editTitleToggle).on('click', function () {
  726. const pullrequest_targetbranch_change = function (update_url) {
  727. const targetBranch = $('#pull-target-branch').data('branch');
  728. const $branchTarget = $('#branch_target');
  729. if (targetBranch === $branchTarget.text()) {
  730. return false;
  731. }
  732. $.post(update_url, {
  733. _csrf: csrf,
  734. target_branch: targetBranch
  735. }).success((data) => {
  736. $branchTarget.text(data.base_branch);
  737. }).always(() => {
  738. reload();
  739. });
  740. };
  741. const pullrequest_target_update_url = $(this).data('target-update-url');
  742. if ($editInput.val().length === 0 || $editInput.val() === $issueTitle.text()) {
  743. $editInput.val($issueTitle.text());
  744. pullrequest_targetbranch_change(pullrequest_target_update_url);
  745. } else {
  746. $.post($(this).data('update-url'), {
  747. _csrf: csrf,
  748. title: $editInput.val()
  749. }, (data) => {
  750. $editInput.val(data.title);
  751. $issueTitle.text(data.title);
  752. pullrequest_targetbranch_change(pullrequest_target_update_url);
  753. reload();
  754. });
  755. }
  756. return false;
  757. });
  758. // Issue Comments
  759. initIssueComments();
  760. // Issue/PR Context Menus
  761. $('.context-dropdown').dropdown({
  762. action: 'hide'
  763. });
  764. // Quote reply
  765. $('.quote-reply').on('click', function (event) {
  766. $(this).closest('.dropdown').find('.menu').toggle('visible');
  767. const target = $(this).data('target');
  768. const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
  769. const content = `> ${quote}\n\n`;
  770. let $content;
  771. if ($(this).hasClass('quote-reply-diff')) {
  772. const $parent = $(this).closest('.comment-code-cloud');
  773. $parent.find('button.comment-form-reply').trigger('click');
  774. $content = $parent.find('[name="content"]');
  775. if ($content.val() !== '') {
  776. $content.val(`${$content.val()}\n\n${content}`);
  777. } else {
  778. $content.val(`${content}`);
  779. }
  780. $content.focus();
  781. } else if (autoSimpleMDE !== null) {
  782. if (autoSimpleMDE.value() !== '') {
  783. autoSimpleMDE.value(`${autoSimpleMDE.value()}\n\n${content}`);
  784. } else {
  785. autoSimpleMDE.value(`${content}`);
  786. }
  787. }
  788. event.preventDefault();
  789. });
  790. // Edit issue or comment content
  791. $('.edit-content').on('click', async function (event) {
  792. $(this).closest('.dropdown').find('.menu').toggle('visible');
  793. const $segment = $(this).closest('.header').next();
  794. const $editContentZone = $segment.find('.edit-content-zone');
  795. const $renderContent = $segment.find('.render-content');
  796. const $rawContent = $segment.find('.raw-content');
  797. let $textarea;
  798. let $simplemde;
  799. // Setup new form
  800. if ($editContentZone.html().length === 0) {
  801. $editContentZone.html($('#edit-content-form').html());
  802. $textarea = $editContentZone.find('textarea');
  803. issuesTribute.attach($textarea.get());
  804. emojiTribute.attach($textarea.get());
  805. let dz;
  806. const $dropzone = $editContentZone.find('.dropzone');
  807. const $files = $editContentZone.find('.comment-files');
  808. if ($dropzone.length > 0) {
  809. $dropzone.data('saved', false);
  810. const filenameDict = {};
  811. dz = await createDropzone($dropzone[0], {
  812. url: $dropzone.data('upload-url'),
  813. headers: {'X-Csrf-Token': csrf},
  814. maxFiles: $dropzone.data('max-file'),
  815. maxFilesize: $dropzone.data('max-size'),
  816. acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
  817. addRemoveLinks: true,
  818. dictDefaultMessage: $dropzone.data('default-message'),
  819. dictInvalidFileType: $dropzone.data('invalid-input-type'),
  820. dictFileTooBig: $dropzone.data('file-too-big'),
  821. dictRemoveFile: $dropzone.data('remove-file'),
  822. init() {
  823. this.on('success', (file, data) => {
  824. filenameDict[file.name] = {
  825. uuid: data.uuid,
  826. submitted: false
  827. };
  828. const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
  829. $files.append(input);
  830. });
  831. this.on('removedfile', (file) => {
  832. if (!(file.name in filenameDict)) {
  833. return;
  834. }
  835. $(`#${filenameDict[file.name].uuid}`).remove();
  836. if ($dropzone.data('remove-url') && $dropzone.data('csrf') && !filenameDict[file.name].submitted) {
  837. $.post($dropzone.data('remove-url'), {
  838. file: filenameDict[file.name].uuid,
  839. _csrf: $dropzone.data('csrf')
  840. });
  841. }
  842. });
  843. this.on('submit', () => {
  844. $.each(filenameDict, (name) => {
  845. filenameDict[name].submitted = true;
  846. });
  847. });
  848. this.on('reload', () => {
  849. $.getJSON($editContentZone.data('attachment-url'), (data) => {
  850. dz.removeAllFiles(true);
  851. $files.empty();
  852. $.each(data, function () {
  853. const imgSrc = `${$dropzone.data('upload-url')}/${this.uuid}`;
  854. dz.emit('addedfile', this);
  855. dz.emit('thumbnail', this, imgSrc);
  856. dz.emit('complete', this);
  857. dz.files.push(this);
  858. filenameDict[this.name] = {
  859. submitted: true,
  860. uuid: this.uuid
  861. };
  862. $dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
  863. const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
  864. $files.append(input);
  865. });
  866. });
  867. });
  868. }
  869. });
  870. dz.emit('reload');
  871. }
  872. // Give new write/preview data-tab name to distinguish from others
  873. const $editContentForm = $editContentZone.find('.ui.comment.form');
  874. const $tabMenu = $editContentForm.find('.tabular.menu');
  875. $tabMenu.attr('data-write', $editContentZone.data('write'));
  876. $tabMenu.attr('data-preview', $editContentZone.data('preview'));
  877. $tabMenu.find('.write.item').attr('data-tab', $editContentZone.data('write'));
  878. $tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
  879. $editContentForm.find('.write.segment').attr('data-tab', $editContentZone.data('write'));
  880. $editContentForm.find('.preview.segment').attr('data-tab', $editContentZone.data('preview'));
  881. $simplemde = setCommentSimpleMDE($textarea);
  882. commentMDEditors[$editContentZone.data('write')] = $simplemde;
  883. initCommentPreviewTab($editContentForm);
  884. initSimpleMDEImagePaste($simplemde, $files);
  885. $editContentZone.find('.cancel.button').on('click', () => {
  886. $renderContent.show();
  887. $editContentZone.hide();
  888. dz.emit('reload');
  889. });
  890. $editContentZone.find('.save.button').on('click', () => {
  891. $renderContent.show();
  892. $editContentZone.hide();
  893. const $attachments = $files.find('[name=files]').map(function () {
  894. return $(this).val();
  895. }).get();
  896. $.post($editContentZone.data('update-url'), {
  897. _csrf: csrf,
  898. content: $textarea.val(),
  899. context: $editContentZone.data('context'),
  900. files: $attachments
  901. }, (data) => {
  902. if (data.length === 0) {
  903. $renderContent.html($('#no-content').html());
  904. } else {
  905. $renderContent.html(data.content);
  906. emojify.run($renderContent[0]);
  907. $('pre code', $renderContent[0]).each(function () {
  908. highlight(this);
  909. });
  910. }
  911. const $content = $segment.parent();
  912. if (!$content.find('.ui.small.images').length) {
  913. if (data.attachments !== '') {
  914. $content.append(
  915. '<div class="ui bottom attached segment"><div class="ui small images"></div></div>'
  916. );
  917. $content.find('.ui.small.images').html(data.attachments);
  918. }
  919. } else if (data.attachments === '') {
  920. $content.find('.ui.small.images').parent().remove();
  921. } else {
  922. $content.find('.ui.small.images').html(data.attachments);
  923. }
  924. dz.emit('submit');
  925. dz.emit('reload');
  926. });
  927. });
  928. } else {
  929. $textarea = $segment.find('textarea');
  930. $simplemde = commentMDEditors[$editContentZone.data('write')];
  931. }
  932. // Show write/preview tab and copy raw content as needed
  933. $editContentZone.show();
  934. $renderContent.hide();
  935. if ($textarea.val().length === 0) {
  936. $textarea.val($rawContent.text());
  937. $simplemde.value($rawContent.text());
  938. }
  939. $textarea.focus();
  940. $simplemde.codemirror.focus();
  941. event.preventDefault();
  942. });
  943. // Delete comment
  944. $('.delete-comment').on('click', function () {
  945. const $this = $(this);
  946. if (window.confirm($this.data('locale'))) {
  947. $.post($this.data('url'), {
  948. _csrf: csrf
  949. }).success(() => {
  950. $(`#${$this.data('comment-id')}`).remove();
  951. });
  952. }
  953. return false;
  954. });
  955. // Change status
  956. const $statusButton = $('#status-button');
  957. $('#comment-form .edit_area').on('keyup', function () {
  958. if ($(this).val().length === 0) {
  959. $statusButton.text($statusButton.data('status'));
  960. } else {
  961. $statusButton.text($statusButton.data('status-and-comment'));
  962. }
  963. });
  964. $statusButton.on('click', () => {
  965. $('#status').val($statusButton.data('status-val'));
  966. $('#comment-form').trigger('submit');
  967. });
  968. // Pull Request merge button
  969. const $mergeButton = $('.merge-button > button');
  970. $mergeButton.on('click', function (e) {
  971. e.preventDefault();
  972. $(`.${$(this).data('do')}-fields`).show();
  973. $(this).parent().hide();
  974. });
  975. $('.merge-button > .dropdown').dropdown({
  976. onChange(_text, _value, $choice) {
  977. if ($choice.data('do')) {
  978. $mergeButton.find('.button-text').text($choice.text());
  979. $mergeButton.data('do', $choice.data('do'));
  980. }
  981. }
  982. });
  983. $('.merge-cancel').on('click', function (e) {
  984. e.preventDefault();
  985. $(this).closest('.form').hide();
  986. $mergeButton.parent().show();
  987. });
  988. initReactionSelector();
  989. }
  990. // Diff
  991. if ($('.repository.diff').length > 0) {
  992. $('.diff-counter').each(function () {
  993. const $item = $(this);
  994. const addLine = $item.find('span[data-line].add').data('line');
  995. const delLine = $item.find('span[data-line].del').data('line');
  996. const addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
  997. $item.find('.bar .add').css('width', `${addPercent}%`);
  998. });
  999. }
  1000. // Quick start and repository home
  1001. $('#repo-clone-ssh').on('click', function () {
  1002. $('.clone-url').text($(this).data('link'));
  1003. $('#repo-clone-url').val($(this).data('link'));
  1004. $(this).addClass('blue');
  1005. $('#repo-clone-https').removeClass('blue');
  1006. localStorage.setItem('repo-clone-protocol', 'ssh');
  1007. });
  1008. $('#repo-clone-https').on('click', function () {
  1009. $('.clone-url').text($(this).data('link'));
  1010. $('#repo-clone-url').val($(this).data('link'));
  1011. $(this).addClass('blue');
  1012. $('#repo-clone-ssh').removeClass('blue');
  1013. localStorage.setItem('repo-clone-protocol', 'https');
  1014. });
  1015. $('#repo-clone-url').on('click', function () {
  1016. $(this).select();
  1017. });
  1018. // Pull request
  1019. const $repoComparePull = $('.repository.compare.pull');
  1020. if ($repoComparePull.length > 0) {
  1021. initFilterSearchDropdown('.choose.branch .dropdown');
  1022. // show pull request form
  1023. $repoComparePull.find('button.show-form').on('click', function (e) {
  1024. e.preventDefault();
  1025. $repoComparePull.find('.pullrequest-form').show();
  1026. autoSimpleMDE.codemirror.refresh();
  1027. $(this).parent().hide();
  1028. });
  1029. }
  1030. // Branches
  1031. if ($('.repository.settings.branches').length > 0) {
  1032. initFilterSearchDropdown('.protected-branches .dropdown');
  1033. $('.enable-protection, .enable-whitelist, .enable-statuscheck').on('change', function () {
  1034. if (this.checked) {
  1035. $($(this).data('target')).removeClass('disabled');
  1036. } else {
  1037. $($(this).data('target')).addClass('disabled');
  1038. }
  1039. });
  1040. $('.disable-whitelist').on('change', function () {
  1041. if (this.checked) {
  1042. $($(this).data('target')).addClass('disabled');
  1043. }
  1044. });
  1045. }
  1046. // Language stats
  1047. if ($('.language-stats').length > 0) {
  1048. $('.language-stats').on('click', (e) => {
  1049. e.preventDefault();
  1050. $('.language-stats-details, .repository-menu').slideToggle();
  1051. });
  1052. }
  1053. }
  1054. function initMigration() {
  1055. const toggleMigrations = function () {
  1056. const authUserName = $('#auth_username').val();
  1057. const cloneAddr = $('#clone_addr').val();
  1058. if (!$('#mirror').is(':checked') && (authUserName && authUserName.length > 0) &&
  1059. (cloneAddr !== undefined && (cloneAddr.startsWith('https://github.com') || cloneAddr.startsWith('http://github.com')))) {
  1060. $('#migrate_items').show();
  1061. } else {
  1062. $('#migrate_items').hide();
  1063. }
  1064. };
  1065. toggleMigrations();
  1066. $('#clone_addr').on('input', toggleMigrations);
  1067. $('#auth_username').on('input', toggleMigrations);
  1068. $('#mirror').on('change', toggleMigrations);
  1069. }
  1070. function initPullRequestReview() {
  1071. $('.show-outdated').on('click', function (e) {
  1072. e.preventDefault();
  1073. const id = $(this).data('comment');
  1074. $(this).addClass('hide');
  1075. $(`#code-comments-${id}`).removeClass('hide');
  1076. $(`#code-preview-${id}`).removeClass('hide');
  1077. $(`#hide-outdated-${id}`).removeClass('hide');
  1078. });
  1079. $('.hide-outdated').on('click', function (e) {
  1080. e.preventDefault();
  1081. const id = $(this).data('comment');
  1082. $(this).addClass('hide');
  1083. $(`#code-comments-${id}`).addClass('hide');
  1084. $(`#code-preview-${id}`).addClass('hide');
  1085. $(`#show-outdated-${id}`).removeClass('hide');
  1086. });
  1087. $('button.comment-form-reply').on('click', function (e) {
  1088. e.preventDefault();
  1089. $(this).hide();
  1090. const form = $(this).parent().find('.comment-form');
  1091. form.removeClass('hide');
  1092. assingMenuAttributes(form.find('.menu'));
  1093. });
  1094. // The following part is only for diff views
  1095. if ($('.repository.pull.diff').length === 0) {
  1096. return;
  1097. }
  1098. $('.diff-detail-box.ui.sticky').sticky();
  1099. $('.btn-review').on('click', function (e) {
  1100. e.preventDefault();
  1101. $(this).closest('.dropdown').find('.menu').toggle('visible');
  1102. }).closest('.dropdown').find('.link.close')
  1103. .on('click', function (e) {
  1104. e.preventDefault();
  1105. $(this).closest('.menu').toggle('visible');
  1106. });
  1107. $('.code-view .lines-code,.code-view .lines-num')
  1108. .on('mouseenter', function () {
  1109. const parent = $(this).closest('td');
  1110. $(this).closest('tr').addClass(
  1111. parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old') ? 'focus-lines-old' : 'focus-lines-new'
  1112. );
  1113. })
  1114. .on('mouseleave', function () {
  1115. $(this).closest('tr').removeClass('focus-lines-new focus-lines-old');
  1116. });
  1117. $('.add-code-comment').on('click', function (e) {
  1118. // https://github.com/go-gitea/gitea/issues/4745
  1119. if ($(e.target).hasClass('btn-add-single')) {
  1120. return;
  1121. }
  1122. e.preventDefault();
  1123. const isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
  1124. const side = $(this).data('side');
  1125. const idx = $(this).data('idx');
  1126. const path = $(this).data('path');
  1127. const form = $('#pull_review_add_comment').html();
  1128. const tr = $(this).closest('tr');
  1129. let ntr = tr.next();
  1130. if (!ntr.hasClass('add-comment')) {
  1131. ntr = $(`<tr class="add-comment">${
  1132. isSplit ? '<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>' :
  1133. '<td class="lines-num"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left add-comment-right"></td>'
  1134. }</tr>`);
  1135. tr.after(ntr);
  1136. }
  1137. const td = ntr.find(`.add-comment-${side}`);
  1138. let commentCloud = td.find('.comment-code-cloud');
  1139. if (commentCloud.length === 0) {
  1140. td.html(form);
  1141. commentCloud = td.find('.comment-code-cloud');
  1142. assingMenuAttributes(commentCloud.find('.menu'));
  1143. td.find("input[name='line']").val(idx);
  1144. td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
  1145. td.find("input[name='path']").val(path);
  1146. }
  1147. commentCloud.find('textarea').focus();
  1148. });
  1149. }
  1150. function assingMenuAttributes(menu) {
  1151. const id = Math.floor(Math.random() * Math.floor(1000000));
  1152. menu.attr('data-write', menu.attr('data-write') + id);
  1153. menu.attr('data-preview', menu.attr('data-preview') + id);
  1154. menu.find('.item').each(function () {
  1155. const tab = $(this).attr('data-tab') + id;
  1156. $(this).attr('data-tab', tab);
  1157. });
  1158. menu.parent().find("*[data-tab='write']").attr('data-tab', `write${id}`);
  1159. menu.parent().find("*[data-tab='preview']").attr('data-tab', `preview${id}`);
  1160. initCommentPreviewTab(menu.parent('.form'));
  1161. return id;
  1162. }
  1163. function initRepositoryCollaboration() {
  1164. // Change collaborator access mode
  1165. $('.access-mode.menu .item').on('click', function () {
  1166. const $menu = $(this).parent();
  1167. $.post($menu.data('url'), {
  1168. _csrf: csrf,
  1169. uid: $menu.data('uid'),
  1170. mode: $(this).data('value')
  1171. });
  1172. });
  1173. }
  1174. function initTeamSettings() {
  1175. // Change team access mode
  1176. $('.organization.new.team input[name=permission]').on('change', () => {
  1177. const val = $('input[name=permission]:checked', '.organization.new.team').val();
  1178. if (val === 'admin') {
  1179. $('.organization.new.team .team-units').hide();
  1180. } else {
  1181. $('.organization.new.team .team-units').show();
  1182. }
  1183. });
  1184. }
  1185. function initWikiForm() {
  1186. const $editArea = $('.repository.wiki textarea#edit_area');
  1187. let sideBySideChanges = 0;
  1188. let sideBySideTimeout = null;
  1189. if ($editArea.length > 0) {
  1190. const simplemde = new SimpleMDE({
  1191. autoDownloadFontAwesome: false,
  1192. element: $editArea[0],
  1193. forceSync: true,
  1194. previewRender(plainText, preview) { // Async method
  1195. setTimeout(() => {
  1196. // FIXME: still send render request when return back to edit mode
  1197. const render = function () {
  1198. sideBySideChanges = 0;
  1199. if (sideBySideTimeout !== null) {
  1200. clearTimeout(sideBySideTimeout);
  1201. sideBySideTimeout = null;
  1202. }
  1203. $.post($editArea.data('url'), {
  1204. _csrf: csrf,
  1205. mode: 'gfm',
  1206. context: $editArea.data('context'),
  1207. text: plainText
  1208. }, (data) => {
  1209. preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
  1210. emojify.run($('.editor-preview')[0]);
  1211. $(preview).find('pre code').each((_, e) => {
  1212. highlight(e);
  1213. });
  1214. });
  1215. };
  1216. if (!simplemde.isSideBySideActive()) {
  1217. render();
  1218. } else {
  1219. // delay preview by keystroke counting
  1220. sideBySideChanges++;
  1221. if (sideBySideChanges > 10) {
  1222. render();
  1223. }
  1224. // or delay preview by timeout
  1225. if (sideBySideTimeout !== null) {
  1226. clearTimeout(sideBySideTimeout);
  1227. sideBySideTimeout = null;
  1228. }
  1229. sideBySideTimeout = setTimeout(render, 600);
  1230. }
  1231. }, 0);
  1232. if (!simplemde.isSideBySideActive()) {
  1233. return 'Loading...';
  1234. }
  1235. return preview.innerHTML;
  1236. },
  1237. renderingConfig: {
  1238. singleLineBreaks: false
  1239. },
  1240. indentWithTabs: false,
  1241. tabSize: 4,
  1242. spellChecker: false,
  1243. toolbar: ['bold', 'italic', 'strikethrough', '|',
  1244. 'heading-1', 'heading-2', 'heading-3', 'heading-bigger', 'heading-smaller', '|',
  1245. {
  1246. name: 'code-inline',
  1247. action(e) {
  1248. const cm = e.codemirror;
  1249. const selection = cm.getSelection();
  1250. cm.replaceSelection(`\`${selection}\``);
  1251. if (!selection) {
  1252. const cursorPos = cm.getCursor();
  1253. cm.setCursor(cursorPos.line, cursorPos.ch - 1);
  1254. }
  1255. cm.focus();
  1256. },
  1257. className: 'fa fa-angle-right',
  1258. title: 'Add Inline Code',
  1259. }, 'code', 'quote', '|', {
  1260. name: 'checkbox-empty',
  1261. action(e) {
  1262. const cm = e.codemirror;
  1263. cm.replaceSelection(`\n- [ ] ${cm.getSelection()}`);
  1264. cm.focus();
  1265. },
  1266. className: 'fa fa-square-o',
  1267. title: 'Add Checkbox (empty)',
  1268. },
  1269. {
  1270. name: 'checkbox-checked',
  1271. action(e) {
  1272. const cm = e.codemirror;
  1273. cm.replaceSelection(`\n- [x] ${cm.getSelection()}`);
  1274. cm.focus();
  1275. },
  1276. className: 'fa fa-check-square-o',
  1277. title: 'Add Checkbox (checked)',
  1278. }, '|',
  1279. 'unordered-list', 'ordered-list', '|',
  1280. 'link', 'image', 'table', 'horizontal-rule', '|',
  1281. 'clean-block', 'preview', 'fullscreen', 'side-by-side', '|',
  1282. {
  1283. name: 'revert-to-textarea',
  1284. action(e) {
  1285. e.toTextArea();
  1286. },
  1287. className: 'fa fa-file',
  1288. title: 'Revert to simple textarea',
  1289. },
  1290. ]
  1291. });
  1292. $(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
  1293. setTimeout(() => {
  1294. const $bEdit = $('.repository.wiki.new .previewtabs a[data-tab="write"]');
  1295. const $bPrev = $('.repository.wiki.new .previewtabs a[data-tab="preview"]');
  1296. const $toolbar = $('.editor-toolbar');
  1297. const $bPreview = $('.editor-toolbar a.fa-eye');
  1298. const $bSideBySide = $('.editor-toolbar a.fa-columns');
  1299. $bEdit.on('click', () => {
  1300. if ($toolbar.hasClass('disabled-for-preview')) {
  1301. $bPreview.trigger('click');
  1302. }
  1303. });
  1304. $bPrev.on('click', () => {
  1305. if (!$toolbar.hasClass('disabled-for-preview')) {
  1306. $bPreview.trigger('click');
  1307. }
  1308. });
  1309. $bPreview.on('click', () => {
  1310. setTimeout(() => {
  1311. if ($toolbar.hasClass('disabled-for-preview')) {
  1312. if ($bEdit.hasClass('active')) {
  1313. $bEdit.removeClass('active');
  1314. }
  1315. if (!$bPrev.hasClass('active')) {
  1316. $bPrev.addClass('active');
  1317. }
  1318. } else {
  1319. if (!$bEdit.hasClass('active')) {
  1320. $bEdit.addClass('active');
  1321. }
  1322. if ($bPrev.hasClass('active')) {
  1323. $bPrev.removeClass('active');
  1324. }
  1325. }
  1326. }, 0);
  1327. });
  1328. $bSideBySide.on('click', () => {
  1329. sideBySideChanges = 10;
  1330. });
  1331. }, 0);
  1332. }
  1333. }
  1334. // Adding function to get the cursor position in a text field to jQuery object.
  1335. $.fn.getCursorPosition = function () {
  1336. const el = $(this).get(0);
  1337. let pos = 0;
  1338. if ('selectionStart' in el) {
  1339. pos = el.selectionStart;
  1340. } else if ('selection' in document) {
  1341. el.focus();
  1342. const Sel = document.selection.createRange();
  1343. const SelLength = document.selection.createRange().text.length;
  1344. Sel.moveStart('character', -el.value.length);
  1345. pos = Sel.text.length - SelLength;
  1346. }
  1347. return pos;
  1348. };
  1349. function setSimpleMDE($editArea) {
  1350. if (codeMirrorEditor) {
  1351. codeMirrorEditor.toTextArea();
  1352. codeMirrorEditor = null;
  1353. }
  1354. if (simpleMDEditor) {
  1355. return true;
  1356. }
  1357. simpleMDEditor = new SimpleMDE({
  1358. autoDownloadFontAwesome: false,
  1359. element: $editArea[0],
  1360. forceSync: true,
  1361. renderingConfig: {
  1362. singleLineBreaks: false
  1363. },
  1364. indentWithTabs: false,
  1365. tabSize: 4,
  1366. spellChecker: false,
  1367. previewRender(plainText, preview) { // Async method
  1368. setTimeout(() => {
  1369. // FIXME: still send render request when return back to edit mode
  1370. $.post($editArea.data('url'), {
  1371. _csrf: csrf,
  1372. mode: 'gfm',
  1373. context: $editArea.data('context'),
  1374. text: plainText
  1375. }, (data) => {
  1376. preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
  1377. emojify.run($('.editor-preview')[0]);
  1378. });
  1379. }, 0);
  1380. return 'Loading...';
  1381. },
  1382. toolbar: ['bold', 'italic', 'strikethrough', '|',
  1383. 'heading-1', 'heading-2', 'heading-3', 'heading-bigger', 'heading-smaller', '|',
  1384. 'code', 'quote', '|',
  1385. 'unordered-list', 'ordered-list', '|',
  1386. 'link', 'image', 'table', 'horizontal-rule', '|',
  1387. 'clean-block', 'preview', 'fullscreen', 'side-by-side', '|',
  1388. {
  1389. name: 'revert-to-textarea',
  1390. action(e) {
  1391. e.toTextArea();
  1392. },
  1393. className: 'fa fa-file',
  1394. title: 'Revert to simple textarea',
  1395. },
  1396. ]
  1397. });
  1398. $(simpleMDEditor.codemirror.getInputField()).addClass('js-quick-submit');
  1399. return true;
  1400. }
  1401. function setCommentSimpleMDE($editArea) {
  1402. const simplemde = new SimpleMDE({
  1403. autoDownloadFontAwesome: false,
  1404. element: $editArea[0],
  1405. forceSync: true,
  1406. renderingConfig: {
  1407. singleLineBreaks: false
  1408. },
  1409. indentWithTabs: false,
  1410. tabSize: 4,
  1411. spellChecker: false,
  1412. toolbar: ['bold', 'italic', 'strikethrough', '|',
  1413. 'heading-1', 'heading-2', 'heading-3', 'heading-bigger', 'heading-smaller', '|',
  1414. 'code', 'quote', '|',
  1415. 'unordered-list', 'ordered-list', '|',
  1416. 'link', 'image', 'table', 'horizontal-rule', '|',
  1417. 'clean-block', '|',
  1418. {
  1419. name: 'revert-to-textarea',
  1420. action(e) {
  1421. e.toTextArea();
  1422. },
  1423. className: 'fa fa-file',
  1424. title: 'Revert to simple textarea',
  1425. },
  1426. ]
  1427. });
  1428. $(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
  1429. simplemde.codemirror.setOption('extraKeys', {
  1430. Enter: () => {
  1431. if (!(issuesTribute.isActive || emojiTribute.isActive)) {
  1432. return CodeMirror.Pass;
  1433. }
  1434. },
  1435. Backspace: (cm) => {
  1436. if (cm.getInputField().trigger) {
  1437. cm.getInputField().trigger('input');
  1438. }
  1439. cm.execCommand('delCharBefore');
  1440. }
  1441. });
  1442. issuesTribute.attach(simplemde.codemirror.getInputField());
  1443. emojiTribute.attach(simplemde.codemirror.getInputField());
  1444. return simplemde;
  1445. }
  1446. function setCodeMirror($editArea) {
  1447. if (simpleMDEditor) {
  1448. simpleMDEditor.toTextArea();
  1449. simpleMDEditor = null;
  1450. }
  1451. if (codeMirrorEditor) {
  1452. return true;
  1453. }
  1454. codeMirrorEditor = CodeMirror.fromTextArea($editArea[0], {
  1455. lineNumbers: true
  1456. });
  1457. codeMirrorEditor.on('change', (cm, _change) => {
  1458. $editArea.val(cm.getValue());
  1459. });
  1460. return true;
  1461. }
  1462. function initEditor() {
  1463. $('.js-quick-pull-choice-option').on('change', function () {
  1464. if ($(this).val() === 'commit-to-new-branch') {
  1465. $('.quick-pull-branch-name').show();
  1466. $('.quick-pull-branch-name input').prop('required', true);
  1467. } else {
  1468. $('.quick-pull-branch-name').hide();
  1469. $('.quick-pull-branch-name input').prop('required', false);
  1470. }
  1471. $('#commit-button').text($(this).attr('button_text'));
  1472. });
  1473. const $editFilename = $('#file-name');
  1474. $editFilename.on('keyup', function (e) {
  1475. const $section = $('.breadcrumb span.section');
  1476. const $divider = $('.breadcrumb div.divider');
  1477. let value;
  1478. let parts;
  1479. if (e.keyCode === 8) {
  1480. if ($(this).getCursorPosition() === 0) {
  1481. if ($section.length > 0) {
  1482. value = $section.last().find('a').text();
  1483. $(this).val(value + $(this).val());
  1484. $(this)[0].setSelectionRange(value.length, value.length);
  1485. $section.last().remove();
  1486. $divider.last().remove();
  1487. }
  1488. }
  1489. }
  1490. if (e.keyCode === 191) {
  1491. parts = $(this).val().split('/');
  1492. for (let i = 0; i < parts.length; ++i) {
  1493. value = parts[i];
  1494. if (i < parts.length - 1) {
  1495. if (value.length) {
  1496. $(`<span class="section"><a href="#">${value}</a></span>`).insertBefore($(this));
  1497. $('<div class="divider"> / </div>').insertBefore($(this));
  1498. }
  1499. } else {
  1500. $(this).val(value);
  1501. }
  1502. $(this)[0].setSelectionRange(0, 0);
  1503. }
  1504. }
  1505. parts = [];
  1506. $('.breadcrumb span.section').each(function () {
  1507. const element = $(this);
  1508. if (element.find('a').length) {
  1509. parts.push(element.find('a').text());
  1510. } else {
  1511. parts.push(element.text());
  1512. }
  1513. });
  1514. if ($(this).val()) parts.push($(this).val());
  1515. $('#tree_path').val(parts.join('/'));
  1516. }).trigger('keyup');
  1517. const $editArea = $('.repository.editor textarea#edit_area');
  1518. if (!$editArea.length) return;
  1519. const markdownFileExts = $editArea.data('markdown-file-exts').split(',');
  1520. const lineWrapExtensions = $editArea.data('line-wrap-extensions').split(',');
  1521. $editFilename.on('keyup', () => {
  1522. const val = $editFilename.val();
  1523. let mode, spec, extension, extWithDot, dataUrl, apiCall;
  1524. extension = extWithDot = '';
  1525. const m = /.+\.([^.]+)$/.exec(val);
  1526. if (m) {
  1527. extension = m[1];
  1528. extWithDot = `.${extension}`;
  1529. }
  1530. const info = CodeMirror.findModeByExtension(extension);
  1531. const previewLink = $('a[data-tab=preview]');
  1532. if (info) {
  1533. mode = info.mode;
  1534. spec = info.mime;
  1535. apiCall = mode;
  1536. } else {
  1537. apiCall = extension;
  1538. }
  1539. if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.includes(apiCall)) {
  1540. dataUrl = previewLink.data('url');
  1541. previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, `$1/${mode}`));
  1542. previewLink.show();
  1543. } else {
  1544. previewLink.hide();
  1545. }
  1546. // If this file is a Markdown extensions, we will load that editor and return
  1547. if (markdownFileExts.includes(extWithDot)) {
  1548. if (setSimpleMDE($editArea)) {
  1549. return;
  1550. }
  1551. }
  1552. // Else we are going to use CodeMirror
  1553. if (!codeMirrorEditor && !setCodeMirror($editArea)) {
  1554. return;
  1555. }
  1556. if (mode) {
  1557. codeMirrorEditor.setOption('mode', spec);
  1558. CodeMirror.autoLoadMode(codeMirrorEditor, mode);
  1559. }
  1560. if (lineWrapExtensions.includes(extWithDot)) {
  1561. codeMirrorEditor.setOption('lineWrapping', true);
  1562. } else {
  1563. codeMirrorEditor.setOption('lineWrapping', false);
  1564. }
  1565. // get the filename without any folder
  1566. let value = $editFilename.val();
  1567. if (value.length === 0) {
  1568. return;
  1569. }
  1570. value = value.split('/');
  1571. value = value[value.length - 1];
  1572. $.getJSON($editFilename.data('ec-url-prefix') + value, (editorconfig) => {
  1573. if (editorconfig.indent_style === 'tab') {
  1574. codeMirrorEditor.setOption('indentWithTabs', true);
  1575. codeMirrorEditor.setOption('extraKeys', {});
  1576. } else {
  1577. codeMirrorEditor.setOption('indentWithTabs', false);
  1578. // required because CodeMirror doesn't seems to use spaces correctly for {"indentWithTabs": false}:
  1579. // - https://github.com/codemirror/CodeMirror/issues/988
  1580. // - https://codemirror.net/doc/manual.html#keymaps
  1581. codeMirrorEditor.setOption('extraKeys', {
  1582. Tab(cm) {
  1583. const spaces = new Array(parseInt(cm.getOption('indentUnit')) + 1).join(' ');
  1584. cm.replaceSelection(spaces);
  1585. }
  1586. });
  1587. }
  1588. codeMirrorEditor.setOption('indentUnit', editorconfig.indent_size || 4);
  1589. codeMirrorEditor.setOption('tabSize', editorconfig.tab_width || 4);
  1590. });
  1591. }).trigger('keyup');
  1592. // Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
  1593. // to enable or disable the commit button
  1594. const $commitButton = $('#commit-button');
  1595. const $editForm = $('.ui.edit.form');
  1596. const dirtyFileClass = 'dirty-file';
  1597. // Disabling the button at the start
  1598. $commitButton.prop('disabled', true);
  1599. // Registering a custom listener for the file path and the file content
  1600. $editForm.areYouSure({
  1601. silent: true,
  1602. dirtyClass: dirtyFileClass,
  1603. fieldSelector: ':input:not(.commit-form-wrapper :input)',
  1604. change() {
  1605. const dirty = $(this).hasClass(dirtyFileClass);
  1606. $commitButton.prop('disabled', !dirty);
  1607. }
  1608. });
  1609. $commitButton.on('click', (event) => {
  1610. // A modal which asks if an empty file should be committed
  1611. if ($editArea.val().length === 0) {
  1612. $('#edit-empty-content-modal').modal({
  1613. onApprove() {
  1614. $('.edit.form').trigger('submit');
  1615. }
  1616. }).modal('show');
  1617. event.preventDefault();
  1618. }
  1619. });
  1620. }
  1621. function initOrganization() {
  1622. if ($('.organization').length === 0) {
  1623. return;
  1624. }
  1625. // Options
  1626. if ($('.organization.settings.options').length > 0) {
  1627. $('#org_name').on('keyup', function () {
  1628. const $prompt = $('#org-name-change-prompt');
  1629. if ($(this).val().toString().toLowerCase() !== $(this).data('org-name').toString().toLowerCase()) {
  1630. $prompt.show();
  1631. } else {
  1632. $prompt.hide();
  1633. }
  1634. });
  1635. }
  1636. // Labels
  1637. if ($('.organization.settings.labels').length > 0) {
  1638. initLabelEdit();
  1639. }
  1640. }
  1641. function initUserSettings() {
  1642. // Options
  1643. if ($('.user.settings.profile').length > 0) {
  1644. $('#username').on('keyup', function () {
  1645. const $prompt = $('#name-change-prompt');
  1646. if ($(this).val().toString().toLowerCase() !== $(this).data('name').toString().toLowerCase()) {
  1647. $prompt.show();
  1648. } else {
  1649. $prompt.hide();
  1650. }
  1651. });
  1652. }
  1653. }
  1654. function initGithook() {
  1655. if ($('.edit.githook').length === 0) {
  1656. return;
  1657. }
  1658. CodeMirror.autoLoadMode(CodeMirror.fromTextArea($('#content')[0], {
  1659. lineNumbers: true,
  1660. mode: 'shell'
  1661. }), 'shell');
  1662. }
  1663. function initWebhook() {
  1664. if ($('.new.webhook').length === 0) {
  1665. return;
  1666. }
  1667. $('.events.checkbox input').on('change', function () {
  1668. if ($(this).is(':checked')) {
  1669. $('.events.fields').show();
  1670. }
  1671. });
  1672. $('.non-events.checkbox input').on('change', function () {
  1673. if ($(this).is(':checked')) {
  1674. $('.events.fields').hide();
  1675. }
  1676. });
  1677. const updateContentType = function () {
  1678. const visible = $('#http_method').val() === 'POST';
  1679. $('#content_type').parent().parent()[visible ? 'show' : 'hide']();
  1680. };
  1681. updateContentType();
  1682. $('#http_method').on('change', () => {
  1683. updateContentType();
  1684. });
  1685. // Test delivery
  1686. $('#test-delivery').on('click', function () {
  1687. const $this = $(this);
  1688. $this.addClass('loading disabled');
  1689. $.post($this.data('link'), {
  1690. _csrf: csrf
  1691. }).done(
  1692. setTimeout(() => {
  1693. window.location.href = $this.data('redirect');
  1694. }, 5000)
  1695. );
  1696. });
  1697. }
  1698. function initAdmin() {
  1699. if ($('.admin').length === 0) {
  1700. return;
  1701. }
  1702. // New user
  1703. if ($('.admin.new.user').length > 0 || $('.admin.edit.user').length > 0) {
  1704. $('#login_type').on('change', function () {
  1705. if ($(this).val().substring(0, 1) === '0') {
  1706. $('#login_name').removeAttr('required');
  1707. $('.non-local').hide();
  1708. $('.local').show();
  1709. $('#user_name').focus();
  1710. if ($(this).data('password') === 'required') {
  1711. $('#password').attr('required', 'required');
  1712. }
  1713. } else {
  1714. $('#login_name').attr('required', 'required');
  1715. $('.non-local').show();
  1716. $('.local').hide();
  1717. $('#login_name').focus();
  1718. $('#password').removeAttr('required');
  1719. }
  1720. });
  1721. }
  1722. function onSecurityProtocolChange() {
  1723. if ($('#security_protocol').val() > 0) {
  1724. $('.has-tls').show();
  1725. } else {
  1726. $('.has-tls').hide();
  1727. }
  1728. }
  1729. function onUsePagedSearchChange() {
  1730. if ($('#use_paged_search').prop('checked')) {
  1731. $('.search-page-size').show()
  1732. .find('input').attr('required', 'required');
  1733. } else {
  1734. $('.search-page-size').hide()
  1735. .find('input').removeAttr('required');
  1736. }
  1737. }
  1738. function onOAuth2Change() {
  1739. $('.open_id_connect_auto_discovery_url, .oauth2_use_custom_url').hide();
  1740. $('.open_id_connect_auto_discovery_url input[required]').removeAttr('required');
  1741. const provider = $('#oauth2_provider').val();
  1742. switch (provider) {
  1743. case 'github':
  1744. case 'gitlab':
  1745. case 'gitea':
  1746. case 'nextcloud':
  1747. $('.oauth2_use_custom_url').show();
  1748. break;
  1749. case 'openidConnect':
  1750. $('.open_id_connect_auto_discovery_url input').attr('required', 'required');
  1751. $('.open_id_connect_auto_discovery_url').show();
  1752. break;
  1753. }
  1754. onOAuth2UseCustomURLChange();
  1755. }
  1756. function onOAuth2UseCustomURLChange() {
  1757. const provider = $('#oauth2_provider').val();
  1758. $('.oauth2_use_custom_url_field').hide();
  1759. $('.oauth2_use_custom_url_field input[required]').removeAttr('required');
  1760. if ($('#oauth2_use_custom_url').is(':checked')) {
  1761. $('#oauth2_token_url').val($(`#${provider}_token_url`).val());
  1762. $('#oauth2_auth_url').val($(`#${provider}_auth_url`).val());
  1763. $('#oauth2_profile_url').val($(`#${provider}_profile_url`).val());
  1764. $('#oauth2_email_url').val($(`#${provider}_email_url`).val());
  1765. switch (provider) {
  1766. case 'github':
  1767. $('.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input, .oauth2_email_url input').attr('required', 'required');
  1768. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url, .oauth2_email_url').show();
  1769. break;
  1770. case 'nextcloud':
  1771. case 'gitea':
  1772. case 'gitlab':
  1773. $('.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input').attr('required', 'required');
  1774. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url').show();
  1775. $('#oauth2_email_url').val('');
  1776. break;
  1777. }
  1778. }
  1779. }
  1780. // New authentication
  1781. if ($('.admin.new.authentication').length > 0) {
  1782. $('#auth_type').on('change', function () {
  1783. $('.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls, .search-page-size, .sspi').hide();
  1784. $('.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]').removeAttr('required');
  1785. $('.binddnrequired').removeClass('required');
  1786. const authType = $(this).val();
  1787. switch (authType) {
  1788. case '2': // LDAP
  1789. $('.ldap').show();
  1790. $('.binddnrequired input, .ldap div.required:not(.dldap) input').attr('required', 'required');
  1791. $('.binddnrequired').addClass('required');
  1792. break;
  1793. case '3': // SMTP
  1794. $('.smtp').show();
  1795. $('.has-tls').show();
  1796. $('.smtp div.required input, .has-tls').attr('required', 'required');
  1797. break;
  1798. case '4': // PAM
  1799. $('.pam').show();
  1800. $('.pam input').attr('required', 'required');
  1801. break;
  1802. case '5': // LDAP
  1803. $('.dldap').show();
  1804. $('.dldap div.required:not(.ldap) input').attr('required', 'required');
  1805. break;
  1806. case '6': // OAuth2
  1807. $('.oauth2').show();
  1808. $('.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input').attr('required', 'required');
  1809. onOAuth2Change();
  1810. break;
  1811. case '7': // SSPI
  1812. $('.sspi').show();
  1813. $('.sspi div.required input').attr('required', 'required');
  1814. break;
  1815. }
  1816. if (authType === '2' || authType === '5') {
  1817. onSecurityProtocolChange();
  1818. }
  1819. if (authType === '2') {
  1820. onUsePagedSearchChange();
  1821. }
  1822. });
  1823. $('#auth_type').trigger('change');
  1824. $('#security_protocol').on('change', onSecurityProtocolChange);
  1825. $('#use_paged_search').on('change', onUsePagedSearchChange);
  1826. $('#oauth2_provider').on('change', onOAuth2Change);
  1827. $('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
  1828. }
  1829. // Edit authentication
  1830. if ($('.admin.edit.authentication').length > 0) {
  1831. const authType = $('#auth_type').val();
  1832. if (authType === '2' || authType === '5') {
  1833. $('#security_protocol').on('change', onSecurityProtocolChange);
  1834. if (authType === '2') {
  1835. $('#use_paged_search').on('change', onUsePagedSearchChange);
  1836. }
  1837. } else if (authType === '6') {
  1838. $('#oauth2_provider').on('change', onOAuth2Change);
  1839. $('#oauth2_use_custom_url').on('change', onOAuth2UseCustomURLChange);
  1840. onOAuth2Change();
  1841. }
  1842. }
  1843. // Notice
  1844. if ($('.admin.notice')) {
  1845. const $detailModal = $('#detail-modal');
  1846. // Attach view detail modals
  1847. $('.view-detail').on('click', function () {
  1848. $detailModal.find('.content p').text($(this).data('content'));
  1849. $detailModal.modal('show');
  1850. return false;
  1851. });
  1852. // Select actions
  1853. const $checkboxes = $('.select.table .ui.checkbox');
  1854. $('.select.action').on('click', function () {
  1855. switch ($(this).data('action')) {
  1856. case 'select-all':
  1857. $checkboxes.checkbox('check');
  1858. break;
  1859. case 'deselect-all':
  1860. $checkboxes.checkbox('uncheck');
  1861. break;
  1862. case 'inverse':
  1863. $checkboxes.checkbox('toggle');
  1864. break;
  1865. }
  1866. });
  1867. $('#delete-selection').on('click', function () {
  1868. const $this = $(this);
  1869. $this.addClass('loading disabled');
  1870. const ids = [];
  1871. $checkboxes.each(function () {
  1872. if ($(this).checkbox('is checked')) {
  1873. ids.push($(this).data('id'));
  1874. }
  1875. });
  1876. $.post($this.data('link'), {
  1877. _csrf: csrf,
  1878. ids
  1879. }).done(() => {
  1880. window.location.href = $this.data('redirect');
  1881. });
  1882. });
  1883. }
  1884. }
  1885. function buttonsClickOnEnter() {
  1886. $('.ui.button').on('keypress', function (e) {
  1887. if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar
  1888. $(this).trigger('click');
  1889. }
  1890. });
  1891. }
  1892. function searchUsers() {
  1893. const $searchUserBox = $('#search-user-box');
  1894. $searchUserBox.search({
  1895. minCharacters: 2,
  1896. apiSettings: {
  1897. url: `${AppSubUrl}/api/v1/users/search?q={query}`,
  1898. onResponse(response) {
  1899. const items = [];
  1900. $.each(response.data, (_i, item) => {
  1901. let title = item.login;
  1902. if (item.full_name && item.full_name.length > 0) {
  1903. title += ` (${htmlEncode(item.full_name)})`;
  1904. }
  1905. items.push({
  1906. title,
  1907. image: item.avatar_url
  1908. });
  1909. });
  1910. return {results: items};
  1911. }
  1912. },
  1913. searchFields: ['login', 'full_name'],
  1914. showNoResults: false
  1915. });
  1916. }
  1917. function searchTeams() {
  1918. const $searchTeamBox = $('#search-team-box');
  1919. $searchTeamBox.search({
  1920. minCharacters: 2,
  1921. apiSettings: {
  1922. url: `${AppSubUrl}/api/v1/orgs/${$searchTeamBox.data('org')}/teams/search?q={query}`,
  1923. headers: {'X-Csrf-Token': csrf},
  1924. onResponse(response) {
  1925. const items = [];
  1926. $.each(response.data, (_i, item) => {
  1927. const title = `${item.name} (${item.permission} access)`;
  1928. items.push({
  1929. title,
  1930. });
  1931. });
  1932. return {results: items};
  1933. }
  1934. },
  1935. searchFields: ['name', 'description'],
  1936. showNoResults: false
  1937. });
  1938. }
  1939. function searchRepositories() {
  1940. const $searchRepoBox = $('#search-repo-box');
  1941. $searchRepoBox.search({
  1942. minCharacters: 2,
  1943. apiSettings: {
  1944. url: `${AppSubUrl}/api/v1/repos/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
  1945. onResponse(response) {
  1946. const items = [];
  1947. $.each(response.data, (_i, item) => {
  1948. items.push({
  1949. title: item.full_name.split('/')[1],
  1950. description: item.full_name
  1951. });
  1952. });
  1953. return {results: items};
  1954. }
  1955. },
  1956. searchFields: ['full_name'],
  1957. showNoResults: false
  1958. });
  1959. }
  1960. function initCodeView() {
  1961. if ($('.code-view .linenums').length > 0) {
  1962. $(document).on('click', '.lines-num span', function (e) {
  1963. const $select = $(this);
  1964. const $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
  1965. selectRange($list, $list.filter(`[rel=${$select.attr('id')}]`), (e.shiftKey ? $list.filter('.active').eq(0) : null));
  1966. deSelect();
  1967. });
  1968. $(window).on('hashchange', () => {
  1969. let m = window.location.hash.match(/^#(L\d+)-(L\d+)$/);
  1970. const $list = $('.code-view ol.linenums > li');
  1971. let $first;
  1972. if (m) {
  1973. $first = $list.filter(`.${m[1]}`);
  1974. selectRange($list, $first, $list.filter(`.${m[2]}`));
  1975. $('html, body').scrollTop($first.offset().top - 200);
  1976. return;
  1977. }
  1978. m = window.location.hash.match(/^#(L|n)(\d+)$/);
  1979. if (m) {
  1980. $first = $list.filter(`.L${m[2]}`);
  1981. selectRange($list, $first);
  1982. $('html, body').scrollTop($first.offset().top - 200);
  1983. }
  1984. }).trigger('hashchange');
  1985. }
  1986. $('.fold-code').on('click', ({target}) => {
  1987. const box = target.closest('.file-content');
  1988. const folded = box.dataset.folded !== 'true';
  1989. target.classList.add(`fa-chevron-${folded ? 'right' : 'down'}`);
  1990. target.classList.remove(`fa-chevron-${folded ? 'down' : 'right'}`);
  1991. box.dataset.folded = String(folded);
  1992. });
  1993. function insertBlobExcerpt(e) {
  1994. const $blob = $(e.target);
  1995. const $row = $blob.parent().parent();
  1996. $.get(`${$blob.data('url')}?${$blob.data('query')}&anchor=${$blob.data('anchor')}`, (blob) => {
  1997. $row.replaceWith(blob);
  1998. $(`[data-anchor="${$blob.data('anchor')}"]`).on('click', (e) => { insertBlobExcerpt(e) });
  1999. $('.diff-detail-box.ui.sticky').sticky();
  2000. });
  2001. }
  2002. $('.ui.blob-excerpt').on('click', (e) => { insertBlobExcerpt(e) });
  2003. }
  2004. function initU2FAuth() {
  2005. if ($('#wait-for-key').length === 0) {
  2006. return;
  2007. }
  2008. u2fApi.ensureSupport()
  2009. .then(() => {
  2010. $.getJSON(`${AppSubUrl}/user/u2f/challenge`).success((req) => {
  2011. u2fApi.sign(req.appId, req.challenge, req.registeredKeys, 30)
  2012. .then(u2fSigned)
  2013. .catch((err) => {
  2014. if (err === undefined) {
  2015. u2fError(1);
  2016. return;
  2017. }
  2018. u2fError(err.metaData.code);
  2019. });
  2020. });
  2021. }).catch(() => {
  2022. // Fallback in case browser do not support U2F
  2023. window.location.href = `${AppSubUrl}/user/two_factor`;
  2024. });
  2025. }
  2026. function u2fSigned(resp) {
  2027. $.ajax({
  2028. url: `${AppSubUrl}/user/u2f/sign`,
  2029. type: 'POST',
  2030. headers: {'X-Csrf-Token': csrf},
  2031. data: JSON.stringify(resp),
  2032. contentType: 'application/json; charset=utf-8',
  2033. }).done((res) => {
  2034. window.location.replace(res);
  2035. }).fail(() => {
  2036. u2fError(1);
  2037. });
  2038. }
  2039. function u2fRegistered(resp) {
  2040. if (checkError(resp)) {
  2041. return;
  2042. }
  2043. $.ajax({
  2044. url: `${AppSubUrl}/user/settings/security/u2f/register`,
  2045. type: 'POST',
  2046. headers: {'X-Csrf-Token': csrf},
  2047. data: JSON.stringify(resp),
  2048. contentType: 'application/json; charset=utf-8',
  2049. success() {
  2050. reload();
  2051. },
  2052. fail() {
  2053. u2fError(1);
  2054. }
  2055. });
  2056. }
  2057. function checkError(resp) {
  2058. if (!('errorCode' in resp)) {
  2059. return false;
  2060. }
  2061. if (resp.errorCode === 0) {
  2062. return false;
  2063. }
  2064. u2fError(resp.errorCode);
  2065. return true;
  2066. }
  2067. function u2fError(errorType) {
  2068. const u2fErrors = {
  2069. browser: $('#unsupported-browser'),
  2070. 1: $('#u2f-error-1'),
  2071. 2: $('#u2f-error-2'),
  2072. 3: $('#u2f-error-3'),
  2073. 4: $('#u2f-error-4'),
  2074. 5: $('.u2f-error-5')
  2075. };
  2076. u2fErrors[errorType].removeClass('hide');
  2077. Object.keys(u2fErrors).forEach((type) => {
  2078. if (type !== errorType) {
  2079. u2fErrors[type].addClass('hide');
  2080. }
  2081. });
  2082. $('#u2f-error').modal('show');
  2083. }
  2084. function initU2FRegister() {
  2085. $('#register-device').modal({allowMultiple: false});
  2086. $('#u2f-error').modal({allowMultiple: false});
  2087. $('#register-security-key').on('click', (e) => {
  2088. e.preventDefault();
  2089. u2fApi.ensureSupport()
  2090. .then(u2fRegisterRequest)
  2091. .catch(() => {
  2092. u2fError('browser');
  2093. });
  2094. });
  2095. }
  2096. function u2fRegisterRequest() {
  2097. $.post(`${AppSubUrl}/user/settings/security/u2f/request_register`, {
  2098. _csrf: csrf,
  2099. name: $('#nickname').val()
  2100. }).success((req) => {
  2101. $('#nickname').closest('div.field').removeClass('error');
  2102. $('#register-device').modal('show');
  2103. if (req.registeredKeys === null) {
  2104. req.registeredKeys = [];
  2105. }
  2106. u2fApi.register(req.appId, req.registerRequests, req.registeredKeys, 30)
  2107. .then(u2fRegistered)
  2108. .catch((reason) => {
  2109. if (reason === undefined) {
  2110. u2fError(1);
  2111. return;
  2112. }
  2113. u2fError(reason.metaData.code);
  2114. });
  2115. }).fail((xhr) => {
  2116. if (xhr.status === 409) {
  2117. $('#nickname').closest('div.field').addClass('error');
  2118. }
  2119. });
  2120. }
  2121. function initWipTitle() {
  2122. $('.title_wip_desc > a').on('click', (e) => {
  2123. e.preventDefault();
  2124. const $issueTitle = $('#issue_title');
  2125. $issueTitle.focus();
  2126. const value = $issueTitle.val().trim().toUpperCase();
  2127. for (const i in wipPrefixes) {
  2128. if (value.startsWith(wipPrefixes[i].toUpperCase())) {
  2129. return;
  2130. }
  2131. }
  2132. $issueTitle.val(`${wipPrefixes[0]} ${$issueTitle.val()}`);
  2133. });
  2134. }
  2135. function initTemplateSearch() {
  2136. const $repoTemplate = $('#repo_template');
  2137. const checkTemplate = function () {
  2138. const $templateUnits = $('#template_units');
  2139. const $nonTemplate = $('#non_template');
  2140. if ($repoTemplate.val() !== '' && $repoTemplate.val() !== '0') {
  2141. $templateUnits.show();
  2142. $nonTemplate.hide();
  2143. } else {
  2144. $templateUnits.hide();
  2145. $nonTemplate.show();
  2146. }
  2147. };
  2148. $repoTemplate.on('change', checkTemplate);
  2149. checkTemplate();
  2150. const changeOwner = function () {
  2151. $('#repo_template_search')
  2152. .dropdown({
  2153. apiSettings: {
  2154. url: `${AppSubUrl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
  2155. onResponse(response) {
  2156. const filteredResponse = {success: true, results: []};
  2157. filteredResponse.results.push({
  2158. name: '',
  2159. value: ''
  2160. });
  2161. // Parse the response from the api to work with our dropdown
  2162. $.each(response.data, (_r, repo) => {
  2163. filteredResponse.results.push({
  2164. name: htmlEncode(repo.full_name),
  2165. value: repo.id
  2166. });
  2167. });
  2168. return filteredResponse;
  2169. },
  2170. cache: false,
  2171. },
  2172. fullTextSearch: true
  2173. });
  2174. };
  2175. $('#uid').on('change', changeOwner);
  2176. changeOwner();
  2177. }
  2178. $(document).ready(async () => {
  2179. // Show exact time
  2180. $('.time-since').each(function () {
  2181. $(this)
  2182. .addClass('poping up')
  2183. .attr('data-content', $(this).attr('title'))
  2184. .attr('data-variation', 'inverted tiny')
  2185. .attr('title', '');
  2186. });
  2187. // Semantic UI modules.
  2188. $('.dropdown:not(.custom)').dropdown();
  2189. $('.jump.dropdown').dropdown({
  2190. action: 'hide',
  2191. onShow() {
  2192. $('.poping.up').popup('hide');
  2193. }
  2194. });
  2195. $('.slide.up.dropdown').dropdown({
  2196. transition: 'slide up'
  2197. });
  2198. $('.upward.dropdown').dropdown({
  2199. direction: 'upward'
  2200. });
  2201. $('.ui.accordion').accordion();
  2202. $('.ui.checkbox').checkbox();
  2203. $('.ui.progress').progress({
  2204. showActivity: false
  2205. });
  2206. $('.poping.up').popup();
  2207. $('.top.menu .poping.up').popup({
  2208. onShow() {
  2209. if ($('.top.menu .menu.transition').hasClass('visible')) {
  2210. return false;
  2211. }
  2212. }
  2213. });
  2214. $('.tabular.menu .item').tab();
  2215. $('.tabable.menu .item').tab();
  2216. $('.toggle.button').on('click', function () {
  2217. $($(this).data('target')).slideToggle(100);
  2218. });
  2219. // make table <tr> element clickable like a link
  2220. $('tr[data-href]').on('click', function () {
  2221. window.location = $(this).data('href');
  2222. });
  2223. // Dropzone
  2224. const $dropzone = $('#dropzone');
  2225. if ($dropzone.length > 0) {
  2226. const filenameDict = {};
  2227. await createDropzone('#dropzone', {
  2228. url: $dropzone.data('upload-url'),
  2229. headers: {'X-Csrf-Token': csrf},
  2230. maxFiles: $dropzone.data('max-file'),
  2231. maxFilesize: $dropzone.data('max-size'),
  2232. acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
  2233. addRemoveLinks: true,
  2234. dictDefaultMessage: $dropzone.data('default-message'),
  2235. dictInvalidFileType: $dropzone.data('invalid-input-type'),
  2236. dictFileTooBig: $dropzone.data('file-too-big'),
  2237. dictRemoveFile: $dropzone.data('remove-file'),
  2238. init() {
  2239. this.on('success', (file, data) => {
  2240. filenameDict[file.name] = data.uuid;
  2241. const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
  2242. $('.files').append(input);
  2243. });
  2244. this.on('removedfile', (file) => {
  2245. if (file.name in filenameDict) {
  2246. $(`#${filenameDict[file.name]}`).remove();
  2247. }
  2248. if ($dropzone.data('remove-url') && $dropzone.data('csrf')) {
  2249. $.post($dropzone.data('remove-url'), {
  2250. file: filenameDict[file.name],
  2251. _csrf: $dropzone.data('csrf')
  2252. });
  2253. }
  2254. });
  2255. },
  2256. });
  2257. }
  2258. // Emojify
  2259. emojify.setConfig({
  2260. img_dir: `${AppSubUrl}/vendor/plugins/emojify/images`,
  2261. ignore_emoticons: true
  2262. });
  2263. const hasEmoji = document.getElementsByClassName('has-emoji');
  2264. for (let i = 0; i < hasEmoji.length; i++) {
  2265. emojify.run(hasEmoji[i]);
  2266. for (let j = 0; j < hasEmoji[i].childNodes.length; j++) {
  2267. if (hasEmoji[i].childNodes[j].nodeName === 'A') {
  2268. emojify.run(hasEmoji[i].childNodes[j]);
  2269. }
  2270. }
  2271. }
  2272. // Helpers.
  2273. $('.delete-button').on('click', showDeletePopup);
  2274. $('.add-all-button').on('click', showAddAllPopup);
  2275. $('.link-action').on('click', linkAction);
  2276. $('.link-email-action').on('click', linkEmailAction);
  2277. $('.delete-branch-button').on('click', showDeletePopup);
  2278. $('.undo-button').on('click', function () {
  2279. const $this = $(this);
  2280. $.post($this.data('url'), {
  2281. _csrf: csrf,
  2282. id: $this.data('id')
  2283. }).done((data) => {
  2284. window.location.href = data.redirect;
  2285. });
  2286. });
  2287. $('.show-panel.button').on('click', function () {
  2288. $($(this).data('panel')).show();
  2289. });
  2290. $('.show-modal.button').on('click', function () {
  2291. $($(this).data('modal')).modal('show');
  2292. });
  2293. $('.delete-post.button').on('click', function () {
  2294. const $this = $(this);
  2295. $.post($this.data('request-url'), {
  2296. _csrf: csrf
  2297. }).done(() => {
  2298. window.location.href = $this.data('done-url');
  2299. });
  2300. });
  2301. // Set anchor.
  2302. $('.markdown').each(function () {
  2303. $(this).find('h1, h2, h3, h4, h5, h6').each(function () {
  2304. let node = $(this);
  2305. node = node.wrap('<div class="anchor-wrap"></div>');
  2306. node.append(`<a class="anchor" href="#${encodeURIComponent(node.attr('id'))}">${svg('octicon-link', 16)}</a>`);
  2307. });
  2308. });
  2309. $('.issue-checkbox').on('click', () => {
  2310. const numChecked = $('.issue-checkbox').children('input:checked').length;
  2311. if (numChecked > 0) {
  2312. $('#issue-filters').addClass('hide');
  2313. $('#issue-actions').removeClass('hide');
  2314. } else {
  2315. $('#issue-filters').removeClass('hide');
  2316. $('#issue-actions').addClass('hide');
  2317. }
  2318. });
  2319. $('.issue-action').on('click', function () {
  2320. let {action} = this.dataset;
  2321. let {elementId} = this.dataset;
  2322. const issueIDs = $('.issue-checkbox').children('input:checked').map(function () {
  2323. return this.dataset.issueId;
  2324. }).get().join();
  2325. const {url} = this.dataset;
  2326. if (elementId === '0' && url.substr(-9) === '/assignee') {
  2327. elementId = '';
  2328. action = 'clear';
  2329. }
  2330. updateIssuesMeta(url, action, issueIDs, elementId, '').then(() => {
  2331. // NOTICE: This reset of checkbox state targets Firefox caching behaviour, as the checkboxes stay checked after reload
  2332. if (action === 'close' || action === 'open') {
  2333. // uncheck all checkboxes
  2334. $('.issue-checkbox input[type="checkbox"]').each((_, e) => { e.checked = false });
  2335. }
  2336. reload();
  2337. });
  2338. });
  2339. // NOTICE: This event trigger targets Firefox caching behaviour, as the checkboxes stay checked after reload
  2340. // trigger ckecked event, if checkboxes are checked on load
  2341. $('.issue-checkbox input[type="checkbox"]:checked').first().each((_, e) => {
  2342. e.checked = false;
  2343. $(e).trigger('click');
  2344. });
  2345. $('.resolve-conversation').on('click', function (e) {
  2346. e.preventDefault();
  2347. const id = $(this).data('comment-id');
  2348. const action = $(this).data('action');
  2349. const url = $(this).data('update-url');
  2350. $.post(url, {
  2351. _csrf: csrf,
  2352. action,
  2353. comment_id: id,
  2354. }).then(reload);
  2355. });
  2356. buttonsClickOnEnter();
  2357. searchUsers();
  2358. searchTeams();
  2359. searchRepositories();
  2360. initCommentForm();
  2361. initInstall();
  2362. initRepository();
  2363. initMigration();
  2364. initWikiForm();
  2365. initEditForm();
  2366. initEditor();
  2367. initOrganization();
  2368. initGithook();
  2369. initWebhook();
  2370. initAdmin();
  2371. initCodeView();
  2372. initVueApp();
  2373. initTeamSettings();
  2374. initCtrlEnterSubmit();
  2375. initNavbarContentToggle();
  2376. initTopicbar();
  2377. initU2FAuth();
  2378. initU2FRegister();
  2379. initIssueList();
  2380. initWipTitle();
  2381. initPullRequestReview();
  2382. initRepoStatusChecker();
  2383. initTemplateSearch();
  2384. initContextPopups();
  2385. // Repo clone url.
  2386. if ($('#repo-clone-url').length > 0) {
  2387. switch (localStorage.getItem('repo-clone-protocol')) {
  2388. case 'ssh':
  2389. if ($('#repo-clone-ssh').length === 0) {
  2390. $('#repo-clone-https').trigger('click');
  2391. }
  2392. break;
  2393. default:
  2394. $('#repo-clone-https').trigger('click');
  2395. break;
  2396. }
  2397. }
  2398. const routes = {
  2399. 'div.user.settings': initUserSettings,
  2400. 'div.repository.settings.collaboration': initRepositoryCollaboration
  2401. };
  2402. let selector;
  2403. for (selector in routes) {
  2404. if ($(selector).length > 0) {
  2405. routes[selector]();
  2406. break;
  2407. }
  2408. }
  2409. const $cloneAddr = $('#clone_addr');
  2410. $cloneAddr.on('change', () => {
  2411. const $repoName = $('#repo_name');
  2412. if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
  2413. $repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
  2414. }
  2415. });
  2416. // parallel init of lazy-loaded features
  2417. await Promise.all([
  2418. highlight(document.querySelectorAll('pre code')),
  2419. initGitGraph(),
  2420. initClipboard(),
  2421. initUserHeatmap(),
  2422. ]);
  2423. });
  2424. function changeHash(hash) {
  2425. if (window.history.pushState) {
  2426. window.history.pushState(null, null, hash);
  2427. } else {
  2428. window.location.hash = hash;
  2429. }
  2430. }
  2431. function deSelect() {
  2432. if (window.getSelection) {
  2433. window.getSelection().removeAllRanges();
  2434. } else {
  2435. document.selection.empty();
  2436. }
  2437. }
  2438. function selectRange($list, $select, $from) {
  2439. $list.removeClass('active');
  2440. if ($from) {
  2441. let a = parseInt($select.attr('rel').substr(1));
  2442. let b = parseInt($from.attr('rel').substr(1));
  2443. let c;
  2444. if (a !== b) {
  2445. if (a > b) {
  2446. c = a;
  2447. a = b;
  2448. b = c;
  2449. }
  2450. const classes = [];
  2451. for (let i = a; i <= b; i++) {
  2452. classes.push(`.L${i}`);
  2453. }
  2454. $list.filter(classes.join(',')).addClass('active');
  2455. changeHash(`#L${a}-L${b}`);
  2456. return;
  2457. }
  2458. }
  2459. $select.addClass('active');
  2460. changeHash(`#${$select.attr('rel')}`);
  2461. }
  2462. $(() => {
  2463. // Warn users that try to leave a page after entering data into a form.
  2464. // Except on sign-in pages, and for forms marked as 'ignore-dirty'.
  2465. if ($('.user.signin').length === 0) {
  2466. $('form:not(.ignore-dirty)').areYouSure();
  2467. }
  2468. // Parse SSH Key
  2469. $('#ssh-key-content').on('change paste keyup', function () {
  2470. const arrays = $(this).val().split(' ');
  2471. const $title = $('#ssh-key-title');
  2472. if ($title.val() === '' && arrays.length === 3 && arrays[2] !== '') {
  2473. $title.val(arrays[2]);
  2474. }
  2475. });
  2476. });
  2477. function showDeletePopup() {
  2478. const $this = $(this);
  2479. let filter = '';
  2480. if ($this.attr('id')) {
  2481. filter += `#${$this.attr('id')}`;
  2482. }
  2483. const dialog = $(`.delete.modal${filter}`);
  2484. dialog.find('.name').text($this.data('name'));
  2485. dialog.modal({
  2486. closable: false,
  2487. onApprove() {
  2488. if ($this.data('type') === 'form') {
  2489. $($this.data('form')).trigger('submit');
  2490. return;
  2491. }
  2492. $.post($this.data('url'), {
  2493. _csrf: csrf,
  2494. id: $this.data('id')
  2495. }).done((data) => {
  2496. window.location.href = data.redirect;
  2497. });
  2498. }
  2499. }).modal('show');
  2500. return false;
  2501. }
  2502. function showAddAllPopup() {
  2503. const $this = $(this);
  2504. let filter = '';
  2505. if ($this.attr('id')) {
  2506. filter += `#${$this.attr('id')}`;
  2507. }
  2508. const dialog = $(`.addall.modal${filter}`);
  2509. dialog.find('.name').text($this.data('name'));
  2510. dialog.modal({
  2511. closable: false,
  2512. onApprove() {
  2513. if ($this.data('type') === 'form') {
  2514. $($this.data('form')).trigger('submit');
  2515. return;
  2516. }
  2517. $.post($this.data('url'), {
  2518. _csrf: csrf,
  2519. id: $this.data('id')
  2520. }).done((data) => {
  2521. window.location.href = data.redirect;
  2522. });
  2523. }
  2524. }).modal('show');
  2525. return false;
  2526. }
  2527. function linkAction(e) {
  2528. e.preventDefault();
  2529. const $this = $(this);
  2530. const redirect = $this.data('redirect');
  2531. $.post($this.data('url'), {
  2532. _csrf: csrf
  2533. }).done((data) => {
  2534. if (data.redirect) {
  2535. window.location.href = data.redirect;
  2536. } else if (redirect) {
  2537. window.location.href = redirect;
  2538. } else {
  2539. window.location.reload();
  2540. }
  2541. });
  2542. }
  2543. function linkEmailAction(e) {
  2544. const $this = $(this);
  2545. $('#form-uid').val($this.data('uid'));
  2546. $('#form-email').val($this.data('email'));
  2547. $('#form-primary').val($this.data('primary'));
  2548. $('#form-activate').val($this.data('activate'));
  2549. $('#form-uid').val($this.data('uid'));
  2550. $('#change-email-modal').modal('show');
  2551. e.preventDefault();
  2552. }
  2553. function initVueComponents() {
  2554. const vueDelimeters = ['${', '}'];
  2555. Vue.component('repo-search', {
  2556. delimiters: vueDelimeters,
  2557. props: {
  2558. searchLimit: {
  2559. type: Number,
  2560. default: 10
  2561. },
  2562. suburl: {
  2563. type: String,
  2564. required: true
  2565. },
  2566. uid: {
  2567. type: Number,
  2568. required: true
  2569. },
  2570. organizations: {
  2571. type: Array,
  2572. default: []
  2573. },
  2574. isOrganization: {
  2575. type: Boolean,
  2576. default: true
  2577. },
  2578. canCreateOrganization: {
  2579. type: Boolean,
  2580. default: false
  2581. },
  2582. organizationsTotalCount: {
  2583. type: Number,
  2584. default: 0
  2585. },
  2586. moreReposLink: {
  2587. type: String,
  2588. default: ''
  2589. }
  2590. },
  2591. data() {
  2592. return {
  2593. tab: 'repos',
  2594. repos: [],
  2595. reposTotalCount: 0,
  2596. reposFilter: 'all',
  2597. searchQuery: '',
  2598. isLoading: false,
  2599. staticPrefix: StaticUrlPrefix,
  2600. repoTypes: {
  2601. all: {
  2602. count: 0,
  2603. searchMode: '',
  2604. },
  2605. forks: {
  2606. count: 0,
  2607. searchMode: 'fork',
  2608. },
  2609. mirrors: {
  2610. count: 0,
  2611. searchMode: 'mirror',
  2612. },
  2613. sources: {
  2614. count: 0,
  2615. searchMode: 'source',
  2616. },
  2617. collaborative: {
  2618. count: 0,
  2619. searchMode: 'collaborative',
  2620. },
  2621. }
  2622. };
  2623. },
  2624. computed: {
  2625. showMoreReposLink() {
  2626. return this.repos.length > 0 && this.repos.length < this.repoTypes[this.reposFilter].count;
  2627. },
  2628. searchURL() {
  2629. return `${this.suburl}/api/v1/repos/search?sort=updated&order=desc&uid=${this.uid}&q=${this.searchQuery
  2630. }&limit=${this.searchLimit}&mode=${this.repoTypes[this.reposFilter].searchMode
  2631. }${this.reposFilter !== 'all' ? '&exclusive=1' : ''}`;
  2632. },
  2633. repoTypeCount() {
  2634. return this.repoTypes[this.reposFilter].count;
  2635. }
  2636. },
  2637. mounted() {
  2638. this.searchRepos(this.reposFilter);
  2639. const self = this;
  2640. Vue.nextTick(() => {
  2641. self.$refs.search.focus();
  2642. });
  2643. },
  2644. methods: {
  2645. changeTab(t) {
  2646. this.tab = t;
  2647. },
  2648. changeReposFilter(filter) {
  2649. this.reposFilter = filter;
  2650. this.repos = [];
  2651. this.repoTypes[filter].count = 0;
  2652. this.searchRepos(filter);
  2653. },
  2654. showRepo(repo, filter) {
  2655. switch (filter) {
  2656. case 'sources':
  2657. return repo.owner.id === this.uid && !repo.mirror && !repo.fork;
  2658. case 'forks':
  2659. return repo.owner.id === this.uid && !repo.mirror && repo.fork;
  2660. case 'mirrors':
  2661. return repo.mirror;
  2662. case 'collaborative':
  2663. return repo.owner.id !== this.uid && !repo.mirror;
  2664. default:
  2665. return true;
  2666. }
  2667. },
  2668. searchRepos(reposFilter) {
  2669. const self = this;
  2670. this.isLoading = true;
  2671. const searchedMode = this.repoTypes[reposFilter].searchMode;
  2672. const searchedURL = this.searchURL;
  2673. const searchedQuery = this.searchQuery;
  2674. $.getJSON(searchedURL, (result, _textStatus, request) => {
  2675. if (searchedURL === self.searchURL) {
  2676. self.repos = result.data;
  2677. const count = request.getResponseHeader('X-Total-Count');
  2678. if (searchedQuery === '' && searchedMode === '') {
  2679. self.reposTotalCount = count;
  2680. }
  2681. self.repoTypes[reposFilter].count = count;
  2682. }
  2683. }).always(() => {
  2684. if (searchedURL === self.searchURL) {
  2685. self.isLoading = false;
  2686. }
  2687. });
  2688. },
  2689. repoClass(repo) {
  2690. if (repo.fork) {
  2691. return 'octicon-repo-forked';
  2692. } if (repo.mirror) {
  2693. return 'octicon-repo-clone';
  2694. } if (repo.template) {
  2695. return `octicon-repo-template${repo.private ? '-private' : ''}`;
  2696. } if (repo.private) {
  2697. return 'octicon-lock';
  2698. }
  2699. return 'octicon-repo';
  2700. }
  2701. }
  2702. });
  2703. }
  2704. function initCtrlEnterSubmit() {
  2705. $('.js-quick-submit').on('keydown', function (e) {
  2706. if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode === 13 || e.keyCode === 10)) {
  2707. $(this).closest('form').trigger('submit');
  2708. }
  2709. });
  2710. }
  2711. function initVueApp() {
  2712. const el = document.getElementById('app');
  2713. if (!el) {
  2714. return;
  2715. }
  2716. initVueComponents();
  2717. new Vue({
  2718. delimiters: ['${', '}'],
  2719. el,
  2720. data: {
  2721. searchLimit: Number((document.querySelector('meta[name=_search_limit]') || {}).content),
  2722. suburl: AppSubUrl,
  2723. uid: Number((document.querySelector('meta[name=_context_uid]') || {}).content),
  2724. activityTopAuthors: window.ActivityTopAuthors || [],
  2725. },
  2726. components: {
  2727. ActivityTopAuthors,
  2728. },
  2729. });
  2730. }
  2731. window.timeAddManual = function () {
  2732. $('.mini.modal')
  2733. .modal({
  2734. duration: 200,
  2735. onApprove() {
  2736. $('#add_time_manual_form').trigger('submit');
  2737. }
  2738. }).modal('show');
  2739. };
  2740. window.toggleStopwatch = function () {
  2741. $('#toggle_stopwatch_form').trigger('submit');
  2742. };
  2743. window.cancelStopwatch = function () {
  2744. $('#cancel_stopwatch_form').trigger('submit');
  2745. };
  2746. function initFilterBranchTagDropdown(selector) {
  2747. $(selector).each(function () {
  2748. const $dropdown = $(this);
  2749. const $data = $dropdown.find('.data');
  2750. const data = {
  2751. items: [],
  2752. mode: $data.data('mode'),
  2753. searchTerm: '',
  2754. noResults: '',
  2755. canCreateBranch: false,
  2756. menuVisible: false,
  2757. active: 0
  2758. };
  2759. $data.find('.item').each(function () {
  2760. data.items.push({
  2761. name: $(this).text(),
  2762. url: $(this).data('url'),
  2763. branch: $(this).hasClass('branch'),
  2764. tag: $(this).hasClass('tag'),
  2765. selected: $(this).hasClass('selected')
  2766. });
  2767. });
  2768. $data.remove();
  2769. new Vue({
  2770. delimiters: ['${', '}'],
  2771. el: this,
  2772. data,
  2773. beforeMount() {
  2774. const vm = this;
  2775. this.noResults = vm.$el.getAttribute('data-no-results');
  2776. this.canCreateBranch = vm.$el.getAttribute('data-can-create-branch') === 'true';
  2777. document.body.addEventListener('click', (event) => {
  2778. if (vm.$el.contains(event.target)) {
  2779. return;
  2780. }
  2781. if (vm.menuVisible) {
  2782. Vue.set(vm, 'menuVisible', false);
  2783. }
  2784. });
  2785. },
  2786. watch: {
  2787. menuVisible(visible) {
  2788. if (visible) {
  2789. this.focusSearchField();
  2790. }
  2791. }
  2792. },
  2793. computed: {
  2794. filteredItems() {
  2795. const vm = this;
  2796. const items = vm.items.filter((item) => {
  2797. return ((vm.mode === 'branches' && item.branch) || (vm.mode === 'tags' && item.tag)) &&
  2798. (!vm.searchTerm || item.name.toLowerCase().includes(vm.searchTerm.toLowerCase()));
  2799. });
  2800. vm.active = (items.length === 0 && vm.showCreateNewBranch ? 0 : -1);
  2801. return items;
  2802. },
  2803. showNoResults() {
  2804. return this.filteredItems.length === 0 && !this.showCreateNewBranch;
  2805. },
  2806. showCreateNewBranch() {
  2807. const vm = this;
  2808. if (!this.canCreateBranch || !vm.searchTerm || vm.mode === 'tags') {
  2809. return false;
  2810. }
  2811. return vm.items.filter((item) => item.name.toLowerCase() === vm.searchTerm.toLowerCase()).length === 0;
  2812. }
  2813. },
  2814. methods: {
  2815. selectItem(item) {
  2816. const prev = this.getSelected();
  2817. if (prev !== null) {
  2818. prev.selected = false;
  2819. }
  2820. item.selected = true;
  2821. window.location.href = item.url;
  2822. },
  2823. createNewBranch() {
  2824. if (!this.showCreateNewBranch) {
  2825. return;
  2826. }
  2827. this.$refs.newBranchForm.trigger('submit');
  2828. },
  2829. focusSearchField() {
  2830. const vm = this;
  2831. Vue.nextTick(() => {
  2832. vm.$refs.searchField.focus();
  2833. });
  2834. },
  2835. getSelected() {
  2836. for (let i = 0, j = this.items.length; i < j; ++i) {
  2837. if (this.items[i].selected) return this.items[i];
  2838. }
  2839. return null;
  2840. },
  2841. getSelectedIndexInFiltered() {
  2842. for (let i = 0, j = this.filteredItems.length; i < j; ++i) {
  2843. if (this.filteredItems[i].selected) return i;
  2844. }
  2845. return -1;
  2846. },
  2847. scrollToActive() {
  2848. let el = this.$refs[`listItem${this.active}`];
  2849. if (!el || el.length === 0) {
  2850. return;
  2851. }
  2852. if (Array.isArray(el)) {
  2853. el = el[0];
  2854. }
  2855. const cont = this.$refs.scrollContainer;
  2856. if (el.offsetTop < cont.scrollTop) {
  2857. cont.scrollTop = el.offsetTop;
  2858. } else if (el.offsetTop + el.clientHeight > cont.scrollTop + cont.clientHeight) {
  2859. cont.scrollTop = el.offsetTop + el.clientHeight - cont.clientHeight;
  2860. }
  2861. },
  2862. keydown(event) {
  2863. const vm = this;
  2864. if (event.keyCode === 40) {
  2865. // arrow down
  2866. event.preventDefault();
  2867. if (vm.active === -1) {
  2868. vm.active = vm.getSelectedIndexInFiltered();
  2869. }
  2870. if (vm.active + (vm.showCreateNewBranch ? 0 : 1) >= vm.filteredItems.length) {
  2871. return;
  2872. }
  2873. vm.active++;
  2874. vm.scrollToActive();
  2875. }
  2876. if (event.keyCode === 38) {
  2877. // arrow up
  2878. event.preventDefault();
  2879. if (vm.active === -1) {
  2880. vm.active = vm.getSelectedIndexInFiltered();
  2881. }
  2882. if (vm.active <= 0) {
  2883. return;
  2884. }
  2885. vm.active--;
  2886. vm.scrollToActive();
  2887. }
  2888. if (event.keyCode === 13) {
  2889. // enter
  2890. event.preventDefault();
  2891. if (vm.active >= vm.filteredItems.length) {
  2892. vm.createNewBranch();
  2893. } else if (vm.active >= 0) {
  2894. vm.selectItem(vm.filteredItems[vm.active]);
  2895. }
  2896. }
  2897. if (event.keyCode === 27) {
  2898. // escape
  2899. event.preventDefault();
  2900. vm.menuVisible = false;
  2901. }
  2902. }
  2903. }
  2904. });
  2905. });
  2906. }
  2907. $('.commit-button').on('click', function (e) {
  2908. e.preventDefault();
  2909. $(this).parent().find('.commit-body').toggle();
  2910. });
  2911. function initNavbarContentToggle() {
  2912. const content = $('#navbar');
  2913. const toggle = $('#navbar-expand-toggle');
  2914. let isExpanded = false;
  2915. toggle.on('click', () => {
  2916. isExpanded = !isExpanded;
  2917. if (isExpanded) {
  2918. content.addClass('shown');
  2919. toggle.addClass('active');
  2920. } else {
  2921. content.removeClass('shown');
  2922. toggle.removeClass('active');
  2923. }
  2924. });
  2925. }
  2926. function initTopicbar() {
  2927. const mgrBtn = $('#manage_topic');
  2928. const editDiv = $('#topic_edit');
  2929. const viewDiv = $('#repo-topics');
  2930. const saveBtn = $('#save_topic');
  2931. const topicDropdown = $('#topic_edit .dropdown');
  2932. const topicForm = $('#topic_edit.ui.form');
  2933. const topicPrompts = getPrompts();
  2934. mgrBtn.on('click', () => {
  2935. viewDiv.hide();
  2936. editDiv.css('display', ''); // show Semantic UI Grid
  2937. });
  2938. function getPrompts() {
  2939. const hidePrompt = $('div.hide#validate_prompt');
  2940. const prompts = {
  2941. countPrompt: hidePrompt.children('#count_prompt').text(),
  2942. formatPrompt: hidePrompt.children('#format_prompt').text()
  2943. };
  2944. hidePrompt.remove();
  2945. return prompts;
  2946. }
  2947. saveBtn.on('click', () => {
  2948. const topics = $('input[name=topics]').val();
  2949. $.post(saveBtn.data('link'), {
  2950. _csrf: csrf,
  2951. topics
  2952. }, (_data, _textStatus, xhr) => {
  2953. if (xhr.responseJSON.status === 'ok') {
  2954. viewDiv.children('.topic').remove();
  2955. if (topics.length) {
  2956. const topicArray = topics.split(',');
  2957. const last = viewDiv.children('a').last();
  2958. for (let i = 0; i < topicArray.length; i++) {
  2959. const link = $('<a class="ui repo-topic small label topic"></a>');
  2960. link.attr('href', `${AppSubUrl}/explore/repos?q=${encodeURIComponent(topicArray[i])}&topic=1`);
  2961. link.text(topicArray[i]);
  2962. link.insertBefore(last);
  2963. }
  2964. }
  2965. editDiv.css('display', 'none');
  2966. viewDiv.show();
  2967. }
  2968. }).fail((xhr) => {
  2969. if (xhr.status === 422) {
  2970. if (xhr.responseJSON.invalidTopics.length > 0) {
  2971. topicPrompts.formatPrompt = xhr.responseJSON.message;
  2972. const {invalidTopics} = xhr.responseJSON;
  2973. const topicLables = topicDropdown.children('a.ui.label');
  2974. topics.split(',').forEach((value, index) => {
  2975. for (let i = 0; i < invalidTopics.length; i++) {
  2976. if (invalidTopics[i] === value) {
  2977. topicLables.eq(index).removeClass('green').addClass('red');
  2978. }
  2979. }
  2980. });
  2981. } else {
  2982. topicPrompts.countPrompt = xhr.responseJSON.message;
  2983. }
  2984. }
  2985. }).always(() => {
  2986. topicForm.form('validate form');
  2987. });
  2988. });
  2989. topicDropdown.dropdown({
  2990. allowAdditions: true,
  2991. forceSelection: false,
  2992. fields: {name: 'description', value: 'data-value'},
  2993. saveRemoteData: false,
  2994. label: {
  2995. transition: 'horizontal flip',
  2996. duration: 200,
  2997. variation: false,
  2998. blue: true,
  2999. basic: true,
  3000. },
  3001. className: {
  3002. label: 'ui small label'
  3003. },
  3004. apiSettings: {
  3005. url: `${AppSubUrl}/api/v1/topics/search?q={query}`,
  3006. throttle: 500,
  3007. cache: false,
  3008. onResponse(res) {
  3009. const formattedResponse = {
  3010. success: false,
  3011. results: [],
  3012. };
  3013. const stripTags = function (text) {
  3014. return text.replace(/<[^>]*>?/gm, '');
  3015. };
  3016. const query = stripTags(this.urlData.query.trim());
  3017. let found_query = false;
  3018. const current_topics = [];
  3019. topicDropdown.find('div.label.visible.topic,a.label.visible').each((_, e) => { current_topics.push(e.dataset.value) });
  3020. if (res.topics) {
  3021. let found = false;
  3022. for (let i = 0; i < res.topics.length; i++) {
  3023. // skip currently added tags
  3024. if (current_topics.includes(res.topics[i].topic_name)) {
  3025. continue;
  3026. }
  3027. if (res.topics[i].topic_name.toLowerCase() === query.toLowerCase()) {
  3028. found_query = true;
  3029. }
  3030. formattedResponse.results.push({description: res.topics[i].topic_name, 'data-value': res.topics[i].topic_name});
  3031. found = true;
  3032. }
  3033. formattedResponse.success = found;
  3034. }
  3035. if (query.length > 0 && !found_query) {
  3036. formattedResponse.success = true;
  3037. formattedResponse.results.unshift({description: query, 'data-value': query});
  3038. } else if (query.length > 0 && found_query) {
  3039. formattedResponse.results.sort((a, b) => {
  3040. if (a.description.toLowerCase() === query.toLowerCase()) return -1;
  3041. if (b.description.toLowerCase() === query.toLowerCase()) return 1;
  3042. if (a.description > b.description) return -1;
  3043. if (a.description < b.description) return 1;
  3044. return 0;
  3045. });
  3046. }
  3047. return formattedResponse;
  3048. },
  3049. },
  3050. onLabelCreate(value) {
  3051. value = value.toLowerCase().trim();
  3052. this.attr('data-value', value).contents().first().replaceWith(value);
  3053. return $(this);
  3054. },
  3055. onAdd(addedValue, _addedText, $addedChoice) {
  3056. addedValue = addedValue.toLowerCase().trim();
  3057. $($addedChoice).attr('data-value', addedValue);
  3058. $($addedChoice).attr('data-text', addedValue);
  3059. }
  3060. });
  3061. $.fn.form.settings.rules.validateTopic = function (_values, regExp) {
  3062. const topics = topicDropdown.children('a.ui.label');
  3063. const status = topics.length === 0 || topics.last().attr('data-value').match(regExp);
  3064. if (!status) {
  3065. topics.last().removeClass('green').addClass('red');
  3066. }
  3067. return status && topicDropdown.children('a.ui.label.red').length === 0;
  3068. };
  3069. topicForm.form({
  3070. on: 'change',
  3071. inline: true,
  3072. fields: {
  3073. topics: {
  3074. identifier: 'topics',
  3075. rules: [
  3076. {
  3077. type: 'validateTopic',
  3078. value: /^[a-z0-9][a-z0-9-]{0,35}$/,
  3079. prompt: topicPrompts.formatPrompt
  3080. },
  3081. {
  3082. type: 'maxCount[25]',
  3083. prompt: topicPrompts.countPrompt
  3084. }
  3085. ]
  3086. },
  3087. }
  3088. });
  3089. }
  3090. window.toggleDeadlineForm = function () {
  3091. $('#deadlineForm').fadeToggle(150);
  3092. };
  3093. window.setDeadline = function () {
  3094. const deadline = $('#deadlineDate').val();
  3095. window.updateDeadline(deadline);
  3096. };
  3097. window.updateDeadline = function (deadlineString) {
  3098. $('#deadline-err-invalid-date').hide();
  3099. $('#deadline-loader').addClass('loading');
  3100. let realDeadline = null;
  3101. if (deadlineString !== '') {
  3102. const newDate = Date.parse(deadlineString);
  3103. if (Number.isNaN(newDate)) {
  3104. $('#deadline-loader').removeClass('loading');
  3105. $('#deadline-err-invalid-date').show();
  3106. return false;
  3107. }
  3108. realDeadline = new Date(newDate);
  3109. }
  3110. $.ajax(`${$('#update-issue-deadline-form').attr('action')}/deadline`, {
  3111. data: JSON.stringify({
  3112. due_date: realDeadline,
  3113. }),
  3114. headers: {
  3115. 'X-Csrf-Token': csrf,
  3116. 'X-Remote': true,
  3117. },
  3118. contentType: 'application/json',
  3119. type: 'POST',
  3120. success() {
  3121. reload();
  3122. },
  3123. error() {
  3124. $('#deadline-loader').removeClass('loading');
  3125. $('#deadline-err-invalid-date').show();
  3126. }
  3127. });
  3128. };
  3129. window.deleteDependencyModal = function (id, type) {
  3130. $('.remove-dependency')
  3131. .modal({
  3132. closable: false,
  3133. duration: 200,
  3134. onApprove() {
  3135. $('#removeDependencyID').val(id);
  3136. $('#dependencyType').val(type);
  3137. $('#removeDependencyForm').trigger('submit');
  3138. }
  3139. }).modal('show');
  3140. };
  3141. function initIssueList() {
  3142. const repolink = $('#repolink').val();
  3143. const repoId = $('#repoId').val();
  3144. const crossRepoSearch = $('#crossRepoSearch').val();
  3145. const tp = $('#type').val();
  3146. let issueSearchUrl = `${AppSubUrl}/api/v1/repos/${repolink}/issues?q={query}&type=${tp}`;
  3147. if (crossRepoSearch === 'true') {
  3148. issueSearchUrl = `${AppSubUrl}/api/v1/repos/issues/search?q={query}&priority_repo_id=${repoId}&type=${tp}`;
  3149. }
  3150. $('#new-dependency-drop-list')
  3151. .dropdown({
  3152. apiSettings: {
  3153. url: issueSearchUrl,
  3154. onResponse(response) {
  3155. const filteredResponse = {success: true, results: []};
  3156. const currIssueId = $('#new-dependency-drop-list').data('issue-id');
  3157. // Parse the response from the api to work with our dropdown
  3158. $.each(response, (_i, issue) => {
  3159. // Don't list current issue in the dependency list.
  3160. if (issue.id === currIssueId) {
  3161. return;
  3162. }
  3163. filteredResponse.results.push({
  3164. name: `#${issue.number} ${htmlEncode(issue.title)
  3165. }<div class="text small dont-break-out">${htmlEncode(issue.repository.full_name)}</div>`,
  3166. value: issue.id
  3167. });
  3168. });
  3169. return filteredResponse;
  3170. },
  3171. cache: false,
  3172. },
  3173. fullTextSearch: true
  3174. });
  3175. $('.menu a.label-filter-item').each(function () {
  3176. $(this).on('click', function (e) {
  3177. if (e.altKey) {
  3178. e.preventDefault();
  3179. const href = $(this).attr('href');
  3180. const id = $(this).data('label-id');
  3181. const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`;
  3182. const newStr = 'labels=$1-$2$3&';
  3183. window.location = href.replace(new RegExp(regStr), newStr);
  3184. }
  3185. });
  3186. });
  3187. $('.menu .ui.dropdown.label-filter').on('keydown', (e) => {
  3188. if (e.altKey && e.keyCode === 13) {
  3189. const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected');
  3190. if (selectedItems.length > 0) {
  3191. const item = $(selectedItems[0]);
  3192. const href = item.attr('href');
  3193. const id = item.data('label-id');
  3194. const regStr = `labels=(-?[0-9]+%2c)*(${id})(%2c-?[0-9]+)*&`;
  3195. const newStr = 'labels=$1-$2$3&';
  3196. window.location = href.replace(new RegExp(regStr), newStr);
  3197. }
  3198. }
  3199. });
  3200. }
  3201. window.cancelCodeComment = function (btn) {
  3202. const form = $(btn).closest('form');
  3203. if (form.length > 0 && form.hasClass('comment-form')) {
  3204. form.addClass('hide');
  3205. form.parent().find('button.comment-form-reply').show();
  3206. } else {
  3207. form.closest('.comment-code-cloud').remove();
  3208. }
  3209. };
  3210. window.submitReply = function (btn) {
  3211. const form = $(btn).closest('form');
  3212. if (form.length > 0 && form.hasClass('comment-form')) {
  3213. form.trigger('submit');
  3214. }
  3215. };
  3216. window.onOAuthLoginClick = function () {
  3217. const oauthLoader = $('#oauth2-login-loader');
  3218. const oauthNav = $('#oauth2-login-navigator');
  3219. oauthNav.hide();
  3220. oauthLoader.removeClass('disabled');
  3221. setTimeout(() => {
  3222. // recover previous content to let user try again
  3223. // usually redirection will be performed before this action
  3224. oauthLoader.addClass('disabled');
  3225. oauthNav.show();
  3226. }, 5000);
  3227. };
  3228. // Pull SVGs via AJAX to workaround CORS issues with <use> tags
  3229. // https://css-tricks.com/ajaxing-svg-sprite/
  3230. $.get(`${window.config.StaticUrlPrefix}/img/svg/icons.svg`, (data) => {
  3231. const div = document.createElement('div');
  3232. div.style.display = 'none';
  3233. div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
  3234. document.body.insertBefore(div, document.body.childNodes[0]);
  3235. });