sidebar.component.ts
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {Component, Inject, Input} from "ng-forward";
import {SidebarNotificationService} from "./sidebar.notification.service";
import {SessionService} from '../../login/session.service';
import {SidebarSectionComponent} from './sidebar-section.component';
@Component({
selector: 'sidebar',
templateUrl: 'app/layout/sidebar/sidebar.html',
directives: [SidebarSectionComponent]
})
@Inject(SidebarNotificationService, SessionService)
/**
* @ngdoc object
* @name sidebar.SidebarComponent
* @requires [SidebarNotificationService, SessionService]
* @description
* This is a widget to a sidebar with visible control.
* Needs a SidebarSectionComponent to show sections/items/subitems
* menu
*
* <b>Usage example:</b>
* @example
* <pre>
* let sidebar: SidebarComponent = new SidebarComponent(SidebarNotificationService, SessionService);
* sidebar.visible = true;
* </pre>
*/
export class SidebarComponent {
/**
* @ngdoc property
* @name visible
* @propertyOf sidebar.SidebarComponent
* @description
* Controls if this component is show/hide
*/
@Input()
private visible: boolean = false;
/**
* @ngdoc property
* @name showStatus
* @propertyOf sidebar.SidebarComponent
* @description
* Controls the show/hide state of the circle user status
*/
@Input('showstatus')
public showStatus: boolean = false;
/**
* @ngdoc property
* @name user
* @propertyOf sidebar.SidebarComponent
* @description
* The user data to show into sidebar
*/
@Input()
public user: { name: string } = {
name: ''
};
/**
* @ngdoc method
* @name constructor
* @methodOf sidebar.SidebarComponent
* @param {SidebarNotificationService} notificationService The service that emmits events to show/hide this component
* @param {SessionService} session The service that loads the user data when user is logged
* @description
* The constructor for this component. Loads the dependencies services
*/
constructor(private notificationService: SidebarNotificationService, private session: SessionService) { }
/**
* @ngdoc method
* @name ngOnInit
* @methodOf sidebar.SidebarComponent
* @description
* Check the initial visibility when this component is loaded
*/
ngOnInit() {
let userData: any = this.session.currentUser();
if (userData) {
this.user = userData.person;
}
this.notificationService.setVisibility(this.visible);
this.notificationService.subscribe((visible: boolean) => {
this.visible = visible;
});
}
/**
* @ngdoc method
* @name isVisible
* @methodOf sidebar.SidebarComponent
* @returns {boolean} True, whether this component is visible, otherwise returns false
* @description
* Verify whether sidebar is visible or not
*/
isVisible(): boolean {
return <boolean>this.visible;
}
}