From bc5bc7cb9efe760a540b761eb3cd712ef3de129f Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Wed, 3 Aug 2016 16:45:38 -0500 Subject: [PATCH] Fix class names and move each class to its own file --- .../allowed_to_merge_dropdowns.js.es6 | 13 +++++ .../allowed_to_merge_select.js.es6 | 0 .../allowed_to_push_dropdowns.js.es6 | 13 +++++ .../protected_branch_access_dropdown.js.es6 | 18 +++++++ ....js.es6 => protected_branch_create.js.es6} | 51 +------------------ ...it.js.es6 => protected_branch_edit.js.es6} | 19 ++----- .../protected_branch_edit_list.js.es6 | 12 +++++ .../protected_branch_select.js.es6 | 6 +-- app/assets/stylesheets/pages/projects.scss | 9 +++- .../_branches_list.html.haml | 12 +++-- 10 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 app/assets/javascripts/allowed_to_merge_dropdowns.js.es6 delete mode 100644 app/assets/javascripts/allowed_to_merge_select.js.es6 create mode 100644 app/assets/javascripts/allowed_to_push_dropdowns.js.es6 create mode 100644 app/assets/javascripts/protected_branch_access_dropdown.js.es6 rename app/assets/javascripts/{protect_branch_create.js.es6 => protected_branch_create.js.es6} (52%) rename app/assets/javascripts/{protect_branch_edit.js.es6 => protected_branch_edit.js.es6} (78%) create mode 100644 app/assets/javascripts/protected_branch_edit_list.js.es6 diff --git a/app/assets/javascripts/allowed_to_merge_dropdowns.js.es6 b/app/assets/javascripts/allowed_to_merge_dropdowns.js.es6 new file mode 100644 index 00000000000..3f62ad26f0f --- /dev/null +++ b/app/assets/javascripts/allowed_to_merge_dropdowns.js.es6 @@ -0,0 +1,13 @@ +class AllowedToMergeDropdowns { + constructor (options) { + const { $dropdowns, onSelect } = options; + + $dropdowns.each((i, el) => { + new ProtectedBranchAccessDropdown({ + $dropdown: $(el), + data: gon.merge_access_levels, + onSelect: onSelect + }); + }); + } +} diff --git a/app/assets/javascripts/allowed_to_merge_select.js.es6 b/app/assets/javascripts/allowed_to_merge_select.js.es6 deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/app/assets/javascripts/allowed_to_push_dropdowns.js.es6 b/app/assets/javascripts/allowed_to_push_dropdowns.js.es6 new file mode 100644 index 00000000000..055be38ccdb --- /dev/null +++ b/app/assets/javascripts/allowed_to_push_dropdowns.js.es6 @@ -0,0 +1,13 @@ +class AllowedToPushDropdowns { + constructor (options) { + const { $dropdowns, onSelect } = options; + + $dropdowns.each((i, el) => { + new ProtectedBranchAccessDropdown({ + $dropdown: $(el), + data: gon.push_access_levels, + onSelect: onSelect + }); + }); + } +} \ No newline at end of file diff --git a/app/assets/javascripts/protected_branch_access_dropdown.js.es6 b/app/assets/javascripts/protected_branch_access_dropdown.js.es6 new file mode 100644 index 00000000000..045c12570bd --- /dev/null +++ b/app/assets/javascripts/protected_branch_access_dropdown.js.es6 @@ -0,0 +1,18 @@ +class ProtectedBranchAccessDropdown { + constructor(options) { + const { $dropdown, data, onSelect } = options; + + $dropdown.glDropdown({ + data: data, + selectable: true, + fieldName: $dropdown.data('field-name'), + toggleLabel(item) { + return item.text; + }, + clicked(item, $el, e) { + e.preventDefault(); + onSelect(); + } + }); + } +} diff --git a/app/assets/javascripts/protect_branch_create.js.es6 b/app/assets/javascripts/protected_branch_create.js.es6 similarity index 52% rename from app/assets/javascripts/protect_branch_create.js.es6 rename to app/assets/javascripts/protected_branch_create.js.es6 index 830cc0beb73..efe91478b66 100644 --- a/app/assets/javascripts/protect_branch_create.js.es6 +++ b/app/assets/javascripts/protected_branch_create.js.es6 @@ -1,50 +1,3 @@ -class ProtectedBranchesAccessDropdown { - constructor(options) { - const { $dropdown, data, onSelect } = options; - - $dropdown.glDropdown({ - data: data, - selectable: true, - fieldName: $dropdown.data('field-name'), - toggleLabel(item) { - return item.text; - }, - clicked(item, $el, e) { - e.preventDefault(); - onSelect(); - } - }); - } -} - -class AllowedToMergeDropdowns { - constructor (options) { - const { $dropdowns, onSelect } = options; - - $dropdowns.each((i, el) => { - new ProtectedBranchesAccessDropdown({ - $dropdown: $(el), - data: gon.merge_access_levels, - onSelect: onSelect - }); - }); - } -} - -class AllowedToPushSelects { - constructor (options) { - const { $dropdowns, onSelect } = options; - - $dropdowns.each((i, el) => { - new ProtectedBranchesAccessDropdown({ - $dropdown: $(el), - data: gon.push_access_levels, - onSelect: onSelect - }); - }); - } -} - class ProtectedBranchCreate { constructor() { this.$wrap = this.$form = $('#new_protected_branch'); @@ -59,12 +12,12 @@ class ProtectedBranchCreate { }); // Allowed to Push dropdowns - new AllowedToPushSelects({ + new AllowedToPushDropdowns({ $dropdowns: this.$wrap.find('.js-allowed-to-push'), onSelect: this.onSelect.bind(this) }); - new ProtectedBranchSelects({ + new ProtectedBranchDropdowns({ $dropdowns: this.$wrap.find('.js-protected-branch-select'), onSelect: this.onSelect.bind(this) }); diff --git a/app/assets/javascripts/protect_branch_edit.js.es6 b/app/assets/javascripts/protected_branch_edit.js.es6 similarity index 78% rename from app/assets/javascripts/protect_branch_edit.js.es6 rename to app/assets/javascripts/protected_branch_edit.js.es6 index b8ba22a1d6c..20f13427c0b 100644 --- a/app/assets/javascripts/protect_branch_edit.js.es6 +++ b/app/assets/javascripts/protected_branch_edit.js.es6 @@ -10,14 +10,14 @@ class ProtectedBranchEdit { buildDropdowns() { // Allowed to merge dropdown - new ProtectedBranchesAccessDropdown({ + new ProtectedBranchAccessDropdown({ $dropdown: this.$allowedToMergeDropdown, data: gon.merge_access_levels, onSelect: this.onSelect.bind(this) }); // Allowed to push dropdown - new ProtectedBranchesAccessDropdown({ + new ProtectedBranchAccessDropdown({ $dropdown: this.$allowedToPushDropdown, data: gon.push_access_levels, onSelect: this.onSelect.bind(this) @@ -47,23 +47,10 @@ class ProtectedBranchEdit { success: () => { this.$wrap.effect('highlight'); }, - error: function() { + error() { $.scrollTo(0); new Flash('Failed to update branch!'); } }); } } - -class ProtectedBranchEditList { - constructor() { - this.$wrap = $('.protected-branches-list'); - - // Build edit forms - this.$wrap.find('.js-protected-branch-edit-form').each((i, el) => { - new ProtectedBranchEdit({ - $wrap: $(el) - }); - }); - } -} diff --git a/app/assets/javascripts/protected_branch_edit_list.js.es6 b/app/assets/javascripts/protected_branch_edit_list.js.es6 new file mode 100644 index 00000000000..6021ed87e2a --- /dev/null +++ b/app/assets/javascripts/protected_branch_edit_list.js.es6 @@ -0,0 +1,12 @@ +class ProtectedBranchEditList { + constructor() { + this.$wrap = $('.protected-branches-list'); + + // Build edit forms + this.$wrap.find('.js-protected-branch-edit-form').each((i, el) => { + new ProtectedBranchEdit({ + $wrap: $(el) + }); + }); + } +} diff --git a/app/assets/javascripts/protected_branch_select.js.es6 b/app/assets/javascripts/protected_branch_select.js.es6 index 9a259a473ae..6ca90453d49 100644 --- a/app/assets/javascripts/protected_branch_select.js.es6 +++ b/app/assets/javascripts/protected_branch_select.js.es6 @@ -1,4 +1,4 @@ -class ProtectedBranchSelect { +class ProtectedBranchDropdown { constructor(options) { this.onSelect = options.onSelect; this.$dropdown = options.$dropdown; @@ -74,12 +74,12 @@ class ProtectedBranchSelect { } } -class ProtectedBranchSelects { +class ProtectedBranchDropdowns { constructor(options) { const { $dropdowns, onSelect } = options; $dropdowns.each((i, el) => { - new ProtectedBranchSelect({ + new ProtectedBranchDropdown({ $dropdown: $(el), onSelect: onSelect }); diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss index 63ac471b356..cf9aa02600d 100644 --- a/app/assets/stylesheets/pages/projects.scss +++ b/app/assets/stylesheets/pages/projects.scss @@ -675,7 +675,14 @@ pre.light-well { } } - &.table-bordered { + .settings-message { + margin: 0; + border-radius: 0 0 1px 1px; + padding: 20px 0; + border: none; + } + + .table-bordered { border-radius: 1px; th:not(:last-child), td:not(:last-child) { diff --git a/app/views/projects/protected_branches/_branches_list.html.haml b/app/views/projects/protected_branches/_branches_list.html.haml index dc471f515d4..777e96c073f 100644 --- a/app/views/projects/protected_branches/_branches_list.html.haml +++ b/app/views/projects/protected_branches/_branches_list.html.haml @@ -1,16 +1,18 @@ -.panel.panel-default +.panel.panel-default.protected-branches-list - if @protected_branches.empty? + .panel-heading + %b Protected branch (#{@protected_branches.size}) %p.settings-message.text-center - No branches are protected, protect a branch with the form above. + There are currently no protected braches, protect a branch with the form above. - else - can_admin_project = can?(current_user, :admin_project, @project) - %table.table.protected-branches-list.table-bordered + %table.table.table-bordered %colgroup - %col{ width: "20%" } + %col{ width: "25%" } %col{ width: "30%" } %col{ width: "25%" } - %col{ width: "25%" } + %col{ width: "20%" } %thead %tr %th Protected branch (#{@protected_branches.size})