Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User administration; Statistics #530

Merged
merged 11 commits into from
Aug 21, 2015
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ yasaricli:slugify
yasinuslu:blaze-meta
rocketchat:colors
raix:push@2.6.13-rc.1
monbro:mongodb-mapreduce-aggregation
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mizzao:autocomplete@0.5.1
mizzao:timesync@0.3.3
mobile-status-bar@1.0.3
momentjs:moment@2.10.6
monbro:mongodb-mapreduce-aggregation@1.0.1
mongo@1.1.0
mongo-livedata@1.0.8
mrt:reactive-store@0.0.1
Expand Down
30 changes: 30 additions & 0 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ label.required:after {
&.meteor-developer {
background-color: #de4f4f;
}
&.button-block {
display: block;
width: 100%;
}
}

.sec-header {
Expand Down Expand Up @@ -2766,6 +2770,23 @@ a.github-fork {
}
}
}
.edit-form {
white-space: normal;
h3 {
font-size: 24px;
margin-bottom: 8px;
line-height: 22px;
}
p {
line-height: 18px;
font-size: 12px;
font-weight: 300;
color: @secondary-font-color;
}
> .input-line {
margin-top: 20px;
}
}
}

.user-image-status(@color) {
Expand Down Expand Up @@ -3451,6 +3472,15 @@ a.github-fork {
}
}

.statistics-table {
border: 1px solid black;
th, td {
border: 1px solid black;
text-align: left;
padding: 3px 10px;
}
}

.rocket-team {
display: block;
li {
Expand Down
38 changes: 37 additions & 1 deletion client/views/admin/adminStatistics.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
Template.adminStatistics.helpers
isAdmin: ->
return Meteor.user().admin is true
isReady: ->
return Template.instance().ready.get()
statistics: ->
return Template.instance().statistics.get()
inGB: (size) ->
if size > 1073741824
return _.numberFormat(size / 1024 / 1024 / 1024, 2) + ' GB'
return _.numberFormat(size / 1024 / 1024, 2) + ' MB'
humanReadable: (time) ->
days = Math.floor time / 86400
hours = Math.floor (time % 86400) / 3600
minutes = Math.floor ((time % 86400) % 3600) / 60
seconds = ((time % 86400) % 3600) % 60
out = ""
if days > 0
out += "#{days} #{TAPi18next.t 'project:days'}, "
if hours > 0
out += "#{hours} #{TAPi18next.t 'project:hours'}, "
if minutes > 0
out += "#{minutes} #{TAPi18next.t 'project:minutes'}, "
if seconds > 0
out += "#{seconds} #{TAPi18next.t 'project:seconds'}"
return out
numFormat: (number) ->
return _.numberFormat(number, 2)

Template.adminUsers.onRendered ->
Template.adminStatistics.onRendered ->
Tracker.afterFlush ->
SideNav.setFlex "adminFlex"
SideNav.openFlex()

Template.adminStatistics.onCreated ->
instance = @
@statistics = new ReactiveVar {}
@ready = new ReactiveVar false

Meteor.call 'generateStatistics', (error, statistics) ->
instance.ready.set true
if error
toastr.error error.reason
else
instance.statistics.set statistics
91 changes: 90 additions & 1 deletion client/views/admin/adminStatistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,96 @@ <h2>
{{#unless isAdmin}}
<p>You are not authorized to view this page.</p>
{{else}}

{{#if isReady}}
<table class="statistics-table">
<tr>
<th>{{_ "Stats_Total_Users"}}</th>
<td>{{statistics.totalUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Active_Users"}}</th>
<td>{{statistics.activeUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Non_Active_Users"}}</th>
<td>{{statistics.nonActiveUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Online_Users"}}</th>
<td>{{statistics.onlineUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Offline_Users"}}</th>
<td>{{statistics.offlineUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Total_Rooms"}}</th>
<td>{{statistics.totalRooms}}</td>
</tr>
<tr>
<th>{{_ "Stats_Total_Channels"}}</th>
<td>{{statistics.totalChannels}}</td>
</tr>
<tr>
<th>{{_ "Stats_Total_Private_Groups"}}</th>
<td>{{statistics.totalPrivateGroups}}</td>
</tr>
<tr>
<th>{{_ "Stats_Total_Direct_Messages"}}</th>
<td>{{statistics.totalDirect}}</td>
</tr>
<tr>
<th>{{_ "Stats_Max_Room_Users"}}</th>
<td>{{statistics.maxRoomUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Avg_Channel_Users"}}</th>
<td>{{numFormat statistics.avgChannelUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_Avg_Private_Group_Users"}}</th>
<td>{{numFormat statistics.avgPrivateGroupUsers}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Type"}}</th>
<td>{{statistics.os.type}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Platform"}}</th>
<td>{{statistics.os.platform}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Arch"}}</th>
<td>{{statistics.os.arch}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Release"}}</th>
<td>{{statistics.os.release}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Uptime"}}</th>
<td>{{humanReadable statistics.os.uptime}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Loadavg"}}</th>
<td>{{numFormat statistics.os.loadavg.[0]}}, {{numFormat statistics.os.loadavg.[1]}}, {{numFormat statistics.os.loadavg.[2]}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Totalmem"}}</th>
<td>{{inGB statistics.os.totalmem}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Freemem"}}</th>
<td>{{inGB statistics.os.freemem}}</td>
</tr>
<tr>
<th>{{_ "Stats_OS_Cpus"}}</th>
<td>{{statistics.os.cpus.length}}</td>
</tr>
</table>
{{else}}
{{_ "Please_wait_statistics"}}
{{/if}}
{{/unless}}
</div>
</section>
Expand Down
10 changes: 9 additions & 1 deletion client/views/admin/users/adminUserChannels.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Template.adminUserChannels.helpers
type: ->
return if @t is 'd' then 'at' else if @t is 'p' then 'lock' else 'hash'
return if @t is 'd' then 'at' else if @t is 'p' then 'lock' else 'hash'
route: ->
return switch @t
when 'd'
FlowRouter.path('direct', {username: @name})
when 'p'
FlowRouter.path('group', {name: @name})
when 'c'
FlowRouter.path('channel', {name: @name})
2 changes: 1 addition & 1 deletion client/views/admin/users/adminUserChannels.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="adminUserChannels">
<div class="user-info-channel">
<h3><a href="{{pathFor 'room' _id=rid}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
<h3><a href="{{route}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
</div>
</template>
35 changes: 35 additions & 0 deletions client/views/admin/users/adminUserEdit.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Template.adminUserEdit.helpers
email: ->
return @emails?[0]?.address

Template.adminUserEdit.events
'click .cancel': (e, t) ->
e.stopPropagation()
e.preventDefault()
t.cancel()

'click .save': (e, t) ->
e.stopPropagation()
e.preventDefault()
t.save()

Template.adminUserEdit.onCreated ->
instance = @

@cancel = ->
$('.user-info-content').hide()
$('#adminUserInfo').show()

@save = ->
userData = { _id: Template.currentData()._id }
userData.name = $("#name", ".edit-form").val()

unless userData._id and userData.name
toastr.error TAPi18next.t 'project:The_field_is_required', TAPi18next.t 'project:Name'
else
Meteor.call 'updateUser', userData, (error, result) ->
if result
toastr.success t('User_updated_successfully')
instance.cancel()
if error
toastr.error error.reason
15 changes: 15 additions & 0 deletions client/views/admin/users/adminUserEdit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template name="adminUserEdit">
<div class="about clearfix">
<form class="edit-form">
<h3>{{name}}</h3>
<div class="input-line">
<label for="name">{{_ "Name"}}</label>
<input type="text" id="name" autocomplete="off" value="{{name}}">
</div>
</form>
</div>
<nav>
<button class='button button-block cancel secondary'><span>{{_ "Cancel"}}</span></button>
<button class='button button-block blue save'><span>{{_ "Save"}}</span></button>
</nav>
</template>
36 changes: 33 additions & 3 deletions client/views/admin/users/adminUserInfo.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,45 @@ Template.adminUserInfo.helpers
return "UTC #{@utcOffset}"

Template.adminUserInfo.events
'click .deactivate': ->
'click .deactivate': (e) ->
e.stopPropagation()
e.preventDefault()
Meteor.call 'setUserActiveStatus', Template.currentData()._id, false, (error, result) ->
if result
toastr.success t('User_has_been_deactivated')
if error
toastr.error error.reason

'click .activate': ->
'click .activate': (e) ->
e.stopPropagation()
e.preventDefault()
Meteor.call 'setUserActiveStatus', Template.currentData()._id, true, (error, result) ->
if result
toastr.success t('User_has_been_activated')
if error
toastr.error error.reason

'click .make-admin': (e) ->
e.stopPropagation()
e.preventDefault()
Meteor.call 'setAdminStatus', Template.currentData()._id, true, (error, result) ->
if result
toastr.success t('User_is_now_an_admin')
if error
toastr.error error.reason

'click .remove-admin': (e) ->
e.stopPropagation()
e.preventDefault()
Meteor.call 'setAdminStatus', Template.currentData()._id, false, (error, result) ->
if result
toastr.success t('User_is_no_longer_an_admin')
if error
toastr.error error.reason

'click .delete': ->
'click .delete': (e) ->
e.stopPropagation()
e.preventDefault()
_id = Template.currentData()._id
swal {
title: t('Are_you_sure')
Expand All @@ -58,3 +82,9 @@ Template.adminUserInfo.events
if error
toastr.error error.reason

'click .edit-user': (e) ->
e.stopPropagation()
e.preventDefault()

$('.user-info-content').hide()
$('#user-edit-form').show()
12 changes: 9 additions & 3 deletions client/views/admin/users/adminUserInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ <h3>{{name}}</h3>
</div>
</div>
<nav>
<button class='button lightblue edit-user button-block'><span><i class='icon-edit'></i> {{_ "Edit"}}</span></button>
{{#if admin}}
<button class='button lightblue remove-admin button-block'><span><i class='icon-shield'></i> {{_ "Remove_Admin"}}</span></button>
{{else}}
<button class='button lightblue make-admin button-block'><span><i class='icon-shield'></i> {{_ "Make_Admin"}}</span></button>
{{/if}}
{{#if active}}
<button class='button deactivate'><span><i class='icon-block'></i> {{_ "Deactivate"}}</span></button>
<button class='button deactivate button-block'><span><i class='icon-block'></i> {{_ "Deactivate"}}</span></button>
{{else}}
<button class='button activate'><span><i class='icon-ok-circled'></i> {{_ "Activate"}}</span></button>
<button class='button activate button-block'><span><i class='icon-ok-circled'></i> {{_ "Activate"}}</span></button>
{{/if}}
<button class='button delete red'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
<button class='button delete red button-block'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
</nav>
</template>
Loading