lesli_vault 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +38 -0
  3. data/app/assets/config/lesli_vault_manifest.js +38 -0
  4. data/app/assets/images/lesli_vault/vault-logo.svg +160 -0
  5. data/app/assets/javascripts/lesli_vault/application.js +2848 -0
  6. data/app/assets/stylesheets/lesli_vault/application.scss +15 -0
  7. data/app/assets/stylesheets/lesli_vault/dashboards.scss +32 -0
  8. data/app/assets/stylesheets/lesli_vault/descriptors.scss +32 -0
  9. data/app/assets/stylesheets/lesli_vault/roles.scss +32 -0
  10. data/app/assets/stylesheets/lesli_vault/system_controller.scss +32 -0
  11. data/app/controllers/lesli_vault/application_controller.rb +37 -0
  12. data/app/controllers/lesli_vault/dashboards_controller.rb +6 -0
  13. data/app/controllers/lesli_vault/descriptor/activities_controller.rb +122 -0
  14. data/app/controllers/lesli_vault/descriptor/privileges_controller.rb +104 -0
  15. data/app/controllers/lesli_vault/descriptors_controller.rb +130 -0
  16. data/app/controllers/lesli_vault/role/activities_controller.rb +76 -0
  17. data/app/controllers/lesli_vault/role/descriptors_controller.rb +95 -0
  18. data/app/controllers/lesli_vault/role/privileges_controller.rb +48 -0
  19. data/app/controllers/lesli_vault/roles_controller.rb +226 -0
  20. data/app/controllers/lesli_vault/system_controller/actions_controller.rb +112 -0
  21. data/app/controllers/lesli_vault/system_controllers_controller.rb +64 -0
  22. data/app/helpers/lesli_vault/application_helper.rb +4 -0
  23. data/app/helpers/lesli_vault/dashboards_helper.rb +4 -0
  24. data/app/helpers/lesli_vault/descriptor/activities_helper.rb +4 -0
  25. data/app/helpers/lesli_vault/descriptor/privileges_helper.rb +4 -0
  26. data/app/helpers/lesli_vault/descriptors_helper.rb +4 -0
  27. data/app/helpers/lesli_vault/role/activities_helper.rb +4 -0
  28. data/app/helpers/lesli_vault/role/descriptors_helper.rb +4 -0
  29. data/app/helpers/lesli_vault/role/privileges_helper.rb +4 -0
  30. data/app/helpers/lesli_vault/roles_helper.rb +4 -0
  31. data/app/helpers/lesli_vault/system_controller/actions_helper.rb +4 -0
  32. data/app/helpers/lesli_vault/system_controllers_helper.rb +4 -0
  33. data/app/jobs/lesli_vault/application_job.rb +37 -0
  34. data/app/mailers/lesli_vault/application_mailer.rb +39 -0
  35. data/app/models/lesli_vault/application_record.rb +39 -0
  36. data/app/models/lesli_vault/descriptor/activity.rb +40 -0
  37. data/app/models/lesli_vault/descriptor/privilege.rb +40 -0
  38. data/app/models/lesli_vault/descriptor.rb +41 -0
  39. data/app/models/lesli_vault/role/activity.rb +40 -0
  40. data/app/models/lesli_vault/role/descriptor.rb +40 -0
  41. data/app/models/lesli_vault/role/privilege.rb +40 -0
  42. data/app/models/lesli_vault/role.rb +39 -0
  43. data/app/models/lesli_vault/system_controller/action.rb +39 -0
  44. data/app/models/lesli_vault/system_controller.rb +40 -0
  45. data/app/services/application_lesli_services.rb +168 -0
  46. data/app/services/descriptor_services.rb +197 -0
  47. data/app/services/role_services.rb +218 -0
  48. data/app/services/system_controller_services.rb +99 -0
  49. data/app/views/layouts/lesli_vault/application.html.erb +15 -0
  50. data/app/views/lesli_vault/dashboards/show.html.erb +1 -0
  51. data/app/views/lesli_vault/descriptor/activities/_form.html.erb +32 -0
  52. data/app/views/lesli_vault/descriptor/activities/edit.html.erb +34 -0
  53. data/app/views/lesli_vault/descriptor/activities/index.html.erb +34 -0
  54. data/app/views/lesli_vault/descriptor/activities/new.html.erb +34 -0
  55. data/app/views/lesli_vault/descriptor/activities/show.html.erb +34 -0
  56. data/app/views/lesli_vault/descriptor/privileges/_form.html.erb +32 -0
  57. data/app/views/lesli_vault/descriptor/privileges/edit.html.erb +34 -0
  58. data/app/views/lesli_vault/descriptor/privileges/index.html.erb +34 -0
  59. data/app/views/lesli_vault/descriptor/privileges/new.html.erb +34 -0
  60. data/app/views/lesli_vault/descriptor/privileges/show.html.erb +34 -0
  61. data/app/views/lesli_vault/descriptors/_form.html.erb +32 -0
  62. data/app/views/lesli_vault/descriptors/edit.html.erb +34 -0
  63. data/app/views/lesli_vault/descriptors/index.html.erb +34 -0
  64. data/app/views/lesli_vault/descriptors/new.html.erb +34 -0
  65. data/app/views/lesli_vault/descriptors/show.html.erb +34 -0
  66. data/app/views/lesli_vault/role/activities/_form.html.erb +32 -0
  67. data/app/views/lesli_vault/role/activities/edit.html.erb +34 -0
  68. data/app/views/lesli_vault/role/activities/index.html.erb +34 -0
  69. data/app/views/lesli_vault/role/activities/new.html.erb +34 -0
  70. data/app/views/lesli_vault/role/activities/show.html.erb +34 -0
  71. data/app/views/lesli_vault/role/descriptors/_form.html.erb +32 -0
  72. data/app/views/lesli_vault/role/descriptors/edit.html.erb +34 -0
  73. data/app/views/lesli_vault/role/descriptors/index.html.erb +34 -0
  74. data/app/views/lesli_vault/role/descriptors/new.html.erb +34 -0
  75. data/app/views/lesli_vault/role/descriptors/show.html.erb +34 -0
  76. data/app/views/lesli_vault/role/privileges/_form.html.erb +32 -0
  77. data/app/views/lesli_vault/role/privileges/edit.html.erb +34 -0
  78. data/app/views/lesli_vault/role/privileges/index.html.erb +34 -0
  79. data/app/views/lesli_vault/role/privileges/new.html.erb +34 -0
  80. data/app/views/lesli_vault/role/privileges/show.html.erb +34 -0
  81. data/app/views/lesli_vault/roles/edit.html.erb +34 -0
  82. data/app/views/lesli_vault/roles/index.html.erb +34 -0
  83. data/app/views/lesli_vault/roles/new.html.erb +34 -0
  84. data/app/views/lesli_vault/roles/show.html.erb +34 -0
  85. data/app/views/lesli_vault/system_controller/actions/_form.html.erb +32 -0
  86. data/app/views/lesli_vault/system_controller/actions/edit.html.erb +34 -0
  87. data/app/views/lesli_vault/system_controller/actions/index.html.erb +34 -0
  88. data/app/views/lesli_vault/system_controller/actions/new.html.erb +34 -0
  89. data/app/views/lesli_vault/system_controller/actions/show.html.erb +34 -0
  90. data/app/views/lesli_vault/system_controllers/_form.html.erb +32 -0
  91. data/app/views/lesli_vault/system_controllers/edit.html.erb +34 -0
  92. data/app/views/lesli_vault/system_controllers/index.html.erb +34 -0
  93. data/app/views/lesli_vault/system_controllers/new.html.erb +34 -0
  94. data/app/views/lesli_vault/system_controllers/show.html.erb +34 -0
  95. data/app/vue/lesli_vault/application.js +38 -0
  96. data/app/vue/lesli_vault/apps/descriptors/components/form.vue +147 -0
  97. data/app/vue/lesli_vault/apps/descriptors/edit.vue +83 -0
  98. data/app/vue/lesli_vault/apps/descriptors/index.vue +116 -0
  99. data/app/vue/lesli_vault/apps/descriptors/new.vue +76 -0
  100. data/app/vue/lesli_vault/apps/descriptors/privileges.vue +179 -0
  101. data/app/vue/lesli_vault/apps/descriptors/show.vue +240 -0
  102. data/app/vue/lesli_vault/apps/roles/componentForm.vue +231 -0
  103. data/app/vue/lesli_vault/apps/roles/componentPrivilegeCustom.vue +86 -0
  104. data/app/vue/lesli_vault/apps/roles/componentPrivilegeStandard.vue +173 -0
  105. data/app/vue/lesli_vault/apps/roles/edit.vue +93 -0
  106. data/app/vue/lesli_vault/apps/roles/index.vue +169 -0
  107. data/app/vue/lesli_vault/apps/roles/logs.vue +110 -0
  108. data/app/vue/lesli_vault/apps/roles/new.vue +89 -0
  109. data/app/vue/lesli_vault/apps/roles/show.vue +111 -0
  110. data/app/vue/lesli_vault/apps/security/index.vue +208 -0
  111. data/app/vue/lesli_vault/stores/descriptor.js +116 -0
  112. data/app/vue/lesli_vault/stores/descriptors.js +167 -0
  113. data/app/vue/lesli_vault/stores/role.js +243 -0
  114. data/app/vue/lesli_vault/stores/roles.js +89 -0
  115. data/app/vue/lesli_vault/stores/systemController.js +67 -0
  116. data/config/routes.rb +52 -0
  117. data/lib/lesli_vault/engine.rb +18 -0
  118. data/lib/lesli_vault/version.rb +3 -0
  119. data/lib/lesli_vault.rb +6 -0
  120. data/lib/tasks/lesli_vault_tasks.rake +4 -0
  121. data/lib/tasks/system/controllers.rake +112 -0
  122. data/lib/vue/application.js +7 -0
  123. data/readme.md +19 -0
  124. metadata +181 -0
@@ -0,0 +1,179 @@
1
+ <script setup>
2
+ /*
3
+
4
+ Lesli
5
+
6
+ Copyright (c) 2023, Lesli Technologies, S. A.
7
+
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program. If not, see http://www.gnu.org/licenses/.
20
+
21
+ Lesli · Your Smart Business Assistant.
22
+
23
+ Made with ♥ by https://www.lesli.tech
24
+ Building a better future, one line of code at a time.
25
+
26
+ @contact hello@lesli.tech
27
+ @website https://lesli.tech
28
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
29
+
30
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
31
+ // ·
32
+
33
+ */
34
+
35
+
36
+
37
+ // · import vue tools
38
+ import { inject, onMounted, ref } from "vue"
39
+
40
+
41
+ // · import lesli stores
42
+ import { useDescriptor } from "LesliApp/administration/stores/descriptor"
43
+ import { useSystemController } from "LesliApp/administration/stores/systemController"
44
+
45
+
46
+ // · import vue router composable
47
+ import { useRouter, useRoute } from "vue-router"
48
+
49
+
50
+ // · implement stores
51
+ const storeDescriptor = useDescriptor()
52
+ const storeSystemController = useSystemController()
53
+
54
+
55
+ // · translations
56
+ const translations = {
57
+ core: {
58
+ roles: I18n.t("core.roles"),
59
+ shared: I18n.t("core.shared"),
60
+ descriptors: I18n.t('core.role_descriptors')
61
+ }
62
+
63
+ }
64
+
65
+
66
+ //
67
+ const tab = ref(0)
68
+
69
+
70
+ //
71
+ const columns = [{
72
+ label: 'name',
73
+ field: 'controller'
74
+ }, {
75
+ label: 'Active',
76
+ field: 'active'
77
+ }]
78
+
79
+
80
+ //
81
+ onMounted(() => {
82
+ //storeSystemController.fetchControllers()
83
+ setTimeout(() => storeDescriptor.fetchDescriptorPrivileges(), 2000)
84
+
85
+ })
86
+
87
+
88
+ //
89
+ function addPrivilege(action) {
90
+ if (action.active) {
91
+ storeDescriptor.postDescriptorPrivilege(action)
92
+ } else {
93
+ storeDescriptor.deleteDescriptorPrivilege(action)
94
+ }
95
+ }
96
+
97
+ </script>
98
+ <template>
99
+ <application-component>
100
+ <lesli-header :title="'Descriptor: '+storeDescriptor.descriptor.name">
101
+ </lesli-header>
102
+ <lesli-tabs v-model="tab">
103
+ <lesli-tab-item paddingless icon="list" title="Index">
104
+ <lesli-table
105
+ headless
106
+ v-if="storeDescriptor.privileges.index"
107
+ :columns="columns"
108
+ :records="storeDescriptor.privileges.index">
109
+ <template #active="{ record }">
110
+ <lesli-toggle
111
+ v-model="record.active"
112
+ @update:modelValue="addPrivilege(record)">
113
+ </lesli-toggle>
114
+ </template>
115
+ </lesli-table>
116
+ </lesli-tab-item>
117
+
118
+ <lesli-tab-item paddingless icon="add" title="Create">
119
+ <lesli-table
120
+ headless
121
+ v-if="storeDescriptor.privileges.create"
122
+ :columns="columns"
123
+ :records="storeDescriptor.privileges.create">
124
+ <template #active="{ record }">
125
+ <lesli-toggle
126
+ v-model="record.active"
127
+ @update:modelValue="addPrivilege(record)">
128
+ </lesli-toggle>
129
+ </template>
130
+ </lesli-table>
131
+ </lesli-tab-item>
132
+
133
+ <lesli-tab-item paddingless icon="edit" title="Update">
134
+ <lesli-table
135
+ headless
136
+ v-if="storeDescriptor.privileges.update"
137
+ :columns="columns"
138
+ :records="storeDescriptor.privileges.update">
139
+ <template #active="{ record }">
140
+ <lesli-toggle
141
+ v-model="record.active"
142
+ @update:modelValue="addPrivilege(record)">
143
+ </lesli-toggle>
144
+ </template>
145
+ </lesli-table>
146
+ </lesli-tab-item>
147
+
148
+ <lesli-tab-item paddingless icon="visibility" title="Show">
149
+ <lesli-table
150
+ headless
151
+ v-if="storeDescriptor.privileges.show"
152
+ :columns="columns"
153
+ :records="storeDescriptor.privileges.show">
154
+ <template #active="{ record }">
155
+ <lesli-toggle
156
+ v-model="record.active"
157
+ @update:modelValue="addPrivilege(record)">
158
+ </lesli-toggle>
159
+ </template>
160
+ </lesli-table>
161
+ </lesli-tab-item>
162
+
163
+ <lesli-tab-item paddingless icon="delete" title="Destroy">
164
+ <lesli-table
165
+ headless
166
+ v-if="storeDescriptor.privileges.destroy"
167
+ :columns="columns"
168
+ :records="storeDescriptor.privileges.destroy">
169
+ <template #active="{ record }">
170
+ <lesli-toggle
171
+ v-model="record.active"
172
+ @update:modelValue="addPrivilege(record)">
173
+ </lesli-toggle>
174
+ </template>
175
+ </lesli-table>
176
+ </lesli-tab-item>
177
+ </lesli-tabs>
178
+ </application-component>
179
+ </template>
@@ -0,0 +1,240 @@
1
+ <script setup>
2
+ /*
3
+
4
+ Lesli
5
+
6
+ Copyright (c) 2023, Lesli Technologies, S. A.
7
+
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program. If not, see http://www.gnu.org/licenses/.
20
+
21
+ Lesli · Your Smart Business Assistant.
22
+
23
+ Made with ♥ by https://www.lesli.tech
24
+ Building a better future, one line of code at a time.
25
+
26
+ @contact hello@lesli.tech
27
+ @website https://lesli.tech
28
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
29
+
30
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
31
+ // ·
32
+
33
+ */
34
+
35
+
36
+
37
+ // · import vue tools
38
+ import { inject, onMounted, ref } from "vue"
39
+
40
+
41
+ // · import lesli stores
42
+ import { useDescriptor } from "LesliApp/administration/stores/descriptor"
43
+ import { useSystemController } from "LesliApp/administration/stores/systemController"
44
+
45
+
46
+ // · import vue router composable
47
+ import { useRouter, useRoute } from "vue-router"
48
+
49
+
50
+ // · initialize/inject plugins
51
+ const route = useRoute()
52
+ const url = inject("url")
53
+
54
+
55
+ // · implement stores
56
+ const storeDescriptor = useDescriptor()
57
+ const storeSystemController = useSystemController()
58
+
59
+
60
+ // · translations
61
+ const translations = {
62
+ core: {
63
+ roles: I18n.t("core.roles"),
64
+ shared: I18n.t("core.shared"),
65
+ descriptors: I18n.t('core.role_descriptors')
66
+ }
67
+
68
+ }
69
+
70
+
71
+ //
72
+ const tab = ref(0)
73
+
74
+
75
+ //
76
+ const columns = [{
77
+ field: 'controller',
78
+ label: 'Controller'
79
+ },{
80
+ field: 'list_action',
81
+ label: 'List',
82
+ align: 'center'
83
+ },{
84
+ field: 'index_action',
85
+ label: 'Index',
86
+ align: 'center'
87
+ },{
88
+ field: 'show_action',
89
+ label: 'Show',
90
+ align: 'center'
91
+ },{
92
+ field: 'create_action',
93
+ label: 'Create',
94
+ align: 'center'
95
+ },{
96
+ field: 'update_action',
97
+ label: 'Update',
98
+ align: 'center'
99
+ },{
100
+ field: 'destroy_action',
101
+ label: 'Delete',
102
+ align: 'center'
103
+ }]
104
+
105
+
106
+ //
107
+ onMounted(() => {
108
+ storeDescriptor.$reset()
109
+ storeDescriptor.fetchDescriptor(route.params.id)
110
+ })
111
+
112
+
113
+ //
114
+ function addPrivilege(action) {
115
+
116
+ console.log(action)
117
+
118
+ return
119
+ if (action.active) {
120
+ storeDescriptor.postDescriptorPrivilege(action)
121
+ } else {
122
+ storeDescriptor.deleteDescriptorPrivilege(action)
123
+ }
124
+ }
125
+
126
+ </script>
127
+ <template>
128
+ <application-component>
129
+ <lesli-header :title="'Descriptor: '+storeDescriptor.descriptor.name">
130
+ </lesli-header>
131
+
132
+ <lesli-table
133
+ :columns="columns"
134
+ :records="storeDescriptor.privileges"
135
+ :loading="storeDescriptor.privilegesLoading">
136
+
137
+
138
+ <!-- table header -->
139
+
140
+ <template #head(list_action)="{ column }">
141
+ <span class="icon-text">
142
+ <span class="icon">
143
+ <span class="material-icons">
144
+ format_list_bulleted
145
+ </span>
146
+ </span>
147
+ <span>{{ column.label }}</span>
148
+ </span>
149
+ </template>
150
+
151
+ <template #head(index_action)="{ column }">
152
+ <span class="icon-text">
153
+ <span class="icon">
154
+ <span class="material-icons">
155
+ format_list_numbered
156
+ </span>
157
+ </span>
158
+ <span>{{ column.label }}</span>
159
+ </span>
160
+ </template>
161
+
162
+ <template #head(show_action)="{ column }">
163
+ <span class="icon-text">
164
+ <span class="icon">
165
+ <span class="material-icons">
166
+ visibility
167
+ </span>
168
+ </span>
169
+ <span>{{ column.label }}</span>
170
+ </span>
171
+ </template>
172
+
173
+ <template #head(create_action)="{ column }">
174
+ <span class="icon-text">
175
+ <span class="icon">
176
+ <span class="material-icons">
177
+ add
178
+ </span>
179
+ </span>
180
+ <span>{{ column.label }}</span>
181
+ </span>
182
+ </template>
183
+
184
+ <template #head(update_action)="{ column }">
185
+ <span class="icon-text">
186
+ <span class="icon">
187
+ <span class="material-icons">
188
+ edit
189
+ </span>
190
+ </span>
191
+ <span>{{ column.label }}</span>
192
+ </span>
193
+ </template>
194
+
195
+ <template #head(destroy_action)="{ column }">
196
+ <span class="icon-text">
197
+ <span class="icon">
198
+ <span class="material-icons">
199
+ delete
200
+ </span>
201
+ </span>
202
+ <span>{{ column.label }}</span>
203
+ </span>
204
+ </template>
205
+
206
+
207
+ <!-- table content -->
208
+
209
+ <template #list_action="{ record, value }">
210
+ <lesli-toggle v-if="value" v-model="record.actionlist" @update:modelValue="addPrivilege(record)">>
211
+ </lesli-toggle>
212
+ </template>
213
+
214
+ <template #index_action="{ record, value }">
215
+ <lesli-toggle v-if="value" v-model="record.index_active" @update:modelValue="addPrivilege(record)">>
216
+ </lesli-toggle>
217
+ </template>
218
+
219
+ <template #show_action="{ record, value }">
220
+ <lesli-toggle v-if="value" v-model="record.show_active" @update:modelValue="addPrivilege(record)">>
221
+ </lesli-toggle>
222
+ </template>
223
+
224
+ <template #create_action="{ record, value }">
225
+ <lesli-toggle v-if="value" v-model="record.create_active" @update:modelValue="addPrivilege(record)">>
226
+ </lesli-toggle>
227
+ </template>
228
+
229
+ <template #update_action="{ record, value }">
230
+ <lesli-toggle v-if="value" v-model="record.update_active" @update:modelValue="addPrivilege(record)">>
231
+ </lesli-toggle>
232
+ </template>
233
+
234
+ <template #destroy_action="{ record, value }">
235
+ <lesli-toggle v-if="value" v-model="record.destroy_active" @update:modelValue="addPrivilege(record)">>
236
+ </lesli-toggle>
237
+ </template>
238
+ </lesli-table>
239
+ </application-component>
240
+ </template>
@@ -0,0 +1,231 @@
1
+ <script setup>
2
+ /*
3
+
4
+ Lesli
5
+
6
+ Copyright (c) 2023, Lesli Technologies, S. A.
7
+
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program. If not, see http://www.gnu.org/licenses/.
20
+
21
+ Lesli · Your Smart Business Assistant.
22
+
23
+ Made with ♥ by https://www.lesli.tech
24
+ Building a better future, one line of code at a time.
25
+
26
+ @contact hello@lesli.tech
27
+ @website https://lesli.tech
28
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
29
+
30
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
31
+ // ·
32
+
33
+ */
34
+
35
+
36
+
37
+ // · import vue tools
38
+ import { ref, reactive, onMounted, watch, computed, inject } from "vue"
39
+ import { useRouter, useRoute } from "vue-router"
40
+
41
+
42
+ // · import lesli stores
43
+ import { useRole } from "../../stores/role"
44
+
45
+
46
+ // · initialize/inject plugins
47
+ const router = useRouter()
48
+ const route = useRoute()
49
+ const msg = inject("msg")
50
+ const url = inject("url")
51
+
52
+
53
+ // ·
54
+ const storeRole = useRole()
55
+
56
+
57
+ // ·
58
+ const translations = {
59
+ core: {
60
+ shared: I18n.t('core.shared'),
61
+ roles: I18n.t('core.roles')
62
+ }
63
+ }
64
+
65
+
66
+ // ·
67
+ onMounted(() => {
68
+ if (route.params.id) {
69
+ storeRole.fetchRole(route.params.id)
70
+ } else {
71
+ storeRole.$reset()
72
+ }
73
+ storeRole.getOptions()
74
+ })
75
+
76
+
77
+ // ·
78
+ function submitRole() {
79
+
80
+ if (storeRole.role.id) {
81
+ storeRole.putRole()
82
+ }
83
+
84
+ if (!storeRole.role.id) {
85
+ return storeRole.postRole().then(result => {
86
+ msg.success(translations.core.roles.messages_success_role_created_successfully)
87
+ router.push(url.admin("roles/:id/edit", result.id).s)
88
+ })
89
+ }
90
+
91
+ }
92
+
93
+
94
+ // ·
95
+ function isObjectLevelPermissionSelected(olp) {
96
+ return storeRole.role.object_level_permission == olp
97
+ }
98
+
99
+ </script>
100
+ <template>
101
+ <form @submit.prevent="submitRole" class="box">
102
+
103
+ <!-- Role name -->
104
+ <div class="field">
105
+ <label class="label">
106
+ {{ translations.core.roles.column_name }}
107
+ <sup class="has-text-danger">*</sup>
108
+ </label>
109
+ <div class="control">
110
+ <input v-model="storeRole.role.name" class="input" type="text" required />
111
+ </div>
112
+ </div>
113
+
114
+ <!-- Default path -->
115
+ <div class="field">
116
+ <label class="label">{{ translations.core.roles.column_default_path }}</label>
117
+ <div class="control">
118
+ <input v-model="storeRole.role.default_path" class="input" type="text" :placeholder="translations.core.roles.view_placeholder_default_path_at_login">
119
+ </div>
120
+ <p class="help"> {{ translations.core.roles.view_text_default_path_description }}</p>
121
+ </div>
122
+
123
+ <!-- Limit to default path -->
124
+ <div class="field">
125
+ <label class="label">
126
+ {{ translations.core.roles.column_limit_to_path }}
127
+ </label>
128
+ <div class="control">
129
+ <div class="select">
130
+ <lesli-select
131
+ v-model="storeRole.role.limit_to_path"
132
+ :options="[{
133
+ label: translations.core.roles.view_text_limit_to_path,
134
+ value: true
135
+ }, {
136
+ label: translations.core.roles.view_text_allow_all_paths,
137
+ value: false
138
+ }]">
139
+ </lesli-select>
140
+ </div>
141
+ </div>
142
+ <p class="help"> {{ translations.core.roles.view_text_default_path_description }}</p>
143
+ </div>
144
+
145
+ <hr>
146
+
147
+ <!-- Object level permission -->
148
+ <div class="field">
149
+ <label class="label">
150
+ {{ translations.core.roles.view_text_hierarchical_level }}
151
+ <sup class="has-text-danger">*</sup>
152
+ </label>
153
+ <ul class="hierarchical_level_selector">
154
+ <li :class="['hover', 'p-1', { 'has-background-info has-text-light' : isObjectLevelPermissionSelected(olp.level) }]"
155
+ v-for="(olp, index) in storeRole.options.object_level_permissions" :key="index"
156
+ v-on:click="storeRole.role.object_level_permission = olp.level">
157
+ <p class="icon-text">
158
+ <span class="icon">
159
+ <span class="material-icons">
160
+ {{ isObjectLevelPermissionSelected(olp.level) ? 'check_box' : 'check_box_outline_blank' }}
161
+ </span>
162
+ <i :class="['fas', isObjectLevelPermissionSelected(olp.level) ? 'fa-check' : 'fa-chevron-right']"></i>
163
+ </span>
164
+ <span>
165
+ {{ `${translations.core.roles.view_text_level || 'Level' } ${ index + 1 }` }}
166
+ <i v-if="olp.roles.length">- {{ olp.roles.map(role => role.name).join(', ') }}</i>
167
+ </span>
168
+ </p>
169
+ </li>
170
+ </ul>
171
+ </div>
172
+
173
+ <hr>
174
+
175
+ <!-- Only own data -->
176
+ <div class="field">
177
+ <label class="label">
178
+ {{ translations.core.roles.column_only_my_data }}
179
+ <sup class="has-text-danger">*</sup>
180
+ </label>
181
+ <div class="control">
182
+ <div class="select">
183
+ <lesli-select
184
+ v-model="storeRole.role.only_my_data"
185
+ :options="[{
186
+ label: translations.core.roles.view_text_restrict_data_access,
187
+ value: true
188
+ }, {
189
+ label: translations.core.roles.view_text_allow_to_see_all_the_data,
190
+ value: false
191
+ }]">
192
+ </lesli-select>
193
+ </div>
194
+ </div>
195
+ </div>
196
+
197
+ <hr>
198
+
199
+ <!-- Enable/disable role -->
200
+ <div class="field">
201
+ <label class="label">
202
+ {{ translations.core.roles.view_text_status }}
203
+ <sup class="has-text-danger">*</sup>
204
+ </label>
205
+ <div class="control">
206
+ <div class="select">
207
+ <lesli-select
208
+ v-model="storeRole.role.active"
209
+ :options="[{
210
+ label: translations.core.roles.view_text_active,
211
+ value: true
212
+ },{
213
+ label: translations.core.roles.view_text_disabled,
214
+ value: false
215
+ }]">
216
+ </lesli-select>
217
+ </div>
218
+ </div>
219
+ </div>
220
+
221
+ <hr>
222
+
223
+ <div class="field is-grouped">
224
+ <div class="control">
225
+ <lesli-button icon="save">
226
+ {{ translations.core.shared.view_btn_save }}
227
+ </lesli-button>
228
+ </div>
229
+ </div>
230
+ </form>
231
+ </template>