@@ -2,19 +2,47 @@ var router = new Navigo(null, true, '#');
2
2
var frontendServiceUrl = $ ( '#frontendServiceUrl' ) . text ( ) ;
3
3
var frontendServiceBackEndPath = "/backend" ;
4
4
var timerInterval ;
5
+ var ldapEnabled = true ;
6
+
7
+ // Start ## getters and setters
8
+
9
+ function isLdapEnabled ( ) {
10
+ return Boolean ( ldapEnabled ) ;
11
+ }
12
+
13
+ function setLdapEnabled ( value ) {
14
+ ldapEnabled = Boolean ( value ) ;
15
+ }
16
+
17
+ function getCurrentUser ( ) {
18
+ return sessionStorage . getItem ( "currentUser" ) ;
19
+ }
20
+
21
+ function setCurrentUser ( user ) {
22
+ sessionStorage . removeItem ( "currentUser" ) ;
23
+ sessionStorage . setItem ( "currentUser" , user ) ;
24
+ }
25
+
26
+ // End ## getters and setters
27
+
28
+ function stringContainsSubstring ( string , substring ) {
29
+ var isSubstring = string . indexOf ( substring ) !== - 1 ;
30
+ return isSubstring ;
31
+ }
5
32
6
33
function addBackendParameter ( url ) {
34
+ var parameterKey = "backendname" ;
35
+
7
36
if ( ! sessionStorage . selectedActive ) {
8
37
return url ;
9
38
}
10
- var delimiter = "" ;
11
- var parameterKey = "backendname" ;
12
39
13
- if ( url . includes ( "?" ) ) {
40
+ var delimiter = "?" ;
41
+ if ( stringContainsSubstring ( url , delimiter ) ) {
42
+ // url has delimeter ?, then delimeter should be &
14
43
delimiter = "&" ;
15
- } else {
16
- delimiter = "?" ;
17
44
}
45
+
18
46
url = url + delimiter + parameterKey + "=" + sessionStorage . selectedActive ;
19
47
return url ;
20
48
}
@@ -32,7 +60,7 @@ AjaxHttpSender.prototype.sendAjax = function (contextPath, type, data, callback,
32
60
if ( ! dataType ) {
33
61
dataType = "json" ;
34
62
}
35
- url = addBackendParameter ( frontendServiceUrl + contextPath )
63
+ url = addBackendParameter ( frontendServiceUrl + contextPath ) ;
36
64
$ . ajax ( {
37
65
url : url ,
38
66
type : type ,
@@ -61,9 +89,10 @@ AjaxHttpSender.prototype.sendAjax = function (contextPath, type, data, callback,
61
89
}
62
90
}
63
91
} ) ;
64
- }
92
+ } ;
65
93
// /Stop ## Global AJAX Sender function ##################################
66
94
95
+ // Start ## Common functions ##
67
96
function formatUrl ( host , port , useHttps , contextPath ) {
68
97
var protocol = "http" ;
69
98
if ( useHttps ) {
@@ -87,6 +116,21 @@ function formatUrl(host, port, useHttps, contextPath) {
87
116
return protocol + "://" + host + port + contextPath ;
88
117
}
89
118
119
+ function isString ( value ) {
120
+ var isString = typeof value === 'string' || value instanceof String ;
121
+ return isString ;
122
+ }
123
+
124
+ function isStringDefined ( value ) {
125
+ var isDefined = false ;
126
+ if ( isString ( value ) ) {
127
+ isDefined = value . length != 0 ;
128
+ }
129
+ return isDefined ;
130
+ }
131
+
132
+ // /Stop ## Common functions ##################################
133
+
90
134
// Start ## Routing ##
91
135
var routes = { } ;
92
136
routes [ "subscriptions" ] = function ( ) {
@@ -164,20 +208,19 @@ function updateBackEndInstanceList() {
164
208
} ) ;
165
209
}
166
210
167
- function singleInstanceModel ( name , host , port , contextPath , https , active ) {
168
- this . name = ko . observable ( name ) ,
169
- this . host = ko . observable ( host ) ,
170
- this . port = ko . observable ( port ) ,
171
- this . contextPath = ko . observable ( contextPath ) ,
172
- this . https = ko . observable ( https ) ,
173
- this . active = ko . observable ( active ) ,
174
- this . information = name . toUpperCase ( ) + " - " + host + " " + port + "/" + contextPath ;
211
+ function singleInstanceModel ( name , host , port , contextPath , https , active , defaultBackend ) {
212
+ this . name = ko . observable ( name ) ;
213
+ this . host = ko . observable ( host ) ;
214
+ this . port = ko . observable ( port ) ;
215
+ this . contextPath = ko . observable ( contextPath ) ;
216
+ this . https = ko . observable ( https ) ;
217
+ this . active = ko . observable ( active ) ;
218
+ this . defaultBackend = ko . observable ( defaultBackend ) ;
219
+ this . information = name . toUpperCase ( ) + " - " + host + " " + port + "/" + contextPath ;
175
220
}
176
221
177
- function viewModel ( backendInstanceData ) {
178
- var self = this ;
179
- self . instances = ko . observableArray ( ) ;
180
- var jsonBackendInstanceData = JSON . parse ( ko . toJSON ( backendInstanceData ) ) ;
222
+ function getInstanceModels ( jsonBackendInstanceData ) {
223
+ instanceModels = [ ] ;
181
224
182
225
for ( var i = 0 ; i < jsonBackendInstanceData . length ; i ++ ) {
183
226
var instanceData = jsonBackendInstanceData [ i ] ;
@@ -187,9 +230,10 @@ function viewModel(backendInstanceData) {
187
230
var port = instanceData . port ;
188
231
var https = instanceData . https ;
189
232
var contextPath = instanceData . contextPath ;
233
+ var defaultBackend = instanceData . defaultBackend ;
190
234
191
235
var thisInstanceShouldBeSelectedAsActive =
192
- instanceData . defaultBackend == true && ! sessionStorage . selectedActive ||
236
+ defaultBackend == true && ! sessionStorage . selectedActive ||
193
237
sessionStorage . selectedActive && sessionStorage . selectedActive == name ;
194
238
195
239
if ( thisInstanceShouldBeSelectedAsActive ) {
@@ -198,27 +242,38 @@ function viewModel(backendInstanceData) {
198
242
}
199
243
200
244
sessionStorage . setItem ( name , formatUrl ( host , port , https , contextPath ) ) ;
201
- var singleInstance = new singleInstanceModel ( name , host , port , contextPath , https , isActive ) ;
202
- self . instances . push ( singleInstance ) ;
245
+ var singleInstance = new singleInstanceModel ( name , host , port , contextPath , https , isActive , defaultBackend ) ;
246
+ instanceModels . push ( singleInstance ) ;
203
247
}
248
+ return instanceModels ;
249
+ }
250
+
251
+ function viewModel ( backendInstanceData ) {
252
+ var self = this ;
204
253
254
+ var jsonBackendInstanceData = JSON . parse ( ko . toJSON ( backendInstanceData ) ) ;
255
+ var instanceModels = getInstanceModels ( jsonBackendInstanceData ) ;
205
256
self . selectedActive = ko . observable ( sessionStorage . selectedActive ) ;
206
257
258
+ self . instances = ko . observableArray ( ) ;
259
+ instanceModels . forEach ( function ( instanceModel ) {
260
+ self . instances . push ( instanceModel ) ;
261
+ } ) ;
262
+
207
263
self . onChange = function ( ) {
208
264
if ( typeof self . selectedActive ( ) !== "undefined" ) {
209
265
sessionStorage . selectedActive = self . selectedActive ( ) ;
210
266
location . reload ( ) ;
211
267
} else {
212
268
$ . jGrowl ( "Please choose backend instance" , { sticky : false , theme : 'Error' } ) ;
213
269
}
214
- }
270
+ } ;
215
271
}
216
272
// End ## Load Back end list ##
217
273
218
274
// Start ## Login and Security ##
219
275
function doIfUserLoggedIn ( user ) {
220
- sessionStorage . removeItem ( "currentUser" ) ;
221
- sessionStorage . setItem ( "currentUser" , user ) ;
276
+ setCurrentUser ( user ) ;
222
277
$ ( "#userItem" ) . show ( ) ;
223
278
$ ( "#userItem" ) . addClass ( "user-login" ) ;
224
279
$ ( "#ldapUserName" ) . text ( user ) ;
@@ -228,7 +283,7 @@ function doIfUserLoggedIn(user) {
228
283
}
229
284
230
285
function doIfUserLoggedOut ( ) {
231
- sessionStorage . removeItem ( "currentUser ") ;
286
+ setCurrentUser ( " ") ;
232
287
$ ( "#userItem" ) . show ( ) ;
233
288
$ ( "#userItem" ) . removeClass ( "user-login" ) ;
234
289
$ ( "#ldapUserName" ) . text ( "Guest" ) ;
@@ -246,8 +301,10 @@ function doIfSecurityOff() {
246
301
function checkBackendSecured ( ) {
247
302
var callback = {
248
303
success : function ( responseData , textStatus ) {
249
- var ldapEnabled = JSON . parse ( ko . toJSON ( responseData ) ) . security ;
250
- if ( ldapEnabled == true ) {
304
+ var response = JSON . parse ( ko . toJSON ( responseData ) ) ;
305
+ var ldapStatus = response . security ;
306
+ setLdapEnabled ( ldapStatus ) ;
307
+ if ( isLdapEnabled ( ) ) {
251
308
checkLoggedInUser ( ) ;
252
309
} else {
253
310
doIfSecurityOff ( ) ;
@@ -277,9 +334,6 @@ function checkLoggedInUser() {
277
334
ajaxHttpSender . sendAjax ( contextPath , "GET" , null , callback ) ;
278
335
}
279
336
280
- function getCurrentUserInSession ( ) {
281
- return sessionStorage . getItem ( "currentUser" ) ;
282
- }
283
337
// End ## Login and Security ##
284
338
285
339
// Start ## Status Indicator ##
@@ -293,7 +347,7 @@ var statusType = {
293
347
var statusText = {
294
348
backend_down : "<strong>Back end is down!</strong> Wait for it go up or switch to another back end before continuing!" ,
295
349
test_rules_disabled : "<strong>Test Rule service is disabled!</strong> To enable it set the backend property [testaggregated.enabled] as [true]"
296
- }
350
+ } ;
297
351
298
352
function addStatusIndicator ( statusType , statusText ) {
299
353
var statusIndicator = $ ( ".content" ) [ 0 ] . previousElementSibling ;
0 commit comments