From 205090fcfb741884215723281dfb0afb56efbbfb Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 25 Jul 2017 11:56:41 +0100 Subject: Removed inline JS in shared HAML files --- app/assets/javascripts/dispatcher.js | 65 ++++++++++++++++++++-- app/assets/javascripts/issuable_context.js | 4 +- app/assets/javascripts/main.js | 1 - app/assets/javascripts/milestone_select.js | 2 +- app/assets/javascripts/project.js | 29 +++++----- app/assets/javascripts/snippets_list.js | 9 --- app/helpers/notes_helper.rb | 10 ++++ app/views/shared/_clone_panel.html.haml | 8 --- app/views/shared/_label.html.haml | 8 --- .../shared/_personal_access_tokens_form.html.haml | 15 ----- app/views/shared/issuable/_filter.html.haml | 10 ---- app/views/shared/issuable/_participants.html.haml | 2 - app/views/shared/issuable/_search_bar.html.haml | 9 --- app/views/shared/issuable/_sidebar.html.haml | 10 +--- app/views/shared/notes/_notes_with_form.html.haml | 3 +- app/views/snippets/_snippets.html.haml | 6 +- 16 files changed, 90 insertions(+), 101 deletions(-) delete mode 100644 app/assets/javascripts/snippets_list.js diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index ffe97c071ba..8a142e49b72 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -27,6 +27,10 @@ /* global Shortcuts */ /* global Sidebar */ /* global ShortcutsWiki */ +/* global IssuableContext */ +/* global IssueStatusSelect */ +/* global SubscriptionSelect */ +/* global Notes */ import Issue from './issue'; import BindInOut from './behaviors/bind_in_out'; @@ -126,6 +130,42 @@ import PerformanceBar from './performance_bar'; .init(); } + function initIssuableSidebar() { + new MilestoneSelect({ + full_path: gl.sidebarOptions.fullPath, + }); + new LabelsSelect(); + new IssuableContext(gl.sidebarOptions.currentUser); + gl.Subscription.bindAll('.subscription'); + new gl.DueDateSelectors(); + window.sidebar = new Sidebar(); + } + + function initLegacyFilters() { + new UsersSelect(); + new LabelsSelect(); + new MilestoneSelect(); + new IssueStatusSelect(); + new SubscriptionSelect(); + $('form.filter-form').on('submit', function (event) { + event.preventDefault(); + gl.utils.visitUrl(`${this.action}&${$(this).serialize()}`); + }); + } + + function initNotes() { + const dataEl = document.querySelector('.js-notes-data'); + const { + notesUrl, + notesIds, + now, + diffView, + autocomplete, + } = JSON.parse(dataEl.innerHTML); + + window.notes = new Notes(notesUrl, notesIds, now, diffView, autocomplete); + } + switch (page) { case 'profiles:preferences:show': initExperimentalFlags(); @@ -156,6 +196,8 @@ import PerformanceBar from './performance_bar'; new Issue(); shortcut_handler = new ShortcutsIssuable(); new ZenMode(); + initIssuableSidebar(); + initNotes(); break; case 'dashboard:milestones:index': new ProjectSelect(); @@ -166,10 +208,12 @@ import PerformanceBar from './performance_bar'; new Milestone(); new Sidebar(); break; + case 'dashboard:issues': + case 'dashboard:merge_requests': case 'groups:issues': case 'groups:merge_requests': - new UsersSelect(); new ProjectSelect(); + initLegacyFilters(); break; case 'dashboard:todos:index': new Todos(); @@ -237,6 +281,9 @@ import PerformanceBar from './performance_bar'; new gl.GLForm($('.tag-form'), true); new RefSelectDropdown($('.js-branch-select'), window.gl.availableRefs); break; + case 'projects:snippets:show': + initNotes(); + break; case 'projects:snippets:new': case 'projects:snippets:edit': case 'projects:snippets:create': @@ -253,19 +300,17 @@ import PerformanceBar from './performance_bar'; new ZenMode(); new gl.GLForm($('.release-form'), true); break; + case 'projects:merge_requests:conflicts:show': case 'projects:merge_requests:show': new gl.Diff(); shortcut_handler = new ShortcutsIssuable(true); new ZenMode(); + initIssuableSidebar(); + initNotes(); break; case 'dashboard:activity': new gl.Activities(); break; - case 'dashboard:issues': - case 'dashboard:merge_requests': - new ProjectSelect(); - new UsersSelect(); - break; case 'projects:commit:show': new Commit(); new gl.Diff(); @@ -274,6 +319,7 @@ import PerformanceBar from './performance_bar'; new MiniPipelineGraph({ container: '.js-commit-pipeline-graph', }).bindEvents(); + initNotes(); break; case 'projects:commit:pipelines': new MiniPipelineGraph({ @@ -367,10 +413,12 @@ import PerformanceBar from './performance_bar'; case 'projects:labels:edit': new Labels(); break; + case 'groups:labels:index': case 'projects:labels:index': if ($('.prioritized-labels').length) { new gl.LabelManager(); } + new gl.ProjectLabelSubscription('.label-subscription'); break; case 'projects:network:show': // Ensure we don't create a particular shortcut handler here. This is @@ -415,10 +463,15 @@ import PerformanceBar from './performance_bar'; case 'snippets:show': new LineHighlighter(); new BlobViewer(); + initNotes(); break; case 'import:fogbugz:new_user_map': new UsersSelect(); break; + case 'profiles:personal_access_tokens:index': + case 'admin:impersonation_tokens:index': + new gl.DueDateSelectors(); + break; } switch (path.first()) { case 'sessions': diff --git a/app/assets/javascripts/issuable_context.js b/app/assets/javascripts/issuable_context.js index a4d7bf096ef..a45ff3fc43e 100644 --- a/app/assets/javascripts/issuable_context.js +++ b/app/assets/javascripts/issuable_context.js @@ -50,11 +50,9 @@ import UsersSelect from './users_select'; } IssuableContext.prototype.initParticipants = function() { - var _this; - _this = this; $(document).on("click", ".js-participants-more", this.toggleHiddenParticipants); return $(".js-participants-author").each(function(i) { - if (i >= _this.PARTICIPANTS_ROW_COUNT) { + if (i >= 7) { return $(this).addClass("js-participants-hidden").hide(); } }); diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index e96d51de838..6d3f5390cf6 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -145,7 +145,6 @@ import './right_sidebar'; import './search'; import './search_autocomplete'; import './smart_interval'; -import './snippets_list'; import './star'; import './subscription'; import './subscription_select'; diff --git a/app/assets/javascripts/milestone_select.js b/app/assets/javascripts/milestone_select.js index 9d481d7c003..6756ab0b3aa 100644 --- a/app/assets/javascripts/milestone_select.js +++ b/app/assets/javascripts/milestone_select.js @@ -8,7 +8,7 @@ var _this, $els; if (currentProject != null) { _this = this; - this.currentProject = JSON.parse(currentProject); + this.currentProject = typeof currentProject === 'string' ? JSON.parse(currentProject) : currentProject; } $els = $(els); diff --git a/app/assets/javascripts/project.js b/app/assets/javascripts/project.js index 738e710deb9..a3f7d69b98d 100644 --- a/app/assets/javascripts/project.js +++ b/app/assets/javascripts/project.js @@ -6,21 +6,22 @@ import Cookies from 'js-cookie'; (function() { this.Project = (function() { function Project() { - $('ul.clone-options-dropdown a').click(function() { - var url; - if ($(this).hasClass('active')) { - return; - } - $('.active').not($(this)).removeClass('active'); - $(this).toggleClass('active'); - url = $("#project_clone").val(); - $('#project_clone').val(url); + const $cloneOptions = $('ul.clone-options-dropdown'); + const $projectCloneField = $('#project_clone'); + const $cloneBtnText = $('a.clone-dropdown-btn span'); + + $('a', $cloneOptions).on('click', (e) => { + const $this = $(e.currentTarget); + const url = $this.attr('href'); + + e.preventDefault(); + + $('.active', $cloneOptions).not($this).removeClass('active'); + $this.toggleClass('active'); + $projectCloneField.val(url); + $cloneBtnText.text($this.text()); + return $('.clone').text(url); - // Git protocol switcher - // Remove the active class for all buttons (ssh, http, kerberos if shown) - // Add the active class for the clicked button - // Update the input field - // Update the command line instructions }); // Ref switcher this.initRefSwitcher(); diff --git a/app/assets/javascripts/snippets_list.js b/app/assets/javascripts/snippets_list.js deleted file mode 100644 index 3b6d999b1c3..00000000000 --- a/app/assets/javascripts/snippets_list.js +++ /dev/null @@ -1,9 +0,0 @@ -function SnippetsList() { - const $holder = $('.snippets-list-holder'); - - $holder.find('.pagination').on('ajax:success', (e, data) => { - $holder.replaceWith(data.html); - }); -} - -window.gl.SnippetsList = SnippetsList; diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 0a0881d95cf..505579674c9 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -130,4 +130,14 @@ module NotesHelper can?(current_user, :create_note, @project) end end + + def initial_notes_data(autocomplete) + { + notesUrl: notes_url, + notesIds: @notes.map(&:id), + now: Time.now.to_i, + diffView: diff_view, + autocomplete: autocomplete + } + end end diff --git a/app/views/shared/_clone_panel.html.haml b/app/views/shared/_clone_panel.html.haml index 75704eda361..b4843eafdb7 100644 --- a/app/views/shared/_clone_panel.html.haml +++ b/app/views/shared/_clone_panel.html.haml @@ -20,11 +20,3 @@ = text_field_tag :project_clone, default_url_to_repo(project), class: "js-select-on-focus form-control", readonly: true, aria: { label: 'Project clone URL' } .input-group-btn = clipboard_button(target: '#project_clone', title: _("Copy URL to clipboard"), class: "btn-default btn-clipboard") - -:javascript - $('ul.clone-options-dropdown a').on('click',function(e){ - e.preventDefault(); - var $this = $(this); - $('a.clone-dropdown-btn span').text($this.text()); - $('#project_clone').val($this.attr('href')); - }); diff --git a/app/views/shared/_label.html.haml b/app/views/shared/_label.html.haml index 2f776a17f45..8ded7440de3 100644 --- a/app/views/shared/_label.html.haml +++ b/app/views/shared/_label.html.haml @@ -76,11 +76,3 @@ = link_to destroy_label_path(label), title: "Delete", class: 'btn btn-transparent btn-action remove-row', method: :delete, data: {confirm: label_deletion_confirm_text(label), toggle: "tooltip"} do %span.sr-only Delete = icon('trash-o') - - - if current_user - - if can_subscribe_to_label_in_different_levels?(label) - :javascript - new gl.GroupLabelSubscription('##{dom_id(label)} .label-subscription'); - - else - :javascript - new gl.ProjectLabelSubscription('##{dom_id(label)} .label-subscription'); diff --git a/app/views/shared/_personal_access_tokens_form.html.haml b/app/views/shared/_personal_access_tokens_form.html.haml index b20055a564e..e415ec64c38 100644 --- a/app/views/shared/_personal_access_tokens_form.html.haml +++ b/app/views/shared/_personal_access_tokens_form.html.haml @@ -23,18 +23,3 @@ .prepend-top-default = f.submit "Create #{type} token", class: "btn btn-create" - -:javascript - var $dateField = $('.datepicker'); - var date = $dateField.val(); - - new Pikaday({ - field: $dateField.get(0), - theme: 'gitlab-theme animate-picker', - format: 'yyyy-mm-dd', - minDate: new Date(), - container: $dateField.parent().get(0), - onSelect: function(dateText) { - $dateField.val(dateFormat(new Date(dateText), 'yyyy-mm-dd')); - } - }); diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml index 2cabbc8c560..c4ed7f6e750 100644 --- a/app/views/shared/issuable/_filter.html.haml +++ b/app/views/shared/issuable/_filter.html.haml @@ -36,13 +36,3 @@ .row-content-block.second-block.filtered-labels{ class: ("hidden" unless has_labels) } - if has_labels = render 'shared/labels_row', labels: @labels - -:javascript - new LabelsSelect(); - new MilestoneSelect(); - new IssueStatusSelect(); - new SubscriptionSelect(); - $('form.filter-form').on('submit', function (event) { - event.preventDefault(); - gl.utils.visitUrl(this.action + '&' + $(this).serialize()); - }); diff --git a/app/views/shared/issuable/_participants.html.haml b/app/views/shared/issuable/_participants.html.haml index db407363a09..8a71819aa8e 100644 --- a/app/views/shared/issuable/_participants.html.haml +++ b/app/views/shared/issuable/_participants.html.haml @@ -16,5 +16,3 @@ .hide-collapsed.participants-more %a.js-participants-more{ href: "#", data: { original_text: "+ #{participants_size - 7} more", less_text: "- show less" } } + #{participants_extra} more -:javascript - IssuableContext.prototype.PARTICIPANTS_ROW_COUNT = #{participants_row}; diff --git a/app/views/shared/issuable/_search_bar.html.haml b/app/views/shared/issuable/_search_bar.html.haml index 6f0b7600698..3428d6e0445 100644 --- a/app/views/shared/issuable/_search_bar.html.haml +++ b/app/views/shared/issuable/_search_bar.html.haml @@ -108,12 +108,3 @@ #js-add-issues-btn.prepend-left-10 - elsif type != :boards_modal = render 'shared/sort_dropdown' - -- unless type === :boards_modal - :javascript - $(document).off('page:restore').on('page:restore', function (event) { - if (gl.FilteredSearchManager) { - const filteredSearchManager = new gl.FilteredSearchManager(); - filteredSearchManager.setup(); - } - }); diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml index ecbaa901792..094f2472693 100644 --- a/app/views/shared/issuable/_sidebar.html.haml +++ b/app/views/shared/issuable/_sidebar.html.haml @@ -143,12 +143,6 @@ endpoint: "#{issuable_json_path(issuable)}?basic=true", editable: #{can_edit_issuable ? true : false}, currentUser: #{current_user.to_json(only: [:username, :id, :name], methods: :avatar_url)}, - rootPath: "#{root_path}" + rootPath: "#{root_path}", + fullPath: "#{@project.full_path}", }; - - new MilestoneSelect('{"full_path":"#{@project.full_path}"}'); - new LabelsSelect(); - new IssuableContext('#{escape_javascript(current_user.to_json(only: [:username, :id, :name]))}'); - gl.Subscription.bindAll('.subscription'); - new gl.DueDateSelectors(); - window.sidebar = new Sidebar(); diff --git a/app/views/shared/notes/_notes_with_form.html.haml b/app/views/shared/notes/_notes_with_form.html.haml index f0fcc414756..eae04c9bbb8 100644 --- a/app/views/shared/notes/_notes_with_form.html.haml +++ b/app/views/shared/notes/_notes_with_form.html.haml @@ -22,5 +22,4 @@ = link_to "sign in", new_session_path(:user, redirect_to_referer: 'yes') to comment -:javascript - var notes = new Notes("#{notes_url}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}", #{autocomplete}) +%script.js-notes-data{ type: "application/json" }= initial_notes_data(autocomplete).to_json.html_safe diff --git a/app/views/snippets/_snippets.html.haml b/app/views/snippets/_snippets.html.haml index ac3701233ad..dfea8b40bd8 100644 --- a/app/views/snippets/_snippets.html.haml +++ b/app/views/snippets/_snippets.html.haml @@ -1,4 +1,3 @@ -- remote = local_assigns.fetch(:remote, false) - link_project = local_assigns.fetch(:link_project, false) .snippets-list-holder @@ -8,7 +7,4 @@ %li .nothing-here-block Nothing here. - = paginate @snippets, theme: 'gitlab', remote: remote - -:javascript - gl.SnippetsList(); + = paginate @snippets, theme: 'gitlab' -- cgit v1.2.1 From fe27de8bf124d65013da1d82618a1ab45584ff68 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 25 Jul 2017 16:27:51 +0100 Subject: moved some code into new files fixed duplication of code --- app/assets/javascripts/dispatcher.js | 40 ++----------------------- app/assets/javascripts/init_issuable_sidebar.js | 16 ++++++++++ app/assets/javascripts/init_legacy_filters.js | 14 +++++++++ app/assets/javascripts/init_notes.js | 14 +++++++++ app/assets/javascripts/main.js | 5 ++++ app/assets/javascripts/todos.js | 4 --- 6 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 app/assets/javascripts/init_issuable_sidebar.js create mode 100644 app/assets/javascripts/init_legacy_filters.js create mode 100644 app/assets/javascripts/init_notes.js diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 8a142e49b72..2802c3a375a 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -30,7 +30,6 @@ /* global IssuableContext */ /* global IssueStatusSelect */ /* global SubscriptionSelect */ -/* global Notes */ import Issue from './issue'; import BindInOut from './behaviors/bind_in_out'; @@ -66,6 +65,9 @@ import initSettingsPanels from './settings_panels'; import initExperimentalFlags from './experimental_flags'; import OAuthRememberMe from './oauth_remember_me'; import PerformanceBar from './performance_bar'; +import initNotes from './init_notes'; +import initLegacyFilters from './init_legacy_filters'; +import initIssuableSidebar from './init_issuable_sidebar'; (function() { var Dispatcher; @@ -130,42 +132,6 @@ import PerformanceBar from './performance_bar'; .init(); } - function initIssuableSidebar() { - new MilestoneSelect({ - full_path: gl.sidebarOptions.fullPath, - }); - new LabelsSelect(); - new IssuableContext(gl.sidebarOptions.currentUser); - gl.Subscription.bindAll('.subscription'); - new gl.DueDateSelectors(); - window.sidebar = new Sidebar(); - } - - function initLegacyFilters() { - new UsersSelect(); - new LabelsSelect(); - new MilestoneSelect(); - new IssueStatusSelect(); - new SubscriptionSelect(); - $('form.filter-form').on('submit', function (event) { - event.preventDefault(); - gl.utils.visitUrl(`${this.action}&${$(this).serialize()}`); - }); - } - - function initNotes() { - const dataEl = document.querySelector('.js-notes-data'); - const { - notesUrl, - notesIds, - now, - diffView, - autocomplete, - } = JSON.parse(dataEl.innerHTML); - - window.notes = new Notes(notesUrl, notesIds, now, diffView, autocomplete); - } - switch (page) { case 'profiles:preferences:show': initExperimentalFlags(); diff --git a/app/assets/javascripts/init_issuable_sidebar.js b/app/assets/javascripts/init_issuable_sidebar.js new file mode 100644 index 00000000000..82071348d99 --- /dev/null +++ b/app/assets/javascripts/init_issuable_sidebar.js @@ -0,0 +1,16 @@ +/* eslint-disable no-new */ +/* global MilestoneSelect */ +/* global LabelsSelect */ +/* global IssuableContext */ +/* global Sidebar */ + +export default () => { + new MilestoneSelect({ + full_path: gl.sidebarOptions.fullPath, + }); + new LabelsSelect(); + new IssuableContext(gl.sidebarOptions.currentUser); + gl.Subscription.bindAll('.subscription'); + new gl.DueDateSelectors(); + window.sidebar = new Sidebar(); +}; diff --git a/app/assets/javascripts/init_legacy_filters.js b/app/assets/javascripts/init_legacy_filters.js new file mode 100644 index 00000000000..aa25f295bbc --- /dev/null +++ b/app/assets/javascripts/init_legacy_filters.js @@ -0,0 +1,14 @@ +/* eslint-disable no-new */ +/* global UsersSelect */ +/* global LabelsSelect */ +/* global MilestoneSelect */ +/* global IssueStatusSelect */ +/* global SubscriptionSelect */ + +export default () => { + new UsersSelect(); + new LabelsSelect(); + new MilestoneSelect(); + new IssueStatusSelect(); + new SubscriptionSelect(); +}; diff --git a/app/assets/javascripts/init_notes.js b/app/assets/javascripts/init_notes.js new file mode 100644 index 00000000000..3a8b4360cb6 --- /dev/null +++ b/app/assets/javascripts/init_notes.js @@ -0,0 +1,14 @@ +/* global Notes */ + +export default () => { + const dataEl = document.querySelector('.js-notes-data'); + const { + notesUrl, + notesIds, + now, + diffView, + autocomplete, + } = JSON.parse(dataEl.innerHTML); + + window.notes = new Notes(notesUrl, notesIds, now, diffView, autocomplete); +}; diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 6d3f5390cf6..3afc420140d 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -346,4 +346,9 @@ $(function () { gl.utils.renderTimeago(); $(document).trigger('init.scrolling-tabs'); + + $('form.filter-form').on('submit', function (event) { + event.preventDefault(); + gl.utils.visitUrl(`${this.action}&${$(this).serialize()}`); + }); }); diff --git a/app/assets/javascripts/todos.js b/app/assets/javascripts/todos.js index cd305631c10..bba8b5abbb4 100644 --- a/app/assets/javascripts/todos.js +++ b/app/assets/javascripts/todos.js @@ -37,10 +37,6 @@ export default class Todos { this.initFilterDropdown($('.js-type-search'), 'type'); this.initFilterDropdown($('.js-action-search'), 'action_id'); - $('form.filter-form').on('submit', function applyFilters(event) { - event.preventDefault(); - gl.utils.visitUrl(`${this.action}&${$(this).serialize()}`); - }); return new UsersSelect(); } -- cgit v1.2.1 From 887227e0371858d5d048f61bfe0700e4b7ebab58 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 25 Jul 2017 16:46:15 +0100 Subject: moved some more inline code removed some global variable comments --- app/assets/javascripts/dispatcher.js | 3 --- app/assets/javascripts/init_issuable_sidebar.js | 6 ++++-- app/assets/javascripts/issuable_context.js | 4 +++- app/assets/javascripts/sidebar/sidebar_bundle.js | 3 ++- app/helpers/issuables_helper.rb | 10 ++++++++++ app/views/shared/issuable/_sidebar.html.haml | 9 +-------- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 2802c3a375a..0b2c7e434f0 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -27,9 +27,6 @@ /* global Shortcuts */ /* global Sidebar */ /* global ShortcutsWiki */ -/* global IssuableContext */ -/* global IssueStatusSelect */ -/* global SubscriptionSelect */ import Issue from './issue'; import BindInOut from './behaviors/bind_in_out'; diff --git a/app/assets/javascripts/init_issuable_sidebar.js b/app/assets/javascripts/init_issuable_sidebar.js index 82071348d99..29e3d2ea94e 100644 --- a/app/assets/javascripts/init_issuable_sidebar.js +++ b/app/assets/javascripts/init_issuable_sidebar.js @@ -5,11 +5,13 @@ /* global Sidebar */ export default () => { + const sidebarOptions = JSON.parse(document.querySelector('.js-sidebar-options').innerHTML); + new MilestoneSelect({ - full_path: gl.sidebarOptions.fullPath, + full_path: sidebarOptions.fullPath, }); new LabelsSelect(); - new IssuableContext(gl.sidebarOptions.currentUser); + new IssuableContext(sidebarOptions.currentUser); gl.Subscription.bindAll('.subscription'); new gl.DueDateSelectors(); window.sidebar = new Sidebar(); diff --git a/app/assets/javascripts/issuable_context.js b/app/assets/javascripts/issuable_context.js index a45ff3fc43e..26392db4b5b 100644 --- a/app/assets/javascripts/issuable_context.js +++ b/app/assets/javascripts/issuable_context.js @@ -4,6 +4,8 @@ import Cookies from 'js-cookie'; import UsersSelect from './users_select'; +const PARTICIPANTS_ROW_COUNT = 7; + (function() { this.IssuableContext = (function() { function IssuableContext(currentUser) { @@ -52,7 +54,7 @@ import UsersSelect from './users_select'; IssuableContext.prototype.initParticipants = function() { $(document).on("click", ".js-participants-more", this.toggleHiddenParticipants); return $(".js-participants-author").each(function(i) { - if (i >= 7) { + if (i >= PARTICIPANTS_ROW_COUNT) { return $(this).addClass("js-participants-hidden").hide(); } }); diff --git a/app/assets/javascripts/sidebar/sidebar_bundle.js b/app/assets/javascripts/sidebar/sidebar_bundle.js index 2b02af87d8a..a9df66748c5 100644 --- a/app/assets/javascripts/sidebar/sidebar_bundle.js +++ b/app/assets/javascripts/sidebar/sidebar_bundle.js @@ -5,7 +5,8 @@ import sidebarAssignees from './components/assignees/sidebar_assignees'; import Mediator from './sidebar_mediator'; function domContentLoaded() { - const mediator = new Mediator(gl.sidebarOptions); + const sidebarOptions = JSON.parse(document.querySelector('.js-sidebar-options').innerHTML); + const mediator = new Mediator(sidebarOptions); mediator.fetch(); const sidebarAssigneesEl = document.querySelector('#js-vue-sidebar-assignees'); diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 425af547330..f4fad7150e8 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -354,4 +354,14 @@ module IssuablesHelper params[:format] = :json if issuable.is_a?(Issue) end end + + def issuable_sidebar_options(issuable, can_edit_issuable) + { + endpoint: "#{issuable_json_path(issuable)}?basic=true", + editable: can_edit_issuable, + currentUser: current_user.as_json(only: [:username, :id, :name], methods: :avatar_url), + rootPath: root_path, + fullPath: @project.full_path + } + end end diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml index 094f2472693..b08267357e5 100644 --- a/app/views/shared/issuable/_sidebar.html.haml +++ b/app/views/shared/issuable/_sidebar.html.haml @@ -138,11 +138,4 @@ = project_ref = clipboard_button(text: project_ref, title: "Copy reference to clipboard", placement: "left") - :javascript - gl.sidebarOptions = { - endpoint: "#{issuable_json_path(issuable)}?basic=true", - editable: #{can_edit_issuable ? true : false}, - currentUser: #{current_user.to_json(only: [:username, :id, :name], methods: :avatar_url)}, - rootPath: "#{root_path}", - fullPath: "#{@project.full_path}", - }; + %script.js-sidebar-options{ type: "application/json" }= issuable_sidebar_options(issuable, can_edit_issuable).to_json.html_safe -- cgit v1.2.1 From 425dbdd222244bc00cab8c2dbd6bb94233d11a15 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 26 Jul 2017 11:13:35 +0100 Subject: fixed label subscription & merge conflicts --- app/assets/javascripts/dispatcher.js | 11 +++++++++-- app/assets/javascripts/init_legacy_filters.js | 3 ++- .../javascripts/merge_conflicts/merge_conflicts_bundle.js | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 0b2c7e434f0..bab2d59e67f 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -263,7 +263,6 @@ import initIssuableSidebar from './init_issuable_sidebar'; new ZenMode(); new gl.GLForm($('.release-form'), true); break; - case 'projects:merge_requests:conflicts:show': case 'projects:merge_requests:show': new gl.Diff(); shortcut_handler = new ShortcutsIssuable(true); @@ -381,7 +380,15 @@ import initIssuableSidebar from './init_issuable_sidebar'; if ($('.prioritized-labels').length) { new gl.LabelManager(); } - new gl.ProjectLabelSubscription('.label-subscription'); + $('.label-subscription').each((i, el) => { + const $el = $(el); + + if ($el.find('.dropdown-group-label').length) { + new gl.GroupLabelSubscription($el); + } else { + new gl.ProjectLabelSubscription($el); + } + }); break; case 'projects:network:show': // Ensure we don't create a particular shortcut handler here. This is diff --git a/app/assets/javascripts/init_legacy_filters.js b/app/assets/javascripts/init_legacy_filters.js index aa25f295bbc..1211c2c802c 100644 --- a/app/assets/javascripts/init_legacy_filters.js +++ b/app/assets/javascripts/init_legacy_filters.js @@ -1,10 +1,11 @@ /* eslint-disable no-new */ -/* global UsersSelect */ /* global LabelsSelect */ /* global MilestoneSelect */ /* global IssueStatusSelect */ /* global SubscriptionSelect */ +import UsersSelect from './users_select'; + export default () => { new UsersSelect(); new LabelsSelect(); diff --git a/app/assets/javascripts/merge_conflicts/merge_conflicts_bundle.js b/app/assets/javascripts/merge_conflicts/merge_conflicts_bundle.js index 17030c3e4d3..d74cf5328ad 100644 --- a/app/assets/javascripts/merge_conflicts/merge_conflicts_bundle.js +++ b/app/assets/javascripts/merge_conflicts/merge_conflicts_bundle.js @@ -2,6 +2,7 @@ /* global Flash */ import Vue from 'vue'; +import initIssuableSidebar from '../init_issuable_sidebar'; import './merge_conflict_store'; import './merge_conflict_service'; import './mixins/line_conflict_utils'; @@ -19,6 +20,8 @@ $(() => { resolveConflictsPath: conflictsEl.dataset.resolveConflictsPath }); + initIssuableSidebar(); + gl.MergeConflictsResolverApp = new Vue({ el: '#conflicts', data: mergeConflictsStore.state, -- cgit v1.2.1 From 795a63d83fa086a1785cfba3d50cc00f08c70967 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 28 Jul 2017 09:00:09 +0100 Subject: fixed form action not submitting the correct URL --- app/assets/javascripts/main.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index ca126217bda..cd45091c211 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -355,7 +355,12 @@ $(function () { $(document).trigger('init.scrolling-tabs'); $('form.filter-form').on('submit', function (event) { + const link = document.createElement('a'); + link.href = this.action; + + const action = `${this.action}${link.search === '' ? '?' : '&'}`; + event.preventDefault(); - gl.utils.visitUrl(`${this.action}&${$(this).serialize()}`); + gl.utils.visitUrl(`${action}${$(this).serialize()}`); }); }); -- cgit v1.2.1