Skip to content

Commit

Permalink
converted Rocketchat logger coffee to js (#6495)
Browse files Browse the repository at this point in the history
* conversion coffee to js

* removed coffee files

* Update server.js
  • Loading branch information
ggazzo authored and rodrigok committed Mar 29, 2017
1 parent bc5878a commit 343f3eb
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 553 deletions.
17 changes: 0 additions & 17 deletions packages/rocketchat-logger/client/viewLogs.coffee

This file was deleted.

24 changes: 24 additions & 0 deletions packages/rocketchat-logger/client/viewLogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

this.stdout = new Mongo.Collection('stdout');

Meteor.startup(function() {
return RocketChat.AdminBox.addOption({
href: 'admin-view-logs',
i18nLabel: 'View_Logs',
permissionGranted() {
return RocketChat.authz.hasAllPermission('view-logs');
}
});
});

FlowRouter.route('/admin/view-logs', {
name: 'admin-view-logs',
action() {
return BlazeLayout.render('main', {
center: 'pageSettingsContainer',
pageTitle: t('View_Logs'),
pageTemplate: 'viewLogs',
noScroll: true
});
}
});
106 changes: 0 additions & 106 deletions packages/rocketchat-logger/client/views/viewLogs.coffee

This file was deleted.

124 changes: 124 additions & 0 deletions packages/rocketchat-logger/client/views/viewLogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import moment from 'moment';
// TODO: remove this globals
/* globals ansispan stdout readMessage*/

Template.viewLogs.onCreated(function() {
this.subscribe('stdout');
return this.atBottom = true;
});

Template.viewLogs.helpers({
hasPermission() {
return RocketChat.authz.hasAllPermission('view-logs');
},
logs() {
return stdout.find({}, {
sort: {
ts: 1
}
});
},
ansispan(string) {
string = ansispan(string.replace(/\s/g, '&nbsp;').replace(/(\\n|\n)/g, '<br>'));
string = string.replace(/(.\d{8}-\d\d:\d\d:\d\d\.\d\d\d\(?.{0,2}\)?)/, '<span class="terminal-time">$1</span>');
return string;
},
formatTS(date) {
return moment(date).format('YMMDD-HH:mm:ss.SSS(ZZ)');
}
});

Template.viewLogs.events({
'click .new-logs'() {
Template.instance().atBottom = true;
return Template.instance().sendToBottomIfNecessary();
}
});

Template.viewLogs.onRendered(function() {

const wrapper = this.find('.terminal');
const wrapperUl = this.find('.terminal');
const newLogs = this.find('.new-logs');
const template = this;
template.isAtBottom = function(scrollThreshold) {
if (scrollThreshold == null) {
scrollThreshold = 0;
}
if (wrapper.scrollTop + scrollThreshold >= wrapper.scrollHeight - wrapper.clientHeight) {
newLogs.className = 'new-logs not';
return true;
}
return false;
};
template.sendToBottom = function() {
wrapper.scrollTop = wrapper.scrollHeight - wrapper.clientHeight;
return newLogs.className = 'new-logs not';
};
template.checkIfScrollIsAtBottom = function() {
template.atBottom = template.isAtBottom(100);
readMessage.enable();
return readMessage.read();
};
template.sendToBottomIfNecessary = function() {
if (template.atBottom === true && template.isAtBottom() !== true) {
return template.sendToBottom();
} else if (template.atBottom === false) {
return newLogs.className = 'new-logs';
}
};
template.sendToBottomIfNecessaryDebounced = _.debounce(template.sendToBottomIfNecessary, 10);
template.sendToBottomIfNecessary();
if (window.MutationObserver == null) {
wrapperUl.addEventListener('DOMSubtreeModified', function() {
return template.sendToBottomIfNecessaryDebounced();
});
} else {
const observer = new MutationObserver(function(mutations) {
return mutations.forEach(function() {
return template.sendToBottomIfNecessaryDebounced();
});
});
observer.observe(wrapperUl, {
childList: true
});
}
template.onWindowResize = function() {
return Meteor.defer(function() {
return template.sendToBottomIfNecessaryDebounced();
});
};
window.addEventListener('resize', template.onWindowResize);
wrapper.addEventListener('mousewheel', function() {
template.atBottom = false;
return Meteor.defer(function() {
return template.checkIfScrollIsAtBottom();
});
});
wrapper.addEventListener('wheel', function() {
template.atBottom = false;
return Meteor.defer(function() {
return template.checkIfScrollIsAtBottom();
});
});
wrapper.addEventListener('touchstart', function() {
return template.atBottom = false;
});
wrapper.addEventListener('touchend', function() {
Meteor.defer(function() {
return template.checkIfScrollIsAtBottom();
});
Meteor.setTimeout(function() {
return template.checkIfScrollIsAtBottom();
}, 1000);
return Meteor.setTimeout(function() {
return template.checkIfScrollIsAtBottom();
}, 2000);
});
return wrapper.addEventListener('scroll', function() {
template.atBottom = false;
return Meteor.defer(function() {
return template.checkIfScrollIsAtBottom();
});
});
});
73 changes: 0 additions & 73 deletions packages/rocketchat-logger/logger.coffee

This file was deleted.

Loading

0 comments on commit 343f3eb

Please sign in to comment.