import {Component, ComponentRef, Inject, Input} from '@angular/core';
import {Component as IComponent} from 'app/models/components/component';
import {WorkflowServiceNg2} from 'app/ng2/services/workflow.service';
-
+import {HierarchyDisplayOptions} from "../../components/logic/hierarchy-navigtion/hierarchy-display-options";
import {ISdcConfig, SdcConfigToken} from "app/ng2/config/sdc-config.config";
import {TranslateService} from "app/ng2/shared/translator/translate.service";
import {IModalButtonComponent, SdcUiServices} from 'onap-ui-angular';
import {ModalComponent} from 'app/ng2/components/ui/modal/modal.component';
-
+import {ResourceType, ComponentType} from "app/utils";
import {ModalService} from 'app/ng2/services/modal.service';
import {
ArtifactModel,
CapabilitiesGroup,
InputBEModel,
InterfaceModel,
+ ComponentInstance,
ModalModel,
OperationModel,
WORKFLOW_ASSOCIATION_OPTIONS
import {ComponentServiceNg2} from 'app/ng2/services/component-services/component.service';
import {TopologyTemplateService} from "../../services/component-services/topology-template.service";
import {InterfaceOperationModel} from "../../../models/interfaceOperation";
-import {
- InterfaceOperationHandlerComponent
-} from "../composition/interface-operatons/operation-creator/interface-operation-handler.component";
-import {
- DropdownValue
-} from "../../components/ui/form-components/dropdown/ui-element-dropdown.component";
+import {InterfaceOperationHandlerComponent} from "../composition/interface-operatons/operation-creator/interface-operation-handler.component";
+import {DropdownValue} from "../../components/ui/form-components/dropdown/ui-element-dropdown.component";
import {ToscaArtifactModel} from "../../../models/toscaArtifact";
import {ToscaArtifactService} from "../../services/tosca-artifact.service";
-import {
- InterfaceOperationComponent
-} from "../interface-operation/interface-operation.page.component";
+import {InterfaceOperationComponent} from "../interface-operation/interface-operation.page.component";
import {Observable} from "rxjs/Observable";
import {PluginsService} from 'app/ng2/services/plugins.service';
+import { InstanceFeDetails } from 'app/models/instance-fe-details';
export class UIOperationModel extends OperationModel {
isCollapsed: boolean = true;
}
}
-// tslint:disable-next-line:max-classes-per-file
class ModalTranslation {
CREATE_TITLE: string;
EDIT_TITLE: string;
}
}
-// tslint:disable-next-line:max-classes-per-file
@Component({
selector: 'interface-definition',
templateUrl: './interface-definition.page.component.html',
interfaces: UIInterfaceModel[];
inputs: InputBEModel[];
+ instancesNavigationData = [];
+ instances: any = [];
+ loadingInstances: boolean = false;
+ selectedInstanceData: any = null;
+ hierarchyInstancesDisplayOptions: HierarchyDisplayOptions = new HierarchyDisplayOptions('uniqueId', 'name', 'archived', null, 'iconClass');
+ enableFlag : boolean = false;
+
deploymentArtifactsFilePath: Array<DropdownValue> = [];
toscaArtifactTypes: Array<DropdownValue> = [];
modalTranslation: ModalTranslation;
workflows: any[];
capabilities: CapabilitiesGroup;
- isViewOnly: boolean;
openOperation: OperationModel;
enableWorkflowAssociation: boolean;
workflowIsOnline: boolean;
+ validImplementationProps: boolean = true;
+ validMilestoneActivities: boolean = true;
+ validMilestoneFilters: boolean = true;
+ serviceInterfaces: InterfaceModel[];
@Input() component: IComponent;
@Input() readonly: boolean;
this.ComponentServiceNg2.getInterfaceOperations(this.component),
this.ComponentServiceNg2.getComponentInputs(this.component),
this.ComponentServiceNg2.getInterfaceTypes(this.component),
- this.ComponentServiceNg2.getCapabilitiesAndRequirements(this.component.componentType, this.component.uniqueId)
+ this.ComponentServiceNg2.getCapabilitiesAndRequirements(this.component.componentType, this.component.uniqueId),
+ this.componentServiceNg2.getComponentResourcePropertiesData(this.component)
).subscribe((response: any[]) => {
const callback = (workflows) => {
this.isLoading = false;
+ this.serviceInterfaces = response[0].interfaces;
this.initInterfaces(response[0].interfaces);
this.sortInterfaces();
this.inputs = response[1].inputs;
this.interfaceTypes = response[2];
this.workflows = (workflows.items) ? workflows.items : workflows;
this.capabilities = response[3].capabilities;
+ this.instances = response[4].componentInstances;
+ const serviceInstance = new ComponentInstance();
+ serviceInstance.name = "SELF";
+ serviceInstance.uniqueId = this.component.uniqueId;
+ if (this.instances != null) {
+ this.instances.unshift(serviceInstance);
+ } else {
+ this.instances = [serviceInstance];
+ }
+ _.forEach(this.instances, (instance) => {
+ this.instancesNavigationData.push(instance);
+ });
+ this.onInstanceSelectedUpdate(this.instancesNavigationData[0]);
+ this.loadingInstances = false;
+
};
if (this.enableWorkflowAssociation && this.workflowIsOnline) {
this.WorkflowServiceNg2.getWorkflows().subscribe(
callback([]);
}
});
+
this.loadToscaArtifacts();
}
+ onInstanceSelectedUpdate = (instance: any) => {
+ this.interfaces = [];
+ this.selectedInstanceData = instance;
+ if (instance.name != "SELF") {
+ this.enableFlag = this.isAllowAddOperation(instance.originType);
+ if (!instance.interfaces) {
+ return;
+ }
+ let newInterfaces : InterfaceModel[] = [];
+ if (instance.interfaces instanceof Array) {
+ instance.interfaces.forEach(result => {
+ let interfaceObj = new InterfaceModel();
+ interfaceObj.type = result.type;
+ interfaceObj.uniqueId = result.uniqueId;
+ if (result.operations instanceof Array) {
+ interfaceObj.operations = result.operations;
+ } else if (!_.isEmpty(result.operations)) {
+ interfaceObj.operations = [];
+ Object.keys(result.operations).forEach(name => {
+ result.operations[name].interfaceId = result.type;
+ result.operations[name].interfaceType = result.type;
+ interfaceObj.operations.push(result.operations[name]);
+ });
+ }
+ newInterfaces.push(interfaceObj);
+ });
+ } else {
+ Object.keys(instance.interfaces).forEach(key => {
+ let obj = instance.interfaces[key];
+ let interfaceObj = new InterfaceModel();
+ interfaceObj.type = obj.type;
+ interfaceObj.uniqueId = obj.uniqueId;
+ if (obj.operations instanceof Array) {
+ interfaceObj.operations = obj.operations;
+ } else if (!_.isEmpty(obj.operations)) {
+ interfaceObj.operations = [];
+ Object.keys(obj.operations).forEach(name => {
+ obj.operations[name].interfaceId = key;
+ obj.operations[name].interfaceType = key;
+ interfaceObj.operations.push(obj.operations[name]);
+ });
+ }
+ newInterfaces.push(interfaceObj);
+ });
+ }
+ this.interfaces = newInterfaces.map((interf) => new UIInterfaceModel(interf));
+ } else {
+ this.enableFlag = false;
+ this.interfaces = this.serviceInterfaces.map((interf) => new UIInterfaceModel(interf));
+ }
+ this.sortInterfaces();
+ }
+
+ isAllowAddOperation(originType: string): boolean {
+ if (originType && (originType === ResourceType.VFC || originType === ResourceType.CP || originType === ResourceType.VL)){
+ return true;
+ }
+ return false;
+ }
+
initInterfaces(interfaces: InterfaceModel[]): void {
if (interfaces) {
this.interfaces = interfaces.map((interf) => new UIInterfaceModel(interf));
}
private disableSaveButton = (): boolean => {
- return this.isViewOnly ||
- (this.isEnableAddArtifactImplementation()
- && (!this.modalInstance.instance.dynamicContent.toscaArtifactTypeSelected ||
- !this.modalInstance.instance.dynamicContent.artifactName)
- );
+ let disable:boolean = true;
+ if(this.readonly) {
+ return disable;
+ }
+ const validMilestoneActivities = this.modalInstance.instance.dynamicContent.instance.validMilestoneActivities;
+ const validMilestoneFilters = this.modalInstance.instance.dynamicContent.instance.validMilestoneFilters;
+ if (!validMilestoneActivities || !validMilestoneFilters) {
+ return disable;
+ }
+
+ let selectedInterfaceOperation = this.modalInstance.instance.dynamicContent.instance.selectedInterfaceOperation;
+ let isInterfaceOperation:boolean = !(typeof selectedInterfaceOperation == 'undefined' || _.isEmpty(selectedInterfaceOperation));
+ let selectedInterfaceType = this.modalInstance.instance.dynamicContent.instance.selectedInterfaceType;
+ let isInterfaceType:boolean = !(typeof selectedInterfaceType == 'undefined' || _.isEmpty(selectedInterfaceType));
+ let bothSet: boolean = isInterfaceOperation && isInterfaceType;
+
+ let enableAddArtifactImplementation = this.modalInstance.instance.dynamicContent.instance.enableAddArtifactImplementation;
+ if(enableAddArtifactImplementation) {
+ let validImplementationProps = this.modalInstance.instance.dynamicContent.instance.validImplementationProps;
+ let toscaArtifactTypeSelected = this.modalInstance.instance.dynamicContent.instance.toscaArtifactTypeSelected;
+ let isToscaArtifactType:boolean = !(typeof toscaArtifactTypeSelected == 'undefined' || _.isEmpty(toscaArtifactTypeSelected));
+ disable = !bothSet || !isToscaArtifactType || !validImplementationProps;
+ return disable;
+ }
+ disable = !bothSet;
+ return disable;
}
onSelectInterfaceOperation(interfaceModel: UIInterfaceModel, operation: InterfaceOperationModel) {
const isEdit = operation !== undefined;
- const cancelButton: ButtonModel = new ButtonModel(this.modalTranslation.CANCEL_BUTTON, 'outline white', this.cancelAndCloseModal);
- const saveButton: ButtonModel = new ButtonModel(this.modalTranslation.SAVE_BUTTON, 'blue',
- () => isEdit ? this.updateOperation() : this.createOperationCallback(),
- this.disableSaveButton
- );
+ const modalButtons = [];
+ if (!this.readonly) {
+ const saveButton: ButtonModel = new ButtonModel(this.modalTranslation.SAVE_BUTTON, 'blue',
+ () => isEdit ? this.updateOperation() : this.createOperationCallback(),
+ this.disableSaveButton
+ );
+ modalButtons.push(saveButton);
+ }
+ modalButtons.push(new ButtonModel(this.modalTranslation.CANCEL_BUTTON, 'outline white', this.cancelAndCloseModal));
const interfaceDataModal: ModalModel =
- new ModalModel('l', this.modalTranslation.EDIT_TITLE, '', [saveButton, cancelButton], 'custom');
+ new ModalModel('l', this.modalTranslation.EDIT_TITLE, '', modalButtons, 'custom');
this.modalInstance = this.modalServiceNg2.createCustomModal(interfaceDataModal);
this.modalServiceNg2.addDynamicContentToModal(
selectedInterface: interfaceModel ? interfaceModel : new UIInterfaceModel(),
selectedInterfaceOperation: operation ? operation : new InterfaceOperationModel(),
validityChangedCallback: this.disableSaveButton,
- isViewOnly: this.isViewOnly,
- isEdit: isEdit,
+ isViewOnly: this.readonly,
+ validImplementationProps: this.validImplementationProps,
+ validMilestoneActivities: this.validMilestoneActivities,
+ validMilestoneFilters: this.validMilestoneFilters,
+ 'isEdit': isEdit,
interfaceTypesMap: this.interfaceTypesMap,
modelName: this.component.model
}
this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = true;
const interfaceOperationHandlerComponentInstance: InterfaceOperationHandlerComponent = this.modalInstance.instance.dynamicContent.instance;
const operationToUpdate = this.modalInstance.instance.dynamicContent.instance.operationToUpdate;
+ let timeout = null;
+ if (operationToUpdate.implementation && operationToUpdate.implementation.timeout != null) {
+ timeout = operationToUpdate.implementation.timeout;
+ }
const isArtifactChecked = interfaceOperationHandlerComponentInstance.enableAddArtifactImplementation;
if (!isArtifactChecked) {
const artifactName = interfaceOperationHandlerComponentInstance.artifactName ?
interfaceOperationHandlerComponentInstance.artifactName : '';
operationToUpdate.implementation = new ArtifactModel({'artifactName': artifactName, 'artifactVersion': ''} as ArtifactModel);
}
- this.componentServiceNg2.updateComponentInterfaceOperation(this.component.uniqueId, operationToUpdate)
- .subscribe((newOperation: InterfaceOperationModel) => {
- let oldOpIndex;
- let oldInterf;
- this.interfaces.forEach(interf => {
- interf.operations.forEach(op => {
- if (op.uniqueId === newOperation.uniqueId) {
- oldInterf = interf;
- oldOpIndex = interf.operations.findIndex((el) => el.uniqueId === op.uniqueId);
- }
+ if (timeout != null) {
+ operationToUpdate.implementation.timeout = timeout;
+ }
+ if (this.component.componentType === ComponentType.SERVICE) {
+ this.topologyTemplateService.updateComponentInstanceInterfaceOperation(this.component.uniqueId, this.component.componentType, this.selectedInstanceData.uniqueId, operationToUpdate)
+ .subscribe((res) => {
+ const interf: InterfaceModel = _.find(res.interfaces, interf => interf.type === operationToUpdate.interfaceType);
+ const newOp: OperationModel = _.find(interf.operations, op => op.name === operationToUpdate.name);
+ let newOperation = new InterfaceOperationModel({
+ ...newOp,
+ interfaceType: interf.type,
+ interfaceId: interf.uniqueId,
+ })
+ let oldOpIndex;
+ let oldInterf;
+ this.interfaces.forEach(interf => {
+ interf.operations.forEach(op => {
+ if (op.uniqueId === newOperation.uniqueId) {
+ oldInterf = interf;
+ oldOpIndex = interf.operations.findIndex((el) => el.uniqueId === op.uniqueId);
+ }
+ });
});
+ oldInterf.operations.splice(oldOpIndex, 1);
+ oldInterf.operations.push(new InterfaceOperationModel(newOperation));
+ }, () => {
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ }, () => {
+ this.sortInterfaces();
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ this.modalServiceNg2.closeCurrentModal();
});
- oldInterf.operations.splice(oldOpIndex, 1);
- oldInterf.operations.push(new InterfaceOperationModel(newOperation));
- }, error => {
- this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
- }, () => {
- this.sortInterfaces();
- this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
- this.modalServiceNg2.closeCurrentModal();
- });
+ } else {
+ this.componentServiceNg2.updateComponentInterfaceOperation(this.component.uniqueId, operationToUpdate)
+ .subscribe((newOperation: InterfaceOperationModel) => {
+ let oldOpIndex;
+ let oldInterf;
+ this.interfaces.forEach(interf => {
+ interf.operations.forEach(op => {
+ if (op.uniqueId === newOperation.uniqueId) {
+ oldInterf = interf;
+ oldOpIndex = interf.operations.findIndex((el) => el.uniqueId === op.uniqueId);
+ }
+ });
+ });
+ oldInterf.operations.splice(oldOpIndex, 1);
+ oldInterf.operations.push(new InterfaceOperationModel(newOperation));
+ }, () => {
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ }, () => {
+ this.sortInterfaces();
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ this.modalServiceNg2.closeCurrentModal();
+ });
+ }
}
private createOperationCallback(): void {
this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = true;
const operationToUpdate = this.modalInstance.instance.dynamicContent.instance.operationToUpdate;
- console.log('createOperationCallback', operationToUpdate);
- console.log('this.component', this.component);
- this.componentServiceNg2.createComponentInterfaceOperation(this.component.uniqueId, this.component.getTypeUrl(), operationToUpdate)
- .subscribe((newOperation: InterfaceOperationModel) => {
- const foundInterface = this.interfaces.find(value => value.type === newOperation.interfaceType);
- if (foundInterface) {
- foundInterface.operations.push(new UIOperationModel(new OperationModel(newOperation)));
- } else {
- const uiInterfaceModel = new UIInterfaceModel();
- uiInterfaceModel.type = newOperation.interfaceType;
- uiInterfaceModel.uniqueId = newOperation.interfaceType;
- uiInterfaceModel.operations = [];
- uiInterfaceModel.operations.push(new UIOperationModel(new OperationModel(newOperation)));
- this.interfaces.push(uiInterfaceModel);
- }
- }, error => {
- this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
- }, () => {
- this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
- this.modalServiceNg2.closeCurrentModal();
- });
+ if (this.component.componentType === ComponentType.SERVICE) {
+ this.topologyTemplateService.createComponentInstanceInterfaceOperation(this.component.uniqueId, this.selectedInstanceData.uniqueId, operationToUpdate)
+ .subscribe((newOperation: InterfaceOperationModel) => {
+ const foundInterface = this.interfaces.find(value => value.type === newOperation.interfaceType);
+ if (foundInterface) {
+ foundInterface.operations.push(new UIOperationModel(new OperationModel(newOperation)));
+ } else {
+ const uiInterfaceModel = new UIInterfaceModel();
+ uiInterfaceModel.type = newOperation.interfaceType;
+ uiInterfaceModel.uniqueId = newOperation.interfaceType;
+ uiInterfaceModel.operations = [];
+ uiInterfaceModel.operations.push(new UIOperationModel(new OperationModel(newOperation)));
+ this.interfaces.push(uiInterfaceModel);
+ }
+ }, () => {
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ this.modalServiceNg2.closeCurrentModal();
+ }, () => {
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ this.modalServiceNg2.closeCurrentModal();
+ });
+ } else {
+ this.componentServiceNg2.createComponentInterfaceOperation(this.component.uniqueId, this.component.getTypeUrl(), operationToUpdate)
+ .subscribe((newOperation: InterfaceOperationModel) => {
+ const foundInterface = this.interfaces.find(value => value.type === newOperation.interfaceType);
+ if (foundInterface) {
+ foundInterface.operations.push(new UIOperationModel(new OperationModel(newOperation)));
+ } else {
+ const uiInterfaceModel = new UIInterfaceModel();
+ uiInterfaceModel.type = newOperation.interfaceType;
+ uiInterfaceModel.uniqueId = newOperation.interfaceType;
+ uiInterfaceModel.operations = [];
+ uiInterfaceModel.operations.push(new UIOperationModel(new OperationModel(newOperation)));
+ this.interfaces.push(uiInterfaceModel);
+ }
+ }, () => {
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ this.modalServiceNg2.closeCurrentModal();
+ }, () => {
+ this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+ this.modalServiceNg2.closeCurrentModal();
+ });
+ }
}
private handleEnableAddArtifactImplementation = (newOperation: InterfaceOperationModel): InterfaceOperationModel => {