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

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