eservices-core 1.0.516 → 1.0.518
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/use-wizard.d.ts +49 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +148 -1
- package/dist/services/process-wizard-service.d.ts +19 -2
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IWizardFixedResponse } from "./../index";
|
|
2
|
+
/**
|
|
3
|
+
* @description Метод для работы с wizard и для контроллирования состояния.
|
|
4
|
+
* @param {String} entity Название сущности для которой вызывается wizard. Иными словами можно принимать данную строку
|
|
5
|
+
* как название области в которую для которой ищется процесс.
|
|
6
|
+
* @param {String} processName Название процесса, которые будет выполняться далее.
|
|
7
|
+
* @param options Объект опций, для изменения поведения визарда.
|
|
8
|
+
* */
|
|
9
|
+
export declare function useWizard(entity: string, processName: string, options: IWizardOptions): {
|
|
10
|
+
initialize: () => Promise<void>;
|
|
11
|
+
state: {
|
|
12
|
+
wait: string | false;
|
|
13
|
+
};
|
|
14
|
+
currentStepConfig: any;
|
|
15
|
+
next: (changes?: any) => Promise<any>;
|
|
16
|
+
};
|
|
17
|
+
export interface IWizardState {
|
|
18
|
+
/**
|
|
19
|
+
* @description Параметр показыает на то, что на данный момент выполняется любой запрос на получение/изменение
|
|
20
|
+
* данных. В случае null, false - запрос не выполняется. Если тип занчения string, то запрос выполняется, а хранимое
|
|
21
|
+
* значение является label для спинера.
|
|
22
|
+
* */
|
|
23
|
+
wait: null | false | string;
|
|
24
|
+
}
|
|
25
|
+
export interface IWizardOptions {
|
|
26
|
+
onValidation: (arr: IWizardFixedResponse['validationResults']) => void;
|
|
27
|
+
onCompleted: (data: IWizardCompletedResult) => void;
|
|
28
|
+
onConfirmation: (data: IWizardConfirmationResult) => void;
|
|
29
|
+
presets?: Record<string, any>;
|
|
30
|
+
}
|
|
31
|
+
export declare type IWizardCompletedResult = IWizardFixedResponse & {
|
|
32
|
+
statusName: 'Completed';
|
|
33
|
+
};
|
|
34
|
+
export declare type IWizardConfirmationResult = IWizardFixedResponse & {
|
|
35
|
+
statusName: 'FinalStepWithConfirmation';
|
|
36
|
+
};
|
|
37
|
+
export declare type IWizardValidationErrorResult = IWizardFixedResponse & {
|
|
38
|
+
statusName: 'ValidationError';
|
|
39
|
+
};
|
|
40
|
+
export interface IWizardStepConfig {
|
|
41
|
+
label?: string;
|
|
42
|
+
name: string;
|
|
43
|
+
number: number;
|
|
44
|
+
fields: {
|
|
45
|
+
label: string;
|
|
46
|
+
name: string;
|
|
47
|
+
type: string;
|
|
48
|
+
}[];
|
|
49
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { ListCell } from "./classes/List";
|
|
|
16
16
|
import { IListCell } from "./classes/new/List";
|
|
17
17
|
import { IAffectedEntity } from "./hooks/use-form-action";
|
|
18
18
|
import { IWizardFixedResponse } from "./services/process-wizard-service";
|
|
19
|
+
import { IWizardCompletedResult, IWizardConfirmationResult, IWizardValidationErrorResult, IWizardStepConfig } from "./hooks/use-wizard";
|
|
19
20
|
import { setupSocket, useSocket } from "./socket/use-socket";
|
|
20
21
|
import WidgetBreadcrumbs from "./widgets/breadcrumbs/widget-breadcrumbs.vue";
|
|
21
22
|
import WidgetList from "./widgets/list/widget-list.vue";
|
|
@@ -69,6 +70,7 @@ import { useTableRequest, useTableState } from "./classes/table/Table";
|
|
|
69
70
|
import { useCommunication } from "./classes/Communication";
|
|
70
71
|
import useFormRequest from "./hooks/use-form-request";
|
|
71
72
|
import { useProvideList, useListConfig, useListOrder, useListFilter } from "./classes/new/List";
|
|
73
|
+
import { useWizard } from "./hooks/use-wizard";
|
|
72
74
|
import { SYMBOL_ROW } from "./classes/table/Table";
|
|
73
75
|
export {
|
|
74
76
|
/**
|
|
@@ -84,7 +86,7 @@ export { fileService, processWizardService, viewService, authService, dataServic
|
|
|
84
86
|
/**
|
|
85
87
|
* HOOKS
|
|
86
88
|
* */
|
|
87
|
-
export { useFormMetadata, useFormAction, useFormLabel, useFormRequestData, useListFilter, useListOrder, useListState, useCustomerState, useTableState, useTableRequest, useCommunication, useFormRequest, useManagerState, useProvideList, useListConfig, };
|
|
89
|
+
export { useFormMetadata, useFormAction, useFormLabel, useFormRequestData, useListFilter, useListOrder, useListState, useCustomerState, useTableState, useTableRequest, useCommunication, useFormRequest, useManagerState, useProvideList, useListConfig, useWizard };
|
|
88
90
|
/**
|
|
89
91
|
* All components binding with VueComponents must have name started with Widget.
|
|
90
92
|
* */
|
|
@@ -110,7 +112,7 @@ export { utils, Request };
|
|
|
110
112
|
/**
|
|
111
113
|
* Interfaces and Types
|
|
112
114
|
* */
|
|
113
|
-
export { IListCell, IListConfig, IFilterConfig, ISortConfig, ICustomerContext, IActionExecuteResult, IValidationEffect, INotificationCard, ApplicationType, IAffectedEntity, IWizardFixedResponse };
|
|
115
|
+
export { IListCell, IListConfig, IFilterConfig, ISortConfig, ICustomerContext, IActionExecuteResult, IValidationEffect, INotificationCard, ApplicationType, IAffectedEntity, IWizardFixedResponse, IWizardCompletedResult, IWizardConfirmationResult, IWizardValidationErrorResult, IWizardStepConfig };
|
|
114
116
|
declare const _default: {
|
|
115
117
|
widgets: {
|
|
116
118
|
inputs: {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* eservices-core v1.0.
|
|
2
|
+
* eservices-core v1.0.518
|
|
3
3
|
* (c) 2023 ESERVICES
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
@@ -5517,6 +5517,152 @@ function useFormRequest(form, formParams) {
|
|
|
5517
5517
|
return { shadowFormState, initShadow };
|
|
5518
5518
|
}
|
|
5519
5519
|
|
|
5520
|
+
function checkCompleted(res) {
|
|
5521
|
+
return res.statusName === 'Completed';
|
|
5522
|
+
}
|
|
5523
|
+
function checkConfirmation(res) {
|
|
5524
|
+
return res.statusName === "FinalStepWithConfirmation";
|
|
5525
|
+
}
|
|
5526
|
+
function checkValidationError(res) {
|
|
5527
|
+
return res.statusName === 'ValidationError';
|
|
5528
|
+
}
|
|
5529
|
+
/**
|
|
5530
|
+
* @description Метод для работы с wizard и для контроллирования состояния.
|
|
5531
|
+
* @param {String} entity Название сущности для которой вызывается wizard. Иными словами можно принимать данную строку
|
|
5532
|
+
* как название области в которую для которой ищется процесс.
|
|
5533
|
+
* @param {String} processName Название процесса, которые будет выполняться далее.
|
|
5534
|
+
* @param options Объект опций, для изменения поведения визарда.
|
|
5535
|
+
* */
|
|
5536
|
+
function useWizard(entity, processName, options) {
|
|
5537
|
+
/**
|
|
5538
|
+
* @description Хранит значение токена, который передается при запросе.
|
|
5539
|
+
* */
|
|
5540
|
+
let token = null;
|
|
5541
|
+
const state = vue.reactive({
|
|
5542
|
+
wait: null
|
|
5543
|
+
});
|
|
5544
|
+
let stepsConfig = [];
|
|
5545
|
+
let currentStep = null;
|
|
5546
|
+
const currentStepConfig = vue.ref(null);
|
|
5547
|
+
function updateFormFields() {
|
|
5548
|
+
currentStepConfig.value = stepsConfig.find(v => v.name === currentStep) || null;
|
|
5549
|
+
}
|
|
5550
|
+
function getFields() {
|
|
5551
|
+
var _a;
|
|
5552
|
+
if (!currentStep)
|
|
5553
|
+
return [];
|
|
5554
|
+
return ((_a = stepsConfig.find(v => v.name === currentStep)) === null || _a === void 0 ? void 0 : _a.fields) || [];
|
|
5555
|
+
}
|
|
5556
|
+
function handleAnswer(res) {
|
|
5557
|
+
updateFormFields();
|
|
5558
|
+
if (checkValidationError(res)) {
|
|
5559
|
+
return void options.onValidation(res.validationResults);
|
|
5560
|
+
}
|
|
5561
|
+
if ((res.statusName === 'FinalStep' || res.statusName === 'NextStep') && (!getFields().length || checkFieldsForValues(getFields(), options.presets))) {
|
|
5562
|
+
return next(options.presets || {});
|
|
5563
|
+
}
|
|
5564
|
+
if (checkCompleted(res))
|
|
5565
|
+
options.onCompleted(res);
|
|
5566
|
+
if (checkConfirmation(res))
|
|
5567
|
+
options.onConfirmation(res);
|
|
5568
|
+
}
|
|
5569
|
+
/**
|
|
5570
|
+
* @description Функция инициализации процесса. Получает данные о процессе и запускает первый шаг.
|
|
5571
|
+
* */
|
|
5572
|
+
function initialize() {
|
|
5573
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5574
|
+
try {
|
|
5575
|
+
yield updateWizardInformation();
|
|
5576
|
+
yield requestStartProcess();
|
|
5577
|
+
}
|
|
5578
|
+
catch (e) {
|
|
5579
|
+
const { message } = parseError(e);
|
|
5580
|
+
NotificationSystem.add('error', message);
|
|
5581
|
+
}
|
|
5582
|
+
});
|
|
5583
|
+
}
|
|
5584
|
+
/**
|
|
5585
|
+
* @description Получение информации о wizard-процессе.
|
|
5586
|
+
* */
|
|
5587
|
+
function updateWizardInformation() {
|
|
5588
|
+
state.wait = "Loading process information.";
|
|
5589
|
+
return processWizardService.getStartConfig(processName, entity)
|
|
5590
|
+
.then(res => {
|
|
5591
|
+
stepsConfig = res.steps.map(step => ({
|
|
5592
|
+
label: step.title,
|
|
5593
|
+
name: step.stepName,
|
|
5594
|
+
number: step.number,
|
|
5595
|
+
fields: step.frontendEntity.objectTypes.reduce((acc, frontendEntity) => {
|
|
5596
|
+
frontendEntity.properties.forEach(field => {
|
|
5597
|
+
acc.push({
|
|
5598
|
+
name: field.name,
|
|
5599
|
+
label: field.title,
|
|
5600
|
+
type: field.refEntityName || field.dataType
|
|
5601
|
+
});
|
|
5602
|
+
});
|
|
5603
|
+
return acc;
|
|
5604
|
+
}, [])
|
|
5605
|
+
}));
|
|
5606
|
+
})
|
|
5607
|
+
.then(res => {
|
|
5608
|
+
state.wait = false;
|
|
5609
|
+
return res;
|
|
5610
|
+
});
|
|
5611
|
+
}
|
|
5612
|
+
function saveStepState(response) {
|
|
5613
|
+
currentStep = response.nextStepName;
|
|
5614
|
+
token = response.token;
|
|
5615
|
+
return response;
|
|
5616
|
+
}
|
|
5617
|
+
function handleError(error) {
|
|
5618
|
+
const parsedError = parseError(error);
|
|
5619
|
+
NotificationSystem.add('error', parsedError.message);
|
|
5620
|
+
}
|
|
5621
|
+
/**
|
|
5622
|
+
* @description Запрос(первый вызов) визарда в самом начале для инициализации процессе. В интерфейсе должен
|
|
5623
|
+
* выполняться автоматически, после чтения метаданных.
|
|
5624
|
+
* */
|
|
5625
|
+
function requestStartProcess() {
|
|
5626
|
+
state.wait = 'Starting process';
|
|
5627
|
+
return processWizardService.startProcess(processName, entity)
|
|
5628
|
+
.then(saveStepState)
|
|
5629
|
+
.then(handleAnswer)
|
|
5630
|
+
.catch(handleError)
|
|
5631
|
+
.finally(() => {
|
|
5632
|
+
state.wait = null;
|
|
5633
|
+
});
|
|
5634
|
+
}
|
|
5635
|
+
function next(changes = {}) {
|
|
5636
|
+
if (!token || !currentStep)
|
|
5637
|
+
return Promise.reject('Not step or token.');
|
|
5638
|
+
state.wait = 'Expect the result';
|
|
5639
|
+
return processWizardService.runStep(processName, entity, currentStep, token, changes)
|
|
5640
|
+
.then(saveStepState)
|
|
5641
|
+
.then(handleAnswer)
|
|
5642
|
+
.catch(handleError)
|
|
5643
|
+
.finally(() => {
|
|
5644
|
+
state.wait = false;
|
|
5645
|
+
});
|
|
5646
|
+
}
|
|
5647
|
+
return {
|
|
5648
|
+
initialize,
|
|
5649
|
+
state,
|
|
5650
|
+
currentStepConfig: vue.readonly(currentStepConfig),
|
|
5651
|
+
next
|
|
5652
|
+
};
|
|
5653
|
+
}
|
|
5654
|
+
/**
|
|
5655
|
+
* @description Функция проверяет являются ли поля самозаполненными. В случае если все "да", то вёрнся true.
|
|
5656
|
+
* */
|
|
5657
|
+
function checkFieldsForValues(fields, values) {
|
|
5658
|
+
for (let i = 0; i < fields.length; i++) {
|
|
5659
|
+
const item = fields[i];
|
|
5660
|
+
if (!jenesiusVueForm.utils.getPropFromObject(values, item.name))
|
|
5661
|
+
return false;
|
|
5662
|
+
}
|
|
5663
|
+
return true;
|
|
5664
|
+
}
|
|
5665
|
+
|
|
5520
5666
|
const utils = {
|
|
5521
5667
|
clickOutside,
|
|
5522
5668
|
requestHandler,
|
|
@@ -5597,5 +5743,6 @@ exports.useProvideList = useProvideList;
|
|
|
5597
5743
|
exports.useSocket = useSocket;
|
|
5598
5744
|
exports.useTableRequest = useTableRequest;
|
|
5599
5745
|
exports.useTableState = useTableState;
|
|
5746
|
+
exports.useWizard = useWizard;
|
|
5600
5747
|
exports.utils = utils;
|
|
5601
5748
|
exports.viewService = viewService;
|
|
@@ -31,15 +31,32 @@ interface ObjectType {
|
|
|
31
31
|
}
|
|
32
32
|
interface IWizardProcessResponse {
|
|
33
33
|
createdEntites: [];
|
|
34
|
-
dataSets:
|
|
34
|
+
dataSets: {
|
|
35
|
+
entityName: string;
|
|
36
|
+
note: null;
|
|
37
|
+
records: {
|
|
38
|
+
primaryKey: Record<string, any>;
|
|
39
|
+
values: any[];
|
|
40
|
+
}[];
|
|
41
|
+
title: string;
|
|
42
|
+
typeName: any;
|
|
43
|
+
viewFields: string[];
|
|
44
|
+
}[];
|
|
35
45
|
nextStepName: string;
|
|
36
46
|
notes: any[];
|
|
37
47
|
statusCode: number;
|
|
38
48
|
statusName: string;
|
|
39
49
|
token: string;
|
|
40
|
-
validationResults: [];
|
|
50
|
+
validationResults: IValidationItem[];
|
|
41
51
|
}
|
|
42
52
|
export declare type IWizardFixedResponse = Omit<IWizardProcessResponse, 'createdEntites'> & {
|
|
43
53
|
createdEntities: IWizardProcessResponse['createdEntites'];
|
|
44
54
|
};
|
|
55
|
+
export interface IValidationItem {
|
|
56
|
+
message: string;
|
|
57
|
+
name: string;
|
|
58
|
+
statusCode: number;
|
|
59
|
+
statusName: string;
|
|
60
|
+
title: string;
|
|
61
|
+
}
|
|
45
62
|
export {};
|