harbor-shell.component.ts 2.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';

import { ModalEvent } from '../modal-event';
import { SearchEvent } from '../search-event';
import { modalAccountSettings, modalPasswordSetting } from '../modal-events.const';

import { AccountSettingsModalComponent } from '../../account/account-settings/account-settings-modal.component';
import { SearchResultComponent } from '../global-search/search-result.component';
import { PasswordSettingComponent } from '../../account/password/password-setting.component';
import { NavigatorComponent } from '../navigator/navigator.component';
kunw's avatar
kunw committed
12 13 14

@Component({
    selector: 'harbor-shell',
15 16
    templateUrl: 'harbor-shell.component.html',
    styleUrls: ["harbor-shell.component.css"]
kunw's avatar
kunw committed
17
})
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

export class HarborShellComponent implements OnInit {

    @ViewChild(AccountSettingsModalComponent)
    private accountSettingsModal: AccountSettingsModalComponent;

    @ViewChild(SearchResultComponent)
    private searchResultComponet: SearchResultComponent;

    @ViewChild(PasswordSettingComponent)
    private pwdSetting: PasswordSettingComponent;

    @ViewChild(NavigatorComponent)
    private navigator: NavigatorComponent;

    //To indicator whwther or not the search results page is displayed
    //We need to use this property to do some overriding work
    private isSearchResultsOpened: boolean = false;

    constructor(private route: ActivatedRoute) { }

    ngOnInit() {
        this.route.data.subscribe(data => {
            //dummy
        });
    }

    public get showSearch(): boolean {
        return this.isSearchResultsOpened;
    }

    //Open modal dialog
    openModal(event: ModalEvent): void {
        switch (event.modalName) {
            case modalAccountSettings:
                this.accountSettingsModal.open();
                break;
            case modalPasswordSetting:
                this.pwdSetting.open();
                break;
            default:
                break;
        }
    }

    //Handle the global search event and then let the result page to trigger api
    doSearch(event: SearchEvent): void {
        //Once this method is called
        //the search results page must be opened
        this.isSearchResultsOpened = true;

        //Call the child component to do the real work
        this.searchResultComponet.doSearch(event.term);
    }

    //Search results page closed
    //remove the related ovevriding things
    searchClose(event: boolean): void {
        if (event) {
            this.isSearchResultsOpened = false;
        }
    }
kunw's avatar
kunw committed
80
}