@simitgroup/simpleapp-generator 1.2.8 → 1.3.0-alpha

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.
Files changed (84) hide show
  1. package/dist/buildinschemas/organization.d.ts.map +1 -1
  2. package/dist/buildinschemas/organization.js +3 -1
  3. package/dist/buildinschemas/organization.js.map +1 -1
  4. package/dist/framework.d.ts.map +1 -1
  5. package/dist/framework.js +3 -8
  6. package/dist/framework.js.map +1 -1
  7. package/dist/generate.js +14 -14
  8. package/dist/generate.js.map +1 -1
  9. package/package.json +1 -1
  10. package/src/buildinschemas/organization.ts +3 -1
  11. package/src/framework.ts +4 -8
  12. package/src/generate.ts +17 -16
  13. package/templates/basic/nest/controller.ts.eta +17 -0
  14. package/templates/basic/nest/default.ts.eta +6 -2
  15. package/templates/basic/nuxt/default.ts.eta +10 -6
  16. package/templates/basic/nuxt/pages.[id].vue.eta +9 -7
  17. package/templates/basic/nuxt/pages.form.vue.eta +16 -36
  18. package/templates/basic/nuxt/pages.landing.vue.eta +42 -35
  19. package/templates/basic/nuxt/pages.viewer.vue.eta +4 -6
  20. package/templates/nest/.env._eta +0 -1
  21. package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +14 -2
  22. package/templates/nest/src/simpleapp/generate/controllers/simpleapp.controller.ts.eta +32 -18
  23. package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +76 -13
  24. package/templates/nuxt/assets/css/style.css._eta +19 -7
  25. package/templates/nuxt/assets/primevue/passthrough.ts._eta +20 -9
  26. package/templates/nuxt/components/button/ButtonDefault.vue._eta +1 -2
  27. package/templates/nuxt/components/button/ButtonMultiple.vue._eta +21 -0
  28. package/templates/nuxt/components/debug/DebugDocumentData.vue.eta +3 -4
  29. package/templates/nuxt/components/event/EventDocumentViewer.vue._eta +75 -65
  30. package/templates/nuxt/components/form/FormBranch.vue.eta +83 -0
  31. package/templates/nuxt/components/form/readme.md.eta +1 -0
  32. package/templates/nuxt/components/header/button/HeaderButtonMenuPicker.vue._eta +13 -11
  33. package/templates/nuxt/components/header/button/HeaderButtonProfile.vue.eta +11 -17
  34. package/templates/nuxt/components/list/ListDocument.vue.eta +25 -0
  35. package/templates/nuxt/components/list/ListDocumentTable.vue.eta +77 -0
  36. package/templates/nuxt/components/list/ListView.vue.eta +129 -60
  37. package/templates/nuxt/components/mobile/MobileToolbar.vue.eta +10 -0
  38. package/templates/nuxt/components/overlay/OverlaySideBarCrud.vue.eta +21 -0
  39. package/templates/nuxt/components/overlay/OverlayViewer.vue.eta +20 -0
  40. package/templates/nuxt/components/page/PageDocList.vue.eta +170 -0
  41. package/templates/nuxt/components/renderer/RendererBoolean.vue.eta +8 -4
  42. package/templates/nuxt/components/renderer/RendererDate.vue.eta +4 -4
  43. package/templates/nuxt/components/renderer/RendererLink.vue.eta +12 -20
  44. package/templates/nuxt/components/renderer/RendererViewer.vue.eta +27 -21
  45. package/templates/nuxt/components/simpleApp/SimpleAppAutocomplete.vue.eta +201 -174
  46. package/templates/nuxt/components/simpleApp/SimpleAppFieldContainer.vue.eta +115 -111
  47. package/templates/nuxt/components/simpleApp/SimpleAppFormToolBar.vue.eta +183 -91
  48. package/templates/nuxt/components/simpleApp/SimpleAppInput.vue.eta +383 -263
  49. package/templates/nuxt/components/table/TableDocuments.vue.eta +3 -3
  50. package/templates/nuxt/components/text/TextDanger.vue._eta +5 -0
  51. package/templates/nuxt/components/text/TextSubtitle.vue._eta +5 -0
  52. package/templates/nuxt/components/text/TextTitle.vue._eta +5 -0
  53. package/templates/nuxt/composables/date.generate.ts.eta +14 -9
  54. package/templates/nuxt/i18n.config.ts.eta +1 -1
  55. package/templates/nuxt/lang/en.ts.eta +16 -0
  56. package/templates/nuxt/layouts/default.vue._eta +32 -17
  57. package/templates/nuxt/layouts/mobile.vue._eta +35 -12
  58. package/templates/nuxt/nuxt.config.ts._eta +3 -7
  59. package/templates/nuxt/pages/[xorg]/organization/[id].vue.eta +39 -0
  60. package/templates/nuxt/pages/[xorg]/organization/new.vue.eta +30 -143
  61. package/templates/nuxt/pages/[xorg]/organization/viewer.vue.eta +3 -0
  62. package/templates/nuxt/pages/[xorg]/organization.vue.eta +81 -127
  63. package/templates/nuxt/pages/[xorg]/user/[id].vue.eta +38 -4
  64. package/templates/nuxt/pages/[xorg]/user/form.vue.eta +329 -0
  65. package/templates/nuxt/pages/[xorg]/user/index.vue.eta +29 -292
  66. package/templates/nuxt/pages/[xorg]/{organization/[id]/branches/[bid].vue → user/new.vue.eta} +10 -4
  67. package/templates/nuxt/pages/[xorg]/user/viewer.vue.eta +30 -0
  68. package/templates/nuxt/pages/[xorg]/user.vue.eta +88 -78
  69. package/templates/nuxt/pages/profile.vue.eta +12 -3
  70. package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +2 -3
  71. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +6 -0
  72. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +41 -2
  73. package/templates/nuxt/types/documentlist.ts.eta +0 -9
  74. package/templates/nuxt/types/events.ts.eta +1 -0
  75. package/templates/nuxt/types/simpleappinput.ts.eta +12 -2
  76. package/templates/nuxt/types/user.ts.eta +2 -0
  77. package/templates/project/lang/default._json +5 -0
  78. package/tsconfig.tsbuildinfo +1 -1
  79. package/templates/nuxt/components/docPage/DocPageList.vue.eta +0 -125
  80. package/templates/nuxt/lang/en.ts._eta +0 -6
  81. package/templates/nuxt/pages/[xorg]/organization/[bid].vue.eta +0 -14
  82. package/templates/nuxt/pages/[xorg]/organization/[id]/branches/new.vue +0 -149
  83. package/templates/nuxt/pages/[xorg]/organization/[id]/index.vue.eta +0 -1
  84. /package/templates/nuxt/lang/{df.ts.eta → df.ts.etaxxxx} +0 -0
@@ -1,160 +1,114 @@
1
+ <template>
2
+ <title>{{ t("organization") }}</title>
3
+ <div class="w-full flex-col flex">
4
+ <MobileToolbar>
5
+ <template #center>{{ t('organization') }}</template>
6
+ <template #end>
7
+ <ButtonText @click="showEditOrg=true"><i class="pi pi-pencil"></i></ButtonText>
8
+ </template>
9
+ </MobileToolbar>
10
+ <div class="w-full flex flex-row p-2">
11
+ <div class="p-4">
12
+ <div class="border w-12 h-12 md:w-24 md:h24"></div>
13
+ </div>
14
+ <div class="flex flex-col flex-1 ">
15
+ <TextTitle>{{ data.orgName }} / {{ data.orgCode }}</TextTitle>
16
+ <div class="text-gray-600 dark:text-gray-400 text-sm">{{ data.description }}</div>
17
+ <div class="text-gray-600 dark:text-gray-400 text-sm">
18
+ {{ data.country }}/{{ data.currency }}/{{ data.timeZone }}//{{ data.offsetMinute }}
19
+ </div>
20
+
21
+ </div>
22
+ </div>
23
+
24
+
25
+ <div class="w-full p-2">
26
+ <h1>Branches</h1>
27
+ <ButtonText @click="goBranch('new')">{{ t('addBranch') }}</ButtonText>
28
+ <ListView
29
+ :list="branchlist"
30
+ title-field="branchName"
31
+ sub-title-field="branchCode"
32
+ :url="getDocumentUrl('organization', id)"
33
+ >
34
+ </ListView>
35
+ </div>
36
+
37
+
38
+ <OverlaySideBarCrud v-model="showEditOrg" close-event-name="organization">
39
+ <FormOrganization :_id="getUserProfile()?.orgRecordId" @after="afterOrganization"></FormOrganization>
40
+ </OverlaySideBarCrud>
41
+
42
+ <OverlaySideBarCrud v-model="showEditBranch" close-event-name="branch">
43
+ <NuxtPage :_id="id"></NuxtPage>
44
+ </OverlaySideBarCrud>
45
+ </div>
46
+ </template>
47
+
1
48
  <script setup lang="ts">
2
- /**
3
- * This file was automatically generated by simpleapp everytime regenerate code.
4
- * delete file "delete-me-for-avoid-override" if you want to modify this file and
5
- * prevent regenerate code override it.
6
- * last change 2023-09-09
7
- * author: Ks Tan
8
- */
9
- import { SimpleAppInputType } from "~/types";
49
+
50
+ import { FormCrudEvent, SimpleAppInputType } from "~/types";
10
51
  import ConfirmPopup from "primevue/confirmpopup";
11
52
  import { useConfirm } from "primevue/useconfirm";
12
53
  const confirm = useConfirm();
54
+ const showEditOrg = ref<boolean>(false)
55
+ const showEditBranch = ref<boolean>(false)
13
56
 
14
57
  const { $OrganizationDoc, $BranchDoc, $event, $listen } = useNuxtApp();
58
+
59
+ const orgId = computed(()=><string>getUserProfile()?.orgRecordId)
15
60
  const doc = $OrganizationDoc();
16
61
  const brancdoc = $BranchDoc();
17
62
  const data = doc.getReactiveData();
18
63
  const branchlist = ref([]);
19
64
  const isReadOnly = ref(true);
20
65
  const getCurrentOrg = async () => {
21
- await doc.getById(getUserProfile().orgRecordId);
66
+ await doc.getById(orgId.value);
67
+ await fetchRecord()
22
68
  };
23
- const fetchRecord = async (id: string) => {
24
- await doc.getById(id);
69
+ const fetchRecord = async () => {
70
+ //fetch org
71
+ // await doc.getById(data.value.orgId);
72
+ //fetch branch
25
73
  branchlist.value = await brancdoc.search({
26
74
  filter: { orgId: data.value.orgId },
27
75
  });
76
+
77
+ console.log("reload data",branchlist)
28
78
  };
29
79
 
30
80
  const id = computed((): string => String(useRoute().params.id ?? ""));
31
- const updateData = async () => {
32
- doc
33
- .update()
34
- .then(() => {
35
- refresh();
36
- isReadOnly.value = true;
37
- })
38
- .catch((err) => {
39
- console.error(err);
40
- });
41
- };
42
81
 
43
- const refresh = () => {
44
- $event("RefreshDocumentList", { documentName: doc.getDocName() });
45
- };
46
82
 
47
83
  definePageMeta({
48
84
  menuPath: "setting/organization",
49
85
  });
50
86
 
51
87
  //branch record update then reload
52
- $listen("RefreshDocumentList", (data) => {
53
- console.log("refresh from branch", data.documentName, "==", doc.getDocName());
54
- if (data.documentName == "branch") {
55
- fetchRecord(id.value);
88
+ $listen("RefreshDocumentList", async (data) => {
89
+ console.log("trigger RefreshDocumentList",data)
90
+ if (data.documentName == "branch" || data.documentName == "organization") {
91
+ await fetchRecord();
56
92
  }
57
93
  });
58
94
 
59
- if (id) {
60
- fetchRecord(id.value);
95
+
96
+
97
+ const showBranchDialogIfRequired = () =>{
98
+ if(useRoute().path.includes('/new') || id.value) showEditBranch.value=true
99
+ }
100
+
101
+ const afterOrganization = (actionName:FormCrudEvent)=>{
102
+ if(actionName==FormCrudEvent.update){
103
+ showEditOrg.value=false
104
+ getCurrentOrg()
105
+ }
61
106
  }
62
107
 
108
+ watch(()=>useRoute().path,()=>showBranchDialogIfRequired())
109
+ onMounted(()=>showBranchDialogIfRequired())
63
110
  getCurrentOrg();
111
+
112
+
113
+
64
114
  </script>
65
- <template>
66
- <div class="grid grid-cols-3">
67
- <title>{{ t("organization") }}</title>
68
- <div class="">
69
- <Card>
70
- <template #header><h1 class="text-2xl">Organization</h1></template>
71
- <template #content>
72
- <SimpleAppForm #default="o" :document="doc" :readonly="isReadOnly">
73
- <div
74
- class="simpleapp-tool-bar col-span-4 text-left gap-4"
75
- v-if="canPerform(doc.getDocName(), 'update')"
76
- >
77
- <Button
78
- v-if="isReadOnly"
79
- class="btn btn-primary"
80
- @click="isReadOnly = false"
81
- type="button"
82
- >Edit</Button
83
- >
84
- <Button
85
- v-else
86
- class="btn btn-primary"
87
- @click="updateData"
88
- type="button"
89
- >Update</Button
90
- >
91
- <ConfirmPopup></ConfirmPopup>
92
- </div>
93
- <div class="flex flex-col">
94
- <div class="grid grid-cols-2 gap-4">
95
- <SimpleAppInput
96
- :input-type="SimpleAppInputType.text"
97
- autofocus
98
- v-model="data.orgCode"
99
- :setting="o.getField('#/properties/orgCode')"
100
- />
101
- <SimpleAppInput
102
- :input-type="SimpleAppInputType.text"
103
- v-model="data.orgName"
104
- class=""
105
- :setting="o.getField('#/properties/orgName')"
106
- />
107
- <SimpleAppInput
108
- :input-type="SimpleAppInputType.checkbox"
109
- v-model="data.active"
110
- :setting="o.getField('#/properties/active')"
111
- />
112
- <SimpleAppInput
113
- :input-type="SimpleAppInputType.text"
114
- v-model="data.timeZone"
115
- :setting="o.getField('#/properties/timeZone')"
116
- />
117
- <SimpleAppInput
118
- :input-type="SimpleAppInputType.text"
119
- v-model="data.currency"
120
- :setting="o.getField('#/properties/currency')"
121
- />
122
- </div>
123
- <div>
124
- <SimpleAppInput
125
- :input-type="SimpleAppInputType.textarea"
126
- :setting="o.getField('#/properties/description')"
127
- v-model="data.description"
128
- />
129
- </div>
130
- </div>
131
- <DebugDocumentData v-model="data" label="organization" />
132
- </SimpleAppForm>
133
- </template>
134
- </Card>
135
- </div>
136
- <div>
137
- <Card>
138
- <template #header>
139
- <!-- <h1 class="text-2xl font-bold">{{ data.orgName }}</h1> -->
140
- </template>
141
- <template #content>
142
- <div class="">
143
- <h1>Branches</h1>
144
- <Button @click="goBranch('new')">New</Button>
145
- <ListView
146
- :list="branchlist"
147
- title-field="branchName"
148
- sub-title-field="branchCode"
149
- :url="getDocumentUrl('organization', id)"
150
- >
151
- </ListView>
152
- </div>
153
- </template>
154
- </Card>
155
- </div>
156
- <div>
157
- <NuxtPage></NuxtPage>
158
- </div>
159
- </div>
160
- </template>
@@ -1,6 +1,40 @@
1
- <script setup lang="ts">
2
- import Index from './index.vue'
3
- </script>
4
1
  <template>
5
- <index></index>
2
+ <Crud :_id="userid" @after="after" />
6
3
  </template>
4
+
5
+ <script setup lang="ts">
6
+ /**
7
+ * This file was automatically generated by simpleapp everytime regenerate code.
8
+ * delete file "delete-me-for-avoid-override" if you want to modify this file and
9
+ * prevent regenerate code override it.
10
+ * last change 2023-09-09
11
+ * author: Ks Tan
12
+ */
13
+ import Crud from "./form.vue";
14
+ import { User } from "~/simpleapp/generate/types";
15
+ const userid = computed(() => getPathPara("id"));
16
+ const doc = useNuxtApp().$UserDoc();
17
+
18
+ const props = defineProps<{ _id: string }>();
19
+ const after = (actionName: string, data: User, result: any) => {
20
+ switch (actionName) {
21
+ case "new":
22
+ goTo(doc.getDocName(),);
23
+ break;
24
+ case "create":
25
+ refreshDocumentList("user");
26
+ if (isMobile()) goTo("user");
27
+ else goTo(doc.getDocName(), data._id);
28
+ break;
29
+ case "update":
30
+ refreshDocumentList("user");
31
+ if (isMobile()) goTo("user");
32
+ break;
33
+ case "delete":
34
+ refreshDocumentList("user");
35
+ goTo(doc.getDocName(), );
36
+
37
+ break;
38
+ }
39
+ };
40
+ </script>
@@ -0,0 +1,329 @@
1
+ <template>
2
+ <div class="grid grid-cols-1 xl:grid-cols-2">
3
+ <div v-if="isMobile()"
4
+ class="flex flex-1 absolute w-full h h-16 z z-20 dark:bg-gray-900 place-items-center content-center">
5
+ <ButtonText @click="goTo('user')">{{ t("cancel") }}</ButtonText>
6
+ <TextTitle class="flex-1 text-center">{{userdata.fullName ?? t("user")}}</TextTitle>
7
+ <ButtonText @click="actionListener('update')">{{ t('save') }}</ButtonText>
8
+ </div>
9
+ <div v-else class="h h-16"></div>
10
+ <Card>
11
+ <template #header>
12
+ <h1 class="font-bold">{{ usertitle }}</h1>
13
+ </template>
14
+ <template #content>
15
+ <SimpleAppForm :document="userdoc" #default="o">
16
+ <div class="flex flex-col gap-2">
17
+ <SimpleAppInput
18
+ :input-type="SimpleAppInputType.text"
19
+ autofocus
20
+ :setting="o.getField('#/properties/fullName')"
21
+ v-model="userdata.fullName"
22
+ />
23
+
24
+ <SimpleAppInput
25
+ :input-type="SimpleAppInputType.text"
26
+ type="email"
27
+ :setting="o.getField('#/properties/email')"
28
+ v-model="userdata.email"
29
+ />
30
+
31
+ <SimpleAppInput
32
+ :input-type="SimpleAppInputType.checkbox"
33
+ :setting="o.getField('#/properties/active')"
34
+ v-model="userdata.active"
35
+ />
36
+ <SimpleAppInput
37
+ :input-type="SimpleAppInputType.textarea"
38
+ :setting="o.getField('#/properties/description')"
39
+ v-model="userdata.description"
40
+ />
41
+ <div>
42
+ <ButtonPrimary v-if="!isMobile()" @click="actionListener('update')">{{ t('save') }}</ButtonPrimary>
43
+ <ButtonDanger
44
+ v-if="!userdata.uid"
45
+ @click="actionListener('delete')"
46
+ class="btn btn-danger"
47
+ >{{ t('delete') }}</ButtonDanger
48
+ >
49
+ </div>
50
+ </div>
51
+ </SimpleAppForm>
52
+ </template>
53
+ </Card>
54
+
55
+ <Card class="m-2">
56
+ <template #header>
57
+ <div class="relative w-full ...">
58
+ <h1 class="font-bold">{{ permissiontitle }}</h1>
59
+ <div class="absolute top-0 right-0 h-16 w-16 ...">
60
+ <UserButtonPermissionInfo></UserButtonPermissionInfo>
61
+ </div>
62
+ </div>
63
+ </template>
64
+ <template #content>
65
+ <BlockUI :blocked="blockscreen">
66
+ <!-- <div class="text-right m mr-2">
67
+
68
+ </div> -->
69
+
70
+ <div class="">
71
+ <Card
72
+ v-if="currentpermissions.length > 0"
73
+ v-for="o in orglist"
74
+ class="m-2"
75
+ >
76
+ <template #title>{{ o.orgName }}</template>
77
+ <template #content>
78
+ <table class="w w-full">
79
+ <tr v-for="(b, index) in branchlist">
80
+ <td v-if="checkBranchInOrg(o, b)" class="text-center">
81
+ {{ b.branchCode }}
82
+ </td>
83
+ <td
84
+ v-if="checkBranchInOrg(o, b)"
85
+ class="text-center flex flex-row"
86
+ >
87
+ <div>
88
+ <SelectButton
89
+ v-model="currentpermissions[index]['group']"
90
+ :options="grouplist"
91
+ option-label="label"
92
+ option-value="value"
93
+ @change="applyPermission(currentpermissions[index])"
94
+ ></SelectButton>
95
+ </div>
96
+ </td>
97
+ </tr>
98
+ </table>
99
+ </template>
100
+ </Card>
101
+ </div>
102
+ </BlockUI>
103
+ </template>
104
+ </Card>
105
+ </div>
106
+ </template>
107
+ <script setup lang="ts">
108
+ // import Card from "primevue/card";
109
+ import { SimpleAppInputType } from "~/types";
110
+ import { Permission, User } from "../../../simpleapp/generate/openapi/api";
111
+ import _ from "lodash";
112
+ import SelectButton from "primevue/selectbutton";
113
+ import { SearchBody, EventType } from "~/types";
114
+ import {
115
+ UserListItem,
116
+ NotificationStatus,
117
+ Notification,
118
+ BranchListItem,
119
+ OrgListItem,
120
+ PermissionListItem,
121
+ } from "~/types";
122
+ const {
123
+ $event,
124
+ $PermissionDoc,
125
+ $OrganizationDoc,
126
+ $BranchDoc,
127
+ $UserDoc,
128
+ // $InvitationDoc,
129
+ } = useNuxtApp();
130
+ const emits = defineEmits(['after'])
131
+ const props = defineProps<{_id:string}>()
132
+ const userdoc = $UserDoc();
133
+ const userdata = userdoc.getReactiveData();
134
+ const currentpermissions = ref<Permission[]>([]);
135
+ currentpermissions.value = [];
136
+ const blockscreen = ref(false);
137
+ const permlist = ref<PermissionListItem[]>([]);
138
+ // const userlist = ref<UserListItem[]>([]);
139
+ const orglist = ref<OrgListItem[]>([]);
140
+ const branchlist = ref<BranchListItem[]>([]);
141
+ const permdoc = $PermissionDoc();
142
+ const orgdoc = $OrganizationDoc();
143
+ const branchdoc = $BranchDoc();
144
+ const permissiontitle = "Permission Information";
145
+ const usertitle = "User Information";
146
+ const grouplist = getAllGroups().map((item) => {
147
+ return { value: item, label: _.capitalize(item) };
148
+ });
149
+
150
+
151
+ const newData = () => userdoc.setNew();
152
+ const createData = async () => await userdoc.create();
153
+ const updateData = async () => await userdoc.update();
154
+ const deleteData = async () => await userdoc.delete(userdata.value._id ?? "");
155
+
156
+
157
+ /**
158
+ * delete user
159
+ * @param user:User object
160
+ */
161
+ const deleteUser = async (user: any) => {
162
+ await userdoc.delete(String(userdata.value._id));
163
+ //NotificationEvent
164
+ $event("RefreshUser", "");
165
+ goTo("user");
166
+ };
167
+
168
+ /**********applPermission ******/
169
+ /**
170
+ * apply permission:
171
+ * _id:'', group:'' => skip
172
+ * _id: '', group:'something' => create
173
+ * _id:'something', 'group':'something' => update
174
+ * _id:'something', group:'' => remove
175
+ */
176
+ const applyPermission = async (d: Permission) => {
177
+ let result;
178
+ // console.log("apply permission", d);
179
+ blockscreen.value = true;
180
+ d._id = String(d._id ?? "");
181
+ d.group = String(d.group ?? "");
182
+ permdoc.setNew();
183
+ const data = permdoc.getReactiveData();
184
+ data.value = {
185
+ orgId: d.orgId,
186
+ branchId: d.branchId,
187
+ group: d.group,
188
+ userId: d.userId,
189
+ };
190
+ // console.log("apply permission", data.value);
191
+ if (!d._id && !d.group) {
192
+ //no changes
193
+ } else if (!d._id && d.group) {
194
+ result = await permdoc.create();
195
+ } else if (d._id && d.group) {
196
+ data.value = d;
197
+ result = await permdoc.update();
198
+ } else if (d._id && !d.group) {
199
+ d.group = "";
200
+ data.value = d;
201
+ result = await permdoc.delete(d._id);
202
+ } else {
203
+ console.warn("unknown apply permission", result);
204
+ }
205
+ // refreshList(false);
206
+ onSelectUser(String(d.userId));
207
+ blockscreen.value = false;
208
+ };
209
+
210
+ const checkBranchInOrg = (org: OrgListItem, branch: BranchListItem) => {
211
+ return org.orgId === branch.orgId;
212
+ };
213
+
214
+
215
+ const onSelectUser = async (userId: string) => {
216
+ console.log("onSelectUser", userId);
217
+ // .addRoute()
218
+ // const user: UserListItem = { ...menuitem };
219
+ const orgsearchbody: SearchBody = {
220
+ fields: ["orgId", "orgCode", "orgName", "active"],
221
+ };
222
+ const branchsearchbody: SearchBody = {
223
+ fields: ["orgId", "branchId", "branchCode", "branchName", "active"],
224
+ };
225
+ const permsearchbody: SearchBody = {
226
+ filter: { userId: userId },
227
+ fields: [
228
+ "uid",
229
+ "userId",
230
+ "branchId",
231
+ "tenantId",
232
+ "orgId",
233
+ "active",
234
+ "group",
235
+ "created",
236
+ ],
237
+ };
238
+
239
+ orglist.value = await orgdoc.search(orgsearchbody);
240
+ branchlist.value = await branchdoc.search(branchsearchbody);
241
+ permlist.value = await permdoc.search(permsearchbody);
242
+ await userdoc.getById(userId);
243
+ // console.log("orglist.value", orglist.value);
244
+ // console.log("branchlist.value", branchlist.value);
245
+ // console.log("permlist.value", permlist.value);
246
+ // selected.value = String(user._id);
247
+
248
+ // activeuser.value = user.fullName;
249
+ //sso id from keycloak
250
+ // const uid = String(user.uid);
251
+ //_id from mongodb
252
+
253
+ currentpermissions.value = [];
254
+
255
+ for (let i = 0; i < branchlist.value.length; i++) {
256
+ const b = branchlist.value[i];
257
+ const permdata = getPermssionData(userId, b.branchId);
258
+ const tmp: Permission = {
259
+ _id: permdata?._id,
260
+ userId: userId,
261
+ tenantId: b.tenantId,
262
+ orgId: b.orgId,
263
+ branchId: b.branchId,
264
+ group: permdata.group,
265
+ };
266
+ currentpermissions.value.push(tmp);
267
+ }
268
+ // console.log("currentpermissions", currentpermissions);
269
+ blockscreen.value = false;
270
+
271
+ };
272
+ /**
273
+ * prepare dataobj (existing or empty dummy data) for each branch permission
274
+ * @param uid
275
+ * @param branchId
276
+ */
277
+ const getPermssionData = (userId: string, branchId: number) => {
278
+ // console.log("getPermssionData", userId, branchId);
279
+ const result = permlist.value.find((item: any) => {
280
+ // console.log(
281
+ // item.userId,
282
+ // "== ",
283
+ // userId,
284
+ // " &&",
285
+ // item.branchId,
286
+ // "==",
287
+ // branchId,
288
+ // );
289
+ return item.userId == userId && item.branchId == branchId;
290
+ });
291
+
292
+ // console.log("permlist.value.",permlist.value,result)
293
+ let pm: Permission = {
294
+ _id: result?._id ?? "",
295
+ orgId: result?.orgId ?? 0,
296
+ tenantId: result?.tenantId ?? 0,
297
+ branchId: branchId,
298
+ userId: userId,
299
+ group: result?.group ?? "",
300
+ };
301
+ return pm;
302
+ };
303
+
304
+
305
+ const actionListener = async (actionName: string) => {
306
+ switch (actionName) {
307
+ case "create":
308
+ await createData();
309
+ break;
310
+ case "update":
311
+ await updateData();
312
+ break;
313
+ case "delete":
314
+ await deleteData();
315
+ break;
316
+ case "new":
317
+ await newData();
318
+ break;
319
+ }
320
+ emits("after", actionName);
321
+ };
322
+
323
+
324
+
325
+ onMounted(() => {
326
+ onSelectUser(props._id);
327
+ });
328
+ </script>
329
+