diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-07-18 18:06:02 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-07-18 18:06:10 +0200 |
commit | 18a85015feb7a27bee89bcfda4421b92f0a9b8c7 (patch) | |
tree | 02eb02d65b07e9c7bfced1070edcdcf2b835bf70 /server/sonar-web/src/main | |
parent | e93420742f6d1361b5043eb56b15cbdbf7d00690 (diff) | |
download | sonarqube-18a85015feb7a27bee89bcfda4421b92f0a9b8c7.tar.gz sonarqube-18a85015feb7a27bee89bcfda4421b92f0a9b8c7.zip |
SONAR-3373 Integrate management of manual rules in Rules space
Diffstat (limited to 'server/sonar-web/src/main')
8 files changed, 224 insertions, 8 deletions
diff --git a/server/sonar-web/src/main/coffee/coding-rules/app.coffee b/server/sonar-web/src/main/coffee/coding-rules/app.coffee index 1add838f708..6aecd42562e 100644 --- a/server/sonar-web/src/main/coffee/coding-rules/app.coffee +++ b/server/sonar-web/src/main/coffee/coding-rules/app.coffee @@ -34,6 +34,7 @@ requirejs [ 'coding-rules/views/coding-rules-bulk-change-dropdown-view', 'coding-rules/views/coding-rules-facets-view', 'coding-rules/views/coding-rules-custom-rule-creation-view', + 'coding-rules/views/coding-rules-manual-rule-creation-view', # filters 'navigator/filters/base-filters', @@ -70,6 +71,7 @@ requirejs [ CodingRulesBulkChangeDropdownView, CodingRulesFacetsView, CodingRulesCustomRuleCreationView, + CodingRulesManualRuleCreationView, # filters BaseFilters, @@ -274,6 +276,11 @@ requirejs [ language: 'none' + App.createManualRule = -> + App.codingRulesManualRuleCreationView.model = new Backbone.Model() + App.codingRulesManualRuleCreationView.show() + + # Construct layout App.addInitializer -> @layout = new CodingRulesLayout app: @ @@ -317,6 +324,10 @@ requirejs [ @codingRulesCustomRuleCreationView = new CodingRulesCustomRuleCreationView app: @ + # Construct custom rule creation view + App.addInitializer -> + @codingRulesManualRuleCreationView = new CodingRulesManualRuleCreationView app: @ + # Define filters App.addInitializer -> @filters = new BaseFilters.Filters diff --git a/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee b/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee index 636c6a2cf17..772cd484040 100644 --- a/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee +++ b/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee @@ -52,7 +52,8 @@ define [ changeQualityProfile: '.coding-rules-detail-quality-profile-update' createCustomRule: '#coding-rules-custom-rules-create' changeCustomRule: '#coding-rules-detail-custom-rule-change' - deleteCustomRule: '#coding-rules-detail-custom-rule-delete' + changeManualRule: '#coding-rules-detail-manual-rule-change' + deleteCustomRule: '#coding-rules-detail-rule-delete' events: @@ -69,7 +70,8 @@ define [ 'click @ui.changeQualityProfile': 'changeQualityProfile' 'click @ui.createCustomRule': 'createCustomRule' 'click @ui.changeCustomRule': 'changeCustomRule' - 'click @ui.deleteCustomRule': 'deleteCustomRule' + 'click @ui.changeManualRule': 'changeManualRule' + 'click @ui.deleteCustomRule': 'deleteRule' 'click .coding-rules-detail-parameter-details': 'showParamPopup' 'click .coding-rules-subcharacteristic': 'showDebtPopup' @@ -293,7 +295,12 @@ define [ @options.app.codingRulesCustomRuleCreationView.show() - deleteCustomRule: -> + changeManualRule: -> + @options.app.codingRulesManualRuleCreationView.model = @model + @options.app.codingRulesManualRuleCreationView.show() + + + deleteRule: -> confirmDialog title: t 'delete' html: t 'are_you_sure' @@ -313,6 +320,7 @@ define [ contextQualityProfile = @options.app.getQualityProfile() repoKey = @model.get 'repo' isManual = (@options.app.manualRepository().key == repoKey) + isCustom = (@model.get('templateKey') != null) qualityProfilesVisible = not isManual if qualityProfilesVisible @@ -330,6 +338,7 @@ define [ repository: _.find(@options.app.repositories, (repo) -> repo.key == repoKey).name isManual: isManual canWrite: @options.app.canWrite + isEditable: (@options.app.canWrite and (isManual or isCustom)) qualityProfilesVisible: qualityProfilesVisible subcharacteristic: @options.app.getSubcharacteristicName(@model.get 'debtSubChar') createdAt: new Date(@model.get 'createdAt') diff --git a/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-manual-rule-creation-view.coffee b/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-manual-rule-creation-view.coffee new file mode 100644 index 00000000000..4adb0d9afe4 --- /dev/null +++ b/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-manual-rule-creation-view.coffee @@ -0,0 +1,134 @@ +define [ + 'backbone.marionette', + 'templates/coding-rules' +], ( + Marionette, + Templates +) -> + + class CodingRulesManualRuleCreationView extends Marionette.ItemView + className: 'modal' + template: Templates['coding-rules-manual-rule-creation'] + + + ui: + manualRuleCreationKey: '#coding-rules-manual-rule-creation-key' + manualRuleCreationName: '#coding-rules-manual-rule-creation-name' + manualRuleCreationHtmlDescription: '#coding-rules-manual-rule-creation-html-description' + manualRuleCreationSeverity: '#coding-rules-manual-rule-creation-severity' + manualRuleCreationStatus: '#coding-rules-manual-rule-creation-status' + manualRuleCreationParameters: '[name]' + manualRuleCreationCreate: '#coding-rules-manual-rule-creation-create' + manualRuleCreationReactivate: '#coding-rules-manual-rule-creation-reactivate' + modalFoot: '.modal-foot' + + + events: + 'input @ui.manualRuleCreationName': 'generateKey' + 'keydown @ui.manualRuleCreationName': 'generateKey' + 'keyup @ui.manualRuleCreationName': 'generateKey' + + 'input @ui.manualRuleCreationKey': 'flagKey' + 'keydown @ui.manualRuleCreationKey': 'flagKey' + 'keyup @ui.manualRuleCreationKey': 'flagKey' + + 'click #coding-rules-manual-rule-creation-cancel': 'hide' + 'click @ui.manualRuleCreationCreate': 'create' + 'click @ui.manualRuleCreationReactivate': 'reactivate' + + + generateKey: -> + unless @keyModifiedByUser + if @ui.manualRuleCreationKey + generatedKey = @ui.manualRuleCreationName.val().latinize().replace(/[^A-Za-z0-9]/g, '_') + @ui.manualRuleCreationKey.val generatedKey + + flagKey: -> + @keyModifiedByUser = true + # Cannot use @ui.manualRuleCreationReactivate.hide() directly since it was not there at initial render + jQuery(@ui.manualRuleCreationReactivate.selector).hide() + + + create: -> + action = 'create' + if @model and @model.has 'key' + action = 'update' + + postData = + name: @ui.manualRuleCreationName.val() + markdown_description: @ui.manualRuleCreationHtmlDescription.val() + + if @model && @model.has 'key' + postData.key = @model.get 'key' + else + postData.manual_key = @ui.manualRuleCreationKey.val() + postData.prevent_reactivation = true + + @sendRequest(action, postData) + + + reactivate: -> + postData = + name: @existingRule.name + markdown_description: @existingRule.mdDesc + manual_key: @ui.manualRuleCreationKey.val() + prevent_reactivation: false + + @sendRequest('create', postData) + + + sendRequest: (action, postData) -> + @$('.modal-error').hide() + @$('.modal-warning').hide() + + origFooter = @ui.modalFoot.html() + @ui.modalFoot.html '<i class="spinner"></i>' + + jQuery.ajax + type: 'POST' + url: "#{baseUrl}/api/rules/" + action + data: postData + error: () -> + .done (r) => + @options.app.showRule r.rule.key + @hide() + .fail (jqXHR, textStatus, errorThrown) => + if jqXHR.status == 409 + @existingRule = jqXHR.responseJSON.rule + @$('.modal-warning').show() + @ui.modalFoot.html Templates['coding-rules-manual-rule-reactivation'](@) + else + jQuery.ajaxSettings.error(jqXHR, textStatus, errorThrown) + @ui.modalFoot.html origFooter + + + onRender: -> + @$el.dialog + dialogClass: 'no-close', + width: '600px', + draggable: false, + autoOpen: false, + modal: true, + minHeight: 50, + resizable: false, + title: null + + @keyModifiedByUser = false + + format = (state) -> + return state.text unless state.id + "<i class='icon-severity-#{state.id.toLowerCase()}'></i> #{state.text}" + + + show: -> + @render() + @$el.dialog 'open' + + + hide: -> + @$el.dialog 'close' + + + serializeData: -> + _.extend super, + change: @model && @model.has 'key' diff --git a/server/sonar-web/src/main/coffee/coding-rules/views/header-view.coffee b/server/sonar-web/src/main/coffee/coding-rules/views/header-view.coffee index 9e2ddf78b24..b3554347edf 100644 --- a/server/sonar-web/src/main/coffee/coding-rules/views/header-view.coffee +++ b/server/sonar-web/src/main/coffee/coding-rules/views/header-view.coffee @@ -12,7 +12,12 @@ define [ events: 'click #coding-rules-new-search': 'newSearch' + 'click #coding-rules-create-rule': 'createRule' newSearch: -> @options.app.router.emptyQuery() + + + createRule: -> + @options.app.createManualRule() diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-detail.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-detail.hbs index 2d4cb44417f..1762144fc35 100644 --- a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-detail.hbs +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-detail.hbs @@ -51,15 +51,17 @@ <div class="coding-rules-detail-description rule-desc markdown">{{{htmlDesc}}}</div> -{{#if templateKey}} - {{#if canWrite}} +{{#if isEditable}} <div class="coding-rules-detail-description"> <div class="button-group"> - <button id="coding-rules-detail-custom-rule-change">{{t 'edit'}}</button> - <button id="coding-rules-detail-custom-rule-delete" class="button-red">{{t 'delete'}}</button> + {{#if isManual}} + <button id="coding-rules-detail-manual-rule-change">{{t 'edit'}}</button> + {{else}} + <button id="coding-rules-detail-custom-rule-change">{{t 'edit'}}</button> + {{/if}} + <button id="coding-rules-detail-rule-delete" class="button-red">{{t 'delete'}}</button> </div> </div> - {{/if}} {{else}} {{#unless isManual}} <div class="coding-rules-detail-description coding-rules-detail-description-extra"> diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-header.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-header.hbs index 598ded5a8a6..12fbc46ac5c 100644 --- a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-header.hbs +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-header.hbs @@ -2,4 +2,5 @@ <div class="navigator-header-actions button-group"> <button id="coding-rules-new-search">{{t 'coding_rules.new_search'}}</button> + <button id="coding-rules-create-rule">{{t 'coding_rules.create'}}</button> </div> diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-manual-rule-creation.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-manual-rule-creation.hbs new file mode 100644 index 00000000000..f7b027215b6 --- /dev/null +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-manual-rule-creation.hbs @@ -0,0 +1,47 @@ +<form> + <div class="modal-head"> + {{#if change}} + <h2>{{t 'coding_rules.update_manual_rule'}}</h2> + {{else}} + <h2>{{t 'coding_rules.create_manual_rule'}}</h2> + {{/if}} + </div> + + <div class="modal-body"> + <div class="modal-error"></div> + <div class="modal-warning">{{t 'coding_rules.reactivate.help'}}</div> + + <table> + <tr class="property"> + <th><h3>{{t 'name'}} <em class="mandatory">*</em></h3></th> + <td> + <input type="text" name="name" id="coding-rules-manual-rule-creation-name" value="{{name}}"/> + </td> + </tr> + <tr class="property"> + <th><h3>{{t 'key'}}{{#unless change}} <em class="mandatory">*</em>{{/unless}}</h3></th> + <td> + {{#if change}} + {{key}} + {{else}} + <input type="text" name="key" id="coding-rules-manual-rule-creation-key" value="{{internalKey}}"/> + {{/if}} + </td> + </tr> + <tr class="property"> + <th><h3>{{t 'description'}} <em class="mandatory">*</em></h3></th> + <td> + <textarea type="textarea" name="markdown_description" id="coding-rules-manual-rule-creation-html-description" + rows="4" style="width: 100%; margin-bottom: 4px;">{{{mdDesc}}}</textarea> + </td> + </tr> + </table> + </div> + + <div class="modal-foot"> + <button id="coding-rules-manual-rule-creation-create"> + {{#if change}}{{t 'save'}}{{else}}{{t 'create'}}{{/if}} + </button> + <a id="coding-rules-manual-rule-creation-cancel" class="action">{{t 'cancel'}}</a> + </div> +</form> diff --git a/server/sonar-web/src/main/hbs/coding-rules/coding-rules-manual-rule-reactivation.hbs b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-manual-rule-reactivation.hbs new file mode 100644 index 00000000000..2410c7fd95f --- /dev/null +++ b/server/sonar-web/src/main/hbs/coding-rules/coding-rules-manual-rule-reactivation.hbs @@ -0,0 +1,7 @@ +<button id="coding-rules-manual-rule-creation-reactivate"> + {{t 'coding_rules.reactivate'}} +</button> +<button id="coding-rules-manual-rule-creation-create"> + {{#if change}}{{t 'save'}}{{else}}{{t 'create'}}{{/if}} +</button> +<a id="coding-rules-manual-rule-creation-cancel" class="action">{{t 'cancel'}}</a> |