InstanceBeAttributesMap,
InstanceFeAttributesMap
} from "app/models/attributes-outputs/attribute-fe-map";
+import {
+ InstanceBePropertiesMap
+} from "app/models/properties-inputs/property-fe-map";
import {ModalService} from "../../services/modal.service";
import {InstanceFeDetails} from "../../../models/instance-fe-details";
import {HierarchyDisplayOptions} from "../../components/logic/hierarchy-navigtion/hierarchy-display-options";
import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model";
import {AttributeCreatorComponent} from "app/ng2/pages/attributes-outputs/attribute-creator/attribute-creator.component";
import {AttributeRowSelectedEvent} from "app/ng2/components/logic/attributes-table/attributes-table.component";
+import { DeclareInputComponent } from '../properties-assignment/declare-input/declare-input.component';
const SERVICE_SELF_TITLE = "SELF";
@ViewChild('attributeOutputTabs') attributeOutputTabs: Tabs;
- constructor(private attributesService: AttributesService,
- private hierarchyNavService: HierarchyNavService,
- private attributesUtils: AttributesUtils,
- private outputsUtils: OutputsUtils,
- private componentServiceNg2: ComponentServiceNg2,
- private componentInstanceServiceNg2: ComponentInstanceServiceNg2,
- @Inject("$stateParams") _stateParams,
- @Inject("$scope") private $scope: ng.IScope,
- @Inject("$state") private $state: ng.ui.IStateService,
- @Inject("Notification") private Notification: any,
- private componentModeService: ComponentModeService,
- private EventListenerService: EventListenerService,
- private ModalServiceSdcUI: SdcUiServices.ModalService,
- private ModalService: ModalService,
- private keysPipe: KeysPipe,
- private topologyTemplateService: TopologyTemplateService) {
+ constructor(
+ private attributesService: AttributesService,
+ private hierarchyNavService: HierarchyNavService,
+ private attributesUtils: AttributesUtils,
+ private outputsUtils: OutputsUtils,
+ private componentServiceNg2: ComponentServiceNg2,
+ private componentInstanceServiceNg2: ComponentInstanceServiceNg2,
+ @Inject("$stateParams") _stateParams,
+ @Inject("$scope") private $scope: ng.IScope,
+ @Inject("$state") private $state: ng.ui.IStateService,
+ @Inject("Notification") private Notification: any,
+ private componentModeService: ComponentModeService,
+ private EventListenerService: EventListenerService,
+ private ModalServiceSdcUI: SdcUiServices.ModalService,
+ private ModalService: ModalService,
+ private keysPipe: KeysPipe,
+ private topologyTemplateService: TopologyTemplateService
+ ) {
this.instanceFeAttributesMap = new InstanceFeAttributesMap();
/* This is the way you can access the component data, please do not use any data except metadata, all other data should be received from the new api calls on the first time
event.preventDefault();
this.showUnsavedChangesAlert().then(() => {
this.$state.go(toState, toParams);
- }, () => {
});
}
});
.subscribe((response) => {
this.serviceBeAttributesMap = new InstanceBeAttributesMap();
this.serviceBeAttributesMap[this.component.uniqueId] = response;
- this.processInstanceAttributesResponse(this.serviceBeAttributesMap, false);
+ this.processInstanceAttributesResponse(this.serviceBeAttributesMap, false, null);
}, (error) => {
this.Notification.error({
message: 'Failed to get Service Attribute:' + error,
changeSelectedInstance = (instance: ComponentInstance) => {
this.selectedInstanceData = instance;
this.loadingAttributes = true;
+ this.instanceFeAttributesMap = undefined;
if (instance instanceof ComponentInstance) {
- let instanceBeAttributesMap: InstanceBeAttributesMap = new InstanceBeAttributesMap();
+ let instanceBeAttributesMap: InstanceBeAttributesMap | InstanceBePropertiesMap = new InstanceBeAttributesMap();
if (this.isOutput(instance.originType)) {
this.componentInstanceServiceNg2
.getComponentInstanceOutputs(this.component, instance)
.subscribe(response => {
instanceBeAttributesMap[instance.uniqueId] = response;
- this.processInstanceAttributesResponse(instanceBeAttributesMap, true);
+ this.processInstanceAttributesResponse(instanceBeAttributesMap, true, instance.uniqueId);
}, error => {
this.Notification.error({
message: 'Failed to change Selected Instance:' + error,
this.componentInstanceServiceNg2
.getComponentInstanceAttributes(this.component, instance.uniqueId)
.subscribe(response => {
+ instanceBeAttributesMap = new InstanceBeAttributesMap();
+ instanceBeAttributesMap[instance.uniqueId] = response;
+ this.processInstanceAttributesResponse(instanceBeAttributesMap, false, instance.uniqueId);
+ }, error => {
+ this.Notification.error({
+ message: 'Failed to change Selected Instance:' + error,
+ title: 'Failure'
+ });
+ }, () => {
+ this.loadingAttributes = false;
+ });
+ this.componentInstanceServiceNg2
+ .getComponentInstanceProperties(this.component, instance.uniqueId)
+ .subscribe(response => {
+ instanceBeAttributesMap = new InstanceBePropertiesMap();
instanceBeAttributesMap[instance.uniqueId] = response;
- this.processInstanceAttributesResponse(instanceBeAttributesMap, false);
+ this.processInstanceAttributesResponse(instanceBeAttributesMap, false, instance.uniqueId);
}, error => {
this.Notification.error({
message: 'Failed to change Selected Instance:' + error,
this.loadingAttributes = false;
});
}
-
this.resourceIsReadonly = (instance.componentName === "vnfConfiguration");
} else {
this.loadingAttributes = false;
/**
* Entry point handling response from server
*/
- processInstanceAttributesResponse = (instanceBeAttributesMap: InstanceBeAttributesMap, originTypeIsVF: boolean) => {
- this.instanceFeAttributesMap = this.attributesUtils.convertAttributesMapToFEAndCreateChildren(instanceBeAttributesMap, originTypeIsVF, this.outputs); //create flattened children, disable declared attribs, and init values
+ processInstanceAttributesResponse = (instanceBeAttributesMap: InstanceBePropertiesMap | InstanceBeAttributesMap, originTypeIsVF: boolean, instanceId: string) => {
+ let attributesMap = this.attributesUtils.convertAttributesMapToFEAndCreateChildren(instanceBeAttributesMap, originTypeIsVF, this.outputs); //create flattened children, disable declared attribs, and init values
+ if (!this.instanceFeAttributesMap) {
+ this.instanceFeAttributesMap = attributesMap;
+ } else if (instanceId) {
+ let toAdd: AttributeFEModel[];
+ if (instanceBeAttributesMap instanceof InstanceBeAttributesMap) {
+ toAdd = this.instanceFeAttributesMap[instanceId].filter(currentAtr => !attributesMap[instanceId].some(newAtr => newAtr.name === currentAtr.name))
+ this.instanceFeAttributesMap[instanceId] = attributesMap[instanceId];
+ } else {
+ toAdd = attributesMap[instanceId].filter(currentAtr => !this.instanceFeAttributesMap[instanceId].some(newAtr => newAtr.name === currentAtr.name))
+ }
+ this.instanceFeAttributesMap[instanceId] = this.instanceFeAttributesMap[instanceId].concat(toAdd);
+ }
this.checkedAttributesCount = 0;
};
this.attributeOutputTabs.triggerTabChange(this.currentMainTab.title);
this.showUnsavedChangesAlert().then(() => {
this.attributeOutputTabs.selectTab(this.attributeOutputTabs.tabs.find((tab) => tab.title === event.title));
- }, () => {
});
return;
}
this.searchQuery = '';
};
+ declareOutput = (): void => {
+ if (this.checkedAttributesCount == 1) {
+ this.openAddOutputNameModal();
+ } else if (this.checkedAttributesCount > 1) {
+ this.declareAttributes();
+ }
+ }
+
+ private openAddOutputNameModal = (): void => {
+ const modalTitle = 'Enter name of the ouput to be created';
+ const modalButtons = [];
+ const modal = this.ModalService.createCustomModal(new ModalModel(
+ 'sm',
+ modalTitle,
+ null,
+ modalButtons,
+ null /* type */
+ ));
+ modalButtons.push(new ButtonModel('Save', 'blue',
+ () => {
+ const outputName: string = modal.instance.dynamicContent.instance.inputNameForm.value;
+ if (outputName) {
+ this.declareAttributes(outputName);
+ } else {
+ this.Notification.warning({
+ message: 'Failed to set input name',
+ title: 'Warning'
+ });
+ }
+ this.ModalService.closeCurrentModal();
+ }
+ ));
+ modalButtons.push(new ButtonModel('Cancel', 'outline grey', () => {
+ this.ModalService.closeCurrentModal();
+ }));
+ this.ModalService.addDynamicContentToModal(modal, DeclareInputComponent, {defaultInputName: this.generateDefaultOutputName()});
+ modal.instance.open();
+ }
+
+ generateDefaultOutputName = (): string => {
+ let defaultInputName: string;
+ let instancesIds = this.keysPipe.transform(this.instanceFeAttributesMap, []);
+ angular.forEach(instancesIds, (instanceId: string) => {
+ const selectedOutput : AttributeBEModel = this.attributesService.getCheckedAttributes(this.instanceFeAttributesMap[instanceId])[0];
+ let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId);
+ defaultInputName = selectedOutput.name;
+ if (selectedInstanceData.invariantName) {
+ defaultInputName = selectedInstanceData.invariantName+'_'+selectedOutput.name;
+ }
+ });
+ return defaultInputName;
+ }
/*** DECLARE ATTRIBUTES/OUTPUTS ***/
- declareAttributes = (): void => {
+ declareAttributes = (outputName?: string): void => {
+ this.loadingAttributes = true;
let selectedComponentInstancesAttributes: InstanceBeAttributesMap = new InstanceBeAttributesMap();
let selectedComponentInstancesOutputs: InstanceBeAttributesMap = new InstanceBeAttributesMap();
let instancesIds = this.keysPipe.transform(this.instanceFeAttributesMap, []);
if (!this.isOutput(selectedInstanceData.originType)) {
// convert Attribute FE model -> Attribute BE model, extract only checked
selectedComponentInstancesAttributes[instanceId] = this.attributesService.getCheckedAttributes(this.instanceFeAttributesMap[instanceId]);
+ if (outputName) {
+ selectedComponentInstancesAttributes[instanceId][0].outputName = outputName;
+ }
} else {
selectedComponentInstancesOutputs[instanceId] = this.attributesService.getCheckedAttributes(this.instanceFeAttributesMap[instanceId]);
}
this.outputs.push(newOutput);
this.updateAttributeValueAfterDeclare(newOutput);
});
- });
+ this.loadingAttributes = false;
+ }, error => {this.loadingAttributes = false;}); //ignore error
};
saveChangedData = (): Promise<(AttributeBEModel | OutputBEModel)[]> => {
let request;
let handleSuccess, handleError;
if (this.isAttributesTabSelected) {
- this.changedData.map((changedAttrib) => {
+ const changedAttribs = this.changedData.map((changedAttrib) => {
changedAttrib = <AttributeFEModel>changedAttrib;
const attribBE = new AttributeBEModel(changedAttrib);
attribBE.toscaPresentation = new ToscaPresentationData();
delete attribBE.origName;
return attribBE;
});
+
+ if (this.selectedInstanceData instanceof ComponentInstance) {
+ if (this.isSelf()) {
+ console.log("changedAttribs", changedAttribs);
+ request = this.topologyTemplateService.updateServiceAttributes(this.component.uniqueId, _.map(changedAttribs, cp => {
+ delete cp.constraints;
+ return cp;
+ }));
+ } else {
+ request = this.componentInstanceServiceNg2
+ .updateInstanceAttributes(this.component.componentType, this.component.uniqueId, this.selectedInstanceData.uniqueId, changedAttribs);
+ }
+ handleSuccess = (response) => {
+ // reset each changed attribute with new value and remove it from changed attributes list
+ response.forEach((resAttrib) => {
+ const changedAttrib = <AttributeFEModel>this.changedData.shift();
+ this.attributesUtils.resetAttributeValue(changedAttrib, resAttrib.value);
+ });
+ resolve(response);
+ console.log("updated instance attributes: ", response);
+ };
+ }
} else if (this.isOutputsTabSelected) {
const changedOutputs: OutputBEModel[] = this.changedData.map((changedOutput) => {
changedOutput = <OutputFEModel>changedOutput;
outputBE.defaultValue = changedOutput.getJSONDefaultValue();
return outputBE;
});
- request = this.componentServiceNg2
- .updateComponentOutputs(this.component, changedOutputs);
+ request = this.componentServiceNg2.updateComponentOutputs(this.component, changedOutputs);
handleSuccess = (response) => {
// reset each changed attribute with new value and remove it from changed attributes list
response.forEach((resOutput) => {
changedOutput.required = resOutput.required;
});
}
- this.savingChangedData = true;
- request.subscribe(
- (response) => {
- this.savingChangedData = false;
- handleSuccess && handleSuccess(response);
- this.updateHasChangedData();
- resolve(response);
- },
- (error) => {
- this.savingChangedData = false;
- handleError && handleError(error);
- this.updateHasChangedData();
- reject(error);
- }
- );
}
+ this.savingChangedData = true;
+ request.subscribe(
+ (response) => {
+ this.savingChangedData = false;
+ handleSuccess && handleSuccess(response);
+ this.updateHasChangedData();
+ resolve(response);
+ },
+ (error) => {
+ this.savingChangedData = false;
+ handleError && handleError(error);
+ this.updateHasChangedData();
+ reject(error);
+ }
+ );
+
});
};
if (this.isAttributesTabSelected) {
this.checkedAttributesCount = 0;
}
+ this.instanceFeAttributesMap[this.selectedInstanceData.uniqueId].forEach(prop => prop.isSelected = false);
+ this.hasChangedData = false;
+ this.isValidChangedData = false;
},
() => {
this.Notification.error({
this.attributeOutputTabs.setTabIndication('Outputs', numOutputs);
};
-
- resetUnsavedChangesForOutput = (output: OutputFEModel) => {
- this.outputsUtils.resetOutputDefaultValue(output, output.defaultValue);
- this.changedData = this.changedData.filter((changedItem) => changedItem.uniqueId !== output.uniqueId);
- this.updateHasChangedData();
- }
-
deleteOutput = (output: OutputFEModel) => {
- //reset any unsaved changes to the output before deleting it
- this.resetUnsavedChangesForOutput(output);
-
let outputToDelete = new OutputBEModel(output);
this.componentServiceNg2