8c6d99ca724578ea70fb59a78c8c6df2a10c5c09
[ccsdk/cds.git] /
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 } 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
32 @Component({
33   selector: 'app-sources-template',
34   templateUrl: './sources-template.component.html',
35   styleUrls: ['./sources-template.component.scss']
36 })
37 export class SourcesTemplateComponent implements OnInit {
38     rdState: Observable<IResourcesState>;
39     resources: IResources;
40     todo = [];
41     sources:ISourcesData; 
42     sourcesOptions = [];
43
44  constructor(private store: Store<IAppState>) {
45     this.rdState = this.store.select('resources');
46  }
47
48  ngOnInit() {
49     this.rdState.subscribe(
50       resourcesdata => {
51         var resourcesState: IResourcesState = { resources: resourcesdata.resources, isLoadSuccess: resourcesdata.isLoadSuccess, isSaveSuccess: resourcesdata.isSaveSuccess, isUpdateSuccess: resourcesdata.isUpdateSuccess };
52         this.sources = resourcesState.resources.sources;
53         for (let key in this.sources) {
54           if (this.sources.hasOwnProperty(key)) {
55             this.sourcesOptions.push(this.sources[key]);             
56           }
57         }
58         console.log(this.sourcesOptions);
59     })
60  }
61
62  drop(event: CdkDragDrop<string[]>) {
63     if (event.previousContainer === event.container) {
64       moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
65     } else {
66       transferArrayItem(event.previousContainer.data,
67                         event.container.data,
68                         event.previousIndex,
69                         event.currentIndex);
70     }
71   }    
72 }