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