Skip to content

Commit

Permalink
Fixes #691; Adds sorting to channels list.
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloschmidt committed Mar 7, 2016
1 parent a1f0e8c commit bf87abd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Makes channels list load faster by not getting full channel data, such as usernames.
- Fixes #2399. Fixes bug with highlighted words which allowed an empty string to be defined as highlight.
- Fix #766; Disable E-mail Confirmation setting when SMTP is not set.
- Closes #691; Adds sorting to channels list.

## 0.20.0, 2016-Feb-29

Expand Down
1 change: 1 addition & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
"Not_found_or_not_allowed" : "Not Found or Not Allowed",
"Nothing_found" : "Nothing found",
"Notify_all_in_this_room" : "Notify all in this room",
"Number_of_messages" : "Number of messages",
"OAuth_Application" : "OAuth Application",
"OAuth_Applications" : "OAuth Applications",
"Offline_DM_Email" : "[__site__] You have been direct messaged by __user__",
Expand Down
24 changes: 13 additions & 11 deletions packages/rocketchat-theme/assets/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -1240,26 +1240,28 @@ a.github-fork {

.flex-control {
.search {
display: table;
width: 100%;
margin-bottom: 10px;
}
.sort {
display: table;
width: 100%;
margin-bottom: 30px;
position: relative;

.sort-item {
display: table-cell;
vertical-align: middle;
text-align: center;
position: relative;
padding-right: 5px;
i {
display: inline-block;
}

&:first {
width: 1px;
}
select {
display: inline-block;
width: calc(@rooms-box-width - 76px);
margin-left: 10px;
border: none;
border-radius: 0;
border-bottom: 1px solid rgba(255,255,255,0.6);
color: rgba(255,255,255,0.85);
-webkit-appearance: none;
background-size: 8px 10px;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Template.listChannelsFlex.helpers
return Template.instance().hasMore.get()
tSearchChannels: ->
return t('Search_Channels')
sortSelected: (sort) ->
return Template.instance().sort.get() is sort

Template.listChannelsFlex.events
'click header': ->
Expand Down Expand Up @@ -32,14 +34,18 @@ Template.listChannelsFlex.events
instance.nameFilter.set($(e.currentTarget).val())
, 300

'change #sort': (e, instance) ->
instance.sort.set($(e.currentTarget).val())

Template.listChannelsFlex.onCreated ->
@channelsList = new ReactiveVar []
@hasMore = new ReactiveVar true
@limit = new ReactiveVar 50
@nameFilter = new ReactiveVar ''
@sort = new ReactiveVar 'msgs'

@autorun =>
Meteor.call 'channelsList', @nameFilter.get(), @limit.get(), (err, result) =>
Meteor.call 'channelsList', @nameFilter.get(), @limit.get(), @sort.get(), (err, result) =>
if result
@hasMore.set true
@channelsList.set result.channels
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-ui-sidenav/side-nav/listChannelsFlex.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ <h4>{{_ "Channels"}}</h4>
</div>
</form>
</div>
<div class="sort">
<i class="icon-sort-alt-up"></i>
<select class="c-select" id="sort">
<option value="name" selected="{{sortSelected 'name'}}">{{_ "Name"}}</option>
<option value="msgs" selected="{{sortSelected 'msgs'}}">{{_ "Number_of_messages"}}</option>
</select>
</div>
</div>
<h4>{{_ "Channels_list"}}</h4>
<ul>
Expand Down
9 changes: 7 additions & 2 deletions server/methods/channelsList.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
Meteor.methods
channelsList: (filter, limit) ->
channelsList: (filter, limit, sort) ->
options = { fields: { name: 1 }, sort: { msgs:-1 } }
if _.isNumber limit
options.limit = limit
if _.trim(sort)
switch sort
when 'name'
options.sort = { name: 1 }
when 'msgs'
options.sort = { msgs: -1 }

if filter
options.sort = { name: 1 }
return { channels: RocketChat.models.Rooms.findByNameContainingAndTypes(filter, ['c'], options).fetch() }
else
return { channels: RocketChat.models.Rooms.findByTypeAndArchivationState('c', false, options).fetch() }

0 comments on commit bf87abd

Please sign in to comment.