adminforth 1.0.17 → 1.0.25
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.js → mongo.ts} +16 -11
- package/dataConnectors/{postgres.js → postgres.ts} +6 -2
- package/dataConnectors/{sqlite.js → sqlite.ts} +6 -2
- package/dist/auth.js +68 -0
- package/dist/dataConnectors/mongo.js +204 -0
- package/dist/dataConnectors/postgres.js +298 -0
- package/dist/dataConnectors/sqlite.js +261 -0
- package/dist/index.js +693 -0
- package/dist/modules/codeInjector.js +346 -0
- package/dist/modules/utils.js +12 -0
- package/dist/servers/express.js +210 -0
- package/dist/spa/src/main.js +16 -0
- package/dist/spa/src/router/index.js +79 -0
- package/dist/spa/src/stores/core.js +154 -0
- package/dist/spa/src/stores/modal.js +35 -0
- package/dist/spa/src/utils.js +59 -0
- package/dist/spa/vite.config.js +44 -0
- package/dist/spa_tmp/src/custom/custom/vueUses.js +10 -0
- package/dist/spa_tmp/src/main.js +29 -0
- package/dist/spa_tmp/src/router/index.js +83 -0
- package/dist/spa_tmp/src/stores/core.js +150 -0
- package/dist/spa_tmp/src/stores/modal.js +35 -0
- package/dist/spa_tmp/src/utils.js +59 -0
- package/dist/spa_tmp/vite.config.js +43 -0
- package/dist/types.js +30 -0
- package/{index.js → index.ts} +115 -6
- package/modules/{codeInjector.js → codeInjector.ts} +29 -13
- package/package.json +9 -3
- package/servers/{express.js → express.ts} +8 -2
- package/spa/package.json +2 -2
- package/spa/src/views/ListView.vue +1 -1
- package/tsconfig.json +112 -0
- package/{types.js → types.ts} +2 -0
- /package/{auth.js → auth.ts} +0 -0
- /package/modules/{utils.js → utils.ts} +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useCoreStore = void 0;
|
|
16
|
+
const vue_1 = require("vue");
|
|
17
|
+
const pinia_1 = require("pinia");
|
|
18
|
+
const utils_1 = require("@/utils");
|
|
19
|
+
const router_1 = __importDefault(require("@/router"));
|
|
20
|
+
function findHomepage(menu) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
for (const item of menu) {
|
|
23
|
+
if (item.homepage) {
|
|
24
|
+
return item;
|
|
25
|
+
}
|
|
26
|
+
if (item.children) {
|
|
27
|
+
const res = findHomepage(item.children);
|
|
28
|
+
if (res) {
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.useCoreStore = (0, pinia_1.defineStore)('core', () => {
|
|
37
|
+
const resourceById = (0, vue_1.ref)([]);
|
|
38
|
+
const menu = (0, vue_1.ref)([]);
|
|
39
|
+
const config = (0, vue_1.ref)({});
|
|
40
|
+
const record = (0, vue_1.ref)({});
|
|
41
|
+
const resourceColumns = (0, vue_1.ref)(null);
|
|
42
|
+
const resourceColumnsError = (0, vue_1.ref)('');
|
|
43
|
+
const resourceColumnsId = (0, vue_1.ref)(null);
|
|
44
|
+
const user = (0, vue_1.ref)(null);
|
|
45
|
+
function fetchMenuAndResource() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const resp = yield (0, utils_1.callAdminForthApi)({
|
|
48
|
+
path: '/get_base_config',
|
|
49
|
+
method: 'GET',
|
|
50
|
+
});
|
|
51
|
+
menu.value = resp.menu;
|
|
52
|
+
resourceById.value = resp.resources.reduce((acc, resource) => {
|
|
53
|
+
acc[resource.resourceId] = resource;
|
|
54
|
+
return acc;
|
|
55
|
+
}, {});
|
|
56
|
+
config.value = resp.config;
|
|
57
|
+
user.value = resp.user;
|
|
58
|
+
// find homepage:true in menu recuresively
|
|
59
|
+
if (import.meta.env.DEV) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const homepage = yield findHomepage(menu.value);
|
|
64
|
+
if (homepage) {
|
|
65
|
+
if (homepage.resourceId) {
|
|
66
|
+
// redirect to homepage
|
|
67
|
+
router_1.default.push({ name: 'resource-list', params: { resourceId: homepage.resourceId } });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// redirect to path
|
|
71
|
+
router_1.default.push(homepage.path);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function fetchRecord(_a) {
|
|
78
|
+
return __awaiter(this, arguments, void 0, function* ({ resourceId, primaryKey }) {
|
|
79
|
+
record.value = null;
|
|
80
|
+
record.value = yield (0, utils_1.callAdminForthApi)({
|
|
81
|
+
path: '/get_record',
|
|
82
|
+
method: 'POST',
|
|
83
|
+
body: {
|
|
84
|
+
resourceId: resourceId,
|
|
85
|
+
primaryKey: primaryKey,
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function fetchColumns(_a) {
|
|
91
|
+
return __awaiter(this, arguments, void 0, function* ({ resourceId }) {
|
|
92
|
+
if (resourceColumnsId.value === resourceId && resourceColumns.value) {
|
|
93
|
+
// already fetched
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
resourceColumnsId.value = resourceId;
|
|
97
|
+
resourceColumns.value = null;
|
|
98
|
+
resourceColumnsError.value = '';
|
|
99
|
+
const res = yield (0, utils_1.callAdminForthApi)({
|
|
100
|
+
path: '/get_resource_columns',
|
|
101
|
+
method: 'POST',
|
|
102
|
+
body: {
|
|
103
|
+
resourceId,
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (res.error) {
|
|
107
|
+
resourceColumnsError.value = res.error;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
resourceColumns.value = res.resource.columns;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function getPublicConfig() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const res = yield (0, utils_1.callAdminForthApi)({
|
|
117
|
+
path: '/get_public_config',
|
|
118
|
+
method: 'GET',
|
|
119
|
+
});
|
|
120
|
+
config.value = Object.assign(Object.assign({}, config.value), res);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function logout() {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
yield (0, utils_1.callAdminForthApi)({
|
|
126
|
+
path: '/logout',
|
|
127
|
+
method: 'POST',
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const username = (0, vue_1.computed)(() => {
|
|
132
|
+
const usernameField = config.value.usernameField;
|
|
133
|
+
return user.value && user.value[usernameField];
|
|
134
|
+
});
|
|
135
|
+
const userFullname = (0, vue_1.computed)(() => {
|
|
136
|
+
const userFullnameField = config.value.userFullnameField;
|
|
137
|
+
return user.value && user.value[userFullnameField];
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
config,
|
|
141
|
+
resourceById,
|
|
142
|
+
menu,
|
|
143
|
+
username,
|
|
144
|
+
userFullname,
|
|
145
|
+
getPublicConfig,
|
|
146
|
+
fetchMenuAndResource,
|
|
147
|
+
fetchRecord,
|
|
148
|
+
record,
|
|
149
|
+
resourceColumns,
|
|
150
|
+
fetchColumns,
|
|
151
|
+
resourceColumnsError,
|
|
152
|
+
logout
|
|
153
|
+
};
|
|
154
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useModalStore = void 0;
|
|
4
|
+
const vue_1 = require("vue");
|
|
5
|
+
const pinia_1 = require("pinia");
|
|
6
|
+
exports.useModalStore = (0, pinia_1.defineStore)('modal', () => {
|
|
7
|
+
const modalContent = (0, vue_1.ref)({
|
|
8
|
+
title: 'title',
|
|
9
|
+
content: 'content',
|
|
10
|
+
acceptText: 'acceptText',
|
|
11
|
+
cancelText: 'cancelText',
|
|
12
|
+
});
|
|
13
|
+
const isOpened = (0, vue_1.ref)(false);
|
|
14
|
+
const onAcceptFunction = (0, vue_1.ref)(() => { });
|
|
15
|
+
function togleModal() {
|
|
16
|
+
isOpened.value = !isOpened.value;
|
|
17
|
+
}
|
|
18
|
+
function setOnAcceptFunction(func) {
|
|
19
|
+
onAcceptFunction.value = func;
|
|
20
|
+
}
|
|
21
|
+
function setModalContent(content) {
|
|
22
|
+
modalContent.value = content;
|
|
23
|
+
}
|
|
24
|
+
function resetmodalState() {
|
|
25
|
+
isOpened.value = false;
|
|
26
|
+
modalContent.value = {
|
|
27
|
+
title: 'title',
|
|
28
|
+
content: 'content',
|
|
29
|
+
acceptText: 'acceptText',
|
|
30
|
+
cancelText: 'cancelText',
|
|
31
|
+
};
|
|
32
|
+
setOnAcceptFunction(() => { });
|
|
33
|
+
}
|
|
34
|
+
return { isOpened, setModalContent, togleModal, modalContent, setOnAcceptFunction, onAcceptFunction, resetmodalState };
|
|
35
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getIcon = exports.callAdminForthApi = exports.callApi = void 0;
|
|
16
|
+
const vue_1 = require("vue");
|
|
17
|
+
const router_1 = __importDefault(require("./router"));
|
|
18
|
+
function callApi(_a) {
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* ({ path, method, body = undefined }) {
|
|
20
|
+
const options = {
|
|
21
|
+
method,
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify(body),
|
|
26
|
+
};
|
|
27
|
+
const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
|
|
28
|
+
const r = yield fetch(fullPath, options);
|
|
29
|
+
if (r.status == 401) {
|
|
30
|
+
console.log('router', router_1.default);
|
|
31
|
+
router_1.default.push({ name: 'login' });
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return yield r.json();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.callApi = callApi;
|
|
38
|
+
function callAdminForthApi(_a) {
|
|
39
|
+
return __awaiter(this, arguments, void 0, function* ({ path, method, body = undefined }) {
|
|
40
|
+
try {
|
|
41
|
+
return callApi({ path: `/adminapi/v1${path}`, method, body });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error('error', e);
|
|
45
|
+
return { error: `Unexpected error: ${e}` };
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.callAdminForthApi = callAdminForthApi;
|
|
50
|
+
function getIcon(icon) {
|
|
51
|
+
// icon format is "feather:icon-name". We need to get IconName in pascal case
|
|
52
|
+
if (!icon.includes(':')) {
|
|
53
|
+
throw new Error('Icon name should be in format "icon-set:icon-name"');
|
|
54
|
+
}
|
|
55
|
+
const [iconSet, iconName] = icon.split(':');
|
|
56
|
+
const compName = 'Icon' + iconName.split('-').map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
57
|
+
return (0, vue_1.resolveComponent)(compName);
|
|
58
|
+
}
|
|
59
|
+
exports.getIcon = getIcon;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_url_1 = require("node:url");
|
|
7
|
+
const vite_1 = require("vite");
|
|
8
|
+
const plugin_vue_1 = __importDefault(require("@vitejs/plugin-vue"));
|
|
9
|
+
const customLogger = {
|
|
10
|
+
info(msg) {
|
|
11
|
+
// Filter out the lines containing '➜ Local:' or '➜ Network:'
|
|
12
|
+
if (!msg.includes('➜')) {
|
|
13
|
+
console.log(msg);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
warn(msg) {
|
|
17
|
+
console.warn(msg);
|
|
18
|
+
},
|
|
19
|
+
error(msg) {
|
|
20
|
+
console.error(msg);
|
|
21
|
+
},
|
|
22
|
+
clear() {
|
|
23
|
+
console.clear();
|
|
24
|
+
},
|
|
25
|
+
hasWarned: false,
|
|
26
|
+
};
|
|
27
|
+
// https://vitejs.dev/config/
|
|
28
|
+
exports.default = (0, vite_1.defineConfig)({
|
|
29
|
+
base: process.env.VITE_ADMINFORTH_PUBLIC_PATH || '/',
|
|
30
|
+
server: {
|
|
31
|
+
port: 5173,
|
|
32
|
+
strictPort: true, // better predictability
|
|
33
|
+
},
|
|
34
|
+
customLogger,
|
|
35
|
+
plugins: [
|
|
36
|
+
(0, plugin_vue_1.default)(),
|
|
37
|
+
],
|
|
38
|
+
resolve: {
|
|
39
|
+
alias: {
|
|
40
|
+
'@': (0, node_url_1.fileURLToPath)(new node_url_1.URL('./src', import.meta.url)),
|
|
41
|
+
'@@': (0, node_url_1.fileURLToPath)(new node_url_1.URL('./src/custom', import.meta.url)),
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const highcharts_vue_1 = __importDefault(require("highcharts-vue"));
|
|
7
|
+
function default_1(app) {
|
|
8
|
+
app.use(highcharts_vue_1.default);
|
|
9
|
+
}
|
|
10
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vue_1 = require("vue");
|
|
7
|
+
const pinia_1 = require("pinia");
|
|
8
|
+
const vue_flowbite_1 = require("@iconify-prerendered/vue-flowbite");
|
|
9
|
+
const vue_flowbite_2 = require("@iconify-prerendered/vue-flowbite");
|
|
10
|
+
const vue_flowbite_3 = require("@iconify-prerendered/vue-flowbite");
|
|
11
|
+
const vue_flowbite_4 = require("@iconify-prerendered/vue-flowbite");
|
|
12
|
+
const vue_flowbite_5 = require("@iconify-prerendered/vue-flowbite");
|
|
13
|
+
const vue_typcn_1 = require("@iconify-prerendered/vue-typcn");
|
|
14
|
+
const vue_flowbite_6 = require("@iconify-prerendered/vue-flowbite");
|
|
15
|
+
const vueUses_ts_1 = __importDefault(require("@/custom/./custom/vueUses.ts"));
|
|
16
|
+
const App_vue_1 = __importDefault(require("./App.vue"));
|
|
17
|
+
const router_1 = __importDefault(require("./router"));
|
|
18
|
+
const app = (0, vue_1.createApp)(App_vue_1.default);
|
|
19
|
+
app.component('IconChartPieSolid', vue_flowbite_1.IconChartPieSolid);
|
|
20
|
+
app.component('IconBrainSolid', vue_flowbite_2.IconBrainSolid);
|
|
21
|
+
app.component('IconHomeSolid', vue_flowbite_3.IconHomeSolid);
|
|
22
|
+
app.component('IconCaretRightSolid', vue_flowbite_4.IconCaretRightSolid);
|
|
23
|
+
app.component('IconUserSolid', vue_flowbite_5.IconUserSolid);
|
|
24
|
+
app.component('IconArchive', vue_typcn_1.IconArchive);
|
|
25
|
+
app.component('IconTrashBinOutline', vue_flowbite_6.IconTrashBinOutline);
|
|
26
|
+
app.use((0, pinia_1.createPinia)());
|
|
27
|
+
app.use(router_1.default);
|
|
28
|
+
(0, vueUses_ts_1.default)(app);
|
|
29
|
+
app.mount('#app');
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const vue_router_1 = require("vue-router");
|
|
30
|
+
const HomeView_vue_1 = __importDefault(require("../views/HomeView.vue"));
|
|
31
|
+
const ResourceParent_vue_1 = __importDefault(require("@/views/ResourceParent.vue"));
|
|
32
|
+
const ListView_vue_1 = __importDefault(require("@/views/ListView.vue"));
|
|
33
|
+
const ShowView_vue_1 = __importDefault(require("@/views/ShowView.vue"));
|
|
34
|
+
const EditView_vue_1 = __importDefault(require("@/views/EditView.vue"));
|
|
35
|
+
const CreateView_vue_1 = __importDefault(require("@/views/CreateView.vue"));
|
|
36
|
+
const router = (0, vue_router_1.createRouter)({
|
|
37
|
+
history: (0, vue_router_1.createWebHistory)(import.meta.env.BASE_URL),
|
|
38
|
+
routes: [
|
|
39
|
+
{
|
|
40
|
+
path: '/',
|
|
41
|
+
name: 'home',
|
|
42
|
+
component: HomeView_vue_1.default
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
path: '/login',
|
|
46
|
+
name: 'login',
|
|
47
|
+
component: () => Promise.resolve().then(() => __importStar(require('@/views/LoginView.vue')))
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
path: '/resource/:resourceId',
|
|
51
|
+
component: ResourceParent_vue_1.default,
|
|
52
|
+
name: 'resource',
|
|
53
|
+
children: [
|
|
54
|
+
{
|
|
55
|
+
path: '',
|
|
56
|
+
component: ListView_vue_1.default,
|
|
57
|
+
name: 'resource-list'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
path: 'show/:primaryKey',
|
|
61
|
+
component: ShowView_vue_1.default,
|
|
62
|
+
name: 'resource-show'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
path: 'edit/:primaryKey',
|
|
66
|
+
component: EditView_vue_1.default,
|
|
67
|
+
name: 'resource-edit'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
path: 'create',
|
|
71
|
+
component: CreateView_vue_1.default,
|
|
72
|
+
name: 'resource-create'
|
|
73
|
+
},
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
path: '/dashboard',
|
|
78
|
+
name: '/dashboard',
|
|
79
|
+
component: Promise.resolve().then(() => __importStar(require('@/custom/./custom/Dash.vue'))),
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
exports.default = router;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useCoreStore = void 0;
|
|
16
|
+
const vue_1 = require("vue");
|
|
17
|
+
const pinia_1 = require("pinia");
|
|
18
|
+
const utils_1 = require("@/utils");
|
|
19
|
+
const router_1 = __importDefault(require("@/router"));
|
|
20
|
+
function findHomepage(menu) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
for (const item of menu) {
|
|
23
|
+
if (item.homepage) {
|
|
24
|
+
return item;
|
|
25
|
+
}
|
|
26
|
+
if (item.children) {
|
|
27
|
+
const res = findHomepage(item.children);
|
|
28
|
+
if (res) {
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.useCoreStore = (0, pinia_1.defineStore)('core', () => {
|
|
37
|
+
const resourceById = (0, vue_1.ref)([]);
|
|
38
|
+
const menu = (0, vue_1.ref)([]);
|
|
39
|
+
const config = (0, vue_1.ref)({});
|
|
40
|
+
const record = (0, vue_1.ref)({});
|
|
41
|
+
const resourceColumns = (0, vue_1.ref)(null);
|
|
42
|
+
const resourceColumnsError = (0, vue_1.ref)('');
|
|
43
|
+
const resourceColumnsId = (0, vue_1.ref)(null);
|
|
44
|
+
const user = (0, vue_1.ref)(null);
|
|
45
|
+
function fetchMenuAndResource() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const resp = yield (0, utils_1.callAdminForthApi)({
|
|
48
|
+
path: '/get_base_config',
|
|
49
|
+
method: 'GET',
|
|
50
|
+
});
|
|
51
|
+
menu.value = resp.menu;
|
|
52
|
+
resourceById.value = resp.resources.reduce((acc, resource) => {
|
|
53
|
+
acc[resource.resourceId] = resource;
|
|
54
|
+
return acc;
|
|
55
|
+
}, {});
|
|
56
|
+
config.value = resp.config;
|
|
57
|
+
user.value = resp.user;
|
|
58
|
+
// find homepage:true in menu recuresively
|
|
59
|
+
const homepage = yield findHomepage(menu.value);
|
|
60
|
+
if (homepage) {
|
|
61
|
+
if (homepage.resourceId) {
|
|
62
|
+
// redirect to homepage
|
|
63
|
+
router_1.default.push({ name: 'resource-list', params: { resourceId: homepage.resourceId } });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// redirect to path
|
|
67
|
+
router_1.default.push(homepage.path);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function fetchRecord(_a) {
|
|
73
|
+
return __awaiter(this, arguments, void 0, function* ({ resourceId, primaryKey }) {
|
|
74
|
+
record.value = null;
|
|
75
|
+
record.value = yield (0, utils_1.callAdminForthApi)({
|
|
76
|
+
path: '/get_record',
|
|
77
|
+
method: 'POST',
|
|
78
|
+
body: {
|
|
79
|
+
resourceId: resourceId,
|
|
80
|
+
primaryKey: primaryKey,
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function fetchColumns(_a) {
|
|
86
|
+
return __awaiter(this, arguments, void 0, function* ({ resourceId }) {
|
|
87
|
+
console.log('fetchColumns 1', resourceId, resourceColumnsId.value);
|
|
88
|
+
if (resourceColumnsId.value === resourceId && resourceColumns.value) {
|
|
89
|
+
// already fetched
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
resourceColumnsId.value = resourceId;
|
|
93
|
+
resourceColumns.value = null;
|
|
94
|
+
resourceColumnsError.value = '';
|
|
95
|
+
const res = yield (0, utils_1.callAdminForthApi)({
|
|
96
|
+
path: '/get_resource_columns',
|
|
97
|
+
method: 'POST',
|
|
98
|
+
body: {
|
|
99
|
+
resourceId,
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (res.error) {
|
|
103
|
+
resourceColumnsError.value = res.error;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
resourceColumns.value = res.resource.columns;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function getPublicConfig() {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const res = yield (0, utils_1.callAdminForthApi)({
|
|
113
|
+
path: '/get_public_config',
|
|
114
|
+
method: 'GET',
|
|
115
|
+
});
|
|
116
|
+
config.value = Object.assign(Object.assign({}, config.value), res);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function logout() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
yield (0, utils_1.callAdminForthApi)({
|
|
122
|
+
path: '/logout',
|
|
123
|
+
method: 'POST',
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const username = (0, vue_1.computed)(() => {
|
|
128
|
+
const usernameField = config.value.usernameField;
|
|
129
|
+
return user.value && user.value[usernameField];
|
|
130
|
+
});
|
|
131
|
+
const userFullname = (0, vue_1.computed)(() => {
|
|
132
|
+
const userFullnameField = config.value.userFullnameField;
|
|
133
|
+
return user.value && user.value[userFullnameField];
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
config,
|
|
137
|
+
resourceById,
|
|
138
|
+
menu,
|
|
139
|
+
username,
|
|
140
|
+
userFullname,
|
|
141
|
+
getPublicConfig,
|
|
142
|
+
fetchMenuAndResource,
|
|
143
|
+
fetchRecord,
|
|
144
|
+
record,
|
|
145
|
+
resourceColumns,
|
|
146
|
+
fetchColumns,
|
|
147
|
+
resourceColumnsError,
|
|
148
|
+
logout
|
|
149
|
+
};
|
|
150
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useModalStore = void 0;
|
|
4
|
+
const vue_1 = require("vue");
|
|
5
|
+
const pinia_1 = require("pinia");
|
|
6
|
+
exports.useModalStore = (0, pinia_1.defineStore)('modal', () => {
|
|
7
|
+
const modalContent = (0, vue_1.ref)({
|
|
8
|
+
title: 'title',
|
|
9
|
+
content: 'content',
|
|
10
|
+
acceptText: 'acceptText',
|
|
11
|
+
cancelText: 'cancelText',
|
|
12
|
+
});
|
|
13
|
+
const isOpened = (0, vue_1.ref)(false);
|
|
14
|
+
const onAcceptFunction = (0, vue_1.ref)(() => { });
|
|
15
|
+
function togleModal() {
|
|
16
|
+
isOpened.value = !isOpened.value;
|
|
17
|
+
}
|
|
18
|
+
function setOnAcceptFunction(func) {
|
|
19
|
+
onAcceptFunction.value = func;
|
|
20
|
+
}
|
|
21
|
+
function setModalContent(content) {
|
|
22
|
+
modalContent.value = content;
|
|
23
|
+
}
|
|
24
|
+
function resetmodalState() {
|
|
25
|
+
isOpened.value = false;
|
|
26
|
+
modalContent.value = {
|
|
27
|
+
title: 'title',
|
|
28
|
+
content: 'content',
|
|
29
|
+
acceptText: 'acceptText',
|
|
30
|
+
cancelText: 'cancelText',
|
|
31
|
+
};
|
|
32
|
+
setOnAcceptFunction(() => { });
|
|
33
|
+
}
|
|
34
|
+
return { isOpened, setModalContent, togleModal, modalContent, setOnAcceptFunction, onAcceptFunction, resetmodalState };
|
|
35
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getIcon = exports.callAdminForthApi = exports.callApi = void 0;
|
|
16
|
+
const vue_1 = require("vue");
|
|
17
|
+
const router_1 = __importDefault(require("./router"));
|
|
18
|
+
function callApi(_a) {
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* ({ path, method, body = undefined }) {
|
|
20
|
+
const options = {
|
|
21
|
+
method,
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify(body),
|
|
26
|
+
};
|
|
27
|
+
const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
|
|
28
|
+
const r = yield fetch(fullPath, options);
|
|
29
|
+
if (r.status == 401) {
|
|
30
|
+
console.log('router', router_1.default);
|
|
31
|
+
router_1.default.push({ name: 'login' });
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return yield r.json();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.callApi = callApi;
|
|
38
|
+
function callAdminForthApi(_a) {
|
|
39
|
+
return __awaiter(this, arguments, void 0, function* ({ path, method, body = undefined }) {
|
|
40
|
+
try {
|
|
41
|
+
return callApi({ path: `/adminapi/v1${path}`, method, body });
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error('error', e);
|
|
45
|
+
return { error: `Unexpected error: ${e}` };
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.callAdminForthApi = callAdminForthApi;
|
|
50
|
+
function getIcon(icon) {
|
|
51
|
+
// icon format is "feather:icon-name". We need to get IconName in pascal case
|
|
52
|
+
if (!icon.includes(':')) {
|
|
53
|
+
throw new Error('Icon name should be in format "icon-set:icon-name"');
|
|
54
|
+
}
|
|
55
|
+
const [iconSet, iconName] = icon.split(':');
|
|
56
|
+
const compName = 'Icon' + iconName.split('-').map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('');
|
|
57
|
+
return (0, vue_1.resolveComponent)(compName);
|
|
58
|
+
}
|
|
59
|
+
exports.getIcon = getIcon;
|