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