From: Peter Amstutz Date: Wed, 26 Feb 2014 16:58:38 +0000 (-0500) Subject: Pipeline parameter editing supports selection box for choosing from workbench persist... X-Git-Tag: 1.1.0~2715^2~8 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/52838f7dfc576e8a11411fd9f1710a758573a6e7 Pipeline parameter editing supports selection box for choosing from workbench persistent selection list. Actually committing changes not tested yet. Also changed layout of selection dropdown and added "clear selections" button. --- diff --git a/apps/workbench/app/assets/javascripts/application.js b/apps/workbench/app/assets/javascripts/application.js index bcedc4b7b5..e7884b9516 100644 --- a/apps/workbench/app/assets/javascripts/application.js +++ b/apps/workbench/app/assets/javascripts/application.js @@ -21,7 +21,7 @@ //= require bootstrap3-editable/bootstrap-editable //= require_tree . -(function($){ +jQuery(function($){ $.ajaxSetup({ headers: { 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') @@ -140,4 +140,4 @@ fixer.duplicateTheadTr(); fixer.fixThead(); }); -})(jQuery); +}); diff --git a/apps/workbench/app/assets/javascripts/selection.js b/apps/workbench/app/assets/javascripts/selection.js index 5d0900aa76..29c52d6e42 100644 --- a/apps/workbench/app/assets/javascripts/selection.js +++ b/apps/workbench/app/assets/javascripts/selection.js @@ -3,27 +3,31 @@ /** Javascript for local persistent selection. */ +get_selection_list = null; + (function($){ - var get_storage = function() { - if (!sessionStorage.persistentSelection) { - sessionStorage.persistentSelection = JSON.stringify([]); + var storage = localStorage; // sessionStorage + + get_selection_list = function() { + if (!storage.persistentSelection) { + storage.persistentSelection = JSON.stringify([]); } - return JSON.parse(sessionStorage.persistentSelection); + return JSON.parse(storage.persistentSelection); } var put_storage = function(lst) { - sessionStorage.persistentSelection = JSON.stringify(lst); + storage.persistentSelection = JSON.stringify(lst); } var add_selection = function(uuid, name, href, type) { - var lst = get_storage(); + var lst = get_selection_list(); lst.push({"uuid": uuid, "name": name, "href": href, "type": type}); put_storage(lst); update_count(); }; var remove_selection = function(uuid) { - var lst = get_storage(); + var lst = get_selection_list(); for (var i = 0; i < lst.length; i++) { if (lst[i].uuid == uuid) { lst.splice(i, 1); @@ -35,34 +39,42 @@ }; var remove_selection_click = function(e) { - remove_selection($(this).attr('name')); + //remove_selection($(this).attr('name')); + remove_selection($(this).val()); }; + var clear_selections = function() { + put_storage([]); + update_count(); + } + var update_count = function(e) { - var lst = get_storage(); + var lst = get_selection_list(); $("#persistent-selection-count").text(lst.length); - $('#persistent-selection-list > li > table').empty(); if (lst.length > 0) { + $('#persistent-selection-list').html('
  • Clear selections
  • ' + +'
  • '); for (var i = 0; i < lst.length; i++) { $('#persistent-selection-list > li > table').append("" - + "" - + "" + lst[i].type + "" + + "" + + "
    " + + "" + + "
    " + "" + "" - + "" + lst[i].name + "" + + "" + lst[i].name + "" + "" - + "" - + "" - + "" - + "" + + "" + + "" + lst[i].type + "" + "" + + ""); } } else { - $('#persistent-selection-list > li > table').html("No selections."); + $('#persistent-selection-list').html("
  • No selections.
  • "); } var checkboxes = $('.persistent-selection:checkbox'); @@ -79,6 +91,7 @@ } $('.remove-selection').on('click', remove_selection_click); + $('#clear_selections_button').on('click', clear_selections); }; $(document). diff --git a/apps/workbench/app/assets/stylesheets/application.css.scss b/apps/workbench/app/assets/stylesheets/application.css.scss index 2bbff9b8e3..be54dd01ba 100644 --- a/apps/workbench/app/assets/stylesheets/application.css.scss +++ b/apps/workbench/app/assets/stylesheets/application.css.scss @@ -189,15 +189,6 @@ table.table-fixed-header-row tbody { width: 500px; } -#persistent-selection-list li { - margin-left: 1em; - padding: 3px 20px; - font-weight: normal; - line-height: 1.42857; - color: rgb(51, 51, 51); - -} - #persistent-selection-list li table tr { - border-bottom: 1px solid rgb(221, 221, 221); + border-top: 1px solid rgb(221, 221, 221); } diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index 2817735fe8..412f86ce07 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -24,6 +24,7 @@ class ApplicationController < ActionController::Base def unprocessable(message=nil) @errors ||= [] + @errors << message if message render_error status: 422 end diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index 48b6bb404d..b6690427f1 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -3,6 +3,10 @@ module ApplicationHelper controller.current_user end + def self.match_uuid(uuid) + /^([0-9a-z]{5})-([0-9a-z]{5})-([0-9a-z]{15})$/.match(uuid.to_s) + end + def current_api_host Rails.configuration.arvados_v1_base.gsub /https?:\/\/|\/arvados\/v1/,'' end @@ -100,4 +104,61 @@ module ApplicationHelper :class => "editable" }.merge(htmloptions) end + + def render_editable_subattribute(object, attr, subattr, template, htmloptions={}) + attrvalue = object.send(attr) + subattr.each do |k| + attrvalue = attrvalue[k] + end + + datatype = nil + if template + if template.is_a? Hash + if template[:output_of] + return "Output of \"#{template[:output_of]}\"" + elsif template[:datatype] + datatype = template[:datatype] + end + elsif attrvalue == nil + attrvalue = template + end + end + + return attrvalue if !object.attribute_editable? attr + + if not datatype + dataclass = ArvadosBase.resource_class_for_uuid(attrvalue) + if dataclass + datatype = 'select' + else + if /^\d+$/.match(attrvalue) + datatype = 'number' + elsif + datatype = 'text' + end + end + end + + subattr.insert(0, attr) + id = "#{object.uuid}-#{subattr.join('-')}" + + lt = link_to attrvalue, '#', { + "data-emptytext" => "none", + "data-placement" => "bottom", + "data-type" => datatype, + "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore), + "data-title" => "Update #{subattr[-1].to_s.titleize}", + "data-name" => subattr.to_json, + "data-pk" => "{id: \"#{object.uuid}\", key: \"#{object.class.to_s.underscore}\"}", + :class => "editable", + :id => id + }.merge(htmloptions) + + lt += raw(%{ +}) + + lt + end end diff --git a/apps/workbench/app/helpers/collections_helper.rb b/apps/workbench/app/helpers/collections_helper.rb index b2eee48ea6..df0ba22eac 100644 --- a/apps/workbench/app/helpers/collections_helper.rb +++ b/apps/workbench/app/helpers/collections_helper.rb @@ -4,4 +4,8 @@ module CollectionsHelper {source: x.tail_uuid, target: x.head_uuid, type: x.name} end end + + def self.match(uuid) + /^([a-f0-9]{32}(\+[0-9]+)?)(\+.*)?$/.match(uuid.to_s) + end end diff --git a/apps/workbench/app/helpers/provenance_helper.rb b/apps/workbench/app/helpers/provenance_helper.rb index 6d6ae5516c..8278d37f3e 100644 --- a/apps/workbench/app/helpers/provenance_helper.rb +++ b/apps/workbench/app/helpers/provenance_helper.rb @@ -9,7 +9,7 @@ module ProvenanceHelper end def self.collection_uuid(uuid) - m = /^([a-f0-9]{32}(\+[0-9]+)?)(\+.*)?$/.match(uuid.to_s) + m = CollectionsHelper.match(uuid) if m #if m[2] return m[1] diff --git a/apps/workbench/app/models/pipeline_instance.rb b/apps/workbench/app/models/pipeline_instance.rb index da6116e916..14eb89ab2b 100644 --- a/apps/workbench/app/models/pipeline_instance.rb +++ b/apps/workbench/app/models/pipeline_instance.rb @@ -18,7 +18,7 @@ class PipelineInstance < ArvadosBase end def attribute_editable?(attr) - attr == 'name' + attr.to_sym == :name || (attr.to_sym == :components and self.active == nil) end def attributes_for_display diff --git a/apps/workbench/app/views/layouts/application.html.erb b/apps/workbench/app/views/layouts/application.html.erb index 1d6a46828a..2128515860 100644 --- a/apps/workbench/app/views/layouts/application.html.erb +++ b/apps/workbench/app/views/layouts/application.html.erb @@ -115,14 +115,13 @@ --> - diff --git a/apps/workbench/app/views/pipeline_instances/_show_components.html.erb b/apps/workbench/app/views/pipeline_instances/_show_components.html.erb index 1785f6ac0b..395ef77369 100644 --- a/apps/workbench/app/views/pipeline_instances/_show_components.html.erb +++ b/apps/workbench/app/views/pipeline_instances/_show_components.html.erb @@ -23,6 +23,19 @@ table.pipeline-components-table td { <% end %> +<% content_for :js do %> + function select_Collection_source() { + var ret = []; + var lst = get_selection_list(); + for (var i = 0; i < lst.length; i++) { + if (lst[i].type == 'Collection') { + ret.push({text: lst[i].name, value: lst[i].uuid}) + } + } + return ret; + }; +<% end %> + <% if @object.active != nil %> @@ -113,7 +126,8 @@ setInterval(function(){$('a.refresh').click()}, 30000); - <% @object.components.each do |k, v| %> + <% template = PipelineTemplate.find(@object.pipeline_template_uuid) %> + <% template.components.each do |k, v| %> <% sp = v[:script_parameters].collect do |k, v| [k, v] end %> @@ -129,7 +143,7 @@ setInterval(function(){$('a.refresh').click()}, 30000); @@ -139,8 +153,8 @@ setInterval(function(){$('a.refresh').click()}, 30000); <% sp[1..-1].each do |p| %> - - + + <% end %> <% end %>
    - <%= sp[0][1] %> + <%= render_editable_subattribute @object, :components, [k, :script_parameters, sp[0][0].to_sym], sp[0][1] %>
    <%= p[0] %><%= p[1] %><%= p[0] %><%= p[1] %>