From: Tom Clegg Date: Tue, 3 Jun 2014 08:17:32 +0000 (-0400) Subject: 2872: Add selection checkboxes to folder view. Compare pipeline instances and remove... X-Git-Tag: 1.1.0~2551^2~54 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/29487f418ff010e6ed536bc0a4d52997c1d0cd4f?hp=77225263b324d4a75f5f3fae1fd01d244dc4afa1 2872: Add selection checkboxes to folder view. Compare pipeline instances and remove multiple items. --- diff --git a/apps/workbench/app/assets/javascripts/pipeline_instances.js b/apps/workbench/app/assets/javascripts/pipeline_instances.js index d23ced7fbc..614f45fa58 100644 --- a/apps/workbench/app/assets/javascripts/pipeline_instances.js +++ b/apps/workbench/app/assets/javascripts/pipeline_instances.js @@ -72,3 +72,20 @@ $(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(e $(this).append(parsedData.summary + "
"); } }); + +var showhide_compare = function() { + var form = $('form#compare')[0]; + $('input[type=hidden][name="uuids[]"]', form).remove(); + $('input[type=submit]', form).prop('disabled',true).show(); + var checked_inputs = $('[data-object-uuid*=-d1hrv-] input[name="uuids[]"]:checked'); + if (checked_inputs.length >= 2 && checked_inputs.length <= 3) { + checked_inputs.each(function(){ + if(this.checked) { + $('input[type=submit]', form).prop('disabled',false).show(); + $(form).append($('').val(this.value)); + } + }); + } +}; +$('[data-object-uuid*=-d1hrv-] input[name="uuids[]"]').on('click', showhide_compare); +showhide_compare(); diff --git a/apps/workbench/app/assets/javascripts/selection.js b/apps/workbench/app/assets/javascripts/selection.js index 1e32c63564..59f0fd184f 100644 --- a/apps/workbench/app/assets/javascripts/selection.js +++ b/apps/workbench/app/assets/javascripts/selection.js @@ -100,13 +100,11 @@ jQuery(function($){ $('.remove-selection').on('click', remove_selection_click); $('#clear_selections_button').on('click', clear_selections); + $(document).trigger('selections-updated', [lst]); }; $(document). on('change', '.persistent-selection:checkbox', function(e) { - //console.log($(this)); - //console.log($(this).val()); - var inc = 0; if ($(this).is(":checked")) { add_selection($(this).val(), $(this).attr('friendly_name'), $(this).attr('href'), $(this).attr('friendly_type')); @@ -116,7 +114,6 @@ jQuery(function($){ } }); - $(window).on('load storage', update_count); $('#selection-form-content').on("click", function(e) { @@ -178,3 +175,42 @@ select_form_sources = null; return ret; }; })(); + +function dispatch_selection_action() { + // Build a new "href" attribute for this link by starting with the + // "data-href" attribute and appending ?foo[]=bar&foo[]=baz (or + // &foo=... as appropriate) to reflect the current object + // selections. + var data = []; + var param_name = $(this).attr('data-selection-param-name'); + var href = $(this).attr('data-href'); + $('.persistent-selection:checkbox:checked').each(function() { + data.push({name: param_name, value: $(this).val()}); + }); + if (href.indexOf('?') >= 0) + href += '&'; + else + href += '?'; + href += $.param(data, true); + $(this).attr('href', href); + return true; +} + +function enable_disable_selection_actions() { + var $checked = $('.persistent-selection:checkbox:checked'); + $('[data-selection-action]'). + closest('div.btn-group-sm'). + find('*'). + prop('disabled', ($checked.length == 0)); + $('[data-selection-action=compare]'). + closest('li'). + toggleClass('disabled', + ($checked.filter('[value*=-d1hrv-]').length < 2) || + ($checked.not('[value*=-d1hrv-]').length > 0)); +} + +$(document). + on('selections-updated ready ajax:complete', function() { + $('[data-selection-action]').click(dispatch_selection_action); + enable_disable_selection_actions(); + }); diff --git a/apps/workbench/app/controllers/folders_controller.rb b/apps/workbench/app/controllers/folders_controller.rb index 637ae3642b..000cbc9004 100644 --- a/apps/workbench/app/controllers/folders_controller.rb +++ b/apps/workbench/app/controllers/folders_controller.rb @@ -12,32 +12,39 @@ class FoldersController < ApplicationController end def remove_item + params[:item_uuids] = [params[:item_uuid]] + remove_items + render template: 'folders/remove_items' + end + + def remove_items @removed_uuids = [] links = [] - item = ArvadosBase.find params[:item_uuid] - if (item.class == Link and - item.link_class == 'name' and - item.tail_uuid = @object.uuid) - # Given uuid is a name link, linking an object to this - # folder. First follow the link to find the item we're removing, - # then delete the link. - links << item - item = ArvadosBase.find item.head_uuid - else - # Given uuid is an object. Delete all names. - links += Link.where(tail_uuid: @object.uuid, - head_uuid: item.uuid, - link_class: 'name') - end - links.each do |link| - @removed_uuids << link.uuid - link.destroy - end - if item.owner_uuid == @object.uuid - # Object is owned by this folder. Remove it from the folder by - # changing owner to the current user. - item.update_attributes owner_uuid: current_user.uuid - @removed_uuids << item.uuid + params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item| + if (item.class == Link and + item.link_class == 'name' and + item.tail_uuid == @object.uuid) + # Given uuid is a name link, linking an object to this + # folder. First follow the link to find the item we're removing, + # then delete the link. + links << item + item = ArvadosBase.find item.head_uuid + else + # Given uuid is an object. Delete all names. + links += Link.where(tail_uuid: @object.uuid, + head_uuid: item.uuid, + link_class: 'name') + end + links.each do |link| + @removed_uuids << link.uuid + link.destroy + end + if item.owner_uuid == @object.uuid + # Object is owned by this folder. Remove it from the folder by + # changing owner to the current user. + item.update_attributes owner_uuid: current_user.uuid + @removed_uuids << item.uuid + end end end diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index d9e97b95f7..5eed7f8f3d 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -180,7 +180,7 @@ module ApplicationHelper :class => "editable" }.merge(htmloptions).merge(ajax_options) edit_button = raw('') - if htmloptions[:tipplacement] == :left + if htmloptions[:btnplacement] == :left edit_button + ' ' + span_tag else span_tag + ' ' + edit_button diff --git a/apps/workbench/app/views/application/_choose.html.erb b/apps/workbench/app/views/application/_choose.html.erb index 4708ac51e5..c42adacc88 100644 --- a/apps/workbench/app/views/application/_choose.html.erb +++ b/apps/workbench/app/views/application/_choose.html.erb @@ -6,7 +6,7 @@