|
17 | 17 | const $repoDropdown = $("#repo-dropdown");
|
18 | 18 | const $chartTypeDropdown = $("#chart-type");
|
19 | 19 | const $alertTypeDropdown = $("#alert-type");
|
20 |
| - const repos = await getRepos(VSS, Service, GitWebApi); |
21 | 20 |
|
22 | 21 | function reloadWidget(widgetConfigurationContext) {
|
23 | 22 | const customSettings = getSettings();
|
|
27 | 26 | }
|
28 | 27 |
|
29 | 28 | function getSettings() {
|
30 |
| - if (repos) { |
31 |
| - // find the repo with this name |
32 |
| - const repo = repos.find(r => r.name === $repoDropdown.val()); |
33 |
| - |
34 |
| - if (repo) { |
35 |
| - var customSettings = { |
36 |
| - data: JSON.stringify({ |
37 |
| - repo: $repoDropdown.val(), |
38 |
| - repoId: repo.id, |
39 |
| - chartType: $chartTypeDropdown.val(), |
40 |
| - alertType: $alertTypeDropdown.val() |
41 |
| - }) |
42 |
| - }; |
43 |
| - return customSettings; |
44 |
| - } |
45 |
| - } |
46 | 29 |
|
47 |
| - return {}; |
| 30 | + var customSettings = { |
| 31 | + data: JSON.stringify({ |
| 32 | + repo: getSelectedRepoNameFromDropdown($repoDropdown), |
| 33 | + repoId: getSelectedRepoIdFromDropdown($repoDropdown), |
| 34 | + chartType: $chartTypeDropdown.val(), |
| 35 | + alertType: $alertTypeDropdown.val() |
| 36 | + }) |
| 37 | + }; |
| 38 | + return customSettings; |
48 | 39 | }
|
49 | 40 |
|
50 | 41 | function reloadChartOptions() {
|
51 | 42 | const chartType = $chartTypeDropdown.val();
|
| 43 | + console.log(`Inside reloadChartOptions with chartType [${chartType}]`); |
52 | 44 | if (chartType === "1") {
|
53 | 45 | // trend line
|
54 | 46 | $("#alertTypePanel").hide();
|
|
57 | 49 | // pie chart
|
58 | 50 | $("#alertTypePanel").show();
|
59 | 51 | }
|
| 52 | + else if (chartType === "3") { |
| 53 | + // pie chart |
| 54 | + $("#alertTypePanel").show(); |
| 55 | + } |
60 | 56 | }
|
61 | 57 |
|
62 | 58 | return {
|
63 | 59 | load: async function (widgetSettings, widgetConfigurationContext) {
|
64 | 60 | var settings = logWidgetSettings(widgetSettings, VSS, "Chart.2x2");
|
65 |
| - |
66 |
| - // add all repos as selection options to the dropdown |
| 61 | + const repos = await getRepos(VSS, Service, GitWebApi); |
67 | 62 | if (repos) {
|
68 |
| - // add a top option to select no repo |
69 |
| - $repoDropdown.append(`<option value="">Select a repository</option>`); |
70 |
| - // sort the repo alphabetically |
71 |
| - repos.sort((a, b) => a.name.localeCompare(b.name)); |
72 |
| - repos.forEach(r => { |
73 |
| - $repoDropdown.append(`<option value=${r.name}>${r.name}</option>`); |
74 |
| - }); |
| 63 | + fillSelectRepoDropdown($repoDropdown, repos); |
75 | 64 | }
|
76 | 65 |
|
77 |
| - if (settings && settings.repo) { |
| 66 | + if (settings && settings.repoId) { |
78 | 67 | // select the repo that was saved in the settings
|
79 |
| - $repoDropdown.val(settings.repo); |
80 |
| - } |
| 68 | + $repoDropdown.val(settings.repoId); |
| 69 | + } |
81 | 70 |
|
82 |
| - if (settings && settings.chartType) { |
| 71 | + if (settings && settings.chartType) { |
83 | 72 | // select the chartType that was saved in the settings
|
84 | 73 | $chartTypeDropdown.val(settings.chartType);
|
85 |
| - } |
| 74 | + } |
86 | 75 |
|
87 | 76 | if (settings && settings.alertType) {
|
88 | 77 | // select the alertType that was saved in the settings
|
89 | 78 | $alertTypeDropdown.val(settings.alertType);
|
90 | 79 | }
|
91 | 80 |
|
92 |
| - // register a change event handler for the dropdowns |
| 81 | + // register a change event handler for the dropdowns |
93 | 82 | $repoDropdown.on("change", function () {
|
94 | 83 | reloadWidget(widgetConfigurationContext)
|
95 | 84 | });
|
|
99 | 88 | reloadChartOptions();
|
100 | 89 | });
|
101 | 90 |
|
| 91 | + // call the chartTypeDrowdown change handler to show/hide the alertType dropdown |
| 92 | + reloadChartOptions(); |
| 93 | + |
102 | 94 | $alertTypeDropdown.on("change", function () {
|
103 | 95 | reloadWidget(widgetConfigurationContext)
|
104 | 96 | });
|
|
107 | 99 | },
|
108 | 100 | onSave: async function() {
|
109 | 101 | const customSettings = getSettings();
|
| 102 | + let repoId = getSelectedRepoIdFromDropdown($repoDropdown); |
| 103 | + if (repoId == 0 || repoId == 1) { // 0 = select a repo, 1 = all repos |
| 104 | + // do not save |
| 105 | + console.log(`Not saving the settings because repoId is [${repoId}]`); |
| 106 | + return WidgetHelpers.WidgetConfigurationSave.Invalid(); |
| 107 | + } |
110 | 108 |
|
111 | 109 | console.log(`Saving the Chart.2x2 settings with ${JSON.stringify(customSettings)}`)
|
112 | 110 | return WidgetHelpers.WidgetConfigurationSave.Valid(customSettings);
|
|
0 commit comments