riemann-dash 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,217 @@
1
+ var toolbar = (function() {
2
+ // Build UI
3
+ var toolbar = $('#toolbar');
4
+ var form = $('<form/>');
5
+ toolbar.append(form);
6
+
7
+ var pager = $('<div class="pager">');
8
+ var load = $('<div class="load"><div class="bar load1" /><div class="bar load5" /><span title="1- and 5-second subscription manager load averages">Load</span></div>');
9
+ var server = $('<input class="server" type="text" name="text">');
10
+ form.append(pager);
11
+ form.append(server);
12
+ form.append(load);
13
+ form.submit(function(e) {
14
+ return false;
15
+ });
16
+
17
+ // Load /////////////////////////////////////////////////////////////////////
18
+
19
+ window.setInterval(function() {
20
+ load.find('span').text("Load " +
21
+ format.float(subs.load1()) + ', ' +
22
+ format.float(subs.load5()));
23
+ load.find(".load1").animate({width: (subs.load1() * 100) + "%"}, 200);
24
+ load.find(".load5").animate({width: (subs.load5() * 100) + "%"}, 1000);
25
+ }, 1000);
26
+
27
+ // Server ///////////////////////////////////////////////////////////////////
28
+
29
+ // Callbacks
30
+ var onServerChangeCallbacks = [];
31
+
32
+ // React to server being set.
33
+ var onServerChange = function(callback) {
34
+ onServerChangeCallbacks.push(callback);
35
+ }
36
+
37
+ // When server is set, call callbacks.
38
+ server.change(function() {
39
+ onServerChangeCallbacks.forEach(function(f) {
40
+ f(server.val());
41
+ });
42
+ server.blur();
43
+ });
44
+
45
+ // Suppress keybindings
46
+ server.focus(keys.disable);
47
+ server.blur(keys.enable);
48
+
49
+ // Pager ////////////////////////////////////////////////////////////////////
50
+
51
+ var onWorkspaceChangeCallbacks = [];
52
+ var onWorkspaceReorderCallbacks = [];
53
+ var onWorkspaceSwitchCallbacks = [];
54
+ var onWorkspaceAddCallbacks = [];
55
+ var onWorkspaceDeleteCallbacks = [];
56
+ var onWorkspaceChange = function(callback) {
57
+ onWorkspaceChangeCallbacks.push(callback);
58
+ };
59
+ var onWorkspaceReorder = function(callback) {
60
+ onWorkspaceReorderCallbacks.push(callback);
61
+ }
62
+ var onWorkspaceSwitch = function(callback) {
63
+ onWorkspaceSwitchCallbacks.push(callback);
64
+ }
65
+ var onWorkspaceAdd = function(callback) {
66
+ onWorkspaceAddCallbacks.push(callback);
67
+ }
68
+ var onWorkspaceDelete = function(callback) {
69
+ onWorkspaceDeleteCallbacks.push(callback);
70
+ }
71
+
72
+ // Set workspaces.
73
+ var workspaces = function(workspaces) {
74
+ pager.empty();
75
+
76
+ // Workspaces
77
+ var workspaceList = $('<ol>');
78
+ pager.append(workspaceList);
79
+
80
+ workspaces.forEach(function(workspace) {
81
+ workspaceList.append(workspaceTile(workspace));
82
+ });
83
+
84
+ // Reordering
85
+ workspaceList.sortable({
86
+ axis: "x",
87
+ containment: pager,
88
+ delay: 20,
89
+ distance: 4,
90
+ tolerance: "intersect",
91
+ update: function() {
92
+ console.log("hi");
93
+ var ids = workspaceList.find('li').map(function() {
94
+ return $(this).data('workspaceId');
95
+ });
96
+ console.log("New ids are: ", ids);
97
+ onWorkspaceReorderCallbacks.forEach(function(f) {
98
+ f(ids);
99
+ });
100
+ }
101
+ });
102
+
103
+ // New button
104
+ var add = $('<div class="add button">+</div>');
105
+ add.click(function() {
106
+ onWorkspaceAddCallbacks.forEach(function(f) {
107
+ f();
108
+ });
109
+ });
110
+
111
+ pager.append(add);
112
+ };
113
+
114
+ // Returns a tile for a workspace.
115
+ var workspaceTile = function(workspace) {
116
+ var tile = $('<li class="button" />');
117
+ tile.text(workspace.name);
118
+ tile.data('workspaceId', workspace.id);
119
+ // tile.disableTextSelect();
120
+
121
+ // Switch to this workspace.
122
+ tile.click(function() {
123
+ if (! tile.hasClass("current")) {
124
+ onWorkspaceSwitchCallbacks.forEach(function(f) {
125
+ f(workspace);
126
+ });
127
+ }
128
+ });
129
+
130
+ // Edit this workspace name.
131
+ tile.dblclick(function() {
132
+ namer = workspaceNamer(workspace);
133
+ keys.disable();
134
+ tile.replaceWith(namer);
135
+ namer.focus();
136
+ });
137
+
138
+ // Delete
139
+ var del = $('<div class="delete">×</div>');
140
+ del.click(function() {
141
+ onWorkspaceDeleteCallbacks.forEach(function(f) {
142
+ f(workspace);
143
+ });
144
+ });
145
+ tile.append(del);
146
+
147
+ return tile;
148
+ }
149
+
150
+ // A box to rename a workspace.
151
+ var workspaceNamer = function(workspace) {
152
+ var field = $('<input type="text" />');
153
+ field.val(workspace.name);
154
+
155
+ // Change the workspace, firing callbacks and replacing the pager tile.
156
+ var submit = function(w2) {
157
+ onWorkspaceChangeCallbacks.forEach(function(f) {
158
+ f(workspace, w2);
159
+ });
160
+
161
+ keys.enable();
162
+ }
163
+
164
+ // When the input changes, change the workspace.
165
+ field.change(function() {
166
+ var newWorkspace = _.clone(workspace);
167
+ newWorkspace.name = field.val();
168
+ submit(newWorkspace);
169
+ });
170
+
171
+ // When we leave focus, revert.
172
+ field.blur(function() { submit(workspace) });
173
+ field.keydown(function(e) {
174
+ if (e.which === 13) {
175
+ field.change();
176
+ } else if (e.which === 27) {
177
+ submit(workspace);
178
+ }
179
+ });
180
+
181
+ return field;
182
+ }
183
+
184
+ // Focus a workspace.
185
+ var workspace = function(workspace) {
186
+ console.log("Switching to workspace", workspace);
187
+ pager.find('li').removeClass('current');
188
+ if (workspace === null) {
189
+ return;
190
+ }
191
+
192
+ pager.find('li').each(function(i, el) {
193
+ if ($(el).data('workspaceId') === workspace.id) {
194
+ $(el).addClass('current');
195
+ }
196
+ });
197
+ }
198
+
199
+ return {
200
+ server: function(s) {
201
+ if (s === undefined) {
202
+ return server.val();
203
+ } else {
204
+ server.val(s);
205
+ return s;
206
+ }
207
+ },
208
+ onServerChange: onServerChange,
209
+ onWorkspaceChange: onWorkspaceChange,
210
+ onWorkspaceReorder: onWorkspaceReorder,
211
+ onWorkspaceSwitch: onWorkspaceSwitch,
212
+ onWorkspaceAdd: onWorkspaceAdd,
213
+ onWorkspaceDelete: onWorkspaceDelete,
214
+ workspaces: workspaces,
215
+ workspace: workspace
216
+ }
217
+ })();
@@ -0,0 +1,5 @@
1
+ // Underscore.js 1.4.2
2
+ // http://underscorejs.org
3
+ // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
4
+ // Underscore may be freely distributed under the MIT license.
5
+ (function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.2";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(T.has(e,o)&&t.call(r,e[o],o,e)===n)return};T.map=T.collect=function(e,t,n){var r=[];return e==null?r:p&&e.map===p?e.map(t,n):(N(e,function(e,i,s){r[r.length]=t.call(n,e,i,s)}),r)},T.reduce=T.foldl=T.inject=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o<r.computed&&(r={value:e,computed:o})}),r.value},T.shuffle=function(e){var t,n=0,r=[];return N(e,function(e){t=T.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return T.isFunction(e)?e:function(t){return t[e]}};T.sortBy=function(e,t,n){var r=k(t);return T.pluck(T.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(n<r||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t);return N(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};T.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(T.has(e,t)?e[t]:e[t]=[]).push(n)})},T.countBy=function(e,t,n){return L(e,t,n,function(e,t,n){T.has(e,t)||(e[t]=0),e[t]++})},T.sortedIndex=function(e,t,n,r){n=n==null?T.identity:k(n);var i=n.call(r,t),s=0,o=e.length;while(s<o){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},T.toArray=function(e){return e?e.length===+e.length?u.call(e):T.values(e):[]},T.size=function(e){return e.length===+e.length?e.length:T.keys(e).length},T.first=T.head=T.take=function(e,t,n){return t!=null&&!n?u.call(e,0,t):e[0]},T.initial=function(e,t,n){return u.call(e,0,e.length-(t==null||n?1:t))},T.last=function(e,t,n){return t!=null&&!n?u.call(e,Math.max(e.length-t,0)):e[e.length-1]},T.rest=T.tail=T.drop=function(e,t,n){return u.call(e,t==null||n?1:t)},T.compact=function(e){return T.filter(e,function(e){return!!e})};var A=function(e,t,n){return N(e,function(e){T.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};T.flatten=function(e,t){return A(e,t,[])},T.without=function(e){return T.difference(e,u.call(arguments,1))},T.uniq=T.unique=function(e,t,n,r){var i=n?T.map(e,n,r):e,s=[],o=[];return N(i,function(n,r){if(t?!r||o[o.length-1]!==n:!T.contains(o,n))o.push(n),s.push(e[r])}),s},T.union=function(){return T.uniq(a.apply(r,arguments))},T.intersection=function(e){var t=u.call(arguments,1);return T.filter(T.uniq(e),function(e){return T.every(t,function(t){return T.indexOf(t,e)>=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r<t;r++)n[r]=T.pluck(e,""+r);return n},T.object=function(e,t){var n={};for(var r=0,i=e.length;r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},T.indexOf=function(e,t,n){if(e==null)return-1;var r=0,i=e.length;if(n){if(typeof n!="number")return r=T.sortedIndex(e,t),e[r]===t?r:-1;r=n<0?Math.max(0,i+n):n}if(b&&e.indexOf===b)return e.indexOf(t,n);for(;r<i;r++)if(e[r]===t)return r;return-1},T.lastIndexOf=function(e,t,n){if(e==null)return-1;var r=n!=null;if(w&&e.lastIndexOf===w)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);var i=r?n:e.length;while(i--)if(e[i]===t)return i;return-1},T.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);while(i<r)s[i++]=e,e+=n;return s};var O=function(){};T.bind=function(t,n){var r,i;if(t.bind===x&&x)return x.apply(t,u.call(arguments,1));if(!T.isFunction(t))throw new TypeError;return i=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=t.prototype;var e=new O,s=t.apply(e,i.concat(u.call(arguments)));return Object(s)===s?s:e}return t.apply(n,i.concat(u.call(arguments)))}},T.bindAll=function(e){var t=u.call(arguments,1);return t.length==0&&(t=T.functions(e)),N(t,function(t){e[t]=T.bind(e[t],e)}),e},T.memoize=function(e,t){var n={};return t||(t=T.identity),function(){var r=t.apply(this,arguments);return T.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},T.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},T.defer=function(e){return T.delay.apply(T,[e,1].concat(u.call(arguments,1)))},T.throttle=function(e,t){var n,r,i,s,o,u,a=T.debounce(function(){o=s=!1},t);return function(){n=this,r=arguments;var f=function(){i=null,o&&(u=e.apply(n,r)),a()};return i||(i=setTimeout(f,t)),s?o=!0:(s=!0,u=e.apply(n,r)),a(),u}},T.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},T.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},T.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},T.compose=function(){var e=arguments;return function(){var t=arguments;for(var n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r<e;r++)t.call(n,r)},T.random=function(e,t){return t==null&&(t=e,e=0),e+(0|Math.random()*(t-e+1))};var _={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);
@@ -0,0 +1,35 @@
1
+ var util = (function() {
2
+ var uniqueId = function(bytes) {
3
+ bytes = bytes || 20;
4
+ var s = '';
5
+ for (var i = 0; i < bytes * 2; i++) {
6
+ s += Math.floor(Math.random() * 16).toString(16);
7
+ }
8
+ return s;
9
+ }
10
+
11
+ // Merge two maps nondestructively.
12
+ var merge = function(m1, m2) {
13
+ return _.extend(_.clone(m1), m2);
14
+ }
15
+
16
+ return {
17
+ merge: merge,
18
+ uniqueId: uniqueId
19
+ }
20
+ })();
21
+
22
+ $(function() {
23
+ // Allow disabling text selection.
24
+ $.extend($.fn.disableTextSelect = function() {
25
+ return this.each(function(){
26
+ if($.browser.mozilla){//Firefox
27
+ $(this).css('MozUserSelect','none');
28
+ }else if($.browser.msie){//IE
29
+ $(this).bind('selectstart',function(){return false;});
30
+ }else{//Opera, etc.
31
+ $(this).mousedown(function(){return false;});
32
+ }
33
+ });
34
+ });
35
+ });
@@ -196,14 +196,16 @@ var view = (function() {
196
196
  View.prototype.delete = function() {
197
197
  this.unfocus();
198
198
  var p = this.parent;
199
- if (p){
199
+ if (p) {
200
200
  if (p.removeChild) {
201
201
  p.removeChild(this);
202
202
  }
203
203
  p.reflow();
204
204
  }
205
- this.el.remove();
206
- this.el = null;
205
+ if (this.el) {
206
+ this.el.remove();
207
+ this.el = null;
208
+ }
207
209
  }
208
210
 
209
211
  // Remove us from our parent, and have them reflow.
@@ -289,7 +291,9 @@ var view = (function() {
289
291
  // Unfocus this view
290
292
  View.prototype.unfocus = function() {
291
293
  focusOverlay.hide();
292
- this.el.removeClass("focused");
294
+ if (this.el) {
295
+ this.el.removeClass("focused");
296
+ }
293
297
  if (focused === this) {
294
298
  focused = null;
295
299
  }
@@ -472,11 +476,14 @@ var view = (function() {
472
476
 
473
477
  var Balloon = function(json) {
474
478
  View.call(this, json);
479
+ this.container = json.container;
475
480
  this.clickFocusable = false;
481
+ this.el.detach();
482
+ this.el.appendTo(this.container);
483
+
476
484
  this.child = reify(json.child);
477
485
  this.child.parent = this;
478
486
  this.el.append(this.child.el);
479
- this.parent = this.el.parent();
480
487
  }
481
488
  inherit(View, Balloon);
482
489
  types.Balloon = Balloon;
@@ -497,13 +504,24 @@ var view = (function() {
497
504
  this.el.append(this.child.el);
498
505
  }
499
506
 
507
+ Balloon.prototype.removeChild = function(c) {
508
+ this.child = null;
509
+ }
510
+
500
511
  Balloon.prototype.reflow = function() {
501
- var p = this.parent;
512
+ var p = this.container;
502
513
  this.width(p.width());
503
514
  this.height(p.height());
504
- this.child.width(p.width());
505
- this.child.height(p.height());
506
- this.child.reflow();
515
+ if (this.child) {
516
+ this.child.width(p.width());
517
+ this.child.height(p.height());
518
+ this.child.reflow();
519
+ }
520
+ }
521
+
522
+ Balloon.prototype.delete = function() {
523
+ this.child.delete();
524
+ View.prototype.delete.call(this);
507
525
  }
508
526
 
509
527
  // Fullscreen //////////////////////////////////////////////////////////////
@@ -594,7 +612,7 @@ var view = (function() {
594
612
  }
595
613
 
596
614
  Stack.prototype.delete = function() {
597
- this.children.forEach(function(c) {
615
+ this.children.slice().forEach(function(c) {
598
616
  c.delete();
599
617
  });
600
618
  View.prototype.delete.call(this);
@@ -0,0 +1,279 @@
1
+ (function() {
2
+ var fitopts = {min: 6, max: 1000};
3
+
4
+ var Grid = function(json) {
5
+ view.View.call(this, json);
6
+ this.query = json.query;
7
+ this.title = json.title;
8
+ this.max = json.max || "all";
9
+ this.clickFocusable = true;
10
+
11
+ // Initial display
12
+ this.el.addClass('grid');
13
+ this.el.append(
14
+ '<div class="title"></div>' +
15
+ '<table></table>'
16
+ );
17
+ this.box = this.el.find('.box');
18
+ this.el.find('.title').text(this.title);
19
+
20
+ // State
21
+ this.hosts = [];
22
+ this.services = [];
23
+ this.events = {};
24
+ if (this.max === "service" || this.max === "host") {
25
+ this.currentMax = {};
26
+ }
27
+
28
+ // Subscribe
29
+ if (this.query) {
30
+ var me = this;
31
+ this.sub = subs.subscribe(this.query, function(e) {
32
+ me.update.call(me, e);
33
+ });
34
+ }
35
+ }
36
+
37
+ view.inherit(view.View, Grid);
38
+ view.Grid = Grid;
39
+ view.types.Grid = Grid;
40
+
41
+ Grid.prototype.json = function() {
42
+ return $.extend(view.View.prototype.json.call(this), {
43
+ type: 'Grid',
44
+ title: this.title,
45
+ query: this.query,
46
+ max: this.max,
47
+ });
48
+ }
49
+
50
+ Grid.prototype.editForm = function() {
51
+ return Mustache.render('<label for="title">Title</label>' +
52
+ '<input type="text" name="title" value="{{title}}" /><br />' +
53
+ '<label for="query">Query</label>' +
54
+ '<input type="text" name="query" value="{{query}}" /><br />' +
55
+ '<label for="max">Max</label>' +
56
+ '<input type="text" name="max" value="{{max}}" /><br />' +
57
+ '<span class="desc">"all", "host", "service", or any number.</span>',
58
+ this)
59
+ }
60
+
61
+ // Returns all events, flat.
62
+ Grid.prototype.allEvents = function() {
63
+ var events = [];
64
+ for (host in this.events) {
65
+ for (service in this.events[host]) {
66
+ events.push(this.events[host][service]);
67
+ }
68
+ }
69
+ }
70
+
71
+ // What is the maximum for this event?
72
+ Grid.prototype.eventMax = function(event) {
73
+ if (this.max === "host") {
74
+ return this.currentMax[event.host] || -1/0;
75
+ } else if (this.max === "service") {
76
+ return this.currentMax[event.service] || -1/0;
77
+ } else {
78
+ return this.currentMax || -1/0;
79
+ }
80
+ }
81
+
82
+ // Update a single jq element with information about an event.
83
+ Grid.prototype.renderElement = function(element, event) {
84
+ if (event === undefined) {
85
+ return;
86
+ }
87
+
88
+ // State
89
+ element.attr('class', "state box " + event.state);
90
+
91
+ // Metric
92
+ element.find('.metric').text(format.float(event.metric));
93
+
94
+ // Description
95
+ element.attr('title', event.state + ' at ' + event.time + "\n\n" +
96
+ event.description);
97
+
98
+ // Bar chart
99
+ if (event.metric) {
100
+ element.find('.bar').css('width',
101
+ (event.metric / this.eventMax(event) * 100) + "%");
102
+ }
103
+ }
104
+
105
+
106
+ // Render a single event if there's been no change to table structure.
107
+ Grid.prototype.partialRender = function(event) {
108
+ var table = this.el.find('table');
109
+ var hostIndex = this.hosts.indexOf(event.host);
110
+ var serviceIndex = this.services.indexOf(event.service);
111
+ var row = this.el.find('tbody tr')[hostIndex];
112
+ var td = $($(row).find('td')[serviceIndex]);
113
+
114
+ this.renderElement(td, event);
115
+ }
116
+
117
+ // Rerender the table
118
+ Grid.prototype.render = function() {
119
+ var table = this.el.find('table');
120
+ table.empty();
121
+
122
+ // Header
123
+ table.append("<thead><tr><th></th></tr></thead>");
124
+ var row = table.find("thead tr");
125
+ this.services.forEach(function(service) {
126
+ var element = $('<th>');
127
+ element.text(service);
128
+ row.append(element);
129
+ });
130
+
131
+ this.hosts.forEach(function(host) {
132
+ row = $("<tr><th></th>");
133
+ table.append(row);
134
+ row.find('th').text(host);
135
+ this.services.forEach(function(service) {
136
+ var event = this.events[host][service];
137
+ var element = $('<td><span class="metric" /><div class="bar" /></td>');
138
+ this.renderElement(element, event);
139
+ row.append(element);
140
+ }, this);
141
+ }, this);
142
+ };
143
+
144
+ // Update cached maxima with a new event. Returns true if maxima changed.
145
+ Grid.prototype.updateMax = function(event) {
146
+ if (event !== undefined &&
147
+ (event.metric === undefined ||
148
+ event.metric <= (this.eventMax(event) || -1/0))) {
149
+ // We haven't bumped our max; no change.
150
+ return false;
151
+ }
152
+
153
+ var e;
154
+ if (this.max === "all") {
155
+ this.currentMax = -1/0;
156
+ for (host in this.events) {
157
+ for (service in this.events[host]) {
158
+ e = this.events[host][service];
159
+ this.currentMax = Math.max(e.metric, this.currentMax || -1/0);
160
+ }
161
+ }
162
+ } else if (this.max === "host" ) {
163
+ this.currentMax = {};
164
+ for (host in this.events) {
165
+ for (service in this.events[host]) {
166
+ e = this.events[host][service];
167
+ this.currentMax[e.host] =
168
+ Math.max(e.metric, this.currentMax[e.host] || -1/0)
169
+ }
170
+ }
171
+ } else if (this.max === "service") {
172
+ this.currentMax = {};
173
+ for (host in this.events) {
174
+ for (service in this.events[host]) {
175
+ e = this.events[host][service];
176
+ this.currentMax[e.service] =
177
+ Math.max(e.metric, this.currentMax[e.service] || -1/0);
178
+ }
179
+ }
180
+ } else {
181
+ this.currentMax = this.max;
182
+ return false;
183
+ }
184
+
185
+ return true;
186
+ }
187
+
188
+ // Stores an event in the internal state tables. Returns true if we
189
+ // haven't seen this host/service before.
190
+ Grid.prototype.saveEvent = function(e) {
191
+ // Host list
192
+ if (this.hosts.indexOf(e.host) === -1) {
193
+ this.hosts.push(e.host);
194
+ this.hosts = _.uniq(this.hosts.sort(), true);
195
+ }
196
+
197
+ // Services list
198
+ if (this.services.indexOf(e.service) === -1) {
199
+ this.services.push(e.service);
200
+ this.services = _.uniq(this.services.sort(), true);
201
+ }
202
+
203
+ // Events map
204
+ if (this.events[e.host] === undefined) {
205
+ // New host
206
+ this.events[e.host] = {};
207
+ }
208
+ if (this.events[e.host][e.service] === undefined) {
209
+ // New event
210
+ var newEvent = true;
211
+ } else {
212
+ var newEvent = false;
213
+ }
214
+
215
+ // Store event
216
+ this.events[e.host][e.service] = e;
217
+
218
+ return newEvent;
219
+ }
220
+
221
+ // Add an event.
222
+ Grid.prototype.add = function(e) {
223
+ var newEvent = this.saveEvent(e);
224
+ var newMax = this.updateMax(e);
225
+
226
+ if (newEvent || newMax) {
227
+ this.render();
228
+ } else {
229
+ this.partialRender(e);
230
+ }
231
+ }
232
+
233
+ // Remove an event.
234
+ Grid.prototype.remove = function(e) {
235
+ delete this.events[e.host][e.service];
236
+ if (_.isEmpty(this.events[e.host])) {
237
+ delete this.events[e.host];
238
+ };
239
+
240
+ // Recompute hosts
241
+ this.hosts = _.keys(this.events).sort();
242
+
243
+ // Recompute services
244
+ var services = {};
245
+ for (var host in this.events) {
246
+ for (var service in this.events[host]) {
247
+ services[this.events[host][service].service] = true;
248
+ }
249
+ }
250
+ this.services = _.keys(services).sort();
251
+
252
+ this.updateMax();
253
+ this.render();
254
+ }
255
+
256
+ // Accept an event.
257
+ Grid.prototype.update = function(e) {
258
+ if (e.state === "expired") {
259
+ this.remove(e);
260
+ } else {
261
+ this.add(e);
262
+ }
263
+ }
264
+
265
+ Grid.prototype.reflow = function() {
266
+ this.el.find('table').height(
267
+ this.height() -
268
+ this.el.find('.title').height()
269
+ );
270
+ }
271
+
272
+ Grid.prototype.delete = function() {
273
+ if (this.sub != undefined) {
274
+ this.sub.close();
275
+ }
276
+ this.update = function() {};
277
+ view.View.prototype.delete.call(this);
278
+ }
279
+ })();
@@ -9,6 +9,7 @@
9
9
  "<p>To edit a view, hit e. Use enter, or click 'apply', to apply your changes. Escape cancels.</p>" +
10
10
  "<p>To save your changes to the server, press s. You can refresh the page, or press r to reload.</p>" +
11
11
  "<p>Make views bigger and smaller with the +/- keys. Pageup selects the parent of the current view. To delete a view, use the delete key.</p>" +
12
+ "<p>Switch between workspaces with alt-1, alt-2, etc.</p>" +
12
13
  "<p>My sincere apologies for layout jankiness. There are a few gross bugs and incapabilities in the current hstack/vstack system; if things get really bad, you can always edit ws/config.json on the server. The control scheme will probably change; I appreciate your ideas and patches.</p>" +
13
14
  '</div>'
14
15
  );
@@ -1,4 +1,4 @@
1
1
  module Riemann; end
2
2
  class Riemann::Dash
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end