1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
define(['handlebars'], function (Handlebars) {
/*
* Shortcut for templates retrieving
*/
window.getTemplate = function(templateSelector) {
return Handlebars.compile(jQuery(templateSelector).html() || '');
};
var defaultActions = ['comment', 'assign', 'assign_to_me', 'plan', 'set_severity'];
Handlebars.registerHelper('capitalize', function(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
});
Handlebars.registerHelper('severityIcon', function(severity) {
return new Handlebars.SafeString(
'<i class="icon-severity-' + severity.toLowerCase() + '"></i>'
);
});
Handlebars.registerHelper('statusIcon', function(status) {
return new Handlebars.SafeString(
'<i class="icon-status-' + status.toLowerCase() + '"></i>'
);
});
Handlebars.registerHelper('resolutionIcon', function(resolution) {
return new Handlebars.SafeString(
'<i class="icon-resolution-' + resolution.toLowerCase() + '"></i>'
);
});
Handlebars.registerHelper('eq', function(v1, v2, options) {
return v1 == v2 ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('notEq', function(v1, v2, options) {
return v1 != v2 ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('all', function() {
var args = Array.prototype.slice.call(arguments, 0, -1),
options = arguments[arguments.length - 1],
all = args.reduce(function(prev, current) {
return prev && current;
}, true);
return all ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('any', function() {
var args = Array.prototype.slice.call(arguments, 0, -1),
options = arguments[arguments.length - 1],
all = args.reduce(function(prev, current) {
return prev || current;
}, true);
return all ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('inArray', function(array, element, options) {
if (array.indexOf(element) !== -1) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('ifNotEmpty', function() {
var args = Array.prototype.slice.call(arguments, 0, -1),
options = arguments[arguments.length - 1],
notEmpty = args.reduce(function(prev, current) {
return prev || (current && current.length > 0);
}, false);
return notEmpty ? options.fn(this) : '';
});
Handlebars.registerHelper('dashboardUrl', function(componentKey, componentQualifier) {
var url = '/dashboard/index/' + decodeURIComponent(componentKey);
if (componentQualifier === 'FIL' || componentQualifier === 'CLA') {
url += '?metric=sqale_index';
}
return url;
});
Handlebars.registerHelper('translate', function(key, prefix) {
var args = Array.prototype.slice.call(arguments, 0, -1),
tokens = args.reduce(function(prev, current) {
return prev.concat(current.split('.'));
}, []),
start = window.SS.phrases;
return tokens.reduce(function(prev, current) {
return current ? prev[current] : prev;
}, start);
});
Handlebars.registerHelper('pluginActions', function(actions, options) {
var pluginActions = _.difference(actions, defaultActions);
return pluginActions.reduce(function(prev, current) {
return prev + options.fn(current);
}, '');
});
Handlebars.registerHelper('ifHasExtraTransitions', function(transitions, options) {
if (transitions && transitions.length > 1) {
return options.fn(this);
} else {
return '';
}
});
Handlebars.registerHelper('ifHasExtraActions', function(actions, options) {
var actionsLeft = _.difference(actions, _.without(defaultActions, 'set_severity'));
if (actionsLeft.length > 0) {
return options.fn(this);
} else {
return '';
}
});
Handlebars.registerHelper('withFirst', function(list, options) {
if (list && list.length > 0) {
return options.fn(list[0]);
} else {
return '';
}
});
Handlebars.registerHelper('withoutFirst', function(list, options) {
if (list && list.length > 1) {
return list.slice(1).reduce(function(prev, current) {
return prev + options.fn(current);
}, '');
} else {
return '';
}
});
Handlebars.registerHelper('sources', function(source, scm, options) {
var sources = _.map(source, function(code, line) {
return {
lineNumber: line,
code: code,
scm: (scm && scm[line]) ? { author: scm[line][0], date: scm[line][1] } : undefined
}
});
return sources.reduce(function(prev, current, index) {
return prev + options.fn(_.extend({ first: index === 0 }, current));
}, '');
});
Handlebars.registerHelper('operators', function(metricType, options) {
var ops = ['LT', 'GT', 'EQ', 'NE'];
return ops.reduce(function(prev, current) {
return prev + options.fn(current);
}, '');
});
});
|