1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import * as _ from "lodash";
import {ActionOnFirstLevel} from "./firstLevel/firstLevel.actions";
import {ServiceInstanceActions} from "../../models/serviceInstanceActions";
import {ServiceState} from "./main.reducer";
import {ServiceInstance} from "../../models/serviceInstance";
export function deleteFirstLevel(state: ServiceState, action: ActionOnFirstLevel,shouldUpdateServiceValidationCounter: boolean){
let newState = _.cloneDeep(state);
let firstLevel = newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey];
let oldAction = firstLevel.action;
if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState;
if (shouldUpdateServiceValidationCounter){
updateServiceValidationCounter(newState, firstLevel['isMissingData'], false, action.serviceId);
}
newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey].action = (oldAction + '_Delete') as ServiceInstanceActions;
return newState;
}
export function updateServiceValidationCounter(newState: any, oldValidationState: boolean, newValidationState: boolean, serviceUuid: string) {
if (oldValidationState && !newValidationState) {
newState.serviceInstance[serviceUuid].validationCounter--;
} else if (!oldValidationState && newValidationState) {
newState.serviceInstance[serviceUuid].validationCounter++;
}
resetUpgradeStatus(newState, serviceUuid);
};
function resetUpgradeStatus(newState: any, serviceUuid: string){
newState.serviceInstance[serviceUuid].upgradedVFMSonsCounter = 0;
newState.serviceInstance[serviceUuid].isUpgraded = false;
}
export const updateUniqueNames = (oldName: string, newName: string, serviceInstance: ServiceInstance): void => {
let existingNames = serviceInstance.existingNames;
if (!_.isNil(oldName) && oldName.toLowerCase() in existingNames) {
delete existingNames[oldName.toLowerCase()];
}
if (!_.isNil(newName)) {
existingNames[newName.toLowerCase()] = "";
}
};
export const calculateNextUniqueModelName = (nfModelName: string, serviceId: string, state: any, levelName: string): string => {
let counter: number = null;
while (true) {
let pattern = !_.isNil(counter) ? ("_" + counter) : "";
if (!_.isNil(state.serviceInstance[serviceId][levelName][nfModelName + pattern])) {
counter = counter ? (counter + 1) : 1;
} else {
return nfModelName + pattern;
}
}
};
|