Skip to content

Commit

Permalink
Closes #2178; Admin View Logs should auto-scroll to end
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Feb 29, 2016
1 parent 44c1a1d commit debb6d0
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 2 deletions.
3 changes: 2 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@
"Name_optional" : "Name (optional)",
"New_Application" : "New Application",
"New_integration" : "New integration",
"New_logs" : "New logs",
"New_messages" : "New messages",
"New_password" : "New password",
"No_channel_with_name_%s_was_found" : "No channel with name <strong>\"%s\"</strong> was found!",
Expand Down Expand Up @@ -460,9 +461,9 @@
"Push_gcm_api_key" : "GCM API Key",
"Push_gcm_project_number" : "GCM Project Number",
"Push_production" : "Production",
"Push_test_push" : "Test",
"Push_show_message" : "Show message in notification",
"Push_show_username_room" : "Show channel/group/username in notification",
"Push_test_push" : "Test",
"Quick_Search" : "Quick Search",
"quote" : "quote",
"Recents" : "Recents",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-logger/client/viewLogs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ FlowRouter.route '/admin/view-logs',
center: 'pageSettingsContainer'
pageTitle: t('View_Logs')
pageTemplate: 'viewLogs'
noScroll: true
81 changes: 81 additions & 0 deletions packages/rocketchat-logger/client/views/viewLogs.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Template.viewLogs.onCreated ->
@subscribe 'stdout'
@atBottom = true


Template.viewLogs.helpers
hasPermission: ->
Expand All @@ -15,3 +17,82 @@ Template.viewLogs.helpers

formatTS: (date) ->
return moment(date).format('YMMDD-HH:mm:ss.SSS(ZZ)')


Template.viewLogs.events
'click .new-logs': (e) ->
Template.instance().atBottom = true
Template.instance().sendToBottomIfNecessary()


Template.viewLogs.onRendered ->
wrapper = this.find('.terminal')
wrapperUl = this.find('.terminal')
newLogs = this.find('.new-logs')

template = this

template.isAtBottom = ->
if wrapper.scrollTop >= wrapper.scrollHeight - wrapper.clientHeight
newLogs.className = "new-logs not"
return true
return false

template.sendToBottom = ->
wrapper.scrollTop = wrapper.scrollHeight - wrapper.clientHeight
newLogs.className = "new-logs not"

template.checkIfScrollIsAtBottom = ->
template.atBottom = template.isAtBottom()
readMessage.enable()
readMessage.read()

template.sendToBottomIfNecessary = ->
if template.atBottom is true and template.isAtBottom() isnt true
template.sendToBottom()
else if template.atBottom is false
newLogs.className = "new-logs"

template.sendToBottomIfNecessaryDebounced = _.debounce template.sendToBottomIfNecessary, 10

template.sendToBottomIfNecessary()

if not window.MutationObserver?
wrapperUl.addEventListener 'DOMSubtreeModified', ->
template.sendToBottomIfNecessaryDebounced()
else
observer = new MutationObserver (mutations) ->
mutations.forEach (mutation) ->
template.sendToBottomIfNecessaryDebounced()

observer.observe wrapperUl,
childList: true

template.onWindowResize = ->
Meteor.defer ->
template.sendToBottomIfNecessaryDebounced()

window.addEventListener 'resize', template.onWindowResize

wrapper.addEventListener 'mousewheel', ->
template.atBottom = false
Meteor.defer ->
template.checkIfScrollIsAtBottom()

wrapper.addEventListener 'wheel', ->
template.atBottom = false
Meteor.defer ->
template.checkIfScrollIsAtBottom()

wrapper.addEventListener 'touchstart', ->
template.atBottom = false

wrapper.addEventListener 'touchend', ->
Meteor.defer ->
template.checkIfScrollIsAtBottom()
Meteor.setTimeout ->
template.checkIfScrollIsAtBottom()
, 1000
Meteor.setTimeout ->
template.checkIfScrollIsAtBottom()
, 2000
4 changes: 4 additions & 0 deletions packages/rocketchat-logger/client/views/viewLogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</div>
{{/each}}
</div>
<div class="new-logs not">
<i class="icon-down-big"></i>
<span>{{_ "New_logs"}}</span>
</div>
{{else}}
{{_ "Not_authorized"}}
{{/if}}
Expand Down
27 changes: 27 additions & 0 deletions packages/rocketchat-theme/assets/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
user-select: text;
}

.no-scroll {
overflow: hidden !important;
}

.page-settings, .page-settings * {
-webkit-user-select: text;
-moz-user-select: text;
Expand Down Expand Up @@ -4445,6 +4449,7 @@ a.github-fork {
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
margin-bottom: 0px !important;

* {
-webkit-user-select: text;
Expand All @@ -4462,6 +4467,28 @@ a.github-fork {
}
}

.new-logs {
margin: 0 -65px;
position: absolute;
border-radius: 20px;
width: 130px;
height: 30px;
text-align: center;
line-height: 30px;
font-size: 0.8em;
cursor: pointer;
bottom: 8px;
left: 50%;
background: #FFF;
color: #428bca;

.transition(transform 0.3s ease-out);
.transform(translateY(0));
&.not {
.transform(translateY(150%));
}
}

.powered-by {
margin-top: 1em;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2>
<span class="page-title">{{pageTitle}}</span>
</h2>
</head>
<div class="content">
<div class="content {{#if noScroll}}no-scroll{{/if}}">
{{> Template.dynamic template=pageTemplate}}
</div>
</section>
Expand Down

0 comments on commit debb6d0

Please sign in to comment.