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

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