@opengis/admin 0.2.7 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { resolveComponent as e, openBlock as r, createBlock as t } from "vue";
2
- import { _ as c } from "./import-file-1QgPYOHQ.js";
2
+ import { _ as c } from "./import-file-DtUVr-xP.js";
3
3
  const n = {};
4
4
  function s(_, p, a, i, f, m) {
5
5
  const o = e("router-view");
@@ -0,0 +1,128 @@
1
+ import { _ as g, u as x, c as m } from "./import-file-DtUVr-xP.js";
2
+ import { resolveComponent as f, openBlock as p, createElementBlock as y, createElementVNode as l, createBlock as w, createCommentVNode as k } from "vue";
3
+ const v = {
4
+ data() {
5
+ return {
6
+ formValues: {},
7
+ scheme: null,
8
+ table: "",
9
+ token: ""
10
+ };
11
+ },
12
+ mounted() {
13
+ this.getFormScheme();
14
+ },
15
+ methods: {
16
+ flattenMenu(e) {
17
+ const t = [];
18
+ return e.forEach((a) => {
19
+ a.menu ? t.push(...this.flattenMenu(a.menu)) : t.push(a);
20
+ }), t;
21
+ },
22
+ async getFormScheme() {
23
+ var i, n;
24
+ const e = this.flattenMenu(x.value);
25
+ e != null && e.length || this.$router.replace("/404");
26
+ const t = e == null ? void 0 : e.find((s) => {
27
+ var o, r;
28
+ return (s == null ? void 0 : s.path) == ((r = (o = this.$route) == null ? void 0 : o.query) == null ? void 0 : r.table);
29
+ });
30
+ t || this.$router.replace("/404");
31
+ const a = t == null ? void 0 : t.table;
32
+ this.table = a;
33
+ try {
34
+ const {
35
+ data: { form: s }
36
+ } = await m.get(`/api/template/table/${a}`), { data: o } = await m.get(
37
+ `/api/table/${this.table}/${(n = (i = this.$route) == null ? void 0 : i.query) == null ? void 0 : n.id}`
38
+ );
39
+ this.token = (o == null ? void 0 : o.token) || "", this.formValues = o || {};
40
+ const { data: r } = await m.get(`/api/template/form/${s}`);
41
+ this.scheme = (r == null ? void 0 : r.schema) || r;
42
+ } catch {
43
+ }
44
+ },
45
+ async onlyEditObject() {
46
+ var t, a, i, n, s, o, r, d, u;
47
+ const e = this.$refs.form;
48
+ try {
49
+ await e.doValidation(), await m.put(`/api/table/${this.token}`, this.formValues), await this.$notify({
50
+ title: "Успішно!",
51
+ message: "Об'єкт успішно створено",
52
+ type: "success"
53
+ });
54
+ } catch (c) {
55
+ const b = ((t = c == null ? void 0 : c.response) == null ? void 0 : t.data) || "";
56
+ let h = ((s = (n = (i = (a = Object.entries(e == null ? void 0 : e.formErrors)) == null ? void 0 : a[0]) == null ? void 0 : i[1]) == null ? void 0 : n[0]) == null ? void 0 : s.message) === "Це поле обов'язкове" ? "Заповніть обов'язкові поля" : (u = (d = (r = (o = Object.entries(e == null ? void 0 : e.formErrors)) == null ? void 0 : o[0]) == null ? void 0 : r[1]) == null ? void 0 : d[0]) == null ? void 0 : u.message;
57
+ this.$notify({
58
+ title: "Помилка!",
59
+ message: b || h || "Сталася помилка валідаціі",
60
+ type: "error"
61
+ });
62
+ }
63
+ },
64
+ async editObjectAndRedirect() {
65
+ var t, a, i, n, s, o, r, d, u;
66
+ const e = this.$refs.form;
67
+ try {
68
+ await e.doValidation(), await m.put(`/api/table/${this.token}`, this.formValues), await this.$router.back(), await this.$notify({
69
+ title: "Успішно!",
70
+ message: "Об'єкт успішно створено",
71
+ type: "success"
72
+ });
73
+ } catch (c) {
74
+ const b = ((t = c == null ? void 0 : c.response) == null ? void 0 : t.data) || "";
75
+ let h = ((s = (n = (i = (a = Object.entries(e == null ? void 0 : e.formErrors)) == null ? void 0 : a[0]) == null ? void 0 : i[1]) == null ? void 0 : n[0]) == null ? void 0 : s.message) === "Це поле обов'язкове" ? "Заповніть обов'язкові поля" : (u = (d = (r = (o = Object.entries(e == null ? void 0 : e.formErrors)) == null ? void 0 : o[0]) == null ? void 0 : r[1]) == null ? void 0 : d[0]) == null ? void 0 : u.message;
76
+ this.$notify({
77
+ title: "Помилка!",
78
+ message: b || h || "Сталася помилка валідаціі",
79
+ type: "error"
80
+ });
81
+ }
82
+ }
83
+ }
84
+ }, V = {
85
+ style: { width: "calc(100vw - 260px)" },
86
+ class: "bg-gray-50"
87
+ }, $ = { class: "h-[76px] mt-[15px] flex items-center justify-between mx-[20px] px-[20px] bg-white border rounded-xl" }, E = { class: "flex items-center gap-[6px]" }, j = {
88
+ style: { height: "calc(100vh - 155px)", width: "calc(100vw - 260px)" },
89
+ class: "bg-gray-50 p-[20px] flex"
90
+ }, O = { class: "bg-white w-full rounded-xl border p-[20px] overflow-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar:horizontal]:h-[8px] [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-track]:bg-neutral-700 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-500" };
91
+ function _(e, t, a, i, n, s) {
92
+ const o = f("VsForm");
93
+ return p(), y("div", V, [
94
+ l("div", $, [
95
+ t[4] || (t[4] = l("h2", { class: "text-xl font-medium" }, "Редагувати", -1)),
96
+ l("div", E, [
97
+ l("button", {
98
+ onClick: t[0] || (t[0] = (r) => e.$router.back()),
99
+ class: "flex items-center px-3 py-2 text-sm font-medium text-gray-800 duration-300 bg-white border border-gray-100 rounded-lg shadow gap-x-2 focus:outline-none hover:bg-gray-50 hover:border-gray-100"
100
+ }, " Повернутися "),
101
+ l("button", {
102
+ onClick: t[1] || (t[1] = (...r) => s.onlyEditObject && s.onlyEditObject(...r)),
103
+ class: "inline-flex items-center px-3 py-2 text-sm font-medium text-white duration-300 bg-blue-600 border border-transparent rounded-lg gap-x-2 hover:bg-blue-700 hover:text-white"
104
+ }, " Зберегти "),
105
+ l("button", {
106
+ onClick: t[2] || (t[2] = (...r) => s.editObjectAndRedirect && s.editObjectAndRedirect(...r)),
107
+ class: "inline-flex items-center px-3 py-2 text-sm font-medium text-white duration-300 bg-blue-600 border border-transparent rounded-lg gap-x-2 hover:bg-blue-700 hover:text-white"
108
+ }, " Зберегти і повернутися ")
109
+ ])
110
+ ]),
111
+ l("div", j, [
112
+ l("div", O, [
113
+ n.scheme ? (p(), w(o, {
114
+ key: 0,
115
+ ref: "form",
116
+ scheme: n.scheme,
117
+ modelValue: n.formValues,
118
+ "onUpdate:modelValue": t[3] || (t[3] = (r) => n.formValues = r),
119
+ class: "p-0 mt-[20px]"
120
+ }, null, 8, ["scheme", "modelValue"])) : k("", !0)
121
+ ])
122
+ ])
123
+ ]);
124
+ }
125
+ const M = /* @__PURE__ */ g(v, [["render", _]]);
126
+ export {
127
+ M as default
128
+ };
@@ -3594,16 +3594,16 @@ function rD(t) {
3594
3594
  }
3595
3595
  const sD = [
3596
3596
  // { name: 'profile', path: '/profile', component: () => import('../components/profile/vs-profile.vue') },
3597
- { name: "edit", path: "/edit", component: () => import("./edit-page-TnYoAVr7.js") },
3598
- { name: "add", path: "/add", component: () => import("./add-page-Dv6JSPJD.js") },
3597
+ { name: "edit", path: "/edit", component: () => import("./edit-page-Boj91vBk.js") },
3598
+ { name: "add", path: "/add", component: () => import("./add-page-691SOUZb.js") },
3599
3599
  {
3600
3600
  name: "card-view",
3601
3601
  path: "/card",
3602
- component: () => import("./card-view-DbHBF1Gz.js"),
3602
+ component: () => import("./card-view-CX7x_aTI.js"),
3603
3603
  children: [{
3604
3604
  name: "table",
3605
3605
  path: ":table",
3606
- component: () => import("./card-view-DbHBF1Gz.js"),
3606
+ component: () => import("./card-view-CX7x_aTI.js"),
3607
3607
  children: [{ name: "card", path: ":id", component: () => Promise.resolve().then(() => u7) }]
3608
3608
  }]
3609
3609
  }
@@ -3657,14 +3657,14 @@ const uD = /* @__PURE__ */ Tt(oD, [["render", cD]]), hD = (t) => {
3657
3657
  {
3658
3658
  path: "/",
3659
3659
  name: "home",
3660
- component: () => import("./admin-view-xT8rj54J.js"),
3660
+ component: () => import("./admin-view-EqjCuhXc.js"),
3661
3661
  children: [
3662
3662
  ...e,
3663
3663
  ...t,
3664
3664
  // { path: '/', redirect: '/home' },
3665
3665
  {
3666
3666
  path: "/:catchAll(.*)",
3667
- component: () => import("./admin-interface-BWZcS6r_.js")
3667
+ component: () => import("./admin-interface-BOJ8_vEA.js")
3668
3668
  }
3669
3669
  ]
3670
3670
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -24,5 +24,6 @@ export default async function route() {
24
24
  handlebars.registerHelper('badge', badge);
25
25
  handlebars.registerHelper('contentList', contentList);
26
26
  handlebarsSync.registerHelper('ifCond', ifCond);
27
+ handlebarsSync.registerHelper('button', buttonHelper);
27
28
  handlebars.registerHelper('ifCond', ifCond);
28
29
  }
@@ -13,6 +13,12 @@ export default async function plugin(fastify) {
13
13
  const user1 = config?.auth?.disable || process.env.NODE_ENV !== 'admin' ? { uid: '1' } : null;
14
14
  await initPG(client);
15
15
 
16
+ addHook('preForm', async ({ form, user }) => {
17
+ if (!user?.uid) return null;
18
+ const opt = await getToken({ mode: 'w', token: form, uid: user.uid, json: 1 });
19
+ return opt;
20
+ });
21
+
16
22
  fastify.addHook('onListen', async () => {
17
23
  const json = await getMenu({ user: { uid: 1 } });
18
24
  // insert interface list to db (user access management)
@@ -22,17 +22,19 @@ export default async function getTemplateApi(req) {
22
22
  ) {
23
23
  return `access restricted ${name}`;
24
24
  }
25
- /* if (type === 'form' && user?.uid) {
25
+ if (type === 'form' && user?.uid) {
26
26
  const schema = data.schema || data;
27
27
  Object.keys(schema || {}).filter((key) => schema?.[key]?.add).map((key) => {
28
+ const { add } = schema[key];
29
+ Object.assign(add, { table: add.table || add.model }); // support old forms w/ model key
28
30
  const [token] = setToken({
29
- ids: [JSON.stringify(schema[key].add)],
31
+ ids: [JSON.stringify(add)],
30
32
  uid: user.uid,
31
33
  array: 1,
32
34
  });
33
- Object.assign(schema[key].add, { form: token });
35
+ Object.assign(schema[key].add, { token, api: `${config.prefix || '/api'}/table/${token}` });
34
36
  });
35
- } */
37
+ }
36
38
  await applyHook('afterTemplate', { name, type, data, user });
37
39
  if (tokenData.obj) {
38
40
  const obj = tokenData.obj.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {})
@@ -1,120 +0,0 @@
1
- import { _ as d, u as m, c as n } from "./import-file-1QgPYOHQ.js";
2
- import { resolveComponent as b, openBlock as u, createElementBlock as h, createElementVNode as a, createBlock as f, createCommentVNode as p } from "vue";
3
- const g = {
4
- data() {
5
- return {
6
- formValues: {},
7
- scheme: null,
8
- table: "",
9
- token: ""
10
- };
11
- },
12
- mounted() {
13
- this.getFormScheme();
14
- },
15
- methods: {
16
- flattenMenu(t) {
17
- const e = [];
18
- return t.forEach((l) => {
19
- l.menu ? e.push(...this.flattenMenu(l.menu)) : e.push(l);
20
- }), e;
21
- },
22
- async getFormScheme() {
23
- var c, i;
24
- const t = this.flattenMenu(m.value);
25
- t != null && t.length || this.$router.replace("/404");
26
- const e = t == null ? void 0 : t.find((o) => {
27
- var s, r;
28
- return (o == null ? void 0 : o.path) == ((r = (s = this.$route) == null ? void 0 : s.query) == null ? void 0 : r.table);
29
- });
30
- e || this.$router.replace("/404");
31
- const l = e == null ? void 0 : e.table;
32
- this.table = l;
33
- try {
34
- const {
35
- data: { form: o }
36
- } = await n.get(`/api/template/table/${l}`), { data: s } = await n.get(
37
- `/api/table/${this.table}/${(i = (c = this.$route) == null ? void 0 : c.query) == null ? void 0 : i.id}`
38
- );
39
- this.token = (s == null ? void 0 : s.token) || "", this.formValues = s || {};
40
- const { data: r } = await n.get(`/api/template/form/${o}`);
41
- this.scheme = (r == null ? void 0 : r.schema) || r;
42
- } catch {
43
- }
44
- },
45
- async onlyEditObject() {
46
- try {
47
- await this.$refs.form.doValidation(), await n.put(`/api/table/${this.token}`, this.formValues), await this.$notify({
48
- title: "Успішно!",
49
- message: "Об'єкт успішно створено",
50
- type: "success"
51
- });
52
- } catch {
53
- this.$notify({
54
- title: "Помилка!",
55
- message: "Сталася помилка",
56
- type: "error"
57
- });
58
- }
59
- },
60
- async editObjectAndRedirect() {
61
- try {
62
- await this.$refs.form.doValidation(), await n.put(`/api/table/${this.token}`, this.formValues), await this.$router.back(), await this.$notify({
63
- title: "Успішно!",
64
- message: "Об'єкт успішно створено",
65
- type: "success"
66
- });
67
- } catch {
68
- this.$notify({
69
- title: "Помилка!",
70
- message: "Сталася помилка",
71
- type: "error"
72
- });
73
- }
74
- }
75
- }
76
- }, x = {
77
- style: { width: "calc(100vw - 260px)" },
78
- class: "bg-gray-50"
79
- }, y = { class: "h-[76px] mt-[15px] flex items-center justify-between mx-[20px] px-[20px] bg-white border rounded-xl" }, w = { class: "flex items-center gap-[6px]" }, k = {
80
- style: { height: "calc(100vh - 155px)", width: "calc(100vw - 260px)" },
81
- class: "bg-gray-50 p-[20px] flex"
82
- }, v = { class: "bg-white w-full rounded-xl border p-[20px] overflow-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar:horizontal]:h-[8px] [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-track]:bg-neutral-700 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-500" };
83
- function V(t, e, l, c, i, o) {
84
- const s = b("VsForm");
85
- return u(), h("div", x, [
86
- a("div", y, [
87
- e[4] || (e[4] = a("h2", { class: "text-xl font-medium" }, "Редагувати", -1)),
88
- a("div", w, [
89
- a("button", {
90
- onClick: e[0] || (e[0] = (r) => t.$router.back()),
91
- class: "flex items-center px-3 py-2 text-sm font-medium text-gray-800 duration-300 bg-white border border-gray-100 rounded-lg shadow gap-x-2 focus:outline-none hover:bg-gray-50 hover:border-gray-100"
92
- }, " Повернутися "),
93
- a("button", {
94
- onClick: e[1] || (e[1] = (...r) => o.onlyEditObject && o.onlyEditObject(...r)),
95
- class: "inline-flex items-center px-3 py-2 text-sm font-medium text-white duration-300 bg-blue-600 border border-transparent rounded-lg gap-x-2 hover:bg-blue-700 hover:text-white"
96
- }, " Зберегти "),
97
- a("button", {
98
- onClick: e[2] || (e[2] = (...r) => o.editObjectAndRedirect && o.editObjectAndRedirect(...r)),
99
- class: "inline-flex items-center px-3 py-2 text-sm font-medium text-white duration-300 bg-blue-600 border border-transparent rounded-lg gap-x-2 hover:bg-blue-700 hover:text-white"
100
- }, " Зберегти і повернутися ")
101
- ])
102
- ]),
103
- a("div", k, [
104
- a("div", v, [
105
- i.scheme ? (u(), f(s, {
106
- key: 0,
107
- ref: "form",
108
- scheme: i.scheme,
109
- modelValue: i.formValues,
110
- "onUpdate:modelValue": e[3] || (e[3] = (r) => i.formValues = r),
111
- class: "p-0 mt-[20px]"
112
- }, null, 8, ["scheme", "modelValue"])) : p("", !0)
113
- ])
114
- ])
115
- ]);
116
- }
117
- const j = /* @__PURE__ */ d(g, [["render", V]]);
118
- export {
119
- j as default
120
- };