summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-05-05 17:10:54 -0500
committerAlfredo Sumaran <alfredo@gitlab.com>2016-06-03 17:14:23 -0500
commitf1291b1b9f28f2ee32d7bbc63b7b57db10b03006 (patch)
tree8acbb60aafee9f76ed5c9526fbfa520252bf68bf /app
parentf02ee98697ba2829bf092d662c24e2e553832fe9 (diff)
downloadgitlab-ce-f1291b1b9f28f2ee32d7bbc63b7b57db10b03006.tar.gz
Bulk assignment implementation
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/dispatcher.js.coffee1
-rw-r--r--app/assets/javascripts/issues-bulk-assignment.js.coffee108
-rw-r--r--app/views/shared/issuable/_filter.html.haml4
3 files changed, 111 insertions, 2 deletions
diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee
index cd418ad244a..bae67a2ebaf 100644
--- a/app/assets/javascripts/dispatcher.js.coffee
+++ b/app/assets/javascripts/dispatcher.js.coffee
@@ -17,6 +17,7 @@ class Dispatcher
switch page
when 'projects:issues:index'
Issuable.init()
+ new IssuableBulkActions()
shortcut_handler = new ShortcutsNavigation()
when 'projects:issues:show'
new Issue()
diff --git a/app/assets/javascripts/issues-bulk-assignment.js.coffee b/app/assets/javascripts/issues-bulk-assignment.js.coffee
new file mode 100644
index 00000000000..da463a586c0
--- /dev/null
+++ b/app/assets/javascripts/issues-bulk-assignment.js.coffee
@@ -0,0 +1,108 @@
+class @IssuableBulkActions
+ constructor: (opts = {}) ->
+ # Set defaults
+ {
+ @container = $('.content')
+ @form = @getElement('.bulk-update')
+ @issues = @getElement('.issues-list .issue')
+ } = opts
+
+ @bindEvents()
+
+ getElement: (selector) ->
+ @container.find selector
+
+ bindEvents: ->
+ @form.on 'submit', @onFormSubmit.bind(@)
+
+ onFormSubmit: (e) ->
+ e.preventDefault()
+ @submit()
+
+ submit: ->
+ _this = @
+
+ xhr = $.ajax
+ url: @form.attr 'action'
+ method: @form.attr 'method'
+ dataType: 'JSON',
+ data: @getFormDataAsObject()
+
+ xhr.done (response, status, xhr) ->
+ Turbolinks.visit(location.href)
+
+ xhr.fail ->
+ console.error 'fail'
+
+ xhr.always ->
+ _this.onFormSubmitAlways()
+
+ onFormSubmitAlways: ->
+ @form.find('[type="submit"]').enable()
+
+ getSelectedIssues: ->
+ @issues.has('.selected_issue:checked')
+
+ getLabelsFromSelection: ->
+ labels = []
+
+ @getSelectedIssues().map ->
+ _labels = $(@).data('labels')
+ console.log _labels
+ if _labels
+ _labels.map (labelId)->
+ labels.push(labelId) if labels.indexOf(labelId) is -1
+
+ labels
+
+ ###*
+ * Will return only labels that were marked previously and the user has unmarked
+ * @return {Array} Label IDs
+ ###
+ getUnmarkedIndeterminedLabels: ->
+ result = []
+ labelsToKeep = []
+
+ for el in @getElement('.labels-filter .is-indeterminate')
+ labelsToKeep.push $(el).data('labelId')
+
+ for id in @getLabelsFromSelection()
+ # Only the ones that we are not going to keep
+ result.push(id) if labelsToKeep.indexOf(id) is -1
+
+ result
+
+ ###*
+ * Simple form serialization, it will return just what we need
+ * Returns key/value pairs from form data
+ ###
+ getFormDataAsObject: ->
+ formData =
+ update:
+ issues_ids: @form.find('#update_issues_ids').val()
+ add_label_ids: []
+ remove_label_ids: []
+
+ for id in @getLabelsToApply()
+ formData.update.add_label_ids.push id
+
+ for id in @getLabelsToRemove()
+ formData.update.remove_label_ids.push id
+
+ formData
+
+ getLabelsToApply: ->
+ labelIds = []
+ $labels = @form.find('.labels-filter input[name="update[label_ids][]"]')
+
+ for label in $labels
+ labelIds.push $(label).val() if label
+
+ labelIds
+
+ ###*
+ * Just an alias of @getUnmarkedIndeterminedLabels
+ * @return {Array} Array of labels
+ ###
+ getLabelsToRemove: ->
+ @getUnmarkedIndeterminedLabels()
diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml
index 0ca4b9a681a..8758de12f42 100644
--- a/app/views/shared/issuable/_filter.html.haml
+++ b/app/views/shared/issuable/_filter.html.haml
@@ -31,7 +31,7 @@
- if controller.controller_name == 'issues'
.issues_bulk_update.hide
- = form_tag bulk_update_namespace_project_issues_path(@project.namespace, @project), method: :post do
+ = form_tag bulk_update_namespace_project_issues_path(@project.namespace, @project), method: :post, class: 'bulk-update' do
.filter-item.inline
= dropdown_tag("Status", options: { toggle_class: "js-issue-status", title: "Change status", dropdown_class: "dropdown-menu-status dropdown-menu-selectable", data: { field_name: "update[state_event]" } } ) do
%ul
@@ -46,7 +46,7 @@
= dropdown_tag("Milestone", options: { title: "Assign milestone", toggle_class: 'js-milestone-select js-extra-options js-filter-submit js-filter-bulk-update', filter: true, dropdown_class: "dropdown-menu-selectable dropdown-menu-milestone", placeholder: "Search milestones", data: { show_no: true, field_name: "update[milestone_id]", project_id: @project.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), use_id: true } })
.filter-item.inline.labels-filter
- = render "shared/issuable/label_dropdown", classes: ' js-filter-bulk-update js-multiselect ', extra_options: false, filter_submit: false, show_footer: false, extra_options: false, data_options: { field_name: "update[label_ids][]", show_no: false, show_any: false, use_id: true }
+ = render "shared/issuable/label_dropdown", classes: ' js-filter-bulk-update js-multiselect ', show_create: false, show_footer: false, extra_options: false, filter_submit: false, show_footer: false, data_options: { persist_when_hide: "true", field_name: "update[label_ids][]", show_no: false, show_any: false, use_id: true }
= hidden_field_tag 'update[issues_ids]', []
= hidden_field_tag :state_event, params[:state_event]