forked from latestchatty/chatty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavbar.ts
135 lines (116 loc) · 3.76 KB
/
Navbar.ts
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
declare var _:any
import {Component, OnInit} from 'angular2/core'
import {ActionService} from '../services/ActionService'
import {DisableHotkeys} from '../directives/DisableHotkeys'
import {PostService} from '../services/PostService'
import {SettingsService} from '../services/SettingsService'
import {ShackMessageService} from '../services/ShackMessageService'
import {TabService} from '../services/TabService'
import {ModelService} from '../services/ModelService'
import {ReplyBox} from '../replybox/ReplyBox'
import './navbar.scss';
@Component({
selector: 'navbar',
template: require('./navbar.html'),
directives: [DisableHotkeys, ReplyBox]
})
export class Navbar implements OnInit {
public loginRunning = false
public loginInvalid = false
public username
public password
public postQueue
public newThreads
public newThreadPost = {id: 0, replying: false}
public tabs
public filterExpression
private skipFilter = false
constructor(private actionService:ActionService,
private modelService:ModelService,
private postService:PostService,
private settingsService:SettingsService,
private shackMessageService:ShackMessageService,
private tabService:TabService) {
}
ngOnInit() {
this.username = this.settingsService.getUsername()
this.newThreads = this.modelService.getNewThreads()
this.postQueue = this.postService.getQueue()
this.tabs = this.tabService.getTabs()
}
isLoggedIn() {
return this.settingsService.isLoggedIn()
}
doLogin() {
this.loginRunning = true
this.loginInvalid = false
this.actionService.login(this.username, this.password)
.then(result => {
if (result) {
this.shackMessageService.refresh()
} else {
this.loginInvalid = true
}
this.password = null
this.loginRunning = false
})
}
doLogout() {
this.shackMessageService.clear()
this.postService.clearQueue()
this.username = null
this.password = null
this.actionService.logout()
this.loginRunning = false
this.loginInvalid = false
}
clearPostQueue() {
this.postService.clearQueue()
}
filterChanged() {
if (!this.skipFilter) {
this.tabService.selectTab(this.tabs[0], true)
this.tabService.filterThreads(this.filterExpression)
} else {
this.skipFilter = false
}
}
filterChangedDebounce = _.debounce(() => this.filterChanged(), 150)
selectTab(tab) {
//don't filter back, just select tab
this.skipFilter = true
this.filterExpression = null
window.scrollTo(0, 0)
this.tabService.selectTab(tab)
}
addFilterTab() {
let tab = this.tabService.addTab('filter', this.filterExpression)
this.selectTab(tab)
}
removeTab($event, tab) {
$event.preventDefault()
this.tabService.removeTab(tab)
}
newThread() {
if (!this.newThreadPost.replying) {
this.actionService.openReplyBox(this.newThreadPost)
} else {
this.newThreadPost.replying = false
}
}
reflowThreads() {
window.scrollTo(0, 0)
this.tabService.selectTab(this.tabs[0])
this.actionService.reflowThreads()
this.filterExpression = null
}
getTotalMessageCount() {
return this.shackMessageService.getTotalMessageCount()
}
getUnreadMessageCount() {
return this.shackMessageService.getUnreadMessageCount()
}
goToInbox() {
return this.shackMessageService.goToInbox()
}
}