-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
63 changed files
with
2,723 additions
and
683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
app/css/* | ||
app/*.js | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
app | ||
gulpfile.js | ||
wercker.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/** | ||
* Main JS controller for webapp | ||
*/ | ||
|
||
angular | ||
.module('app', [ | ||
'ngAnimate', | ||
'angularMoment', | ||
'LocalForageModule', | ||
'rt.popup' | ||
]) | ||
.controller('MainController', function MainController($scope, $injector) { | ||
var $sce = $injector.get('$sce') | ||
var $moment = $injector.get('moment') | ||
var $localForage = $injector.get('$localForage') | ||
var $window = $injector.get('$window') | ||
var $streamLines = $('.stream-lines') | ||
var BUFFER_SIZE = 100 | ||
var ctrl = this | ||
|
||
ctrl.paused = false | ||
ctrl.version = '<%= version %>' | ||
ctrl.lines = [] | ||
|
||
/** | ||
* Socket stuff | ||
*/ | ||
|
||
ctrl.socket = io(document.location.origin, { path: document.location.pathname + 'socket.io' }) | ||
|
||
ctrl.socket.on('streams', function (streams) { | ||
ctrl.streams = streams | ||
$scope.$apply() | ||
}) | ||
|
||
ctrl.socket.on('backlog', function (lines) { | ||
if (!lines) return | ||
ctrl.lines = lines.map(formatLine) | ||
$scope.$apply() | ||
updateScroll() | ||
console.info('%s: backlog received %d', ctrl.activeStream, lines.length) | ||
}) | ||
|
||
ctrl.socket.on('line', function (line) { | ||
ctrl.lines.push(formatLine(line)) | ||
|
||
if (ctrl.lines.length > BUFFER_SIZE) { | ||
ctrl.lines.length >= 100 && ctrl.lines.shift() | ||
} | ||
|
||
$scope.$apply() | ||
updateScroll() | ||
}) | ||
|
||
ctrl.selectStream = function selectStream(stream) { | ||
ctrl.activeStream = stream | ||
ctrl.socket.emit('select stream', stream) | ||
ctrl.resume() | ||
$localForage.setItem('activeStream', stream) | ||
} | ||
|
||
ctrl.isSelected = function isSelected(stream) { | ||
return ctrl.activeStream === stream | ||
} | ||
|
||
function updateScroll() { | ||
var where = ctrl.streamDirection ? $streamLines[0].scrollHeight : 0 | ||
$streamLines.scrollTop(where) | ||
} | ||
|
||
function formatLine(line) { | ||
if (!line.content) { | ||
// handle empty line | ||
line.html = $sce.trustAsHtml('') | ||
} else if ('object' === line.type) { | ||
// for object just format JSON | ||
line.html = hljs.highlight('json', JSON.stringify(line.content, null, ' ')).value | ||
line.html = $sce.trustAsHtml('<pre>' + line.html + '</pre>') | ||
} else { | ||
// for log lines use ansi format | ||
line.html = ansi_up.ansi_to_html(line.content, { use_classes: true }) | ||
line.html = $sce.trustAsHtml(line.html) | ||
} | ||
|
||
return line | ||
} | ||
|
||
ctrl.resume = function resume() { | ||
if (!ctrl.paused) return | ||
ctrl.paused = false | ||
ctrl.socket.emit('select stream', ctrl.activeStream) | ||
$streamLines.on('mousewheel', ctrl.pause) | ||
} | ||
|
||
ctrl.pause = function pause() { | ||
if (ctrl.paused) return | ||
ctrl.paused = true | ||
ctrl.socket.emit('select stream') | ||
$streamLines.off('mousewheel', ctrl.pause) | ||
$scope.$apply() | ||
} | ||
|
||
$streamLines.on('mousewheel', ctrl.pause) | ||
|
||
/** | ||
* Settings and preferences | ||
*/ | ||
|
||
ctrl.toggleFavorite = function toggleFavorite(stream) { | ||
if (ctrl.favorites[stream]) { | ||
delete ctrl.favorites[stream] | ||
} else { | ||
ctrl.favorites[stream] = true | ||
} | ||
|
||
$localForage.setItem('favorites', ctrl.favorites) | ||
} | ||
|
||
ctrl.setTheme = function setTheme(theme) { | ||
ctrl.theme = theme | ||
$localForage.setItem('theme', theme) | ||
} | ||
|
||
ctrl.setFontFamily = function setFontFamily(fontFamily) { | ||
ctrl.fontFamily = fontFamily | ||
$localForage.setItem('fontFamily', fontFamily) | ||
} | ||
|
||
ctrl.incFontSize = function incFontSize(fontSize) { | ||
ctrl.fontSize = Math.min(7, ctrl.fontSize + 1) | ||
$localForage.setItem('fontSize', ctrl.fontSize) | ||
} | ||
|
||
ctrl.resetFontSize = function resetFontSize() { | ||
ctrl.fontSize = 4 | ||
$localForage.setItem('fontSize', ctrl.fontSize) | ||
} | ||
|
||
ctrl.decFontSize = function decFontSize(fontSize) { | ||
ctrl.fontSize = Math.max(1, ctrl.fontSize - 1) | ||
$localForage.setItem('fontSize', fontSize) | ||
} | ||
|
||
ctrl.setStreamDirection = function setStreamDirection(streamDirection) { | ||
ctrl.streamDirection = streamDirection | ||
$localForage.setItem('streamDirection', streamDirection) | ||
} | ||
|
||
/** | ||
* Load storage in memory and boot | ||
*/ | ||
|
||
$localForage.getItem('theme').then(function (theme) { | ||
ctrl.theme = theme || 'dark' | ||
}) | ||
|
||
$localForage.getItem('fontFamily').then(function (fontFamily) { | ||
ctrl.fontFamily = fontFamily || 1 | ||
}) | ||
|
||
$localForage.getItem('fontSize').then(function (fontSize) { | ||
ctrl.fontSize = fontSize || 4 | ||
}) | ||
|
||
$localForage.getItem('favorites').then(function (favorites) { | ||
ctrl.favorites = favorites || {} | ||
}) | ||
|
||
$localForage.getItem('activeStream').then(function (activeStream) { | ||
if (!activeStream) return | ||
console.info('%s: restoring session', activeStream) | ||
ctrl.selectStream(activeStream) | ||
}) | ||
|
||
$localForage.getItem('streamDirection').then(function (streamDirection) { | ||
ctrl.streamDirection = undefined === streamDirection ? true : streamDirection | ||
}) | ||
|
||
/** | ||
* Tell UI we're ready to roll | ||
*/ | ||
|
||
ctrl.loaded = true | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.