@wawjs/ngx-bos 22.0.0

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 (90) hide show
  1. package/AGENTS.md +23 -0
  2. package/README.md +105 -0
  3. package/RELEASES.md +21 -0
  4. package/ai/architecture.md +40 -0
  5. package/ai/code-style.md +33 -0
  6. package/ai/decisions/2026-06-02-browser-only-bos-spa.md +16 -0
  7. package/ai/decisions/2026-06-02-package-boundary.md +22 -0
  8. package/ai/decisions/2026-06-02-version-start.md +12 -0
  9. package/ai/decisions/index.md +7 -0
  10. package/ai/onboarding.md +19 -0
  11. package/ai/task-execution.md +35 -0
  12. package/ai/tooling.md +33 -0
  13. package/fesm2022/wawjs-ngx-bos.mjs +2287 -0
  14. package/fesm2022/wawjs-ngx-bos.mjs.map +1 -0
  15. package/package.json +38 -0
  16. package/src/feature/file/file.component.html +123 -0
  17. package/src/feature/file/file.component.scss +209 -0
  18. package/src/feature/file/file.component.ts +220 -0
  19. package/src/feature/file/file.const.ts +20 -0
  20. package/src/feature/file/file.interface.ts +12 -0
  21. package/src/feature/file/file.service.ts +34 -0
  22. package/src/feature/file/file.util.ts +72 -0
  23. package/src/feature/file/index.ts +9 -0
  24. package/src/feature/file/pages/files/files.component.html +12 -0
  25. package/src/feature/file/pages/files/files.component.ts +117 -0
  26. package/src/feature/file/pages/files/files.routes.ts +9 -0
  27. package/src/feature/file/selectors/file/file-selector.component.html +11 -0
  28. package/src/feature/file/selectors/file/file-selector.component.ts +27 -0
  29. package/src/feature/user/LICENSE +21 -0
  30. package/src/feature/user/README.md +1 -0
  31. package/src/feature/user/components/user-preview/user-preview.component.html +7 -0
  32. package/src/feature/user/components/user-preview/user-preview.component.scss +27 -0
  33. package/src/feature/user/components/user-preview/user-preview.component.ts +16 -0
  34. package/src/feature/user/guards/admins.guard.ts +22 -0
  35. package/src/feature/user/guards/authenticated.guard.ts +14 -0
  36. package/src/feature/user/guards/guest.guard.ts +14 -0
  37. package/src/feature/user/module.json +1 -0
  38. package/src/feature/user/pages/clients/clients.component.html +8 -0
  39. package/src/feature/user/pages/clients/clients.component.scss +0 -0
  40. package/src/feature/user/pages/clients/clients.component.ts +45 -0
  41. package/src/feature/user/pages/clients/clients.routes.ts +9 -0
  42. package/src/feature/user/pages/users/users.component.html +18 -0
  43. package/src/feature/user/pages/users/users.component.ts +57 -0
  44. package/src/feature/user/pages/users/users.routes.ts +9 -0
  45. package/src/feature/user/selectors/user/user-selector.component.html +6 -0
  46. package/src/feature/user/selectors/user/user-selector.component.scss +0 -0
  47. package/src/feature/user/selectors/user/user-selector.component.ts +17 -0
  48. package/src/feature/user/user.const.ts +13 -0
  49. package/src/feature/user/user.form.ts +54 -0
  50. package/src/feature/user/user.interface.ts +12 -0
  51. package/src/feature/user/user.service.ts +176 -0
  52. package/src/form-components/ace/ace.component.html +14 -0
  53. package/src/form-components/ace/ace.component.scss +22 -0
  54. package/src/form-components/ace/ace.component.ts +210 -0
  55. package/src/form-components/ace/ace.form.ts +184 -0
  56. package/src/form-components/button/button.component.html +15 -0
  57. package/src/form-components/button/button.component.ts +31 -0
  58. package/src/form-components/button/button.form.ts +74 -0
  59. package/src/form-components/file/file.component.html +73 -0
  60. package/src/form-components/file/file.component.ts +91 -0
  61. package/src/form-components/file/file.form.ts +112 -0
  62. package/src/form-components/form-bridge.interface.ts +27 -0
  63. package/src/form-components/index.ts +85 -0
  64. package/src/form-components/input/input.component.html +16 -0
  65. package/src/form-components/input/input.component.ts +31 -0
  66. package/src/form-components/input/input.form.ts +117 -0
  67. package/src/form-components/select/select.component.html +24 -0
  68. package/src/form-components/select/select.component.ts +31 -0
  69. package/src/form-components/select/select.form.ts +88 -0
  70. package/src/form-components/tinymce/tinymce.component.html +13 -0
  71. package/src/form-components/tinymce/tinymce.component.scss +19 -0
  72. package/src/form-components/tinymce/tinymce.component.ts +221 -0
  73. package/src/form-components/tinymce/tinymce.form.ts +191 -0
  74. package/src/icons/spider/LICENSE +21 -0
  75. package/src/icons/spider/README.md +127 -0
  76. package/src/icons/spider/index.ts +1 -0
  77. package/src/icons/spider/module.json +4 -0
  78. package/src/icons/spider/spider.component.html +115 -0
  79. package/src/icons/spider/spider.component.scss +20 -0
  80. package/src/icons/spider/spider.component.ts +20 -0
  81. package/src/ngx-bos.config.ts +55 -0
  82. package/src/pages/form/form.component.html +9 -0
  83. package/src/pages/form/form.component.ts +86 -0
  84. package/src/pages/form/form.routes.ts +9 -0
  85. package/src/pages/forms/forms.component.html +9 -0
  86. package/src/pages/forms/forms.component.ts +77 -0
  87. package/src/pages/forms/forms.routes.ts +9 -0
  88. package/src/pipes/phone.pipe.ts +17 -0
  89. package/src/public-api.ts +36 -0
  90. package/types/wawjs-ngx-bos.d.ts +332 -0
@@ -0,0 +1,209 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ .wfile {
6
+ &._disabled {
7
+ opacity: 0.6;
8
+ pointer-events: none;
9
+ }
10
+
11
+ &__label {
12
+ margin-bottom: 6px;
13
+ }
14
+
15
+ &__body {
16
+ border: 1px solid var(--c-border);
17
+ border-radius: var(--radius);
18
+ overflow: hidden;
19
+ background: var(--c-bg-secondary);
20
+ box-shadow: var(--shadow-sm);
21
+ }
22
+
23
+ &__body--thumb-only {
24
+ display: inline-flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ inline-size: 100px;
28
+ block-size: 100px;
29
+ padding: 0;
30
+ }
31
+
32
+ &__empty {
33
+ color: var(--c-placeholder);
34
+ font-size: 0.85rem;
35
+ text-align: center;
36
+ padding: var(--sp-2);
37
+ }
38
+
39
+ &__thumb {
40
+ display: block;
41
+ inline-size: 100%;
42
+ block-size: 100%;
43
+ object-fit: cover;
44
+ }
45
+
46
+ &__name {
47
+ display: block;
48
+ max-inline-size: 100%;
49
+ overflow: hidden;
50
+ text-overflow: ellipsis;
51
+ white-space: nowrap;
52
+ padding: var(--sp-2);
53
+ }
54
+
55
+ &__remove {
56
+ position: absolute;
57
+ top: 6px;
58
+ right: 6px;
59
+ inline-size: 28px;
60
+ block-size: 28px;
61
+ display: inline-flex;
62
+ align-items: center;
63
+ justify-content: center;
64
+ border-radius: var(--radius-btn);
65
+ border: 1px solid var(--c-border);
66
+ background: var(--c-bg-secondary);
67
+ cursor: pointer;
68
+
69
+ &:hover {
70
+ background: var(--c-bg-tertiary);
71
+ }
72
+ }
73
+
74
+ &__dropzone {
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ gap: var(--sp-2);
79
+ padding: var(--sp-4);
80
+ background: var(--c-bg-tertiary);
81
+ border-bottom: 1px solid var(--c-border);
82
+ color: var(--c-text-primary);
83
+
84
+ &._compact {
85
+ padding: var(--sp-3);
86
+ }
87
+
88
+ &._clickable {
89
+ cursor: pointer;
90
+
91
+ &:hover {
92
+ background: var(--c-bg-secondary);
93
+ }
94
+ }
95
+ }
96
+
97
+ &__placeholder {
98
+ color: var(--c-placeholder);
99
+ }
100
+
101
+ &__actions {
102
+ display: flex;
103
+ align-items: center;
104
+ justify-content: space-between;
105
+ gap: var(--sp-2);
106
+ padding: var(--sp-2) var(--sp-3);
107
+ border-top: 1px solid var(--c-border);
108
+ background: var(--c-bg-secondary);
109
+ }
110
+
111
+ &__files {
112
+ display: grid;
113
+ gap: var(--sp-2);
114
+ padding: var(--sp-3);
115
+ }
116
+
117
+ &__file {
118
+ display: flex;
119
+ align-items: center;
120
+ justify-content: space-between;
121
+ gap: var(--sp-2);
122
+ padding: var(--sp-2) var(--sp-3);
123
+ border: 1px solid var(--c-border);
124
+ border-radius: var(--radius-card);
125
+ background: var(--c-bg-secondary);
126
+
127
+ &-meta {
128
+ display: grid;
129
+ gap: 2px;
130
+ min-width: 0;
131
+ }
132
+
133
+ &-name {
134
+ color: var(--c-text-primary);
135
+ font-weight: 600;
136
+ white-space: nowrap;
137
+ text-overflow: ellipsis;
138
+ overflow: hidden;
139
+ }
140
+
141
+ &-size {
142
+ color: var(--c-text-muted);
143
+ font-size: 0.85rem;
144
+ }
145
+
146
+ &-actions {
147
+ display: inline-flex;
148
+ gap: var(--sp-1);
149
+ }
150
+ }
151
+
152
+ &__thumbs {
153
+ display: grid;
154
+ gap: var(--sp-2);
155
+ grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
156
+ padding: var(--sp-3);
157
+ }
158
+
159
+ &__thumb {
160
+ position: relative;
161
+ border: 1px solid var(--c-border);
162
+ border-radius: var(--radius-card);
163
+ background: var(--c-bg-secondary);
164
+ overflow: hidden;
165
+ aspect-ratio: 1 / 1;
166
+
167
+ img {
168
+ display: block;
169
+ inline-size: 100%;
170
+ block-size: 100%;
171
+ object-fit: cover;
172
+ }
173
+
174
+ &-remove {
175
+ position: absolute;
176
+ top: 6px;
177
+ right: 6px;
178
+ inline-size: 28px;
179
+ block-size: 28px;
180
+ display: inline-flex;
181
+ align-items: center;
182
+ justify-content: center;
183
+ border-radius: var(--radius-btn);
184
+ border: 1px solid var(--c-border);
185
+ background: var(--c-bg-secondary);
186
+ cursor: pointer;
187
+
188
+ &:hover {
189
+ background: var(--c-bg-tertiary);
190
+ }
191
+ }
192
+ }
193
+
194
+ &__preview {
195
+ display: block;
196
+ padding: var(--sp-3);
197
+ border-top: 1px solid var(--c-border);
198
+ background: var(--c-bg-secondary);
199
+
200
+ img {
201
+ display: block;
202
+ inline-size: 100%;
203
+ max-block-size: 280px;
204
+ object-fit: contain;
205
+ border-radius: var(--radius-card);
206
+ background: var(--c-bg-tertiary);
207
+ }
208
+ }
209
+ }
@@ -0,0 +1,220 @@
1
+ import { NgTemplateOutlet } from '@angular/common';
2
+ import {
3
+ Component,
4
+ TemplateRef,
5
+ computed,
6
+ inject,
7
+ input,
8
+ model,
9
+ } from '@angular/core';
10
+ import { ButtonComponent, ModalService } from '@wawjs/ngx-ui';
11
+ import { fileToDataUrl } from './file.util';
12
+ import { TranslateDirective } from '@wawjs/ngx-translate';
13
+ import type { FabricCropResult } from '@wawjs/ngx-fabric';
14
+ import { fileDefaults } from './file.const';
15
+ import { FileService } from './file.service';
16
+
17
+ export type FileMode =
18
+ | 'single-image'
19
+ | 'single-file'
20
+ | 'multi-image'
21
+ | 'multi-file';
22
+
23
+ export type FileView = 'dropzone' | 'list' | 'thumb-only';
24
+
25
+ @Component({
26
+ selector: 'ngx-file',
27
+ imports: [NgTemplateOutlet, TranslateDirective, ButtonComponent],
28
+ templateUrl: './file.component.html',
29
+ styleUrl: './file.component.scss',
30
+ })
31
+ export class FileComponent {
32
+ /** UI props */
33
+ readonly label = input<string>(fileDefaults.label);
34
+ readonly placeholder = input<string>(fileDefaults.placeholder);
35
+ readonly disabled = input<boolean>(fileDefaults.disabled);
36
+ readonly clearable = input<boolean>(fileDefaults.clearable);
37
+ readonly accept = input<string>(fileDefaults.accept);
38
+ readonly preview = input<boolean>(fileDefaults.preview);
39
+
40
+ /** Behaviour */
41
+ readonly mode = input<FileMode>(fileDefaults.mode as FileMode);
42
+ readonly view = input<FileView>(fileDefaults.view as FileView);
43
+
44
+ /** Optional crop box (for image modes) */
45
+ readonly cropWidth = input<number | null>(fileDefaults.cropWidth);
46
+ readonly cropHeight = input<number | null>(fileDefaults.cropHeight);
47
+
48
+ /** Custom templates */
49
+ readonly t_item = input<TemplateRef<unknown>>();
50
+ readonly t_empty = input<TemplateRef<unknown>>();
51
+
52
+ /** Back-end routing */
53
+ readonly container = input<string>(fileDefaults.container);
54
+ readonly name = input<string>(fileDefaults.name);
55
+
56
+ /** Separate models for each mode */
57
+ readonly wImage = model<string | null>(null, { alias: 'wImage' });
58
+ readonly wFile = model<string | null>(null, { alias: 'wFile' });
59
+ readonly wImages = model<string[]>([], { alias: 'wImages' });
60
+ readonly wFiles = model<string[]>([], { alias: 'wFiles' });
61
+
62
+ private readonly _modal = inject(ModalService);
63
+ private readonly _fs = inject(FileService);
64
+
65
+ readonly isDisabled = computed(() => this.disabled());
66
+ readonly isMultiple = computed(() => this.mode().startsWith('multi-'));
67
+ readonly isImageMode = computed(() => this.mode().includes('image'));
68
+
69
+ /** Normalized list of URLs for rendering */
70
+ readonly files = computed<string[]>(() => {
71
+ const mode = this.mode();
72
+ switch (mode) {
73
+ case 'single-image':
74
+ return this.wImage() ? [this.wImage() as string] : [];
75
+ case 'single-file':
76
+ return this.wFile() ? [this.wFile() as string] : [];
77
+ case 'multi-image':
78
+ return this.wImages();
79
+ case 'multi-file':
80
+ return this.wFiles();
81
+ default:
82
+ return [];
83
+ }
84
+ });
85
+
86
+ triggerPick(input: HTMLInputElement): void {
87
+ if (!this.isDisabled()) {
88
+ input.click();
89
+ }
90
+ }
91
+
92
+ isImage(src: string): boolean {
93
+ return /\.(png|jpe?g|webp|gif)(\?|$)/i.test(src ?? '');
94
+ }
95
+
96
+ async onPicked(input: HTMLInputElement): Promise<void> {
97
+ const list = input.files;
98
+ if (!list || !list.length) return;
99
+
100
+ const doCrop =
101
+ this.isImageMode() && !!this.cropWidth() && !!this.cropHeight();
102
+ const urls: string[] = [];
103
+ const container = this.container();
104
+ const name = this.name();
105
+
106
+ for (let i = 0; i < list.length; i++) {
107
+ const f = list.item(i)!;
108
+
109
+ // Always read file as data URL
110
+ const dataUrl = await fileToDataUrl(f);
111
+
112
+ if (doCrop) {
113
+ // Lazy-load fabric crop modal only when actually cropping
114
+ const { FabricCropModalComponent } = await import(
115
+ '@wawjs/ngx-fabric'
116
+ );
117
+ await new Promise<void>((resolve) => {
118
+ this._modal.show({
119
+ component: FabricCropModalComponent,
120
+ size: 'big',
121
+ image: dataUrl,
122
+ width: this.cropWidth()!,
123
+ height: this.cropHeight()!,
124
+ aspectRatio: this.cropWidth()! / this.cropHeight()!,
125
+ outputWidth: this.cropWidth()!,
126
+ outputHeight: this.cropHeight()!,
127
+ onCrop: (result: FabricCropResult) => {
128
+ this._fs
129
+ .uploadBase64(result.base64, container, name)
130
+ .then((url) => {
131
+ urls.push(url);
132
+ resolve();
133
+ });
134
+ },
135
+ onCancel: () => resolve(),
136
+ });
137
+ });
138
+ } else {
139
+ const url = await this._fs.uploadBase64(
140
+ dataUrl,
141
+ container,
142
+ name,
143
+ );
144
+ urls.push(url);
145
+ }
146
+
147
+ // If single mode, ignore extra files after first
148
+ if (!this.isMultiple()) {
149
+ break;
150
+ }
151
+ }
152
+
153
+ this._applyNewUrls(urls);
154
+ input.value = '';
155
+ }
156
+
157
+ removeAt(index: number): void {
158
+ const mode = this.mode();
159
+
160
+ if (mode === 'single-image') {
161
+ this.wImage.set(null);
162
+ return;
163
+ }
164
+
165
+ if (mode === 'single-file') {
166
+ this.wFile.set(null);
167
+ return;
168
+ }
169
+
170
+ // Multi modes
171
+ const current = [...this.files()];
172
+ current.splice(index, 1);
173
+
174
+ if (mode === 'multi-image') {
175
+ this.wImages.set(current);
176
+ } else if (mode === 'multi-file') {
177
+ this.wFiles.set(current);
178
+ }
179
+ }
180
+
181
+ clear(): void {
182
+ const mode = this.mode();
183
+ if (mode === 'single-image') {
184
+ this.wImage.set(null);
185
+ } else if (mode === 'single-file') {
186
+ this.wFile.set(null);
187
+ } else if (mode === 'multi-image') {
188
+ this.wImages.set([]);
189
+ } else if (mode === 'multi-file') {
190
+ this.wFiles.set([]);
191
+ }
192
+ }
193
+
194
+ private _applyNewUrls(urls: string[]): void {
195
+ const mode = this.mode();
196
+
197
+ if (!urls.length) {
198
+ return;
199
+ }
200
+
201
+ if (mode === 'single-image') {
202
+ this.wImage.set(urls[0] ?? null);
203
+ return;
204
+ }
205
+
206
+ if (mode === 'single-file') {
207
+ this.wFile.set(urls[0] ?? null);
208
+ return;
209
+ }
210
+
211
+ if (mode === 'multi-image') {
212
+ this.wImages.set([...this.wImages(), ...urls]);
213
+ return;
214
+ }
215
+
216
+ if (mode === 'multi-file') {
217
+ this.wFiles.set([...this.wFiles(), ...urls]);
218
+ }
219
+ }
220
+ }
@@ -0,0 +1,20 @@
1
+ export const fileDefaults = {
2
+ label: '',
3
+ placeholder: 'Select file',
4
+ disabled: false,
5
+ clearable: true,
6
+ accept: '*/*',
7
+ preview: true,
8
+
9
+ // behaviour
10
+ mode: 'single-image', // 'single-image' | 'single-file' | 'multi-image' | 'multi-file'
11
+ view: 'dropzone', // 'dropzone' | 'list' | 'thumb-only'
12
+
13
+ // crop
14
+ cropWidth: null as number | null,
15
+ cropHeight: null as number | null,
16
+
17
+ // backend routing
18
+ container: 'general',
19
+ name: '',
20
+ };
@@ -0,0 +1,12 @@
1
+ import { CrudDocument } from '@wawjs/ngx-crud';
2
+
3
+ export interface File extends CrudDocument<File> {
4
+ name: string;
5
+ description: string;
6
+ url?: string;
7
+ }
8
+
9
+ export interface ImageResizeBounds {
10
+ width: number;
11
+ height: number;
12
+ }
@@ -0,0 +1,34 @@
1
+ import { Injectable, inject } from '@angular/core';
2
+ import { CrudService } from '@wawjs/ngx-crud';
3
+ import { HttpService } from '@wawjs/ngx-http';
4
+ import { NGX_BOS_CONFIG } from '../../ngx-bos.config';
5
+ import { File } from './file.interface';
6
+
7
+ @Injectable({ providedIn: 'root' })
8
+ export class FileService extends CrudService<File> {
9
+ private readonly _http = inject(HttpService);
10
+ private readonly _bosConfig = inject(NGX_BOS_CONFIG);
11
+
12
+ constructor() {
13
+ super({ name: 'file' });
14
+ }
15
+
16
+ /**
17
+ * Upload base64 (data URL) to backend with optional container/name.
18
+ * Returns a URL string from the API.
19
+ */
20
+ async uploadBase64(
21
+ dataUrl: string,
22
+ container = 'general',
23
+ name = '',
24
+ ): Promise<string> {
25
+ return await new Promise<string>((resolve) => {
26
+ this._http.post(
27
+ '/api/cloudflare/upload-base64',
28
+ { container, name, dataUrl },
29
+ (resp: { key: string }) =>
30
+ resolve(this._bosConfig.cdnUrl + '/' + resp.key),
31
+ );
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,72 @@
1
+ import { ImageResizeBounds } from './file.interface';
2
+
3
+ /**
4
+ * Read a File as base64 data URL.
5
+ */
6
+ export function fileToDataUrl(file: File): Promise<string> {
7
+ return new Promise((resolve, reject) => {
8
+ const reader = new FileReader();
9
+
10
+ reader.onload = () => resolve(reader.result as string);
11
+ reader.onerror = reject;
12
+
13
+ reader.readAsDataURL(file);
14
+ });
15
+ }
16
+
17
+ /**
18
+ * Resize an image file so it fits within given bounds, preserving aspect ratio.
19
+ * Returns a base64 data URL (or the original if no resize is needed / not image).
20
+ */
21
+ export async function resizeImageToBounds(
22
+ file: File,
23
+ bounds: ImageResizeBounds,
24
+ ): Promise<string> {
25
+ const original = await fileToDataUrl(file);
26
+
27
+ // Not an image → just return original
28
+ if (!file.type.startsWith('image/')) {
29
+ return original;
30
+ }
31
+
32
+ return new Promise((resolve) => {
33
+ const img = new Image();
34
+
35
+ img.onload = () => {
36
+ const maxW = bounds.width || 1920;
37
+ const maxH = bounds.height || 1080;
38
+
39
+ // Already within bounds → no resize
40
+ if (img.width <= maxW && img.height <= maxH) {
41
+ resolve(original);
42
+ return;
43
+ }
44
+
45
+ const infoRatio = maxW / maxH;
46
+ const imgRatio = img.width / img.height;
47
+
48
+ let width: number;
49
+ let height: number;
50
+
51
+ if (imgRatio > infoRatio) {
52
+ width = Math.min(maxW, img.width);
53
+ height = width / imgRatio;
54
+ } else {
55
+ height = Math.min(maxH, img.height);
56
+ width = height * imgRatio;
57
+ }
58
+
59
+ const canvas = document.createElement('canvas');
60
+ canvas.width = width;
61
+ canvas.height = height;
62
+
63
+ const ctx = canvas.getContext('2d');
64
+ ctx?.drawImage(img, 0, 0, width, height);
65
+
66
+ const resized = canvas.toDataURL('image/jpeg', 1);
67
+ resolve(resized);
68
+ };
69
+
70
+ img.src = original;
71
+ });
72
+ }
@@ -0,0 +1,9 @@
1
+ export * from './file.component';
2
+
3
+ export * from './file.interface';
4
+
5
+ export * from './file.service';
6
+
7
+ export * from './file.util';
8
+
9
+ export * from './file.const';
@@ -0,0 +1,12 @@
1
+ <wtable title="Files" [columns]="columns" [config]="config" [rows]="rows">
2
+ <ng-template cell="img" let-element>
3
+ <img
4
+ [src]="element.url || ''"
5
+ (click)="copy(element.url)"
6
+ style="height: 100px"
7
+ />
8
+ </ng-template>
9
+ <ng-template cell="url" let-element>
10
+ <span (click)="copy(element.url || '')">{{ element.url }}</span>
11
+ </ng-template>
12
+ </wtable>
@@ -0,0 +1,117 @@
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: 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.splice(0, this.rows.length);
105
+ this.rows.push(...rows);
106
+ });
107
+ },
108
+ 250,
109
+ );
110
+ }
111
+
112
+ private _page = 1;
113
+
114
+ private _preCreate(file: File): void {
115
+ delete (file as any).__created;
116
+ }
117
+ }