Skip to content

Instantly share code, notes, and snippets.

@h4ck4life
Forked from ericf/logismo.js
Created September 10, 2013 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h4ck4life/6511782 to your computer and use it in GitHub Desktop.
Save h4ck4life/6511782 to your computer and use it in GitHub Desktop.
YUI.add('logismo', function(Y) {
/**
* Logismo
*/
var Logismo,
LOGISMO = 'logismo',
EVENTS_RESOURCE_PATH = 'eventsResourcePath',
VIEWS_COOKIE_NAME = 'viewsCookieName',
POLL_INTERVAL = 'pollInterval',
SCROLL_LOCKED = 'scrollLocked',
CHANGE = 'Change',
isString = Y.Lang.isString,
isNumber = Y.Lang.isNumber,
isBoolean = Y.Lang.isBoolean;
// *** Constructor *** //
Logismo = function (config) {
Logismo.superclass.constructor.apply(this, arguments);
};
// *** Static *** //
Y.mix(Logismo, {
NAME : LOGISMO,
ATTRS : {
eventsResourcePath : {
validator : isString,
writeOnce : true
},
viewsCookieName : {
value : 'views',
validator : isString,
writeOnce : true
},
pollInterval : {
value : 1000,
validator : isNumber
},
scrollLocked : {
value : false,
validator : isBoolean
}
}
});
// *** Prototype *** //
Y.extend(Logismo, Y.Base, {
// *** Instance Members *** //
_eventsResource : null,
_controlPanel : null,
_log : null,
// *** Base Methods *** //
initializer : function (config) {
if ( ! this.get(EVENTS_RESOURCE_PATH)) {
Y.error('A Logismo Window needs to be configured with: eventsResourcePath');
}
// Events Resource
this._eventsResource = Y.io.poll(this.get(POLL_INTERVAL), this.get(EVENTS_RESOURCE_PATH), {
method : 'DELETE',
headers : { Accept : 'application/json' },
context : this,
on : {
modified : this._onEventsResourceModified
}
});
// Control Panel
this._controlPanel = new Y.Logismo.ControlPanel({
polling : this._eventsResource.get('polling'),
scrollLocked : this.get(SCROLL_LOCKED)
});
this._controlPanel.addView(this.getSavedViews());
this._controlPanel.render('body');
// Log
this._log = new Y.Logismo.Log({
view : this._controlPanel.get('activeView')
}).render('body');
// *** Event Wiring *** //
this.after(POLL_INTERVAL+CHANGE, this._afterPollIntervalChange);
this.after(SCROLL_LOCKED+CHANGE, this._afterScrollLockedChange);
this._eventsResource.after('pollingChange', Y.bind(this._afterPollingChange, this));
this._controlPanel.on('lockScrollRequest', Y.bind(this.lockScroll, this));
this._controlPanel.on('unlockScrollRequest', Y.bind(this.unlockScroll, this));
this._controlPanel.on('pauseRequest', Y.bind(this._eventsResource.stop, this._eventsResource));
this._controlPanel.on('resumeRequest', Y.bind(this._eventsResource.start, this._eventsResource));
this._controlPanel.on('flushRequest', Y.bind(this._log.flush, this._log));
this._controlPanel.after('viewsUpdate', Y.bind(this._afterViewsUpdate, this));
this._controlPanel.after('activeViewChange', Y.bind(this._afterActiveViewChange, this));
this._log.on('renderedEvents', Y.bind(this._onLogRenderedEvents, this));
this._eventsResource.start();
},
destructor : function () {},
// *** Public Methods *** //
scrollIntoView : function () {
if ( ! this.get(SCROLL_LOCKED)) {
Y.one('body').scrollIntoView(this._log.get('newestOnTop'));
}
},
lockScroll : function () {
this.set(SCROLL_LOCKED, true);
},
unlockScroll : function () {
this.set(SCROLL_LOCKED, false);
},
getSavedViews : function () {
var viewCookies = Y.Cookie.getSubs(this.get(VIEWS_COOKIE_NAME)),
views = [];
if ( ! viewCookies) {
return null;
}
Y.Object.each(viewCookies, function(c){
views.push(this._cookieToViewConfig(c));
}, this);
return views;
},
setSavedViews : function (views) {
var cookieName = this.get(VIEWS_COOKIE_NAME),
viewCookies = Y.Cookie.getSubs(cookieName);
if (viewCookies) {
Y.Object.each(viewCookies, function (c, n){
Y.Cookie.removeSub(cookieName, n);
});
}
Y.Array.each(views, function(v){
Y.Cookie.setSub(cookieName, v.getId(), this._viewToCookieString(v));
}, this);
},
// *** Private Methods *** //
_cookieToViewConfig : function (cookie) {
var parts = cookie.split(','),
logExpression = parts[0],
logLevel = parts[1],
containingText = parts[2],
newestOnTop = parts[3],
expandAll = parts[4];
return {
logExpression : logExpression && logExpression.length > 0 ? logExpression : null,
logLevel : logLevel ? logLevel : null,
containingText : containingText && containingText.length > 0 ? containingText : null,
newestOnTop : newestOnTop === 'true' ? true : false,
expandAll : expandAll === 'true' ? true : false
};
},
_viewToCookieString : function (v) {
return (v.logExpressionToString()) + ',' +
(v.get('logLevel')) + ',' +
(v.get('containingText') || '') + ',' +
(v.get('newestOnTop') ? 'true' : 'false') + ',' +
(v.get('expandAll') ? 'true' : 'false');
},
_afterPollIntervalChange : function (e) {
this._eventsResource.set('interval', e.newVal);
},
_afterScrollLockedChange : function (e) {
this._controlPanel.set('scrollLocked', e.newVal);
},
_onEventsResourceModified : function (txId, r, args) {
var logEvents = Y.JSON.parse(r.responseText).logEvents;
this._log.addEvents(logEvents);
// this._controlPanel.addStat(logEvents.length);
},
_afterPollingChange : function (e) {
this._controlPanel.set('polling', e.newVal);
},
_afterViewsUpdate : function (e) {
this.setSavedViews(this._controlPanel.get('views'));
},
_afterActiveViewChange : function (e) {
Y.log('activeViewChange: '+ e.newVal, 'info', 'logismo');
this._log.set('view', e.newVal);
},
_onLogRenderedEvents : function (e) {
if (this._log.get('view')) {
if (e.taggedEvents && e.taggedEvents.length > 0) {
this.scrollIntoView();
}
} else {
this.scrollIntoView();
}
}
});
Y.namespace('Logismo');
Y.Logismo.Window = Logismo;
}, '@VERSION@' ,{requires:['base-base', 'controlpanel', 'log', 'view', 'io-poller', 'json-parse', 'cookie']});
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Logismo Web Viewer</title>
<link href="/utils/reset.css,base.css;-uq3jmregrvo4ubu6imlk5aq28" rel="stylesheet" type="text/css" />
<link href="/log/resources/log.css;-3e4ghcv7ef1difaj4aspv0n2pc" rel="stylesheet" type="text/css" />
</head>
<body class="yui-skin-sam">
<script src="http://localhost:8080/yui3/_v_3.0.0/yui/yui-min.js;3pql1ujvguv5ev77ri3l51q8t9" type="text/javascript">
</script>
<script type="text/javascript">
YUI({
"base": "http://localhost:8080/yui3/_v_3.0.0/",
"comboBase": "http://localhost:8080/yui3/_v_3.0.0/_combo?",
"root": "",
"combine": true,
"modules": {
"markout": {
"type": "js",
"fullpath": "http://localhost:8080/utils/markout/markout-min.js;2b2mdn9u9bc8gaml73s2i4vsqf",
"requires": ["dom-style", "selector-css2", "node-base"]
},
"io-poller": {
"type": "js",
"fullpath": "http://localhost:8080/utils/io-poller/io-poller-min.js;-2e1p0cv4bh8gd1uoslcn4kmfcg",
"requires": ["base", "io-base"]
},
"form": {
"type": "js",
"fullpath": "http://localhost:8080/utils/form/form-min.js;-2pcgmemmsb2jf98ch4f8o9olqd",
"requires": ["plugin", "node-base", "node-pluginhost", "node-event-delegate"]
},
"logevent": {
"type": "js",
"fullpath": "http://localhost:8080/log/resources/logevent/logevent-min.js;-14o4jc0qgi8uohjgt25fvolelc",
"requires": ["markout", "classnamemanager", "datatype-date"]
},
"view": {
"type": "js",
"fullpath": "http://localhost:8080/log/resources/view/view-min.js;-2hlv1vcp8cu8nm068tloomg3fk",
"requires": ["widget", "markout", "form"]
},
"controlpanel": {
"type": "js",
"fullpath": "http://localhost:8080/log/resources/controlpanel/controlpanel-min.js;-2cm6va6odus7oaj9i4lb1podu4",
"requires": ["widget", "view"]
},
"log": {
"type": "js",
"fullpath": "http://localhost:8080/log/resources/log/log-min.js;-2796q9d5eijbgaek73jc056r6g",
"requires": ["widget", "markout", "logevent", "view", "stylesheet"]
},
"logismo": {
"type": "js",
"fullpath": "http://localhost:8080/log/resources/logismo/logismo-min.js;-nv92605fkce8cb279i7im2kbr",
"requires": ["base-base", "controlpanel", "log", "view", "io-poller", "json-parse", "cookie"]
}
}
}).use('logismo', function(Y){
(new Y.Logismo.Window({
"eventsResourcePath": "events/"
}));
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment