-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.js
185 lines (183 loc) · 6.18 KB
/
client.js
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
var Db = require('db');
var Dom = require('dom');
var Modal = require('modal');
var Obs = require('obs');
var Plugin = require('plugin');
var Page = require('page');
var Server = require('server');
var Ui = require('ui');
exports.render = function() {
Dom.section(function() {
Dom.style({
Box: 'middle'
});
Ui.avatar(Plugin.userAvatar(), {
onTap: function() {
Plugin.userInfo();
}
});
Dom.div(function() {
Dom.style({
Flex: true
});
Dom.h2("Hello, developer");
Dom.text("This is an example Group App demonstrating some Happening API's.");
});
});
Dom.section(function() {
var clientCounter;
Dom.h2("Reactive dom");
Dom.userText("Group Apps are built using Javascript or CoffeeScript. User interfaces are drawn using an abstraction upon the web DOM you know and love. It works **reactively**: changes in the data model are automatically mapped to changes in the interface.");
clientCounter = Obs.create(0);
Dom.div(function() {
Ui.button("Increment me: " + clientCounter.get(), function() {
clientCounter.modify(function(v) {
return v + 1;
});
});
});
});
Dom.section(function() {
Dom.h2("Server side code");
Dom.text("Group Apps contain both code that is run on clients (phones, tablets, web browsers) and on Happening's servers. Server side code is invoked using RPC calls from a client, using timers or subscribing to user events (eg: a user leaves a group).");
Dom.div(function() {
Ui.button("Get server time", function() {
return Server.call('getTime', function(time) {
return Modal.show("The time on the server is: " + time);
});
});
});
});
Dom.section(function() {
Dom.h2("Synchronized data store");
Dom.text("A hierarchical data store is available that is automatically synchronized across all the devices of group members. You write to it from server side code.");
Dom.div(function() {
Ui.button("Synchronized counter: " + Db.shared.get('counter'), function() {
Server.call('incr');
});
});
});
Dom.section(function() {
Dom.h2("Use the source");
Dom.text("We're working on writing more documentation. For now, experiment by looking at the sources of Group Apps we've made available on GitHub.");
Dom.div(function() {
Ui.button("Visit github.com", function() {
Plugin.openUrl('https://github.com/happening');
});
});
});
return Dom.section(function() {
Dom.h2("Some examples");
Ui.button("Event API", function() {
Page.nav(function() {
Page.setTitle("Event API");
Dom.section(function() {
Dom.text("API to send push events (to users that are following your plugin).");
Ui.button("Push group event", function() {
Server.send('event');
});
});
});
});
Ui.button("Http API", function() {
Page.nav(function() {
Page.setTitle("Http API");
Dom.section(function() {
Dom.h2("Outgoing");
Dom.text("API to make HTTP requests from the Happening backend.");
Ui.button("Fetch HackerNews headlines", function() {
Server.send('fetchHn');
});
Db.shared.iterate('hn', function(article) {
Ui.item(function() {
Dom.text(article.get('title'));
Dom.onTap(function() {
Plugin.openUrl(article.get('url'));
});
});
});
});
Dom.section(function() {
Dom.h2("Incoming Http");
Dom.text("API to receive HTTP requests in the Happening backend.");
Dom.div(function() {
Dom.style({
padding: '10px',
margin: '3px 0',
background: '#ddd',
_userSelect: 'text'
});
return Dom.code("curl --data-binary 'your text' " + Plugin.inboundUrl());
});
Dom.div(function() {
Dom.style({
padding: '10px',
background: Plugin.colors().bar,
color: Plugin.colors().barText
});
Dom.text(Db.shared.get('http') || "<awaiting request>");
});
});
});
});
Ui.button("Photo API", function() {
var Photo;
Photo = require('photo');
Page.nav(function() {
Page.setTitle("Photo API");
Dom.section(function() {
var photoKey;
Dom.text("API to show, upload or manipulate photos.");
Ui.bigButton("Pick photo", function() {
Photo.pick();
});
if (photoKey = Db.shared.get('photo')) {
(require('photoview')).render({
key: photoKey
});
}
});
});
});
Ui.button("Plugin API", function() {
Page.nav(function() {
Page.setTitle("Plugin API");
Dom.section(function() {
Dom.text("API to get user or group context.");
});
Ui.list(function() {
var items, name, text, value;
items = {
"Plugin.agent": Plugin.agent(),
"Plugin.colors": Plugin.colors(),
"Plugin.groupAvatar": Plugin.groupAvatar(),
"Plugin.groupCode": Plugin.groupCode(),
"Plugin.groupId": Plugin.groupId(),
"Plugin.groupName": Plugin.groupName(),
"Plugin.userAvatar": Plugin.userAvatar(),
"Plugin.userId": Plugin.userId(),
"Plugin.userIsAdmin": Plugin.userIsAdmin(),
"Plugin.userName": Plugin.userName(),
"Plugin.users": Plugin.users.get(),
"Page.state": Page.state.get(),
"Dom.viewport": Dom.viewport.get()
};
for (name in items) {
value = items[name];
text = ("" + name + " = ") + JSON.stringify(value);
Ui.item(text.replace(/,/g, ', '));
}
});
});
});
Ui.button("Social API", function() {
Page.nav(function() {
Page.setTitle("Social API");
Dom.section(function() {
Dom.text("API to show comments or like boxes.");
});
require('social').renderComments();
});
});
});
};