adminforth 1.1.65 → 1.1.66
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/dataConnectors/mongo.ts +7 -13
- package/dataConnectors/postgres.ts +2 -2
- package/dataConnectors/sqlite.ts +2 -2
- package/dist/dataConnectors/mongo.js +1 -9
- package/dist/index.js +1 -3
- package/dist/plugins/AuditLogPlugin/custom/AuditLogView.vue +7 -6
- package/dist/plugins/AuditLogPlugin/index.js +18 -13
- package/dist/spa/index.html +2 -2
- package/dist/spa/package-lock.json +17 -4
- package/dist/spa/package.json +2 -1
- package/dist/spa/spa/src/App.vue +24 -12
- package/dist/spa/spa/src/composables/useStores.ts +16 -4
- package/dist/spa/spa/src/main.ts +1 -1
- package/dist/spa/src/App.vue +125 -45
- package/dist/spa/src/assets/logo.svg +19 -1
- package/dist/spa/src/components/AcceptModal.vue +2 -9
- package/dist/spa/src/components/BreadcrumbsWithButtons.vue +1 -1
- package/dist/spa/src/components/CustomDatePicker.vue +16 -3
- package/dist/spa/src/components/CustomDateRangePicker.vue +11 -2
- package/dist/spa/src/components/Dropdown.vue +6 -1
- package/dist/spa/src/components/Filters.vue +40 -19
- package/dist/spa/src/components/ResourceForm.vue +26 -24
- package/dist/spa/src/components/ResourceListTable.vue +419 -0
- package/dist/spa/src/components/Toast.vue +66 -0
- package/dist/spa/src/components/ValueRenderer.vue +14 -8
- package/dist/spa/src/composables/useFrontendApi.ts +26 -0
- package/dist/spa/src/composables/useStores.ts +113 -0
- package/dist/spa/src/main.ts +1 -1
- package/dist/spa/src/router/index.ts +30 -20
- package/dist/spa/src/spa_types/core.ts +51 -0
- package/dist/spa/src/stores/core.ts +48 -31
- package/dist/spa/src/stores/filters.ts +22 -0
- package/dist/spa/src/stores/modal.ts +13 -3
- package/dist/spa/src/stores/toast.ts +15 -0
- package/dist/spa/src/stores/user.ts +54 -0
- package/dist/spa/src/utils.ts +62 -7
- package/dist/spa/src/views/CreateView.vue +67 -15
- package/dist/spa/src/views/EditView.vue +45 -11
- package/dist/spa/src/views/ListView.vue +82 -366
- package/dist/spa/src/views/LoginView.vue +16 -4
- package/dist/spa/src/views/ShowView.vue +105 -21
- package/dist/spa/tailwind.config.js +1 -1
- package/dist/spa/vite.config.ts +6 -0
- package/index.ts +4 -5
- package/package.json +1 -1
- package/plugins/AuditLogPlugin/custom/AuditLogView.vue +7 -6
- package/plugins/AuditLogPlugin/index.ts +23 -15
- package/spa/src/App.vue +24 -12
- package/spa/src/composables/useStores.ts +16 -4
- package/spa/src/main.ts +1 -1
- package/types/AdminForthConfig.ts +16 -3
- package/types/FrontendAPI.ts +1 -15
- package/dist/plugins/AccessControl/index.js +0 -66
- package/dist/plugins/AccessControl/types.js +0 -1
- package/dist/spa/public/favicon.ico +0 -0
- package/dist/spa/spa/public/favicon.ico +0 -0
- package/dist/types.js +0 -30
- /package/dist/spa/{spa/public → public/assets}/favicon.png +0 -0
package/dataConnectors/mongo.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import { MongoClient } from 'mongodb';
|
|
3
|
-
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections } from '../types/AdminForthConfig.js';
|
|
3
|
+
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections, AdminForthDataSourceConnector } from '../types/AdminForthConfig.js';
|
|
4
4
|
|
|
5
|
-
class MongoConnector {
|
|
5
|
+
class MongoConnector implements AdminForthDataSourceConnector {
|
|
6
6
|
db: MongoClient
|
|
7
7
|
|
|
8
|
-
constructor({ url }) {
|
|
8
|
+
constructor({ url }: { url: string }) {
|
|
9
9
|
this.db = new MongoClient(url);
|
|
10
10
|
(async () => {
|
|
11
11
|
try {
|
|
@@ -65,16 +65,10 @@ class MongoConnector {
|
|
|
65
65
|
|
|
66
66
|
getFieldValue(field, value) {
|
|
67
67
|
if (field.type == AdminForthDataTypes.DATETIME) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return dayjs.unix(+value).toISOString();
|
|
73
|
-
} else if (field._underlineType == 'varchar') {
|
|
74
|
-
return dayjs.unix(+value).toISOString();
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error(`AdminForth does not support row type: ${field._underlineType} for timestamps, use VARCHAR (with iso strings) or TIMESTAMP/INT (with unix timestamps)`);
|
|
77
|
-
}
|
|
68
|
+
if (!value) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return dayjs.unix(value).toISOString();
|
|
78
72
|
|
|
79
73
|
} else if (field.type == AdminForthDataTypes.DATE) {
|
|
80
74
|
if (!value) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import pkg from 'pg';
|
|
3
|
-
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections } from '../types/AdminForthConfig.js';
|
|
3
|
+
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections, AdminForthDataSourceConnector } from '../types/AdminForthConfig.js';
|
|
4
4
|
|
|
5
5
|
const { Client } = pkg;
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
class PostgresConnector {
|
|
8
|
+
class PostgresConnector implements AdminForthDataSourceConnector {
|
|
9
9
|
|
|
10
10
|
db: any;
|
|
11
11
|
|
package/dataConnectors/sqlite.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import betterSqlite3 from 'better-sqlite3';
|
|
2
|
-
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections } from '../types/AdminForthConfig.js';
|
|
2
|
+
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections, AdminForthDataSourceConnector } from '../types/AdminForthConfig.js';
|
|
3
3
|
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
|
|
6
|
-
class SQLiteConnector {
|
|
6
|
+
class SQLiteConnector implements AdminForthDataSourceConnector {
|
|
7
7
|
|
|
8
8
|
db: any;
|
|
9
9
|
|
|
@@ -71,15 +71,7 @@ class MongoConnector {
|
|
|
71
71
|
if (!value) {
|
|
72
72
|
return null;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
return dayjs.unix(+value).toISOString();
|
|
76
|
-
}
|
|
77
|
-
else if (field._underlineType == 'varchar') {
|
|
78
|
-
return dayjs.unix(+value).toISOString();
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
throw new Error(`AdminForth does not support row type: ${field._underlineType} for timestamps, use VARCHAR (with iso strings) or TIMESTAMP/INT (with unix timestamps)`);
|
|
82
|
-
}
|
|
74
|
+
return dayjs.unix(value).toISOString();
|
|
83
75
|
}
|
|
84
76
|
else if (field.type == AdminForthDataTypes.DATE) {
|
|
85
77
|
if (!value) {
|
package/dist/index.js
CHANGED
|
@@ -633,11 +633,9 @@ class AdminForth {
|
|
|
633
633
|
let userFullName = '';
|
|
634
634
|
if (adminUser.isRoot) {
|
|
635
635
|
username = this.config.rootUser.username;
|
|
636
|
-
console.log(username, 'this is the root');
|
|
637
636
|
}
|
|
638
637
|
else {
|
|
639
638
|
const dbUser = adminUser.dbUser;
|
|
640
|
-
console.log(dbUser, 'this is the db user', adminUser, 'this is the admin user');
|
|
641
639
|
username = dbUser[this.config.auth.usernameField];
|
|
642
640
|
userFullName = dbUser[this.config.auth.userFullNameField];
|
|
643
641
|
}
|
|
@@ -1031,7 +1029,7 @@ class AdminForth {
|
|
|
1031
1029
|
}
|
|
1032
1030
|
// execute hook if needed
|
|
1033
1031
|
for (const hook of listify((_3 = (_2 = resource.hooks) === null || _2 === void 0 ? void 0 : _2.edit) === null || _3 === void 0 ? void 0 : _3.afterSave)) {
|
|
1034
|
-
const resp = yield hook({ resource, record, adminUser });
|
|
1032
|
+
const resp = yield hook({ resource, record, adminUser, oldRecord });
|
|
1035
1033
|
if (!resp || (!resp.ok && !resp.error)) {
|
|
1036
1034
|
throw new Error(`Hook afterSave must return object with {ok: true} or { error: 'Error' } `);
|
|
1037
1035
|
}
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
import VueDiff from 'vue-diff';
|
|
3
3
|
import { ref } from 'vue';
|
|
4
4
|
import 'vue-diff/dist/index.css';
|
|
5
|
-
|
|
6
|
-
const props = defineProps(['prev', 'current', 'meta']);
|
|
5
|
+
import { app } from '@/main';
|
|
7
6
|
|
|
8
7
|
app.use(VueDiff);
|
|
8
|
+
|
|
9
|
+
const props = defineProps(['column', 'record', 'meta', 'resource', 'adminUser']);
|
|
9
10
|
</script>
|
|
10
11
|
|
|
11
12
|
<template>
|
|
12
13
|
<Diff
|
|
13
14
|
:mode="'split'"
|
|
14
15
|
:theme="'light'"
|
|
15
|
-
:language="'
|
|
16
|
-
:prev="props.
|
|
17
|
-
:current="props.
|
|
16
|
+
:language="'JSON'"
|
|
17
|
+
:prev="props.record[props.meta.resourceColumns.resourceDataColumnName].oldRecord"
|
|
18
|
+
:current="props.record[props.meta.resourceColumns.resourceDataColumnName].newRecord"
|
|
18
19
|
/>
|
|
19
|
-
|
|
20
|
+
</template>
|
|
20
21
|
|
|
@@ -11,20 +11,26 @@ import AdminForthPlugin from "../base.js";
|
|
|
11
11
|
class AuditLogPlugin extends AdminForthPlugin {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
super(options, import.meta.url);
|
|
14
|
-
this.createLogRecord = (resource, action, data, user) => __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
this.createLogRecord = (resource, action, data, user, oldRecord) => __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
var _a;
|
|
16
16
|
const recordIdFieldName = (_a = resource.columns.find((c) => c.primaryKey === true)) === null || _a === void 0 ? void 0 : _a.name;
|
|
17
|
-
const recordId = data[recordIdFieldName];
|
|
17
|
+
const recordId = (data === null || data === void 0 ? void 0 : data[recordIdFieldName]) || (oldRecord === null || oldRecord === void 0 ? void 0 : oldRecord[recordIdFieldName]);
|
|
18
|
+
const connector = this.adminforth.connectors[resource.dataSource];
|
|
19
|
+
const newRecord = yield connector.getRecordByPrimaryKey(resource, recordId);
|
|
20
|
+
let newData = {
|
|
21
|
+
'oldRecord': oldRecord || {},
|
|
22
|
+
'newRecord': newRecord
|
|
23
|
+
};
|
|
24
|
+
// console.log('newData', newData)
|
|
18
25
|
const record = {
|
|
19
26
|
[this.options.resourceColumns.resourceIdColumnName]: resource.resourceId,
|
|
20
27
|
[this.options.resourceColumns.resourceActionColumnName]: action,
|
|
21
|
-
[this.options.resourceColumns.resourceDataColumnName]:
|
|
28
|
+
[this.options.resourceColumns.resourceDataColumnName]: newData,
|
|
22
29
|
[this.options.resourceColumns.resourceUserIdColumnName]: user.pk,
|
|
23
30
|
[this.options.resourceColumns.resourceRecordIdColumnName]: recordId,
|
|
24
31
|
[this.options.resourceColumns.resourceCreatedColumnName]: new Date()
|
|
25
32
|
};
|
|
26
33
|
const auditLogResource = this.adminforth.config.resources.find((r) => r.resourceId === this.auditLogResource);
|
|
27
|
-
console.log('rec', record);
|
|
28
34
|
yield this.adminforth.createResourceRecord({ resource: auditLogResource, record, adminUser: user });
|
|
29
35
|
return { ok: true };
|
|
30
36
|
});
|
|
@@ -49,18 +55,17 @@ class AuditLogPlugin extends AdminForthPlugin {
|
|
|
49
55
|
};
|
|
50
56
|
}
|
|
51
57
|
diffColumn.components = {
|
|
52
|
-
|
|
58
|
+
show: {
|
|
53
59
|
file: this.componentPath('AuditLogView.vue'),
|
|
54
60
|
meta: Object.assign(Object.assign({}, this.options), { pluginInstanceId: this.pluginInstanceId })
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
|
-
resource.columns.push(diffColumn);
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
60
65
|
const defaultHooks = {
|
|
61
|
-
create: {
|
|
62
|
-
edit: {
|
|
63
|
-
delete: {
|
|
66
|
+
create: { afterSave: [] },
|
|
67
|
+
edit: { afterSave: [] },
|
|
68
|
+
delete: { afterSave: [] }
|
|
64
69
|
};
|
|
65
70
|
if (!resource.hooks) {
|
|
66
71
|
resource.hooks = defaultHooks;
|
|
@@ -69,11 +74,11 @@ class AuditLogPlugin extends AdminForthPlugin {
|
|
|
69
74
|
resource.hooks = Object.assign(Object.assign({}, defaultHooks), resource.hooks);
|
|
70
75
|
}
|
|
71
76
|
Object.keys(resource.hooks).forEach((hook) => {
|
|
72
|
-
if (!Array.isArray(resource.hooks[hook].
|
|
73
|
-
resource.hooks[hook].
|
|
77
|
+
if (!Array.isArray(resource.hooks[hook].afterSave)) {
|
|
78
|
+
resource.hooks[hook].afterSave = [resource.hooks[hook].afterSave];
|
|
74
79
|
}
|
|
75
|
-
resource.hooks[hook].
|
|
76
|
-
return yield this.createLogRecord(resource, hook, record, adminUser);
|
|
80
|
+
resource.hooks[hook].afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ resource, record, adminUser, oldRecord }) {
|
|
81
|
+
return yield this.createLogRecord(resource, hook, record, adminUser, oldRecord);
|
|
77
82
|
}));
|
|
78
83
|
});
|
|
79
84
|
});
|
package/dist/spa/index.html
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
|
-
<link rel="icon" href="
|
|
5
|
+
<link rel="icon" href="/* IMPORTANT:ADMINFORTH FAVICON */">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title
|
|
7
|
+
<title>/* IMPORTANT:ADMINFORTH TITLE */</title>
|
|
8
8
|
<!--
|
|
9
9
|
<script>
|
|
10
10
|
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"flowbite-datepicker": "^1.2.6",
|
|
18
18
|
"pinia": "^2.1.7",
|
|
19
19
|
"unhead": "^1.9.12",
|
|
20
|
+
"uuid": "^10.0.0",
|
|
20
21
|
"vue": "^3.4.21",
|
|
21
22
|
"vue-router": "^4.3.0",
|
|
22
23
|
"vue-slider-component": "^4.1.0-beta.7"
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"sass": "^1.77.2",
|
|
37
38
|
"tailwindcss": "^3.4.3",
|
|
38
39
|
"typescript": "~5.4.0",
|
|
39
|
-
"vite": "^5.2.
|
|
40
|
+
"vite": "^5.2.13",
|
|
40
41
|
"vue-tsc": "^2.0.11"
|
|
41
42
|
}
|
|
42
43
|
},
|
|
@@ -4032,10 +4033,22 @@
|
|
|
4032
4033
|
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
|
|
4033
4034
|
"dev": true
|
|
4034
4035
|
},
|
|
4036
|
+
"node_modules/uuid": {
|
|
4037
|
+
"version": "10.0.0",
|
|
4038
|
+
"resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
|
|
4039
|
+
"integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
|
|
4040
|
+
"funding": [
|
|
4041
|
+
"https://github.com/sponsors/broofa",
|
|
4042
|
+
"https://github.com/sponsors/ctavan"
|
|
4043
|
+
],
|
|
4044
|
+
"bin": {
|
|
4045
|
+
"uuid": "dist/bin/uuid"
|
|
4046
|
+
}
|
|
4047
|
+
},
|
|
4035
4048
|
"node_modules/vite": {
|
|
4036
|
-
"version": "5.2.
|
|
4037
|
-
"resolved": "https://registry.npmjs.org/vite/-/vite-5.2.
|
|
4038
|
-
"integrity": "sha512
|
|
4049
|
+
"version": "5.2.13",
|
|
4050
|
+
"resolved": "https://registry.npmjs.org/vite/-/vite-5.2.13.tgz",
|
|
4051
|
+
"integrity": "sha512-SSq1noJfY9pR3I1TUENL3rQYDQCFqgD+lM6fTRAM8Nv6Lsg5hDLaXkjETVeBt+7vZBCMoibD+6IWnT2mJ+Zb/A==",
|
|
4039
4052
|
"dev": true,
|
|
4040
4053
|
"dependencies": {
|
|
4041
4054
|
"esbuild": "^0.20.1",
|
package/dist/spa/package.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"flowbite-datepicker": "^1.2.6",
|
|
22
22
|
"pinia": "^2.1.7",
|
|
23
23
|
"unhead": "^1.9.12",
|
|
24
|
+
"uuid": "^10.0.0",
|
|
24
25
|
"vue": "^3.4.21",
|
|
25
26
|
"vue-router": "^4.3.0",
|
|
26
27
|
"vue-slider-component": "^4.1.0-beta.7"
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"sass": "^1.77.2",
|
|
41
42
|
"tailwindcss": "^3.4.3",
|
|
42
43
|
"typescript": "~5.4.0",
|
|
43
|
-
"vite": "^5.2.
|
|
44
|
+
"vite": "^5.2.13",
|
|
44
45
|
"vue-tsc": "^2.0.11"
|
|
45
46
|
}
|
|
46
47
|
}
|
package/dist/spa/spa/src/App.vue
CHANGED
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
</style>
|
|
164
164
|
|
|
165
165
|
<script setup lang="ts">
|
|
166
|
-
import { computed, onMounted, ref, watch, defineComponent } from 'vue';
|
|
166
|
+
import { computed, onMounted, ref, watch, defineComponent, onBeforeMount } from 'vue';
|
|
167
167
|
import { RouterLink, RouterView } from 'vue-router';
|
|
168
168
|
import { initFlowbite } from 'flowbite'
|
|
169
169
|
import './index.scss'
|
|
@@ -211,6 +211,8 @@ const theme = ref('light');
|
|
|
211
211
|
function toggleTheme() {
|
|
212
212
|
theme.value = theme.value === 'light' ? 'dark' : 'light';
|
|
213
213
|
document.documentElement.classList.toggle('dark');
|
|
214
|
+
window.localStorage.setItem('theme', theme.value);
|
|
215
|
+
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
function clickOnMenuItem (label: string) {
|
|
@@ -237,14 +239,8 @@ async function initRouter() {
|
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
async function loadMenu() {
|
|
240
|
-
await coreStore.fetchMenuAndResource()
|
|
242
|
+
await coreStore.fetchMenuAndResource();
|
|
241
243
|
loginRedirectCheckIsReady.value = true;
|
|
242
|
-
|
|
243
|
-
coreStore.menu.forEach((item, i) => {
|
|
244
|
-
if (item.open) {
|
|
245
|
-
opened.value.push(i);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
244
|
}
|
|
249
245
|
|
|
250
246
|
|
|
@@ -256,16 +252,32 @@ watch(route, () => {
|
|
|
256
252
|
})
|
|
257
253
|
});
|
|
258
254
|
|
|
255
|
+
watch (()=>coreStore.menu, () => {
|
|
256
|
+
coreStore.menu.forEach((item, i) => {
|
|
257
|
+
if (item.open) {
|
|
258
|
+
opened.value.push(i);
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
watch([loggedIn, routerIsReady, loginRedirectCheckIsReady], ([l,r,lr]) => {
|
|
264
|
+
if (l && r && lr) {
|
|
265
|
+
setTimeout(() => {
|
|
266
|
+
initFlowbite();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
|
|
259
271
|
// initialize components based on data attribute selectors
|
|
260
272
|
onMounted(async () => {
|
|
261
273
|
loadMenu(); // run this in async mode
|
|
262
274
|
// before init flowbite we have to wait router initialized because it affects dom(our v-ifs) and fetch menu
|
|
263
275
|
await initRouter()
|
|
264
|
-
|
|
265
|
-
initFlowbite();
|
|
266
|
-
});
|
|
267
|
-
|
|
276
|
+
})
|
|
268
277
|
|
|
278
|
+
onBeforeMount(()=>{
|
|
279
|
+
theme.value = window.localStorage.getItem('theme') || 'light';
|
|
280
|
+
document.documentElement.classList.toggle('dark', theme.value === 'dark');
|
|
269
281
|
})
|
|
270
282
|
|
|
271
283
|
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { FrontendAPIInterface, ConfirmParams, AlertParams,
|
|
1
|
+
import type { FrontendAPIInterface, ConfirmParams, AlertParams, } from '../types/FrontendAPI';
|
|
2
|
+
import type { AdminForthFilterOperators } from '@/types/AdminForthConfig';
|
|
2
3
|
import { useToastStore } from '../stores/toast';
|
|
3
4
|
import { useModalStore } from '../stores/modal';
|
|
4
5
|
import { useCoreStore } from '@/stores/core';
|
|
@@ -6,9 +7,20 @@ import { useFiltersStore } from '@/stores/filters';
|
|
|
6
7
|
import router from '@/router'
|
|
7
8
|
import type { AdminForthResourceColumn } from '@/types/AdminForthConfig';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
type FilterParams = {
|
|
11
|
+
/**
|
|
12
|
+
* Field of resource to filter
|
|
13
|
+
*/
|
|
14
|
+
field: string;
|
|
15
|
+
/**
|
|
16
|
+
* Operator of filter
|
|
17
|
+
*/
|
|
18
|
+
operator: AdminForthFilterOperators;
|
|
19
|
+
/**
|
|
20
|
+
* Value of filter
|
|
21
|
+
*/
|
|
22
|
+
value: string | number | boolean ;
|
|
23
|
+
}
|
|
12
24
|
|
|
13
25
|
declare global {
|
|
14
26
|
interface Window {
|
package/dist/spa/spa/src/main.ts
CHANGED
package/dist/spa/src/App.vue
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<nav
|
|
3
|
-
v-if="loggedIn"
|
|
4
|
-
class="fixed h-14 top-0 z-
|
|
3
|
+
v-if="loggedIn && routerIsReady && loginRedirectCheckIsReady"
|
|
4
|
+
class="fixed h-14 top-0 z-20 w-full border-b shadow-sm bg-header-bg shadow-header-shadow dark:bg-header-bg-hover dark:border-nav-menu-devider">
|
|
5
5
|
<div class="px-3 py-3 lg:px-5 lg:pl-3">
|
|
6
6
|
<div class="flex items-center justify-between">
|
|
7
7
|
<div class="flex items-center justify-start rtl:justify-end">
|
|
8
|
-
<button
|
|
8
|
+
<button @click="sideBarOpen = !sideBarOpen"
|
|
9
|
+
type="button" class="inline-flex items-center p-2 text-sm rounded-lg sm:hidden hover:bg-nav-menu-bg-hover focus:outline-none focus:ring-2 focus:ring-nav-menu-devider dark:text-nav-menu-icons dark:hover:bg-nav-menu-bg-hover dark:focus:ring-nav-menu-devider">
|
|
9
10
|
<span class="sr-only">Open sidebar</span>
|
|
10
11
|
<svg class="w-6 h-6" aria-hidden="true" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
|
|
11
12
|
<path clip-rule="evenodd" fill-rule="evenodd" d="M2 4.75A.75.75 0 012.75 4h14.5a.75.75 0 010 1.5H2.75A.75.75 0 012 4.75zm0 10.5a.75.75 0 01.75-.75h7.5a.75.75 0 010 1.5h-7.5a.75.75 0 01-.75-.75zM2 10a.75.75 0 01.75-.75h14.5a.75.75 0 010 1.5H2.75A.75.75 0 012 10z"></path>
|
|
@@ -55,38 +56,41 @@
|
|
|
55
56
|
|
|
56
57
|
|
|
57
58
|
<aside
|
|
58
|
-
v-if="loggedIn"
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
v-if="loggedIn && routerIsReady && loginRedirectCheckIsReady"
|
|
61
|
+
|
|
62
|
+
id="logo-sidebar" class="fixed border-none top-0 left-0 z-20 w-64 h-screen transition-transform border-r border-nav-menu-border sm:translate-x-0 dark:bg-gray-800 dark:border-gray-700"
|
|
63
|
+
:class="{ '-translate-x-full': !sideBarOpen, 'transform-none': sideBarOpen }"
|
|
64
|
+
aria-label="Sidebar"
|
|
65
|
+
>
|
|
66
|
+
<div class="h-full px-3 pb-4 overflow-y-auto bg-white dark:bg-gray-800 border-r">
|
|
62
67
|
<div class="flex ms-2 md:me-24 m-4 ">
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
<img :src="loadFile(coreStore.config?.brandLogo || '@/assets/logo.svg')" :alt="`${ coreStore.config?.brandName } Logo`" class="h-8 me-3" />
|
|
69
|
+
<span class="self-center text-header-text-size font-semibold sm:text-header-text-size whitespace-nowrap dark:text-header-text text-header-logo-color">
|
|
70
|
+
{{ coreStore.config?.brandName }}
|
|
71
|
+
</span>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
68
74
|
<ul class="space-y-2 font-medium">
|
|
69
75
|
<template v-for="(item, i) in coreStore.menu" :key="`menu-${i}`">
|
|
70
76
|
<div v-if="item.type === 'divider'" class="border-t border-nav-menu-devider dark:border-gray-700"></div>
|
|
71
77
|
<div v-else-if="item.type === 'gap'" class="flex items-center justify-center h-8"></div>
|
|
72
78
|
<div v-else-if="item.type === 'heading'" class="flex items-center justify-left pl-2 h-8 text-gray-400 dark:text-gray-400
|
|
73
79
|
">{{ item.label }}</div>
|
|
74
|
-
|
|
75
|
-
|
|
76
80
|
<li v-else-if="item.children">
|
|
77
|
-
<button
|
|
81
|
+
<button @click="clickOnMenuItem(i)" type="button" class="flex items-center w-full p-2 text-base text-nav-menu-text rounded-default transition duration-75 group hover:bg-nav-menu-bg-hover dark:text-white dark:hover:bg-gray-700"
|
|
78
82
|
:aria-controls="`dropdown-example${i}`"
|
|
79
83
|
:data-collapse-toggle="`dropdown-example${i}`"
|
|
80
84
|
>
|
|
81
85
|
<component v-if="item.icon" :is="getIcon(item.icon)" class="w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 dark:group-hover:text-white" ></component>
|
|
82
86
|
|
|
83
87
|
<span class="flex-1 ms-3 text-left rtl:text-right whitespace-nowrap">{{ item.label }}</span>
|
|
84
|
-
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
|
|
88
|
+
<svg :class="{'rotate-180': opened.includes(i) }" class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
|
|
85
89
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4"/>
|
|
86
90
|
</svg>
|
|
87
91
|
</button>
|
|
88
92
|
|
|
89
|
-
<ul :id="`dropdown-example${i}`" role="none" class="pt-1 space-y-1" :class="{ 'hidden': !
|
|
93
|
+
<ul :id="`dropdown-example${i}`" role="none" class="pt-1 space-y-1" :class="{ 'hidden': !opened.includes(i) }">
|
|
90
94
|
<template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
|
|
91
95
|
<li>
|
|
92
96
|
<MenuLink :item="child" isChild="true" />
|
|
@@ -101,20 +105,61 @@
|
|
|
101
105
|
</ul>
|
|
102
106
|
</div>
|
|
103
107
|
</aside>
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
<div class="p-4 sm:ml-64 dark:bg-gray-800" v-if="loggedIn && routerIsReady && loginRedirectCheckIsReady">
|
|
106
111
|
<div class="p-0 dark:border-gray-700 mt-14">
|
|
107
112
|
<RouterView/>
|
|
108
113
|
</div>
|
|
109
114
|
</div>
|
|
110
115
|
|
|
111
|
-
<div v-else-if="routerIsReady">
|
|
116
|
+
<div v-else-if="routerIsReady && loginRedirectCheckIsReady">
|
|
112
117
|
<RouterView/>
|
|
113
118
|
</div>
|
|
119
|
+
<div v-else class="flex items-center justify-center h-screen">
|
|
120
|
+
<div class="text-3xl text-gray-400 animate-bounce">
|
|
121
|
+
<svg aria-hidden="true" class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" 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>
|
|
122
|
+
<span class="sr-only">Loading...</span>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
114
125
|
<AcceptModal />
|
|
126
|
+
<div v-if="toastStore.toasts.length>0" class="fixed bottom-5 right-5 flex gap-1 flex-col-reverse">
|
|
127
|
+
<transition-group
|
|
128
|
+
name="fade"
|
|
129
|
+
tag="div"
|
|
130
|
+
class="flex flex-col-reverse gap-1"
|
|
131
|
+
>
|
|
132
|
+
<Toast :toast="t" @close="toastStore.removeToast(t)" v-for="(t,i) in toastStore.toasts" :key="`t-${t.id}`" ></Toast>
|
|
133
|
+
</transition-group>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<div v-if="sideBarOpen"
|
|
137
|
+
@click="sideBarOpen = false"
|
|
138
|
+
|
|
139
|
+
drawer-backdrop="" class="bg-gray-900/50 dark:bg-gray-900/80 fixed inset-0 z-5"></div>
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
115
143
|
</template>
|
|
116
144
|
|
|
117
|
-
<style scoped>
|
|
145
|
+
<style lang="scss" scoped>
|
|
146
|
+
|
|
147
|
+
.fade-leave-active {
|
|
148
|
+
@apply transition-opacity duration-500;
|
|
149
|
+
}
|
|
150
|
+
.fade-leave-to {
|
|
151
|
+
@apply opacity-0;
|
|
152
|
+
}
|
|
153
|
+
.fade-enter-active {
|
|
154
|
+
@apply transition-opacity duration-500;
|
|
155
|
+
}
|
|
156
|
+
.fade-enter-from {
|
|
157
|
+
@apply opacity-0;
|
|
158
|
+
}
|
|
159
|
+
.fade-enter-to {
|
|
160
|
+
@apply opacity-100;
|
|
161
|
+
}
|
|
162
|
+
|
|
118
163
|
</style>
|
|
119
164
|
|
|
120
165
|
<script setup lang="ts">
|
|
@@ -123,6 +168,8 @@ import { RouterLink, RouterView } from 'vue-router';
|
|
|
123
168
|
import { initFlowbite } from 'flowbite'
|
|
124
169
|
import './index.scss'
|
|
125
170
|
import { useCoreStore } from '@/stores/core';
|
|
171
|
+
import { useUserStore } from '@/stores/user';
|
|
172
|
+
import {useModalStore} from '@/stores/modal';
|
|
126
173
|
import { IconMoonSolid, IconSunSolid } from '@iconify-prerendered/vue-flowbite';
|
|
127
174
|
import AcceptModal from './components/AcceptModal.vue';
|
|
128
175
|
import MenuLink from './components/MenuLink.vue';
|
|
@@ -130,25 +177,34 @@ import { useRoute, useRouter } from 'vue-router';
|
|
|
130
177
|
import { getIcon } from '@/utils';
|
|
131
178
|
import { useHead } from 'unhead'
|
|
132
179
|
import { createHead } from 'unhead'
|
|
180
|
+
import { loadFile } from '@/utils';
|
|
181
|
+
import Toast from './components/Toast.vue';
|
|
182
|
+
import {useToastStore} from '@/stores/toast';
|
|
183
|
+
import { FrontendAPI } from '@/composables/useStores'
|
|
133
184
|
// import { link } from 'fs';
|
|
134
185
|
const coreStore = useCoreStore();
|
|
135
|
-
|
|
136
|
-
|
|
186
|
+
const modalStore = useModalStore();
|
|
187
|
+
const toastStore = useToastStore();
|
|
188
|
+
const userStore = useUserStore();
|
|
189
|
+
const frontendApi = new FrontendAPI();
|
|
190
|
+
frontendApi.init();
|
|
191
|
+
const splitAtLast = (str: string, separator: string) => {
|
|
192
|
+
const index = str.lastIndexOf(separator);
|
|
193
|
+
return [str.slice(0, index), str.slice(index + 1)];
|
|
194
|
+
}
|
|
137
195
|
createHead()
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
196
|
+
const sideBarOpen = ref(false);
|
|
144
197
|
const route = useRoute();
|
|
145
198
|
const router = useRouter();
|
|
146
199
|
const title = ref('');
|
|
200
|
+
//create a ref to store the opened menu items with ts type;
|
|
201
|
+
const opened = ref<string[]>([]);
|
|
147
202
|
|
|
148
203
|
|
|
149
204
|
const routerIsReady = ref(false);
|
|
205
|
+
const loginRedirectCheckIsReady = ref(false);
|
|
150
206
|
|
|
151
|
-
const loggedIn = computed(() => route.name !== 'login'
|
|
207
|
+
const loggedIn = computed(() => route.name !== 'login');
|
|
152
208
|
|
|
153
209
|
const theme = ref('light');
|
|
154
210
|
|
|
@@ -157,9 +213,19 @@ function toggleTheme() {
|
|
|
157
213
|
document.documentElement.classList.toggle('dark');
|
|
158
214
|
}
|
|
159
215
|
|
|
216
|
+
function clickOnMenuItem (label: string) {
|
|
217
|
+
if (opened.value.includes(label)) {
|
|
218
|
+
opened.value = opened.value.filter((item) => item !== label);
|
|
219
|
+
} else {
|
|
220
|
+
opened.value.push(label);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
160
225
|
async function logout() {
|
|
161
|
-
|
|
162
|
-
|
|
226
|
+
userStore.unauthorize();
|
|
227
|
+
await userStore.logout();
|
|
228
|
+
router.push({ name: 'login' })
|
|
163
229
|
}
|
|
164
230
|
|
|
165
231
|
|
|
@@ -170,22 +236,36 @@ async function initRouter() {
|
|
|
170
236
|
routerIsReady.value = true;
|
|
171
237
|
}
|
|
172
238
|
|
|
239
|
+
async function loadMenu() {
|
|
240
|
+
await coreStore.fetchMenuAndResource()
|
|
241
|
+
loginRedirectCheckIsReady.value = true;
|
|
242
|
+
|
|
243
|
+
coreStore.menu.forEach((item, i) => {
|
|
244
|
+
if (item.open) {
|
|
245
|
+
opened.value.push(i);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
watch(route, () => {
|
|
253
|
+
title.value = `${coreStore.config?.title || coreStore.config?.brandName || 'Adminforth'} | ${ Object.values(route.params)[0] || route.meta.title || ' '}`;
|
|
254
|
+
useHead({
|
|
255
|
+
title: title.value,
|
|
256
|
+
})
|
|
257
|
+
});
|
|
258
|
+
|
|
173
259
|
// initialize components based on data attribute selectors
|
|
174
260
|
onMounted(async () => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
await
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
rel: 'icon',
|
|
184
|
-
href: coreStore.config.favicon || '/favicon.ico',
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
|
|
188
|
-
})
|
|
261
|
+
loadMenu(); // run this in async mode
|
|
262
|
+
// before init flowbite we have to wait router initialized because it affects dom(our v-ifs) and fetch menu
|
|
263
|
+
await initRouter()
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
initFlowbite();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
|
|
189
269
|
})
|
|
190
270
|
|
|
191
271
|
</script>
|