Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / components / ui / menu / menu-list.component.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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, Input, ContentChildren, SimpleChanges, QueryList } from '@angular/core';
22 import { MenuItemComponent } from "./menu-item.component";
23 import { Point } from "app/models";
24
25 @Component({
26     selector: 'menu-list',
27     templateUrl: './menu-list.component.html',
28     styleUrls:['./menu-list.component.less']
29 })
30 export class MenuListComponent {
31     @Input('open') inputOpen:boolean = false;
32     @Input('position') inputPosition:Point = new Point();
33     @Input() styleClass:any;
34
35     @ContentChildren(MenuItemComponent) menuItems:QueryList<MenuItemComponent>;
36
37     private position:Point;
38     private isOpen:boolean = false;
39
40     constructor() {
41     }
42
43     ngOnChanges(changes:SimpleChanges) {
44         if (changes.inputOpen) {
45             (changes.inputOpen.currentValue) ? this.open() : this.close();
46         }
47         if (changes.inputPosition) {
48             this.changePosition(changes.inputPosition.currentValue);
49         }
50     }
51
52     ngAfterContentInit() {
53         this.menuItems.forEach((c) => c.parentMenu = this);
54         this.menuItems.changes.subscribe((list) => {
55             list.forEach((c) => c.parentMenu = this);
56         });
57     }
58
59     open(): void {
60         this.isOpen = true;
61     }
62
63     close(): void {
64         this.isOpen = false;
65     }
66
67     changePosition(position:Point) {
68         this.position = position;
69     }
70 }