-
Notifications
You must be signed in to change notification settings - Fork 1
/
CRM.eve
423 lines (340 loc) · 13.9 KB
/
CRM.eve
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# Contact Application
This application demonstrates some basic patterns you might want to use in a mobile application or website. These concepts include:
- application architecture
- navigating between pages
- displaying lists of information
- joining and filtering data
- reusing interface components
- responding to events
## The App Record
`#app` stores some useful state for the application, including the current user, the current page, and the current contact.
```
commit
[#app]
```
Set some initial state on `#app` and mark it as `#init`. This block sets the start time of the app, so `#time` is brought into the search. Since we only want this to happen once, we search for `#app` that is not `#init`. Then, we mark the `#app` as `#init` to prevent the block from firing again due to a time update.
```
search
app = [#app]
[#time day month year hours minutes seconds ampm]
not(app = [#init])
user = [#user name: "Corey Montella"]
//user = [#user name: "Eric Hoffman"]
commit
app <- [#init user
page: [#about contact: user]
start-time: [#start-time day month year hours minutes seconds ampm]]
```
### Main App
The main application is a shell for all other pages in the app. This component draws the main interface, navigation buttons, and provides a "content" div into which other pages are injected.
```
search
app = [#app user]
[#time time-string]
// Handle the case when the user has no threads
threads = if app.unread then app.unread
else 0
// If the user is looking at a contact, display that contact's avatar and info. Otherwise, display the user's own avatar.
current-contact = if app.contact then app.contact
else user
bind @browser
[#link rel: "stylesheet" href: "examples/css/crm.css"]
[#div #container class: "container" children:
[#div class: "scroll" children:
[#div class: "banner"]
[#div class: "bio-info" children:
[#div class: "avatar-container" children:
[#img class: "avatar", src: current-contact.avatarURL]]
[#div class: "name2" text: "{{current-contact.name}}"]
[#div class: "info" text: "{{current-contact.title}}"]
[#div class: "info" text: "{{time-string}}, {{current-contact.location}}"]]
[#div #content class: "content"]]
[#div class: "navigation" children:
[#div #about #nav class: "nav-button middle", children:
[#div class: "icon ion-person"]
[#div class: "label" text: "profile"]]
[#div #threads #nav class: "nav-button middle", children:
[#div class: "icon ion-chatboxes"]
[#div class: "bubble" text: threads]
[#div class: "label" text: "messages"]]
[#div #contacts #nav class: "nav-button middle" children:
[#div class: "icon ion-person-stalker" text: ""]
[#div class: "label" text: "contacts"]]
[#div #more #nav class: "nav-button" children:
[#div class: "icon ion-android-more-horizontal" text: ""]
[#div class: "label" text: "more"]]]]
```
As part of the main application, we display a count of unread messages in the navigation bar:
```
search
app = [#app user]
threads = [#thread users: user, messages]
messages = [#unread]
bind
app.unread := count[given: messages]
```
## Pages
The application is composed of various pages, that are injected into the main content area depending on the contents of `#app.page`. Only one page should be displayed at a time.
### About Page
Displays information relating to a contact. This page is constructed in three parts. The first part displays phone and email for the contact:
```
search @browser @session
content = [#content]
[#app page: [#about contact]]
bind @browser @session
content.children := [#div class: "about" children:
[#div class: "about-line", children:
[#span class: "about-label", text: "Phone"]
[#span text: contact.phone]]
[#div class: "about-line", children:
[#span class: "about-label", text: "Email"]
[#span text: contact.email]]
[#div #recent-contacts children:
[#h3 text: "All Contacts ({{count[given: contact.contacts]}})"]
[#img #contact contact: contact.contacts, class: "recent-avatar" src: contact.contacts.avatarURL]]]
```
If the user has threads, then recent contacts are displayed:
```
search @browser @session
recent-div = [#recent-contacts]
[#app page: [#about contact], user]
threads = [#thread users: contact messages]
recent = threads.users != contact
bind @browser @session
recent-div.children += [#div children:
[#h3 text: "Recent Contacts ({{count[given: recent]}})"]
[#img class: "recent-avatar" src: recent.avatarURL]]
```
If the user has no threads and is looking at his own about page, a message is displayed prompting the user to start a conversation with someone:
```
search @browser @session
recent-div = [#recent-contacts]
[#app page: [#about contact], user]
user = contact
not([#thread users: user])
bind @browser
recent-div.children += [#div children:
[#h3 text: "Recent Contacts (0)"]
[#div #contacts #nav children:
[#div class: "plus" text: "+"]
[#div text: "Start a Thread"]]]
```
If there is no contact for the about page, then use the current user's info
```
search
[#app page user]
page = [#about]
not(page = [contact])
commit
page.contact := user
```
### Messages Page
Each message is displayed with the user's avatar and name. An abbreviated timestamp is also displayed.
```
search @browser @session
content = [#content]
app = [#app page: [#thread thread]]
msgs = thread.messages
name = if msgs.sender.name = app.user.name then "Me"
else msgs.sender.name
msgs.time = [timestamp time-string]
bind @browser
content.children := [#div class: "flex-spacer" children:
[#div #convo class: "convo" children:
[#div sort: msgs.time.timestamp class: "msg" message: msgs children:
[#img class: "msg-avatar" src: msgs.sender.avatarURL]
[#span #contact contact: msgs.sender, class: "msg-name" text: name]
[#span class: "msg-time" text: time-string]
[#div class: "msg-text" text: msgs.text]]]
[#input #send-message thread class: "msg-input"]]
```
### Threads Page
Each thread is shown with the contact's avatar and name, and the number of messages in the thread.
```
search @browser @session
content = [#content]
app = [#app page: [#threads], user]
thread = [#thread users: user, messages]
contacts = thread.users != app.user
message-count = count[given: thread.messages, per: thread.users]
bind @browser
content.children := [#div thread class: "thread" children:
[#div #thread thread, class: "thread-box" children:
[#img class: "msg-avatar" src: contacts.avatarURL]
[#div class: "msg-name" text: contacts.name]
[#div text: "{{message-count}} messages"]]
[#div #archive-button thread class: "ion-archive"]]
```
If the user has no threads, display a message prompting the user to start a conversation with a contact
```
search @browser @session
content = [#content]
app = [#app page: [#threads], user]
not(threads = [#thread users: user, messages])
bind @browser
content.children := [#div #contacts #nav class: "button", text: "Start a Thread"]
```
### Contacts Page
Contacts are shown with all their contact details. Clicking on a contact opens up a detailed contact page.
```
search @browser @session
content = [#content]
[#app user page: [#contacts]]
bind @browser @session
content.children := [#div #contact contact: user.contacts, class: "contact" contact: user.contacts, children:
[#img class: "contact-avatar" src: user.contacts.avatarURL]
[#div class: "contact-name", text: user.contacts.name]
[#div text: "Location: {{user.contacts.location}}"]
[#div text: "Phone: {{user.contacts.phone}}"]
[#div text: "Email: {{user.contacts.email}}"]]
```
### More Page
More information about Eve!
```
search @browser @session
content = [#content]
[#app page: [#more]]
bind @browser
content.children := [#div #more class: "more" children:
[#h2 text: "Learn more about Eve"]
[#ul children:
[#li children: [#a href: "http://witheve.com" text: "Homepage"]]
[#li children: [#a href: "https://witheve.github.io/docs/tutorials/quickstart/" text: "Quick Start Tutorial"]]
[#li children: [#a href: "http://github.com/witheve" text: "GitHub Repository"]]]
[#h2 text: "Join the Community"]
[#ul children:
[#li children: [#a href: "http://blog.witheve.com" text: "Development Diary"]]
[#li children: [#a href: "https://github.com/witheve/rfcs" text: "Request for Comments"]]
[#li children: [#a href: "https://groups.google.com/forum/#!forum/eve-talk" text: "Mailing List"]]
[#li children: [#a href: "https://twitter.com/with_eve" text: "Twitter"]]]]
```
## Events
### Set current page
When the user clicks on a `#nav` button, set the app page to that element. We use this in subsequent blocks to fill the `#content` area of the app.
```
search @event @browser @session
[#click element]
element = [#nav]
app = [#app user]
commit
app.page := [tag: element.tag]
app.contact := none
```
### Display contact
When the user clicks on a contact's name, their "About" page is displayed. Otherwise, the user's own "About" page is displayed.
```
search @event @browser @session
[#click element: [#contact contact]]
app = [#app]
commit
app.contact := contact
app.page := [#about contact]
```
### Display messages
Messages are displayed for a current thread. By displaying messages, they are automatically marked as read, which decrements the count on the navigation bar.
```
search @event @browser @session
[#click element: [#thread thread]]
app = [#app]
commit
app.page := [#thread thread]
thread.messages -= #unread
```
### Send a message
When the user presses "enter" in the message input box, a message is added to the current thread, with the current time. This event should also clear the input box.
```
search @event @browser @session
[#keydown key: "enter" element: input]
input = [#send-message thread value]
[#app user]
time = [#time timestamp time-string]
commit @browser
input.value := ""
thread.messages += [#message sender: user, time: [timestamp time-string], text: value]
```
### Archive a thread
When the user archives a thread, the `#archive` tag is added to that thread, which then exludes it from display in the main thread list. Archiving a thread also marks all unread messages as read.
- TODO Add a place to see all archived threads
```
search @event @browser @session
[#click element: [#archive-button thread]]
messages = thread.messages
commit @session
thread += #archived
messages -= #unread
```
## Test Data
The users and messages in this application are fabricated.
```
search
t1 = 1479258949716
t2 = t1 + 1000
t3 = t2 + 1000
t4 = t3 + 1000
t5 = t4 + 1000
t6 = t5 + 1000
time-string = "5:15 PM"
commit
corey = [#user
name: "Corey Montella"
title: "Software Engineer"
avatarURL: "https://avatars2.githubusercontent.com/u/10619266?v=3&s=466"
location: "San Francisco, CA"
email: "corey@kodowa.com"
phone: "555-555-5555"]
chris = [#user
name: "Chris Granger"
title: "CEO"
avatarURL: "https://avatars3.githubusercontent.com/u/70036?v=3&s=466"
location: "San Francisco, CA"
email: "chris@kodowa.com"
phone: "555-555-5556"]
josh = [#user
name: "Josh Cole"
title: "Software Engineer"
avatarURL: "https://avatars2.githubusercontent.com/u/313870?v=3&s=466"
location: "San Francisco, CA"
email: "josh@kodowa.com"
phone: "555-555-5557"]
rob = [#user
name: "Rob Attorri"
title: "President"
avatarURL: "https://avatars1.githubusercontent.com/u/1314445?v=3&s=466"
location: "San Francisco, CA"
email: "rob@kodowa.com"
phone: "555-555-5558"]
eric = [#user
name: "Eric Hoffman"
title: "Software Engineer"
avatarURL: "https://avatars3.githubusercontent.com/u/1807982?v=3&s=466"
location: "San Francisco, CA"
email: "eric@kodowa.com"
phone: "555-555-5559"]
// Add contacts to users
corey.contacts := (chris, josh, rob, eric)
chris.contacts := (corey, josh, rob)
josh.contacts := (corey, rob, eric)
rob.contacts := (corey, josh, chris, eric)
eric.contacts := (josh, rob)
// Make some threads
[#thread #new-messages users: (corey, chris) messages:
[#message sender: corey, time: [timestamp: t1, time-string], text: "Hey"]
[#message sender: chris, time: [timestamp: t2, time-string], text: "Hey, how are you."]
[#message sender: corey, time: [timestamp: t3, time-string], text: "I'm fine, how are you?"]
[#message #unread sender: chris, time: [timestamp: t4, time-string], text: "Fine as well."]
[#message #unread sender: chris, time: [timestamp: t5, time-string], text: "Glad we got that out of the way!"]
[#message #unread sender: chris, time: [timestamp: t6, time-string], text: "What did you work on yesterday?"]]
[#thread users: (corey, josh) messages:
[#message sender: josh, time: [timestamp: t1, time-string], text: "Hey"]
[#message sender: corey, time: [timestamp: t2, time-string], text: "What's up Josh?"]
[#message sender: josh, time: [timestamp: t3, time-string], text: "I need to tell you something...."]
[#message sender: corey, time: [timestamp: t4, time-string], text: "Uh oh..."]
[#message sender: corey, time: [timestamp: t5, time-string], text: "Well what is it? Don't leave me hanging!"]]
[#thread #new-messages users: (corey, rob) messages:
[#message sender: corey, time: [timestamp: t1, time-string], text: "Did Josh tell you what happened?"]
[#message sender: rob, time: [timestamp: t2, time-string], text: "Yeah, don't worry, we took care of it. "]
[#message sender: corey, time: [timestamp: t3, time-string], text: "Well what happened?"]
[#message sender: rob, time: [timestamp: t4, time-string], text: "Like I said, don't worry about it."]
[#message sender: corey, time: [timestamp: t5, time-string], text: "..."]
[#message #unread sender: rob, time: [timestamp: t6, time-string], text: "🔥"]]
```