adminforth 2.4.0-next.26 → 2.4.0-next.261
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/commands/callTsProxy.js +14 -4
- package/commands/cli.js +10 -3
- package/commands/createApp/templates/api.ts.hbs +10 -0
- package/commands/createApp/templates/custom/tsconfig.json.hbs +2 -3
- package/commands/createApp/templates/index.ts.hbs +12 -1
- package/commands/createApp/utils.js +25 -8
- package/commands/createCustomComponent/configLoader.js +17 -4
- package/commands/createCustomComponent/main.js +1 -0
- package/commands/createCustomComponent/templates/customCrud/beforeActionButtons.vue.hbs +38 -0
- package/commands/createPlugin/templates/custom/tsconfig.json.hbs +2 -5
- package/commands/createPlugin/templates/package.json.hbs +1 -1
- package/commands/generateModels.js +30 -22
- package/dist/auth.d.ts +9 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +21 -2
- package/dist/auth.js.map +1 -1
- package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
- package/dist/dataConnectors/baseConnector.js +46 -15
- package/dist/dataConnectors/baseConnector.js.map +1 -1
- package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
- package/dist/dataConnectors/clickhouse.js +15 -0
- package/dist/dataConnectors/clickhouse.js.map +1 -1
- package/dist/dataConnectors/mongo.d.ts.map +1 -1
- package/dist/dataConnectors/mongo.js +50 -15
- package/dist/dataConnectors/mongo.js.map +1 -1
- package/dist/dataConnectors/mysql.d.ts.map +1 -1
- package/dist/dataConnectors/mysql.js +11 -0
- package/dist/dataConnectors/mysql.js.map +1 -1
- package/dist/dataConnectors/postgres.d.ts.map +1 -1
- package/dist/dataConnectors/postgres.js +43 -14
- package/dist/dataConnectors/postgres.js.map +1 -1
- package/dist/dataConnectors/sqlite.d.ts.map +1 -1
- package/dist/dataConnectors/sqlite.js +11 -0
- package/dist/dataConnectors/sqlite.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/dist/modules/codeInjector.d.ts +2 -0
- package/dist/modules/codeInjector.d.ts.map +1 -1
- package/dist/modules/codeInjector.js +50 -6
- package/dist/modules/codeInjector.js.map +1 -1
- package/dist/modules/configValidator.d.ts +6 -0
- package/dist/modules/configValidator.d.ts.map +1 -1
- package/dist/modules/configValidator.js +184 -19
- package/dist/modules/configValidator.js.map +1 -1
- package/dist/modules/restApi.d.ts.map +1 -1
- package/dist/modules/restApi.js +164 -26
- package/dist/modules/restApi.js.map +1 -1
- package/dist/modules/styles.d.ts +499 -13
- package/dist/modules/styles.d.ts.map +1 -1
- package/dist/modules/styles.js +555 -31
- package/dist/modules/styles.js.map +1 -1
- package/dist/modules/utils.d.ts +7 -15
- package/dist/modules/utils.d.ts.map +1 -1
- package/dist/modules/utils.js +45 -68
- package/dist/modules/utils.js.map +1 -1
- package/dist/servers/express.d.ts +5 -0
- package/dist/servers/express.d.ts.map +1 -1
- package/dist/servers/express.js +40 -1
- package/dist/servers/express.js.map +1 -1
- package/dist/spa/index.html +1 -1
- package/dist/spa/package-lock.json +5 -4
- package/dist/spa/package.json +1 -1
- package/dist/spa/src/App.vue +58 -173
- package/dist/spa/src/adminforth.ts +42 -18
- package/dist/spa/src/afcl/BarChart.vue +2 -2
- package/dist/spa/src/afcl/Button.vue +6 -6
- package/dist/spa/src/afcl/ButtonGroup.vue +91 -0
- package/dist/spa/src/afcl/Card.vue +25 -0
- package/dist/spa/src/afcl/Checkbox.vue +21 -13
- package/dist/spa/src/afcl/CountryFlag.vue +4 -1
- package/dist/spa/src/{components/CustomDatePicker.vue → afcl/DatePicker.vue} +95 -9
- package/dist/spa/src/afcl/Dialog.vue +47 -27
- package/dist/spa/src/afcl/Dropzone.vue +12 -12
- package/dist/spa/src/afcl/Input.vue +5 -5
- package/dist/spa/src/afcl/JsonViewer.vue +25 -0
- package/dist/spa/src/afcl/LinkButton.vue +3 -3
- package/dist/spa/src/afcl/PieChart.vue +5 -5
- package/dist/spa/src/afcl/ProgressBar.vue +7 -7
- package/dist/spa/src/afcl/Select.vue +68 -34
- package/dist/spa/src/afcl/Skeleton.vue +6 -6
- package/dist/spa/src/afcl/Table.vue +213 -74
- package/dist/spa/src/afcl/Textarea.vue +31 -0
- package/dist/spa/src/afcl/Toggle.vue +32 -0
- package/dist/spa/src/afcl/Tooltip.vue +26 -18
- package/dist/spa/src/afcl/VerticalTabs.vue +16 -7
- package/dist/spa/src/afcl/index.ts +6 -3
- package/dist/spa/src/components/AcceptModal.vue +48 -14
- package/dist/spa/src/components/Breadcrumbs.vue +5 -5
- package/dist/spa/src/components/ColumnValueInput.vue +38 -18
- package/dist/spa/src/components/ColumnValueInputWrapper.vue +4 -3
- package/dist/spa/src/components/CustomDateRangePicker.vue +9 -8
- package/dist/spa/src/components/CustomRangePicker.vue +37 -8
- package/dist/spa/src/components/ErrorMessage.vue +21 -0
- package/dist/spa/src/components/Filters.vue +85 -39
- package/dist/spa/src/components/GroupsTable.vue +9 -8
- package/dist/spa/src/components/MenuLink.vue +90 -23
- package/dist/spa/src/components/ResourceForm.vue +94 -51
- package/dist/spa/src/components/ResourceListTable.vue +90 -80
- package/dist/spa/src/components/ResourceListTableVirtual.vue +86 -76
- package/dist/spa/src/components/ShowTable.vue +21 -15
- package/dist/spa/src/components/Sidebar.vue +470 -0
- package/dist/spa/src/components/SingleSkeletLoader.vue +6 -6
- package/dist/spa/src/components/SkeleteLoader.vue +3 -3
- package/dist/spa/src/components/ThreeDotsMenu.vue +73 -14
- package/dist/spa/src/components/Toast.vue +27 -9
- package/dist/spa/src/components/UserMenuSettingsButton.vue +69 -0
- package/dist/spa/src/components/ValueRenderer.vue +43 -16
- package/dist/spa/src/controls/BoolToggle.vue +34 -0
- package/dist/spa/src/i18n.ts +1 -1
- package/dist/spa/src/renderers/CompactField.vue +1 -1
- package/dist/spa/src/renderers/CompactUUID.vue +1 -1
- package/dist/spa/src/router/index.ts +8 -0
- package/dist/spa/src/shims-vue.d.ts +5 -0
- package/dist/spa/src/spa_types/core.ts +13 -1
- package/dist/spa/src/stores/core.ts +13 -1
- package/dist/spa/src/stores/filters.ts +29 -2
- package/dist/spa/src/stores/modal.ts +6 -1
- package/dist/spa/src/stores/toast.ts +22 -3
- package/dist/spa/src/types/Back.ts +158 -22
- package/dist/spa/src/types/Common.ts +81 -32
- package/dist/spa/src/types/FrontendAPI.ts +31 -5
- package/dist/spa/src/types/adapters/CaptchaAdapter.ts +34 -0
- package/dist/spa/src/types/adapters/EmailAdapter.ts +2 -2
- package/dist/spa/src/types/adapters/ImageVisionAdapter.ts +30 -0
- package/dist/spa/src/types/adapters/KeyValueAdapter.ts +16 -0
- package/dist/spa/src/types/adapters/index.ts +8 -0
- package/dist/spa/src/utils.ts +279 -9
- package/dist/spa/src/views/CreateView.vue +18 -19
- package/dist/spa/src/views/EditView.vue +25 -19
- package/dist/spa/src/views/ListView.vue +144 -87
- package/dist/spa/src/views/LoginView.vue +26 -35
- package/dist/spa/src/views/ResourceParent.vue +2 -2
- package/dist/spa/src/views/SettingsView.vue +121 -0
- package/dist/spa/src/views/ShowView.vue +59 -39
- package/dist/spa/src/websocket.ts +6 -1
- package/dist/spa/tsconfig.app.json +1 -1
- package/dist/spa/vite.config.ts +45 -2
- package/dist/types/Back.d.ts +134 -14
- package/dist/types/Back.d.ts.map +1 -1
- package/dist/types/Back.js +15 -0
- package/dist/types/Back.js.map +1 -1
- package/dist/types/Common.d.ts +96 -29
- package/dist/types/Common.d.ts.map +1 -1
- package/dist/types/Common.js.map +1 -1
- package/dist/types/FrontendAPI.d.ts +31 -3
- package/dist/types/FrontendAPI.d.ts.map +1 -1
- package/dist/types/FrontendAPI.js.map +1 -1
- package/dist/types/adapters/CaptchaAdapter.d.ts +30 -0
- package/dist/types/adapters/CaptchaAdapter.d.ts.map +1 -0
- package/dist/types/adapters/CaptchaAdapter.js +5 -0
- package/dist/types/adapters/CaptchaAdapter.js.map +1 -0
- package/dist/types/adapters/EmailAdapter.d.ts +1 -1
- package/dist/types/adapters/ImageVisionAdapter.d.ts +25 -0
- package/dist/types/adapters/ImageVisionAdapter.d.ts.map +1 -0
- package/dist/types/adapters/ImageVisionAdapter.js +2 -0
- package/dist/types/adapters/ImageVisionAdapter.js.map +1 -0
- package/dist/types/adapters/KeyValueAdapter.d.ts +10 -0
- package/dist/types/adapters/KeyValueAdapter.d.ts.map +1 -0
- package/dist/types/adapters/KeyValueAdapter.js +2 -0
- package/dist/types/adapters/KeyValueAdapter.js.map +1 -0
- package/dist/types/adapters/index.d.ts +9 -0
- package/dist/types/adapters/index.d.ts.map +1 -0
- package/dist/types/adapters/index.js +2 -0
- package/dist/types/adapters/index.js.map +1 -0
- package/package.json +4 -2
- package/dist/spa/src/types/adapters/index.js +0 -5
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for Captcha adapters.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface CaptchaAdapter {
|
|
6
|
+
/**
|
|
7
|
+
* Returns the script source URL for the captcha widget.
|
|
8
|
+
*/
|
|
9
|
+
getScriptSrc(): string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the site key for the captcha.
|
|
13
|
+
*/
|
|
14
|
+
getSiteKey(): string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns the widget ID for the captcha.
|
|
18
|
+
*/
|
|
19
|
+
getWidgetId(): string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the script HTML for the captcha widget.
|
|
23
|
+
*/
|
|
24
|
+
getRenderWidgetCode(): string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the function name to render the captcha widget.
|
|
28
|
+
*/
|
|
29
|
+
getRenderWidgetFunctionName(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Validates the captcha token.
|
|
32
|
+
*/
|
|
33
|
+
validate(token: string, ip: string): Promise<Record<string, any>>;
|
|
34
|
+
}
|
|
@@ -2,7 +2,7 @@ export interface EmailAdapter {
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This method is called to validate the configuration of the adapter
|
|
5
|
-
* and should throw a clear user-
|
|
5
|
+
* and should throw a clear user-readable error if the configuration is invalid.
|
|
6
6
|
*/
|
|
7
7
|
validate(): Promise<void>;
|
|
8
8
|
|
|
@@ -24,4 +24,4 @@ export interface EmailAdapter {
|
|
|
24
24
|
error?: string;
|
|
25
25
|
ok?: boolean;
|
|
26
26
|
}>;
|
|
27
|
-
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ImageVisionAdapter {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This method is called to validate the configuration of the adapter
|
|
5
|
+
* and should throw a clear user-readable error if the configuration is invalid.
|
|
6
|
+
*/
|
|
7
|
+
validate(): void;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Input file extension supported
|
|
11
|
+
*/
|
|
12
|
+
inputFileExtensionSupported(): string[];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This method should generate an image based on the provided prompt and input files.
|
|
16
|
+
* @param prompt - The prompt to generate the image
|
|
17
|
+
* @param inputFileUrls - An array of input file paths (optional)
|
|
18
|
+
* @returns A promise that resolves to an object containing the generated image and any error message
|
|
19
|
+
*/
|
|
20
|
+
generate({
|
|
21
|
+
prompt,
|
|
22
|
+
inputFileUrls,
|
|
23
|
+
}: {
|
|
24
|
+
prompt: string,
|
|
25
|
+
inputFileUrls: string[],
|
|
26
|
+
}): Promise<{
|
|
27
|
+
response: string;
|
|
28
|
+
error?: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Might have implementations like RAM, Redis, Memcached,
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export interface KeyValueAdapter {
|
|
7
|
+
|
|
8
|
+
get(key: string): Promise<string | null>;
|
|
9
|
+
|
|
10
|
+
set(key: string, value: string, expiresInSeconds?: number): Promise<void>;
|
|
11
|
+
|
|
12
|
+
delete(key: string): Promise<void>;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { EmailAdapter } from './EmailAdapter.js';
|
|
2
|
+
export type { CompletionAdapter } from './CompletionAdapter.js';
|
|
3
|
+
export type { ImageGenerationAdapter } from './ImageGenerationAdapter.js';
|
|
4
|
+
export type { KeyValueAdapter } from './KeyValueAdapter.js';
|
|
5
|
+
export type { ImageVisionAdapter } from './ImageVisionAdapter.js';
|
|
6
|
+
export type { OAuth2Adapter } from './OAuth2Adapter.js';
|
|
7
|
+
export type { StorageAdapter } from './StorageAdapter.js';
|
|
8
|
+
export type { CaptchaAdapter } from './CaptchaAdapter.js';
|
package/dist/spa/src/utils.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import { onMounted, ref, resolveComponent } from 'vue';
|
|
2
2
|
import type { CoreConfig } from './spa_types/core';
|
|
3
|
-
import type { ValidationObject } from './types/
|
|
3
|
+
import type { ValidationObject } from './types/Common.js';
|
|
4
4
|
import router from "./router";
|
|
5
5
|
import { useCoreStore } from './stores/core';
|
|
6
6
|
import { useUserStore } from './stores/user';
|
|
7
7
|
import { Dropdown } from 'flowbite';
|
|
8
8
|
import adminforth from './adminforth';
|
|
9
9
|
import sanitizeHtml from 'sanitize-html'
|
|
10
|
+
import debounce from 'debounce';
|
|
11
|
+
import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
|
|
10
12
|
|
|
11
13
|
const LS_LANG_KEY = `afLanguage`;
|
|
14
|
+
const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
|
|
15
|
+
const ITEMS_PER_PAGE_LIMIT = 100;
|
|
12
16
|
|
|
13
|
-
export async function callApi({path, method, body
|
|
17
|
+
export async function callApi({path, method, body, headers}: {
|
|
14
18
|
path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
15
19
|
body?: any
|
|
20
|
+
headers?: Record<string, string>
|
|
16
21
|
}): Promise<any> {
|
|
17
22
|
const options = {
|
|
18
23
|
method,
|
|
19
24
|
headers: {
|
|
20
25
|
'Content-Type': 'application/json',
|
|
21
26
|
'accept-language': localStorage.getItem(LS_LANG_KEY) || 'en',
|
|
27
|
+
...headers
|
|
22
28
|
},
|
|
23
29
|
body: JSON.stringify(body),
|
|
24
30
|
};
|
|
@@ -27,6 +33,7 @@ export async function callApi({path, method, body=undefined}: {
|
|
|
27
33
|
const r = await fetch(fullPath, options);
|
|
28
34
|
if (r.status == 401 ) {
|
|
29
35
|
useUserStore().unauthorize();
|
|
36
|
+
useCoreStore().resetAdminUser();
|
|
30
37
|
await router.push({ name: 'login' });
|
|
31
38
|
return null;
|
|
32
39
|
}
|
|
@@ -46,7 +53,7 @@ export async function callApi({path, method, body=undefined}: {
|
|
|
46
53
|
|
|
47
54
|
export async function callAdminForthApi({ path, method, body=undefined, headers=undefined }: {
|
|
48
55
|
path: string,
|
|
49
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
56
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
|
|
50
57
|
body?: any,
|
|
51
58
|
headers?: Record<string, string>
|
|
52
59
|
}): Promise<any> {
|
|
@@ -92,13 +99,14 @@ export const loadFile = (file: string) => {
|
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
export function checkEmptyValues(value: any, viewType: 'show' | 'list' ) {
|
|
95
|
-
const config: CoreConfig | {} = useCoreStore().config;
|
|
102
|
+
const config: CoreConfig | {} | null = useCoreStore().config;
|
|
96
103
|
let emptyFieldPlaceholder = '';
|
|
97
|
-
if (config
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
if (config && 'emptyFieldPlaceholder' in config) {
|
|
105
|
+
const efp = (config as CoreConfig).emptyFieldPlaceholder;
|
|
106
|
+
if(typeof efp === 'string') {
|
|
107
|
+
emptyFieldPlaceholder = efp;
|
|
100
108
|
} else {
|
|
101
|
-
emptyFieldPlaceholder =
|
|
109
|
+
emptyFieldPlaceholder = efp?.[viewType] || '';
|
|
102
110
|
}
|
|
103
111
|
if (value === null || value === undefined || value === '') {
|
|
104
112
|
return emptyFieldPlaceholder;
|
|
@@ -179,7 +187,7 @@ export function verySimpleHash(str: string): string {
|
|
|
179
187
|
return `${str.split('').reduce((a, b)=>{a=((a<<5)-a)+b.charCodeAt(0);return a&a},0)}`;
|
|
180
188
|
}
|
|
181
189
|
|
|
182
|
-
export function humanifySize(size) {
|
|
190
|
+
export function humanifySize(size: number) {
|
|
183
191
|
if (!size) {
|
|
184
192
|
return '';
|
|
185
193
|
}
|
|
@@ -208,4 +216,266 @@ export function protectAgainstXSS(value: string) {
|
|
|
208
216
|
'img': [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ]
|
|
209
217
|
}
|
|
210
218
|
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function isPolymorphicColumn(column: any): boolean {
|
|
222
|
+
return !!(column.foreignResource?.polymorphicResources && column.foreignResource.polymorphicResources.length > 0);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function handleForeignResourcePagination(
|
|
226
|
+
column: any,
|
|
227
|
+
items: any[],
|
|
228
|
+
emptyResultsCount: number = 0,
|
|
229
|
+
isSearching: boolean = false
|
|
230
|
+
): { hasMore: boolean; emptyResultsCount: number } {
|
|
231
|
+
const isPolymorphic = isPolymorphicColumn(column);
|
|
232
|
+
|
|
233
|
+
if (isPolymorphic) {
|
|
234
|
+
if (isSearching) {
|
|
235
|
+
return {
|
|
236
|
+
hasMore: items.length > 0,
|
|
237
|
+
emptyResultsCount: 0
|
|
238
|
+
};
|
|
239
|
+
} else {
|
|
240
|
+
if (items.length === 0) {
|
|
241
|
+
const newEmptyCount = emptyResultsCount + 1;
|
|
242
|
+
return {
|
|
243
|
+
hasMore: newEmptyCount < MAX_CONSECUTIVE_EMPTY_RESULTS, // Stop loading after 2 consecutive empty results
|
|
244
|
+
emptyResultsCount: newEmptyCount
|
|
245
|
+
};
|
|
246
|
+
} else {
|
|
247
|
+
return {
|
|
248
|
+
hasMore: true,
|
|
249
|
+
emptyResultsCount: 0
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
return {
|
|
255
|
+
hasMore: items.length === ITEMS_PER_PAGE_LIMIT,
|
|
256
|
+
emptyResultsCount: 0
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export async function loadMoreForeignOptions({
|
|
262
|
+
columnName,
|
|
263
|
+
searchTerm = '',
|
|
264
|
+
columns,
|
|
265
|
+
resourceId,
|
|
266
|
+
columnOptions,
|
|
267
|
+
columnLoadingState,
|
|
268
|
+
columnOffsets,
|
|
269
|
+
columnEmptyResultsCount
|
|
270
|
+
}: {
|
|
271
|
+
columnName: string;
|
|
272
|
+
searchTerm?: string;
|
|
273
|
+
columns: any[];
|
|
274
|
+
resourceId: string;
|
|
275
|
+
columnOptions: any;
|
|
276
|
+
columnLoadingState: any;
|
|
277
|
+
columnOffsets: any;
|
|
278
|
+
columnEmptyResultsCount: any;
|
|
279
|
+
}) {
|
|
280
|
+
const column = columns?.find(c => c.name === columnName);
|
|
281
|
+
if (!column || !column.foreignResource) return;
|
|
282
|
+
|
|
283
|
+
const state = columnLoadingState[columnName];
|
|
284
|
+
if (state.loading || !state.hasMore) return;
|
|
285
|
+
|
|
286
|
+
state.loading = true;
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const list = await callAdminForthApi({
|
|
290
|
+
method: 'POST',
|
|
291
|
+
path: `/get_resource_foreign_data`,
|
|
292
|
+
body: {
|
|
293
|
+
resourceId,
|
|
294
|
+
column: columnName,
|
|
295
|
+
limit: 100,
|
|
296
|
+
offset: columnOffsets[columnName],
|
|
297
|
+
search: searchTerm,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (!list || !Array.isArray(list.items)) {
|
|
302
|
+
console.warn(`Unexpected API response for column ${columnName}:`, list);
|
|
303
|
+
state.hasMore = false;
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!columnOptions.value) {
|
|
308
|
+
columnOptions.value = {};
|
|
309
|
+
}
|
|
310
|
+
if (!columnOptions.value[columnName]) {
|
|
311
|
+
columnOptions.value[columnName] = [];
|
|
312
|
+
}
|
|
313
|
+
columnOptions.value[columnName].push(...list.items);
|
|
314
|
+
|
|
315
|
+
columnOffsets[columnName] += 100;
|
|
316
|
+
|
|
317
|
+
const paginationResult = handleForeignResourcePagination(
|
|
318
|
+
column,
|
|
319
|
+
list.items,
|
|
320
|
+
columnEmptyResultsCount[columnName] || 0,
|
|
321
|
+
false // not searching
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
columnEmptyResultsCount[columnName] = paginationResult.emptyResultsCount;
|
|
325
|
+
state.hasMore = paginationResult.hasMore;
|
|
326
|
+
|
|
327
|
+
} catch (error) {
|
|
328
|
+
console.error('Error loading more options:', error);
|
|
329
|
+
} finally {
|
|
330
|
+
state.loading = false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export async function searchForeignOptions({
|
|
335
|
+
columnName,
|
|
336
|
+
searchTerm,
|
|
337
|
+
columns,
|
|
338
|
+
resourceId,
|
|
339
|
+
columnOptions,
|
|
340
|
+
columnLoadingState,
|
|
341
|
+
columnOffsets,
|
|
342
|
+
columnEmptyResultsCount
|
|
343
|
+
}: {
|
|
344
|
+
columnName: string;
|
|
345
|
+
searchTerm: string;
|
|
346
|
+
columns: any[];
|
|
347
|
+
resourceId: string;
|
|
348
|
+
columnOptions: any;
|
|
349
|
+
columnLoadingState: any;
|
|
350
|
+
columnOffsets: any;
|
|
351
|
+
columnEmptyResultsCount: any;
|
|
352
|
+
}) {
|
|
353
|
+
const column = columns?.find(c => c.name === columnName);
|
|
354
|
+
|
|
355
|
+
if (!column || !column.foreignResource || !column.foreignResource.searchableFields) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const state = columnLoadingState[columnName];
|
|
360
|
+
if (state.loading) return;
|
|
361
|
+
|
|
362
|
+
state.loading = true;
|
|
363
|
+
|
|
364
|
+
try {
|
|
365
|
+
const list = await callAdminForthApi({
|
|
366
|
+
method: 'POST',
|
|
367
|
+
path: `/get_resource_foreign_data`,
|
|
368
|
+
body: {
|
|
369
|
+
resourceId,
|
|
370
|
+
column: columnName,
|
|
371
|
+
limit: 100,
|
|
372
|
+
offset: 0,
|
|
373
|
+
search: searchTerm,
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
if (!list || !Array.isArray(list.items)) {
|
|
378
|
+
console.warn(`Unexpected API response for column ${columnName}:`, list);
|
|
379
|
+
state.hasMore = false;
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (!columnOptions.value) {
|
|
384
|
+
columnOptions.value = {};
|
|
385
|
+
}
|
|
386
|
+
columnOptions.value[columnName] = list.items;
|
|
387
|
+
columnOffsets[columnName] = 100;
|
|
388
|
+
|
|
389
|
+
const paginationResult = handleForeignResourcePagination(
|
|
390
|
+
column,
|
|
391
|
+
list.items,
|
|
392
|
+
columnEmptyResultsCount[columnName] || 0,
|
|
393
|
+
true // is searching
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
columnEmptyResultsCount[columnName] = paginationResult.emptyResultsCount;
|
|
397
|
+
state.hasMore = paginationResult.hasMore;
|
|
398
|
+
|
|
399
|
+
} catch (error) {
|
|
400
|
+
console.error('Error searching options:', error);
|
|
401
|
+
} finally {
|
|
402
|
+
state.loading = false;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function createSearchInputHandlers(
|
|
407
|
+
columns: any[],
|
|
408
|
+
searchFunction: (columnName: string, searchTerm: string) => void,
|
|
409
|
+
getDebounceMs?: (column: any) => number
|
|
410
|
+
) {
|
|
411
|
+
if (!columns) return {};
|
|
412
|
+
|
|
413
|
+
return columns.reduce((acc, c) => {
|
|
414
|
+
if (c.foreignResource && c.foreignResource.searchableFields) {
|
|
415
|
+
const debounceMs = getDebounceMs ? getDebounceMs(c) : 300;
|
|
416
|
+
return {
|
|
417
|
+
...acc,
|
|
418
|
+
[c.name]: debounce((searchTerm: string) => {
|
|
419
|
+
searchFunction(c.name, searchTerm);
|
|
420
|
+
}, debounceMs),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
return acc;
|
|
424
|
+
}, {} as Record<string, (searchTerm: string) => void>);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function checkShowIf(c: AdminForthResourceColumnInputCommon, record: Record<string, any>) {
|
|
428
|
+
if (!c.showIf) return true;
|
|
429
|
+
|
|
430
|
+
const evaluatePredicate = (predicate: Predicate): boolean => {
|
|
431
|
+
const results: boolean[] = [];
|
|
432
|
+
|
|
433
|
+
if ("$and" in predicate) {
|
|
434
|
+
results.push(predicate.$and.every(evaluatePredicate));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if ("$or" in predicate) {
|
|
438
|
+
results.push(predicate.$or.some(evaluatePredicate));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const fieldEntries = Object.entries(predicate).filter(([key]) => !key.startsWith('$'));
|
|
442
|
+
if (fieldEntries.length > 0) {
|
|
443
|
+
const fieldResult = fieldEntries.every(([field, condition]) => {
|
|
444
|
+
const recordValue = record[field];
|
|
445
|
+
|
|
446
|
+
if (condition === undefined) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
if (typeof condition !== "object" || condition === null) {
|
|
450
|
+
return recordValue === condition;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if ("$eq" in condition) return recordValue === condition.$eq;
|
|
454
|
+
if ("$not" in condition) return recordValue !== condition.$not;
|
|
455
|
+
if ("$gt" in condition) return recordValue > condition.$gt;
|
|
456
|
+
if ("$gte" in condition) return recordValue >= condition.$gte;
|
|
457
|
+
if ("$lt" in condition) return recordValue < condition.$lt;
|
|
458
|
+
if ("$lte" in condition) return recordValue <= condition.$lte;
|
|
459
|
+
if ("$in" in condition) return (Array.isArray(condition.$in) && condition.$in.includes(recordValue));
|
|
460
|
+
if ("$nin" in condition) return (Array.isArray(condition.$nin) && !condition.$nin.includes(recordValue));
|
|
461
|
+
if ("$includes" in condition)
|
|
462
|
+
return (
|
|
463
|
+
Array.isArray(recordValue) &&
|
|
464
|
+
recordValue.includes(condition.$includes)
|
|
465
|
+
);
|
|
466
|
+
if ("$nincludes" in condition)
|
|
467
|
+
return (
|
|
468
|
+
Array.isArray(recordValue) &&
|
|
469
|
+
!recordValue.includes(condition.$nicludes)
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
return true;
|
|
473
|
+
});
|
|
474
|
+
results.push(fieldResult);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return results.every(result => result);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
return evaluatePredicate(c.showIf);
|
|
211
481
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<component
|
|
5
5
|
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.beforeBreadcrumbs || []"
|
|
6
6
|
:is="getCustomComponent(c)"
|
|
7
|
-
:meta="c.meta"
|
|
7
|
+
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
8
8
|
:record="coreStore.record"
|
|
9
9
|
:resource="coreStore.resource"
|
|
10
10
|
:adminUser="coreStore.adminUser"
|
|
@@ -13,25 +13,25 @@
|
|
|
13
13
|
<BreadcrumbsWithButtons>
|
|
14
14
|
<!-- save and cancle -->
|
|
15
15
|
<button @click="$router.back()"
|
|
16
|
-
class="af-cancel-button flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-
|
|
16
|
+
class="af-cancel-button flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-lightCreateViewButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover"
|
|
17
17
|
>
|
|
18
18
|
{{ $t('Cancel') }}
|
|
19
19
|
</button>
|
|
20
20
|
|
|
21
21
|
<button
|
|
22
22
|
@click="saveRecord"
|
|
23
|
-
class="af-save-button flex items-center py-1 px-3 text-sm font-medium rounded-default text-
|
|
23
|
+
class="af-save-button flex items-center py-1 px-3 text-sm font-medium rounded-default text-lightCreateViewSaveButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewSaveButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewSaveButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewSaveButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover disabled:opacity-50 gap-1"
|
|
24
24
|
:disabled="saving || (validating && !isValid)"
|
|
25
25
|
>
|
|
26
26
|
<svg v-if="saving"
|
|
27
|
-
aria-hidden="true" class="w-4 h-4 mr-1 text-gray-200 animate-spin dark:text-gray-600 fill-
|
|
27
|
+
aria-hidden="true" class="w-4 h-4 mr-1 text-gray-200 animate-spin dark:text-gray-600 fill-lightCreateViewSaveButtonText" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
|
|
28
28
|
|
|
29
|
-
<IconFloppyDiskSolid v-else class="w-4 h-4
|
|
29
|
+
<IconFloppyDiskSolid v-else class="w-4 h-4" />
|
|
30
30
|
{{ $t('Save') }}
|
|
31
31
|
</button>
|
|
32
32
|
|
|
33
33
|
<ThreeDotsMenu
|
|
34
|
-
:threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.create?.threeDotsDropdownItems"
|
|
34
|
+
:threeDotsDropdownItems="(coreStore.resourceOptions?.pageInjections?.create?.threeDotsDropdownItems as [])"
|
|
35
35
|
></ThreeDotsMenu>
|
|
36
36
|
|
|
37
37
|
</BreadcrumbsWithButtons>
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
<component
|
|
40
40
|
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs || []"
|
|
41
41
|
:is="getCustomComponent(c)"
|
|
42
|
-
:meta="c.meta"
|
|
42
|
+
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
43
43
|
:record="coreStore.record"
|
|
44
44
|
:resource="coreStore.resource"
|
|
45
45
|
:adminUser="coreStore.adminUser"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
<ResourceForm
|
|
52
52
|
v-else
|
|
53
53
|
:record="record"
|
|
54
|
-
:resource="coreStore.resource"
|
|
54
|
+
:resource="coreStore.resource!"
|
|
55
55
|
@update:record="onUpdateRecord"
|
|
56
56
|
@update:isValid="isValid = $event"
|
|
57
57
|
:validating="validating"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
<component
|
|
64
64
|
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom || []"
|
|
65
65
|
:is="getCustomComponent(c)"
|
|
66
|
-
:meta="c.meta"
|
|
66
|
+
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
67
67
|
:record="coreStore.record"
|
|
68
68
|
:resource="coreStore.resource"
|
|
69
69
|
:adminUser="coreStore.adminUser"
|
|
@@ -88,6 +88,7 @@ import { showErrorTost } from '@/composables/useFrontendApi';
|
|
|
88
88
|
import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
|
|
89
89
|
import adminforth from '@/adminforth';
|
|
90
90
|
import { useI18n } from 'vue-i18n';
|
|
91
|
+
import { type AdminForthComponentDeclarationFull } from '@/types/Common.js';
|
|
91
92
|
|
|
92
93
|
const isValid = ref(false);
|
|
93
94
|
const validating = ref(false);
|
|
@@ -109,36 +110,34 @@ const initialValues = ref({});
|
|
|
109
110
|
const readonlyColumns = ref([]);
|
|
110
111
|
|
|
111
112
|
|
|
112
|
-
async function onUpdateRecord(newRecord) {
|
|
113
|
-
console.log('newRecord', newRecord);
|
|
113
|
+
async function onUpdateRecord(newRecord: any) {
|
|
114
114
|
record.value = newRecord;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
onMounted(async () => {
|
|
118
118
|
loading.value = true;
|
|
119
119
|
await coreStore.fetchResourceFull({
|
|
120
|
-
resourceId: route.params.resourceId
|
|
120
|
+
resourceId: route.params.resourceId as string
|
|
121
121
|
});
|
|
122
|
-
initialValues.value = (coreStore.resource?.columns || []).reduce((acc, column) => {
|
|
122
|
+
initialValues.value = (coreStore.resource?.columns || []).reduce<Record<string, unknown>>((acc, column) => {
|
|
123
123
|
if (column.suggestOnCreate !== undefined) {
|
|
124
124
|
acc[column.name] = column.suggestOnCreate;
|
|
125
125
|
}
|
|
126
126
|
return acc;
|
|
127
127
|
}, {});
|
|
128
128
|
if (route.query.values) {
|
|
129
|
-
initialValues.value = { ...initialValues.value, ...JSON.parse(decodeURIComponent(route.query.values)) };
|
|
129
|
+
initialValues.value = { ...initialValues.value, ...JSON.parse(decodeURIComponent(route.query.values as string)) };
|
|
130
130
|
}
|
|
131
131
|
if (route.query.readonlyColumns) {
|
|
132
|
-
readonlyColumns.value = JSON.parse(decodeURIComponent(route.query.readonlyColumns));
|
|
132
|
+
readonlyColumns.value = JSON.parse(decodeURIComponent(route.query.readonlyColumns as string));
|
|
133
133
|
}
|
|
134
134
|
record.value = initialValues.value;
|
|
135
135
|
loading.value = false;
|
|
136
|
-
checkAcessByAllowedActions(coreStore.resourceOptions
|
|
136
|
+
checkAcessByAllowedActions(coreStore.resourceOptions!.allowedActions,'create');
|
|
137
137
|
initThreeDotsDropdown();
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
async function saveRecord() {
|
|
141
|
-
console.log('saveRecord isValid', isValid.value);
|
|
142
141
|
if (!isValid.value) {
|
|
143
142
|
validating.value = true;
|
|
144
143
|
return;
|
|
@@ -154,12 +153,12 @@ async function saveRecord() {
|
|
|
154
153
|
record: record.value,
|
|
155
154
|
},
|
|
156
155
|
});
|
|
157
|
-
if (response?.error) {
|
|
156
|
+
if (response?.error && response?.error !== 'Operation aborted by hook') {
|
|
158
157
|
showErrorTost(response.error);
|
|
159
158
|
}
|
|
160
159
|
saving.value = false;
|
|
161
160
|
if (route.query.returnTo) {
|
|
162
|
-
router.push(route.query.returnTo);
|
|
161
|
+
router.push(<string>route.query.returnTo);
|
|
163
162
|
} else {
|
|
164
163
|
router.push({
|
|
165
164
|
name: 'resource-show',
|