forked from sdavis3/code-coverage-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.html
303 lines (274 loc) · 18.5 KB
/
configuration.html
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="sdk/scripts/VSS.SDK.min.js"></script>
<script type="text/javascript">
// Initialize
VSS.init({
explicitNotifyLoaded: true,
usePlatformStyles: true,
usePlatformScripts: true
});
VSS.require(["TFS/Dashboards/WidgetHelpers", "TFS/Build/RestClient"],
function (WidgetHelpers, TFS_Build_WebApi) {
// TODO: The following line may need VSS.ready() instead. Need to test.
VSS.register("CodeCoverageWidget.Configuration", function () {
WidgetHelpers.IncludeWidgetConfigurationStyles();
var projectId = VSS.getWebContext().project.id;
var $buildDefinitionDropdown = $("#build-definition-dropdown");
var $coverageMeasurementDropdown = $("#coverage-measurement-dropdown");
var $decimalPlacesDropdown = $("#decimal-places-dropdown");
var $checkOptionBuildName = $("#check-option-build-name");
var $checkOptionMeasurementName = $("#check-option-measurement-name");
var $checkOptionDelta = $("#check-option-delta");
return {
load: function (widgetSettings, widgetConfigurationContext) {
// Retrieve configurations settings
var settings = JSON.parse(widgetSettings.customSettings.data);
TFS_Build_WebApi.getClient().getDefinitions(projectId).then(function (query) {
// Populate dropdown with list of build definitions
$.each(query, function(key, value) {
$buildDefinitionDropdown.append($("<option />").val(value.id).text(value.name));
});
// Sort dropdown list of build definitions alphabetically
$('#build-definition-dropdown').html($('#build-definition-dropdown' + ' option').sort(function(a, b) {
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
}));
// If a build definition has been previously selected, set the dropdown value
if (settings && settings.buildDefinition) {
$buildDefinitionDropdown.val(settings.buildDefinition).trigger("chosen:updated");
}
else {
// Set the Please select... item as the default
$('#build-definition-dropdown').prepend($('<option />').val('').text('Please select a build definition:'));
$('#build-definition-dropdown').val('');
$("#build-definition-dropdown option[value='']").attr("disabled", true);
}
// If a coverage measurement has been previously selected, set the dropdown value
if (settings && settings.coverageMeasurement) {
$coverageMeasurementDropdown.val(settings.coverageMeasurement).trigger("chosen:updated");
}
else {
// Set Lines... item as the default regardless of project type
$('#coverage-measurement-dropdown').val('Lines');
}
// If number of decimal places has been previously selected, set the dropdown value
if (settings && settings.decimalPlaces) {
$decimalPlacesDropdown.val(settings.decimalPlaces).trigger("chosen:updated");
}
else {
// Set zero... item as the default
$('#decimal-places-dropdown').val('0');
}
// Use the widget helper and return success as Widget Status
return WidgetHelpers.WidgetStatusHelper.Success();
}, function (error) {
// Use the widget helper and return failure as Widget Status
return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
});
// If show build name has been previously selected, set the checkbox value
if (settings && settings.checkOptionBuildName == true) {
$checkOptionBuildName.prop('checked', true);
}
// Otherwise, mark the box as unchecked
else {
$checkOptionBuildName.prop('checked', false);
}
// If show measurement name has been previously selected, set the checkbox value
if (settings && settings.checkOptionMeasurementName == true) {
$checkOptionMeasurementName.prop('checked', true);
}
// Otherwise, mark the box as unchecked
else {
$checkOptionMeasurementName.prop('checked', false);
}
// If show delta has been previously selected, set the checkbox value
if (settings && settings.checkOptionDelta == true) {
$checkOptionDelta.prop('checked', true);
}
// Otherwise, mark the box as unchecked
else {
$checkOptionDelta.prop('checked', false);
}
// If a build definition change has been made, prepare to persist the new values
$buildDefinitionDropdown.on("change", function () {
// Output diagnostics info to console
console.log('event: buildDefinitionDropdown.change');
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs);
});
// If a coverage measurement change has been made, prepare to persist the new values
$coverageMeasurementDropdown.on("change", function () {
// Output diagnostics info to console
console.log('event: coverageMeasurementDropdown.change');
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs);
});
// If a decimal places shown change has been made, prepare to persist the new values
$decimalPlacesDropdown.on("change", function () {
// Output diagnostics info to console
console.log('event: decimalPlacesDropdown.change');
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs);
});
// If a show build name change has been made, prepare to persist the new values
$checkOptionBuildName.on("change", function () {
// Output diagnostics info to console
console.log('event: checkOptionBuildName.change');
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs);
});
// If a show measurement name change has been made, prepare to persist the new values
$checkOptionMeasurementName.on("change", function () {
// Output diagnostics info to console
console.log('event: checkOptionMeasurementName.change');
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs);
});
// If a show delta change has been made, prepare to persist the new values
$checkOptionDelta.on("change", function () {
// Output diagnostics info to console
console.log('event: checkOptionDelta.change');
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
var eventName = WidgetHelpers.WidgetEvent.ConfigurationChange;
var eventArgs = WidgetHelpers.WidgetEvent.Args(customSettings);
widgetConfigurationContext.notify(eventName, eventArgs);
});
return WidgetHelpers.WidgetStatusHelper.Success();
},
onSave: function() {
// Output diagnostics info to console
console.log('event: onSave');
// Persist the selected definition
var customSettings = {
data: JSON.stringify({
buildDefinition: $buildDefinitionDropdown.val(),
coverageMeasurement: $coverageMeasurementDropdown.val(),
decimalPlaces: $decimalPlacesDropdown.val(),
checkOptionBuildName: $checkOptionBuildName.prop('checked'),
checkOptionMeasurementName: $checkOptionMeasurementName.prop('checked'),
checkOptionDelta: $checkOptionDelta.prop('checked')
})
};
return WidgetHelpers.WidgetConfigurationSave.Valid(customSettings);
}
}
});
VSS.notifyLoadSucceeded();
});
</script>
</head>
<body>
<div class="widget-configuration">
<div class="dropdown">
<label>Build definition</label>
<div class="wrapper">
<select id="build-definition-dropdown">
<!--<option value="Shared Queries/Feedback">Shared Queries/Feedback</option>-->
</select>
</div>
</div>
<div class="dropdown">
<label>Coverage measurement</label>
<div class="wrapper">
<select id="coverage-measurement-dropdown">
<option value="Blocks">Blocks</option>
<option value="Branch">Branch</option>
<option value="Branches">Branches</option>
<option value="Class">Class</option>
<option value="Complexity">Complexity</option>
<option value="Instruction">Instruction</option>
<option value="Line">Line</option>
<option value="Lines">Lines</option>
<option value="Method">Method</option>
</select>
</div>
</div>
<div class="dropdown">
<label>Decimal place to show</label>
<div class="wrapper">
<select id="decimal-places-dropdown">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
</div>
<div class="checkbox">
<fieldset class="checkbox">
<legend>Additional options</legend>
<input type="checkbox" id="check-option-build-name" name="check-option-build-name">
<label for="check-option-build-name">Show the name of the build</label><br/>
<input type="checkbox" id="check-option-measurement-name" name="check-option-measurement-name">
<label for="check-option-measurement-name">Show the name of the coverage measurement</label><br />
<input type="checkbox" id="check-option-delta" name="check-option-delta">
<label for="check-option-delta">Show the delta from previous build's coverage</label><br />
</fieldset>
</div>
</div>
</body>
</html>