diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-06-17 11:55:16 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-06-17 12:04:03 +0200 |
commit | 506ce5d2ea9d52754b21bd1727be028006be3142 (patch) | |
tree | 02516d75929268b8138ca685a3c4715948a2dcaf | |
parent | 610cca8350f54ce80f7925579c6ee672784c52cc (diff) | |
download | sonarqube-506ce5d2ea9d52754b21bd1727be028006be3142.tar.gz sonarqube-506ce5d2ea9d52754b21bd1727be028006be3142.zip |
SONAR-5355 SONAR-5360 Allow reactivation of existing custom rule
5 files changed, 59 insertions, 4 deletions
diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 54adbb06fad..9cdd515603d 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1716,12 +1716,15 @@ coding_rules.order=Order coding_rules.ordered_by=Ordered By coding_rules.original=Original: coding_rules.overrides="{0}" overrides "{1}" +coding_rules.overwrite=Overwrite coding_rules.page=Coding Rules coding_rules.parameters=Parameters coding_rules.parameters.default_value=Default Value: coding_rules.permalink=Permalink coding_rules.quality_profiles=Quality Profiles coding_rules.quality_profile=Quality Profile +coding_rules.reactivate=Reactivate +coding_rules.reactivate.help=A rule with the same key has been previously deleted. Please reactivate the existing rule or modify the key to create a new rule. coding_rules.repository=Repository: coding_rules.revert_to_parent_definition=Revert to Parent Definition coding_rules.rule_template=Rule Template diff --git a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-custom-rule-creation-view.coffee b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-custom-rule-creation-view.coffee index 04be236be47..26321af5804 100644 --- a/sonar-server/src/main/coffee/coding-rules/views/coding-rules-custom-rule-creation-view.coffee +++ b/sonar-server/src/main/coffee/coding-rules/views/coding-rules-custom-rule-creation-view.coffee @@ -19,6 +19,8 @@ define [ customRuleCreationStatus: '#coding-rules-custom-rule-creation-status' customRuleCreationParameters: '[name]' customRuleCreationCreate: '#coding-rules-custom-rule-creation-create' + customRuleCreationReactivate: '#coding-rules-custom-rule-creation-reactivate' + modalFoot: '.modal-foot' events: @@ -32,6 +34,7 @@ define [ 'click #coding-rules-custom-rule-creation-cancel': 'hide' 'click @ui.customRuleCreationCreate': 'create' + 'click @ui.customRuleCreationReactivate': 'reactivate' generateKey: -> @@ -42,6 +45,8 @@ define [ flagKey: -> @keyModifiedByUser = true + # Cannot use @ui.customRuleCreationReactivate.hide() directly since it was not there at initial render + jQuery(@ui.customRuleCreationReactivate.selector).hide() create: -> @@ -60,24 +65,54 @@ define [ else postData.template_key = @templateRule.get 'key' postData.custom_key = @ui.customRuleCreationKey.val() + postData.prevent_reactivation = true params = @ui.customRuleCreationParameters.map(-> key: jQuery(@).prop('name'), value: jQuery(@).val() || jQuery(@).prop('placeholder') || '').get() postData.params = (params.map (param) -> param.key + '=' + param.value).join(';') + @sendRequest(action, postData) - origFooter = @$('.modal-foot').html() - @$('.modal-foot').html '<i class="spinner"></i>' + + reactivate: -> + postData = + name: @existingRule.name + html_description: @existingRule.htmlDesc + severity: @existingRule.severity + status: @existingRule.status + template_key: @existingRule.templateKey + custom_key: @ui.customRuleCreationKey.val() + prevent_reactivation: false + + params = @existingRule.params + postData.params = (params.map (param) -> param.key + '=' + param.defaultValue).join(';') + + @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 => - @$('.modal-foot').html origFooter + .fail (jqXHR, textStatus, errorThrown) => + if jqXHR.status == 409 + @existingRule = jqXHR.responseJSON.rule + @$('.modal-warning').show() + @ui.modalFoot.html Templates['coding-rules-custom-rule-reactivation'](@) + else + jQuery.ajaxSettings.error(jqXHR, textStatus, errorThrown) + @ui.modalFoot.html origFooter onRender: -> diff --git a/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-creation.hbs b/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-creation.hbs index 57a9182ff70..ebc66880c45 100644 --- a/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-creation.hbs +++ b/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-creation.hbs @@ -9,6 +9,7 @@ <div class="modal-body"> <div class="modal-error"></div> + <div class="modal-warning">{{t 'coding_rules.reactivate.help'}}</div> <table> <tr class="property"> diff --git a/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-reactivation.hbs b/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-reactivation.hbs new file mode 100644 index 00000000000..2de07a6a814 --- /dev/null +++ b/sonar-server/src/main/hbs/coding-rules/coding-rules-custom-rule-reactivation.hbs @@ -0,0 +1,7 @@ +<button id="coding-rules-custom-rule-creation-reactivate"> + {{t 'coding_rules.reactivate'}} +</button> +<button id="coding-rules-custom-rule-creation-create"> + {{#if change}}{{t 'save'}}{{else}}{{t 'create'}}{{/if}} +</button> +<a id="coding-rules-custom-rule-creation-cancel" class="action">{{t 'cancel'}}</a> diff --git a/sonar-server/src/main/less/style.less b/sonar-server/src/main/less/style.less index 33c298fe662..317c2c1b291 100644 --- a/sonar-server/src/main/less/style.less +++ b/sonar-server/src/main/less/style.less @@ -2545,6 +2545,15 @@ ul.modal-head-metadata li { display: none; } +.modal-warning { + border: solid 1px #FFD324; + background-color: #FFF6BF; + color: #514721; + margin: 0 0 4px; + padding: 4px; + display: none; +} + textarea.width100 { width: 100%; -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ |