@@ -40,34 +40,33 @@ jQuery(document).ready(function() {
40
40
}
41
41
// /Stop ## Global AJAX Sender function ##################################
42
42
43
- var checkEiBackend = false ;
44
43
// Check EI Backend Server Status ########################################
45
- function checkEiBackendServer ( ) {
44
+ var backendStatus = false ;
45
+ function checkBackendStatus ( ) {
46
46
var EIConnBtn = document . getElementById ( "btnEIConnection" ) ;
47
47
if ( EIConnBtn == null ) {
48
48
return ;
49
49
}
50
50
var red = "#ff0000" ;
51
51
var green = "#00ff00" ;
52
52
$ . ajax ( {
53
- url : "/subscriptions/testDummySubscription " ,
54
- contentType : 'application/json; charset=utf-8' ,
53
+ url : "/auth/checkStatus " ,
54
+ contentType : 'application/json; charset=utf-8' ,
55
55
type : 'GET' ,
56
- error : function ( XMLHttpRequest , textStatus , errorThrown ) {
57
- doIfUserLoggedOut ( ) ;
56
+ error : function ( XMLHttpRequest ) {
58
57
if ( XMLHttpRequest . status == 401 ) {
58
+ doIfUserLoggedOut ( ) ;
59
59
EIConnBtn . style . background = green ;
60
- checkEiBackend = true ;
60
+ backendStatus = true ;
61
61
} else {
62
62
EIConnBtn . style . background = red ;
63
- checkEiBackend = false ;
63
+ backendStatus = false ;
64
64
}
65
65
} ,
66
- success : function ( data , textStatus , xhr ) {
66
+ success : function ( ) {
67
67
EIConnBtn . style . background = green ;
68
- checkEiBackend = true ;
69
- } ,
70
- complete : function ( XMLHttpRequest , textStatus ) { }
68
+ backendStatus = true ;
69
+ }
71
70
} ) ;
72
71
}
73
72
@@ -76,25 +75,26 @@ jQuery(document).ready(function() {
76
75
if ( currentUser != "" ) {
77
76
$ ( "#userName" ) . text ( currentUser ) ;
78
77
$ ( "#logoutBlock" ) . show ( ) ;
78
+ $ ( ".show_if_authorized" ) . show ( ) ;
79
79
}
80
80
}
81
-
82
81
function doIfUserLoggedOut ( ) {
83
82
localStorage . removeItem ( "currentUser" ) ;
84
83
$ ( "#userName" ) . text ( "Guest" ) ;
85
84
$ ( "#loginBlock" ) . show ( ) ;
86
85
$ ( "#logoutBlock" ) . hide ( ) ;
86
+ $ ( ".show_if_authorized" ) . hide ( ) ;
87
87
}
88
88
89
89
// Check if EI Backend Server is online every X seconds
90
- window . setInterval ( function ( ) { checkEiBackendServer ( ) ; } , 15000 ) ;
90
+ window . setInterval ( function ( ) { checkBackendStatus ( ) ; } , 15000 ) ;
91
91
92
92
// Check if EI Backend Server is online when Status Connection button is pressed.
93
93
$ ( '.container' ) . on ( 'click' , 'button.btnEIConnectionStatus' , function ( event ) {
94
94
event . stopPropagation ( ) ;
95
95
event . preventDefault ( ) ;
96
96
97
- checkEiBackendServer ( ) ;
97
+ checkBackendStatus ( ) ;
98
98
} ) ;
99
99
// END OF EI Backend Server check #########################################
100
100
@@ -251,16 +251,33 @@ jQuery(document).ready(function() {
251
251
252
252
253
253
254
- } ; // var SubscriptionViewModel = function(){
254
+ } ;
255
+
256
+ // Start to check is backend secured
257
+ var isSecured = false ;
258
+ $ . ajax ( {
259
+ url : "/auth" ,
260
+ contentType : 'application/json; charset=utf-8' ,
261
+ type : 'GET' ,
262
+ error : function ( ) { } ,
263
+ success : function ( data ) {
264
+ isSecured = JSON . parse ( ko . toJSON ( data ) ) . security ;
265
+ if ( isSecured == true ) {
266
+ doIfUserLoggedIn ( ) ;
267
+ }
268
+ } ,
269
+ complete : function ( ) {
270
+ checkBackendStatus ( ) ;
271
+ }
272
+ } ) ;
273
+ // Finish to check is backend secured
255
274
256
- checkEiBackendServer ( ) ;
257
- doIfUserLoggedIn ( ) ;
258
275
// Cleanup old ViewModel and Knockout Obeservables from previous page load.
259
276
var observableObject = $ ( '#ViewModelDOMObject' ) [ 0 ] ;
260
277
ko . cleanNode ( observableObject ) ;
261
278
// Apply bindings
262
279
var vm = new SubscriptionViewModel ( ) ;
263
- ko . applyBindings ( vm , document . getElementById ( "ViewModelDOMObject" ) ) ;
280
+ ko . applyBindings ( vm , observableObject ) ;
264
281
265
282
266
283
// /Stop ## Knockout #####################################################
@@ -270,17 +287,19 @@ jQuery(document).ready(function() {
270
287
271
288
272
289
// /Start ## Datatables ##################################################
290
+ var currentUser = localStorage . getItem ( "currentUser" ) ;
273
291
table = $ ( '#table' ) . DataTable ( {
274
-
275
292
"processing" : true , //Feature control the processing indicator.
276
293
"serverSide" : false , //Feature control DataTables' server-side processing mode.
277
294
"fixedHeader" : true ,
278
295
"order" : [ ] , //Initial no order.
296
+ "searching" : true ,
279
297
// Load data for the table's content from an Ajax source
280
298
"ajax" : {
281
299
"url" : frontendServiceUrl + "/subscriptions" ,
282
300
"type" : "GET" ,
283
- "dataSrc" : "" // Flat structure from EI backend REST API
301
+ "dataSrc" : "" , // Flat structure from EI backend REST API
302
+ "error" : function ( ) { }
284
303
} ,
285
304
//Set column definition initialisation properties.
286
305
"columnDefs" : [
@@ -294,19 +313,26 @@ jQuery(document).ready(function() {
294
313
}
295
314
} ,
296
315
{
297
- "targets" : [ 1 ] ,
316
+ "targets" : [ 1 ] ,
317
+ "orderable" : true ,
318
+ "title" : "UserName" ,
319
+ "data" : "userName" ,
320
+ "defaultContent" : ""
321
+ } ,
322
+ {
323
+ "targets" : [ 2 ] ,
298
324
"orderable" : true ,
299
325
"title" : "SubscriptionName" ,
300
326
"data" : "subscriptionName"
301
327
} ,
302
328
{
303
- "targets" : [ 2 ] ,
329
+ "targets" : [ 3 ] ,
304
330
"orderable" : true ,
305
331
"title" : "Type" ,
306
332
"data" : "aggregationtype"
307
333
} ,
308
334
{
309
- "targets" : [ 3 ] ,
335
+ "targets" : [ 4 ] ,
310
336
"orderable" : true ,
311
337
"title" : "Date" ,
312
338
"data" : "created" ,
@@ -315,32 +341,47 @@ jQuery(document).ready(function() {
315
341
}
316
342
} ,
317
343
{
318
- "targets" : [ 4 ] ,
344
+ "targets" : [ 5 ] ,
319
345
"orderable" : true ,
320
346
"title" : "NotificationType" ,
321
347
"data" : "notificationType"
322
348
} ,
323
349
{
324
- "targets" : [ 5 ] ,
350
+ "targets" : [ 6 ] ,
325
351
"orderable" : true ,
326
352
"title" : "NotificationMeta" ,
327
353
"data" : "notificationMeta"
328
354
} ,
329
355
{
330
- "targets" : [ 6 ] ,
356
+ "targets" : [ 7 ] ,
331
357
"orderable" : true ,
332
358
"title" : "Repeat" ,
333
359
"data" : "repeat"
334
360
} ,
335
361
{
336
- "targets" : [ 7 ] , //last column
362
+ "targets" : [ 8 ] , //last column
337
363
"orderable" : false ,
338
364
"title" : "Action" ,
339
365
"data" : null ,
340
366
"width" :"150px" ,
341
- "defaultContent" : '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button><button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>'
342
- } ,
367
+ "render" : function ( data , type , row , meta ) {
368
+ if ( isSecured == true && row . userName == currentUser && row . userName != null ) {
369
+ return '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
370
+ + '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>' ;
371
+ } else if ( isSecured == false ) {
372
+ return '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
373
+ + '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>' ;
374
+ } else {
375
+ return '' ;
376
+ }
377
+ }
378
+ }
343
379
] ,
380
+ "initComplete" : function ( ) {
381
+ if ( isSecured == false ) {
382
+ table . column ( 1 ) . visible ( false ) ;
383
+ }
384
+ }
344
385
} ) ;
345
386
// /Stop ## Datatables ##################################################
346
387
0 commit comments