@masterteam/users-groups 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,1221 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { inject, Injectable, computed, signal, Component, input, effect, viewChild, linkedSignal } from '@angular/core';
|
|
4
|
+
import { Breadcrumb } from '@masterteam/components/breadcrumb';
|
|
5
|
+
import { CrudStateBase, REQUEST_CONTEXT, handleApiRequest, UserSearchFieldConfig, ValidatorConfig, UploadFileFieldConfig, TextareaFieldConfig } from '@masterteam/components';
|
|
6
|
+
import { Action, Selector, State, Store, select } from '@ngxs/store';
|
|
7
|
+
import { HttpClient, HttpContext } from '@angular/common/http';
|
|
8
|
+
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
|
|
9
|
+
import { TranslocoService, TranslocoDirective, TranslocoPipe } from '@jsverse/transloco';
|
|
10
|
+
import { Page } from '@masterteam/components/page';
|
|
11
|
+
import { Button } from '@masterteam/components/button';
|
|
12
|
+
import { Table } from '@masterteam/components/table';
|
|
13
|
+
import * as i1 from 'primeng/skeleton';
|
|
14
|
+
import { SkeletonModule } from 'primeng/skeleton';
|
|
15
|
+
import { Avatar } from '@masterteam/components/avatar';
|
|
16
|
+
import { ModalService } from '@masterteam/components/modal';
|
|
17
|
+
import * as i2 from '@angular/forms';
|
|
18
|
+
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
|
19
|
+
import { DynamicForm } from '@masterteam/forms/dynamic-form';
|
|
20
|
+
import { ModalRef, DialogService } from '@masterteam/components/dialog';
|
|
21
|
+
import { Tabs } from '@masterteam/components/tabs';
|
|
22
|
+
import { finalize } from 'rxjs';
|
|
23
|
+
|
|
24
|
+
class GetUsers {
|
|
25
|
+
static type = '[UsersGroups] Get Users';
|
|
26
|
+
}
|
|
27
|
+
class GetUser {
|
|
28
|
+
userName;
|
|
29
|
+
static type = '[UsersGroups] Get One';
|
|
30
|
+
constructor(userName) {
|
|
31
|
+
this.userName = userName;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class CreateUser {
|
|
35
|
+
payload;
|
|
36
|
+
static type = '[UsersGroups] Create User';
|
|
37
|
+
constructor(payload) {
|
|
38
|
+
this.payload = payload;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class AddUserToGroup {
|
|
42
|
+
payload;
|
|
43
|
+
static type = '[UsersGroups] Add User To Group';
|
|
44
|
+
constructor(payload) {
|
|
45
|
+
this.payload = payload;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class UpdateUser {
|
|
49
|
+
userId;
|
|
50
|
+
changes;
|
|
51
|
+
static type = '[UsersGroups] Update User';
|
|
52
|
+
constructor(userId, changes) {
|
|
53
|
+
this.userId = userId;
|
|
54
|
+
this.changes = changes;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class DeleteUser {
|
|
58
|
+
userName;
|
|
59
|
+
static type = '[UsersGroups] Delete User';
|
|
60
|
+
constructor(userName) {
|
|
61
|
+
this.userName = userName;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class DeleteUserFromGroup {
|
|
65
|
+
payload;
|
|
66
|
+
static type = '[UsersGroups] Delete User From Group';
|
|
67
|
+
constructor(payload) {
|
|
68
|
+
this.payload = payload;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class GetGroups {
|
|
72
|
+
static type = '[UsersGroups] Get Groups';
|
|
73
|
+
}
|
|
74
|
+
class ClearSelectedGroup {
|
|
75
|
+
static type = '[UsersGroups] Clear Selected Group';
|
|
76
|
+
}
|
|
77
|
+
class GetGroup {
|
|
78
|
+
groupId;
|
|
79
|
+
static type = '[UsersGroups] Get One Group';
|
|
80
|
+
constructor(groupId) {
|
|
81
|
+
this.groupId = groupId;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class CreateGroup {
|
|
85
|
+
payload;
|
|
86
|
+
static type = '[UsersGroups] Create Group';
|
|
87
|
+
constructor(payload) {
|
|
88
|
+
this.payload = payload;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class UpdateGroup {
|
|
92
|
+
groupId;
|
|
93
|
+
changes;
|
|
94
|
+
static type = '[UsersGroups] Update Group';
|
|
95
|
+
constructor(groupId, changes) {
|
|
96
|
+
this.groupId = groupId;
|
|
97
|
+
this.changes = changes;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
class DeleteGroup {
|
|
101
|
+
groupId;
|
|
102
|
+
static type = '[UsersGroups] Delete Group';
|
|
103
|
+
constructor(groupId) {
|
|
104
|
+
this.groupId = groupId;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var UsersGroupsActionKey;
|
|
109
|
+
(function (UsersGroupsActionKey) {
|
|
110
|
+
UsersGroupsActionKey["GetUsers"] = "getUsers";
|
|
111
|
+
UsersGroupsActionKey["GetUser"] = "getUser";
|
|
112
|
+
UsersGroupsActionKey["CreateUser"] = "createUser";
|
|
113
|
+
UsersGroupsActionKey["UpdateUser"] = "updateUser";
|
|
114
|
+
UsersGroupsActionKey["DeleteUser"] = "deleteUser";
|
|
115
|
+
UsersGroupsActionKey["AddUserToGroup"] = "addUserToGroup";
|
|
116
|
+
UsersGroupsActionKey["DeleteUserFromGroup"] = "deleteUserFromGroup";
|
|
117
|
+
UsersGroupsActionKey["GetGroups"] = "getGroups";
|
|
118
|
+
UsersGroupsActionKey["GetGroup"] = "getGroup";
|
|
119
|
+
UsersGroupsActionKey["CreateGroup"] = "createGroup";
|
|
120
|
+
UsersGroupsActionKey["UpdateGroup"] = "updateGroup";
|
|
121
|
+
UsersGroupsActionKey["DeleteGroup"] = "deleteGroup";
|
|
122
|
+
})(UsersGroupsActionKey || (UsersGroupsActionKey = {}));
|
|
123
|
+
|
|
124
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
125
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
126
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
127
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
128
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
129
|
+
};
|
|
130
|
+
let UsersGroupsState = class UsersGroupsState extends CrudStateBase {
|
|
131
|
+
http = inject(HttpClient);
|
|
132
|
+
context = new HttpContext().set(REQUEST_CONTEXT, {
|
|
133
|
+
useBaseUrl: true,
|
|
134
|
+
});
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Data Selectors - Individual selectors for fine-grained reactivity
|
|
137
|
+
// ============================================================================
|
|
138
|
+
static getUsers(state) {
|
|
139
|
+
return state.users;
|
|
140
|
+
}
|
|
141
|
+
static getSelectedUser(state) {
|
|
142
|
+
return state.selectedUser;
|
|
143
|
+
}
|
|
144
|
+
static getGroups(state) {
|
|
145
|
+
return state.groups;
|
|
146
|
+
}
|
|
147
|
+
static getSelectedGroup(state) {
|
|
148
|
+
return state.selectedGroup;
|
|
149
|
+
}
|
|
150
|
+
// ============================================================================
|
|
151
|
+
// Loading/Error Slice Selectors - REQUIRED for optimal performance
|
|
152
|
+
// ============================================================================
|
|
153
|
+
static getLoadingActive(state) {
|
|
154
|
+
return state.loadingActive;
|
|
155
|
+
}
|
|
156
|
+
static getErrors(state) {
|
|
157
|
+
return state.errors;
|
|
158
|
+
}
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// CRUD Actions
|
|
161
|
+
// ============================================================================
|
|
162
|
+
getUsers(ctx) {
|
|
163
|
+
const req$ = this.http.get('Identity/users', {
|
|
164
|
+
context: this.context,
|
|
165
|
+
});
|
|
166
|
+
return handleApiRequest({
|
|
167
|
+
ctx,
|
|
168
|
+
key: UsersGroupsActionKey.GetUsers,
|
|
169
|
+
request$: req$,
|
|
170
|
+
onSuccess: (response) => ({
|
|
171
|
+
users: response.data ?? [],
|
|
172
|
+
}),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getUser(ctx, { userName }) {
|
|
176
|
+
const req$ = this.http.get(`Identity/users/${userName}?editMode=true`, { context: this.context });
|
|
177
|
+
return handleApiRequest({
|
|
178
|
+
ctx,
|
|
179
|
+
key: UsersGroupsActionKey.GetUser,
|
|
180
|
+
request$: req$,
|
|
181
|
+
onSuccess: (response) => ({
|
|
182
|
+
selectedUser: response.data?.[0] ?? null,
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
createUser(ctx, { payload }) {
|
|
187
|
+
const req$ = this.http.post('Identity/user', payload, {
|
|
188
|
+
context: this.context,
|
|
189
|
+
});
|
|
190
|
+
return handleApiRequest({
|
|
191
|
+
ctx,
|
|
192
|
+
key: UsersGroupsActionKey.CreateUser,
|
|
193
|
+
request$: req$,
|
|
194
|
+
onSuccess: (response, state) => {
|
|
195
|
+
const newUser = response.data;
|
|
196
|
+
if (!newUser)
|
|
197
|
+
return {};
|
|
198
|
+
return {
|
|
199
|
+
users: this.adapter.addOne(state.users, newUser),
|
|
200
|
+
selectedUser: newUser,
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
onError: (error) => {
|
|
204
|
+
throw error;
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
addUserToGroup(ctx, { payload }) {
|
|
209
|
+
const req$ = this.http.post(`identity/groups/${payload.groupId}/members`, { member: payload?.userId });
|
|
210
|
+
return handleApiRequest({
|
|
211
|
+
ctx,
|
|
212
|
+
key: UsersGroupsActionKey.AddUserToGroup,
|
|
213
|
+
request$: req$,
|
|
214
|
+
onSuccess: (response, state) => {
|
|
215
|
+
const newMembers = response.data?.members ?? [];
|
|
216
|
+
const existingMembers = state.selectedGroup?.members ?? [];
|
|
217
|
+
return {
|
|
218
|
+
selectedGroup: {
|
|
219
|
+
...(state.selectedGroup ?? {}),
|
|
220
|
+
members: [...existingMembers, ...newMembers],
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
updateUser(ctx, { changes, userId }) {
|
|
227
|
+
const req$ = this.http.put(`Identity/user/${userId}`, changes, {
|
|
228
|
+
context: this.context,
|
|
229
|
+
});
|
|
230
|
+
return handleApiRequest({
|
|
231
|
+
ctx,
|
|
232
|
+
key: UsersGroupsActionKey.UpdateUser,
|
|
233
|
+
request$: req$,
|
|
234
|
+
onSuccess: (response, state) => {
|
|
235
|
+
const updatedUser = response.data;
|
|
236
|
+
if (!updatedUser)
|
|
237
|
+
return {};
|
|
238
|
+
return {
|
|
239
|
+
users: this.adapter.upsertOne(state.users, updatedUser, 'userId'),
|
|
240
|
+
selectedUser: updatedUser,
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
onError: (error) => {
|
|
244
|
+
throw error;
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
deleteUser(ctx, { userName }) {
|
|
249
|
+
const req$ = this.http.delete(`Identity/user/${userName}`, {
|
|
250
|
+
context: this.context,
|
|
251
|
+
});
|
|
252
|
+
return this.delete(ctx, {
|
|
253
|
+
key: UsersGroupsActionKey.DeleteUser,
|
|
254
|
+
request$: req$,
|
|
255
|
+
stateProperty: (state) => state.users,
|
|
256
|
+
uniqueKey: 'userName',
|
|
257
|
+
id: userName,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
deleteUserFromGroup(ctx, { payload }) {
|
|
261
|
+
const req$ = this.http.delete(`identity/groups/${payload.groupId}/members/${payload.userName}`);
|
|
262
|
+
return handleApiRequest({
|
|
263
|
+
ctx,
|
|
264
|
+
key: UsersGroupsActionKey.DeleteUserFromGroup,
|
|
265
|
+
request$: req$,
|
|
266
|
+
onSuccess: (_response, state) => {
|
|
267
|
+
const filteredMembers = state.selectedGroup?.members?.filter((e) => e.user.userName !== payload.userName) ?? [];
|
|
268
|
+
return {
|
|
269
|
+
selectedGroup: {
|
|
270
|
+
...(state.selectedGroup ?? {}),
|
|
271
|
+
members: filteredMembers,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
getGroups(ctx) {
|
|
278
|
+
const req$ = this.http.get('Identity/groups');
|
|
279
|
+
return handleApiRequest({
|
|
280
|
+
ctx,
|
|
281
|
+
key: UsersGroupsActionKey.GetGroups,
|
|
282
|
+
request$: req$,
|
|
283
|
+
onSuccess: (response) => ({
|
|
284
|
+
groups: response.data ?? [],
|
|
285
|
+
}),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
getGroup(ctx, { groupId }) {
|
|
289
|
+
const req$ = this.http.get(`Identity/groups/${groupId}?Mode=edit`);
|
|
290
|
+
return handleApiRequest({
|
|
291
|
+
ctx,
|
|
292
|
+
key: UsersGroupsActionKey.GetGroup,
|
|
293
|
+
request$: req$,
|
|
294
|
+
onSuccess: (response) => ({
|
|
295
|
+
selectedGroup: response.data ?? null,
|
|
296
|
+
}),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
createGroup(ctx, { payload }) {
|
|
300
|
+
const req$ = this.http.post('Identity/groups', payload);
|
|
301
|
+
return handleApiRequest({
|
|
302
|
+
ctx,
|
|
303
|
+
key: UsersGroupsActionKey.CreateGroup,
|
|
304
|
+
request$: req$,
|
|
305
|
+
onSuccess: (response, state) => {
|
|
306
|
+
const newGroup = response.data?.result ?? null;
|
|
307
|
+
if (!newGroup)
|
|
308
|
+
return {};
|
|
309
|
+
return {
|
|
310
|
+
groups: this.adapter.addOne(state.groups, newGroup),
|
|
311
|
+
selectedGroup: newGroup,
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
updateGroup(ctx, { changes, groupId }) {
|
|
317
|
+
const req$ = this.http.put(`Identity/groups/${groupId}`, changes);
|
|
318
|
+
return handleApiRequest({
|
|
319
|
+
ctx,
|
|
320
|
+
key: UsersGroupsActionKey.UpdateGroup,
|
|
321
|
+
request$: req$,
|
|
322
|
+
onSuccess: (response, state) => {
|
|
323
|
+
const updatedGroup = {
|
|
324
|
+
...response.data,
|
|
325
|
+
members: state.selectedGroup?.members,
|
|
326
|
+
membersCount: state.selectedGroup?.members?.length ?? 0,
|
|
327
|
+
};
|
|
328
|
+
return {
|
|
329
|
+
groups: this.adapter.upsertOne(state.groups, updatedGroup, 'id'),
|
|
330
|
+
selectedGroup: updatedGroup,
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
deleteGroup(ctx, { groupId }) {
|
|
336
|
+
const req$ = this.http.delete(`Identity/groups/${groupId}`);
|
|
337
|
+
return this.delete(ctx, {
|
|
338
|
+
key: UsersGroupsActionKey.DeleteGroup,
|
|
339
|
+
request$: req$,
|
|
340
|
+
stateProperty: (state) => state.groups,
|
|
341
|
+
uniqueKey: 'id',
|
|
342
|
+
id: groupId,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
// ============================================================================
|
|
346
|
+
// Simple State Updates (No HTTP)
|
|
347
|
+
// ============================================================================
|
|
348
|
+
clearSelectedGroup(ctx) {
|
|
349
|
+
ctx.patchState({ selectedGroup: null });
|
|
350
|
+
}
|
|
351
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroupsState, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
352
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroupsState });
|
|
353
|
+
};
|
|
354
|
+
__decorate([
|
|
355
|
+
Action(GetUsers)
|
|
356
|
+
], UsersGroupsState.prototype, "getUsers", null);
|
|
357
|
+
__decorate([
|
|
358
|
+
Action(GetUser)
|
|
359
|
+
], UsersGroupsState.prototype, "getUser", null);
|
|
360
|
+
__decorate([
|
|
361
|
+
Action(CreateUser)
|
|
362
|
+
], UsersGroupsState.prototype, "createUser", null);
|
|
363
|
+
__decorate([
|
|
364
|
+
Action(AddUserToGroup)
|
|
365
|
+
], UsersGroupsState.prototype, "addUserToGroup", null);
|
|
366
|
+
__decorate([
|
|
367
|
+
Action(UpdateUser)
|
|
368
|
+
], UsersGroupsState.prototype, "updateUser", null);
|
|
369
|
+
__decorate([
|
|
370
|
+
Action(DeleteUser)
|
|
371
|
+
], UsersGroupsState.prototype, "deleteUser", null);
|
|
372
|
+
__decorate([
|
|
373
|
+
Action(DeleteUserFromGroup)
|
|
374
|
+
], UsersGroupsState.prototype, "deleteUserFromGroup", null);
|
|
375
|
+
__decorate([
|
|
376
|
+
Action(GetGroups)
|
|
377
|
+
], UsersGroupsState.prototype, "getGroups", null);
|
|
378
|
+
__decorate([
|
|
379
|
+
Action(GetGroup)
|
|
380
|
+
], UsersGroupsState.prototype, "getGroup", null);
|
|
381
|
+
__decorate([
|
|
382
|
+
Action(CreateGroup)
|
|
383
|
+
], UsersGroupsState.prototype, "createGroup", null);
|
|
384
|
+
__decorate([
|
|
385
|
+
Action(UpdateGroup)
|
|
386
|
+
], UsersGroupsState.prototype, "updateGroup", null);
|
|
387
|
+
__decorate([
|
|
388
|
+
Action(DeleteGroup)
|
|
389
|
+
], UsersGroupsState.prototype, "deleteGroup", null);
|
|
390
|
+
__decorate([
|
|
391
|
+
Action(ClearSelectedGroup)
|
|
392
|
+
], UsersGroupsState.prototype, "clearSelectedGroup", null);
|
|
393
|
+
__decorate([
|
|
394
|
+
Selector()
|
|
395
|
+
], UsersGroupsState, "getUsers", null);
|
|
396
|
+
__decorate([
|
|
397
|
+
Selector()
|
|
398
|
+
], UsersGroupsState, "getSelectedUser", null);
|
|
399
|
+
__decorate([
|
|
400
|
+
Selector()
|
|
401
|
+
], UsersGroupsState, "getGroups", null);
|
|
402
|
+
__decorate([
|
|
403
|
+
Selector()
|
|
404
|
+
], UsersGroupsState, "getSelectedGroup", null);
|
|
405
|
+
__decorate([
|
|
406
|
+
Selector()
|
|
407
|
+
], UsersGroupsState, "getLoadingActive", null);
|
|
408
|
+
__decorate([
|
|
409
|
+
Selector()
|
|
410
|
+
], UsersGroupsState, "getErrors", null);
|
|
411
|
+
UsersGroupsState = __decorate([
|
|
412
|
+
State({
|
|
413
|
+
name: 'usersGroups',
|
|
414
|
+
defaults: {
|
|
415
|
+
users: [],
|
|
416
|
+
selectedUser: null,
|
|
417
|
+
groups: [],
|
|
418
|
+
selectedGroup: null,
|
|
419
|
+
loadingActive: [],
|
|
420
|
+
errors: {},
|
|
421
|
+
},
|
|
422
|
+
})
|
|
423
|
+
], UsersGroupsState);
|
|
424
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroupsState, decorators: [{
|
|
425
|
+
type: Injectable
|
|
426
|
+
}], propDecorators: { getUsers: [], getUser: [], createUser: [], addUserToGroup: [], updateUser: [], deleteUser: [], deleteUserFromGroup: [], getGroups: [], getGroup: [], createGroup: [], updateGroup: [], deleteGroup: [], clearSelectedGroup: [] } });
|
|
427
|
+
|
|
428
|
+
class UsersGroupsFacade {
|
|
429
|
+
store = inject(Store);
|
|
430
|
+
// ============================================================================
|
|
431
|
+
// Data Selectors - Memoized by NGXS (fine-grained reactivity)
|
|
432
|
+
// ============================================================================
|
|
433
|
+
users = select(UsersGroupsState.getUsers);
|
|
434
|
+
selectedUser = select(UsersGroupsState.getSelectedUser);
|
|
435
|
+
groups = select(UsersGroupsState.getGroups);
|
|
436
|
+
selectedGroup = select(UsersGroupsState.getSelectedGroup);
|
|
437
|
+
// ============================================================================
|
|
438
|
+
// Loading/Error Slices - Memoized by NGXS
|
|
439
|
+
// ============================================================================
|
|
440
|
+
loadingActive = select(UsersGroupsState.getLoadingActive);
|
|
441
|
+
// ============================================================================
|
|
442
|
+
// Loading Signals - Computed from slice (minimal reactivity)
|
|
443
|
+
// ============================================================================
|
|
444
|
+
isLoadingUsers = computed(() => this.loadingActive().includes(UsersGroupsActionKey.GetUsers), ...(ngDevMode ? [{ debugName: "isLoadingUsers" }] : []));
|
|
445
|
+
isLoadingUser = computed(() => this.loadingActive().includes(UsersGroupsActionKey.GetUser), ...(ngDevMode ? [{ debugName: "isLoadingUser" }] : []));
|
|
446
|
+
isSavingUser = computed(() => this.loadingActive().includes(UsersGroupsActionKey.CreateUser) ||
|
|
447
|
+
this.loadingActive().includes(UsersGroupsActionKey.UpdateUser), ...(ngDevMode ? [{ debugName: "isSavingUser" }] : []));
|
|
448
|
+
isDeletingUser = computed(() => this.loadingActive().includes(UsersGroupsActionKey.DeleteUser), ...(ngDevMode ? [{ debugName: "isDeletingUser" }] : []));
|
|
449
|
+
isLoadingGroups = computed(() => this.loadingActive().includes(UsersGroupsActionKey.GetGroups), ...(ngDevMode ? [{ debugName: "isLoadingGroups" }] : []));
|
|
450
|
+
isLoadingGroup = computed(() => this.loadingActive().includes(UsersGroupsActionKey.GetGroup), ...(ngDevMode ? [{ debugName: "isLoadingGroup" }] : []));
|
|
451
|
+
isSavingGroup = computed(() => this.loadingActive().includes(UsersGroupsActionKey.CreateGroup) ||
|
|
452
|
+
this.loadingActive().includes(UsersGroupsActionKey.UpdateGroup), ...(ngDevMode ? [{ debugName: "isSavingGroup" }] : []));
|
|
453
|
+
isDeletingGroup = computed(() => this.loadingActive().includes(UsersGroupsActionKey.DeleteGroup), ...(ngDevMode ? [{ debugName: "isDeletingGroup" }] : []));
|
|
454
|
+
isAddingUserToGroup = computed(() => this.loadingActive().includes(UsersGroupsActionKey.AddUserToGroup), ...(ngDevMode ? [{ debugName: "isAddingUserToGroup" }] : []));
|
|
455
|
+
isDeletingUserFromGroup = computed(() => this.loadingActive().includes(UsersGroupsActionKey.DeleteUserFromGroup), ...(ngDevMode ? [{ debugName: "isDeletingUserFromGroup" }] : []));
|
|
456
|
+
// ============================================================================
|
|
457
|
+
// Action Dispatchers
|
|
458
|
+
// ============================================================================
|
|
459
|
+
getUsers() {
|
|
460
|
+
return this.store.dispatch(new GetUsers());
|
|
461
|
+
}
|
|
462
|
+
getUser(id) {
|
|
463
|
+
return this.store.dispatch(new GetUser(id));
|
|
464
|
+
}
|
|
465
|
+
createUser(payload) {
|
|
466
|
+
return this.store.dispatch(new CreateUser(payload));
|
|
467
|
+
}
|
|
468
|
+
addUserToGroup(userId, groupId) {
|
|
469
|
+
return this.store.dispatch(new AddUserToGroup({ userId, groupId }));
|
|
470
|
+
}
|
|
471
|
+
deleteUserFromGroup(payload) {
|
|
472
|
+
return this.store.dispatch(new DeleteUserFromGroup(payload));
|
|
473
|
+
}
|
|
474
|
+
updateUser(id, changes) {
|
|
475
|
+
return this.store.dispatch(new UpdateUser(id, changes));
|
|
476
|
+
}
|
|
477
|
+
deleteUser(userName) {
|
|
478
|
+
return this.store.dispatch(new DeleteUser(userName));
|
|
479
|
+
}
|
|
480
|
+
getGroups() {
|
|
481
|
+
return this.store.dispatch(new GetGroups());
|
|
482
|
+
}
|
|
483
|
+
getGroup(id) {
|
|
484
|
+
return this.store.dispatch(new GetGroup(id));
|
|
485
|
+
}
|
|
486
|
+
createGroup(payload) {
|
|
487
|
+
return this.store.dispatch(new CreateGroup(payload));
|
|
488
|
+
}
|
|
489
|
+
updateGroup(id, changes) {
|
|
490
|
+
return this.store.dispatch(new UpdateGroup(id, changes));
|
|
491
|
+
}
|
|
492
|
+
deleteGroup(groupId) {
|
|
493
|
+
return this.store.dispatch(new DeleteGroup(groupId));
|
|
494
|
+
}
|
|
495
|
+
clearSelectedGroup() {
|
|
496
|
+
this.store.dispatch(new ClearSelectedGroup());
|
|
497
|
+
}
|
|
498
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroupsFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
499
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroupsFacade, providedIn: 'root' });
|
|
500
|
+
}
|
|
501
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroupsFacade, decorators: [{
|
|
502
|
+
type: Injectable,
|
|
503
|
+
args: [{ providedIn: 'root' }]
|
|
504
|
+
}] });
|
|
505
|
+
|
|
506
|
+
class UsersGroups {
|
|
507
|
+
facade = inject(UsersGroupsFacade);
|
|
508
|
+
route = inject(ActivatedRoute);
|
|
509
|
+
router = inject(Router);
|
|
510
|
+
translocoService = inject(TranslocoService);
|
|
511
|
+
selectedTab = signal('users', ...(ngDevMode ? [{ debugName: "selectedTab" }] : []));
|
|
512
|
+
tabsList = [
|
|
513
|
+
{
|
|
514
|
+
label: this.translocoService.translate('users-groups.users'),
|
|
515
|
+
value: 'users',
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
label: this.translocoService.translate('users-groups.groups'),
|
|
519
|
+
value: 'groups',
|
|
520
|
+
},
|
|
521
|
+
];
|
|
522
|
+
breadcrumbItems = [
|
|
523
|
+
{
|
|
524
|
+
label: '',
|
|
525
|
+
icon: 'general.home-line',
|
|
526
|
+
routerLink: '/control-panel/workspaces',
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
label: this.translocoService.translate('product-settings.product-settings'),
|
|
530
|
+
routerLink: '/control-panel/product-settings',
|
|
531
|
+
},
|
|
532
|
+
{ label: this.translocoService.translate('users-groups.users-groups') },
|
|
533
|
+
];
|
|
534
|
+
ngOnInit() {
|
|
535
|
+
const selectedTab = this.route.snapshot.firstChild?.data['componentType'];
|
|
536
|
+
this.selectedTab.set(selectedTab || 'users');
|
|
537
|
+
this.facade.getUsers();
|
|
538
|
+
}
|
|
539
|
+
goBack() {
|
|
540
|
+
this.router.navigate(['control-panel/product-settings']);
|
|
541
|
+
}
|
|
542
|
+
onTabChange(event) {
|
|
543
|
+
this.selectedTab.set(event);
|
|
544
|
+
if (event == 'users') {
|
|
545
|
+
this.router.navigate(['users'], { relativeTo: this.route });
|
|
546
|
+
}
|
|
547
|
+
else if (event == 'groups') {
|
|
548
|
+
this.router.navigate(['groups'], { relativeTo: this.route });
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
getUsers() {
|
|
552
|
+
this.facade.getUsers();
|
|
553
|
+
}
|
|
554
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroups, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
555
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: UsersGroups, isStandalone: true, selector: "mt-users-groups", ngImport: i0, template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <mt-page\r\n [title]=\"t('users-groups')\"\r\n [avatarIcon]=\"'user.user-circle'\"\r\n [avatarStyle]=\"{\r\n '--p-avatar-background': 'var(--p-sky-100)',\r\n '--p-avatar-color': 'var(--p-sky-700)',\r\n }\"\r\n [tabs]=\"tabsList\"\r\n [activeTab]=\"selectedTab()\"\r\n (tabChange)=\"onTabChange($event)\"\r\n (backButtonClick)=\"goBack()\"\r\n backButton\r\n >\r\n <div class=\"flex justify-between items-end\">\r\n <div>\r\n <h3 class=\"font-bold text-lg\">{{ t(\"users-groups\") }}</h3>\r\n <mt-breadcrumb\r\n [items]=\"breadcrumbItems\"\r\n [styleClass]=\"'flex justify-start mx-1'\"\r\n ></mt-breadcrumb>\r\n </div>\r\n @if (selectedTab() === \"users\") {\r\n <mt-button\r\n [icon]=\"'arrow.refresh-cw-02'\"\r\n [label]=\"\r\n translocoService.translate('users-groups.sync-users-information')\r\n \"\r\n [severity]=\"'primary'\"\r\n [variant]=\"'outlined'\"\r\n [size]=\"'small'\"\r\n (click)=\"getUsers()\"\r\n class=\"mx-4\"\r\n >\r\n </mt-button>\r\n }\r\n </div>\r\n <router-outlet />\r\n </mt-page>\r\n</ng-container>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: Page, selector: "mt-page", inputs: ["backButton", "backButtonIcon", "avatarIcon", "avatarStyle", "avatarShape", "title", "tabs", "activeTab", "contentClass", "contentId"], outputs: ["backButtonClick", "tabChange"] }, { kind: "component", type: Breadcrumb, selector: "mt-breadcrumb", inputs: ["items", "styleClass"], outputs: ["onItemClick"] }, { kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name", "routerOutletData"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }, { kind: "directive", type: TranslocoDirective, selector: "[transloco]", inputs: ["transloco", "translocoParams", "translocoScope", "translocoRead", "translocoPrefix", "translocoLang", "translocoLoadingTpl"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }] });
|
|
556
|
+
}
|
|
557
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UsersGroups, decorators: [{
|
|
558
|
+
type: Component,
|
|
559
|
+
args: [{ selector: 'mt-users-groups', standalone: true, imports: [
|
|
560
|
+
CommonModule,
|
|
561
|
+
Page,
|
|
562
|
+
Breadcrumb,
|
|
563
|
+
RouterOutlet,
|
|
564
|
+
TranslocoDirective,
|
|
565
|
+
Button,
|
|
566
|
+
], template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <mt-page\r\n [title]=\"t('users-groups')\"\r\n [avatarIcon]=\"'user.user-circle'\"\r\n [avatarStyle]=\"{\r\n '--p-avatar-background': 'var(--p-sky-100)',\r\n '--p-avatar-color': 'var(--p-sky-700)',\r\n }\"\r\n [tabs]=\"tabsList\"\r\n [activeTab]=\"selectedTab()\"\r\n (tabChange)=\"onTabChange($event)\"\r\n (backButtonClick)=\"goBack()\"\r\n backButton\r\n >\r\n <div class=\"flex justify-between items-end\">\r\n <div>\r\n <h3 class=\"font-bold text-lg\">{{ t(\"users-groups\") }}</h3>\r\n <mt-breadcrumb\r\n [items]=\"breadcrumbItems\"\r\n [styleClass]=\"'flex justify-start mx-1'\"\r\n ></mt-breadcrumb>\r\n </div>\r\n @if (selectedTab() === \"users\") {\r\n <mt-button\r\n [icon]=\"'arrow.refresh-cw-02'\"\r\n [label]=\"\r\n translocoService.translate('users-groups.sync-users-information')\r\n \"\r\n [severity]=\"'primary'\"\r\n [variant]=\"'outlined'\"\r\n [size]=\"'small'\"\r\n (click)=\"getUsers()\"\r\n class=\"mx-4\"\r\n >\r\n </mt-button>\r\n }\r\n </div>\r\n <router-outlet />\r\n </mt-page>\r\n</ng-container>\r\n" }]
|
|
567
|
+
}] });
|
|
568
|
+
|
|
569
|
+
class UserForm {
|
|
570
|
+
modal = inject(ModalService);
|
|
571
|
+
ref = inject(ModalRef);
|
|
572
|
+
userForEdit = input(null, ...(ngDevMode ? [{ debugName: "userForEdit" }] : []));
|
|
573
|
+
selectedTab = signal('internal', ...(ngDevMode ? [{ debugName: "selectedTab" }] : []));
|
|
574
|
+
translocoService = inject(TranslocoService);
|
|
575
|
+
tabsList = [
|
|
576
|
+
{
|
|
577
|
+
label: this.translocoService.translate('users-groups.internal'),
|
|
578
|
+
value: 'internal',
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
label: this.translocoService.translate('users-groups.external'),
|
|
582
|
+
value: 'external',
|
|
583
|
+
},
|
|
584
|
+
];
|
|
585
|
+
facade = inject(UsersGroupsFacade);
|
|
586
|
+
selectedUser = this.facade.selectedUser;
|
|
587
|
+
internalUserFormControl = new FormControl();
|
|
588
|
+
externalUserFormControl = new FormControl();
|
|
589
|
+
getUserFormLoading = this.facade.isLoadingUser;
|
|
590
|
+
createUpdateUserLoading = this.facade.isSavingUser;
|
|
591
|
+
context = new HttpContext().set(REQUEST_CONTEXT, {
|
|
592
|
+
useBaseUrl: true,
|
|
593
|
+
});
|
|
594
|
+
internalUserFormConfig = signal({
|
|
595
|
+
sections: [
|
|
596
|
+
{
|
|
597
|
+
key: 'internalUserFormConfig',
|
|
598
|
+
type: 'header',
|
|
599
|
+
order: 1,
|
|
600
|
+
fields: [
|
|
601
|
+
new UserSearchFieldConfig({
|
|
602
|
+
key: 'userField',
|
|
603
|
+
label: this.translocoService.translate('users-groups.user-name'),
|
|
604
|
+
apiUrl: 'Identity/adUsers',
|
|
605
|
+
context: this.context,
|
|
606
|
+
validators: [ValidatorConfig.required()],
|
|
607
|
+
order: 1,
|
|
608
|
+
}),
|
|
609
|
+
],
|
|
610
|
+
},
|
|
611
|
+
],
|
|
612
|
+
}, ...(ngDevMode ? [{ debugName: "internalUserFormConfig" }] : []));
|
|
613
|
+
fieldColSpan = computed(() => (this.userForEdit()?.userName ? 12 : 6), ...(ngDevMode ? [{ debugName: "fieldColSpan" }] : []));
|
|
614
|
+
externalUserFormConfig = computed(() => ({
|
|
615
|
+
sections: [
|
|
616
|
+
{
|
|
617
|
+
key: 'externalUserFormConfig',
|
|
618
|
+
type: 'header',
|
|
619
|
+
order: 1,
|
|
620
|
+
fields: [
|
|
621
|
+
new UploadFileFieldConfig({
|
|
622
|
+
key: 'image',
|
|
623
|
+
label: 'Avatar',
|
|
624
|
+
shape: 'circle',
|
|
625
|
+
endPoint: 'avatar',
|
|
626
|
+
context: this.context,
|
|
627
|
+
colSpan: 12,
|
|
628
|
+
order: 1,
|
|
629
|
+
}),
|
|
630
|
+
{
|
|
631
|
+
key: 'displayName',
|
|
632
|
+
label: this.translocoService.translate('users-groups.display-name'),
|
|
633
|
+
placeholder: this.translocoService.translate('users-groups.display-name'),
|
|
634
|
+
validators: [ValidatorConfig.required()],
|
|
635
|
+
colSpan: this.fieldColSpan(),
|
|
636
|
+
order: 2,
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
key: 'email',
|
|
640
|
+
label: this.translocoService.translate('users-groups.email'),
|
|
641
|
+
placeholder: this.translocoService.translate('users-groups.email'),
|
|
642
|
+
inputType: 'email',
|
|
643
|
+
required: true,
|
|
644
|
+
validators: [
|
|
645
|
+
ValidatorConfig.required('Email is required'),
|
|
646
|
+
ValidatorConfig.email('Please enter a valid email address'),
|
|
647
|
+
],
|
|
648
|
+
colSpan: this.fieldColSpan(),
|
|
649
|
+
order: 4,
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
key: 'mobile',
|
|
653
|
+
label: this.translocoService.translate('users-groups.mobile'),
|
|
654
|
+
placeholder: this.translocoService.translate('users-groups.mobile'),
|
|
655
|
+
validators: [ValidatorConfig.required()],
|
|
656
|
+
colSpan: this.fieldColSpan(),
|
|
657
|
+
order: 5,
|
|
658
|
+
},
|
|
659
|
+
],
|
|
660
|
+
},
|
|
661
|
+
],
|
|
662
|
+
}), ...(ngDevMode ? [{ debugName: "externalUserFormConfig" }] : []));
|
|
663
|
+
constructor() {
|
|
664
|
+
effect(() => {
|
|
665
|
+
const userName = this.userForEdit()?.userName;
|
|
666
|
+
if (this.selectedUser() && userName) {
|
|
667
|
+
this.selectedTab.set('external');
|
|
668
|
+
const data = {
|
|
669
|
+
...this.selectedUser(),
|
|
670
|
+
image: this.selectedUser()?.photo,
|
|
671
|
+
};
|
|
672
|
+
this.externalUserFormControl.patchValue(data);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
ngOnInit() {
|
|
677
|
+
if (this.userForEdit()?.userName) {
|
|
678
|
+
this.facade.getUser(this.userForEdit()?.userName || null);
|
|
679
|
+
}
|
|
680
|
+
this.updateFormFields();
|
|
681
|
+
}
|
|
682
|
+
onSubmit() {
|
|
683
|
+
if (this.userForEdit()?.userName) {
|
|
684
|
+
const payload = {
|
|
685
|
+
displayName: this.externalUserFormControl.value?.displayName,
|
|
686
|
+
email: this.externalUserFormControl.value?.email,
|
|
687
|
+
mobile: this.externalUserFormControl.value?.mobile,
|
|
688
|
+
image: this.externalUserFormControl.value?.image?.fileName,
|
|
689
|
+
};
|
|
690
|
+
this.facade.updateUser(this.userForEdit()?.userId, payload).subscribe({
|
|
691
|
+
next: () => {
|
|
692
|
+
this.ref.close(true);
|
|
693
|
+
},
|
|
694
|
+
error: () => { },
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
let payload = {};
|
|
699
|
+
if (this.selectedTab() === 'internal') {
|
|
700
|
+
payload = {
|
|
701
|
+
userName: this.internalUserFormControl.value?.userField?.userName,
|
|
702
|
+
isExternal: false,
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
payload = {
|
|
707
|
+
userId: '',
|
|
708
|
+
userName: this.externalUserFormControl.value?.userName,
|
|
709
|
+
displayName: this.externalUserFormControl.value?.displayName,
|
|
710
|
+
email: this.externalUserFormControl.value?.email,
|
|
711
|
+
mobile: this.externalUserFormControl.value?.mobile,
|
|
712
|
+
password: this.externalUserFormControl.value?.password,
|
|
713
|
+
isExternal: true,
|
|
714
|
+
image: this.externalUserFormControl.value?.image?.fileName,
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
this.facade.createUser(payload).subscribe({
|
|
718
|
+
next: () => {
|
|
719
|
+
this.ref.close(true);
|
|
720
|
+
},
|
|
721
|
+
error: () => { },
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
updateFormFields() {
|
|
726
|
+
if (!this.userForEdit()?.userName) {
|
|
727
|
+
this.externalUserFormConfig().sections[0].fields.push({
|
|
728
|
+
key: 'userName',
|
|
729
|
+
label: this.translocoService.translate('users-groups.user-name'),
|
|
730
|
+
placeholder: this.translocoService.translate('users-groups.user-name'),
|
|
731
|
+
validators: [
|
|
732
|
+
ValidatorConfig.required(),
|
|
733
|
+
ValidatorConfig.pattern('^[a-zA-Z0-9]+$'),
|
|
734
|
+
],
|
|
735
|
+
colSpan: 6,
|
|
736
|
+
order: 3,
|
|
737
|
+
hidden: !!this.userForEdit()?.userName,
|
|
738
|
+
}, {
|
|
739
|
+
key: 'password',
|
|
740
|
+
label: this.translocoService.translate('users-groups.password'),
|
|
741
|
+
placeholder: this.translocoService.translate('users-groups.password'),
|
|
742
|
+
validators: [ValidatorConfig.required()],
|
|
743
|
+
inputType: 'password',
|
|
744
|
+
colSpan: 6,
|
|
745
|
+
order: 6,
|
|
746
|
+
hidden: !!this.userForEdit()?.userName,
|
|
747
|
+
}, {
|
|
748
|
+
key: 'confirmPassword',
|
|
749
|
+
label: this.translocoService.translate('users-groups.confirm-password'),
|
|
750
|
+
placeholder: this.translocoService.translate('users-groups.confirm-password'),
|
|
751
|
+
validators: [ValidatorConfig.required()],
|
|
752
|
+
inputType: 'password',
|
|
753
|
+
colSpan: 6,
|
|
754
|
+
order: 6,
|
|
755
|
+
hidden: !!this.userForEdit()?.userName,
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UserForm, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
760
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: UserForm, isStandalone: true, selector: "mt-user-form", inputs: { userForEdit: { classPropertyName: "userForEdit", publicName: "userForEdit", isSignal: true, isRequired: false, transformFunction: null } }, providers: [DialogService], ngImport: i0, template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div [class]=\"'flex flex-col gap-1 p-4 ' + modal.contentClass\">\r\n @if (!getUserFormLoading()) {\r\n <div class=\"flex justify-center\">\r\n <div class=\"w-60\">\r\n <mt-tabs\r\n [(active)]=\"selectedTab\"\r\n [options]=\"tabsList\"\r\n fluid\r\n size=\"small\"\r\n [disabled]=\"!!this.userForEdit()?.userName\"\r\n ></mt-tabs>\r\n </div>\r\n </div>\r\n\r\n <form class=\"col-span-1\">\r\n @if (selectedTab() === \"internal\") {\r\n <mt-dynamic-form\r\n [formConfig]=\"internalUserFormConfig()\"\r\n [formControl]=\"internalUserFormControl\"\r\n />\r\n } @else {\r\n <mt-dynamic-form\r\n [formConfig]=\"externalUserFormConfig()\"\r\n [formControl]=\"externalUserFormControl\"\r\n />\r\n }\r\n </form>\r\n } @else {\r\n <p-skeleton class=\"my-4 mt-7\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n }\r\n </div>\r\n\r\n <div [class]=\"modal.footerClass\">\r\n <mt-button\r\n [label]=\"selectedUser() ? ('save' | transloco) : ('add' | transloco)\"\r\n (click)=\"onSubmit()\"\r\n [loading]=\"createUpdateUserLoading()\"\r\n [disabled]=\"\r\n selectedTab() === 'internal'\r\n ? !this.internalUserFormControl.valid\r\n : !this.externalUserFormControl.valid\r\n \"\r\n />\r\n </div>\r\n</ng-container>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "directive", type: TranslocoDirective, selector: "[transloco]", inputs: ["transloco", "translocoParams", "translocoScope", "translocoRead", "translocoPrefix", "translocoLang", "translocoLoadingTpl"] }, { kind: "ngmodule", type: SkeletonModule }, { kind: "component", type: i1.Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "component", type: DynamicForm, selector: "mt-dynamic-form", inputs: ["formConfig"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: Tabs, selector: "mt-tabs", inputs: ["options", "optionLabel", "optionValue", "active", "size", "fluid", "disabled"], outputs: ["activeChange", "onChange"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }] });
|
|
761
|
+
}
|
|
762
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: UserForm, decorators: [{
|
|
763
|
+
type: Component,
|
|
764
|
+
args: [{ selector: 'mt-user-form', standalone: true, imports: [
|
|
765
|
+
CommonModule,
|
|
766
|
+
Button,
|
|
767
|
+
TranslocoDirective,
|
|
768
|
+
SkeletonModule,
|
|
769
|
+
DynamicForm,
|
|
770
|
+
ReactiveFormsModule,
|
|
771
|
+
Tabs,
|
|
772
|
+
TranslocoPipe,
|
|
773
|
+
], providers: [DialogService], template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div [class]=\"'flex flex-col gap-1 p-4 ' + modal.contentClass\">\r\n @if (!getUserFormLoading()) {\r\n <div class=\"flex justify-center\">\r\n <div class=\"w-60\">\r\n <mt-tabs\r\n [(active)]=\"selectedTab\"\r\n [options]=\"tabsList\"\r\n fluid\r\n size=\"small\"\r\n [disabled]=\"!!this.userForEdit()?.userName\"\r\n ></mt-tabs>\r\n </div>\r\n </div>\r\n\r\n <form class=\"col-span-1\">\r\n @if (selectedTab() === \"internal\") {\r\n <mt-dynamic-form\r\n [formConfig]=\"internalUserFormConfig()\"\r\n [formControl]=\"internalUserFormControl\"\r\n />\r\n } @else {\r\n <mt-dynamic-form\r\n [formConfig]=\"externalUserFormConfig()\"\r\n [formControl]=\"externalUserFormControl\"\r\n />\r\n }\r\n </form>\r\n } @else {\r\n <p-skeleton class=\"my-4 mt-7\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n }\r\n </div>\r\n\r\n <div [class]=\"modal.footerClass\">\r\n <mt-button\r\n [label]=\"selectedUser() ? ('save' | transloco) : ('add' | transloco)\"\r\n (click)=\"onSubmit()\"\r\n [loading]=\"createUpdateUserLoading()\"\r\n [disabled]=\"\r\n selectedTab() === 'internal'\r\n ? !this.internalUserFormControl.valid\r\n : !this.externalUserFormControl.valid\r\n \"\r\n />\r\n </div>\r\n</ng-container>\r\n" }]
|
|
774
|
+
}], ctorParameters: () => [], propDecorators: { userForEdit: [{ type: i0.Input, args: [{ isSignal: true, alias: "userForEdit", required: false }] }] } });
|
|
775
|
+
function passwordMatchValidator(passwordControlName, confirmPasswordControlName) {
|
|
776
|
+
return (group) => {
|
|
777
|
+
// 1. Get the controls from the group
|
|
778
|
+
const passwordControl = group.get(passwordControlName);
|
|
779
|
+
const confirmPasswordControl = group.get(confirmPasswordControlName);
|
|
780
|
+
// 2. Basic checks (if controls don't exist, or if one is null, it's not a mismatch error)
|
|
781
|
+
if (!passwordControl || !confirmPasswordControl) {
|
|
782
|
+
return null;
|
|
783
|
+
}
|
|
784
|
+
// 3. Check for value mismatch
|
|
785
|
+
if (passwordControl.value !== confirmPasswordControl.value) {
|
|
786
|
+
// 4. Set the error on the 'confirm password' control for clearer user feedback
|
|
787
|
+
confirmPasswordControl.setErrors({ mismatch: true });
|
|
788
|
+
return { mismatch: true }; // The group itself has a mismatch error
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
// 5. If they match, clear any previous mismatch error on the 'confirm password' control
|
|
792
|
+
if (confirmPasswordControl.hasError('mismatch')) {
|
|
793
|
+
const errors = confirmPasswordControl.errors;
|
|
794
|
+
if (errors) {
|
|
795
|
+
delete errors['mismatch'];
|
|
796
|
+
confirmPasswordControl.setErrors(Object.keys(errors).length > 0 ? errors : null);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return null; // No mismatch error
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
class Users {
|
|
805
|
+
typeCol = viewChild.required('typeCol');
|
|
806
|
+
userCol = viewChild.required('userCol');
|
|
807
|
+
facade = inject(UsersGroupsFacade);
|
|
808
|
+
modal = inject(ModalService);
|
|
809
|
+
translocoService = inject(TranslocoService);
|
|
810
|
+
users = computed(() => {
|
|
811
|
+
const tab = this.activeTab();
|
|
812
|
+
const all = this.allUsers();
|
|
813
|
+
switch (tab) {
|
|
814
|
+
case 'internal':
|
|
815
|
+
return all.filter((user) => !user.isExternal);
|
|
816
|
+
case 'external':
|
|
817
|
+
return all.filter((user) => user.isExternal);
|
|
818
|
+
case 'all':
|
|
819
|
+
default:
|
|
820
|
+
return all;
|
|
821
|
+
}
|
|
822
|
+
}, ...(ngDevMode ? [{ debugName: "users" }] : []));
|
|
823
|
+
tabs = signal([
|
|
824
|
+
{
|
|
825
|
+
label: this.translocoService.translate('users-groups.all'),
|
|
826
|
+
value: 'all',
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
label: this.translocoService.translate('users-groups.internal'),
|
|
830
|
+
value: 'internal',
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
label: this.translocoService.translate('users-groups.external'),
|
|
834
|
+
value: 'external',
|
|
835
|
+
},
|
|
836
|
+
], ...(ngDevMode ? [{ debugName: "tabs" }] : []));
|
|
837
|
+
activeTab = signal('all', ...(ngDevMode ? [{ debugName: "activeTab" }] : []));
|
|
838
|
+
tableActions = signal([
|
|
839
|
+
{
|
|
840
|
+
icon: 'general.plus',
|
|
841
|
+
label: this.translocoService.translate('users-groups.add-user'),
|
|
842
|
+
color: 'primary',
|
|
843
|
+
action: () => {
|
|
844
|
+
this.addUserDialog();
|
|
845
|
+
},
|
|
846
|
+
},
|
|
847
|
+
], ...(ngDevMode ? [{ debugName: "tableActions" }] : []));
|
|
848
|
+
deletingRowIds = signal([], ...(ngDevMode ? [{ debugName: "deletingRowIds" }] : []));
|
|
849
|
+
rowActions = signal([
|
|
850
|
+
{
|
|
851
|
+
icon: 'custom.pencil',
|
|
852
|
+
tooltip: this.translocoService.translate('edit'),
|
|
853
|
+
color: 'primary',
|
|
854
|
+
action: (row) => {
|
|
855
|
+
this.addUserDialog(row);
|
|
856
|
+
},
|
|
857
|
+
hidden: (row) => !row.isExternal,
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
icon: 'general.trash-01',
|
|
861
|
+
tooltip: this.translocoService.translate('delete'),
|
|
862
|
+
color: 'danger',
|
|
863
|
+
variant: 'outlined',
|
|
864
|
+
action: (row) => {
|
|
865
|
+
this.deletingRowIds.update((ids) => [...ids, row.userName]);
|
|
866
|
+
this.facade
|
|
867
|
+
.deleteUser(row.userName)
|
|
868
|
+
.pipe(finalize(() => {
|
|
869
|
+
this.deletingRowIds.update((ids) => ids.filter((id) => id !== row.userName));
|
|
870
|
+
}))
|
|
871
|
+
.subscribe();
|
|
872
|
+
},
|
|
873
|
+
confirmation: {
|
|
874
|
+
type: 'popup',
|
|
875
|
+
confirmationType: 'delete',
|
|
876
|
+
},
|
|
877
|
+
loading: (row) => this.deletingRowIds().includes(row.userName),
|
|
878
|
+
},
|
|
879
|
+
], ...(ngDevMode ? [{ debugName: "rowActions" }] : []));
|
|
880
|
+
tableColumns = linkedSignal(() => [
|
|
881
|
+
{
|
|
882
|
+
key: 'displayName',
|
|
883
|
+
label: this.translocoService.translate('users-groups.user'),
|
|
884
|
+
type: 'custom',
|
|
885
|
+
customCellTpl: this.userCol(),
|
|
886
|
+
filterConfig: {
|
|
887
|
+
type: 'text',
|
|
888
|
+
label: this.translocoService.translate('users-groups.user'),
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
key: 'isExternal',
|
|
893
|
+
label: this.translocoService.translate('users-groups.type'),
|
|
894
|
+
type: 'custom',
|
|
895
|
+
customCellTpl: this.typeCol(),
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
key: 'email',
|
|
899
|
+
label: this.translocoService.translate('users-groups.email'),
|
|
900
|
+
filterConfig: {
|
|
901
|
+
type: 'text',
|
|
902
|
+
label: this.translocoService.translate('users-groups.email'),
|
|
903
|
+
},
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
key: 'lastLoginTime.displayValue',
|
|
907
|
+
label: this.translocoService.translate('users-groups.last-seen'),
|
|
908
|
+
},
|
|
909
|
+
], ...(ngDevMode ? [{ debugName: "tableColumns" }] : []));
|
|
910
|
+
loading = this.facade.isLoadingUsers;
|
|
911
|
+
allUsers = this.facade.users;
|
|
912
|
+
ngOnInit() {
|
|
913
|
+
this.facade.getUsers();
|
|
914
|
+
}
|
|
915
|
+
addUserDialog(user = null) {
|
|
916
|
+
const modalType = user ? 'drawer' : 'dialog';
|
|
917
|
+
this.modal.openModal(UserForm, modalType, {
|
|
918
|
+
header: user
|
|
919
|
+
? this.translocoService.translate('users-groups.edit-user')
|
|
920
|
+
: this.translocoService.translate('users-groups.add-user'),
|
|
921
|
+
styleClass: modalType === 'drawer'
|
|
922
|
+
? '!w-[30rem] !absolute !shadow-none'
|
|
923
|
+
: '!w-[50rem]',
|
|
924
|
+
position: modalType === 'drawer' ? 'end' : '',
|
|
925
|
+
appendTo: modalType === 'drawer' ? 'page-content' : 'body',
|
|
926
|
+
dismissableMask: true,
|
|
927
|
+
dismissible: true,
|
|
928
|
+
inputValues: {
|
|
929
|
+
userForEdit: user,
|
|
930
|
+
},
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Users, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
934
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.3", type: Users, isStandalone: true, selector: "mt-users", viewQueries: [{ propertyName: "typeCol", first: true, predicate: ["typeCol"], descendants: true, isSignal: true }, { propertyName: "userCol", first: true, predicate: ["userCol"], descendants: true, isSignal: true }], ngImport: i0, template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div class=\"mt-5\">\r\n <ng-template #typeCol let-row>\r\n <div>{{ row.isExternal ? t(\"external\") : t(\"internal\") }}</div>\r\n </ng-template>\r\n <ng-template #userCol let-row>\r\n <div class=\"flex items-center gap-2\">\r\n <mt-avatar [icon]=\"'custom.user-pp'\"> </mt-avatar> {{ row.displayName }}\r\n </div>\r\n </ng-template>\r\n\r\n <mt-table\r\n [tabs]=\"tabs()\"\r\n [(activeTab)]=\"activeTab\"\r\n [data]=\"users()\"\r\n [columns]=\"tableColumns()\"\r\n [actions]=\"tableActions()\"\r\n [rowActions]=\"rowActions()\"\r\n [generalSearch]=\"true\"\r\n [showFilters]=\"true\"\r\n [loading]=\"loading()\"\r\n >\r\n </mt-table>\r\n </div>\r\n</ng-container>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: SkeletonModule }, { kind: "component", type: Table, selector: "mt-table", inputs: ["filters", "data", "columns", "rowActions", "size", "showGridlines", "stripedRows", "selectableRows", "generalSearch", "showFilters", "loading", "updating", "lazy", "lazyTotalRecords", "reorderableColumns", "reorderableRows", "dataKey", "exportable", "exportFilename", "tabs", "tabsOptionLabel", "tabsOptionValue", "activeTab", "actions", "paginatorPosition", "pageSize", "currentPage", "first", "filterTerm"], outputs: ["selectionChange", "cellChange", "lazyLoad", "columnReorder", "rowReorder", "filtersChange", "activeTabChange", "onTabChange", "pageSizeChange", "currentPageChange", "firstChange", "filterTermChange"] }, { kind: "component", type: Avatar, selector: "mt-avatar", inputs: ["label", "icon", "image", "styleClass", "size", "shape", "badge", "badgeSize", "badgeSeverity"], outputs: ["onImageError"] }, { kind: "directive", type: TranslocoDirective, selector: "[transloco]", inputs: ["transloco", "translocoParams", "translocoScope", "translocoRead", "translocoPrefix", "translocoLang", "translocoLoadingTpl"] }] });
|
|
935
|
+
}
|
|
936
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Users, decorators: [{
|
|
937
|
+
type: Component,
|
|
938
|
+
args: [{ selector: 'mt-users', standalone: true, imports: [CommonModule, SkeletonModule, Table, Avatar, TranslocoDirective], template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div class=\"mt-5\">\r\n <ng-template #typeCol let-row>\r\n <div>{{ row.isExternal ? t(\"external\") : t(\"internal\") }}</div>\r\n </ng-template>\r\n <ng-template #userCol let-row>\r\n <div class=\"flex items-center gap-2\">\r\n <mt-avatar [icon]=\"'custom.user-pp'\"> </mt-avatar> {{ row.displayName }}\r\n </div>\r\n </ng-template>\r\n\r\n <mt-table\r\n [tabs]=\"tabs()\"\r\n [(activeTab)]=\"activeTab\"\r\n [data]=\"users()\"\r\n [columns]=\"tableColumns()\"\r\n [actions]=\"tableActions()\"\r\n [rowActions]=\"rowActions()\"\r\n [generalSearch]=\"true\"\r\n [showFilters]=\"true\"\r\n [loading]=\"loading()\"\r\n >\r\n </mt-table>\r\n </div>\r\n</ng-container>\r\n" }]
|
|
939
|
+
}], propDecorators: { typeCol: [{ type: i0.ViewChild, args: ['typeCol', { isSignal: true }] }], userCol: [{ type: i0.ViewChild, args: ['userCol', { isSignal: true }] }] } });
|
|
940
|
+
|
|
941
|
+
class GroupForm {
|
|
942
|
+
modal = inject(ModalService);
|
|
943
|
+
ref = inject(ModalRef);
|
|
944
|
+
groupForEdit = input(null, ...(ngDevMode ? [{ debugName: "groupForEdit" }] : []));
|
|
945
|
+
translocoService = inject(TranslocoService);
|
|
946
|
+
facade = inject(UsersGroupsFacade);
|
|
947
|
+
selectedGroup = this.facade.selectedGroup;
|
|
948
|
+
groupFormControl = new FormControl();
|
|
949
|
+
getGroupFormLoading = this.facade.isLoadingGroup;
|
|
950
|
+
createUpdateGroupLoading = this.facade.isSavingGroup;
|
|
951
|
+
addUserToGroupLoading = this.facade.isAddingUserToGroup;
|
|
952
|
+
deleteUserFromGroupLoading = this.facade.isDeletingUserFromGroup;
|
|
953
|
+
internalUserFormControl = new FormControl();
|
|
954
|
+
userCol = viewChild.required('userCol');
|
|
955
|
+
isUserExistInMembers = signal(false, ...(ngDevMode ? [{ debugName: "isUserExistInMembers" }] : []));
|
|
956
|
+
context = new HttpContext().set(REQUEST_CONTEXT, {
|
|
957
|
+
useBaseUrl: true,
|
|
958
|
+
});
|
|
959
|
+
groupFormConfig = signal({
|
|
960
|
+
sections: [
|
|
961
|
+
{
|
|
962
|
+
key: 'groupFormConfig',
|
|
963
|
+
type: 'header',
|
|
964
|
+
order: 1,
|
|
965
|
+
fields: [
|
|
966
|
+
{
|
|
967
|
+
key: 'name.en',
|
|
968
|
+
label: this.translocoService.translate('users-groups.group-name-en'),
|
|
969
|
+
placeholder: this.translocoService.translate('users-groups.group-name-en'),
|
|
970
|
+
validators: [ValidatorConfig.required()],
|
|
971
|
+
order: 1,
|
|
972
|
+
},
|
|
973
|
+
{
|
|
974
|
+
key: 'name.ar',
|
|
975
|
+
label: this.translocoService.translate('users-groups.group-name-ar'),
|
|
976
|
+
placeholder: this.translocoService.translate('users-groups.group-name-ar'),
|
|
977
|
+
validators: [ValidatorConfig.required()],
|
|
978
|
+
order: 1,
|
|
979
|
+
},
|
|
980
|
+
new TextareaFieldConfig({
|
|
981
|
+
key: 'description',
|
|
982
|
+
label: this.translocoService.translate('users-groups.description'),
|
|
983
|
+
placeholder: this.translocoService.translate('users-groups.description'),
|
|
984
|
+
order: 3,
|
|
985
|
+
}),
|
|
986
|
+
],
|
|
987
|
+
},
|
|
988
|
+
],
|
|
989
|
+
}, ...(ngDevMode ? [{ debugName: "groupFormConfig" }] : []));
|
|
990
|
+
usersLoading = signal(false, ...(ngDevMode ? [{ debugName: "usersLoading" }] : []));
|
|
991
|
+
internalUserFormConfig = signal({
|
|
992
|
+
sections: [
|
|
993
|
+
{
|
|
994
|
+
key: 'internalUserFormConfig',
|
|
995
|
+
type: 'header',
|
|
996
|
+
order: 1,
|
|
997
|
+
fields: [
|
|
998
|
+
new UserSearchFieldConfig({
|
|
999
|
+
key: 'userField',
|
|
1000
|
+
label: this.translocoService.translate('users-groups.user-name'),
|
|
1001
|
+
apiUrl: 'identity/users',
|
|
1002
|
+
context: this.context,
|
|
1003
|
+
order: 1,
|
|
1004
|
+
}),
|
|
1005
|
+
],
|
|
1006
|
+
},
|
|
1007
|
+
],
|
|
1008
|
+
}, ...(ngDevMode ? [{ debugName: "internalUserFormConfig" }] : []));
|
|
1009
|
+
tableColumns = linkedSignal(() => [
|
|
1010
|
+
{
|
|
1011
|
+
key: 'displayName',
|
|
1012
|
+
label: this.translocoService.translate('users-groups.user'),
|
|
1013
|
+
type: 'custom',
|
|
1014
|
+
customCellTpl: this.userCol(),
|
|
1015
|
+
},
|
|
1016
|
+
], ...(ngDevMode ? [{ debugName: "tableColumns" }] : []));
|
|
1017
|
+
deletingRowIds = signal([], ...(ngDevMode ? [{ debugName: "deletingRowIds" }] : []));
|
|
1018
|
+
rowActions = signal([
|
|
1019
|
+
{
|
|
1020
|
+
icon: 'general.trash-01',
|
|
1021
|
+
tooltip: this.translocoService.translate('delete'),
|
|
1022
|
+
color: 'danger',
|
|
1023
|
+
variant: 'outlined',
|
|
1024
|
+
action: (row) => {
|
|
1025
|
+
this.deletingRowIds.update((ids) => [...ids, row?.user?.userName]);
|
|
1026
|
+
this.facade
|
|
1027
|
+
.deleteUserFromGroup({
|
|
1028
|
+
userName: row?.user?.userName,
|
|
1029
|
+
groupId: this.groupForEdit()?.id,
|
|
1030
|
+
})
|
|
1031
|
+
.pipe(finalize(() => {
|
|
1032
|
+
this.deletingRowIds.update((ids) => ids.filter((id) => id !== row?.user?.userName));
|
|
1033
|
+
}))
|
|
1034
|
+
.subscribe();
|
|
1035
|
+
},
|
|
1036
|
+
confirmation: {
|
|
1037
|
+
type: 'popup',
|
|
1038
|
+
confirmationType: 'delete',
|
|
1039
|
+
},
|
|
1040
|
+
loading: (row) => this.deletingRowIds().includes(row?.user?.userName),
|
|
1041
|
+
},
|
|
1042
|
+
], ...(ngDevMode ? [{ debugName: "rowActions" }] : []));
|
|
1043
|
+
constructor() {
|
|
1044
|
+
// effect(() => {
|
|
1045
|
+
// const groupId = this.groupForEdit()?.id;
|
|
1046
|
+
// if (this.selectedGroup() && groupId) {
|
|
1047
|
+
// this.groupFormControl.patchValue(this.selectedGroup());
|
|
1048
|
+
// }
|
|
1049
|
+
// });
|
|
1050
|
+
}
|
|
1051
|
+
ngOnInit() {
|
|
1052
|
+
if (this.groupForEdit()?.id) {
|
|
1053
|
+
this.facade.getGroup(this.groupForEdit()?.id || null).subscribe((_) => {
|
|
1054
|
+
if (this.selectedGroup()) {
|
|
1055
|
+
this.groupFormControl.patchValue(this.selectedGroup());
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
this.internalUserFormControl.valueChanges.subscribe((value) => {
|
|
1060
|
+
const isUserExistInMembers = this.selectedGroup()?.members?.find((member) => member?.user?.userId === value?.userField?.userId);
|
|
1061
|
+
this.isUserExistInMembers.set(isUserExistInMembers);
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
onSubmit() {
|
|
1065
|
+
if (this.groupForEdit()?.id) {
|
|
1066
|
+
const payload = {
|
|
1067
|
+
name: this.groupFormControl.value?.name,
|
|
1068
|
+
workspace: this.groupFormControl.value?.workspace,
|
|
1069
|
+
description: this.groupFormControl.value?.description,
|
|
1070
|
+
};
|
|
1071
|
+
this.facade.updateGroup(this.groupForEdit()?.id, payload).subscribe({
|
|
1072
|
+
next: () => {
|
|
1073
|
+
this.ref.close(true);
|
|
1074
|
+
},
|
|
1075
|
+
error: () => { },
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
else {
|
|
1079
|
+
const payload = {
|
|
1080
|
+
name: this.groupFormControl.value?.name,
|
|
1081
|
+
workspace: this.groupFormControl.value?.workspace,
|
|
1082
|
+
description: this.groupFormControl.value?.description,
|
|
1083
|
+
};
|
|
1084
|
+
this.facade.createGroup(payload).subscribe({
|
|
1085
|
+
next: () => {
|
|
1086
|
+
this.ref.close(true);
|
|
1087
|
+
},
|
|
1088
|
+
error: () => { },
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
onAddUser() {
|
|
1093
|
+
if (this.internalUserFormControl.value.userField.userId &&
|
|
1094
|
+
!this.isUserExistInMembers()) {
|
|
1095
|
+
this.facade
|
|
1096
|
+
.addUserToGroup(this.internalUserFormControl.value.userField.userName, this.groupForEdit()?.id)
|
|
1097
|
+
.subscribe((_) => {
|
|
1098
|
+
this.internalUserFormControl.setValue({ userField: null });
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: GroupForm, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1103
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: GroupForm, isStandalone: true, selector: "mt-group-form", inputs: { groupForEdit: { classPropertyName: "groupForEdit", publicName: "groupForEdit", isSignal: true, isRequired: false, transformFunction: null } }, providers: [DialogService], viewQueries: [{ propertyName: "userCol", first: true, predicate: ["userCol"], descendants: true, isSignal: true }], ngImport: i0, template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div [class]=\"'flex flex-col gap-1 p-4 ' + modal.contentClass\">\r\n @if (!getGroupFormLoading()) {\r\n <form class=\"col-span-1\">\r\n <mt-dynamic-form\r\n [formConfig]=\"groupFormConfig()\"\r\n [formControl]=\"groupFormControl\"\r\n />\r\n </form>\r\n\r\n @if (groupForEdit()) {\r\n <div class=\"flex gap-3 items-end mt-6 pt-4 border-t-1 border-surface\">\r\n <mt-dynamic-form\r\n class=\"flex-1\"\r\n [formConfig]=\"internalUserFormConfig()\"\r\n [formControl]=\"internalUserFormControl\"\r\n />\r\n <mt-button\r\n icon=\"general.plus\"\r\n class=\"mb-0\"\r\n variant=\"outlined\"\r\n (click)=\"onAddUser()\"\r\n [disabled]=\"\r\n addUserToGroupLoading() ||\r\n isUserExistInMembers() ||\r\n !internalUserFormControl.value?.userField\r\n \"\r\n />\r\n </div>\r\n\r\n <mt-table\r\n [data]=\"selectedGroup()?.members || []\"\r\n [columns]=\"tableColumns()\"\r\n [rowActions]=\"rowActions()\"\r\n [generalSearch]=\"false\"\r\n [showFilters]=\"false\"\r\n [loading]=\"addUserToGroupLoading()\"\r\n >\r\n </mt-table>\r\n <ng-template #userCol let-row>\r\n <div class=\"flex items-center gap-2\">\r\n <mt-avatar [icon]=\"'custom.user-pp'\"> </mt-avatar>\r\n {{ row?.user?.displayName }}\r\n </div>\r\n </ng-template>\r\n }\r\n } @else {\r\n <p-skeleton class=\"my-4 mt-7\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n }\r\n </div>\r\n\r\n <div [class]=\"modal.footerClass\">\r\n <mt-button\r\n [label]=\"selectedGroup() ? ('save' | transloco) : ('add' | transloco)\"\r\n (click)=\"onSubmit()\"\r\n [loading]=\"createUpdateGroupLoading()\"\r\n [disabled]=\"!this.groupFormControl.valid\"\r\n />\r\n </div>\r\n</ng-container>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "directive", type: TranslocoDirective, selector: "[transloco]", inputs: ["transloco", "translocoParams", "translocoScope", "translocoRead", "translocoPrefix", "translocoLang", "translocoLoadingTpl"] }, { kind: "ngmodule", type: SkeletonModule }, { kind: "component", type: i1.Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "component", type: DynamicForm, selector: "mt-dynamic-form", inputs: ["formConfig"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: Avatar, selector: "mt-avatar", inputs: ["label", "icon", "image", "styleClass", "size", "shape", "badge", "badgeSize", "badgeSeverity"], outputs: ["onImageError"] }, { kind: "component", type: Table, selector: "mt-table", inputs: ["filters", "data", "columns", "rowActions", "size", "showGridlines", "stripedRows", "selectableRows", "generalSearch", "showFilters", "loading", "updating", "lazy", "lazyTotalRecords", "reorderableColumns", "reorderableRows", "dataKey", "exportable", "exportFilename", "tabs", "tabsOptionLabel", "tabsOptionValue", "activeTab", "actions", "paginatorPosition", "pageSize", "currentPage", "first", "filterTerm"], outputs: ["selectionChange", "cellChange", "lazyLoad", "columnReorder", "rowReorder", "filtersChange", "activeTabChange", "onTabChange", "pageSizeChange", "currentPageChange", "firstChange", "filterTermChange"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }] });
|
|
1104
|
+
}
|
|
1105
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: GroupForm, decorators: [{
|
|
1106
|
+
type: Component,
|
|
1107
|
+
args: [{ selector: 'mt-group-form', standalone: true, imports: [
|
|
1108
|
+
CommonModule,
|
|
1109
|
+
Button,
|
|
1110
|
+
TranslocoDirective,
|
|
1111
|
+
SkeletonModule,
|
|
1112
|
+
DynamicForm,
|
|
1113
|
+
ReactiveFormsModule,
|
|
1114
|
+
TranslocoPipe,
|
|
1115
|
+
Avatar,
|
|
1116
|
+
Table,
|
|
1117
|
+
], providers: [DialogService], template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div [class]=\"'flex flex-col gap-1 p-4 ' + modal.contentClass\">\r\n @if (!getGroupFormLoading()) {\r\n <form class=\"col-span-1\">\r\n <mt-dynamic-form\r\n [formConfig]=\"groupFormConfig()\"\r\n [formControl]=\"groupFormControl\"\r\n />\r\n </form>\r\n\r\n @if (groupForEdit()) {\r\n <div class=\"flex gap-3 items-end mt-6 pt-4 border-t-1 border-surface\">\r\n <mt-dynamic-form\r\n class=\"flex-1\"\r\n [formConfig]=\"internalUserFormConfig()\"\r\n [formControl]=\"internalUserFormControl\"\r\n />\r\n <mt-button\r\n icon=\"general.plus\"\r\n class=\"mb-0\"\r\n variant=\"outlined\"\r\n (click)=\"onAddUser()\"\r\n [disabled]=\"\r\n addUserToGroupLoading() ||\r\n isUserExistInMembers() ||\r\n !internalUserFormControl.value?.userField\r\n \"\r\n />\r\n </div>\r\n\r\n <mt-table\r\n [data]=\"selectedGroup()?.members || []\"\r\n [columns]=\"tableColumns()\"\r\n [rowActions]=\"rowActions()\"\r\n [generalSearch]=\"false\"\r\n [showFilters]=\"false\"\r\n [loading]=\"addUserToGroupLoading()\"\r\n >\r\n </mt-table>\r\n <ng-template #userCol let-row>\r\n <div class=\"flex items-center gap-2\">\r\n <mt-avatar [icon]=\"'custom.user-pp'\"> </mt-avatar>\r\n {{ row?.user?.displayName }}\r\n </div>\r\n </ng-template>\r\n }\r\n } @else {\r\n <p-skeleton class=\"my-4 mt-7\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n <p-skeleton class=\"my-4\" height=\"3rem\" />\r\n }\r\n </div>\r\n\r\n <div [class]=\"modal.footerClass\">\r\n <mt-button\r\n [label]=\"selectedGroup() ? ('save' | transloco) : ('add' | transloco)\"\r\n (click)=\"onSubmit()\"\r\n [loading]=\"createUpdateGroupLoading()\"\r\n [disabled]=\"!this.groupFormControl.valid\"\r\n />\r\n </div>\r\n</ng-container>\r\n" }]
|
|
1118
|
+
}], ctorParameters: () => [], propDecorators: { groupForEdit: [{ type: i0.Input, args: [{ isSignal: true, alias: "groupForEdit", required: false }] }], userCol: [{ type: i0.ViewChild, args: ['userCol', { isSignal: true }] }] } });
|
|
1119
|
+
|
|
1120
|
+
class Groups {
|
|
1121
|
+
workspaceCol = viewChild.required('workspaceCol');
|
|
1122
|
+
groupCol = viewChild.required('groupCol');
|
|
1123
|
+
facade = inject(UsersGroupsFacade);
|
|
1124
|
+
modal = inject(ModalService);
|
|
1125
|
+
translocoService = inject(TranslocoService);
|
|
1126
|
+
activeTab = signal('all', ...(ngDevMode ? [{ debugName: "activeTab" }] : []));
|
|
1127
|
+
tableActions = signal([
|
|
1128
|
+
{
|
|
1129
|
+
icon: 'general.plus',
|
|
1130
|
+
label: this.translocoService.translate('users-groups.add-group'),
|
|
1131
|
+
color: 'primary',
|
|
1132
|
+
action: () => {
|
|
1133
|
+
this.addGroupDialog();
|
|
1134
|
+
},
|
|
1135
|
+
},
|
|
1136
|
+
], ...(ngDevMode ? [{ debugName: "tableActions" }] : []));
|
|
1137
|
+
deletingRowIds = signal([], ...(ngDevMode ? [{ debugName: "deletingRowIds" }] : []));
|
|
1138
|
+
rowActions = signal([
|
|
1139
|
+
{
|
|
1140
|
+
icon: 'custom.pencil',
|
|
1141
|
+
tooltip: this.translocoService.translate('edit'),
|
|
1142
|
+
color: 'primary',
|
|
1143
|
+
action: (row) => {
|
|
1144
|
+
this.facade.clearSelectedGroup();
|
|
1145
|
+
this.addGroupDialog(row);
|
|
1146
|
+
},
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
icon: 'general.trash-01',
|
|
1150
|
+
tooltip: this.translocoService.translate('delete'),
|
|
1151
|
+
color: 'danger',
|
|
1152
|
+
variant: 'outlined',
|
|
1153
|
+
action: (row) => {
|
|
1154
|
+
this.deletingRowIds.update((ids) => [...ids, row.id]);
|
|
1155
|
+
this.facade
|
|
1156
|
+
.deleteGroup(row.id)
|
|
1157
|
+
.pipe(finalize(() => {
|
|
1158
|
+
this.deletingRowIds.update((ids) => ids.filter((id) => id !== row.id));
|
|
1159
|
+
}))
|
|
1160
|
+
.subscribe();
|
|
1161
|
+
},
|
|
1162
|
+
confirmation: {
|
|
1163
|
+
type: 'popup',
|
|
1164
|
+
confirmationType: 'delete',
|
|
1165
|
+
},
|
|
1166
|
+
loading: (row) => this.deletingRowIds().includes(row.id),
|
|
1167
|
+
},
|
|
1168
|
+
], ...(ngDevMode ? [{ debugName: "rowActions" }] : []));
|
|
1169
|
+
tableColumns = linkedSignal(() => [
|
|
1170
|
+
{
|
|
1171
|
+
key: 'name',
|
|
1172
|
+
label: this.translocoService.translate('users-groups.group'),
|
|
1173
|
+
type: 'custom',
|
|
1174
|
+
customCellTpl: this.groupCol(),
|
|
1175
|
+
filterConfig: {
|
|
1176
|
+
type: 'text',
|
|
1177
|
+
label: this.translocoService.translate('users-groups.group'),
|
|
1178
|
+
},
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
key: 'membersCount',
|
|
1182
|
+
label: this.translocoService.translate('users-groups.users'),
|
|
1183
|
+
},
|
|
1184
|
+
], ...(ngDevMode ? [{ debugName: "tableColumns" }] : []));
|
|
1185
|
+
loading = this.facade.isLoadingGroups;
|
|
1186
|
+
allGroups = this.facade.groups;
|
|
1187
|
+
ngOnInit() {
|
|
1188
|
+
this.facade.getGroups();
|
|
1189
|
+
}
|
|
1190
|
+
addGroupDialog(group = null) {
|
|
1191
|
+
const modalType = group ? 'drawer' : 'dialog';
|
|
1192
|
+
this.modal.openModal(GroupForm, modalType, {
|
|
1193
|
+
header: group
|
|
1194
|
+
? this.translocoService.translate('users-groups.edit-group')
|
|
1195
|
+
: this.translocoService.translate('users-groups.add-group'),
|
|
1196
|
+
styleClass: '!w-[35rem] !absolute !shadow-none',
|
|
1197
|
+
position: modalType === 'drawer' ? 'end' : '',
|
|
1198
|
+
appendTo: modalType === 'drawer' ? 'page-content' : 'body',
|
|
1199
|
+
dismissableMask: true,
|
|
1200
|
+
dismissible: true,
|
|
1201
|
+
inputValues: {
|
|
1202
|
+
groupForEdit: group,
|
|
1203
|
+
},
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Groups, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1207
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.0.3", type: Groups, isStandalone: true, selector: "mt-groups", viewQueries: [{ propertyName: "workspaceCol", first: true, predicate: ["workspaceCol"], descendants: true, isSignal: true }, { propertyName: "groupCol", first: true, predicate: ["groupCol"], descendants: true, isSignal: true }], ngImport: i0, template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div class=\"mt-5\">\r\n <ng-template #workspaceCol let-row>\r\n <div>{{ row.workspace }}</div>\r\n </ng-template>\r\n <ng-template #groupCol let-row>\r\n <div class=\"flex items-center gap-2\">{{ row.name }}</div>\r\n </ng-template>\r\n\r\n <mt-table\r\n [(activeTab)]=\"activeTab\"\r\n [data]=\"allGroups()\"\r\n [columns]=\"tableColumns()\"\r\n [actions]=\"tableActions()\"\r\n [rowActions]=\"rowActions()\"\r\n [generalSearch]=\"true\"\r\n [showFilters]=\"true\"\r\n [loading]=\"loading()\"\r\n >\r\n </mt-table>\r\n </div>\r\n</ng-container>\r\n", styles: [".groups{padding:2rem}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: SkeletonModule }, { kind: "component", type: Table, selector: "mt-table", inputs: ["filters", "data", "columns", "rowActions", "size", "showGridlines", "stripedRows", "selectableRows", "generalSearch", "showFilters", "loading", "updating", "lazy", "lazyTotalRecords", "reorderableColumns", "reorderableRows", "dataKey", "exportable", "exportFilename", "tabs", "tabsOptionLabel", "tabsOptionValue", "activeTab", "actions", "paginatorPosition", "pageSize", "currentPage", "first", "filterTerm"], outputs: ["selectionChange", "cellChange", "lazyLoad", "columnReorder", "rowReorder", "filtersChange", "activeTabChange", "onTabChange", "pageSizeChange", "currentPageChange", "firstChange", "filterTermChange"] }, { kind: "directive", type: TranslocoDirective, selector: "[transloco]", inputs: ["transloco", "translocoParams", "translocoScope", "translocoRead", "translocoPrefix", "translocoLang", "translocoLoadingTpl"] }] });
|
|
1208
|
+
}
|
|
1209
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: Groups, decorators: [{
|
|
1210
|
+
type: Component,
|
|
1211
|
+
args: [{ selector: 'mt-groups', standalone: true, imports: [CommonModule, SkeletonModule, Table, TranslocoDirective], template: "<ng-container *transloco=\"let t; prefix: 'users-groups'\">\r\n <div class=\"mt-5\">\r\n <ng-template #workspaceCol let-row>\r\n <div>{{ row.workspace }}</div>\r\n </ng-template>\r\n <ng-template #groupCol let-row>\r\n <div class=\"flex items-center gap-2\">{{ row.name }}</div>\r\n </ng-template>\r\n\r\n <mt-table\r\n [(activeTab)]=\"activeTab\"\r\n [data]=\"allGroups()\"\r\n [columns]=\"tableColumns()\"\r\n [actions]=\"tableActions()\"\r\n [rowActions]=\"rowActions()\"\r\n [generalSearch]=\"true\"\r\n [showFilters]=\"true\"\r\n [loading]=\"loading()\"\r\n >\r\n </mt-table>\r\n </div>\r\n</ng-container>\r\n", styles: [".groups{padding:2rem}\n"] }]
|
|
1212
|
+
}], propDecorators: { workspaceCol: [{ type: i0.ViewChild, args: ['workspaceCol', { isSignal: true }] }], groupCol: [{ type: i0.ViewChild, args: ['groupCol', { isSignal: true }] }] } });
|
|
1213
|
+
|
|
1214
|
+
// store/index.ts
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Generated bundle index. Do not edit.
|
|
1218
|
+
*/
|
|
1219
|
+
|
|
1220
|
+
export { AddUserToGroup, ClearSelectedGroup, CreateGroup, CreateUser, DeleteGroup, DeleteUser, DeleteUserFromGroup, GetGroup, GetGroups, GetUser, GetUsers, GroupForm, Groups, UpdateGroup, UpdateUser, UserForm, Users, UsersGroups, UsersGroupsActionKey, UsersGroupsFacade, UsersGroupsState };
|
|
1221
|
+
//# sourceMappingURL=masterteam-users-groups.mjs.map
|