]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4884 Add filters: age, alert, component, favorite, date, key, language, name
authorStas Vilchik <vilchiks@gmail.com>
Wed, 27 Nov 2013 06:07:07 +0000 (12:07 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 27 Nov 2013 06:07:34 +0000 (12:07 +0600)
16 files changed:
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_favourites2.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_languages.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/navigator/_filter_templates.html.erb
sonar-server/src/main/webapp/javascripts/navigator/filters/base-filters.js
sonar-server/src/main/webapp/javascripts/navigator/filters/checkbox-filters.js [new file with mode: 0644]
sonar-server/src/main/webapp/javascripts/navigator/filters/favorite-filters.js
sonar-server/src/main/webapp/javascripts/navigator/filters/range-filters.js
sonar-server/src/main/webapp/javascripts/navigator/filters/select-filters.js
sonar-server/src/main/webapp/javascripts/navigator/filters/string-filters.js [new file with mode: 0644]
sonar-server/src/main/webapp/javascripts/navigator/issues-app.js
sonar-server/src/main/webapp/javascripts/navigator/measures-app.js
sonar-server/src/main/webapp/stylesheets/navigator.css
sonar-server/src/main/webapp/stylesheets/navigator.less
sonar-server/wro.xml

index 6e9a297ea32bd0762fd6a1a1af7b3a0a746b72e6..8d6cfb0f0f9b568a1c9a2e60f792cafdace7e88e 100644 (file)
@@ -56,6 +56,8 @@
     <%= javascript_include_tag 'navigator/filters/select-filters' %>
     <%= javascript_include_tag 'navigator/filters/ajax-select-filters' %>
     <%= javascript_include_tag 'navigator/filters/range-filters' %>
+    <%= javascript_include_tag 'navigator/filters/checkbox-filters' %>
+    <%= javascript_include_tag 'navigator/filters/string-filters' %>
     <%= javascript_include_tag 'navigator/filters/favorite-filters' %>
     <%= javascript_include_tag 'navigator/filters/more-criteria-filters' %>
     <%= javascript_include_tag 'navigator/filters/more-criteria-filters' %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_favourites2.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_favourites2.html.erb
new file mode 100644 (file)
index 0000000..e227662
--- /dev/null
@@ -0,0 +1,9 @@
+<% if logged_in? %>
+  {
+  <% current_user.favourited_measure_filters.each do |filter| %>
+    '<%= h filter.id -%>': '<%= h filter.name -%>',
+  <% end %>
+  }
+<% else %>
+  null
+<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_languages.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_languages.html.erb
new file mode 100644 (file)
index 0000000..35a14ca
--- /dev/null
@@ -0,0 +1,8 @@
+{
+<% Api::Utils.languages.each do |lang| %>
+  '<%= h lang.key -%>': '<%= h lang.name -%>',
+<% end %>
+}
+
+
+
index dd1baf376a82f175764e8689252ce4043cf35c54..fe2529c815577dfc0df988ce5354d0545f57c2b2 100644 (file)
   };
 
 
+  _.extend(window.SS, {
+    languages: <%= render :partial => 'measures/languages' -%>,
+    favorites: <%= render :partial => 'measures/favourites2' -%>
+  });
+
+
   var queryParams = [
     { key: 'qualifiers[]', value: <%= @filter.criteria['qualifiers'].to_json -%> },
+    { key: 'alertLevels[]', value: <%= @filter.criteria['alertLevels'].to_json -%> },
+    { key: 'fromDate', value: '<%= h @filter.criteria['fromDate'] -%>' },
+    { key: 'toDate', value: '<%= h @filter.criteria['toDate'] -%>' },
+    { key: 'ageMinDays', value: '<%= h @filter.criteria('ageMinDays') -%>' },
+    { key: 'ageMaxDays', value: '<%= h @filter.criteria['ageMaxDays'] -%>' },
+    <% if @filter.base_resource %>
+    { key: 'base', value: ['<%= h @filter.base_resource.key -%>'], text: ['<%= h @filter.base_resource.name(true) -%>'] },
+    <% end %>
+    { key: 'onFavourites', value: <%= @filter.criteria['onFavourites']=='true' -%> },
+    { key: 'keySearch', value: '<%= h @filter.criteria['keySearch'] -%>' },
+    { key: 'languages[]', value: <%= @filter.criteria['languages'].to_json -%> }
   ];
 
   window.SS.MeasuresNavigatorApp.start();
index cf48cb02a15ed6d3ef23e11b2706423c48f2aff7..beedea8a1f763e4e6b5e284fb82f7cb817a21de0 100644 (file)
   </div>
 </script>
 
+<script id="checkboxFilterTemplate" type="text/template">
+  <div class="navigator-filter-label">{{ name }}</div>
+  <div class="navigator-filter-value">
+    <input type="checkbox" name="{{ property }}" value="true" {[ if (value) { ]}checked{[ } ]}>
+  </div>
+  {[ if (optional) { ]}
+  <div class="navigator-filter-disable">&times;</div>
+  {[ } ]}
+</script>
+
+<script id="stringFilterTemplate" type="text/template">
+  <div class="navigator-filter-details-inner">
+    <input type="text" name="{{ property }}" value="{{ value }}">
+  </div>
+</script>
+
 <script id="favoriteFilterTemplate" type="text/template">
   <div class="navigator-filter-favorite-toggle"></div>
 </script>
index 56129a074a65def15331c00d87e162d9519741dd..efa14127b28309166401b9bfd3b92535d601ae34 100644 (file)
@@ -4,7 +4,13 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
 
 (function() {
 
-  var Filter = Backbone.Model.extend({});
+  var Filter = Backbone.Model.extend({
+
+    defaults: {
+      multiple: true
+    }
+
+  });
 
 
 
diff --git a/sonar-server/src/main/webapp/javascripts/navigator/filters/checkbox-filters.js b/sonar-server/src/main/webapp/javascripts/navigator/filters/checkbox-filters.js
new file mode 100644 (file)
index 0000000..5d7eac2
--- /dev/null
@@ -0,0 +1,51 @@
+/* global _:false */
+
+window.SS = typeof window.SS === 'object' ? window.SS : {};
+
+(function() {
+
+  var CheckboxFilterView = window.SS.BaseFilterView.extend({
+    template: '#checkboxFilterTemplate',
+    className: 'navigator-filter navigator-filter-inline',
+
+
+    events: function() {
+      return {
+        'click .navigator-filter-disable': 'disable'
+      };
+    },
+
+
+    renderInput: function() {},
+
+
+    renderValue: function() {
+      return (this.model.get('value') || false) ? 'Yes' : 'No';
+    },
+
+
+    isDefaultValue: function() {
+      return false;
+    },
+
+
+    restore: function(value) {
+      this.model.set({
+        value: value,
+        enabled: true
+      });
+    }
+
+  });
+
+
+
+  /*
+   * Export public classes
+   */
+
+  _.extend(window.SS, {
+    CheckboxFilterView: CheckboxFilterView
+  });
+
+})();
index a46c5feed869ee168d0e3fef680d967c251b2a12..e55b847f7d94a51b5c4f7c96deb6392db91cb800 100644 (file)
@@ -16,12 +16,12 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
 
     applyFavorite: function(e) {
       var id = $j(e.target).data('id');
-      window.location = baseUrl + '/issues/filter/' + id;
+      window.location = baseUrl + this.model.get('favoriteUrl') + '/' + id;
     },
 
 
     manage: function() {
-      window.location = baseUrl + '/issues/manage';
+      window.location = baseUrl + this.model.get('manageUrl');
     }
 
   });
index e70ffd48e5771b67347801fee10f289ed7993ca9..02e6486bbf5ae7d51c0003a3cca4862539d0e7ea 100644 (file)
@@ -103,12 +103,12 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
           paramTo = _.findWhere(q, { key: this.model.get('propertyTo') }),
           value = {};
 
-      if (paramFrom.value || paramTo.value) {
-        if (paramFrom.value) {
+      if ((paramFrom && paramFrom.value) || (paramTo && paramTo.value)) {
+        if (paramFrom && paramFrom.value) {
           value[this.model.get('propertyFrom')] = paramFrom.value;
         }
 
-        if (paramTo.value) {
+        if (paramTo && paramTo.value) {
           value[this.model.get('propertyTo')] = paramTo.value;
         }
 
index c754f72030c424359c1933cd5dbc3683e86353b7..5681ca8f3d735075010510918814c3facdacef38 100644 (file)
@@ -52,8 +52,13 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
       var id = $j(e.target).val(),
           model = this.options.filterView.choices.findWhere({ id: id });
 
-      this.options.filterView.selection.add(model);
-      this.options.filterView.choices.remove(model);
+      if (this.model.get('multiple')) {
+        this.options.filterView.selection.add(model);
+        this.options.filterView.choices.remove(model);
+      } else {
+        this.options.filterView.choices.add(this.options.filterView.selection.models);
+        this.options.filterView.selection.reset([model]);
+      }
 
       this.updateValue();
       this.updateLists();
@@ -232,9 +237,10 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
     renderValue: function() {
       var value = this.selection.map(function(item) {
             return item.get('text');
-          });
+          }),
+          defaultValue = this.model.get('multiple') ? 'All' : 'Any';
 
-      return this.isDefaultValue() ? 'All' : value.join(', ');
+      return this.isDefaultValue() ? defaultValue : value.join(', ');
     },
 
 
diff --git a/sonar-server/src/main/webapp/javascripts/navigator/filters/string-filters.js b/sonar-server/src/main/webapp/javascripts/navigator/filters/string-filters.js
new file mode 100644 (file)
index 0000000..7e9ef37
--- /dev/null
@@ -0,0 +1,85 @@
+/* global _:false, $j:false */
+
+window.SS = typeof window.SS === 'object' ? window.SS : {};
+
+(function() {
+
+  var DetailsStringFilterView = window.SS.DetailsFilterView.extend({
+    template: '#stringFilterTemplate',
+
+
+    events: {
+      'change input': 'change'
+    },
+
+
+    change: function(e) {
+      this.model.set('value', $j(e.target).val());
+    },
+
+
+    onShow: function() {
+      window.SS.DetailsFilterView.prototype.onShow.apply(this, arguments);
+      this.$(':input').focus();
+    },
+
+
+    serializeData: function() {
+      return _.extend({}, this.model.toJSON(), {
+        value: this.model.get('value') || ''
+      });
+    }
+
+  });
+
+
+
+  var StringFilterView = window.SS.BaseFilterView.extend({
+
+    initialize: function() {
+      window.SS.BaseFilterView.prototype.initialize.call(this, {
+        detailsView: DetailsStringFilterView
+      });
+    },
+
+
+    renderValue: function() {
+      return this.isDefaultValue() ? '—' : this.model.get('value');
+    },
+
+
+    renderInput: function() {
+      $j('<input>')
+          .prop('name', this.model.get('property'))
+          .prop('type', 'hidden')
+          .css('display', 'none')
+          .val(this.model.get('value') || '')
+          .appendTo(this.$el);
+    },
+
+
+    isDefaultValue: function() {
+      return !this.model.get('value');
+    },
+
+
+    restore: function(value) {
+      this.model.set({
+        value: value,
+        enabled: true
+      });
+    }
+
+  });
+
+
+
+  /*
+   * Export public classes
+   */
+
+  _.extend(window.SS, {
+    StringFilterView: StringFilterView
+  });
+
+})();
index 048df0fc80df39d3e8dda1d8c14f0fbdcaa6eecc..c2b38d588aa46fdfd8e82ac2039bac27b9bfd3e2 100644 (file)
@@ -23,7 +23,9 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
           type: window.SS.FavoriteFilterView,
           enabled: true,
           optional: false,
-          choices: window.SS.favorites
+          choices: window.SS.favorites,
+          favoriteUrl: '/issues/filter',
+          manageUrl: '/issues/manage'
         })]);
     }
 
index 76413d7c939ea3a1377fd3546f657368e1f0a215..4612850a6794dc8db6588fd0b0cf27792aaecfee 100644 (file)
@@ -23,7 +23,9 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
           type: window.SS.FavoriteFilterView,
           enabled: true,
           optional: false,
-          choices: window.SS.favorites
+          choices: window.SS.favorites,
+          favoriteUrl: '/measures/filter',
+          manageUrl: '/measures/manage'
         })]);
     }
 
@@ -41,6 +43,79 @@ window.SS = typeof window.SS === 'object' ? window.SS : {};
           'FIL': 'Files',
           'UTS': 'Unit Test Files'
         }
+      }),
+
+      new window.SS.Filter({
+        name: 'Age',
+        propertyFrom: 'ageMinDays',
+        propertyTo: 'ageMaxDays',
+        type: window.SS.RangeFilterView,
+        enabled: false,
+        optional: true
+      }),
+
+      new window.SS.Filter({
+        name: 'Alert',
+        property: 'alertLevels[]',
+        type: window.SS.SelectFilterView,
+        enabled: false,
+        optional: true,
+        choices: {
+          'error': 'Error',
+          'warn': 'Warning',
+          'ok': 'Ok'
+        }
+      }),
+
+      new window.SS.Filter({
+        name: 'Components of',
+        property: 'base',
+        type: window.SS.ProjectFilterView,
+        multiple: false,
+        enabled: false,
+        optional: true
+      }),
+
+      new window.SS.Filter({
+        name: 'Favorites only',
+        property: 'onFavourites',
+        type: window.SS.CheckboxFilterView,
+        enabled: false,
+        optional: true
+      }),
+
+      new window.SS.Filter({
+        name: 'Date',
+        propertyFrom: 'fromDate',
+        propertyTo: 'toDate',
+        type: window.SS.DateRangeFilterView,
+        enabled: false,
+        optional: true
+      }),
+
+      new window.SS.Filter({
+        name: 'Key contains',
+        property: 'keySearch',
+        type: window.SS.StringFilterView,
+        enabled: false,
+        optional: true
+      }),
+
+      new window.SS.Filter({
+        name: 'Language',
+        property: 'languages[]',
+        type: window.SS.SelectFilterView,
+        enabled: false,
+        optional: true,
+        choices: window.SS.languages
+      }),
+
+      new window.SS.Filter({
+        name: 'Name contains',
+        property: 'nameSearch',
+        type: window.SS.StringFilterView,
+        enabled: false,
+        optional: true
       })
     ]);
 
index 9adaf436e25ef059ac84904b5d0bd83a5d4b98d7..023b57618bd576864bf48af098ee25171763581c 100644 (file)
 .navigator-filter-optional {
   padding-right: 0;
 }
+.navigator-filter-inline {
+  cursor: default;
+}
+.navigator-filter-inline:hover,
+.navigator-filter-inline.active {
+  border-color: transparent;
+  background: transparent;
+}
 .navigator-filter-label {
   display: inline-block;
   vertical-align: middle;
index 4305835d20fb34a13bc0af5a060402a7ec5fe28a..504733eb74bdf41565ed22346ca67c3adcd20f24 100644 (file)
   padding-right: 0;
 }
 
+.navigator-filter-inline {
+  cursor: default;
+
+  &:hover,
+  &.active {
+    border-color: transparent;
+    background: transparent;
+  }
+}
+
 .navigator-filter-label {
   display: inline-block;
   vertical-align: middle;
index 125e65af0516a81cfee6547bf8f4a32047c367b5..7ac0b8897e3b3aead985519ac761c6a16a1a7734 100644 (file)
@@ -36,6 +36,8 @@
     <js>/javascripts/navigator/filters/select-filters.js</js>
     <js>/javascripts/navigator/filters/ajax-select-filters.js</js>
     <js>/javascripts/navigator/filters/range-filters.js</js>
+    <js>/javascripts/navigator/filters/checkbox-filters.js</js>
+    <js>/javascripts/navigator/filters/string-filters.js</js>
     <js>/javascripts/navigator/filters/favorite-filters.js</js>
     <js>/javascripts/navigator/filters/more-criteria-filters.js</js>
     <js>/javascripts/navigator/issues-app.js</js>