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

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