@wawjs/ngx-bos 22.0.5 → 22.0.7

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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/RELEASES.md +38 -0
  3. package/ai/code-style.md +15 -0
  4. package/fesm2022/file.service-C8Erkqrm.mjs +48 -0
  5. package/fesm2022/file.service-C8Erkqrm.mjs.map +1 -0
  6. package/fesm2022/{wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs → ngx-bos.config-DjtgUjR8.mjs} +3 -5
  7. package/fesm2022/ngx-bos.config-DjtgUjR8.mjs.map +1 -0
  8. package/fesm2022/user-crud.component-B1_SlIDS.mjs +317 -0
  9. package/fesm2022/user-crud.component-B1_SlIDS.mjs.map +1 -0
  10. package/fesm2022/wawjs-ngx-bos.mjs +206 -187
  11. package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
  12. package/package.json +11 -9
  13. package/src/feature/file/file.component.html +1 -0
  14. package/src/feature/file/file.component.ts +265 -239
  15. package/src/feature/file/file.service.ts +36 -36
  16. package/src/feature/file/file.util.ts +9 -2
  17. package/src/feature/file/pages/files/files.component.html +12 -12
  18. package/src/feature/file/pages/files/files.component.ts +116 -116
  19. package/src/feature/user/guards/admins.guard.ts +21 -21
  20. package/src/feature/user/guards/authenticated.guard.ts +15 -15
  21. package/src/feature/user/guards/guest.guard.ts +15 -15
  22. package/src/feature/user/pages/clients/clients.component.ts +19 -45
  23. package/src/feature/user/pages/user-crud.component.ts +119 -0
  24. package/src/feature/user/pages/users/users.component.ts +33 -86
  25. package/src/feature/user/user.service.ts +120 -21
  26. package/src/feature/user/user.storage.ts +31 -31
  27. package/src/form-components/ace/ace.component.ts +15 -1
  28. package/src/form-components/file/file.component.html +2 -2
  29. package/src/form-components/form-config-cache.ts +70 -0
  30. package/src/form-components/input/input.form.ts +1 -1
  31. package/src/form-components/select/select.component.html +24 -24
  32. package/src/form-components/tinymce/tinymce.component.ts +12 -0
  33. package/src/icons/spider/spider.component.ts +4 -4
  34. package/src/ngx-bos.config.ts +7 -5
  35. package/src/pages/form/form.component.ts +137 -100
  36. package/src/pages/forms/forms.component.ts +14 -2
  37. package/src/public-api.ts +1 -1
  38. package/types/wawjs-ngx-bos.d.ts +52 -15
  39. package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +0 -1
  40. package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs +0 -181
  41. package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs.map +0 -1
@@ -1,116 +1,116 @@
1
- import { Clipboard } from '@angular/cdk/clipboard';
2
- import { Component, inject, signal } from '@angular/core';
3
- import { AlertService, CellDirective, TableComponent } from '@wawjs/ngx-ui';
4
- import { FormInterface, FormService } from '@wawjs/ngx-form';
5
- import { CoreService } from '@wawjs/ngx-core';
6
- import { File, FileService } from '../..';
7
-
8
- const fileFormComponents = {
9
- title: 'File',
10
- components: [
11
- {
12
- name: 'Input',
13
- key: 'url',
14
- props: {
15
- label: 'URL',
16
- placeholder: 'Enter file URL...',
17
- },
18
- },
19
- {
20
- name: 'Input',
21
- key: 'name',
22
- props: {
23
- label: 'Name',
24
- placeholder: 'Enter name...',
25
- },
26
- },
27
- {
28
- name: 'Input',
29
- key: 'description',
30
- props: {
31
- label: 'Description',
32
- placeholder: 'Enter description...',
33
- type: 'textarea',
34
- },
35
- },
36
- ],
37
- } as FormInterface;
38
-
39
- @Component({
40
- templateUrl: './files.component.html',
41
- imports: [TableComponent, CellDirective],
42
- })
43
- export class FilesComponent {
44
- private _fileService = inject(FileService);
45
- private _clipboard = inject(Clipboard);
46
- private _alert = inject(AlertService);
47
- private _form = inject(FormService);
48
- private _core = inject(CoreService);
49
-
50
- columns = ['img', 'url'];
51
-
52
- form = fileFormComponents;
53
-
54
- config = {
55
- paginate: this.setRows.bind(this),
56
- perPage: 20,
57
- setPerPage: this._fileService.setPerPage.bind(this._fileService),
58
- allDocs: false,
59
- create: (): void => {
60
- this._form.modal<File>(this.form, {
61
- label: 'Create',
62
- click: async (created: unknown, close: () => void) => {
63
- close();
64
- this._preCreate(created as File);
65
- this._fileService.create(created as File);
66
- this.setRows();
67
- },
68
- });
69
- },
70
- delete: (doc: File): void => {
71
- this._alert.question({
72
- text: 'Are you sure you want to delete this file?',
73
- buttons: [
74
- { text: 'No' },
75
- {
76
- text: 'Yes',
77
- callback: async (): Promise<void> => {
78
- this._fileService.delete(doc);
79
- this.setRows();
80
- },
81
- },
82
- ],
83
- });
84
- },
85
- };
86
-
87
- readonly rows = signal<File[]>([]);
88
-
89
- constructor() {
90
- this.setRows();
91
- }
92
-
93
- copy(text: string): void {
94
- this._clipboard.copy(text);
95
- this._alert.info({ text: 'Url has been copied' });
96
- }
97
-
98
- setRows(page = this._page): void {
99
- this._page = page;
100
- this._core.afterWhile(
101
- this,
102
- () => {
103
- this._fileService.get({ page }).subscribe((rows) => {
104
- this.rows.set([...rows]);
105
- });
106
- },
107
- 250,
108
- );
109
- }
110
-
111
- private _page = 1;
112
-
113
- private _preCreate(file: File): void {
114
- delete (file as any).__created;
115
- }
116
- }
1
+ import { Clipboard } from '@angular/cdk/clipboard';
2
+ import { Component, inject, signal } from '@angular/core';
3
+ import { AlertService, CellDirective, TableComponent } from '@wawjs/ngx-ui';
4
+ import { FormInterface, FormService } from '@wawjs/ngx-form';
5
+ import { CoreService } from '@wawjs/ngx-core';
6
+ import { File, FileService } from '../..';
7
+
8
+ const fileFormComponents = {
9
+ title: 'File',
10
+ components: [
11
+ {
12
+ name: 'Input',
13
+ key: 'url',
14
+ props: {
15
+ label: 'URL',
16
+ placeholder: 'Enter file URL...',
17
+ },
18
+ },
19
+ {
20
+ name: 'Input',
21
+ key: 'name',
22
+ props: {
23
+ label: 'Name',
24
+ placeholder: 'Enter name...',
25
+ },
26
+ },
27
+ {
28
+ name: 'Input',
29
+ key: 'description',
30
+ props: {
31
+ label: 'Description',
32
+ placeholder: 'Enter description...',
33
+ type: 'textarea',
34
+ },
35
+ },
36
+ ],
37
+ } as FormInterface;
38
+
39
+ @Component({
40
+ templateUrl: './files.component.html',
41
+ imports: [TableComponent, CellDirective],
42
+ })
43
+ export class FilesComponent {
44
+ private _fileService = inject(FileService);
45
+ private _clipboard = inject(Clipboard);
46
+ private _alert = inject(AlertService);
47
+ private _form = inject(FormService);
48
+ private _core = inject(CoreService);
49
+
50
+ columns = ['img', 'url'];
51
+
52
+ form = fileFormComponents;
53
+
54
+ config = {
55
+ paginate: this.setRows.bind(this),
56
+ perPage: 20,
57
+ setPerPage: this._fileService.setPerPage.bind(this._fileService),
58
+ allDocs: false,
59
+ create: (): void => {
60
+ this._form.modal<File>(this.form, {
61
+ label: 'Create',
62
+ click: async (created: unknown, close: () => void) => {
63
+ close();
64
+ this._preCreate(created as File);
65
+ this._fileService.create(created as File);
66
+ this.setRows();
67
+ },
68
+ });
69
+ },
70
+ delete: (doc: File): void => {
71
+ this._alert.question({
72
+ text: 'Are you sure you want to delete this file?',
73
+ buttons: [
74
+ { text: 'No' },
75
+ {
76
+ text: 'Yes',
77
+ callback: async (): Promise<void> => {
78
+ this._fileService.delete(doc);
79
+ this.setRows();
80
+ },
81
+ },
82
+ ],
83
+ });
84
+ },
85
+ };
86
+
87
+ readonly rows = signal<File[]>([]);
88
+
89
+ constructor() {
90
+ this.setRows();
91
+ }
92
+
93
+ copy(text: string): void {
94
+ this._clipboard.copy(text);
95
+ this._alert.info({ text: 'Url has been copied' });
96
+ }
97
+
98
+ setRows(page = this._page): void {
99
+ this._page = page;
100
+ this._core.afterWhile(
101
+ this,
102
+ () => {
103
+ this._fileService.get({ page }).subscribe((rows) => {
104
+ this.rows.set([...rows]);
105
+ });
106
+ },
107
+ 250,
108
+ );
109
+ }
110
+
111
+ private _page = 1;
112
+
113
+ private _preCreate(file: File): void {
114
+ delete (file as any).__created;
115
+ }
116
+ }
@@ -1,21 +1,21 @@
1
- import { inject } from '@angular/core';
2
- import { CanActivateFn, Router } from '@angular/router';
3
- import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
- import { readStoredUser } from '../user.storage';
5
-
6
- export const adminsGuard: CanActivateFn = () => {
7
- const router = inject(Router);
8
- const config = inject(NGX_BOS_CONFIG);
9
-
10
- const user = readStoredUser();
11
-
12
- if (!user) {
13
- return router.parseUrl(config.signPath);
14
- }
15
-
16
- if (user.is?.['admin']) {
17
- return true;
18
- }
19
-
20
- return router.parseUrl(config.profilePath);
21
- };
1
+ import { inject } from '@angular/core';
2
+ import { CanActivateFn, Router } from '@angular/router';
3
+ import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
+
6
+ export const adminsGuard: CanActivateFn = () => {
7
+ const router = inject(Router);
8
+ const config = inject(NGX_BOS_CONFIG);
9
+
10
+ const user = readStoredUser();
11
+
12
+ if (!user) {
13
+ return router.parseUrl(config.signPath);
14
+ }
15
+
16
+ if (user.is?.['admin']) {
17
+ return true;
18
+ }
19
+
20
+ return router.parseUrl(config.profilePath);
21
+ };
@@ -1,15 +1,15 @@
1
- import { inject } from '@angular/core';
2
- import { CanActivateFn, Router } from '@angular/router';
3
- import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
- import { readStoredUser } from '../user.storage';
5
-
6
- export const authenticatedGuard: CanActivateFn = () => {
7
- const router = inject(Router);
8
- const config = inject(NGX_BOS_CONFIG);
9
-
10
- if (readStoredUser()) {
11
- return true;
12
- }
13
-
14
- return router.parseUrl(config.signPath);
15
- };
1
+ import { inject } from '@angular/core';
2
+ import { CanActivateFn, Router } from '@angular/router';
3
+ import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
+
6
+ export const authenticatedGuard: CanActivateFn = () => {
7
+ const router = inject(Router);
8
+ const config = inject(NGX_BOS_CONFIG);
9
+
10
+ if (readStoredUser()) {
11
+ return true;
12
+ }
13
+
14
+ return router.parseUrl(config.signPath);
15
+ };
@@ -1,15 +1,15 @@
1
- import { inject } from '@angular/core';
2
- import { CanActivateFn, Router } from '@angular/router';
3
- import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
- import { readStoredUser } from '../user.storage';
5
-
6
- export const guestGuard: CanActivateFn = () => {
7
- const router = inject(Router);
8
- const config = inject(NGX_BOS_CONFIG);
9
-
10
- if (readStoredUser()) {
11
- return router.parseUrl(config.profilePath);
12
- }
13
-
14
- return true;
15
- };
1
+ import { inject } from '@angular/core';
2
+ import { CanActivateFn, Router } from '@angular/router';
3
+ import { NGX_BOS_CONFIG } from '../../../ngx-bos.config';
4
+ import { readStoredUser } from '../user.storage';
5
+
6
+ export const guestGuard: CanActivateFn = () => {
7
+ const router = inject(Router);
8
+ const config = inject(NGX_BOS_CONFIG);
9
+
10
+ if (readStoredUser()) {
11
+ return router.parseUrl(config.profilePath);
12
+ }
13
+
14
+ return true;
15
+ };
@@ -1,45 +1,19 @@
1
- import { Component, inject } from '@angular/core';
2
- import { FormInterface, FormService } from '@wawjs/ngx-form';
3
- import { TableComponent } from '@wawjs/ngx-ui';
4
- import { CrudComponent } from '@wawjs/ngx-crud';
5
- import { userFormComponentsFactory } from '../../user.form';
6
- import { User } from '../../user.interface';
7
- import { UserService } from '../../user.service';
8
-
9
- @Component({
10
- imports: [TableComponent],
11
- templateUrl: './clients.component.html',
12
- styleUrl: './clients.component.scss',
13
- })
14
- export class ClientsComponent extends CrudComponent<
15
- UserService,
16
- User,
17
- FormInterface
18
- > {
19
- /** Use server-side pagination for clients */
20
- protected override configType: 'server' | 'local' = 'server';
21
-
22
- /** Basic columns for clients table */
23
- columns = ['name', 'email'];
24
-
25
- /** wtable config built by CrudComponent, aware of server mode */
26
- config = this.getConfig();
27
-
28
- protected override allowUrl(): boolean {
29
- // no URL-driven filters for now, same as UsersComponent
30
- return false;
31
- }
32
-
33
- constructor() {
34
- // 'user' docType reuses existing user form components
35
- super(
36
- userFormComponentsFactory(),
37
- inject(FormService),
38
- inject(UserService),
39
- 'user',
40
- );
41
-
42
- // fetch first page from server using CrudComponent logic
43
- this.setDocuments();
44
- }
45
- }
1
+ import { Component } from '@angular/core';
2
+ import { TableComponent } from '@wawjs/ngx-ui';
3
+ import { UserCrudComponent } from '../user-crud.component';
4
+
5
+ @Component({
6
+ imports: [TableComponent],
7
+ templateUrl: './clients.component.html',
8
+ styleUrl: './clients.component.scss',
9
+ })
10
+ export class ClientsComponent extends UserCrudComponent {
11
+ /** Basic columns for clients table */
12
+ columns = ['name', 'email'];
13
+
14
+ /**
15
+ * Local mode reads the shared user list. Server mode would replace that list with one page and
16
+ * shrink the Users table and the user selectors until reload.
17
+ */
18
+ config = this.withoutBulkEdit(this.getConfig());
19
+ }
@@ -0,0 +1,119 @@
1
+ import { effect, inject, untracked } from '@angular/core';
2
+ import { CrudComponent, TableConfig } from '@wawjs/ngx-crud';
3
+ import { FormInterface, FormService } from '@wawjs/ngx-form';
4
+ import { AlertService } from '@wawjs/ngx-ui';
5
+ import { userFormComponentsFactory } from '../user.form';
6
+ import { User } from '../user.interface';
7
+ import { UserService } from '../user.service';
8
+
9
+ /**
10
+ * Shared admin behavior for the Users and Clients tables.
11
+ *
12
+ * The backend's unnamed `/api/user/update` always targets the signed-in user, and user delete only
13
+ * exists as the `admin` variant, so every mutation here goes through `updateAdmin` / `deleteAdmin`.
14
+ * Email is not an updatable key on the backend, so the edit form leaves it out.
15
+ */
16
+ export abstract class UserCrudComponent extends CrudComponent<UserService, User, FormInterface> {
17
+ protected readonly userService = inject(UserService);
18
+
19
+ private readonly _userFormService = inject(FormService);
20
+
21
+ private readonly _userAlertService = inject(AlertService);
22
+
23
+ private readonly _createForm = userFormComponentsFactory();
24
+
25
+ private readonly _editForm: FormInterface = {
26
+ ...this._createForm,
27
+ formId: 'user-edit',
28
+ components: this._createForm.components.filter((component) => component.key !== 'email'),
29
+ };
30
+
31
+ protected override configType: 'server' | 'local' = 'local';
32
+
33
+ constructor() {
34
+ super(userFormComponentsFactory(), inject(FormService), inject(UserService), 'user');
35
+
36
+ // The user list arrives after startup; keep the table in sync with it. setDocuments() reads
37
+ // and writes document signals, so it runs untracked to keep the effect from re-dirtying itself.
38
+ effect(() => {
39
+ this.userService.documents();
40
+
41
+ if (this.userService.isLoaded()) {
42
+ untracked(() => void this.setDocuments());
43
+ }
44
+ });
45
+ }
46
+
47
+ protected override allowUrl(): boolean {
48
+ return false;
49
+ }
50
+
51
+ /** Bulk edit would post every row through the self-update route, so only bulk create stays. */
52
+ protected withoutBulkEdit(config: TableConfig<User>): TableConfig<User> {
53
+ return {
54
+ ...config,
55
+ headerButtons: (config.headerButtons || []).filter((button) => button.class !== 'edit'),
56
+ };
57
+ }
58
+
59
+ protected override create(): void {
60
+ if (this._createForm.formId) {
61
+ this._userFormService.reset(this._createForm.formId, this.createObject());
62
+ }
63
+
64
+ super.create();
65
+ }
66
+
67
+ protected override update(doc: User): void {
68
+ this._userFormService.reset(
69
+ this._editForm.formId as string,
70
+ doc as unknown as Record<string, unknown>,
71
+ );
72
+
73
+ this._userFormService.modal(
74
+ this._editForm,
75
+ {
76
+ label: 'Update',
77
+ click: (updated: unknown, close: () => void) => {
78
+ close();
79
+
80
+ const { email: _email, ...changes } = updated as User;
81
+
82
+ // Send a copy; mutating the row would also change the cached document on failure.
83
+ const next: User = { ...doc, ...changes };
84
+
85
+ this.userService.updateAdmin(next).subscribe({
86
+ next: () => {
87
+ void this.setDocuments();
88
+ },
89
+ error: () => {
90
+ void this.setDocuments();
91
+ },
92
+ });
93
+ },
94
+ },
95
+ doc,
96
+ );
97
+ }
98
+
99
+ protected override async delete(doc: User): Promise<void> {
100
+ this._userAlertService.question({
101
+ text: 'Delete this user?',
102
+ timeout: 0,
103
+ progress: false,
104
+ buttons: [
105
+ {
106
+ text: 'Delete',
107
+ callback: () => {
108
+ this.userService.deleteAdmin(doc).subscribe(() => {
109
+ void this.setDocuments();
110
+ });
111
+ },
112
+ },
113
+ {
114
+ text: 'Cancel',
115
+ },
116
+ ],
117
+ });
118
+ }
119
+ }
@@ -1,86 +1,33 @@
1
- import { Component, inject } from '@angular/core';
2
- import { FormInterface, FormService } from '@wawjs/ngx-form';
3
- import { CrudComponent } from '@wawjs/ngx-crud';
4
- import { CellDirective, InputComponent, TableComponent } from '@wawjs/ngx-ui';
5
- import { userFormComponentsFactory } from '../../user.form';
6
- import { User } from '../../user.interface';
7
- import { UserService } from '../../user.service';
8
-
9
- @Component({
10
- imports: [TableComponent, CellDirective, InputComponent],
11
- templateUrl: './users.component.html',
12
- styleUrl: './users.component.scss',
13
- })
14
- export class UsersComponent extends CrudComponent<
15
- UserService,
16
- User,
17
- FormInterface
18
- > {
19
- protected override configType: 'server' | 'local' = 'local';
20
- private readonly _formService = inject(FormService);
21
-
22
- protected override allowUrl(): boolean {
23
- return false;
24
- }
25
-
26
- protected override async delete(doc: User) {
27
- this.userService.deleteAdmin(doc).subscribe(() => {
28
- this.setDocuments();
29
- });
30
- }
31
-
32
- protected override update(doc: User): void {
33
- if (this.form.formId) {
34
- this._formService.reset(
35
- this.form.formId,
36
- doc as unknown as Record<string, unknown>,
37
- );
38
- }
39
-
40
- this._formService.modal(
41
- this.form,
42
- {
43
- label: 'Update',
44
- click: (updated: unknown, close: () => void) => {
45
- close();
46
- Object.assign(doc, updated as User);
47
- this.userService.updateAdmin(doc).subscribe(() => {
48
- this.setDocuments();
49
- });
50
- },
51
- },
52
- doc,
53
- );
54
- }
55
-
56
- userService = inject(UserService);
57
-
58
- /** Every role gets a checkbox column; matches the columns added in the constructor. */
59
- readonly roles = this.userService.roles;
60
-
61
- columns = ['name', 'email'];
62
-
63
- config = this.getConfig();
64
-
65
- constructor() {
66
- super(
67
- userFormComponentsFactory(),
68
- inject(FormService),
69
- inject(UserService),
70
- 'user',
71
- );
72
-
73
- this.setDocuments();
74
-
75
- for (const role of this.userService.roles) {
76
- this.columns.push(role);
77
- }
78
- }
79
-
80
- updateRole(user: User, role: string, value: boolean): void {
81
- user.is[role] = value;
82
- this.userService.updateAdmin(user).subscribe(() => {
83
- this.setDocuments();
84
- });
85
- }
86
- }
1
+ import { Component } from '@angular/core';
2
+ import { CellDirective, InputComponent, TableComponent } from '@wawjs/ngx-ui';
3
+ import { User } from '../../user.interface';
4
+ import { UserCrudComponent } from '../user-crud.component';
5
+
6
+ @Component({
7
+ imports: [TableComponent, CellDirective, InputComponent],
8
+ templateUrl: './users.component.html',
9
+ styleUrl: './users.component.scss',
10
+ })
11
+ export class UsersComponent extends UserCrudComponent {
12
+ /** Every role gets a checkbox column; matches the columns added in the constructor. */
13
+ readonly roles = this.userService.roles;
14
+
15
+ columns = ['name', 'email', ...this.userService.roles];
16
+
17
+ config = this.withoutBulkEdit(this.getConfig());
18
+
19
+ /** Sends a copy: the row shares its `is` object with the cached user document. */
20
+ updateRole(user: User, role: string, value: boolean): void {
21
+ const next: User = { ...user, is: { ...(user.is || {}), [role]: value } };
22
+
23
+ this.userService.updateAdmin(next).subscribe({
24
+ next: () => {
25
+ void this.setDocuments();
26
+ },
27
+ error: () => {
28
+ // The service rolls back a rejected change; refresh so the table shows the real state.
29
+ void this.setDocuments();
30
+ },
31
+ });
32
+ }
33
+ }