@hostlink/nuxt-light 0.0.103 → 0.0.105

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/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "light",
3
3
  "configKey": "light",
4
- "version": "0.0.103"
4
+ "version": "0.0.105"
5
5
  }
package/dist/module.mjs CHANGED
@@ -59,7 +59,8 @@ const module = defineNuxtModule({
59
59
  { name: "getModelColumns", from },
60
60
  { name: "getModelFields", from },
61
61
  { name: "getModelField", from },
62
- { name: "getGQLFields", from }
62
+ { name: "getGQLFields", from },
63
+ { name: "model", from }
63
64
  ]);
64
65
  addPlugin({
65
66
  src: resolver.resolve("./runtime/plugin"),
@@ -1,8 +1,8 @@
1
1
  <script setup>
2
2
  import { ref } from "vue";
3
3
  import { useRouter, useRoute } from "vue-router";
4
- import { useQuasar } from "quasar";
5
- import { addObject, updateObject } from '../';
4
+ import { Dialog } from "quasar";
5
+ import { model } from "@hostlink/light"
6
6
 
7
7
  const route = useRoute();
8
8
  const router = useRouter();
@@ -32,7 +32,6 @@ const props = defineProps({
32
32
 
33
33
  const loading = ref(false)
34
34
 
35
- const que = useQuasar();
36
35
  const emit = defineEmits(["save", "submit"]);
37
36
  const save = async () => {
38
37
 
@@ -44,37 +43,30 @@ const save = async () => {
44
43
  emit('submit');
45
44
  }
46
45
 
47
-
48
-
49
46
  if (props.modelValue) {
50
47
  const [module, id_name] = route.name.split("-");
51
48
 
52
-
53
- if (route.params[id_name]) {//edit
54
-
55
-
56
-
57
- try {
58
- if (await updateObject(module, parseInt(route.params[id_name]), props.modelValue)) {
49
+ try {
50
+ if (route.params[id_name]) {//edit
51
+ if (await model(module).update(parseInt(route.params[id_name]), props.modelValue)) {
52
+ router.push(`/${module}`);
53
+ return;
54
+ }
55
+ } else {
56
+ if (await model(module).add(props.modelValue)) {
59
57
  router.push(`/${module}`);
60
58
  return;
61
59
  }
62
- } catch (e) {
63
- //show error
64
- que.dialog({
65
- title: "Error",
66
- message: e.message,
67
- ok: "OK"
68
- });
69
-
70
- }
71
- } else { // add
72
- if (await addObject(module, props.modelValue)) {
73
- router.push(`/${module}`);
74
- return;
75
60
  }
61
+ } catch (e) {
62
+ Dialog.create({
63
+ title: "Error",
64
+ message: e.message,
65
+ ok: "OK"
66
+ });
76
67
  }
77
68
  }
69
+
78
70
  loading.value = false
79
71
  }
80
72
  const onSubmit = (e) => {
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
2
  import { useHead, useLight } from "#imports";
3
3
  import { useRouter, useRoute } from "vue-router"
4
- import { removeObject, getID } from '../'
4
+ import { model, getID } from '../'
5
5
 
6
6
  const router = useRouter();
7
7
  const route = useRoute();
@@ -80,7 +80,7 @@ title = title.trim()
80
80
  const module = route.path.split("/")[1];
81
81
  const onDelete = async () => {
82
82
 
83
- if (await removeObject(module, getID())) {
83
+ if (await model(module).delete(getID())) {
84
84
  router.push(`/${module}`);
85
85
  }
86
86
  }
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { useQuasar, QTable, is } from 'quasar';
3
3
  import { ref, computed, onMounted, useSlots, useAttrs } from "vue";
4
- import { t, deleteObject, q, useLight, GQLFieldBuilder } from '../';
4
+ import { t, q, useLight, GQLFieldBuilder, model } from '../';
5
5
  import { toQuery } from '@hostlink/light';
6
6
 
7
7
  const errors = ref<InstanceType<any>>([]);
@@ -436,7 +436,7 @@ const qua = useQuasar();
436
436
  const onDelete = async (id: any) => {
437
437
 
438
438
  try {
439
- await deleteObject(modelName.value, id)
439
+ await model(modelName.value).delete(id);
440
440
  } catch (e: any) {
441
441
  qua.notify({
442
442
  message: e.message,
@@ -1,4 +1,3 @@
1
- import addObject from "./addObject";
2
1
  import f from "./f";
3
2
  import getApiUrl from "./getApiUrl";
4
3
  import getCurrentUser from "./getCurrentUser";
@@ -6,8 +5,6 @@ import getObject from "./getObject";
6
5
  import list from "./list";
7
6
  import m from "./m";
8
7
  import q from "./q";
9
- import removeObject from "./removeObject";
10
- import deleteObject from "./deleteObject";
11
8
  import t from "./t";
12
9
  import updateObject from "./updateObject";
13
10
  import listObject from "./listObject";
@@ -18,8 +15,9 @@ import getModelField from './getModelField';
18
15
  import getModelFields from './getModelFields';
19
16
  import getModelColumns from './getModelColumns';
20
17
  import sv from './sv';
18
+ import model from './model';
21
19
  declare const notify: (message: string, color?: string) => void;
22
20
  import getID from "./getID";
23
21
  declare const getApiBase: () => {};
24
22
  import { getGQLFields } from '@hostlink/light';
25
- export { addObject, f, getApiUrl, getCurrentUser, getObject, list, m, q, removeObject, t, updateObject, notify, getID, deleteObject, listObject, isGranted, getApiBase, loadObject, GQLFieldBuilder, getModelField, getModelFields, getModelColumns, getGQLFields, sv };
23
+ export { f, getApiUrl, getCurrentUser, getObject, list, m, q, t, updateObject, notify, getID, listObject, isGranted, getApiBase, loadObject, GQLFieldBuilder, getModelField, getModelFields, getModelColumns, getGQLFields, sv, model };
@@ -1,6 +1,5 @@
1
1
  import { useRuntimeConfig } from "nuxt/app";
2
2
  import { Notify } from "quasar";
3
- import addObject from "./addObject.mjs";
4
3
  import f from "./f.mjs";
5
4
  import getApiUrl from "./getApiUrl.mjs";
6
5
  import getCurrentUser from "./getCurrentUser.mjs";
@@ -8,8 +7,6 @@ import getObject from "./getObject.mjs";
8
7
  import list from "./list.mjs";
9
8
  import m from "./m.mjs";
10
9
  import q from "./q.mjs";
11
- import removeObject from "./removeObject.mjs";
12
- import deleteObject from "./deleteObject.mjs";
13
10
  import t from "./t.mjs";
14
11
  import updateObject from "./updateObject.mjs";
15
12
  import listObject from "./listObject.mjs";
@@ -20,6 +17,7 @@ import getModelField from "./getModelField.mjs";
20
17
  import getModelFields from "./getModelFields.mjs";
21
18
  import getModelColumns from "./getModelColumns.mjs";
22
19
  import sv from "./sv.mjs";
20
+ import model from "./model.mjs";
23
21
  const notify = function(message, color = "green") {
24
22
  Notify.create({
25
23
  message,
@@ -34,7 +32,6 @@ const getApiBase = () => {
34
32
  };
35
33
  import { getGQLFields } from "@hostlink/light";
36
34
  export {
37
- addObject,
38
35
  f,
39
36
  getApiUrl,
40
37
  getCurrentUser,
@@ -42,12 +39,10 @@ export {
42
39
  list,
43
40
  m,
44
41
  q,
45
- removeObject,
46
42
  t,
47
43
  updateObject,
48
44
  notify,
49
45
  getID,
50
- deleteObject,
51
46
  listObject,
52
47
  isGranted,
53
48
  getApiBase,
@@ -57,5 +52,6 @@ export {
57
52
  getModelFields,
58
53
  getModelColumns,
59
54
  getGQLFields,
60
- sv
55
+ sv,
56
+ model
61
57
  };
@@ -1,4 +1,4 @@
1
- import { Fields } from "@hostlink/light";
1
+ import { type Fields } from "@hostlink/light";
2
2
  export default function list(name: string, props?: {
3
3
  sort?: string;
4
4
  filters?: object;
@@ -0,0 +1,10 @@
1
+ declare const _default: (name: string) => {
2
+ name: string;
3
+ update(id: number, data: Object): Promise<any>;
4
+ delete(id: number): Promise<any>;
5
+ add(data: Object): Promise<any>;
6
+ fields(fields: string[]): import("@hostlink/light").ModelField[];
7
+ get(filters: any, fields: import("@hostlink/light").Fields): Promise<any>;
8
+ list(filters: any, fields: import("@hostlink/light").Fields): Promise<any>;
9
+ };
10
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { model, getModelField } from "@hostlink/light";
2
+ export default (name) => {
3
+ const m = model(name);
4
+ return Object.assign(m, {
5
+ columns(fields) {
6
+ let columns = [];
7
+ for (let f of fields) {
8
+ const field = getModelField(name, f);
9
+ if (!field)
10
+ continue;
11
+ const option = field.getRaw();
12
+ option.name = field.getName();
13
+ columns.push(option);
14
+ }
15
+ return columns;
16
+ }
17
+ });
18
+ return m;
19
+ };
@@ -1,9 +1,7 @@
1
1
  <script setup>
2
- import { getModelColumns } from "#imports"
3
- const columns = getModelColumns('EventLog', ['eventlog_id', 'class', 'id', 'action', 'created_time', 'username'])
4
-
2
+ import { model } from "#imports"
3
+ const columns = model('EventLog').columns(['eventlog_id', 'class', 'id', 'action', 'created_time', 'username'])
5
4
  </script>
6
-
7
5
  <template>
8
6
  <l-page>
9
7
  <l-table @request="$event.loadObjects('EventLog')" :columns="columns" sort-by="eventlog_id:desc"
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
- import { getModelColumns } from "#imports"
2
+ import { model } from "#imports"
3
3
  import { ref } from 'vue'
4
- const columns = getModelColumns("MailLog", ["maillog_id", "from", "to", "subject", "created_time"])
4
+ const columns = model("MailLog").columns(["maillog_id", "from", "to", "subject", "created_time"])
5
5
 
6
6
 
7
7
  columns.push({
@@ -16,7 +16,7 @@ const content = ref("")
16
16
  <template>
17
17
  <l-page>
18
18
  <q-dialog v-model="show" full-width>
19
- <l-card>
19
+ <l-card title="Mail content">
20
20
  <q-card-section>
21
21
  <iframe width="100%" height="500px" :srcdoc="content" frameborder="0"></iframe>
22
22
  </q-card-section>
@@ -1,11 +1,11 @@
1
1
  <script setup>
2
2
  import { ref } from 'vue'
3
- import getModelColumns from "../../lib/getModelColumns";
3
+ import { model } from "#imports"
4
4
  const onRequest = async (request) => {
5
5
  request.loadObjects("User", { status: status.value });
6
6
  //request.loadObjects("User");
7
7
  };
8
- const columns = getModelColumns("User", [ "username", "first_name", "label_name", "email", "phone", "join_date", "status"]);
8
+ const columns = model("User").columns(["username", "first_name", "label_name", "email", "phone", "join_date", "status"]);
9
9
  const status = ref("0");
10
10
  </script>
11
11
 
@@ -1,6 +1,6 @@
1
1
  <script setup>
2
- import getModelColumns from "../../lib/getModelColumns";
3
- const columns = getModelColumns("UserLog", ["userlog_id", "username", "login_dt", "logout_dt", "result", "user_agent"]);
2
+ import { model } from "#imports"
3
+ const columns = model("UserLog").columns(["userlog_id", "username", "login_dt", "logout_dt", "result", "user_agent"]);
4
4
  </script>
5
5
  <template>
6
6
  <l-page>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/nuxt-light",
3
- "version": "0.0.103",
3
+ "version": "0.0.105",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": "@hostlink/nuxt-light",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- declare const _default: (name: string, data: Object) => Promise<any>;
2
- export default _default;
@@ -1,23 +0,0 @@
1
- import { Dialog } from "quasar";
2
- import m from "./m.mjs";
3
- import { VariableType } from "json-to-graphql-query";
4
- export default async (name, data) => {
5
- try {
6
- const variables = {};
7
- Object.entries(data).forEach(([key, value]) => {
8
- if (value instanceof File) {
9
- variables[key] = {
10
- type: "Upload!",
11
- value
12
- };
13
- data[key] = new VariableType(key);
14
- }
15
- });
16
- return await m(`add${name}`, { data }, [{ __variables: variables }]);
17
- } catch (e) {
18
- Dialog.create({
19
- title: "Error",
20
- message: e.message
21
- });
22
- }
23
- };
@@ -1 +0,0 @@
1
- export default function deleteObject(name: string, id: number): Promise<any>;
@@ -1,12 +0,0 @@
1
- import { Dialog } from "quasar";
2
- import m from "./m.mjs";
3
- export default async function deleteObject(name, id) {
4
- try {
5
- return await m(`delete${name}`, { id });
6
- } catch (e) {
7
- Dialog.create({
8
- title: "Error",
9
- message: e.message
10
- });
11
- }
12
- }
@@ -1 +0,0 @@
1
- export default function removeObject(name: string, id: number): Promise<any>;
@@ -1,12 +0,0 @@
1
- import { Dialog } from "quasar";
2
- import m from "./m.mjs";
3
- export default async function removeObject(name, id) {
4
- try {
5
- return await m(`remove${name}`, { id });
6
- } catch (e) {
7
- Dialog.create({
8
- title: "Error",
9
- message: e.message
10
- });
11
- }
12
- }