serviceBePropertiesMap: InstanceBePropertiesMap;
serviceBeCapabilitiesPropertiesMap: InstanceBePropertiesMap;
selectedInstance_FlattenCapabilitiesList: Capability[];
- btnToscaFunctionText: string;
@ViewChild('hierarchyNavTabs') hierarchyNavTabs: Tabs;
@ViewChild('propertyInputTabs') propertyInputTabs: Tabs;
ngOnInit() {
console.debug("==>" + this.constructor.name + ": ngOnInit");
- this.btnToscaFunctionText = this.translateService.translate('TOSCA_FUNCTION_LABEL');
this.loadingInputs = true;
this.loadingPolicies = true;
this.loadingInstances = true;
if (!selectedInstanceData) {
return;
}
- const property: PropertyBEModel = this.buildCheckedInstanceProperty();
- if (property.isToscaGetFunction()) {
- this.clearCheckedInstancePropertyValue();
- return;
- }
this.openToscaGetFunctionModal();
}
}
private openToscaGetFunctionModal() {
- const modalTitle = 'Set value using TOSCA functions';
+ const modalTitle = this.translateService.translate('TOSCA_FUNCTION_MODAL_TITLE');
+ const modalButtons = [];
+ modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_SAVE'), 'blue',
+ () => {
+ const toscaGetFunction: ToscaGetFunction = modal.instance.dynamicContent.instance.toscaGetFunction;
+ if (toscaGetFunction.functionType) {
+ this.updateCheckedInstancePropertyGetFunctionValue(toscaGetFunction);
+ } else {
+ this.clearCheckedInstancePropertyValue();
+ }
+ modal.instance.close();
+ }
+ ));
+ const checkedInstanceProperty = this.buildCheckedInstanceProperty();
+ modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_CANCEL'), 'outline grey', () => {
+ modal.instance.close();
+ }));
const modal = this.modalService.createCustomModal(new ModalModel(
'sm',
modalTitle,
null,
- [
- new ButtonModel(this.translateService.translate('MODAL_SAVE'), 'blue',
- () => {
- const toscaGetFunction: ToscaGetFunction = modal.instance.dynamicContent.instance.toscaGetFunction;
- this.updateCheckedInstancePropertyGetFunctionValue(toscaGetFunction);
- modal.instance.close();
- }
- ),
- new ButtonModel(this.translateService.translate('MODAL_CANCEL'), 'outline grey', () => {
- modal.instance.close();
- }),
- ],
+ modalButtons,
null /* type */
));
- const checkedInstanceProperty = this.buildCheckedInstanceProperty();
+
this.modalService.addDynamicContentToModalAndBindInputs(modal, ToscaFunctionComponent, {
'property': checkedInstanceProperty,
'componentInstanceMap': this.componentInstanceMap
console.error(errorMsg, error);
}, () => {
this.loadingProperties = false;
- this.btnToscaFunctionText = this.translateService.translate('TOSCA_FUNCTION_LABEL');
- });
- }
-
- selectInputBtnLabel = () => {
- let instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
- angular.forEach(instancesIds, (instanceId: string): void => {
- let checkedProperties: PropertyBEModel[] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
- angular.forEach(checkedProperties, (property: PropertyBEModel) => {
- if(this.checkedPropertiesCount == 1) {
- if (property.isToscaGetFunction()) {
- this.btnToscaFunctionText = this.translateService.translate('CLEAR_VALUE_LABEL');
- } else {
- this.btnToscaFunctionText = this.translateService.translate('TOSCA_FUNCTION_LABEL');
- }
- } else {
- this.btnToscaFunctionText = this.translateService.translate('TOSCA_FUNCTION_LABEL');
- }
- });
});
}
updateCheckedPropertyCount = (increment: boolean): void => {
this.checkedPropertiesCount += (increment) ? 1 : -1;
console.debug("CheckedProperties count is now.... " + this.checkedPropertiesCount);
- this.selectInputBtnLabel();
};
updateCheckedChildPropertyCount = (increment: boolean): void => {
* ============LICENSE_END=========================================================
*/
-import {Component, Input} from '@angular/core';
+import {Component, Input, OnInit} from '@angular/core';
import {ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models';
import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
import {WorkspaceService} from "../../workspace/workspace.service";
templateUrl: './tosca-function.component.html',
styleUrls: ['./tosca-function.component.less'],
})
-export class ToscaFunctionComponent {
+export class ToscaFunctionComponent implements OnInit {
@Input() property: PropertyBEModel;
@Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
+ @Input() allowClear: boolean = true;
TOSCA_FUNCTION_GET_PROPERTY = ToscaGetFunctionType.GET_PROPERTY;
dropdownValuesLabel: string;
dropDownErrorMsg: string;
propertySource: string
- toscaGetFunction: ToscaGetFunction = new ToscaGetFunction();
+ toscaGetFunction: ToscaGetFunction = new ToscaGetFunction(undefined);
private componentMetadata: ComponentMetadata;
private translateService: TranslateService) {
}
- ngOnInit() {
+ ngOnInit(): void {
this.componentMetadata = this.workspaceService.metadata;
this.loadToscaFunctions();
this.loadPropertySourceDropdown();
+ this.initToscaGetFunction();
+ }
+
+ private initToscaGetFunction(): void {
+ if (!this.property.isToscaGetFunction()) {
+ return;
+ }
+ this.toscaGetFunction = new ToscaGetFunction(this.property.toscaGetFunction);
+ if (this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY) {
+ if (this.toscaGetFunction.propertySource === PropertySource.SELF) {
+ this.propertySource = PropertySource.SELF;
+ } else {
+ this.propertySource = this.toscaGetFunction.sourceName;
+ }
+ }
+ if (this.toscaGetFunction.propertyName) {
+ this.loadPropertyDropdown(() => {
+ this.selectedProperty = this.propertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.propertyName)
+ });
+ }
+
}
private loadToscaFunctions(): void {
this.toscaFunctions.push(ToscaGetFunctionType.GET_PROPERTY);
}
- private loadPropertySourceDropdown() {
+ private loadPropertySourceDropdown(): void {
this.propertySourceList.push(PropertySource.SELF);
this.componentInstanceMap.forEach((value, key) => {
const instanceName = value.name;
});
}
- private addToPropertySource(source: string) {
+ private addToPropertySource(source: string): void {
this.propertySourceList.push(source);
this.propertySourceList.sort((a, b) => {
if (a === PropertySource.SELF) {
}
onToscaFunctionChange(): void {
+ this.resetPropertySource();
+ if (this.isGetInputSelected()) {
+ this.setSelfPropertySource();
+ this.loadPropertyDropdown();
+ }
+ }
+
+ private loadPropertyDropdown(onComplete: () => any = () => {}): void {
+ this.loadPropertyDropdownLabel();
+ this.loadPropertyDropdownValues(onComplete);
+ }
+
+ private resetForm(): void {
+ this.toscaGetFunction = new ToscaGetFunction(undefined);
+ this.propertySource = undefined;
+ this.selectedProperty = undefined;
+ }
+
+ private resetPropertySource(): void {
this.toscaGetFunction.propertyUniqueId = undefined;
this.toscaGetFunction.propertyName = undefined;
this.toscaGetFunction.propertySource = undefined;
this.toscaGetFunction.sourceName = undefined;
this.toscaGetFunction.propertyPathFromSource = undefined;
this.propertySource = undefined;
- if (this.isGetInputSelected()) {
- this.setSelfPropertySource();
- this.loadDropdownValueLabel();
- this.loadDropdownValues();
- }
+ this.selectedProperty = undefined;
}
- private loadDropdownValueLabel(): void {
+ private loadPropertyDropdownLabel(): void {
if (!this.toscaGetFunction.functionType) {
return;
}
}
}
- private loadDropdownValues(): void {
+ private loadPropertyDropdownValues(onComplete: () => any = () => {}): void {
if (!this.toscaGetFunction.functionType) {
return;
}
- this.resetDropDown();
- this.loadPropertiesInDropdown();
+ this.resetPropertyDropdown();
+ this.fillPropertyDropdownValues(onComplete);
}
- private resetDropDown() {
+ private resetPropertyDropdown(): void {
this.dropDownErrorMsg = undefined;
+ this.selectedProperty = undefined;
this.propertyDropdownList = [];
}
- private loadPropertiesInDropdown() {
+ private fillPropertyDropdownValues(onComplete: () => any = () => {}): void {
this.startLoading();
const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable();
propertiesObservable.subscribe( (response: ComponentGenericResponse) => {
}, (error) => {
console.error('An error occurred while loading properties.', error);
}, () => {
+ onComplete();
this.stopLoading();
});
}
);
}
- private addPropertyToDropdown(propertyDropdownValue: PropertyDropdownValue) {
+ private addPropertyToDropdown(propertyDropdownValue: PropertyDropdownValue): void {
this.propertyDropdownList.push(propertyDropdownValue);
this.propertyDropdownList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel));
}
- private addPropertiesToDropdown(properties: PropertyBEModel[]) {
+ private addPropertiesToDropdown(properties: PropertyBEModel[]): void {
for (const property of properties) {
if (this.property.type === property.type) {
this.addPropertyToDropdown({
}
}
- private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel, parentPropertyList: Array<PropertyBEModel> = []) {
+ private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel, parentPropertyList: Array<PropertyBEModel> = []): void {
const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
if (!dataTypeFound || !dataTypeFound.properties) {
return;
});
}
- private isGetPropertySelected() {
+ private isGetPropertySelected(): boolean {
return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_PROPERTY;
}
- private isGetInputSelected() {
+ private isGetInputSelected(): boolean {
return this.toscaGetFunction.functionType === ToscaGetFunctionType.GET_INPUT;
}
- private isComplexType(propertyType: string) {
+ private isComplexType(propertyType: string): boolean {
return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
}
- private stopLoading() {
+ private stopLoading(): void {
this.isLoading = false;
}
- private startLoading() {
+ private startLoading(): void {
this.isLoading = true;
}
return this.toscaGetFunction.functionType && !this.isLoading && !this.dropDownErrorMsg;
}
- onPropertySourceChange() {
+ onPropertySourceChange(): void {
if (!this.toscaGetFunction.functionType || !this.propertySource) {
return;
}
this.toscaGetFunction.sourceName = this.propertySource;
this.toscaGetFunction.sourceUniqueId = this.instanceNameAndIdMap.get(this.propertySource);
}
- this.loadDropdownValueLabel();
- this.resetDropDown();
- this.loadPropertiesInDropdown();
+ this.loadPropertyDropdown();
}
- private setSelfPropertySource() {
+ private setSelfPropertySource(): void {
this.toscaGetFunction.propertySource = PropertySource.SELF;
this.toscaGetFunction.sourceName = this.componentMetadata.name;
this.toscaGetFunction.sourceUniqueId = this.componentMetadata.uniqueId;
}
- onPropertyChange() {
+ onPropertyChange(): void {
this.toscaGetFunction.propertyUniqueId = this.selectedProperty.propertyId;
this.toscaGetFunction.propertyName = this.selectedProperty.propertyName;
this.toscaGetFunction.propertyPathFromSource = this.selectedProperty.propertyPath;
}
+ onClearValues() {
+ this.resetForm();
+ }
+
+ showClearButton(): boolean {
+ return this.allowClear && this.toscaGetFunction.functionType !== undefined;
+ }
}
export interface PropertyDropdownValue {