@wawjs/ngx-bos 22.0.5 → 22.0.6

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.
@@ -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
+ };
@@ -143,15 +143,27 @@ export class UserService extends CrudService<User> {
143
143
 
144
144
  localStorage.removeItem(USER_STORAGE_KEY);
145
145
 
146
- this._userHttpService.remove('token');
146
+ // Reload only after the server has cleared the session cookie: reloading right away can
147
+ // cancel the request and leave the session alive. Do not wait longer than 3s if the API is down.
148
+ let finished = false;
149
+
150
+ const finish = () => {
151
+ if (finished) return;
152
+
153
+ finished = true;
147
154
 
148
- this._userHttpService.get('/api/user/logout');
155
+ this._router.navigateByUrl(this._bosConfig.signPath);
149
156
 
150
- this._router.navigateByUrl(this._bosConfig.signPath);
157
+ setTimeout(() => {
158
+ location.reload();
159
+ }, 100);
160
+ };
161
+
162
+ this._userHttpService.get('/api/user/logout', finish, { err: finish });
163
+
164
+ this._userHttpService.remove('token');
151
165
 
152
- setTimeout(() => {
153
- location.reload();
154
- }, 100);
166
+ setTimeout(finish, 3000);
155
167
  }
156
168
 
157
169
  updateAdmin(user: User) {
@@ -1,31 +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
+ 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
+ }
@@ -6,10 +6,10 @@ import { Component, input } from '@angular/core';
6
6
  styleUrl: './spider.component.scss',
7
7
  host: {
8
8
  class: 'spider',
9
- '[style.--spider-w]': 'width()',
10
- '[style.--spider-h]': 'height()',
11
- '[style.--spider-start]': 'start()',
12
- '[style.--spider-end]': 'end()',
9
+ '[style.--spider-w]': 'width()',
10
+ '[style.--spider-h]': 'height()',
11
+ '[style.--spider-start]': 'start()',
12
+ '[style.--spider-end]': 'end()',
13
13
  },
14
14
  })
15
15
  export class SpiderComponent {
@@ -27,7 +27,7 @@ export const DEFAULT_NGX_BOS_CONFIG: Required<NgxBosConfig> = {
27
27
  userForm: [],
28
28
  signPath: '/sign',
29
29
  profilePath: '/profile',
30
- defaultUserThumb: 'default.png',
30
+ defaultUserThumb: 'default.png',
31
31
  };
32
32
 
33
33
  export const NGX_BOS_CONFIG = new InjectionToken<Required<NgxBosConfig>>(
@@ -1,100 +1,100 @@
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
- }
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
+ }
package/src/public-api.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * the source app into the package.
6
6
  */
7
7
 
8
- export const NGX_BOS_VERSION = '22.0.4' as const;
8
+ export const NGX_BOS_VERSION = '22.0.5' as const;
9
9
 
10
10
  export type NgxBosVersion = typeof NGX_BOS_VERSION;
11
11