1/**
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { Component } from '@angular/core';
18
19import { AppService } from "./appservice";
20
21
22@Component({
23  selector: 'app-root',
24  templateUrl: './app.component.html',
25  styleUrls: ['./app.component.scss']
26})
27export class AppComponent {
28  _sideNavOpened = false;
29  get sideNavOpened(): boolean {
30    return this._sideNavOpened;
31  }
32  set sideNavOpened(value: boolean) {
33    this._sideNavOpened = value;
34    if (!value) {
35      this.selectedEntity = this.selectedEntity.slice();
36    }
37  }
38  selectedEntity: {name: string; value: any[]}[] = [];
39
40  constructor(private appService: AppService) {
41    appService.closeSideNavEmitter.subscribe(() => {this.sideNavOpened = false});
42    appService.showDetailsEmitter.subscribe(
43      (entity) => {
44        this.selectedEntity.length = 0;
45        if (entity) {
46          let self = this;
47          Object.keys(entity).forEach(function(value){
48            if (value !== 'urlsafe_key') {
49              self.selectedEntity.push({
50                name: value,
51                value: (entity[value] instanceof Array) ? entity[value] : [entity[value]]
52              });
53            }
54          });
55        }
56        this.sideNavOpened = !this.sideNavOpened;
57      },
58      (error) => {
59        console.log(error);
60      }
61    )
62  }
63}
64