2
2
< html xmlns ="http://www.w3.org/1999/xhtml ">
3
3
< head >
4
4
< script src ="../lib/VSS.SDK.min.js "> </ script >
5
+ < script src ="../library.js "> </ script >
5
6
< link rel ="stylesheet " href ="../styles.css " />
6
7
7
8
< script type ="text/javascript ">
13
14
VSS . require ( [ "VSS/Service" , "TFS/Dashboards/WidgetHelpers" , "VSS/Context" , "TFS/VersionControl/GitRestClient" ] ,
14
15
function ( Service , WidgetHelpers , context , GitWebApi ) {
15
16
VSS . register ( "GHAzDoWidget.Chart.Configuration" , function ( ) {
16
- var $repoDropdown = $ ( "#repo-dropdown" ) ;
17
-
18
- async function getRepos ( ) {
19
- try {
20
- const webContext = VSS . getWebContext ( ) ;
21
- const project = webContext . project ;
22
-
23
- // todo: load the available repos in this project
24
- const gitClient = Service . getClient ( GitWebApi . GitHttpClient ) ;
25
- repos = await gitClient . getRepositories ( project . name ) ;
26
- console . log ( `Found these repos: ${ JSON . stringify ( repos ) } ` ) ;
27
- return repos ;
17
+ const $repoDropdown = $ ( "#repo-dropdown" ) ;
18
+ const $chartTypeDropdown = $ ( "#chart-type" ) ;
19
+ const $alertTypeDropdown = $ ( "#alert-type" ) ;
20
+
21
+ function reloadWidget ( widgetConfigurationContext ) {
22
+ const customSettings = getSettings ( ) ;
23
+ var eventName = WidgetHelpers . WidgetEvent . ConfigurationChange ;
24
+ var eventArgs = WidgetHelpers . WidgetEvent . Args ( customSettings ) ;
25
+ widgetConfigurationContext . notify ( eventName , eventArgs ) ;
26
+ }
27
+
28
+ function getSettings ( ) {
29
+ if ( repos ) {
30
+ // find the repo with this name
31
+ const repo = repos . find ( r => r . name === $repoDropdown . val ( ) ) ;
32
+
33
+ if ( repo ) {
34
+ var customSettings = {
35
+ data : JSON . stringify ( {
36
+ repo : $repoDropdown . val ( ) ,
37
+ repoId : repo . id ,
38
+ chartType : $chartTypeDropdown . val ( ) ,
39
+ alertType : $alertTypeDropdown . val ( )
40
+ } )
41
+ } ;
42
+ return customSettings ;
43
+ }
28
44
}
29
- catch ( err ) {
30
- console . log ( `Error loading the available repos: ${ err } ` ) ;
31
- return [ ] ;
45
+
46
+ return { } ;
47
+ }
48
+
49
+ function reloadChartOptions ( ) {
50
+ const chartType = $chartTypeDropdown . val ( ) ;
51
+ if ( chartType === "1" ) {
52
+ // trend line
53
+ $ ( "#alertTypePanel" ) . hide ( ) ;
54
+ }
55
+ else if ( chartType === "2" ) {
56
+ // pie chart
57
+ $ ( "#alertTypePanel" ) . show ( ) ;
32
58
}
33
59
}
34
60
37
63
var settings = JSON . parse ( widgetSettings . customSettings . data ) ;
38
64
console . log ( `Loading the Chart.2x2 settings with ${ JSON . stringify ( settings ) } ` )
39
65
40
- const repos = await getRepos ( ) ;
66
+ const repos = await getRepos ( VSS , Service , GitWebApi ) ;
41
67
// add all repos as selection options to the dropdown
42
68
if ( repos ) {
43
69
// add a top option to select no repo
54
80
$repoDropdown . val ( settings . repo ) ;
55
81
}
56
82
57
- $repoDropdown . on ( "change" , function ( ) {
58
- let repo ;
59
- if ( repos ) {
60
- // find the repo with this name
61
- repo = repos . find ( r => r . name === $repoDropdown . val ( ) ) ;
62
- }
83
+ if ( settings && settings . chartType ) {
84
+ // select the chartType that was saved in the settings
85
+ $chartTypeDropdown . val ( settings . chartType ) ;
86
+ }
63
87
64
- var customSettings = {
65
- data : JSON . stringify ( {
66
- repo : $repoDropdown . val ( ) ,
67
- repoId : repo . id
68
- } )
69
- } ;
70
- var eventName = WidgetHelpers . WidgetEvent . ConfigurationChange ;
71
- var eventArgs = WidgetHelpers . WidgetEvent . Args ( customSettings ) ;
72
- widgetConfigurationContext . notify ( eventName , eventArgs ) ;
88
+ if ( settings && settings . alertType ) {
89
+ // select the alertType that was saved in the settings
90
+ $alertTypeDropdown . val ( settings . alertType ) ;
91
+ }
92
+
93
+ // register a change event handler for the dropdowns
94
+ $repoDropdown . on ( "change" , function ( ) {
95
+ reloadWidget ( widgetConfigurationContext )
96
+ } ) ;
97
+
98
+ $chartTypeDropdown . on ( "change" , function ( ) {
99
+ reloadWidget ( widgetConfigurationContext )
100
+ reloadChartOptions ( ) ;
101
+ } ) ;
102
+
103
+ $alertTypeDropdown . on ( "change" , function ( ) {
104
+ reloadWidget ( widgetConfigurationContext )
73
105
} ) ;
74
106
75
107
return WidgetHelpers . WidgetStatusHelper . Success ( ) ;
76
108
} ,
77
109
onSave : async function ( ) {
78
- const repos = await getRepos ( ) ;
79
- let repo ;
80
- if ( repos ) {
81
- // find the repo with this name
82
- repo = repos . find ( r => r . name === $repoDropdown . val ( ) ) ;
83
- }
84
- var customSettings = {
85
- data : JSON . stringify ( {
86
- repo : $repoDropdown . val ( ) ,
87
- repoId : repo . id
88
- } )
89
- } ;
110
+ const customSettings = getSettings ( ) ;
111
+
90
112
console . log ( `Saving the Chart.2x2 settings with ${ JSON . stringify ( customSettings ) } ` )
91
113
return WidgetHelpers . WidgetConfigurationSave . Valid ( customSettings ) ;
92
114
}
98
120
</ head >
99
121
< body >
100
122
< div class ="container ">
101
- < fieldset >
102
- < label class ="label "> Repository: </ label >
103
- < select id ="repo-dropdown " style ="margin-top:10px ">
104
- <!-- todo: dynamically load the available repos in this project-->
105
- </ select >
106
- </ fieldset >
123
+ < table class ="ghazdo-table ">
124
+ < tr >
125
+ < td >
126
+ < label class ="label "> Repository: </ label >
127
+ </ td >
128
+ < td >
129
+ < select id ="repo-dropdown " class ="dropdown " style ="margin-top:10px "> </ select >
130
+ </ td >
131
+ </ tr >
132
+ < tr >
133
+ < td >
134
+ < label class ="label "> Chart type: </ label >
135
+ </ td >
136
+ < td >
137
+ < select id ="chart-type " class ="dropdown ">
138
+ < option value ="1 "> Trend line</ option >
139
+ < option value ="2 "> Pie chart</ option >
140
+ </ select >
141
+ </ td >
142
+ </ tr >
143
+ < tr id ="alertTypePanel ">
144
+ < td >
145
+ < label class ="label "> Alert type: </ label >
146
+ </ td >
147
+ < td >
148
+ < select id ="alert-type " class ="dropdown ">
149
+ < option value ="1 "> Dependency</ option >
150
+ < option value ="2 "> Secret</ option >
151
+ < option value ="3 "> Code</ option >
152
+ </ select >
153
+ </ td >
154
+ </ table >
107
155
</ div >
108
156
</ body >
109
157
</ html >
0 commit comments