You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 142 kB

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