forked from Geodan/icm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cow2.test.html
224 lines (190 loc) · 7.27 KB
/
cow2.test.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
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Concurrent Online Webgis</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- <link href='http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css' rel='stylesheet' type='text/css'>
--> <link href='http://fonts.googleapis.com/css?family=Dosis:300,500' rel='stylesheet' type='text/css'>
<script src="./libs/cow/lib/underscore/underscore-min.js" type="text/javascript"></script>
<script src="./libs/cow/lib/polyfill-promise/promise-0.1.1.min.js" type="text/javascript"></script>
<!-- IndexedDB -->
<script src="./libs/cow/lib/dbjs/db.js"></script>
<script src="../lib/d3/d3.v3.min.js" charset="utf-8"></script>
<script src="../src/cow2.utils.js" type="text/javascript"></script>
<script src="../src/cow2.record.js" type="text/javascript"></script>
<script src="../src/cow2.syncstore.js" type="text/javascript"></script>
<script src="../src/cow2.peer.js" type="text/javascript"></script>
<script src="../src/cow2.user.js" type="text/javascript"></script>
<script src="../src/cow2.group.js" type="text/javascript"></script>
<script src="../src/cow2.item.js" type="text/javascript"></script>
<script src="../src/cow2.project.js" type="text/javascript"></script>
<script src="../src/cow2.websocket.js" type="text/javascript"></script>
<script src="../src/cow2.core.js" type="text/javascript"></script>
<script src="../src/cow2.js" type="text/javascript"></script>
<script src="scripts/cookies.js" type="text/javascript"></script>
<style>
HTML {
font-family: 'Dosis', Arial, sans-serif;
font-weight: 300;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
color: #555753;
overflow: hidden;
}
h1{
font-family: 'Dosis', Arial, sans-serif;
font-weight: 500;
font-size: 28pt;
color: #555753;
margin-top: 0.6em;
}
h3 {
font-family: 'Dosis', Arial, sans-serif;
font-weight: 500;
font-size: 14pt;
color: #555753;
}
</style>
<script type="text/javascript">
var updateLists = function(){
var data = core.peers();
var peer = d3.select('#peerlist').selectAll('.peer')
.data(data, function(d){return 'peer'+d._id.toString();});
peer.enter().append('div')
.attr('id', function(d){return 'peer'+d._id.toString();})
.classed('peer', true);
peer.html(function(d){
var user = core.users(d.getUserId());
var username = user._id;
var since = new Date(d.timestamp()).toLocaleString();
return '<h3> ' + d._id + ' ('+ username+ ') <small> Since ' + since + ' </h3>'});
peer.exit().remove();
core.userStore().initpromise.done(function(x){
var data = core.users();
var user = d3.select('#userlist').selectAll('.user')
.data(data, function(d){return 'user'+ d._id.toString();});
user.enter().append('div')
//.attr('id', function(d){return 'user'+d._id.toString();})
.classed('user', true);
user.html(function(d){return '<h3>' + d._id + (d.data('name')||"") + '</h3>'})
user.exit().remove();
});
core.projectStore().initpromise.done(function(x){
var expand_project = function(d){
var self = this;
d.itemStore().initpromise.done(function(x){
var data = d.items();
d3.select(self).append('h4').html('Items: ');
var item = d3.select(self).selectAll('.item').data(data, function(e){return 'item'+e._id.toString()});
item.enter().append('span')
.classed('item', true)
.attr('id', function(d){return 'item'+d._id.toString();});
item.html(function(d){
var name = d.data('type');
return d._id + ' ' + name + ','});
item.exit().remove();
});
d.groupStore().initpromise.done(function(x){
var data = d.groups();
d3.select(self).append('h4').html('Groups: ');
var group = d3.select(self).selectAll('.group').data(data, function(e){return 'group'+e._id.toString()});
group.enter().append('span')
.classed('group', true)
.attr('id', function(d){return 'group'+d._id.toString();});
group.html(function(e){
var name = e.data('name');
return e._id + ' '+ name+','});
group.exit().remove();
});
}
var data = core.projects();
var project = d3.select('#projectlist').selectAll('.project')
.data(data, function(d){return 'project'+d._id.toString();});
project.enter().append('div')
.attr('id', function(d){return 'project'+d._id.toString();})
.classed('project', true)
project.html(function(d){return '<h3>' + d._id + ' '+ d.data('name') + '</h3>'})
.append('div')
.each(expand_project);
project.exit().remove();
});
}
var core;
var defaultproject;
var defualtgroup;
$(document).ready(function(){
core = new Cow.core({
wsUrl: 'wss://websocket.geodan.nl:443/new'
});
//TODO: move username admin to other place
//Some username administration with cookies
var username=getCookie("username");
var logon = function(username){
$('#myname').val(username);
core.users({_id:username}).sync();
core.user(username);
}
if (username!=null && username!="")
{
logon(username);
}
else
{
username=prompt("Please enter your name:","");
if (username!=null && username!="")
{
logon(username);
setCookie("username",username,1);
}
}
//Default init settings
core.projectStore().initpromise.done(function(x){
if (!core.projects(1)){
defaultproject = core.projects({_id:1}).data('name',"Sketch").sync();
} else {
defaultproject = core.projects(1);
}
defaultproject.groupStore().initpromise.done(function(x){
if (!defaultproject.groups(1)){
defaultgroup = defaultproject.groups({_id:1}).data('name','Public').sync();
} else {
defaultgroup = defaultproject.groups(1);
}
defaultgroup.members(core.user().id()); //make me a member
});
});
//
//var firstitem = defaultproject.items({_id:1}) //create a new item (overwrite old)
// .data('type','msg') //type is msg
// .data('creator',core.user().id()) //creator is me
// .permissions('edit', 1) //give group 1 the 'edit' permission
// .sync();
window.setInterval(updateLists, 2000);
//What to do when a user changes name
$('#myname').on('blur', function(e, ui) {
var username = $(this).val();
logon(username);
setCookie("username",username,1);
});
});
</script>
</head>
<body>
<div id="top">
<span id="connect" title="click to change connection status"></span>
<span class="welcome"><span data-i18n="txt_welcome" id="txt_welcome">Welcome</span> <input id="myname"/ name="myname" title="click to change your name" value="anonymous" size="13"/></span>
</div>
<div id="content">
<div id="peerlist"><h1>Peers</h1></div>
<div id="userlist"><h1>Users:</h1></div>
<div id="projectlist"><h1>Projects:</h1></div>
</div>
<div id="cow"></div>
<div id="help" ></div>
</body>
</html>