-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathowl004.html
382 lines (332 loc) · 11.1 KB
/
owl004.html
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<head>
<title>openworklist</title>
<meta name="viewport" content="
width=device-width,
initial-scale=1">
</head>
<script src="https://www.gstatic.com/firebasejs/5.0.2/firebase.js"></script>
<body style="
margin:0px">
<script>
var config = {
apiKey: "AIzaSyBLV5t8a-gGxnr5ZoS0znAZLNCemTCBAWo",
authDomain: "openworklist.firebaseapp.com",
databaseURL: "https://openworklist.firebaseio.com",
projectId: "openworklist",
storageBucket: "openworklist.appspot.com",
messagingSenderId: "275344271563"
}
var db = firebase.initializeApp(config).firestore()
db.settings({
timestampsInSnapshots: true
})
var uid = null
firebase.auth().onAuthStateChanged(function(user) {
uid = user && user.uid
})
firebase.auth().signInAnonymously().catch(function(error) {
console.log(error)
})
function waitForUid(cb) {
function helper() {
if (uid) cb(uid)
else setTimeout(helper, 250)
}
helper()
}
function each(o, cb) {
if (o instanceof Array) {
for (var i = 0; i < o.length; i++) {
if (cb(o[i], i, o) == false)
return false
}
} else {
for (var k in o) {
if (o.hasOwnProperty(k)) {
if (cb(o[k], k, o) == false)
return false
}
}
}
return true
}
function randomString(len, re) {
re = re || /[a-zA-Z0-9]/
var chars = []
for (var i = 0; i < 256; i++) {
var c = String.fromCharCode(i)
if (c.match(re)) chars.push(c)
}
var ret = []
for (var i = 0; i < len; i++) {
ret.push(chars[Math.floor(Math.random() * chars.length)])
}
return ret.join('')
}
function create_clear() {
var d = document.createElement('div')
d.style.clear = 'both'
return d
}
function create_spacer(width) {
var d = document.createElement('button')
d.style.background = 'transparent'
d.style.border = '0px'
d.style.width = width + 'px'
d.style.float = 'left'
return d
}
function create_header_button(html, cb) {
var d = document.createElement('button')
d.style.background = 'blue'
d.style.border = '10px solid black'
d.style.borderRadius = '20px'
d.style.width = '160px'
d.style.height = '160px'
d.style.float = 'left'
d.style.fontSize = '40px'
d.style.margin = '10px'
d.innerHTML = html
d.onclick = cb
return d
}
function create_input() {
var d = document.createElement('input')
d.style.background = 'blue'
d.style.border = '10px solid black'
d.style.borderRadius = '20px'
d.style.float = 'left'
d.style.width = '160px'
d.style.fontSize = '40px'
d.style.margin = '10px'
return d
}
function create_label(width, html) {
var d = document.createElement('button')
d.style.background = 'transparent'
d.style.border = '0px'
if (width) d.style.width = width + 'px'
else {
d.style.border = '10px solid transparent'
d.style.borderRadius = '20px'
}
d.style.float = 'left'
d.style.fontSize = '40px'
d.innerHTML = html
return d
}
function create_post_form() {
var d = document.createElement('div')
d.style.position = 'absolute'
d.style.background = '#ddd'
d.style.width = '720px'
d.style.top = '0px'
d.style.marginLeft = 'auto'
d.style.marginRight = 'auto'
var text
function create_textarea() {
var d = document.createElement('textarea')
d.style.background = 'blue'
d.style.border = '10px solid black'
d.style.borderRadius = '20px'
d.style.width = '100%'
d.style.height = '160px'
d.style.fontSize = '20px'
text = d
var D = document.createElement('div')
D.style.padding = '10px'
D.append(d)
return D
}
d.append(create_label(360, 'job description'))
d.append(create_textarea())
d.append(create_label(180, 'min'))
d.append(create_label(180, 'max'))
d.append(create_clear())
var min_people, max_people
d.append(min_people = create_input())
d.append(max_people = create_input())
d.append(create_label(null, 'people'))
d.append(create_clear())
var min_hours, max_hours
d.append(min_hours = create_input())
d.append(max_hours = create_input())
d.append(create_label(null, 'hours per person'))
d.append(create_clear())
var min_pay, max_pay
d.append(min_pay = create_input())
d.append(max_pay = create_input())
d.append(create_label(null, 'pay per hour'))
d.append(create_clear())
d.append(create_spacer(360))
d.append(create_header_button('<span style="font-size:80px">+</span><br/><span style="font-size:20px">POST</span>', function () {
waitForUid(function (uid) {
db.collection('job').add({
uid : uid,
time : firebase.firestore.FieldValue.serverTimestamp(),
text : text.value,
min_people : min_people.value,
max_people : max_people.value,
min_hours : min_hours.value,
max_hours : max_hours.value,
min_pay : min_pay.value,
max_pay : max_pay.value
}).then(function () {
console.log('alsdkjfl')
}).catch(function (e) {
console.log('got here!!!!????, ', e)
})
})
}))
d.append(create_header_button('<span style="font-size:80px">-</span><br/><span style="font-size:20px">CANCEL</span>', function () {
d.remove()
}))
d.append(create_clear())
return d
}
function create_find_form() {
var d = document.createElement('div')
d.style.background = '#ddd'
d.style.width = '720px'
d.style.marginLeft = 'auto'
d.style.marginRight = 'auto'
var words
function create_textarea() {
var d = document.createElement('input')
d.style.background = 'blue'
d.style.border = '10px solid black'
d.style.borderRadius = '20px'
d.style.width = '100%'
d.style.fontSize = '40px'
words = d
var D = document.createElement('div')
D.style.padding = '10px'
D.append(d)
return D
}
d.append(create_label(360, 'contains words'))
d.append(create_textarea())
d.append(create_label(180, 'min'))
d.append(create_label(180, 'max'))
d.append(create_clear())
var min_people, max_people
d.append(min_people = create_input())
d.append(max_people = create_input())
d.append(create_label(null, 'people'))
d.append(create_clear())
var min_hours, max_hours
d.append(min_hours = create_input())
d.append(max_hours = create_input())
d.append(create_label(null, 'hours per person'))
d.append(create_clear())
var min_pay, max_pay
d.append(min_pay = create_input())
d.append(max_pay = create_input())
d.append(create_label(null, 'pay per hour'))
d.append(create_clear())
waitForUid(function (uid) {
words.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_words').set(this.value)
}
min_people.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_min_people').set(this.value)
}
max_people.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_max_people').set(this.value)
}
min_hours.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_min_hours').set(this.value)
}
max_hours.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_max_hours').set(this.value)
}
min_pay.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_min_pay').set(this.value)
}
max_pay.oninput = function () {
db.child('owl004/user_public/' + uid + '/find_max_pay').set(this.value)
}
db.child('owl004/user_public/' + uid).on('value', function (x) {
x = x.val() || {}
words.value = x.find_words || ''
min_people.value = x.find_min_people || ''
max_people.value = x.find_max_people || ''
min_hours.value = x.find_min_hours || ''
max_hours.value = x.find_max_hours || ''
min_pay.value = x.find_min_pay || ''
max_pay.value = x.find_max_pay || ''
})
})
return d
}
function create_find_view() {
var d = document.createElement('div')
d.style.background = '#ddd'
d.style.width = '720px'
d.style.marginLeft = 'auto'
d.style.marginRight = 'auto'
d.append(create_label(180, 'results'))
var results = document.createElement('div')
d.append(results)
d.append(create_clear())
waitForUid(function (uid) {
db.child('owl004/job').on('value', function (x) {
console.log('hihi?')
x = x.val() || {}
var a = []
each(x, function (v, k) { v.key = k; a.push(v) })
a.reverse()
results.innerHTML = ''
each(a, function (x) {
var d = document.createElement('div')
d.style.padding = '10px'
var dd = document.createElement('textarea')
dd.style.background = 'blue'
dd.style.border = '10px solid black'
dd.style.borderRadius = '20px'
dd.style.width = '100%'
dd.style.height = '160px'
dd.style.fontSize = '20px'
dd.value = x.text || ''
d.append(dd)
var dd = document.createElement('textarea')
dd.style.background = 'transparent'
dd.style.textAlign = 'right'
dd.style.border = '10px solid transparent'
dd.style.borderRadius = '20px'
dd.style.color = 'white'
dd.style.width = '100%'
dd.style.height = '160px'
dd.style.fontSize = '12px'
dd.style.marginTop = '-160px'
dd.value = `${x.min_people || 0}-${x.max_people || '\u221E'} people, ` +
`${x.min_hours || 0}-${x.max_hours || '\u221E'} hours, ` +
`$${x.min_pay || 0}-${x.max_pay || '\u221E'}`
d.append(dd)
results.append(d)
})
})
})
return d
}
function create_header() {
var d = document.createElement('div')
d.style.background = '#ddd'
d.style.width = '720px'
d.style.marginLeft = 'auto'
d.style.marginRight = 'auto'
d.append(create_header_button('OWL'))
d.append(create_header_button('🔍', function () {
d.append(create_find_form())
}))
d.append(create_header_button('<span style="font-size:80px">+</span><br/><span style="font-size:20px">POST</span>', function () {
document.body.append(create_post_form())
}))
d.append(create_header_button('<span style="font-size:20px">beautiful statistics</span>'))
d.append(create_clear())
return d
}
document.body.append(create_header())
document.body.append(create_find_view())
</script>
</body>