Merge "Metadata component css changes"
[ccsdk/cds.git] / cds-ui / client / src / app / feature-modules / resource-definition / resource-edit / sources-template / sources-template.component.ts
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : CDS
4 * ================================================================================
5 * Copyright (C) 2019 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21 import { Component, OnInit, ViewChild } from '@angular/core';
22 import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
23 import { IResources } from 'src/app/common/core/store/models/resources.model';
24 import { IResourcesState } from 'src/app/common/core/store/models/resourcesState.model';
25 import { Observable } from 'rxjs';
26 import { Store } from '@ngrx/store';
27 import { IAppState } from '../../../../common/core/store/state/app.state';
28 import { A11yModule } from '@angular/cdk/a11y';
29 import { LoadResourcesSuccess } from 'src/app/common/core/store/actions/resources.action';
30 import { ISourcesData } from 'src/app/common/core/store/models/sourcesData.model';
31 import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';
32
33 @Component({
34   selector: 'app-sources-template',
35   templateUrl: './sources-template.component.html',
36   styleUrls: ['./sources-template.component.scss']
37 })
38 export class SourcesTemplateComponent implements OnInit {
39 //    rdState: Observable<IResourcesState>;
40 //    resources: IResources;
41 //    todo = [];
42 //    sources:ISourcesData; 
43 //    sourcesOptions = [];
44
45     @ViewChild(JsonEditorComponent) editor: JsonEditorComponent;
46     options = new JsonEditorOptions();
47     
48     rdState: Observable<IResourcesState>;
49     resources: IResources;
50     option = ['mdsal','default'];
51     sources:ISourcesData; 
52     sourcesOptions = [];
53     sourcesData = [];
54     
55  constructor(private store: Store<IAppState>) {
56    this.rdState = this.store.select('resources');
57       this.options.mode = 'text';
58     this.options.modes = [ 'text', 'tree', 'view'];
59     this.options.statusBar = false;
60     this.options.onChange = () => console.log(this.editor.get());
61      
62  }
63
64  ngOnInit() {
65     this.rdState.subscribe(
66       resourcesdata => {
67         var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess };
68         this.sources = resourcesState.resources.sources;
69         for (let key in this.sources) {
70             this.sourcesOptions.push(key);  
71         }
72         //console.log(this.sourcesOptions);
73     })
74  }
75
76  onChange() {
77      console.log(this.editor.get())
78  };
79     
80  selected(value){
81     console.log(value);
82         this.sourcesData=this.sources[value];
83         return this.sourcesData;    
84  }    
85     
86  drop(event: CdkDragDrop<string[]>) {
87     if (event.previousContainer === event.container) {
88       moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
89     } else {
90       transferArrayItem(event.previousContainer.data,
91                         event.container.data,
92                         event.previousIndex,
93                         event.currentIndex);
94     }
95   }    
96 }