diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-05-18 16:29:19 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-05-19 18:20:09 +0200 |
commit | e59e4aa2c06a57566f148f4217d286461231ae58 (patch) | |
tree | ad0918eb06b2474a6c71997b7ff573bbb93e0170 /server/sonar-web/src/main/js/apps/coding-rules/facets | |
parent | 8d82c9cf9ba88c1517604b4063ad0fc2a9a1bb9a (diff) | |
download | sonarqube-e59e4aa2c06a57566f148f4217d286461231ae58.tar.gz sonarqube-e59e4aa2c06a57566f148f4217d286461231ae58.zip |
change web structure: separate components
Diffstat (limited to 'server/sonar-web/src/main/js/apps/coding-rules/facets')
16 files changed, 995 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js new file mode 100644 index 00000000000..6695943968d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/active-severity-facet.js @@ -0,0 +1,65 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + template: Templates['coding-rules-severity-facet'], + severities: ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR'], + + initialize: function (options) { + this.listenTo(options.app.state, 'change:query', this.onQueryChange); + }, + + onQueryChange: function () { + var query = this.options.app.state.get('query'), + isProfileSelected = query.qprofile != null, + isActiveShown = '' + query.activation === 'true'; + if (!isProfileSelected || !isActiveShown) { + this.forbid(); + } + }, + + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + this.onQueryChange(); + }, + + forbid: function () { + BaseFacet.prototype.forbid.apply(this, arguments); + this.$el.prop('title', t('coding_rules.filters.active_severity.inactive')); + }, + + allow: function () { + BaseFacet.prototype.allow.apply(this, arguments); + this.$el.prop('title', null); + }, + + sortValues: function (values) { + var order = this.severities; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js new file mode 100644 index 00000000000..b67e07d205b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/available-since-facet.js @@ -0,0 +1,61 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + template: Templates['coding-rules-available-since-facet'], + + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'change input': 'applyFacet' + }); + }, + + onRender: function () { + this.$el.toggleClass('search-navigator-facet-box-collapsed', !this.model.get('enabled')); + this.$el.attr('data-property', this.model.get('property')); + this.$('input').datepicker({ + dateFormat: 'yy-mm-dd', + changeMonth: true, + changeYear: true + }); + var value = this.options.app.state.get('query').available_since; + if (value) { + this.$('input').val(value); + } + }, + + applyFacet: function() { + var obj = {}, + property = this.model.get('property'); + obj[property] = this.$('input').val(); + this.options.app.state.updateFilter(obj); + }, + + getLabelsSource: function () { + return this.options.app.languages; + } + + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js new file mode 100644 index 00000000000..04da173a760 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/base-facet.js @@ -0,0 +1,30 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + 'components/navigator/facets/base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + className: 'search-navigator-facet-box', + template: Templates['coding-rules-base-facet'] + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js new file mode 100644 index 00000000000..7cd9d884257 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/characteristic-facet.js @@ -0,0 +1,85 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + var $ = jQuery; + + return BaseFacet.extend({ + template: Templates['coding-rules-characteristic-facet'], + + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').has_debt_characteristic; + if (value != null && ('' + value === 'false')) { + this.$('.js-facet').filter('[data-empty-characteristic]').addClass('active'); + } + }, + + toggleFacet: function (e) { + var noneCharacteristic = $(e.currentTarget).is('[data-empty-characteristic]'), + property = this.model.get('property'), + obj = {}; + $(e.currentTarget).toggleClass('active'); + if (noneCharacteristic) { + var checked = $(e.currentTarget).is('.active'); + obj.has_debt_characteristic = checked ? 'false' : null; + obj[property] = null; + } else { + obj.has_debt_characteristic = null; + obj[property] = this.getValue(); + } + this.options.app.state.updateFilter(obj); + }, + + disable: function () { + var property = this.model.get('property'), + obj = {}; + obj.has_debt_characteristic = null; + obj[property] = null; + this.options.app.state.updateFilter(obj); + }, + + getValues: function () { + var values = this.model.getValues(), + characteristics = this.options.app.characteristics; + return values.map(function (value) { + var ch = _.findWhere(characteristics, { key: value.val }); + if (ch != null) { + _.extend(value, ch, { label: ch.name }); + } + return value; + }); + }, + + sortValues: function (values) { + return _.sortBy(values, 'index'); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValues()) + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js new file mode 100644 index 00000000000..da7d1949a18 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-labels-facet.js @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet' +], function (BaseFacet) { + + return BaseFacet.extend({ + + getLabelsSource: function () { + return []; + }, + + getValues: function () { + var that = this, + labels = that.getLabelsSource(); + return this.model.getValues().map(function (item) { + return _.extend(item, { + label: labels[item.val] + }); + }); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js new file mode 100644 index 00000000000..7aad57ad48c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/custom-values-facet.js @@ -0,0 +1,89 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + template: Templates['coding-rules-custom-values-facet'], + + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'change .js-custom-value': 'addCustomValue' + }); + }, + + getUrl: function () { + return baseUrl; + }, + + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + this.prepareSearch(); + }, + + prepareSearch: function () { + this.$('.js-custom-value').select2({ + placeholder: t('search_verb'), + minimumInputLength: 1, + allowClear: false, + formatNoMatches: function () { + return t('select2.noMatches'); + }, + formatSearching: function () { + return t('select2.searching'); + }, + formatInputTooShort: function () { + return tp('select2.tooShort', 1); + }, + width: '100%', + ajax: this.prepareAjaxSearch() + }); + }, + + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term, page) { + return { s: term, p: page }; + }, + results: function (data) { + return { more: data.more, results: data.results }; + } + }; + }, + + addCustomValue: function () { + var property = this.model.get('property'), + customValue = this.$('.js-custom-value').select2('val'), + value = this.getValue(); + if (value.length > 0) { + value += ','; + } + value += customValue; + var obj = {}; + obj[property] = value; + this.options.app.state.updateFilter(obj); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js new file mode 100644 index 00000000000..36f56294967 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/inheritance-facet.js @@ -0,0 +1,88 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet' +], function (BaseFacet) { + + var $ = jQuery; + + return BaseFacet.extend({ + + initialize: function (options) { + this.listenTo(options.app.state, 'change:query', this.onQueryChange); + }, + + onQueryChange: function () { + var query = this.options.app.state.get('query'), + isProfileSelected = query.qprofile != null; + if (isProfileSelected) { + var profile = _.findWhere(this.options.app.qualityProfiles, { key: query.qprofile }); + if (profile != null && profile.parentKey == null) { + this.forbid(); + } + } else { + this.forbid(); + } + }, + + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + this.onQueryChange(); + }, + + forbid: function () { + BaseFacet.prototype.forbid.apply(this, arguments); + this.$el.prop('title', t('coding_rules.filters.inheritance.inactive')); + }, + + allow: function () { + BaseFacet.prototype.allow.apply(this, arguments); + this.$el.prop('title', null); + }, + + getValues: function () { + var values = ['NONE', 'INHERITED', 'OVERRIDES']; + return values.map(function (key) { + return { + label: t('coding_rules.filters.inheritance', key.toLowerCase()), + val: key + }; + }); + }, + + toggleFacet: function (e) { + var obj = {}, + property = this.model.get('property'); + if ($(e.currentTarget).is('.active')) { + obj[property] = null; + } else { + obj[property] = $(e.currentTarget).data('value'); + } + this.options.app.state.updateFilter(obj); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js new file mode 100644 index 00000000000..07542add062 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/key-facet.js @@ -0,0 +1,43 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + template: Templates['coding-rules-key-facet'], + + onRender: function () { + this.$el.toggleClass('hidden', !this.options.app.state.get('query').rule_key); + }, + + disable: function () { + this.options.app.state.updateFilter({ rule_key: null }); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + key: this.options.app.state.get('query').rule_key + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js new file mode 100644 index 00000000000..478c589032c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js @@ -0,0 +1,70 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './custom-values-facet' +], function (CustomValuesFacet) { + + return CustomValuesFacet.extend({ + + getUrl: function () { + return baseUrl + '/api/languages/list'; + }, + + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 10000 }; + }, + results: function (data) { + return { + more: false, + results: data.languages.map(function (lang) { + return { id: lang.key, text: lang.name }; + }) + }; + } + }; + }, + + getLabelsSource: function () { + return this.options.app.languages; + }, + + getValues: function () { + var that = this, + labels = that.getLabelsSource(); + return this.model.getValues().map(function (item) { + return _.extend(item, { + label: labels[item.val] + }); + }); + }, + + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } + + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js new file mode 100644 index 00000000000..b7af11147e4 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/quality-profile-facet.js @@ -0,0 +1,99 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + var $ = jQuery; + + return BaseFacet.extend({ + template: Templates['coding-rules-quality-profile-facet'], + + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'click .js-active': 'setActivation', + 'click .js-inactive': 'unsetActivation' + }); + }, + + getValues: function () { + var that = this, + languagesQuery = this.options.app.state.get('query').languages, + languages = languagesQuery != null ? languagesQuery.split(',') : [], + lang = languages.length === 1 ? languages[0] : null, + values = this.options.app.qualityProfiles + .filter(function (profile) { + return lang != null ? profile.lang === lang : true; + }) + .map(function (profile) { + return { + label: profile.name, + extra: that.options.app.languages[profile.lang], + val: profile.key + }; + }); + return _.sortBy(values, 'label'); + }, + + toggleFacet: function (e) { + var obj = {}, + property = this.model.get('property'); + if ($(e.currentTarget).is('.active')) { + obj.activation = null; + obj[property] = null; + } else { + obj.activation = true; + obj[property] = $(e.currentTarget).data('value'); + } + this.options.app.state.updateFilter(obj); + }, + + setActivation: function (e) { + e.stopPropagation(); + this.options.app.state.updateFilter({ activation: 'true' }); + }, + + unsetActivation: function (e) { + e.stopPropagation(); + this.options.app.state.updateFilter({ activation: 'false' }); + }, + + getToggled: function () { + var activation = this.options.app.state.get('query').activation; + return activation === 'true' || activation === true; + }, + + disable: function () { + var obj = { activation: null }, + property = this.model.get('property'); + obj[property] = null; + this.options.app.state.updateFilter(obj); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues(), + toggled: this.getToggled() + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js new file mode 100644 index 00000000000..03431cd76cd --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/query-facet.js @@ -0,0 +1,56 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + template: Templates['coding-rules-query-facet'], + + events: function () { + return _.extend(BaseFacet.prototype.events.apply(this, arguments), { + 'submit form': 'onFormSubmit' + }); + }, + + onRender: function () { + this.$el.attr('data-property', this.model.get('property')); + var query = this.options.app.state.get('query'), + value = query.q; + if (value != null) { + this.$('input').val(value); + } + }, + + onFormSubmit: function (e) { + e.preventDefault(); + this.applyFacet(); + }, + + applyFacet: function() { + var obj = {}, + property = this.model.get('property'); + obj[property] = this.$('input').val(); + this.options.app.state.updateFilter(obj, { force: true }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js new file mode 100644 index 00000000000..08283dc5b18 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/repository-facet.js @@ -0,0 +1,74 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './custom-values-facet' +], function (CustomValuesFacet) { + + return CustomValuesFacet.extend({ + + getUrl: function () { + return baseUrl + '/api/rules/repositories'; + }, + + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 10000 }; + }, + results: function (data) { + return { + more: false, + results: data.repositories.map(function (repo) { + return { id: repo.key, text: repo.name + ' (' + repo.language + ')' }; + }) + }; + } + }; + }, + + getLabelsSource: function () { + var repos = this.options.app.repositories; + return _.object(_.pluck(repos, 'key'), _.pluck(repos, 'name')); + }, + + getValues: function () { + var that = this, + labels = that.getLabelsSource(); + return this.model.getValues().map(function (value) { + var repo = _.findWhere(that.options.app.repositories, { key: value.val }); + if (repo != null) { + var langName = that.options.app.languages[repo.language]; + _.extend(value, { extra: langName }); + } + return _.extend(value, { label: labels[value.val] }); + }); + }, + + serializeData: function () { + return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), { + values: this.getValues() + }); + } + + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js new file mode 100644 index 00000000000..54f71f86691 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/severity-facet.js @@ -0,0 +1,37 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + return BaseFacet.extend({ + template: Templates['coding-rules-severity-facet'], + severities: ['BLOCKER', 'MINOR', 'CRITICAL', 'INFO', 'MAJOR'], + + sortValues: function (values) { + var order = this.severities; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js new file mode 100644 index 00000000000..96854e47564 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/status-facet.js @@ -0,0 +1,49 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet' +], function (BaseFacet) { + + return BaseFacet.extend({ + statuses: ['READY', 'DEPRECATED', 'BETA'], + + getValues: function () { + var values = this.model.getValues(); + var x = values.map(function (value) { + return _.extend(value, { label: t('rules.status', value.val.toLowerCase()) }); + }); + return x; + }, + + sortValues: function (values) { + var order = this.statuses; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); + }); + }, + + serializeData: function () { + return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { + values: this.sortValues(this.getValues()) + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js new file mode 100644 index 00000000000..9a5b0f21570 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/tag-facet.js @@ -0,0 +1,50 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './custom-values-facet' +], function (CustomValuesFacet) { + + return CustomValuesFacet.extend({ + + getUrl: function () { + return baseUrl + '/api/rules/tags'; + }, + + prepareAjaxSearch: function () { + return { + quietMillis: 300, + url: this.getUrl(), + data: function (term) { + return { q: term, ps: 10000 }; + }, + results: function (data) { + return { + more: false, + results: data.tags.map(function (tag) { + return { id: tag, text: tag }; + }) + }; + } + }; + } + + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js b/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js new file mode 100644 index 00000000000..118913333d2 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/facets/template-facet.js @@ -0,0 +1,52 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +define([ + './base-facet', + '../templates' +], function (BaseFacet) { + + var $ = jQuery; + + return BaseFacet.extend({ + template: Templates['coding-rules-template-facet'], + + onRender: function () { + BaseFacet.prototype.onRender.apply(this, arguments); + var value = this.options.app.state.get('query').is_template; + if (value != null) { + this.$('.js-facet').filter('[data-value="' + value + '"]').addClass('active'); + } + }, + + toggleFacet: function (e) { + $(e.currentTarget).toggleClass('active'); + var property = this.model.get('property'), + obj = {}; + if ($(e.currentTarget).hasClass('active')) { + obj[property] = '' + $(e.currentTarget).data('value'); + } else { + obj[property] = null; + } + this.options.app.state.updateFilter(obj); + } + + }); + +}); |