From 251324a846b3045bcd91c818c3910cdfc47af6c5 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Wed, 19 Sep 2012 23:10:31 +0200 Subject: [PATCH] SONAR-3812 Enhanced selection of metric properties --- .../resources/org/sonar/l10n/core.properties | 11 ++++ .../controllers/api/resources_controller.rb | 5 +- .../WEB-INF/app/helpers/application_helper.rb | 60 +++++++++++++++++-- .../WEB-INF/app/helpers/properties_helper.rb | 2 +- .../dashboard/_widget_properties.html.erb | 6 +- 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index cef409fa0b6..5af08a41b80 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -601,6 +601,17 @@ dashboard.TimeMachine.name=Time Machine search.results=results search.duration=({0} seconds) + +#------------------------------------------------------------------------------ +# +# SELECT2.js +# +#------------------------------------------------------------------------------ +select2.noMatches=No matches +select2.searching=Searching... +select2.tooShort=Please enter {0} more characters + + #------------------------------------------------------------------------------ # # WIDGETS diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb index 959b15dbdec..279c9577cf6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb @@ -19,14 +19,15 @@ # class Api::ResourcesController < Api::ApiController + # since version 3.3 def search search_text = params[:s]||'' page=(params[:p] ? params[:p].to_i : 1) page_size=(params[:ps] ? params[:ps].to_i : 10) if params[:q] qualifiers=params[:q].split(',') - elsif params[:rtp] - qualifiers=Java::OrgSonarServerUi::JRubyFacade.getInstance().getQualifiersWithProperty(params[:rtp]) + elsif params[:qp] + qualifiers=Java::OrgSonarServerUi::JRubyFacade.getInstance().getQualifiersWithProperty(params[:qp]) else qualifiers=[] end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index d3ca2a2bb35..f00302f9ed7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -633,7 +633,17 @@ module ApplicationHelper return 0 end - def resource_dropdown(name, options={}) + + # + # Creates an enhanced dropdown selection box of resources. Values are loaded on the fly via Ajax requests. + # ==== Options + # * :width - The width suffixed with unit, for example '300px' or '100%'. Default is '250px' + # * :html_id - The id of the HTML element. Default is the name. + # * :qualifiers - Array of resource qualifiers to filter. + # * :resource_type_property -Filter on resource types on which the property is enabled, for example 'supportsGlobalDashboards'. + # * :selected_resource - the resource that is selected by default. + # + def resource_select_tag(name, options={}) width=options[:width] html_id=options[:html_id]||name @@ -641,7 +651,7 @@ module ApplicationHelper if options[:qualifiers] ws_url+="q=#{options[:qualifiers].join(',')}" elsif options[:resource_type_property] - ws_url+="rtp=#{options[:resource_type_property]}" + ws_url+="qp=#{options[:resource_type_property]}" end ajax_options={ @@ -660,11 +670,18 @@ FUNC } ajax_options.merge!(options[:select2_ajax_options]) if options[:select2_ajax_options] - js_options={'minimumInputLength' => options[:minimumInputLength]||3} + min_length = 3 # see limitation in /api/resources/search + js_options={ + 'minimumInputLength' => min_length, + 'formatNoMatches' => "function(term){return '#{escape_javascript message('select2.noMatches')}'}", + 'formatSearching' => "function(){return '#{escape_javascript message('select2.searching')}'}", + 'formatInputTooShort' => "function(term, minLength){return '#{escape_javascript message('select2.tooShort', :params => [min_length])}'}" + } + js_options['width']= "'#{width}'" if width js_options['ajax']='{' + ajax_options.map{|k,v| "#{k}:#{v}"}.join(',') + '}' js_options.merge!(options[:select2_options]) if options[:select2_options] - html = "" + html = "" js = "$j('##{html_id}').select2({#{js_options.map{|k,v| "#{k}:#{v}"}.join(',')}});" resource = options[:selected_resource] @@ -675,4 +692,39 @@ FUNC "#{html}" end + + # + # Creates an enhanced dropdown selection box of metrics. + # ==== Options + # * :selected_key - the key of the metric that is selected by default. + # * :multiple - If set to true the selection will allow multiple choices. + # * :disabled - If set to true, the user will not be able to use this input. + # * :allow_empty - If set to true, selecting a value is not mandatory + # * :width - The width suffixed with unit, for example '300px' or '100%'. Default is '250px' + # * :html_id - The id of the HTML element. Default is the name. + # + def metric_select_tag(name, metrics, options={}) + width=options[:width]||'250px' + html_id=options[:html_id]||name + js_options={ + 'formatNoMatches' => "function(term){return '#{escape_javascript message('select2.noMatches')}'}", + 'width' => "'#{width}'" + } + + select_tag_prompt=nil + if options[:allow_empty] + # add a cross icon to the select2 box + js_options['placeholder']="''" + js_options['allowClear']=true + + # add a select