vines-services 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/{README → README.md} +19 -9
- data/Rakefile +20 -113
- data/{web/coffeescripts → app/assets/javascripts}/api.coffee +1 -1
- data/{web/coffeescripts/init.coffee → app/assets/javascripts/application.coffee} +9 -0
- data/{web/coffeescripts → app/assets/javascripts}/commands.coffee +1 -1
- data/{web/coffeescripts → app/assets/javascripts}/files.coffee +1 -1
- data/{web/coffeescripts → app/assets/javascripts}/services.coffee +1 -1
- data/{web/coffeescripts → app/assets/javascripts}/setup.coffee +1 -1
- data/{web/coffeescripts → app/assets/javascripts}/systems.coffee +1 -1
- data/app/assets/stylesheets/application.css +9 -0
- data/{web → app/assets}/stylesheets/common.css +0 -0
- data/{web → app/assets}/stylesheets/files.css +0 -0
- data/{web → app/assets}/stylesheets/services.css +0 -0
- data/{web → app/assets}/stylesheets/setup.css +0 -0
- data/{web → app/assets}/stylesheets/systems.css +0 -0
- data/config.ru +12 -0
- data/lib/vines/services/command/init.rb +4 -1
- data/lib/vines/services/version.rb +1 -1
- data/{web/stylesheets/app.css → public/assets/application.css} +854 -395
- data/public/assets/application.js +10 -0
- data/{web → public}/images/default-service.png +0 -0
- data/{web → public}/images/linux.png +0 -0
- data/{web → public}/images/mac.png +0 -0
- data/{web → public}/images/run.png +0 -0
- data/{web → public}/images/windows.png +0 -0
- data/public/index.html +13 -0
- data/test/config_test.rb +1 -1
- data/test/priority_queue_test.rb +1 -1
- data/test/storage/couchdb_test.rb +1 -1
- data/test/vql/compiler_test.rb +1 -1
- data/test/vql/vql_test.rb +1 -1
- data/vines-services.gemspec +44 -0
- metadata +233 -59
- data/web/index.html +0 -17
- data/web/javascripts/api.js +0 -69
- data/web/javascripts/app.js +0 -2
- data/web/javascripts/commands.js +0 -28
- data/web/javascripts/files.js +0 -424
- data/web/javascripts/init.js +0 -27
- data/web/javascripts/services.js +0 -409
- data/web/javascripts/setup.js +0 -507
- data/web/javascripts/systems.js +0 -391
data/web/javascripts/systems.js
DELETED
@@ -1,391 +0,0 @@
|
|
1
|
-
var SystemsPage;
|
2
|
-
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
3
|
-
SystemsPage = (function() {
|
4
|
-
function SystemsPage(session) {
|
5
|
-
this.session = session;
|
6
|
-
this.session.onRoster(__bind(function() {
|
7
|
-
return this.roster();
|
8
|
-
}, this));
|
9
|
-
this.session.onMessage(__bind(function(m) {
|
10
|
-
return this.message(m);
|
11
|
-
}, this));
|
12
|
-
this.session.onPresence(__bind(function(p) {
|
13
|
-
return this.presence(p);
|
14
|
-
}, this));
|
15
|
-
this.commands = new Commands;
|
16
|
-
this.chats = {};
|
17
|
-
this.currentContact = null;
|
18
|
-
this.layout = null;
|
19
|
-
}
|
20
|
-
SystemsPage.prototype.datef = function(millis) {
|
21
|
-
var d, hour, meridian, minutes;
|
22
|
-
d = new Date(millis);
|
23
|
-
meridian = d.getHours() >= 12 ? ' pm' : ' am';
|
24
|
-
hour = d.getHours() > 12 ? d.getHours() - 12 : d.getHours();
|
25
|
-
if (hour === 0) {
|
26
|
-
hour = 12;
|
27
|
-
}
|
28
|
-
minutes = d.getMinutes() + '';
|
29
|
-
if (minutes.length === 1) {
|
30
|
-
minutes = '0' + minutes;
|
31
|
-
}
|
32
|
-
return hour + ':' + minutes + meridian;
|
33
|
-
};
|
34
|
-
SystemsPage.prototype.groupContacts = function() {
|
35
|
-
var contact, group, groups, jid, _i, _len, _ref, _ref2;
|
36
|
-
groups = {};
|
37
|
-
_ref = this.session.roster;
|
38
|
-
for (jid in _ref) {
|
39
|
-
contact = _ref[jid];
|
40
|
-
_ref2 = contact.groups;
|
41
|
-
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
42
|
-
group = _ref2[_i];
|
43
|
-
(groups[group] || (groups[group] = [])).push(contact);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
return groups;
|
47
|
-
};
|
48
|
-
SystemsPage.prototype.roster = function() {
|
49
|
-
var contact, contacts, group, groups, icon, items, name, optgroup, option, opts, sorted, _i, _len, _results;
|
50
|
-
groups = this.groupContacts();
|
51
|
-
sorted = (function() {
|
52
|
-
var _results;
|
53
|
-
_results = [];
|
54
|
-
for (group in groups) {
|
55
|
-
contacts = groups[group];
|
56
|
-
_results.push(group);
|
57
|
-
}
|
58
|
-
return _results;
|
59
|
-
})();
|
60
|
-
sorted = sorted.sort(function(a, b) {
|
61
|
-
a = a.toLowerCase();
|
62
|
-
b = b.toLowerCase();
|
63
|
-
if (a > b) {
|
64
|
-
return 1;
|
65
|
-
} else if (a < b) {
|
66
|
-
return -1;
|
67
|
-
} else {
|
68
|
-
return 0;
|
69
|
-
}
|
70
|
-
});
|
71
|
-
items = $('#roster-items').empty();
|
72
|
-
_results = [];
|
73
|
-
for (_i = 0, _len = sorted.length; _i < _len; _i++) {
|
74
|
-
group = sorted[_i];
|
75
|
-
contacts = groups[group];
|
76
|
-
optgroup = $('<li class="group"></li>').appendTo(items);
|
77
|
-
optgroup.text(group);
|
78
|
-
optgroup.attr('data-group', group);
|
79
|
-
_results.push((function() {
|
80
|
-
var _j, _len2, _results2;
|
81
|
-
_results2 = [];
|
82
|
-
for (_j = 0, _len2 = contacts.length; _j < _len2; _j++) {
|
83
|
-
contact = contacts[_j];
|
84
|
-
option = $("<li data-jid=\"" + contact.jid + "\">\n <span class=\"icon\"></span>\n <span class=\"text\"></span>\n <span class=\"unread\" style=\"display:none;\"></span>\n</li>").appendTo(items);
|
85
|
-
if (contact.offline()) {
|
86
|
-
option.addClass('offline');
|
87
|
-
}
|
88
|
-
option.click(__bind(function(event) {
|
89
|
-
return this.selectContact(event);
|
90
|
-
}, this));
|
91
|
-
name = contact.name || contact.jid.split('@')[0];
|
92
|
-
option.attr('data-name', name);
|
93
|
-
option.attr('data-group', group);
|
94
|
-
$('.text', option).text(name);
|
95
|
-
opts = {
|
96
|
-
fill: '#fff',
|
97
|
-
stroke: '#404040',
|
98
|
-
'stroke-width': 0.3,
|
99
|
-
opacity: 1.0,
|
100
|
-
scale: 0.65
|
101
|
-
};
|
102
|
-
icon = (function() {
|
103
|
-
switch (group) {
|
104
|
-
case 'People':
|
105
|
-
return ICONS.man;
|
106
|
-
case 'Services':
|
107
|
-
return ICONS.magic;
|
108
|
-
default:
|
109
|
-
return ICONS.run;
|
110
|
-
}
|
111
|
-
})();
|
112
|
-
_results2.push(new Button($('.icon', option), icon, opts));
|
113
|
-
}
|
114
|
-
return _results2;
|
115
|
-
}).call(this));
|
116
|
-
}
|
117
|
-
return _results;
|
118
|
-
};
|
119
|
-
SystemsPage.prototype.message = function(message) {
|
120
|
-
var bottom, chat, from, me;
|
121
|
-
this.queueMessage(message);
|
122
|
-
me = message.from === this.session.jid();
|
123
|
-
from = message.from.split('/')[0];
|
124
|
-
if (me || from === this.currentContact) {
|
125
|
-
bottom = this.atBottom();
|
126
|
-
this.appendMessage(message);
|
127
|
-
if (bottom || me) {
|
128
|
-
return this.scroll({
|
129
|
-
animate: true
|
130
|
-
});
|
131
|
-
}
|
132
|
-
} else {
|
133
|
-
chat = this.chat(message.from);
|
134
|
-
chat.unread++;
|
135
|
-
return this.eachContact(from, function(node) {
|
136
|
-
return $('.unread', node).text(chat.unread).show();
|
137
|
-
});
|
138
|
-
}
|
139
|
-
};
|
140
|
-
SystemsPage.prototype.eachContact = function(jid, callback) {
|
141
|
-
var node, _i, _len, _ref, _results;
|
142
|
-
_ref = $("#roster-items li[data-jid='" + jid + "']").get();
|
143
|
-
_results = [];
|
144
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
145
|
-
node = _ref[_i];
|
146
|
-
_results.push(callback($(node)));
|
147
|
-
}
|
148
|
-
return _results;
|
149
|
-
};
|
150
|
-
SystemsPage.prototype.appendMessage = function(message) {
|
151
|
-
var contact, from, me, name, node, prefix, proxied;
|
152
|
-
me = message.from === this.session.jid();
|
153
|
-
proxied = $('jid', message.node).text();
|
154
|
-
from = (proxied || message.from).split('/')[0];
|
155
|
-
contact = this.session.roster[from];
|
156
|
-
name = contact ? contact.name || from : from;
|
157
|
-
node = $("<li data-jid=\"" + from + "\"><pre></pre></li>").appendTo('#messages');
|
158
|
-
prefix = me ? '$ ' : '';
|
159
|
-
$('pre', node).text(prefix + message.text);
|
160
|
-
$('#message-form').css('top', '0px');
|
161
|
-
if (!me) {
|
162
|
-
node.append("<footer>\n <span class=\"author\"></span> @\n <span class=\"time\">" + (this.datef(message.received)) + "</span>\n</footer>");
|
163
|
-
return $('.author', node).text(name);
|
164
|
-
}
|
165
|
-
};
|
166
|
-
SystemsPage.prototype.queueMessage = function(message) {
|
167
|
-
var chat, full, me;
|
168
|
-
me = message.from === this.session.jid();
|
169
|
-
full = message[me ? 'to' : 'from'];
|
170
|
-
chat = this.chat(full);
|
171
|
-
chat.jid = full;
|
172
|
-
return chat.messages.push(message);
|
173
|
-
};
|
174
|
-
SystemsPage.prototype.chat = function(jid) {
|
175
|
-
var bare, chat;
|
176
|
-
bare = jid.split('/')[0];
|
177
|
-
chat = this.chats[bare];
|
178
|
-
if (!chat) {
|
179
|
-
chat = {
|
180
|
-
jid: jid,
|
181
|
-
messages: [],
|
182
|
-
unread: 0
|
183
|
-
};
|
184
|
-
this.chats[bare] = chat;
|
185
|
-
}
|
186
|
-
return chat;
|
187
|
-
};
|
188
|
-
SystemsPage.prototype.presence = function(presence) {
|
189
|
-
var contact, from;
|
190
|
-
from = presence.from.split('/')[0];
|
191
|
-
if (from === this.session.bareJid()) {
|
192
|
-
return;
|
193
|
-
}
|
194
|
-
if (!presence.type || presence.offline) {
|
195
|
-
contact = this.session.roster[from];
|
196
|
-
this.eachContact(from, function(node) {
|
197
|
-
if (contact.offline()) {
|
198
|
-
return node.addClass('offline');
|
199
|
-
} else {
|
200
|
-
return node.removeClass('offline');
|
201
|
-
}
|
202
|
-
});
|
203
|
-
}
|
204
|
-
if (presence.offline) {
|
205
|
-
return this.chat(from).jid = from;
|
206
|
-
}
|
207
|
-
};
|
208
|
-
SystemsPage.prototype.selectContact = function(event) {
|
209
|
-
var contact, jid, selected;
|
210
|
-
$('#blank-slate').fadeOut(200, function() {
|
211
|
-
return $(this).remove();
|
212
|
-
});
|
213
|
-
$('#roster').hide();
|
214
|
-
$('#message').focus();
|
215
|
-
selected = $(event.currentTarget);
|
216
|
-
jid = selected.attr('data-jid');
|
217
|
-
contact = this.session.roster[jid];
|
218
|
-
if (this.currentContact === jid) {
|
219
|
-
return;
|
220
|
-
}
|
221
|
-
this.currentContact = jid;
|
222
|
-
$('#message-label').text($('.text', selected).text());
|
223
|
-
$('#messages').empty();
|
224
|
-
$('#message-form').css('top', '10px');
|
225
|
-
this.layout.resize();
|
226
|
-
return this.restoreChat(jid);
|
227
|
-
};
|
228
|
-
SystemsPage.prototype.restoreChat = function(jid) {
|
229
|
-
var chat, messages, msg, _i, _len;
|
230
|
-
chat = this.chats[jid];
|
231
|
-
messages = [];
|
232
|
-
if (chat) {
|
233
|
-
messages = chat.messages;
|
234
|
-
chat.unread = 0;
|
235
|
-
this.eachContact(jid, function(node) {
|
236
|
-
return $('.unread', node).text('').hide();
|
237
|
-
});
|
238
|
-
}
|
239
|
-
for (_i = 0, _len = messages.length; _i < _len; _i++) {
|
240
|
-
msg = messages[_i];
|
241
|
-
this.appendMessage(msg);
|
242
|
-
}
|
243
|
-
return this.scroll();
|
244
|
-
};
|
245
|
-
SystemsPage.prototype.scroll = function(opts) {
|
246
|
-
var msgs;
|
247
|
-
opts || (opts = {});
|
248
|
-
msgs = $('#messages');
|
249
|
-
if (opts.animate) {
|
250
|
-
return msgs.animate({
|
251
|
-
scrollTop: msgs.prop('scrollHeight')
|
252
|
-
}, 400);
|
253
|
-
} else {
|
254
|
-
return msgs.scrollTop(msgs.prop('scrollHeight'));
|
255
|
-
}
|
256
|
-
};
|
257
|
-
SystemsPage.prototype.atBottom = function() {
|
258
|
-
var bottom, msgs;
|
259
|
-
msgs = $('#messages');
|
260
|
-
bottom = msgs.prop('scrollHeight') - msgs.outerHeight();
|
261
|
-
return msgs.scrollTop() >= bottom;
|
262
|
-
};
|
263
|
-
SystemsPage.prototype.send = function() {
|
264
|
-
var chat, input, jid, text;
|
265
|
-
if (!this.currentContact) {
|
266
|
-
return false;
|
267
|
-
}
|
268
|
-
input = $('#message');
|
269
|
-
text = input.val().trim();
|
270
|
-
if (text) {
|
271
|
-
chat = this.chats[this.currentContact];
|
272
|
-
jid = chat ? chat.jid : this.currentContact;
|
273
|
-
this.message({
|
274
|
-
from: this.session.jid(),
|
275
|
-
text: text,
|
276
|
-
to: jid,
|
277
|
-
received: new Date()
|
278
|
-
});
|
279
|
-
this.session.sendMessage(jid, text);
|
280
|
-
this.commands.push(text);
|
281
|
-
}
|
282
|
-
input.val('');
|
283
|
-
return false;
|
284
|
-
};
|
285
|
-
SystemsPage.prototype.showRoster = function() {
|
286
|
-
var container, form, height, items, rform, roster, up;
|
287
|
-
container = $('#container');
|
288
|
-
form = $('#message-form');
|
289
|
-
roster = $('#roster');
|
290
|
-
items = $('#roster-items');
|
291
|
-
rform = $('#roster-form');
|
292
|
-
up = container.height() - form.position().top < container.height() / 2;
|
293
|
-
if (up) {
|
294
|
-
roster.css('top', '');
|
295
|
-
roster.css('bottom', (form.outerHeight() + 5) + 'px');
|
296
|
-
height = container.height() - form.outerHeight() - 20;
|
297
|
-
} else {
|
298
|
-
roster.css('bottom', '');
|
299
|
-
roster.css('top', (form.position().top + form.outerHeight()) + 'px');
|
300
|
-
height = container.height() - form.position().top - 30;
|
301
|
-
}
|
302
|
-
items.css('max-height', (height - rform.outerHeight() - 40) + 'px');
|
303
|
-
roster.css('max-height', height + 'px');
|
304
|
-
return roster.show();
|
305
|
-
};
|
306
|
-
SystemsPage.prototype.drawBlankSlate = function() {
|
307
|
-
$("<form id=\"blank-slate\" class=\"float\">\n <p>\n Services, and individual systems, can be controlled by sending\n them shell commands through this terminal. Select a system to chat with\n to get started.\n </p>\n <input type=\"submit\" value=\"Select System\"/>\n</form>").appendTo('#alpha');
|
308
|
-
return $('#blank-slate').submit(__bind(function() {
|
309
|
-
this.showRoster();
|
310
|
-
this.layout.resize();
|
311
|
-
return false;
|
312
|
-
}, this));
|
313
|
-
};
|
314
|
-
SystemsPage.prototype.draw = function() {
|
315
|
-
var contact, name;
|
316
|
-
if (!this.session.connected()) {
|
317
|
-
window.location.hash = '';
|
318
|
-
return;
|
319
|
-
}
|
320
|
-
$('body').attr('id', 'systems-page');
|
321
|
-
$('#container').hide().empty();
|
322
|
-
$("<div id=\"alpha\" class=\"primary column x-fill y-fill\">\n <ul id=\"messages\" class=\"scroll\"></ul>\n <form id=\"message-form\">\n <label id=\"message-label\"></label>\n <input id=\"message\" name=\"message\" type=\"text\" maxlength=\"1024\" placeholder=\"Type a command and press enter to send\"/>\n </form>\n <div id=\"roster\" class=\"float\" style=\"display:none;\">\n <ul id=\"roster-items\"></ul>\n <div id=\"roster-form\"></div>\n </div>\n</div>").appendTo('#container');
|
323
|
-
$('#message-form').css('top', '10px');
|
324
|
-
$('#message-form').submit(__bind(function() {
|
325
|
-
return this.send();
|
326
|
-
}, this));
|
327
|
-
$('#messages').click(function() {
|
328
|
-
return $('#roster').hide();
|
329
|
-
});
|
330
|
-
$('#message').focus(function() {
|
331
|
-
return $('#roster').hide();
|
332
|
-
});
|
333
|
-
$(document).keyup(function(e) {
|
334
|
-
if (e.keyCode === 27) {
|
335
|
-
return $('#roster').hide();
|
336
|
-
}
|
337
|
-
});
|
338
|
-
this.roster();
|
339
|
-
$('#message-label').click(__bind(function() {
|
340
|
-
var roster;
|
341
|
-
roster = $('#roster');
|
342
|
-
if (roster.is(':visible')) {
|
343
|
-
return roster.hide();
|
344
|
-
} else {
|
345
|
-
return this.showRoster();
|
346
|
-
}
|
347
|
-
}, this));
|
348
|
-
$('#message').keyup(__bind(function(e) {
|
349
|
-
switch (e.keyCode) {
|
350
|
-
case 38:
|
351
|
-
return $('#message').val(this.commands.prev());
|
352
|
-
case 40:
|
353
|
-
return $('#message').val(this.commands.next());
|
354
|
-
}
|
355
|
-
}, this));
|
356
|
-
if (this.currentContact) {
|
357
|
-
if (this.currentContact) {
|
358
|
-
this.restoreChat(this.currentContact);
|
359
|
-
}
|
360
|
-
contact = this.session.roster[this.currentContact];
|
361
|
-
name = contact.name || contact.jid.split('@')[0];
|
362
|
-
$('#message-label').text(name);
|
363
|
-
$('#message').focus();
|
364
|
-
} else {
|
365
|
-
this.drawBlankSlate();
|
366
|
-
}
|
367
|
-
$('#container').show();
|
368
|
-
this.layout = this.resize();
|
369
|
-
this.scroll();
|
370
|
-
$('#message').focus();
|
371
|
-
new Filter({
|
372
|
-
list: '#roster-items',
|
373
|
-
form: '#roster-form',
|
374
|
-
attrs: ['data-jid', 'data-name']
|
375
|
-
});
|
376
|
-
return $('form', '#roster-form').show();
|
377
|
-
};
|
378
|
-
SystemsPage.prototype.resize = function() {
|
379
|
-
var container, form, label, msg, msgs;
|
380
|
-
container = $('#container');
|
381
|
-
msgs = $('#messages');
|
382
|
-
msg = $('#message');
|
383
|
-
form = $('#message-form');
|
384
|
-
label = $('#message-label');
|
385
|
-
return new Layout(function() {
|
386
|
-
msg.width(form.width() - label.width() - 32);
|
387
|
-
return msgs.css('max-height', container.height() - form.height());
|
388
|
-
});
|
389
|
-
};
|
390
|
-
return SystemsPage;
|
391
|
-
})();
|