@wawjs/ngx-bos 22.0.4 → 22.0.5
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.
- package/AGENTS.md +4 -0
- package/README.md +12 -5
- package/RELEASES.md +15 -0
- package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs +29 -0
- package/fesm2022/wawjs-ngx-bos-ngx-bos.config-B6tWU_X3.mjs.map +1 -0
- package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs +181 -0
- package/fesm2022/wawjs-ngx-bos-user.service-BL0vq7J4.mjs.map +1 -0
- package/fesm2022/wawjs-ngx-bos.mjs +3063 -2293
- package/fesm2022/wawjs-ngx-bos.mjs.map +1 -1
- package/package.json +10 -10
- package/src/feature/file/file.component.ts +239 -236
- package/src/feature/file/file.service.ts +36 -35
- package/src/feature/file/pages/files/files.component.html +12 -12
- package/src/feature/file/pages/files/files.component.ts +116 -117
- package/src/feature/user/guards/admins.guard.ts +21 -28
- package/src/feature/user/guards/authenticated.guard.ts +15 -22
- package/src/feature/user/guards/guest.guard.ts +15 -15
- package/src/feature/user/pages/users/users.component.ts +2 -6
- package/src/feature/user/user.service.ts +7 -22
- package/src/feature/user/user.storage.ts +31 -0
- package/src/pages/form/form.component.ts +100 -86
- package/src/pages/forms/forms.component.ts +9 -22
- package/types/wawjs-ngx-bos.d.ts +402 -305
|
@@ -1,117 +1,116 @@
|
|
|
1
|
-
import { Clipboard } from '@angular/cdk/clipboard';
|
|
2
|
-
import { Component, inject } from '@angular/core';
|
|
3
|
-
import { AlertService, 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],
|
|
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
|
-
rows
|
|
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.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
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,28 +1,21 @@
|
|
|
1
|
-
import { inject
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export const adminsGuard: CanActivateFn = () => {
|
|
7
|
-
const router = inject(Router);
|
|
8
|
-
const config = inject(NGX_BOS_CONFIG);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (user.is && user.is.admin) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return router.parseUrl(config.profilePath);
|
|
28
|
-
};
|
|
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,22 +1,15 @@
|
|
|
1
|
-
import { inject
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export const authenticatedGuard: CanActivateFn = () => {
|
|
7
|
-
const router = inject(Router);
|
|
8
|
-
const config = inject(NGX_BOS_CONFIG);
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (localStorage.getItem('waw_user')) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return router.parseUrl(config.signPath);
|
|
22
|
-
};
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export const guestGuard: CanActivateFn = () => {
|
|
7
|
-
const router = inject(Router);
|
|
8
|
-
const config = inject(NGX_BOS_CONFIG);
|
|
9
|
-
|
|
10
|
-
if (
|
|
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,5 +1,4 @@
|
|
|
1
1
|
import { Component, inject } from '@angular/core';
|
|
2
|
-
import { Router } from '@angular/router';
|
|
3
2
|
import { FormInterface, FormService } from '@wawjs/ngx-form';
|
|
4
3
|
import { CrudComponent } from '@wawjs/ngx-crud';
|
|
5
4
|
import { CellDirective, InputComponent, TableComponent } from '@wawjs/ngx-ui';
|
|
@@ -54,13 +53,10 @@ export class UsersComponent extends CrudComponent<
|
|
|
54
53
|
);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
private _router = inject(Router);
|
|
58
|
-
|
|
59
56
|
userService = inject(UserService);
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
: this.userService.employees;
|
|
58
|
+
/** Every role gets a checkbox column; matches the columns added in the constructor. */
|
|
59
|
+
readonly roles = this.userService.roles;
|
|
64
60
|
|
|
65
61
|
columns = ['name', 'email'];
|
|
66
62
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Service, computed, inject,
|
|
2
|
-
import { isPlatformBrowser } from '@angular/common';
|
|
1
|
+
import { Service, computed, inject, signal } from '@angular/core';
|
|
3
2
|
import { Router } from '@angular/router';
|
|
4
3
|
import { AlertService } from '@wawjs/ngx-ui';
|
|
5
4
|
import { CrudService } from '@wawjs/ngx-crud';
|
|
@@ -7,6 +6,7 @@ import { EmitterService } from '@wawjs/ngx-core';
|
|
|
7
6
|
import { HttpService } from '@wawjs/ngx-http';
|
|
8
7
|
import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
|
|
9
8
|
import { User } from './user.interface';
|
|
9
|
+
import { readStoredUser, USER_STORAGE_KEY } from './user.storage';
|
|
10
10
|
@Service()
|
|
11
11
|
export class UserService extends CrudService<User> {
|
|
12
12
|
private readonly _userHttpService = inject(HttpService);
|
|
@@ -19,8 +19,6 @@ export class UserService extends CrudService<User> {
|
|
|
19
19
|
|
|
20
20
|
private readonly _bosConfig = inject(NGX_BOS_CONFIG);
|
|
21
21
|
|
|
22
|
-
private readonly _isBrowserPlatform = isPlatformBrowser(inject(PLATFORM_ID));
|
|
23
|
-
|
|
24
22
|
readonly url = this._bosConfig.url;
|
|
25
23
|
|
|
26
24
|
roles = this._bosConfig.roles.concat(['admin']);
|
|
@@ -29,13 +27,7 @@ export class UserService extends CrudService<User> {
|
|
|
29
27
|
|
|
30
28
|
readonly users = this.documents;
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
user = signal<User>(
|
|
35
|
-
this._storedUser
|
|
36
|
-
? JSON.parse(this._storedUser)
|
|
37
|
-
: this.prepareDocument()(),
|
|
38
|
-
);
|
|
30
|
+
user = signal<User>(readStoredUser() ?? this.prepareDocument()());
|
|
39
31
|
|
|
40
32
|
thumb = computed(() => {
|
|
41
33
|
const thumb = this.user().thumb;
|
|
@@ -86,18 +78,11 @@ export class UserService extends CrudService<User> {
|
|
|
86
78
|
},
|
|
87
79
|
});
|
|
88
80
|
|
|
89
|
-
if (
|
|
81
|
+
if (localStorage.getItem(USER_STORAGE_KEY)) {
|
|
90
82
|
this.fetch({}, { name: 'me' }).subscribe((user: User) => {
|
|
91
83
|
if (user) {
|
|
92
|
-
if (
|
|
93
|
-
!localStorage.getItem('waw_user') &&
|
|
94
|
-
this._router.url === this._bosConfig.signPath
|
|
95
|
-
) {
|
|
96
|
-
this._router.navigateByUrl(this._bosConfig.profilePath);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
84
|
this.setUser(user);
|
|
100
|
-
} else if (localStorage.getItem(
|
|
85
|
+
} else if (localStorage.getItem(USER_STORAGE_KEY)) {
|
|
101
86
|
this.logout();
|
|
102
87
|
}
|
|
103
88
|
});
|
|
@@ -111,7 +96,7 @@ export class UserService extends CrudService<User> {
|
|
|
111
96
|
setUser(user: User) {
|
|
112
97
|
this.user.set(user);
|
|
113
98
|
|
|
114
|
-
localStorage.setItem(
|
|
99
|
+
localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
|
|
115
100
|
|
|
116
101
|
this._emitterService.complete('us.user');
|
|
117
102
|
}
|
|
@@ -156,7 +141,7 @@ export class UserService extends CrudService<User> {
|
|
|
156
141
|
logout() {
|
|
157
142
|
this.user.set(this.prepareDocument()());
|
|
158
143
|
|
|
159
|
-
localStorage.removeItem(
|
|
144
|
+
localStorage.removeItem(USER_STORAGE_KEY);
|
|
160
145
|
|
|
161
146
|
this._userHttpService.remove('token');
|
|
162
147
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { User } from './user.interface';
|
|
2
|
+
|
|
3
|
+
/** localStorage key holding the signed-in user snapshot. */
|
|
4
|
+
export const USER_STORAGE_KEY = 'waw_user';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads the stored user snapshot. Returns `null` when nothing is stored or when the
|
|
8
|
+
* stored value is corrupted; a corrupted value is removed so it cannot break guards
|
|
9
|
+
* or service initialization again.
|
|
10
|
+
*/
|
|
11
|
+
export function readStoredUser(): User | null {
|
|
12
|
+
const stored = localStorage.getItem(USER_STORAGE_KEY);
|
|
13
|
+
|
|
14
|
+
if (!stored) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const user = JSON.parse(stored) as User | null;
|
|
20
|
+
|
|
21
|
+
if (user && typeof user === 'object') {
|
|
22
|
+
return user;
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
// fall through to cleanup
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
localStorage.removeItem(USER_STORAGE_KEY);
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
@@ -1,86 +1,100 @@
|
|
|
1
|
-
import { Component, effect, inject } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
protected override
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
doc.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
import { Component, computed, effect, inject } from '@angular/core';
|
|
2
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
3
|
+
import { ActivatedRoute } from '@angular/router';
|
|
4
|
+
import { TableComponent } from '@wawjs/ngx-ui';
|
|
5
|
+
import {
|
|
6
|
+
Formcomponent,
|
|
7
|
+
FormcomponentService,
|
|
8
|
+
formcomponentForm,
|
|
9
|
+
FormInterface,
|
|
10
|
+
FormService,
|
|
11
|
+
} from '@wawjs/ngx-form';
|
|
12
|
+
import { CrudComponent } from '@wawjs/ngx-crud';
|
|
13
|
+
import { FORM_COMPONENT_FORM } from '../../form-components';
|
|
14
|
+
import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
|
|
15
|
+
|
|
16
|
+
@Component({
|
|
17
|
+
imports: [TableComponent],
|
|
18
|
+
templateUrl: './form.component.html',
|
|
19
|
+
})
|
|
20
|
+
export class FormComponent extends CrudComponent<
|
|
21
|
+
FormcomponentService,
|
|
22
|
+
Formcomponent,
|
|
23
|
+
FormInterface
|
|
24
|
+
> {
|
|
25
|
+
private _route = inject(ActivatedRoute);
|
|
26
|
+
private _bosConfig = inject(NGX_BOS_CONFIG);
|
|
27
|
+
|
|
28
|
+
private readonly _params = toSignal(this._route.paramMap, {
|
|
29
|
+
initialValue: this._route.snapshot.paramMap,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/** Current `:formId` route param; updates when navigating between forms. */
|
|
33
|
+
readonly formId = computed(() => this._params().get('formId') || '');
|
|
34
|
+
|
|
35
|
+
protected override configType: 'server' | 'local' = 'local';
|
|
36
|
+
|
|
37
|
+
protected override preCreate(doc: Formcomponent) {
|
|
38
|
+
doc.formId = this.formId();
|
|
39
|
+
|
|
40
|
+
doc.appId = this._bosConfig.appId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected override localDocumentsFilter = (doc: Formcomponent) => {
|
|
44
|
+
return doc.formId === this.formId();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
protected override allowUrl() {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Basic columns for clients table */
|
|
52
|
+
columns = ['name', 'key'];
|
|
53
|
+
|
|
54
|
+
/** wtable config built by CrudComponent, aware of server mode */
|
|
55
|
+
config = this.getConfig();
|
|
56
|
+
|
|
57
|
+
constructor() {
|
|
58
|
+
const formcomponentService = inject(FormcomponentService);
|
|
59
|
+
const formService = inject(FormService);
|
|
60
|
+
|
|
61
|
+
super(
|
|
62
|
+
formcomponentForm,
|
|
63
|
+
formService,
|
|
64
|
+
formcomponentService,
|
|
65
|
+
'formcomponent',
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
effect(() => {
|
|
69
|
+
// Re-filter when the route's formId changes (component is reused).
|
|
70
|
+
this.formId();
|
|
71
|
+
|
|
72
|
+
if (formcomponentService.isLoaded()) {
|
|
73
|
+
this.setDocuments();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
this.config.buttons.unshift({
|
|
78
|
+
icon: 'settings',
|
|
79
|
+
click: (doc: Formcomponent) => {
|
|
80
|
+
formService.modal<Record<string, unknown>>(
|
|
81
|
+
FORM_COMPONENT_FORM(doc.name),
|
|
82
|
+
{
|
|
83
|
+
label: 'Update',
|
|
84
|
+
click: async (updated: unknown, close: () => void) => {
|
|
85
|
+
close();
|
|
86
|
+
|
|
87
|
+
doc.props = {
|
|
88
|
+
...doc.props,
|
|
89
|
+
...(updated as object),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
formcomponentService.update(doc);
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
doc.props || {},
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|