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