aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/coffee/coding-rules
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-07-18 18:06:02 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-07-18 18:06:10 +0200
commit18a85015feb7a27bee89bcfda4421b92f0a9b8c7 (patch)
tree02eb02d65b07e9c7bfced1070edcdcf2b835bf70 /server/sonar-web/src/main/coffee/coding-rules
parente93420742f6d1361b5043eb56b15cbdbf7d00690 (diff)
downloadsonarqube-18a85015feb7a27bee89bcfda4421b92f0a9b8c7.tar.gz
sonarqube-18a85015feb7a27bee89bcfda4421b92f0a9b8c7.zip
SONAR-3373 Integrate management of manual rules in Rules space
Diffstat (limited to 'server/sonar-web/src/main/coffee/coding-rules')
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/app.coffee11
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-detail-view.coffee15
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-manual-rule-creation-view.coffee134
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/views/header-view.coffee5
4 files changed, 162 insertions, 3 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()