<%= render :partial => '/coding_rules/templates/coding_rules_list_empty_template.hbs' -%>
<%= render :partial => '/coding_rules/templates/coding_rules_detail_template.hbs' -%>
<%= render :partial => '/coding_rules/templates/coding_rules_facets_item_template.hbs' -%>
+<%= render :partial => '/coding_rules/templates/coding_rules_bulk_change_template.hbs' -%>
--- /dev/null
+<script id="coding-rules-bulk-change-template" type="text/x-handlebars-template">
+ <form>
+ <div class="modal-head">
+ <h2>{{t 'coding_rules.bulk_change'}}</h2>
+ </div>
+
+ <div class="modal-body">
+ <div class="modal-error"></div>
+
+ {{#if inactiveQualityProfile}}
+ <div class="modal-field">
+ <label for="coding-rules-bulk-change-activate-on-qp">Activate on</label>
+ <input id="coding-rules-bulk-change-activate-qp" type="checkbox">
+ <span class="text">{{inactiveQualityProfileName}}</span>
+ </div>
+ {{/if}}
+
+ <div class="modal-field">
+ <label for="coding-rules-bulk-change-activate-on">{{#unless inactiveQualityProfile}}Activate on{{/unless}}</label>
+ <input id="coding-rules-bulk-change-activate" type="checkbox">
+ <select id="coding-rules-bulk-change-activate-on" multiple>
+ {{#each activateOnQualityProfiles}}
+ <option value="{{key}}">{{name}}</option>
+ {{/each}}
+ </select>
+ </div>
+
+ {{#if activeQualityProfile}}
+ <div class="modal-field">
+ <label for="coding-rules-bulk-change-deactivate-on-qp">Deactivate on</label>
+ <input id="coding-rules-bulk-change-deactivate-qp" type="checkbox">
+ <span class="text">{{activeQualityProfileName}}</span>
+ </div>
+ {{/if}}
+
+ <div class="modal-field">
+ <label for="coding-rules-bulk-change-deactivate-on">{{#unless activeQualityProfile}}Deactivate on{{/unless}}</label>
+ <input id="coding-rules-bulk-change-deactivate" type="checkbox">
+ <select id="coding-rules-bulk-change-deactivate-on" multiple>
+ {{#each deactivateOnQualityProfiles}}
+ <option value="{{key}}">{{name}}</option>
+ {{/each}}
+ </select>
+ </div>
+
+ {{#if activeQualityProfile}}
+ <div class="modal-field">
+ <label for="coding-rules-bulk-change-severity">Change Severity</label>
+ <input id="coding-rules-bulk-change-set-severity" type="checkbox">
+ <select id="coding-rules-bulk-change-severity">
+ {{#each severities}}
+ <option value="{{this}}">{{t 'severity' this}}</option>
+ {{/each}}
+ </select>
+ </div>
+ {{/if}}
+ </div>
+
+ <div class="modal-foot">
+ <button>{{t 'apply'}}</button>
+ <a id="coding-rules-cancel-bulk-change" class="action">{{t 'cancel'}}</a>
+ </div>
+ </form>
+</script>
'coding-rules/views/actions-view',
'coding-rules/views/filter-bar-view',
'coding-rules/views/coding-rules-list-view',
+ 'coding-rules/views/coding-rules-bulk-change-view',
# filters
'navigator/filters/base-filters',
CodingRulesActionsView,
CodingRulesFilterBarView,
CodingRulesListView,
+ CodingRulesBulkChangeView,
# filters
BaseFilters,
if value? && value.length == 1 then value[0] else null
+ App.getInactiveQualityProfile = ->
+ value = @inactiveInFilter.get('value')
+ if value? && value.length == 1 then value[0] else null
+
+
# Construct layout
App.addInitializer ->
@layout = new CodingRulesLayout app: @
@layout.actionsRegion.show @codingRulesActionsView
+ # Construct bulk change view
+ App.addInitializer ->
+ @codingRulesBulkChangeView = new CodingRulesBulkChangeView app: @
+
+
# Define filters
App.addInitializer ->
@filters = new BaseFilters.Filters
}
});
- requirejs(['backbone', 'backbone.marionette', 'coding-rules/layout', 'coding-rules/router', 'coding-rules/views/header-view', 'coding-rules/views/actions-view', 'coding-rules/views/filter-bar-view', 'coding-rules/views/coding-rules-list-view', 'navigator/filters/base-filters', 'navigator/filters/choice-filters', 'navigator/filters/string-filters', 'navigator/filters/date-filter-view', 'coding-rules/views/filters/quality-profile-filter-view', 'coding-rules/views/filters/inheritance-filter-view', 'coding-rules/mockjax'], function(Backbone, Marionette, CodingRulesLayout, CodingRulesRouter, CodingRulesHeaderView, CodingRulesActionsView, CodingRulesFilterBarView, CodingRulesListView, BaseFilters, ChoiceFilters, StringFilterView, DateFilterView, QualityProfileFilterView, InheritanceFilterView) {
+ requirejs(['backbone', 'backbone.marionette', 'coding-rules/layout', 'coding-rules/router', 'coding-rules/views/header-view', 'coding-rules/views/actions-view', 'coding-rules/views/filter-bar-view', 'coding-rules/views/coding-rules-list-view', 'coding-rules/views/coding-rules-bulk-change-view', 'navigator/filters/base-filters', 'navigator/filters/choice-filters', 'navigator/filters/string-filters', 'navigator/filters/date-filter-view', 'coding-rules/views/filters/quality-profile-filter-view', 'coding-rules/views/filters/inheritance-filter-view', 'coding-rules/mockjax'], function(Backbone, Marionette, CodingRulesLayout, CodingRulesRouter, CodingRulesHeaderView, CodingRulesActionsView, CodingRulesFilterBarView, CodingRulesListView, CodingRulesBulkChangeView, BaseFilters, ChoiceFilters, StringFilterView, DateFilterView, QualityProfileFilterView, InheritanceFilterView) {
var App, appXHR;
jQuery.ajaxSetup({
error: function(jqXHR) {
return null;
}
};
+ App.getInactiveQualityProfile = function() {
+ var value;
+ value = this.inactiveInFilter.get('value');
+ if ((value != null) && value.length === 1) {
+ return value[0];
+ } else {
+ return null;
+ }
+ };
App.addInitializer(function() {
this.layout = new CodingRulesLayout({
app: this
});
return this.layout.actionsRegion.show(this.codingRulesActionsView);
});
+ App.addInitializer(function() {
+ return this.codingRulesBulkChangeView = new CodingRulesBulkChangeView({
+ app: this
+ });
+ });
App.addInitializer(function() {
this.filters = new BaseFilters.Filters;
this.filters.add(new BaseFilters.Filter({
url: "#{baseUrl}/api/codingrules/app"
responseText: JSON.stringify
qualityprofiles: [
- { name: 'Sonar Way', lang: 'Java' }
- { name: 'Sonar Way', lang: 'JavaScript' }
- { name: 'Quality Profile 1', lang: 'Java' }
+ { key: 'sonarway', name: 'Sonar Way', parent: null },
+ { key: 'qp1', name: 'Quality Profile 1', parent: 'sonarway' },
+ { key: 'qp2', name: 'Quality Profile 2', parent: 'sonarway' },
+ { key: 'qp3', name: 'Quality Profile 3', parent: null },
]
languages:
java: 'Java'
messages:
'all': 'All'
'any': 'Any'
+ 'apply': 'Apply'
'bulk_change': 'Bulk Change'
+ 'cancel': 'Cancel'
'moreCriteria': '+ More Criteria'
'search_verb': 'Search'
'update': 'Update'
'severity.INFO': 'Info'
'coding_rules.activate_quality_profile': 'Activate Quality Profile'
+ 'coding_rules.bulk_change': 'Bulk Change'
'coding_rules.deactivate_quality_profile': 'Deactivate'
'coding_rules.found': 'Found'
'coding_rules.new_search': 'New Search'
+ # POST /api/codingrules/bulk_change
+ jQuery.mockjax
+ url: "#{baseUrl}/api/codingrules/bulk_change"
+
+
# GET /api/qualityprofiles/list
jQuery.mockjax
url: "#{baseUrl}/api/qualityprofiles/list"
responseText: JSON.stringify({
qualityprofiles: [
{
+ key: 'sonarway',
name: 'Sonar Way',
- lang: 'Java'
- }, {
- name: 'Sonar Way',
- lang: 'JavaScript'
+ parent: null
}, {
+ key: 'qp1',
name: 'Quality Profile 1',
- lang: 'Java'
+ parent: 'sonarway'
+ }, {
+ key: 'qp2',
+ name: 'Quality Profile 2',
+ parent: 'sonarway'
+ }, {
+ key: 'qp3',
+ name: 'Quality Profile 3',
+ parent: null
}
],
languages: {
messages: {
'all': 'All',
'any': 'Any',
+ 'apply': 'Apply',
'bulk_change': 'Bulk Change',
+ 'cancel': 'Cancel',
'moreCriteria': '+ More Criteria',
'search_verb': 'Search',
'update': 'Update',
'severity.MINOR': 'Minor',
'severity.INFO': 'Info',
'coding_rules.activate_quality_profile': 'Activate Quality Profile',
+ 'coding_rules.bulk_change': 'Bulk Change',
'coding_rules.deactivate_quality_profile': 'Deactivate',
'coding_rules.found': 'Found',
'coding_rules.new_search': 'New Search',
}
})
});
+ jQuery.mockjax({
+ url: "" + baseUrl + "/api/codingrules/bulk_change"
+ });
jQuery.mockjax({
url: "" + baseUrl + "/api/qualityprofiles/list",
responseText: JSON.stringify({
events:
'click .navigator-actions-order': 'toggleOrderChoices'
'click @ui.orderChoices': 'sort'
+ 'click .navigator-actions-bulk': 'bulkChange'
onRender: ->
@options.app.fetchFirstPage()
+ bulkChange: ->
+ @options.app.codingRulesBulkChangeView.show()
+
+
serializeData: ->
_.extend super,
paging: @collection.paging
CodingRulesStatusView.prototype.events = {
'click .navigator-actions-order': 'toggleOrderChoices',
- 'click @ui.orderChoices': 'sort'
+ 'click @ui.orderChoices': 'sort',
+ 'click .navigator-actions-bulk': 'bulkChange'
};
CodingRulesStatusView.prototype.onRender = function() {
}
};
+ CodingRulesStatusView.prototype.bulkChange = function() {
+ return this.options.app.codingRulesBulkChangeView.show();
+ };
+
CodingRulesStatusView.prototype.serializeData = function() {
return _.extend(CodingRulesStatusView.__super__.serializeData.apply(this, arguments), {
paging: this.collection.paging,
--- /dev/null
+define [
+ 'backbone.marionette',
+ 'common/handlebars-extensions'
+], (
+ Marionette
+) ->
+
+ class CodingRulesBulkChangeView extends Marionette.ItemView
+ className: 'modal'
+ template: getTemplate '#coding-rules-bulk-change-template'
+
+
+ events:
+ 'submit form': 'onSubmit'
+ 'click #coding-rules-cancel-bulk-change': 'hide'
+ 'click label': 'enableAction'
+ 'change select': 'enableAction'
+
+
+ onRender: ->
+ @$el.dialog
+ dialogClass: 'no-close',
+ width: '600px',
+ draggable: false,
+ autoOpen: false,
+ modal: true,
+ minHeight: 50,
+ resizable: false,
+ title: null
+
+ @$('#coding-rules-bulk-change-activate-on, #coding-rules-bulk-change-deactivate-on').select2
+ width: '250px'
+ minimumResultsForSearch: 1
+
+ format = (state) ->
+ return state.text unless state.id
+ "<i class='icon-severity-#{state.id.toLowerCase()}'></i> #{state.text}"
+ @$('#coding-rules-bulk-change-severity').select2
+ width: '250px'
+ minimumResultsForSearch: 999
+ formatResult: format
+ formatSelection: format
+ escapeMarkup: (m) -> m
+
+
+ show: ->
+ @render()
+ @$el.dialog 'open'
+
+
+ hide: ->
+ @$el.dialog 'close'
+
+
+ prepareQuery: ->
+ query = @options.app.getQuery()
+ activateIn = []
+ deactivateIn = []
+ severity = null
+ if @$('#coding-rules-bulk-change-activate-qp').is(':checked')
+ activateIn.push @options.app.getInactiveQualityProfile()
+ if @$('#coding-rules-bulk-change-activate').is(':checked')
+ activateIn.push @$('#coding-rules-bulk-change-activate-on').val()
+ if @$('#coding-rules-bulk-change-deactivate-qp').is(':checked')
+ deactivateIn.push @options.app.getActiveQualityProfile()
+ if @$('#coding-rules-bulk-change-deactivate').is(':checked')
+ deactivateIn.push @$('#coding-rules-bulk-change-deactivate-on').val()
+ if @$('#coding-rules-bulk-change-set-severity').is(':checked')
+ severity = @$('#coding-rules-bulk-change-severity').val()
+ actions = []
+ if activateIn.length > 0
+ actions.push 'bulk_activate'
+ _.extend query, bulk_activate_in: activateIn.join(',')
+ if deactivateIn.length > 0
+ actions.push 'bulk_deactivate'
+ _.extend query, bulk_deactivate_in: deactivateIn.join(',')
+ if severity
+ actions.push 'bulk_set_severity'
+ _.extend query, bulk_severity: severity
+ _.extend query, bulk_actions: actions
+
+ onSubmit: (e) ->
+ e.preventDefault()
+ jQuery.ajax
+ type: 'POST'
+ url: "#{baseUrl}/api/codingrules/bulk_change"
+ data: @prepareQuery()
+ .done =>
+ @options.app.fetchFirstPage()
+ @hide()
+
+
+
+ enableAction: (e) ->
+ jQuery(e.target).siblings('input[type=checkbox]').prop 'checked', true
+
+
+ serializeData: ->
+ qualityProfiles: @options.app.qualityProfiles
+
+ activeQualityProfile: @options.app.getActiveQualityProfile()
+ activeQualityProfileName: @options.app.activeInFilter.view.renderValue()
+ activateOnQualityProfiles: _.reject @options.app.qualityProfiles, (q) => q.key == @options.app.getInactiveQualityProfile()
+
+ inactiveQualityProfile: @options.app.getInactiveQualityProfile()
+ inactiveQualityProfileName: @options.app.inactiveInFilter.view.renderValue()
+ deactivateOnQualityProfiles: _.reject @options.app.qualityProfiles, (q) => q.key == @options.app.getActiveQualityProfile()
+
+ severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO']
--- /dev/null
+// Generated by CoffeeScript 1.6.3
+(function() {
+ var __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ define(['backbone.marionette', 'common/handlebars-extensions'], function(Marionette) {
+ var CodingRulesBulkChangeView, _ref;
+ return CodingRulesBulkChangeView = (function(_super) {
+ __extends(CodingRulesBulkChangeView, _super);
+
+ function CodingRulesBulkChangeView() {
+ _ref = CodingRulesBulkChangeView.__super__.constructor.apply(this, arguments);
+ return _ref;
+ }
+
+ CodingRulesBulkChangeView.prototype.className = 'modal';
+
+ CodingRulesBulkChangeView.prototype.template = getTemplate('#coding-rules-bulk-change-template');
+
+ CodingRulesBulkChangeView.prototype.events = {
+ 'submit form': 'onSubmit',
+ 'click #coding-rules-cancel-bulk-change': 'hide',
+ 'click label': 'enableAction',
+ 'change select': 'enableAction'
+ };
+
+ CodingRulesBulkChangeView.prototype.onRender = function() {
+ var format;
+ this.$el.dialog({
+ dialogClass: 'no-close',
+ width: '600px',
+ draggable: false,
+ autoOpen: false,
+ modal: true,
+ minHeight: 50,
+ resizable: false,
+ title: null
+ });
+ this.$('#coding-rules-bulk-change-activate-on, #coding-rules-bulk-change-deactivate-on').select2({
+ width: '250px',
+ minimumResultsForSearch: 1
+ });
+ format = function(state) {
+ if (!state.id) {
+ return state.text;
+ }
+ return "<i class='icon-severity-" + (state.id.toLowerCase()) + "'></i> " + state.text;
+ };
+ return this.$('#coding-rules-bulk-change-severity').select2({
+ width: '250px',
+ minimumResultsForSearch: 999,
+ formatResult: format,
+ formatSelection: format,
+ escapeMarkup: function(m) {
+ return m;
+ }
+ });
+ };
+
+ CodingRulesBulkChangeView.prototype.show = function() {
+ this.render();
+ return this.$el.dialog('open');
+ };
+
+ CodingRulesBulkChangeView.prototype.hide = function() {
+ return this.$el.dialog('close');
+ };
+
+ CodingRulesBulkChangeView.prototype.prepareQuery = function() {
+ var actions, activateIn, deactivateIn, query, severity;
+ query = this.options.app.getQuery();
+ activateIn = [];
+ deactivateIn = [];
+ severity = null;
+ if (this.$('#coding-rules-bulk-change-activate-qp').is(':checked')) {
+ activateIn.push(this.options.app.getInactiveQualityProfile());
+ }
+ if (this.$('#coding-rules-bulk-change-activate').is(':checked')) {
+ activateIn.push(this.$('#coding-rules-bulk-change-activate-on').val());
+ }
+ if (this.$('#coding-rules-bulk-change-deactivate-qp').is(':checked')) {
+ deactivateIn.push(this.options.app.getActiveQualityProfile());
+ }
+ if (this.$('#coding-rules-bulk-change-deactivate').is(':checked')) {
+ deactivateIn.push(this.$('#coding-rules-bulk-change-deactivate-on').val());
+ }
+ if (this.$('#coding-rules-bulk-change-set-severity').is(':checked')) {
+ severity = this.$('#coding-rules-bulk-change-severity').val();
+ }
+ actions = [];
+ if (activateIn.length > 0) {
+ actions.push('bulk_activate');
+ _.extend(query, {
+ bulk_activate_in: activateIn.join(',')
+ });
+ }
+ if (deactivateIn.length > 0) {
+ actions.push('bulk_deactivate');
+ _.extend(query, {
+ bulk_deactivate_in: deactivateIn.join(',')
+ });
+ }
+ if (severity) {
+ actions.push('bulk_set_severity');
+ _.extend(query, {
+ bulk_severity: severity
+ });
+ }
+ return _.extend(query, {
+ bulk_actions: actions
+ });
+ };
+
+ CodingRulesBulkChangeView.prototype.onSubmit = function(e) {
+ var _this = this;
+ e.preventDefault();
+ return jQuery.ajax({
+ type: 'POST',
+ url: "" + baseUrl + "/api/codingrules/bulk_change",
+ data: this.prepareQuery()
+ }).done(function() {
+ _this.options.app.fetchFirstPage();
+ return _this.hide();
+ });
+ };
+
+ CodingRulesBulkChangeView.prototype.enableAction = function(e) {
+ return jQuery(e.target).siblings('input[type=checkbox]').prop('checked', true);
+ };
+
+ CodingRulesBulkChangeView.prototype.serializeData = function() {
+ var _this = this;
+ return {
+ qualityProfiles: this.options.app.qualityProfiles,
+ activeQualityProfile: this.options.app.getActiveQualityProfile(),
+ activeQualityProfileName: this.options.app.activeInFilter.view.renderValue(),
+ activateOnQualityProfiles: _.reject(this.options.app.qualityProfiles, function(q) {
+ return q.key === _this.options.app.getInactiveQualityProfile();
+ }),
+ inactiveQualityProfile: this.options.app.getInactiveQualityProfile(),
+ inactiveQualityProfileName: this.options.app.inactiveInFilter.view.renderValue(),
+ deactivateOnQualityProfiles: _.reject(this.options.app.qualityProfiles, function(q) {
+ return q.key === _this.options.app.getActiveQualityProfile();
+ }),
+ severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO']
+ };
+ };
+
+ return CodingRulesBulkChangeView;
+
+ })(Marionette.ItemView);
+ });
+
+}).call(this);
width: 250px;
}
+.modal-field .text {
+ line-height: 20px;
+}
+
.modal-foot {
text-align: right;
padding: 2px 10px;