@@ -17,7 +17,7 @@ Template.tenantForm.onCreated(() => {
17
17
} ) ;
18
18
19
19
Template . tenantForm . onDestroyed ( ( ) => {
20
- // Unset sessions
20
+ // Unset spinner
21
21
Session . set ( 'tenantUpdateOngoing' , undefined ) ;
22
22
} ) ;
23
23
@@ -31,17 +31,18 @@ Template.tenantForm.events({
31
31
// Save new Tenant operation began, inform spinner
32
32
Session . set ( 'tenantUpdateOngoing' , true ) ;
33
33
34
+ // Initiate payload
34
35
const tenant = { } ;
35
36
let tenantUsers = [ ] ;
36
37
let notifyUserList = [ ] ;
37
38
39
+ // Get name and description from modal fields
38
40
tenant . name = $ ( '#add-tenant-name' ) . val ( ) ;
39
41
tenant . description = $ ( '#add-tenant-description' ) . val ( ) ;
40
42
41
43
// Get possible users in tenant
42
44
if ( Session . get ( 'tenantUsers' ) ) {
43
45
tenantUsers = Session . get ( 'tenantUsers' ) ;
44
- console . log ( 'tenant users=' , tenantUsers ) ;
45
46
// convert user objects to a list for POST operation
46
47
tenant . users = tenantUsers . map ( ( userdata ) => {
47
48
const usersRow = {
@@ -52,7 +53,7 @@ Template.tenantForm.events({
52
53
} ;
53
54
return usersRow ;
54
55
} ) ;
55
- // gather list of notified users' email addresses
56
+ // gather list of notified users' email addresses for notification sending
56
57
notifyUserList = tenantUsers . filter ( ( userdata ) => {
57
58
if ( userdata . notification === 'checked' ) {
58
59
return true ;
@@ -68,8 +69,6 @@ Template.tenantForm.events({
68
69
Meteor . call ( 'addTenant' , tenant , ( error , result ) => {
69
70
if ( result ) {
70
71
if ( result . status === 201 ) {
71
- // In successful case we can empty the input fields
72
-
73
72
// Empty the tenant user list
74
73
tenantUsers . splice ( 0 , tenantUsers . length ) ;
75
74
// Remove users from session
@@ -80,18 +79,18 @@ Template.tenantForm.events({
80
79
// Empty tenant description field
81
80
$ ( '#add-tenant-description' ) . val ( '' ) ;
82
81
83
- // Operation finished, inform spinner
84
- Session . set ( 'tenantUpdateOngoing' , false ) ;
85
-
86
82
// New tenant successfully added on manager side, empty local list
87
83
tenantList = [ ] ;
88
84
// Save to sessionStorage to be used while adding users to tenant
89
85
Session . set ( 'tenantList' , tenantList ) ;
90
86
87
+ // Operation successfully finished, inform spinner
88
+ Session . set ( 'tenantUpdateOngoing' , false ) ;
89
+
91
90
// Close modal
92
91
Modal . hide ( 'tenantForm' ) ;
93
92
94
- // Notification to users of tenant
93
+ // Send notification to the users of the tenant
95
94
// eslint-disable-next-line max-len
96
95
Meteor . call ( 'informTenantUser' , notifyUserList , 'tenantAddition' , tenant . name , ( nofityChangeError ) => {
97
96
if ( nofityChangeError ) {
@@ -106,15 +105,15 @@ Template.tenantForm.events({
106
105
// Inform user about success
107
106
sAlert . success ( message ) ;
108
107
} else {
109
- // Operation finished, inform spinner
108
+ // Operation finished, failure, inform spinner
110
109
Session . set ( 'tenantUpdateOngoing' , false ) ;
111
110
// Tenant addition failure on manager side, save new tenant object to local array
112
111
const errorMessage = `Tenant manager error! Returns code (${ result . status } ).` ;
113
112
sAlert . error ( errorMessage , { timeout : 'none' } ) ;
114
113
}
115
114
}
116
115
if ( error ) {
117
- // Operation finished, inform spinner
116
+ // Operation finished, failure, inform spinner
118
117
Session . set ( 'tenantUpdateOngoing' , false ) ;
119
118
// Tenant addition failure on manager side, save new tenant object to local array
120
119
const errorMessage = `Tenant operation failed! (${ error } ).` ;
@@ -128,6 +127,7 @@ Template.tenantForm.events({
128
127
// get values of original tenant
129
128
const originalTenant = this . tenantToModify ;
130
129
130
+ // Name and description must be given in order to be able to send modify
131
131
if ( $ ( '#add-tenant-name' ) . val ( ) === '' ) {
132
132
sAlert . error ( 'Tenant must have a name!' , { timeout : 'none' } ) ;
133
133
} else if ( $ ( '#add-tenant-description' ) . val ( ) === '' ) {
@@ -153,7 +153,7 @@ Template.tenantForm.events({
153
153
if ( originalTenant . name !== modifiedTenant . name ) {
154
154
// Fill in tenant id
155
155
modifyTenantPayload . id = originalTenant . id ;
156
- // Fill in replace for name
156
+ // Fill in replace for name operation
157
157
const changedDescription = {
158
158
op : 'replace' ,
159
159
value : $ ( '#add-tenant-name' ) . val ( ) ,
@@ -166,7 +166,7 @@ Template.tenantForm.events({
166
166
if ( originalTenant . description !== modifiedTenant . description ) {
167
167
// Fill in tenant id
168
168
modifyTenantPayload . id = originalTenant . id ;
169
- // Fill in replace for description
169
+ // Fill in replace for description operation
170
170
const changedDescription = {
171
171
op : 'replace' ,
172
172
value : $ ( '#add-tenant-description' ) . val ( ) ,
@@ -198,6 +198,7 @@ Template.tenantForm.events({
198
198
modifiedTenant . users = Session . get ( 'tenantUsers' ) ;
199
199
}
200
200
201
+ // Initiate payload
201
202
const usersNeedChecking = [ ] ;
202
203
const notifyChangedUsers = [ ] ;
203
204
const notifyRemovedUsers = [ ] ;
@@ -217,11 +218,11 @@ Template.tenantForm.events({
217
218
return false ;
218
219
} ) ;
219
220
220
- // If not found in modified user list, the user is removed
221
+ // If not found in modified user list, the user is to be removed
221
222
if ( sameUserInModified . length === 0 ) {
222
223
modifyTenantPayload . id = originalTenant . id ;
223
224
let path = '/users/' ;
224
- // indicate user with original user data index
225
+ // identify user with original user data index
225
226
path = path . concat ( index ) ;
226
227
const removedUser = {
227
228
op : 'remove' ,
@@ -248,6 +249,7 @@ Template.tenantForm.events({
248
249
origUser . provider !== sameUserInModified [ 0 ] . provider ) {
249
250
modifyTenantPayload . id = originalTenant . id ;
250
251
252
+ // endpoint for modification
251
253
let path = '/users/' ;
252
254
// indicate user with original user data index
253
255
path = path . concat ( index ) ;
@@ -280,23 +282,23 @@ Template.tenantForm.events({
280
282
// Add user to to-be-checked list
281
283
usersNeedChecking . push ( checkUser ) ;
282
284
283
- // If notification is indicated, add to notify list
285
+ // If notification is indicated, add user to notify list
284
286
if ( sameUserInModified [ 0 ] . notification ) {
285
287
// Add user to notification about modification list
286
288
notifyChangedUsers . push ( sameUserInModified [ 0 ] ) ;
287
289
}
288
290
289
- // User data is changed, remove from modified list
291
+ // User data is changed, remove user from modified list
290
292
modifiedTenant . users . splice ( modifiedUserIndex , 1 ) ;
291
293
} else {
292
- // User data not changed, remove from modified list only
294
+ // User data not changed, remove user from modified list only
293
295
modifiedTenant . users . splice ( modifiedUserIndex , 1 ) ;
294
296
}
295
297
296
298
return changeList ;
297
299
} , [ ] ) ;
298
300
299
- // Include removed users to request
301
+ // Include removed users to request payload
300
302
if ( userChanges . length > 0 ) {
301
303
modifyTenantPayload . id = originalTenant . id ;
302
304
modifyTenantPayload . body = modifyTenantPayload . body . concat ( userChanges ) ;
@@ -309,7 +311,7 @@ Template.tenantForm.events({
309
311
notifyChangedUsers . push ( user ) ;
310
312
}
311
313
312
- // collect roles
314
+ // collect roles and convert them for tenant manager
313
315
const tenantRoles = [ ] ;
314
316
if ( user . provider ) {
315
317
tenantRoles . push ( 'data-provider' ) ;
@@ -334,13 +336,13 @@ Template.tenantForm.events({
334
336
return addedUser ;
335
337
} ) ;
336
338
337
- // Include added users to request
339
+ // Include added users to request payload
338
340
if ( newUsers . length > 0 ) {
339
341
modifyTenantPayload . id = originalTenant . id ;
340
342
modifyTenantPayload . body = modifyTenantPayload . body . concat ( newUsers ) ;
341
343
}
342
344
343
- // Check if modified users exist on server side
345
+ // Prepare checking for modified users existing on server side
344
346
const userCheckData = { } ;
345
347
if ( usersNeedChecking . length > 0 ) {
346
348
userCheckData . id = originalTenant . id ;
@@ -376,8 +378,8 @@ Template.tenantForm.events({
376
378
} ) ;
377
379
}
378
380
381
+ // if there are removed users, send notifications
379
382
if ( notifyRemovedUsers . length > 0 ) {
380
- // if there are removed users, send notifications
381
383
// eslint-disable-next-line max-len
382
384
Meteor . call ( 'informTenantUser' , notifyRemovedUsers , 'userRemoval' , modifiedTenant . name , ( notifyRemoveError ) => {
383
385
if ( notifyRemoveError ) {
0 commit comments