@things-factory/meta-ui 8.0.0-beta.9 → 8.0.2
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/client/bootstrap.ts +170 -0
- package/client/component/filter/filter-form-meta-code-select.ts +102 -0
- package/client/component/filter/filter-form-meta-object-select.ts +107 -0
- package/client/component/filter/filter-grist-meta-code-select.ts +97 -0
- package/client/component/filter/filter-grist-meta-object-select.ts +102 -0
- package/client/component/grist/editor/grist-editor-code-input.js +96 -0
- package/client/component/grist/editor/grist-editor-meta-code-selector.js +157 -0
- package/client/component/grist/editor/grist-editor-meta-object-selector.js +122 -0
- package/client/component/grist/renderer/grist-renderer-code-input.js +20 -0
- package/client/component/grist/renderer/grist-renderer-meta-code-selector.js +28 -0
- package/client/component/grist/renderer/grist-renderer-meta-object-selector.js +25 -0
- package/client/component/popup/code-input-editor-popup.js +111 -0
- package/client/component/popup/file-upload-popup.js +129 -0
- package/client/component/popup/meta-object-selector-popup.ts +356 -0
- package/client/component/popup/record-based-code-editor-popup.ts +141 -0
- package/client/dynamic-menus.ts +38 -0
- package/client/index.ts +18 -0
- package/client/load-components.ts +17 -0
- package/client/mixin/meta-base-mixin.js +323 -0
- package/client/mixin/meta-basic-grist-mixin.js +283 -0
- package/client/mixin/meta-button-mixin.js +116 -0
- package/client/mixin/meta-form-mixin.js +435 -0
- package/client/mixin/meta-grist-tab-mixin.js +335 -0
- package/client/mixin/meta-main-tab-mixin.js +267 -0
- package/client/mixin/meta-master-detail-mixin.js +395 -0
- package/client/mixin/meta-service-mixin.js +306 -0
- package/client/mixin/meta-tab-detail-mixin.js +283 -0
- package/client/mixin/meta-tab-mixin.js +190 -0
- package/client/pages/activity/meta-activity-define-page.js +422 -0
- package/client/pages/activity/meta-activity-list-page.js +262 -0
- package/client/pages/activity/meta-activity-viewer-element.js +35 -0
- package/client/pages/activity/meta-activity-writer-element.js +48 -0
- package/client/pages/activity/meta-activiy-mixin.js +79 -0
- package/client/pages/button-role/button-role-detail.js +50 -0
- package/client/pages/button-role/button-role-page.js +25 -0
- package/client/pages/doc-number/doc-number-page.js +24 -0
- package/client/pages/doc-number/next-doc-number-popup.js +25 -0
- package/client/pages/entity/config-entity.js +955 -0
- package/client/pages/entity/main-menu-selector.js +245 -0
- package/client/pages/history/history-copy-list-popup.js +145 -0
- package/client/pages/history/history-json-list-popup.js +159 -0
- package/client/pages/menu/dynamic-menu-template.js +92 -0
- package/client/pages/menu/dynamic-menu.ts +744 -0
- package/client/pages/menu/export-menu-popup.js +468 -0
- package/client/pages/meta-form-element.js +9 -0
- package/client/pages/meta-grist-element.js +12 -0
- package/client/pages/meta-grist-page.js +16 -0
- package/client/pages/meta-grist-tab-element.js +16 -0
- package/client/pages/meta-grist-tab-page.js +16 -0
- package/client/pages/meta-main-tab-element.js +12 -0
- package/client/pages/meta-main-tab-page.js +16 -0
- package/client/pages/meta-master-detail-element.js +12 -0
- package/client/pages/meta-master-detail-page.js +16 -0
- package/client/pages/meta-tab-detail-element.js +12 -0
- package/client/pages/meta-tab-detail-page.js +16 -0
- package/client/pages/meta-tab-element.js +15 -0
- package/client/pages/printer-device/printer-device-page.js +24 -0
- package/client/pages/template/doc-template-page.js +24 -0
- package/client/pages/template/template-file-page.js +24 -0
- package/client/pages/terms/config-terminology.js +214 -0
- package/client/pages/work-code/work-code-detail-popup.js +16 -0
- package/client/pages/work-code/work-code-page.js +23 -0
- package/client/route.ts +36 -0
- package/client/tsconfig.json +13 -0
- package/client/utils/grist-default-value.js +36 -0
- package/client/utils/meta-api.js +811 -0
- package/client/utils/meta-crypto.js +52 -0
- package/client/utils/meta-ui-util.js +3304 -0
- package/client/utils/rest-service-util.js +328 -0
- package/client/utils/service-util.js +1327 -0
- package/client/utils/terms-util.ts +119 -0
- package/client/utils/ui-util.js +338 -0
- package/client/utils/value-util.js +234 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/service-util.d.ts +2 -2
- package/dist-client/utils/service-util.js +4 -4
- package/dist-client/utils/service-util.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -24
- package/server/activity/CommonActivity.ts +68 -0
- package/server/index.ts +3 -0
- package/server/routes.ts +61 -0
- package/server/service/button-role/button-role-mutation.ts +105 -0
- package/server/service/button-role/button-role-query.ts +53 -0
- package/server/service/button-role/button-role-type.ts +39 -0
- package/server/service/button-role/button-role.ts +61 -0
- package/server/service/button-role/index.ts +7 -0
- package/server/service/dynamic-menu/dynamic-menu-query.ts +270 -0
- package/server/service/dynamic-menu/dynamic-menu-type.ts +74 -0
- package/server/service/dynamic-menu/index.ts +3 -0
- package/server/service/entity-event-subscriber/entity-event-subscriber.ts +80 -0
- package/server/service/entity-event-subscriber/index.ts +3 -0
- package/server/service/index.ts +41 -0
- package/server/service/menu-button-auth/index.ts +7 -0
- package/server/service/menu-button-auth/menu-button-auth-mutation.ts +133 -0
- package/server/service/menu-button-auth/menu-button-auth-query.ts +138 -0
- package/server/service/menu-button-auth/menu-button-auth-type.ts +63 -0
- package/server/service/menu-button-auth/menu-button-auth.ts +92 -0
- package/server/service/meta-activity/index.ts +5 -0
- package/server/service/meta-activity/meta-activity-mutation.ts +191 -0
- package/server/service/meta-activity/meta-activity-query.ts +43 -0
- package/server/service/meta-activity/meta-activity-type.ts +56 -0
- package/server/service/set-translations/index.ts +3 -0
- package/server/service/set-translations/set-translation-resolver.ts +63 -0
- package/server/service/work-code/index.ts +6 -0
- package/server/service/work-code/work-code-mutation.ts +147 -0
- package/server/service/work-code/work-code-query.ts +67 -0
- package/server/service/work-code/work-code-type.ts +60 -0
- package/server/service/work-code/work-code.ts +83 -0
- package/server/service/work-code-detail/index.ts +6 -0
- package/server/service/work-code-detail/work-code-detail-mutation.ts +149 -0
- package/server/service/work-code-detail/work-code-detail-query.ts +59 -0
- package/server/service/work-code-detail/work-code-detail-type.ts +50 -0
- package/server/service/work-code-detail/work-code-detail.ts +82 -0
- package/server/tsconfig.json +9 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Resolver, FieldResolver, Root, Query, Args, Ctx, Arg } from 'type-graphql'
|
|
2
|
+
import { ListParam, getRepository, getQueryBuilderFromListParams } from '@things-factory/shell'
|
|
3
|
+
import { Menu } from '@things-factory/menu-base'
|
|
4
|
+
|
|
5
|
+
import { DynamicMenuList, ExportMenuInfo } from './dynamic-menu-type'
|
|
6
|
+
|
|
7
|
+
import { Entity, EntityColumn } from '@things-factory/resource-base'
|
|
8
|
+
|
|
9
|
+
import crypto from 'crypto'
|
|
10
|
+
const { camelCase, startCase, snakeCase, kebabCase, upperFirst } = require('lodash')
|
|
11
|
+
|
|
12
|
+
@Resolver(Menu)
|
|
13
|
+
export class DynamicMenuQuery {
|
|
14
|
+
@Query(returns => ExportMenuInfo, { description: 'To fetch a export menu data' })
|
|
15
|
+
async exportMenuInfo(@Arg('id') id: string, @Ctx() context: any): Promise<ExportMenuInfo> {
|
|
16
|
+
const { domain } = context.state
|
|
17
|
+
|
|
18
|
+
// 메뉴
|
|
19
|
+
const menu: Menu = await getRepository(Menu).findOneBy({ id: id, domain: { id: domain.id } })
|
|
20
|
+
const parentMenu: Menu = await getRepository(Menu).findOneBy({ id: menu.parentId, domain: { id: domain.id } })
|
|
21
|
+
|
|
22
|
+
// entity
|
|
23
|
+
let entityName = upperFirst(camelCase(menu.routing))
|
|
24
|
+
const entity: Entity = await getRepository(Entity).findOneBy({ domain: { id: domain.id }, name: entityName })
|
|
25
|
+
|
|
26
|
+
// entity Columns
|
|
27
|
+
const entityColumns: EntityColumn[] = await getRepository(EntityColumn).findBy({
|
|
28
|
+
domain: { id: domain.id },
|
|
29
|
+
entity: { id: entity.id }
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
let entityMeta = getRepository(entityName).metadata
|
|
33
|
+
|
|
34
|
+
const indices = entityMeta.indices.map(x => {
|
|
35
|
+
return {
|
|
36
|
+
name: x.name,
|
|
37
|
+
isUnique: x.isUnique,
|
|
38
|
+
columns: x.columns.map(y => {
|
|
39
|
+
return y.databaseName.toUpperCase()
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const columns = entityMeta.columns
|
|
45
|
+
.map(x => {
|
|
46
|
+
return {
|
|
47
|
+
name: x.databaseName,
|
|
48
|
+
isNullable: x.isNullable,
|
|
49
|
+
length: x.type == 'numeric' ? [x.precision, x.scale].join(',') : x.length,
|
|
50
|
+
type: x.type.toString(),
|
|
51
|
+
default: typeof x.default === 'function' ? undefined : x.default
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
.filter(x => ['data_revision_no', 'deleted_at'].includes(x.name) == false)
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
id,
|
|
58
|
+
menu,
|
|
59
|
+
entity,
|
|
60
|
+
entityColumns,
|
|
61
|
+
indices,
|
|
62
|
+
columns,
|
|
63
|
+
parentMenu
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Query(returns => DynamicMenuList, { description: 'To fetch multiple dynamicMenus' })
|
|
68
|
+
async dynamicMenus(@Args(type => ListParam) params: ListParam, @Ctx() context: any): Promise<DynamicMenuList> {
|
|
69
|
+
const { domain } = context.state
|
|
70
|
+
|
|
71
|
+
let templateCodeIdx = params.filters?.findIndex(x => x.name == 'templateCode')
|
|
72
|
+
let templateCode = undefined
|
|
73
|
+
|
|
74
|
+
if (templateCodeIdx > -1) {
|
|
75
|
+
templateCode = params.filters[templateCodeIdx].value
|
|
76
|
+
params.filters = params.filters.filter(x => x.name != 'templateCode')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let templateTextIdx = params.filters?.findIndex(x => x.name == 'templateText')
|
|
80
|
+
let templateText = undefined
|
|
81
|
+
|
|
82
|
+
if (templateTextIdx > -1) {
|
|
83
|
+
templateText = params.filters[templateTextIdx].value
|
|
84
|
+
params.filters = params.filters.filter(x => x.name != 'templateText')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (templateText) {
|
|
88
|
+
params.pagination.limit = 0
|
|
89
|
+
params.pagination.page = 0
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let groupSearch =
|
|
93
|
+
params.filters?.findIndex(x => x.name == 'parentId' && x.operator == 'is_null') > -1 ? true : false
|
|
94
|
+
|
|
95
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
96
|
+
domain,
|
|
97
|
+
params,
|
|
98
|
+
repository: await getRepository(Menu),
|
|
99
|
+
searchables: ['name', 'description', 'routing']
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
let [items, total] = await queryBuilder.getManyAndCount()
|
|
103
|
+
let result: DynamicMenuList = { items: items, total: total }
|
|
104
|
+
|
|
105
|
+
let self = this
|
|
106
|
+
|
|
107
|
+
if (templateText) {
|
|
108
|
+
if (groupSearch === true) {
|
|
109
|
+
for (let idx = 0; idx < result.items.length; idx++) {
|
|
110
|
+
result.items[idx].children = await getRepository(Menu).findBy({ parent: { id: result.items[idx].id } })
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
items = items.filter(function (item: Menu) {
|
|
115
|
+
return self.checkTemplateByContainsText(
|
|
116
|
+
templateCode,
|
|
117
|
+
templateText,
|
|
118
|
+
groupSearch === true ? item.children : item.template
|
|
119
|
+
)
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
items,
|
|
125
|
+
total
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
checkTemplate(code: string, text: string, template: string) {
|
|
130
|
+
if (!template) return false
|
|
131
|
+
|
|
132
|
+
let templateString: any = ''
|
|
133
|
+
let templateJsonStr = this.dec(template)
|
|
134
|
+
let templateJson = JSON.parse(templateJsonStr)
|
|
135
|
+
|
|
136
|
+
if (code === 'col-name') {
|
|
137
|
+
templateString = templateJson['grid_column'].map(x => {
|
|
138
|
+
return x.name
|
|
139
|
+
})
|
|
140
|
+
} else if (code === 'object-custom') {
|
|
141
|
+
templateString = JSON.stringify(
|
|
142
|
+
templateJson['grid_column']
|
|
143
|
+
.filter(
|
|
144
|
+
x =>
|
|
145
|
+
['meta-object-selector', 'object', 'resource-object'].includes(x.type) &&
|
|
146
|
+
x.object_opt &&
|
|
147
|
+
!x.object_opt.menu
|
|
148
|
+
)
|
|
149
|
+
.map(x => {
|
|
150
|
+
return x.object_opt
|
|
151
|
+
})
|
|
152
|
+
)
|
|
153
|
+
} else if (code === 'object-menu') {
|
|
154
|
+
templateString = JSON.stringify(
|
|
155
|
+
templateJson['grid_column']
|
|
156
|
+
.filter(
|
|
157
|
+
x =>
|
|
158
|
+
['meta-object-selector', 'object', 'resource-object'].includes(x.type) &&
|
|
159
|
+
x.object_opt &&
|
|
160
|
+
x.object_opt.menu
|
|
161
|
+
)
|
|
162
|
+
.map(x => {
|
|
163
|
+
return x.object_opt.menu
|
|
164
|
+
})
|
|
165
|
+
)
|
|
166
|
+
} else if (code === 'code-custom') {
|
|
167
|
+
templateString = JSON.stringify(
|
|
168
|
+
templateJson['grid_column']
|
|
169
|
+
.filter(
|
|
170
|
+
x => ['meta-code-selector', 'resource-code-selector'].includes(x.type) && x.object_opt && !x.object_opt.menu
|
|
171
|
+
)
|
|
172
|
+
.map(x => {
|
|
173
|
+
return x.object_opt
|
|
174
|
+
})
|
|
175
|
+
)
|
|
176
|
+
} else if (code === 'code-menu') {
|
|
177
|
+
templateString = JSON.stringify(
|
|
178
|
+
templateJson['grid_column']
|
|
179
|
+
.filter(
|
|
180
|
+
x => ['meta-code-selector', 'resource-code-selector'].includes(x.type) && x.object_opt && x.object_opt.menu
|
|
181
|
+
)
|
|
182
|
+
.map(x => {
|
|
183
|
+
return x.object_opt.menu
|
|
184
|
+
})
|
|
185
|
+
)
|
|
186
|
+
} else if (code === 'selector-entity') {
|
|
187
|
+
templateString = JSON.stringify(
|
|
188
|
+
templateJson['grid_column']
|
|
189
|
+
.filter(x => x.type == 'select' && x.select_opt && x.select_opt.type == 'entity')
|
|
190
|
+
.map(x => {
|
|
191
|
+
return x.select_opt
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
} else if (code === 'selector-code') {
|
|
195
|
+
templateString = JSON.stringify(
|
|
196
|
+
templateJson['grid_column']
|
|
197
|
+
.filter(x => x.type == 'select' && x.select_opt && x.select_opt.type == 'code')
|
|
198
|
+
.map(x => {
|
|
199
|
+
return x.select_opt.name
|
|
200
|
+
})
|
|
201
|
+
)
|
|
202
|
+
} else if (code === 'selector-scenario') {
|
|
203
|
+
templateString = JSON.stringify(
|
|
204
|
+
templateJson['grid_column']
|
|
205
|
+
.filter(x => x.type == 'select' && x.select_opt && x.select_opt.type == 'scenario')
|
|
206
|
+
.map(x => {
|
|
207
|
+
return x.select_opt.name
|
|
208
|
+
})
|
|
209
|
+
)
|
|
210
|
+
} else {
|
|
211
|
+
templateString = templateJsonStr
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return templateString.includes(text)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
checkTemplateByContainsText(code: string, text: string, template: any) {
|
|
218
|
+
if (Array.isArray(template)) {
|
|
219
|
+
for (let idx = 0; idx < template.length; idx++) {
|
|
220
|
+
let contains = this.checkTemplate(code, text, template[idx].template)
|
|
221
|
+
|
|
222
|
+
if (contains == true) {
|
|
223
|
+
return true
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return false
|
|
228
|
+
} else {
|
|
229
|
+
return this.checkTemplate(code, text, template)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
dec(template: string): string {
|
|
234
|
+
let decResults = []
|
|
235
|
+
let encTemps = template.split('h1z0q9i9x7q6')
|
|
236
|
+
let filters = [
|
|
237
|
+
'aes-256-ecb',
|
|
238
|
+
'aes-256-cbc',
|
|
239
|
+
'aes-256-cfb',
|
|
240
|
+
'aes-256-cfb8',
|
|
241
|
+
'aes-256-cfb1',
|
|
242
|
+
'aes-256-ofb',
|
|
243
|
+
'aes-256-ctr',
|
|
244
|
+
'aes256'
|
|
245
|
+
]
|
|
246
|
+
let salt = encTemps[0]
|
|
247
|
+
let hexKey = Buffer.from(salt, 'hex')
|
|
248
|
+
let ivBase = salt.substring(0, 16)
|
|
249
|
+
let iv = ['', ivBase, ivBase, ivBase, ivBase, ivBase, ivBase, ivBase]
|
|
250
|
+
let filterIdx = 0
|
|
251
|
+
|
|
252
|
+
encTemps = encTemps.splice(1)
|
|
253
|
+
|
|
254
|
+
for (var i = 0; i < encTemps.length; i++, filterIdx++) {
|
|
255
|
+
if (filterIdx == filters.length) filterIdx = 0
|
|
256
|
+
|
|
257
|
+
let decipher = crypto.createDecipheriv(filters[filterIdx], hexKey, iv[filterIdx])
|
|
258
|
+
let decrypted = decipher.update(encTemps[i], 'hex', 'utf8')
|
|
259
|
+
decrypted += decipher.final('utf8')
|
|
260
|
+
|
|
261
|
+
decResults.push(decrypted)
|
|
262
|
+
}
|
|
263
|
+
return JSON.parse(decResults.join(''))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
@FieldResolver(type => Menu)
|
|
267
|
+
async parent(@Root() menu: Menu): Promise<Menu> {
|
|
268
|
+
return await getRepository(Menu).findOneBy({ id: menu.parentId })
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ObjectType, Field, InputType, Int, ID, Float, registerEnumType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Menu } from '@things-factory/menu-base'
|
|
4
|
+
import { Entity, EntityColumn } from '@things-factory/resource-base'
|
|
5
|
+
import { Terminology } from '@things-factory/i18n-base'
|
|
6
|
+
|
|
7
|
+
@ObjectType()
|
|
8
|
+
export class DynamicMenuList {
|
|
9
|
+
@Field(type => [Menu])
|
|
10
|
+
items: Menu[]
|
|
11
|
+
|
|
12
|
+
@Field(type => Int)
|
|
13
|
+
total: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@ObjectType()
|
|
17
|
+
export class DBIndex {
|
|
18
|
+
@Field(type => String)
|
|
19
|
+
name: string
|
|
20
|
+
|
|
21
|
+
@Field(type => Boolean)
|
|
22
|
+
isUnique: boolean
|
|
23
|
+
|
|
24
|
+
@Field(type => [String], { nullable: true })
|
|
25
|
+
columns?: string[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@ObjectType()
|
|
29
|
+
export class DBColumn {
|
|
30
|
+
@Field(type => String)
|
|
31
|
+
name: string
|
|
32
|
+
|
|
33
|
+
@Field(type => Boolean)
|
|
34
|
+
isNullable: boolean
|
|
35
|
+
|
|
36
|
+
@Field(type => String)
|
|
37
|
+
length: string
|
|
38
|
+
|
|
39
|
+
@Field(type => String)
|
|
40
|
+
type: string
|
|
41
|
+
|
|
42
|
+
@Field(type => String || Number || Boolean, { nullable: true })
|
|
43
|
+
default?: any
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ObjectType()
|
|
47
|
+
export class ExportMenuInfo {
|
|
48
|
+
@Field(type => String)
|
|
49
|
+
id: string
|
|
50
|
+
|
|
51
|
+
@Field(type => Menu, { nullable: true })
|
|
52
|
+
menu?: Menu
|
|
53
|
+
|
|
54
|
+
@Field(type => Menu, { nullable: true })
|
|
55
|
+
parentMenu?: Menu
|
|
56
|
+
|
|
57
|
+
@Field(type => Entity, { nullable: true })
|
|
58
|
+
entity?: Entity
|
|
59
|
+
|
|
60
|
+
@Field(type => [EntityColumn], { nullable: true })
|
|
61
|
+
entityColumns?: EntityColumn[]
|
|
62
|
+
|
|
63
|
+
@Field(type => [Terminology], { nullable: true })
|
|
64
|
+
termsLabel?: Terminology[]
|
|
65
|
+
|
|
66
|
+
@Field(type => [Terminology], { nullable: true })
|
|
67
|
+
termsTitle?: Terminology[]
|
|
68
|
+
|
|
69
|
+
@Field(type => [DBIndex], { nullable: true })
|
|
70
|
+
indices?: DBIndex[]
|
|
71
|
+
|
|
72
|
+
@Field(type => [DBColumn], { nullable: true })
|
|
73
|
+
columns?: DBColumn[]
|
|
74
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { EventSubscriber, InsertEvent, UpdateEvent, EntitySubscriberInterface } from 'typeorm'
|
|
2
|
+
import { getRepository } from '@things-factory/shell'
|
|
3
|
+
import { Entity, EntityColumn } from '@things-factory/resource-base'
|
|
4
|
+
import { generateId } from '@things-factory/id-rule-base'
|
|
5
|
+
const { camelCase } = require('lodash')
|
|
6
|
+
import moment from 'moment-timezone'
|
|
7
|
+
|
|
8
|
+
import gql from 'graphql-tag'
|
|
9
|
+
|
|
10
|
+
@EventSubscriber()
|
|
11
|
+
export class EntityEventSubscriber implements EntitySubscriberInterface<any> {
|
|
12
|
+
async beforeInsert(event: InsertEvent<any>): Promise<any> {
|
|
13
|
+
let data = event.entity
|
|
14
|
+
|
|
15
|
+
if (!data) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let entityName = event.metadata.name
|
|
20
|
+
let domainId = undefined
|
|
21
|
+
|
|
22
|
+
if (data.domainId) {
|
|
23
|
+
domainId = data.domainId
|
|
24
|
+
} else if (data.domain) {
|
|
25
|
+
domainId = data.domain.id
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!domainId) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let generateColumns = await this.findEntityColumns(domainId, entityName)
|
|
33
|
+
|
|
34
|
+
if (generateColumns && generateColumns.length > 0) {
|
|
35
|
+
for (let idx = 0; idx < generateColumns.length; idx++) {
|
|
36
|
+
let col = generateColumns[idx]
|
|
37
|
+
let colName = camelCase(col.name)
|
|
38
|
+
|
|
39
|
+
if (event.entity[colName]) {
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let seed = {
|
|
44
|
+
date: moment().format('YYYY-MM-DD'),
|
|
45
|
+
month: moment().format('YYYY-MM'),
|
|
46
|
+
year: moment().format('YYYY')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let genInfo = col.defVal.split(',')
|
|
50
|
+
|
|
51
|
+
for (let mapIdx = 1; mapIdx < genInfo.length; mapIdx++) {
|
|
52
|
+
let nameValue = genInfo[mapIdx].split(':')
|
|
53
|
+
let name: string = nameValue[0]
|
|
54
|
+
let value: string = nameValue[1]
|
|
55
|
+
|
|
56
|
+
seed[name] = value.indexOf('$') > -1 ? value.substring(1) : event.entity[value]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
event.entity[colName] = await generateId({
|
|
60
|
+
domain: { id: domainId },
|
|
61
|
+
type: genInfo[0],
|
|
62
|
+
seed
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async findEntityColumns(domainId: string, entityName: string): Promise<EntityColumn[]> {
|
|
69
|
+
let entity: Entity = await getRepository(Entity).findOne({
|
|
70
|
+
where: { domain: { id: domainId }, name: entityName },
|
|
71
|
+
relations: ['columns']
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
if (!entity) {
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (entity.columns || []).filter(x => x.defVal)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* EXPORT ENTITY TYPES */
|
|
2
|
+
export * from './button-role/button-role'
|
|
3
|
+
export * from './menu-button-auth/menu-button-auth'
|
|
4
|
+
export * from './work-code-detail/work-code-detail'
|
|
5
|
+
export * from './work-code/work-code'
|
|
6
|
+
|
|
7
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
8
|
+
import { entities as ButtonRoleEntities, resolvers as ButtonRoleResolvers } from './button-role'
|
|
9
|
+
import { entities as MenuButtonAuthEntities, resolvers as MenuButtonAuthResolvers } from './menu-button-auth'
|
|
10
|
+
import { resolvers as SetTranslationResolvers } from './set-translations'
|
|
11
|
+
import { resolvers as MetaActivityResolvers } from './meta-activity'
|
|
12
|
+
import { entities as WorkCodeDetailEntities, resolvers as WorkCodeDetailResolvers } from './work-code-detail'
|
|
13
|
+
import { entities as WorkCodeEntities, resolvers as WorkCodeResolvers } from './work-code'
|
|
14
|
+
import { resolvers as DynamicMenuResolvers } from './dynamic-menu'
|
|
15
|
+
import { subscribers as EntityEventSubscriber } from './entity-event-subscriber'
|
|
16
|
+
|
|
17
|
+
export const entities = [
|
|
18
|
+
/* ENTITIES */
|
|
19
|
+
...ButtonRoleEntities,
|
|
20
|
+
...MenuButtonAuthEntities,
|
|
21
|
+
...WorkCodeDetailEntities,
|
|
22
|
+
...WorkCodeEntities
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
export const schema = {
|
|
26
|
+
resolverClasses: [
|
|
27
|
+
/* RESOLVER CLASSES */
|
|
28
|
+
...ButtonRoleResolvers,
|
|
29
|
+
...MenuButtonAuthResolvers,
|
|
30
|
+
...SetTranslationResolvers,
|
|
31
|
+
...MetaActivityResolvers,
|
|
32
|
+
...WorkCodeDetailResolvers,
|
|
33
|
+
...WorkCodeResolvers,
|
|
34
|
+
...DynamicMenuResolvers
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const subscribers = [
|
|
39
|
+
/* SUBSCRIBERS */
|
|
40
|
+
...EntityEventSubscriber
|
|
41
|
+
]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
import { MenuButtonAuth } from './menu-button-auth'
|
|
3
|
+
import { MenuButtonAuthQuery } from './menu-button-auth-query'
|
|
4
|
+
import { MenuButtonAuthMutation } from './menu-button-auth-mutation'
|
|
5
|
+
|
|
6
|
+
export const entities = [MenuButtonAuth]
|
|
7
|
+
export const resolvers = [MenuButtonAuthQuery, MenuButtonAuthMutation]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
|
|
2
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
3
|
+
import { In } from 'typeorm'
|
|
4
|
+
import { MenuButtonAuth } from './menu-button-auth'
|
|
5
|
+
import { NewMenuButtonAuth, MenuButtonAuthPatch } from './menu-button-auth-type'
|
|
6
|
+
import { Domain, getRepository, ScalarObject } from '@things-factory/shell'
|
|
7
|
+
import { User } from '@things-factory/auth-base'
|
|
8
|
+
|
|
9
|
+
@Resolver(MenuButtonAuth)
|
|
10
|
+
export class MenuButtonAuthMutation {
|
|
11
|
+
@Directive('@transaction')
|
|
12
|
+
@Mutation(returns => MenuButtonAuth, { description: 'To create new MenuButtonAuth' })
|
|
13
|
+
async createMenuButtonAuth(@Arg('menuButtonAuth') menuButtonAuth: NewMenuButtonAuth, @Ctx() context: any): Promise<MenuButtonAuth> {
|
|
14
|
+
const { domain, user, tx } = context.state
|
|
15
|
+
|
|
16
|
+
return await tx.getRepository(MenuButtonAuth).save({
|
|
17
|
+
...menuButtonAuth,
|
|
18
|
+
domain,
|
|
19
|
+
creator: user,
|
|
20
|
+
updater: user
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Directive('@transaction')
|
|
25
|
+
@Mutation(returns => MenuButtonAuth, { description: 'To modify MenuButtonAuth information' })
|
|
26
|
+
async updateMenuButtonAuth(
|
|
27
|
+
@Arg('id') id: string,
|
|
28
|
+
@Arg('patch') patch: MenuButtonAuthPatch,
|
|
29
|
+
@Ctx() context: any
|
|
30
|
+
): Promise<MenuButtonAuth> {
|
|
31
|
+
const { domain, user, tx } = context.state
|
|
32
|
+
|
|
33
|
+
const repository = tx.getRepository(MenuButtonAuth)
|
|
34
|
+
const menuButtonAuth = await repository.findOne(
|
|
35
|
+
{
|
|
36
|
+
where: { domain: { id: domain.id }, id },
|
|
37
|
+
relations: ['domain','updater','creator']
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return await repository.save({
|
|
42
|
+
...menuButtonAuth,
|
|
43
|
+
...patch,
|
|
44
|
+
updater: user
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Directive('@transaction')
|
|
49
|
+
@Mutation(returns => [MenuButtonAuth], { description: "To modify multiple MenuButtonAuths' information" })
|
|
50
|
+
async updateMultipleMenuButtonAuth(
|
|
51
|
+
@Arg('patches', type => [MenuButtonAuthPatch]) patches: MenuButtonAuthPatch[],
|
|
52
|
+
@Ctx() context: any
|
|
53
|
+
): Promise<MenuButtonAuth[]> {
|
|
54
|
+
const { domain, user, tx } = context.state
|
|
55
|
+
|
|
56
|
+
let results = []
|
|
57
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
58
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
59
|
+
const menuButtonAuthRepo = tx.getRepository(MenuButtonAuth)
|
|
60
|
+
|
|
61
|
+
if (_createRecords.length > 0) {
|
|
62
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
63
|
+
const newRecord = _createRecords[i]
|
|
64
|
+
|
|
65
|
+
const result = await menuButtonAuthRepo.save({
|
|
66
|
+
...newRecord,
|
|
67
|
+
domain,
|
|
68
|
+
creator: user,
|
|
69
|
+
updater: user
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
results.push({ ...result, cuFlag: '+' })
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (_updateRecords.length > 0) {
|
|
77
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
78
|
+
const updRecord = _updateRecords[i]
|
|
79
|
+
const menuButtonAuth = await menuButtonAuthRepo.findOne({
|
|
80
|
+
where: { domain: { id: domain.id }, id:updRecord.id },
|
|
81
|
+
relations: ['domain','updater','creator']
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const result = await menuButtonAuthRepo.save({
|
|
85
|
+
...menuButtonAuth,
|
|
86
|
+
...updRecord,
|
|
87
|
+
updater: user
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return results
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Directive('@transaction')
|
|
98
|
+
@Mutation(returns => [MenuButtonAuth], { description: "To modify multiple MenuButtonAuths' information" })
|
|
99
|
+
async updateMultipleMenuButtonAuths(
|
|
100
|
+
@Arg('patches', type => ScalarObject ) patches: any,
|
|
101
|
+
@Ctx() context: any
|
|
102
|
+
): Promise<MenuButtonAuth[]> {
|
|
103
|
+
const { domain, user, tx } = context.state
|
|
104
|
+
|
|
105
|
+
console.log(patches)
|
|
106
|
+
return []
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Directive('@transaction')
|
|
110
|
+
@Mutation(returns => Boolean, { description: 'To delete MenuButtonAuth' })
|
|
111
|
+
async deleteMenuButtonAuth(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
|
|
112
|
+
const { domain, tx, user } = context.state
|
|
113
|
+
await tx.getRepository(MenuButtonAuth).remove({ domain, id, updater:user })
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Directive('@transaction')
|
|
118
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple MenuButtonAuths' })
|
|
119
|
+
async deleteMenuButtonAuths(
|
|
120
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
121
|
+
@Ctx() context: any
|
|
122
|
+
): Promise<boolean> {
|
|
123
|
+
const { domain, tx, user } = context.state
|
|
124
|
+
|
|
125
|
+
let delEntitis = ids.map(id=>{
|
|
126
|
+
return {domain,id,updater:user}
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
await tx.getRepository(MenuButtonAuth).remove(delEntitis)
|
|
130
|
+
|
|
131
|
+
return true
|
|
132
|
+
}
|
|
133
|
+
}
|