import ModalForm from '../../../components/common/modal-form';
import Template from '../templates/rule/coding-rules-profile-activation.hbs';
import { csvEscape } from '../../../helpers/csv';
+import { sortProfiles } from '../../quality-profiles/utils';
export default ModalForm.extend({
template: Template,
const availableProfiles = this.getAvailableQualityProfiles(this.options.rule.get('lang'));
const contextProfile = this.options.app.state.get('query').qprofile;
+ // decrease depth by 1, so the top level starts at 0
+ const profilesWithDepth = sortProfiles(availableProfiles).map(profile => ({
+ ...profile,
+ depth: profile.depth - 1
+ }));
+
return {
...ModalForm.prototype.serializeData.apply(this, arguments),
params,
contextProfile,
change: this.model && this.model.has('severity'),
- qualityProfiles: availableProfiles,
+ qualityProfiles: profilesWithDepth,
severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'],
saveEnabled: availableProfiles.length > 0 || (this.model && this.model.get('qProfile')),
isCustomRule: (this.model && this.model.has('templateKey')) || this.options.rule.has('templateKey')
{{else}}
<select id="coding-rules-quality-profile-activation-select">
{{#each qualityProfiles}}
- <option value="{{key}}" {{#eq key ../contextProfile}}selected{{/eq}}>{{name}}</option>
+ <option value="{{key}}" {{#eq key ../contextProfile}}selected{{/eq}}>
+ {{#repeat depth}} {{/repeat}}{{name}}
+ </option>
{{/each}}
</select>
{{/any}}
</select>
</div>
{{#if isCustomRule}}
- <div class="modal-field">
- <p class="note">{{t 'coding_rules.custom_rule.activation_notice'}}</p>
+ <div class="modal-field">
+ <p class="note">{{t 'coding_rules.custom_rule.activation_notice'}}</p>
+ </div>
{{else}}
{{#each params}}
<div class="modal-field">
{{/if}}
</div>
- <div class="modal-foot">
- <button id="coding-rules-quality-profile-activation-activate"
- {{#unless saveEnabled}}disabled="disabled"{{/unless}}>
- {{#if change}}{{t 'save'}}{{else}}{{t 'coding_rules.activate'}}{{/if}}
- </button>
- <a id="coding-rules-quality-profile-activation-cancel" class="js-modal-close">{{t 'cancel'}}</a>
- </div>
+ <div class="modal-foot">
+ <button id="coding-rules-quality-profile-activation-activate"
+ {{#unless saveEnabled}}disabled="disabled"{{/unless}}>
+ {{#if change}}{{t 'save'}}{{else}}{{t 'coding_rules.activate'}}{{/if}}
+ </button>
+ <a id="coding-rules-quality-profile-activation-cancel" class="js-modal-close">{{t 'cancel'}}</a>
+ </div>
</form>
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+// @flow
import sortBy from 'lodash/sortBy';
import moment from 'moment';
-export function sortProfiles (profiles) {
+type Profiles = Array<{
+ key: string,
+ name: string,
+ parentKey?: string
+}>;
+
+export function sortProfiles (profiles: Profiles) {
const result = [];
const sorted = sortBy(profiles, 'name');
return result;
}
-export function createFakeProfile (overrides) {
+export function createFakeProfile (overrides: {}) {
return {
key: 'key',
name: 'name',
};
}
-export function isStagnant (profile) {
+export function isStagnant (profile: { userUpdatedAt: string }) {
return moment().diff(moment(profile.userUpdatedAt), 'years') >= 1;
}