summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2017-12-10 18:55:03 +0200
committerTal Gitelman <tg851x@intl.att.com>2017-12-10 19:33:38 +0200
commit51d50f0ef642e0f996a1c8b8d2ef4838bdfec892 (patch)
tree3ac236a864d74d19b0f5c9020891a7a7e5c31b44 /catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts
parentb5cc2e0695f195716d6ccdc65e73807a6632ec70 (diff)
Final commit to master merge from
Change-Id: Ib464f9a8828437c86fe6def8af238aaf83473507 Issue-ID: SDC-714 Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Diffstat (limited to 'catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts')
-rw-r--r--catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts145
1 files changed, 0 insertions, 145 deletions
diff --git a/catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts b/catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts
deleted file mode 100644
index 246258e44f..0000000000
--- a/catalog-ui/src/app/ng2/components/dynamic-element/dynamic-element.component.ts
+++ /dev/null
@@ -1,145 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-import { Component, Compiler, EventEmitter, ViewContainerRef, ViewChild, Input, Output, ElementRef, ComponentRef, ComponentFactory, ComponentFactoryResolver } from '@angular/core'
-import { UiElementCheckBoxComponent } from './elements-ui/checkbox/ui-element-checkbox.component';
-import { UiElementDropDownComponent, DropdownValue } from './elements-ui/dropdown/ui-element-dropdown.component';
-import { UiElementInputComponent } from './elements-ui/input/ui-element-input.component';
-import {UiElementPopoverInputComponent} from "./elements-ui/popover-input/ui-element-popover-input.component";
-import {ValidationConfiguration} from "app/models";
-import {UiElementIntegerInputComponent} from "./elements-ui/integer-input/ui-element-integer-input.component";
-
-@Component({
- selector: 'dynamic-element',
- template: `<div #target></div>`,
- styleUrls: ['./dynamic-element.component.less'],
- entryComponents: [
- UiElementInputComponent,
- UiElementDropDownComponent,
- UiElementCheckBoxComponent,
- UiElementPopoverInputComponent,
- UiElementIntegerInputComponent
- ]
-})
-export class DynamicElementComponent {
-
- @ViewChild('target', { read: ViewContainerRef }) target: any;
- @Input() type: any;
- @Input() name: string;
- @Input() readonly:boolean;
- @Input() path:string;//optional param. used only for for subnetpoolid type
- value:any;
-
- // Two way binding for value (need to write the "Change" word like this)
- @Output('valueChange') emitter: EventEmitter<string> = new EventEmitter<any>();
- @Input('value') set setValueValue(value) {
- this.value = value;
- }
-
- cmpRef: ComponentRef<any>;
- private isViewInitialized: boolean = false;
- validation = ValidationConfiguration.validation;
-
- constructor(
- private componentFactoryResolver: ComponentFactoryResolver,
- private compiler: Compiler,
- private el: ElementRef) {
- }
-
- updateComponent() {
- if (!this.isViewInitialized) {
- return;
- }
- if (this.cmpRef) {
- this.cmpRef.destroy();
- }
-
- // Factory to create component based on type or peroperty name.
- switch(this.type) {
- case 'list':
- case 'integer':
- this.createComponent(UiElementIntegerInputComponent);
- this.cmpRef.instance.pattern = this.validation.validationPatterns.integer;
- break;
- case 'string':
- if (this.path && this.path.toUpperCase().indexOf("SUBNETPOOLID") !== -1) {
- if(this.name.toUpperCase().indexOf("SUBNETPOOLID") == -1){//if it's an item of subnetpoolid list get the parent name
- let pathArray = this.path.split("#");
- this.name = pathArray[pathArray.length - 2];
- }
- this.createComponent(UiElementPopoverInputComponent);
- }
- else {
- this.createComponent(UiElementInputComponent);
- }
- break;
- case 'boolean':
- //this.createComponent(UiElementCheckBoxComponent);
-
- this.createComponent(UiElementDropDownComponent);
-
- // Build drop down values
- let tmp = [];
- tmp.push(new DropdownValue('true','TRUE'));
- tmp.push(new DropdownValue('false','FALSE'));
- this.cmpRef.instance.values = tmp;
- break;
- default:
- this.createComponent(UiElementInputComponent);
- console.log("ERROR: No ui component to handle type: " + this.type);
- }
-
- // Additional attributes in base element class
- if (this.cmpRef) {
- this.cmpRef.instance.name = this.name;
- this.cmpRef.instance.type = this.type;
- this.cmpRef.instance.value = this.value;
- this.cmpRef.instance.readonly = this.readonly;
- }
-
- // Subscribe to change event of of ui-element-basic and fire event to change the value
- this.cmpRef.instance.baseEmitter.subscribe((value):void => {
- this.emitter.emit(value)
- });
-
- }
-
- createComponent(ComponentToCreate:any):void {
- let factory = this.componentFactoryResolver.resolveComponentFactory(ComponentToCreate);
- this.cmpRef = this.target.createComponent(factory);
- }
-
- ngOnChanges() {
- this.updateComponent();
- }
-
- ngAfterContentInit() {
- //console.log("DynamicElementComponent: ngAfterContentInit: type: " + this.type + " value: " + this.value);
- this.isViewInitialized = true;
- this.updateComponent();
- }
-
- ngOnDestroy() {
- if (this.cmpRef) {
- this.cmpRef.destroy();
- }
- }
-
-}