pui9-docgen 1.16.4

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.
@@ -0,0 +1,517 @@
1
+ <template>
2
+ <div class="pui-form">
3
+ <v-form class="mb-4 pb-4" ref="form" v-model="valid" lazy-validation v-if="modelLoaded">
4
+ <v-layout wrap class="pui-form-layout">
5
+ <v-flex xs12 lg5>
6
+ <pui-field-set :title="$t('puidocgentemplate.form.data')">
7
+ <v-layout wrap>
8
+ <v-flex xs12>
9
+ <pui-text-field
10
+ :label="this.$t('puidocgentemplate.name')"
11
+ v-model="model.name"
12
+ maxlength="100"
13
+ toplabel
14
+ required
15
+ :disabled="formDisabled"
16
+ ></pui-text-field>
17
+ </v-flex>
18
+ <v-flex xs12>
19
+ <pui-text-area
20
+ :label="this.$t('puidocgentemplate.description')"
21
+ v-model="model.description"
22
+ maxlength="1000"
23
+ toplabel
24
+ :disabled="formDisabled"
25
+ ></pui-text-area>
26
+ </v-flex>
27
+ </v-layout>
28
+ </pui-field-set>
29
+ <pui-field-set :title="$t('puidocgentemplate.form.viewAndTemplate')">
30
+ <v-layout wrap>
31
+ <v-flex xs12 md8 xl9>
32
+ <pui-text-field
33
+ :label="this.$t('puidocgentemplate.filename')"
34
+ v-model="model.filename"
35
+ toplabel
36
+ required
37
+ disabled
38
+ ></pui-text-field>
39
+ <input v-show="false" type="file" accept=".doc, .docx, .odt" ref="document" @change="onFilePicked" />
40
+ </v-flex>
41
+ <v-flex xs12 md4 xl3>
42
+ <v-btn color="primary" v-if="isCreatingElement" @click="pickFile" style="margin-top: 20px">{{
43
+ $t('puidocgentemplate.selectfile')
44
+ }}</v-btn>
45
+ </v-flex>
46
+ </v-layout>
47
+ <v-layout wrap>
48
+ <v-flex xs12>
49
+ <pui-select
50
+ id="mainmodel"
51
+ attach="mainmodel"
52
+ :label="$t('puidocgentemplate.mainmodel')"
53
+ toplabel
54
+ required
55
+ clearable
56
+ :disabled="formDisabled || !isCreatingElement"
57
+ v-model="model"
58
+ modelName="puidocgenmodel"
59
+ :itemsToSelect="[{ model: model.mainmodel }]"
60
+ :modelFormMapping="{ model: 'mainmodel' }"
61
+ itemValue="model"
62
+ itemText="label"
63
+ ></pui-select>
64
+ </v-flex>
65
+ <v-flex xs12>
66
+ <pui-select
67
+ v-if="model.mainmodel && columns.length > 0"
68
+ id="columnfilename"
69
+ attach="columnfilename"
70
+ :key="'columnfilename_' + columnfilenameKey"
71
+ :label="$t('puidocgentemplate.columnfilename')"
72
+ toplabel
73
+ clearable
74
+ :disabled="formDisabled"
75
+ v-model="model.columnfilename"
76
+ :items="columns"
77
+ :itemsToSelect="model.columnfilename"
78
+ itemValue="name"
79
+ itemText="name"
80
+ multiple
81
+ ></pui-select>
82
+ </v-flex>
83
+ <v-flex xs12>
84
+ <pui-select
85
+ v-if="model.mainmodel && modelsByEntity.length > 0"
86
+ id="models"
87
+ attach="models"
88
+ :key="'models_' + modelsKey"
89
+ :label="$t('puidocgentemplate.models')"
90
+ toplabel
91
+ clearable
92
+ :disabled="formDisabled"
93
+ v-model="model.models"
94
+ :items="modelsByEntity"
95
+ :itemsToSelect="model.models"
96
+ itemValue="name"
97
+ itemText="name"
98
+ multiple
99
+ ></pui-select>
100
+ </v-flex>
101
+ </v-layout>
102
+ </pui-field-set>
103
+ </v-flex>
104
+ <v-flex xs12 lg7>
105
+ <pui-docgen-template-mapping
106
+ ref="puidocgentemplatemapping"
107
+ :templateid="model.id"
108
+ :title="$t('puidocgentemplate.form.mapping')"
109
+ :subtitle="$t('puidocgentemplate.help.mapping')"
110
+ :systemFields="systemFields"
111
+ :tableFields="tableFields"
112
+ :mappings="model.mapping"
113
+ :columns="columns"
114
+ :disabled="formDisabled"
115
+ :isCreatingElement="isCreatingElement"
116
+ :modelName="modelName"
117
+ ></pui-docgen-template-mapping>
118
+ <pui-docgen-template-filter
119
+ ref="puidocgentemplatefilter"
120
+ :title="$t('puidocgentemplate.form.filter')"
121
+ :subtitle="$t('puidocgentemplate.help.filter')"
122
+ :filter="model.filter"
123
+ :columns="columns"
124
+ :disabled="formDisabled"
125
+ ></pui-docgen-template-filter>
126
+ <pui-docgen-template-parameter
127
+ ref="puidocgentemplateparameter"
128
+ :title="$t('puidocgentemplate.form.parameters')"
129
+ :subtitle="$t('puidocgentemplate.help.parameters')"
130
+ :columns="columns"
131
+ :parameters="model.parameters"
132
+ :disabled="formDisabled"
133
+ ></pui-docgen-template-parameter>
134
+ </v-flex>
135
+ </v-layout>
136
+
137
+ <pui-form-footer>
138
+ <pui-form-footer-btns
139
+ :formDisabled="formDisabled"
140
+ :saveDisabled="saving"
141
+ :saveAndNew="saveAndNew"
142
+ :saveAndUpdate="saveAndUpdate"
143
+ :save="save"
144
+ :back="back"
145
+ ></pui-form-footer-btns>
146
+ </pui-form-footer>
147
+ </v-form>
148
+ <pui-form-loading v-else></pui-form-loading>
149
+ </div>
150
+ </template>
151
+
152
+ <script>
153
+ import PuiFormMethodsMixin from '../../../../pui9-mixins/PuiFormMethodsMixin';
154
+ import PuiDocgenTemplateMapping from './PuiDocgenTemplateMapping';
155
+ import PuiDocgenTemplateFilter from './PuiDocgenTemplateFilter';
156
+ import PuiDocgenTemplateParameter from './PuiDocgenTemplateParameter';
157
+
158
+ export default {
159
+ name: 'PuiDocgenTemplateForm',
160
+ mixins: [PuiFormMethodsMixin],
161
+ components: {
162
+ PuiDocgenTemplateMapping,
163
+ PuiDocgenTemplateFilter,
164
+ PuiDocgenTemplateParameter
165
+ },
166
+ data() {
167
+ return {
168
+ modelName: 'puidocgentemplate',
169
+ fileTypes: {
170
+ 'application/msword': 'fas fa-file-word',
171
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'fas fa-file-word',
172
+ 'application/vnd.oasis.opendocument.text': 'fas fa-file-word'
173
+ },
174
+ modelsByEntity: [],
175
+ systemFields: [],
176
+ tableFields: [],
177
+ columns: [],
178
+ selectedFile: null,
179
+ selectedFileType: null,
180
+ columnfilenameKey: 0,
181
+ modelsKey: 0
182
+ };
183
+ },
184
+ mounted() {
185
+ this.$puiEvents.$on('puiModelsLoaded', () => {
186
+ if (this.model.mainmodel) {
187
+ const modelSelected = this.$store.state.models[this.model.mainmodel];
188
+ if (modelSelected) this.setColumns(modelSelected);
189
+ }
190
+ });
191
+ this.$puiEvents.$on('onPuiSelect_selectedItems-mainmodel', (newVal) => {
192
+ const lupaModel = newVal.model;
193
+ this.modelsByEntity = [];
194
+ this.columns = [];
195
+ if (lupaModel) {
196
+ for (const modelName in this.$store.state.models) {
197
+ const model = this.$store.state.models[modelName];
198
+
199
+ if (lupaModel.entity !== model.entity) {
200
+ continue;
201
+ }
202
+
203
+ if (this.model.models) {
204
+ this.model.models = this.model.models.filter((selectedModel) => {
205
+ return selectedModel.name === model.name;
206
+ });
207
+ } else {
208
+ this.model.models = [];
209
+ }
210
+
211
+ this.modelsByEntity.push({ name: model.name });
212
+
213
+ if (this.columns.length > 0) {
214
+ continue;
215
+ }
216
+
217
+ this.setColumns(model);
218
+
219
+ if (this.model.columnfilename) {
220
+ this.model.columnfilename = this.model.columnfilename.filter((col) => {
221
+ for (let i = 0, columnsLength = this.columns.length; i < columnsLength; i++) {
222
+ if (col.name === this.columns[i].name) {
223
+ return true;
224
+ }
225
+ }
226
+ return false;
227
+ });
228
+ } else {
229
+ this.model.columnfilename = [];
230
+ }
231
+ }
232
+ }
233
+ this.columnfilenameKey += 1;
234
+ this.modelsKey += 1;
235
+ if (this.isCreatingElement) {
236
+ this.getMappings();
237
+ }
238
+ });
239
+ },
240
+ beforeDestroy() {
241
+ this.$puiEvents.$off('onPuiSelect_selectedItems-mainmodel');
242
+ this.$puiEvents.$off('puiModelsLoaded');
243
+ },
244
+ methods: {
245
+ afterGetData() {
246
+ this.getSystemFields();
247
+ this.getTableFields();
248
+
249
+ if (this.model.mapping) {
250
+ const tempMapping = JSON.parse(this.model.mapping);
251
+ let tempTags = [];
252
+ this.model.mapping = [];
253
+ for (let i = 0, mappingLength = tempMapping.length; i < mappingLength; i++) {
254
+ // remove duplicates
255
+ if (tempTags.includes(tempMapping[i].tag)) {
256
+ continue;
257
+ }
258
+ tempTags.push(tempMapping[i].tag);
259
+ this.model.mapping.push(tempMapping[i]);
260
+ }
261
+ }
262
+ if (this.model.filter) {
263
+ this.model.filter = JSON.parse(this.model.filter);
264
+ if (this.model.filter === null) {
265
+ this.model.filter = { groupOp: 'and', groups: [], rules: [] };
266
+ }
267
+ }
268
+ if (this.model.parameters) {
269
+ this.model.parameters = JSON.parse(this.model.parameters);
270
+ }
271
+ if (this.model.models) {
272
+ this.model.models = this.convertModelNamesToModelObjects(this.model.models);
273
+ }
274
+ if (this.model.columnfilename) {
275
+ this.model.columnfilename = this.convertModelNamesToModelObjects(this.model.columnfilename);
276
+ }
277
+ },
278
+ convertModelNamesToModelObjects(modelnames) {
279
+ const models = JSON.parse(modelnames);
280
+ const modelobjects = [];
281
+ for (let i = 0; i < models.length; i++) {
282
+ modelobjects.push({ name: models[i] });
283
+ }
284
+ return modelobjects;
285
+ },
286
+ convertModelObjectsToModelNames(modelobjects) {
287
+ const modelnames = [];
288
+ for (let i = 0; i < modelobjects.length; i++) {
289
+ modelnames.push(modelobjects[i].name);
290
+ }
291
+ return JSON.stringify(modelnames);
292
+ },
293
+ pickFile() {
294
+ this.$refs.document.click();
295
+ },
296
+ onFilePicked(e) {
297
+ const files = e.target.files;
298
+ if (files[0] !== undefined) {
299
+ const file = files[0];
300
+ if (file.name.lastIndexOf('.') <= 0) {
301
+ return;
302
+ }
303
+
304
+ this.model.filename = file.name;
305
+ const fr = new window.FileReader();
306
+ fr.addEventListener('load', () => {
307
+ this.selectedFile = file; // this is the file that can be sent to server...
308
+ this.selectedFileType = this.fileTypes[file.type];
309
+ this.getMappings();
310
+ });
311
+ fr.readAsDataURL(file);
312
+ } else {
313
+ this.model.filename = null;
314
+ this.selectedFile = null;
315
+ this.selectedFileType = null;
316
+ this.getMappings();
317
+ }
318
+ },
319
+ getSystemFields() {
320
+ this.saving = true;
321
+ this.$puiRequests.getRequest(
322
+ this.modelDependency.url.getSystemFields,
323
+ null,
324
+ (response) => {
325
+ this.saving = false;
326
+ if (response && response.data) {
327
+ this.systemFields = response.data;
328
+ }
329
+ },
330
+ (error) => {
331
+ this.saving = false;
332
+ this.onSaveError && this.onSaveError();
333
+ this.onError(error);
334
+ }
335
+ );
336
+ },
337
+ getTableFields() {
338
+ const params = { model: 'puidocgenattribute' };
339
+ this.saving = true;
340
+ this.$puiRequests.postRequest(
341
+ '/puisearch',
342
+ params,
343
+ (response) => {
344
+ this.saving = false;
345
+ if (response && response.data && response.data.data) {
346
+ this.tableFields = response.data.data;
347
+ }
348
+ },
349
+ (error) => {
350
+ this.saving = false;
351
+ this.onSaveError && this.onSaveError();
352
+ this.onError(error);
353
+ }
354
+ );
355
+ },
356
+ getMappings() {
357
+ if (!this.model.mainmodel || !this.selectedFile) {
358
+ this.model.mapping = [];
359
+ return;
360
+ }
361
+
362
+ const formData = new window.FormData();
363
+ formData.append('file', this.selectedFile, this.selectedFile.name);
364
+
365
+ this.saving = true;
366
+ this.$puiRequests.postRequest(
367
+ this.modelDependency.url.getTemplateMapping,
368
+ formData,
369
+ (response) => {
370
+ this.saving = false;
371
+ if (response && response.data) {
372
+ let tempTags = [];
373
+ this.model.mapping = [];
374
+ for (let i = 0, mappingLength = response.data.length; i < mappingLength; i++) {
375
+ // remove duplicates
376
+ if (tempTags.includes(response.data[i].tag)) {
377
+ continue;
378
+ }
379
+ tempTags.push(response.data[i].tag);
380
+ this.model.mapping.push(response.data[i]);
381
+ }
382
+ }
383
+ },
384
+ (error) => {
385
+ this.saving = false;
386
+ this.onSaveError && this.onSaveError();
387
+ this.onError(error);
388
+ }
389
+ );
390
+ },
391
+ beforeSave() {
392
+ this.model.filter = this.$refs.puidocgentemplatefilter.retrieveGroupsData();
393
+ },
394
+ insert(shouldStayInPage) {
395
+ const formData = new window.FormData();
396
+ formData.append('name', this.model.name);
397
+ formData.append('mainmodel', this.model.mainmodel);
398
+ formData.append('mapping', JSON.stringify(this.model.mapping));
399
+ formData.append('file', this.selectedFile, this.selectedFile.name);
400
+ formData.append('filename', this.selectedFile.name);
401
+ formData.append('filter', JSON.stringify(this.model.filter));
402
+ formData.append('parameters', JSON.stringify(this.model.parameters));
403
+ if (this.model.description) {
404
+ formData.append('description', this.model.description);
405
+ }
406
+ if (this.model.columnfilename && Array.isArray(this.model.columnfilename)) {
407
+ formData.append('columnfilename', this.convertModelObjectsToModelNames(this.model.columnfilename));
408
+ }
409
+ if (this.model.models && Array.isArray(this.model.models)) {
410
+ formData.append('models', this.convertModelObjectsToModelNames(this.model.models));
411
+ }
412
+
413
+ this.saving = true;
414
+ this.$puiRequests.uploadFileRequest(
415
+ this.modelDependency.url.uploadTemplate,
416
+ formData,
417
+ (response) => {
418
+ this.saving = false;
419
+ if (response.status === 200) {
420
+ this.$puiEvents.$emit(`onPui-insertRow-dataTable-${this.modelDependency.name}`, response.data);
421
+ this.afterSave && this.afterSave(response.data);
422
+ if (!(shouldStayInPage === true)) {
423
+ if (this.internal.afterInsertGoToUpdate) {
424
+ this.goToUpdate(response.data);
425
+ } else if (this.internal.afterInsertGoToCreate) {
426
+ // Router not allow to go same router with same parameters
427
+ this.refreshRouter();
428
+ } else {
429
+ this.back();
430
+ }
431
+ }
432
+ } else {
433
+ this.onError(response);
434
+ }
435
+ this.resetAfterSaveActions();
436
+ },
437
+ (error) => {
438
+ this.resetAfterSaveActions();
439
+ this.saving = false;
440
+ this.onSaveError && this.onSaveError();
441
+ this.onError(error);
442
+ }
443
+ );
444
+ },
445
+ update(shouldStayInPage) {
446
+ this.saving = true;
447
+ const data = JSON.parse(JSON.stringify(this.model));
448
+ data.mapping = JSON.stringify(data.mapping);
449
+ data.filter = JSON.stringify(data.filter);
450
+ data.parameters = JSON.stringify(data.parameters);
451
+ if (this.model.models && Array.isArray(this.model.models)) {
452
+ data.models = this.convertModelObjectsToModelNames(this.model.models);
453
+ }
454
+ if (this.model.columnfilename && Array.isArray(this.model.columnfilename)) {
455
+ data.columnfilename = this.convertModelObjectsToModelNames(this.model.columnfilename);
456
+ }
457
+
458
+ this.$puiRequests.putRequest(
459
+ this.modelDependency.url.update,
460
+ data,
461
+ (response) => {
462
+ this.saving = false;
463
+ this.$puiEvents.$emit(`onPui-editRow-dataTable-${this.modelDependency.name}`, response.data);
464
+ this.afterSave && this.afterSave(response.data);
465
+ if (!(shouldStayInPage === true)) {
466
+ if (this.internal.afterUpdateGoToUpdate) {
467
+ // Router not allow to go same router with same parameters
468
+ this.refreshRouter();
469
+ } else if (this.internal.afterUpdateGoToCreate) {
470
+ this.goToCreate();
471
+ } else {
472
+ this.back();
473
+ }
474
+ }
475
+ this.resetAfterSaveActions();
476
+ },
477
+ (error) => {
478
+ this.resetAfterSaveActions();
479
+ this.saving = false;
480
+ this.onSaveError && this.onSaveError();
481
+ this.onError(error);
482
+ }
483
+ );
484
+ },
485
+ setColumns(model) {
486
+ for (const index in model.columns) {
487
+ const column = model.columns[index];
488
+ let title = this.$puiI18n.t(column.title);
489
+ title = title !== column.title ? title : column.name;
490
+ this.columns.push({
491
+ name: column.name,
492
+ type: column.type,
493
+ title: title
494
+ });
495
+ }
496
+ this.columns.sort((a, b) => (a.title < b.title ? -1 : a.title > b.title ? 1 : 0));
497
+ }
498
+ }
499
+ };
500
+ </script>
501
+
502
+ <style lang="postcss">
503
+ .puidocgentemplate-subtitle {
504
+ text-align: center;
505
+ }
506
+ .puidocgentemplate-table {
507
+ margin: 0px auto;
508
+ th.docgen-table-column {
509
+ border-bottom-width: 1px;
510
+ border-bottom-color: black;
511
+ border-bottom-style: solid;
512
+ }
513
+ }
514
+ .puidocgentemplate-table-column {
515
+ text-align: center;
516
+ }
517
+ </style>
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <div>
3
+ <pui-datatable :modelName="modelName" :actions="actions"></pui-datatable>
4
+ <pui-docgen-template-modals :modelName="modelName"></pui-docgen-template-modals>
5
+ <pui-docgen-template-parameters-dialog></pui-docgen-template-parameters-dialog>
6
+ </div>
7
+ </template>
8
+
9
+ <script>
10
+ import PuiDocgenTemplateActions from './PuiDocgenTemplateActions.js';
11
+ import PuiDocgenTemplateModals from './PuiDocgenTemplateModals.vue';
12
+
13
+ export default {
14
+ name: 'PuiDocgenTemplateGrid',
15
+ components: { PuiDocgenTemplateModals },
16
+ data() {
17
+ return {
18
+ modelName: 'puidocgentemplate',
19
+ actions: PuiDocgenTemplateActions.actions
20
+ };
21
+ }
22
+ };
23
+ </script>