Skip to content

Commit d7791f5

Browse files
committed
Revised comments
1 parent e9440c8 commit d7791f5

File tree

2 files changed

+63
-78
lines changed

2 files changed

+63
-78
lines changed

apinf_packages/tenant/client/add/add.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Template.tenantForm.onCreated(() => {
1717
});
1818

1919
Template.tenantForm.onDestroyed(() => {
20-
// Unset sessions
20+
// Unset spinner
2121
Session.set('tenantUpdateOngoing', undefined);
2222
});
2323

@@ -31,17 +31,18 @@ Template.tenantForm.events({
3131
// Save new Tenant operation began, inform spinner
3232
Session.set('tenantUpdateOngoing', true);
3333

34+
// Initiate payload
3435
const tenant = {};
3536
let tenantUsers = [];
3637
let notifyUserList = [];
3738

39+
// Get name and description from modal fields
3840
tenant.name = $('#add-tenant-name').val();
3941
tenant.description = $('#add-tenant-description').val();
4042

4143
// Get possible users in tenant
4244
if (Session.get('tenantUsers')) {
4345
tenantUsers = Session.get('tenantUsers');
44-
console.log('tenant users=', tenantUsers);
4546
// convert user objects to a list for POST operation
4647
tenant.users = tenantUsers.map((userdata) => {
4748
const usersRow = {
@@ -52,7 +53,7 @@ Template.tenantForm.events({
5253
};
5354
return usersRow;
5455
});
55-
// gather list of notified users' email addresses
56+
// gather list of notified users' email addresses for notification sending
5657
notifyUserList = tenantUsers.filter((userdata) => {
5758
if (userdata.notification === 'checked') {
5859
return true;
@@ -68,8 +69,6 @@ Template.tenantForm.events({
6869
Meteor.call('addTenant', tenant, (error, result) => {
6970
if (result) {
7071
if (result.status === 201) {
71-
// In successful case we can empty the input fields
72-
7372
// Empty the tenant user list
7473
tenantUsers.splice(0, tenantUsers.length);
7574
// Remove users from session
@@ -80,18 +79,18 @@ Template.tenantForm.events({
8079
// Empty tenant description field
8180
$('#add-tenant-description').val('');
8281

83-
// Operation finished, inform spinner
84-
Session.set('tenantUpdateOngoing', false);
85-
8682
// New tenant successfully added on manager side, empty local list
8783
tenantList = [];
8884
// Save to sessionStorage to be used while adding users to tenant
8985
Session.set('tenantList', tenantList);
9086

87+
// Operation successfully finished, inform spinner
88+
Session.set('tenantUpdateOngoing', false);
89+
9190
// Close modal
9291
Modal.hide('tenantForm');
9392

94-
// Notification to users of tenant
93+
// Send notification to the users of the tenant
9594
// eslint-disable-next-line max-len
9695
Meteor.call('informTenantUser', notifyUserList, 'tenantAddition', tenant.name, (nofityChangeError) => {
9796
if (nofityChangeError) {
@@ -106,15 +105,15 @@ Template.tenantForm.events({
106105
// Inform user about success
107106
sAlert.success(message);
108107
} else {
109-
// Operation finished, inform spinner
108+
// Operation finished, failure, inform spinner
110109
Session.set('tenantUpdateOngoing', false);
111110
// Tenant addition failure on manager side, save new tenant object to local array
112111
const errorMessage = `Tenant manager error! Returns code (${result.status}).`;
113112
sAlert.error(errorMessage, { timeout: 'none' });
114113
}
115114
}
116115
if (error) {
117-
// Operation finished, inform spinner
116+
// Operation finished, failure, inform spinner
118117
Session.set('tenantUpdateOngoing', false);
119118
// Tenant addition failure on manager side, save new tenant object to local array
120119
const errorMessage = `Tenant operation failed! (${error}).`;
@@ -128,6 +127,7 @@ Template.tenantForm.events({
128127
// get values of original tenant
129128
const originalTenant = this.tenantToModify;
130129

130+
// Name and description must be given in order to be able to send modify
131131
if ($('#add-tenant-name').val() === '') {
132132
sAlert.error('Tenant must have a name!', { timeout: 'none' });
133133
} else if ($('#add-tenant-description').val() === '') {
@@ -153,7 +153,7 @@ Template.tenantForm.events({
153153
if (originalTenant.name !== modifiedTenant.name) {
154154
// Fill in tenant id
155155
modifyTenantPayload.id = originalTenant.id;
156-
// Fill in replace for name
156+
// Fill in replace for name operation
157157
const changedDescription = {
158158
op: 'replace',
159159
value: $('#add-tenant-name').val(),
@@ -166,7 +166,7 @@ Template.tenantForm.events({
166166
if (originalTenant.description !== modifiedTenant.description) {
167167
// Fill in tenant id
168168
modifyTenantPayload.id = originalTenant.id;
169-
// Fill in replace for description
169+
// Fill in replace for description operation
170170
const changedDescription = {
171171
op: 'replace',
172172
value: $('#add-tenant-description').val(),
@@ -198,6 +198,7 @@ Template.tenantForm.events({
198198
modifiedTenant.users = Session.get('tenantUsers');
199199
}
200200

201+
// Initiate payload
201202
const usersNeedChecking = [];
202203
const notifyChangedUsers = [];
203204
const notifyRemovedUsers = [];
@@ -217,11 +218,11 @@ Template.tenantForm.events({
217218
return false;
218219
});
219220

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
221222
if (sameUserInModified.length === 0) {
222223
modifyTenantPayload.id = originalTenant.id;
223224
let path = '/users/';
224-
// indicate user with original user data index
225+
// identify user with original user data index
225226
path = path.concat(index);
226227
const removedUser = {
227228
op: 'remove',
@@ -248,6 +249,7 @@ Template.tenantForm.events({
248249
origUser.provider !== sameUserInModified[0].provider) {
249250
modifyTenantPayload.id = originalTenant.id;
250251

252+
// endpoint for modification
251253
let path = '/users/';
252254
// indicate user with original user data index
253255
path = path.concat(index);
@@ -280,23 +282,23 @@ Template.tenantForm.events({
280282
// Add user to to-be-checked list
281283
usersNeedChecking.push(checkUser);
282284

283-
// If notification is indicated, add to notify list
285+
// If notification is indicated, add user to notify list
284286
if (sameUserInModified[0].notification) {
285287
// Add user to notification about modification list
286288
notifyChangedUsers.push(sameUserInModified[0]);
287289
}
288290

289-
// User data is changed, remove from modified list
291+
// User data is changed, remove user from modified list
290292
modifiedTenant.users.splice(modifiedUserIndex, 1);
291293
} else {
292-
// User data not changed, remove from modified list only
294+
// User data not changed, remove user from modified list only
293295
modifiedTenant.users.splice(modifiedUserIndex, 1);
294296
}
295297

296298
return changeList;
297299
}, []);
298300

299-
// Include removed users to request
301+
// Include removed users to request payload
300302
if (userChanges.length > 0) {
301303
modifyTenantPayload.id = originalTenant.id;
302304
modifyTenantPayload.body = modifyTenantPayload.body.concat(userChanges);
@@ -309,7 +311,7 @@ Template.tenantForm.events({
309311
notifyChangedUsers.push(user);
310312
}
311313

312-
// collect roles
314+
// collect roles and convert them for tenant manager
313315
const tenantRoles = [];
314316
if (user.provider) {
315317
tenantRoles.push('data-provider');
@@ -334,13 +336,13 @@ Template.tenantForm.events({
334336
return addedUser;
335337
});
336338

337-
// Include added users to request
339+
// Include added users to request payload
338340
if (newUsers.length > 0) {
339341
modifyTenantPayload.id = originalTenant.id;
340342
modifyTenantPayload.body = modifyTenantPayload.body.concat(newUsers);
341343
}
342344

343-
// Check if modified users exist on server side
345+
// Prepare checking for modified users existing on server side
344346
const userCheckData = {};
345347
if (usersNeedChecking.length > 0) {
346348
userCheckData.id = originalTenant.id;
@@ -376,8 +378,8 @@ Template.tenantForm.events({
376378
});
377379
}
378380

381+
// if there are removed users, send notifications
379382
if (notifyRemovedUsers.length > 0) {
380-
// if there are removed users, send notifications
381383
// eslint-disable-next-line max-len
382384
Meteor.call('informTenantUser', notifyRemovedUsers, 'userRemoval', modifiedTenant.name, (notifyRemoveError) => {
383385
if (notifyRemoveError) {

0 commit comments

Comments
 (0)