-
Notifications
You must be signed in to change notification settings - Fork 1
/
overview.client.coffee
155 lines (146 loc) · 3.81 KB
/
overview.client.coffee
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Db = require 'db'
Dom = require 'dom'
Event = require 'event'
Form = require 'form'
Icon = require 'icon'
Obs = require 'obs'
Page = require 'page'
Plugin = require 'plugin'
Server = require 'server'
Ui = require 'ui'
Util = require 'util'
{tr} = require 'i18n'
renderQuestion = (qid) !->
Dom.div !->
question = Db.shared.ref('rounds', qid)
answered = question.get('answers', Plugin.userId())||0
unResolved = !!question.get('new')
unread = Event.isNew(question.get('time'), question.key())
questionText = Util.getQuestion(qid)
Dom.style
Box: 'left'
margin: '0px 0px'
padding: '10px 4px'
borderRadius: '2px'
if unResolved # either answered (but not resolved) or unanswered
Icon.render
data: if answered is 0 then 'question' else 'clock2' #question2
size: 30
color: '#5b0' if unread
style:
display: 'inline-block'
margin: '5px 17px 5px 5px'
else # avatar of winner
Ui.avatar Plugin.userAvatar(Util.getWinner(qid)),
style:
display: 'inline-block'
margin: '0px 12px 0px 0px'
Dom.div !->
Dom.style
Flex: true
Box: 'middle'
color: '#5b0' if unread
if unResolved
if answered is 0 or Db.local.get('start')?
Dom.text tr("New question")
else
Dom.text tr("Question answered. Waiting for results")
else
Dom.text questionText
Dom.onTap !->
Page.nav {0:qid}
Form.sep()
Dom.last().style
margin: "2px 4px"
renderSpawn = !->
Ui.item !->
Dom.style
Box: 'left'
margin: '0px 0px'
padding: '10px 4px'
borderRadius: '2px'
Icon.render
data: 'add'
size: 30
style:
display: 'inline-block'
margin: '5px 17px 5px 5px'
Dom.div !->
Dom.style
Flex: true
Box: 'middle'
Dom.text tr("Request new question")
Dom.onTap !->
log "request new question"
Server.send 'newRound'
exports.render = ->
maxId = Db.shared.get 'maxRounds'
unfinishedQuestion = !!Db.shared.get('rounds', maxId, 'new')
Dom.div !-> # top 3 contenders
Dom.style
textAlign: 'center'
Dom.onTap !->
Page.nav {0:'scores'}
scores = Db.shared.get 'scores'
scoresOder = ((k for k of scores).sort (a, b) -> scores[b] - scores[a])[...3] # sort and get top 3
for user, i in scoresOder
Dom.div !->
Dom.style
display: 'inline-block'
Box: 'vertical'
margin: '5px 10px'
width: ((Page.width()-16)/3)-30 + "px"
Ui.avatar Plugin.userAvatar(user),
size: 60
style:
position: 'inline-block'
margin: '0px 0px 5px'
display: 'inline-block'
Dom.div !->
Dom.style
fontWeight: 'bold'
textOverflow: 'ellipsis'
overflow: 'hidden'
whiteSpace: 'nowrap'
fontSize: '13px'
Dom.text (i+1) + ". " + Plugin.userName(user)
Dom.div !->
Dom.style fontSize: '13px'
Dom.text tr("score: %1", scores[user])
Dom.section !-> # the questions overview
Dom.style padding: '0px 4px'
renderSpawn() unless unfinishedQuestion or !!Db.shared.get('ooq') # ooq = out of questions
Db.shared.observeEach 'rounds', (question) !->
renderQuestion question.key()
, (question) ->
-question.key()
if Util.debug()
Ui.bigButton "Spawn question", !->
Server.send('newRound')
Ui.bigButton "Resolve question", !->
Server.send('resolve')
exports.renderScores = !->
Page.setTitle tr("Scores")
Dom.section !->
Db.shared.observeEach 'scores', (item) !->
return unless Plugin.userName(item.key())? # skip empty (like 0)
Ui.item !->
Dom.div !->
Ui.avatar Plugin.userAvatar(item.key()),
style:
position: 'inline-block'
onTap: !-> Plugin.userInfo(item.key())
Dom.div !->
Dom.style
Flex: true
marginLeft: '10px'
Dom.text Plugin.userName(item.key())
Dom.div !->
Dom.style
width: '30px'
textAlign: 'center'
marginRight: '-6px'
fontSize: '150%'
Dom.text (item.get())
, (item) ->
-item.get()