@hostlink/nuxt-light 0.0.80 → 0.0.81

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.80"
4
+ "version": "0.0.81"
5
5
  }
package/dist/module.mjs CHANGED
@@ -53,7 +53,7 @@ const module = defineNuxtModule({
53
53
  { name: "listObject", from },
54
54
  { name: "useLight", from: index },
55
55
  { name: "isGranted", from },
56
- { name: "getTypeColumns", from },
56
+ { name: "getObjectColumns", from },
57
57
  { name: "defineType", from }
58
58
  ]);
59
59
  addPlugin({
@@ -1,20 +1,24 @@
1
1
  <script setup>
2
- defineProps({
2
+ import { inject } from 'vue'
3
+ const props = defineProps({
3
4
  label: {
4
5
  type: String,
5
- required: true
6
6
  },
7
7
  type: {
8
8
  type: String,
9
9
  default: "text"
10
+ }, name: {
11
+ type: String,
12
+ default: null
10
13
  }
11
14
  });
15
+
16
+
12
17
  </script>
13
18
  <template>
14
19
  <q-item>
15
20
  <q-item-section>
16
21
  <q-item-label>{{ $t(label) }}</q-item-label>
17
-
18
22
  <q-item-label caption v-if="type == 'caption'">
19
23
  <div style="white-space: pre-wrap;">
20
24
  <slot></slot>
@@ -1,5 +1,51 @@
1
+ <script setup>
2
+
3
+ const props = defineProps({
4
+ modelValue: {
5
+ type: Object
6
+ },
7
+ columns: {
8
+ type: Array
9
+ }
10
+ })
11
+
12
+ const getValue = (column) => {
13
+
14
+ //type of column field is function
15
+ if (column.field && typeof column.field == 'function') {
16
+ return column.field(props.modelValue);
17
+ }
18
+
19
+ //if field is string
20
+ if (column.field && typeof column.field == 'string') {
21
+ return props.modelValue[column.field];
22
+ }
23
+
24
+ return props.modelValue[column.name];
25
+
26
+ }
27
+ const getDisplayValue = (column) => {
28
+ const value = getValue(column);
29
+
30
+ if (column.format) {
31
+ return column.format(value);
32
+ }
33
+ return value;
34
+
35
+ }
36
+
37
+ </script>
1
38
  <template>
2
39
  <q-list bordered separator>
3
- <slot></slot>
40
+ <template v-if="columns">
41
+ <l-item v-for="column in columns" :label="column.label">
42
+ {{ getDisplayValue(column) }}
43
+ </l-item>
44
+
45
+ </template>
46
+ <template v-else>
47
+ <slot></slot>
48
+ </template>
49
+
4
50
  </q-list>
5
51
  </template>
@@ -1,3 +1,3 @@
1
- declare const _default: (type: string, fields: Object) => void;
1
+ declare const _default: (name: string, fields: Object) => void;
2
2
  export default _default;
3
3
  export declare const getData: () => any;
@@ -0,0 +1,5 @@
1
+ let data = {};
2
+ export default (name, fields) => {
3
+ data[name] = fields;
4
+ };
5
+ export const getData = () => data;
@@ -1,13 +1,12 @@
1
1
  import { useRoute } from "vue-router";
2
2
  const route = useRoute();
3
3
  export default () => {
4
- let route2 = useRoute();
5
- let name = route2.name?.toString();
4
+ let name = route.name?.toString();
6
5
  if (name == void 0)
7
6
  return 0;
8
7
  let parts = name.split("-");
9
8
  const module = parts[0];
10
9
  const moduleLower = module.charAt(0).toLowerCase() + module.slice(1);
11
10
  const keyname = parts[1];
12
- return parseInt(route2.params[keyname]);
11
+ return parseInt(route.params[keyname]);
13
12
  };
@@ -1,5 +1,6 @@
1
1
  import { useRoute } from "vue-router";
2
2
  import loadObject from "./loadObject.mjs";
3
+ import getObjectColumn from "./getObjectColumn.mjs";
3
4
  export default async function(fields = []) {
4
5
  let route = useRoute();
5
6
  if (!route.name) {
@@ -12,5 +13,14 @@ export default async function(fields = []) {
12
13
  if (fields instanceof Array && fields.length == 0) {
13
14
  fields.push(id_name);
14
15
  }
15
- return await loadObject(module, filters, fields);
16
+ let fs = fields.map((field) => {
17
+ if (typeof field == "string") {
18
+ const column = getObjectColumn(module, field);
19
+ if (column && column.gqlField) {
20
+ return column.gqlField;
21
+ }
22
+ }
23
+ return field;
24
+ });
25
+ return await loadObject(module, filters, fs);
16
26
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: (type: string, name: string) => any;
2
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { getData } from "./defineObject.mjs";
2
+ export default (type, name) => {
3
+ let data = getData();
4
+ if (!data[type])
5
+ return;
6
+ if (!data[type][name])
7
+ return;
8
+ let options = data[type][name];
9
+ if (!options)
10
+ return;
11
+ if (!options.name) {
12
+ options.name = name;
13
+ }
14
+ return options;
15
+ };
@@ -1,4 +1,4 @@
1
- import { getData } from "./defineType.mjs";
1
+ import { getData } from "./defineObject.mjs";
2
2
  export default (type, names) => {
3
3
  let data = getData();
4
4
  let columns = [];
@@ -15,9 +15,9 @@ import listObject from "./listObject";
15
15
  import loadObject from "./loadObject";
16
16
  import isGranted from "./isGranted";
17
17
  import GQLFieldBuilder from "./GQLFieldBuilder";
18
- import getTypeColumns from "./getTypeColumns";
18
+ import getObjectColumns from "./getObjectColumns";
19
19
  declare const notify: (message: string, color?: string) => void;
20
20
  import getID from "./getID";
21
21
  declare const getApiBase: () => {};
22
- import defineType from './defineType';
23
- export { addObject, f, getApiUrl, getCurrentUser, getObject, list, listData, m, q, removeObject, t, updateObject, notify, getID, deleteObject, listObject, isGranted, getApiBase, loadObject, GQLFieldBuilder, defineType, getTypeColumns };
22
+ import defineObject from './defineObject';
23
+ export { addObject, f, getApiUrl, getCurrentUser, getObject, list, listData, m, q, removeObject, t, updateObject, notify, getID, deleteObject, listObject, isGranted, getApiBase, loadObject, GQLFieldBuilder, defineObject, getObjectColumns };
@@ -17,7 +17,7 @@ import listObject from "./listObject.mjs";
17
17
  import loadObject from "./loadObject.mjs";
18
18
  import isGranted from "./isGranted.mjs";
19
19
  import GQLFieldBuilder from "./GQLFieldBuilder.mjs";
20
- import getTypeColumns from "./getTypeColumns.mjs";
20
+ import getObjectColumns from "./getObjectColumns.mjs";
21
21
  const notify = function(message, color = "green") {
22
22
  Notify.create({
23
23
  message,
@@ -30,7 +30,7 @@ const getApiBase = () => {
30
30
  const config = useRuntimeConfig();
31
31
  return config?.public?.apiBase ?? "/api/";
32
32
  };
33
- import defineType from "./defineType.mjs";
33
+ import defineObject from "./defineObject.mjs";
34
34
  export {
35
35
  addObject,
36
36
  f,
@@ -52,6 +52,6 @@ export {
52
52
  getApiBase,
53
53
  loadObject,
54
54
  GQLFieldBuilder,
55
- defineType,
56
- getTypeColumns
55
+ defineObject,
56
+ getObjectColumns
57
57
  };
@@ -1,8 +1,8 @@
1
1
  <script setup>
2
2
  import { ref } from 'vue'
3
- import getTypeColumns from "../../lib/getTypeColumns";
3
+ import getObjectColumns from "../../lib/getObjectColumns";
4
4
  import sv from "../../lib/sv";
5
- const columns = getTypeColumns("SystemValue", ["name", "value"]);
5
+ const columns = getObjectColumns("SystemValue", ["name", "value"]);
6
6
  </script>
7
7
  <template>
8
8
  <l-page>
@@ -1,13 +1,6 @@
1
1
  <script setup>
2
- import { getObject, loadObject } from '../../../';
2
+ import { getObject, getObjectColumns } from '../../../';
3
3
  const obj = await getObject(["user_id", "username", "first_name", "last_name", "email", "phone", "roles", 'status', 'join_date']);
4
-
5
- //await getObject(["user_id", { test: ["username"] }])
6
- /* const test = async () => {
7
- console.log(await loadObject("User", { user_id: obj.user_id }, ["username"]));
8
- }
9
- */
10
-
11
4
  </script>
12
5
 
13
6
  <template>
@@ -18,16 +11,16 @@ const obj = await getObject(["user_id", "username", "first_name", "last_name", "
18
11
  </template>
19
12
 
20
13
  <l-card>
21
- <l-list>
22
- <l-item label="Username">{{ obj.username }}</l-item>
23
- <l-item label="First name">{{ obj.first_name }}</l-item>
24
- <l-item label="Last name">{{ obj.last_name }}</l-item>
25
- <l-item label="Email">{{ obj.email }}</l-item>
26
- <l-item label="Phone">{{ obj.phone }}</l-item>
27
- <l-item label="Roles">{{ obj.roles.join(",") }}</l-item>
28
- <l-item label="Status">{{ obj.status }}</l-item>
29
- <l-item label="Join date">{{ obj.join_date }}</l-item>
30
-
14
+ <l-list v-model="obj" :columns="getObjectColumns('User', [
15
+ 'username',
16
+ 'first_name',
17
+ 'last_name',
18
+ 'email',
19
+ 'phone',
20
+ 'roles',
21
+ 'status',
22
+ 'join_date'
23
+ ])">
31
24
  </l-list>
32
25
  </l-card>
33
26
  </l-page>
@@ -1,10 +1,10 @@
1
1
  <script setup>
2
2
  import { ref } from 'vue'
3
- import getTypeColumns from "../../lib/getTypeColumns";
3
+ import getObjectColumns from "../../lib/getObjectColumns";
4
4
  const onRequest = async (request) => {
5
5
  request.loadObjects("User", { status: status.value });
6
6
  };
7
- const columns = getTypeColumns("User", ["username", "first_name", "label_name", "email", "phone", "join_date"]);
7
+ const columns = getObjectColumns("User", ["username", "first_name", "label_name", "email", "phone", "join_date"]);
8
8
  const status = ref("0");
9
9
  </script>
10
10
 
@@ -1,6 +1,6 @@
1
1
  <script setup>
2
- import getTypeColumns from "../../lib/getTypeColumns";
3
- const columns = getTypeColumns("UserLog", ["userlog_id", "username", "login_dt", "logout_dt", "result", "user_agent"]);
2
+ import getObjectColumns from "../../lib/getObjectColumns";
3
+ const columns = getObjectColumns("UserLog", ["userlog_id", "username", "login_dt", "logout_dt", "result", "user_agent"]);
4
4
  </script>
5
5
  <template>
6
6
  <l-page>
@@ -7,14 +7,14 @@ import message_en from "./locales/en.json";
7
7
  import message_zh from "./locales/zh-hk.json";
8
8
  import routes from "./routes.mjs";
9
9
  localStorage.getItem("locale") || localStorage.setItem("locale", "en");
10
- import { useLight, defineType } from "./index.mjs";
10
+ import { useLight, defineObject } from "./index.mjs";
11
11
  import TypeUser from "./types/User.mjs";
12
12
  import TypeUserLog from "./types/UserLog.mjs";
13
13
  import TypeSystemValue from "./types/SystemValue.mjs";
14
14
  export default defineNuxtPlugin((nuxtApp) => {
15
- defineType("User", TypeUser);
16
- defineType("UserLog", TypeUserLog);
17
- defineType("SystemValue", TypeSystemValue);
15
+ defineObject("User", TypeUser);
16
+ defineObject("UserLog", TypeUserLog);
17
+ defineObject("SystemValue", TypeSystemValue);
18
18
  nuxtApp.vueApp.config.errorHandler = (error) => {
19
19
  console.log(error);
20
20
  const light = useLight();
@@ -30,5 +30,13 @@ declare const _default: {
30
30
  searchable: boolean;
31
31
  searchType: string;
32
32
  };
33
+ roles: {
34
+ label: string;
35
+ format: (value: any) => any;
36
+ };
37
+ status: {
38
+ label: string;
39
+ format: (value: any) => "Active" | "Inactive";
40
+ };
33
41
  };
34
42
  export default _default;
@@ -5,12 +5,12 @@ export default {
5
5
  searchable: true
6
6
  },
7
7
  first_name: {
8
- label: "First Name",
8
+ label: "First name",
9
9
  sortable: true,
10
10
  searchable: true
11
11
  },
12
12
  last_name: {
13
- label: "Last Name",
13
+ label: "Last name",
14
14
  sortable: true,
15
15
  searchable: true
16
16
  },
@@ -25,9 +25,19 @@ export default {
25
25
  searchable: true
26
26
  },
27
27
  join_date: {
28
- label: "Join Date",
28
+ label: "Join date",
29
29
  sortable: true,
30
30
  searchable: true,
31
31
  searchType: "date"
32
+ },
33
+ roles: {
34
+ label: "Roles",
35
+ format: (value) => value.join(", ")
36
+ },
37
+ status: {
38
+ label: "Status",
39
+ format: (value) => {
40
+ return value == 0 ? "Active" : "Inactive";
41
+ }
32
42
  }
33
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/nuxt-light",
3
- "version": "0.0.80",
3
+ "version": "0.0.81",
4
4
  "description": "HostLink Nuxt Light Framework",
5
5
  "repository": "@hostlink/nuxt-light",
6
6
  "license": "MIT",
@@ -1,5 +0,0 @@
1
- let data = {};
2
- export default (type, fields) => {
3
- data[type] = fields;
4
- };
5
- export const getData = () => data;