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

Including tab for listing room uploaded files #955

Merged
merged 10 commits into from
Oct 3, 2015
Merged
1 change: 1 addition & 0 deletions client/routes/roomRoute.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ openRoom = (type, name) ->
RocketChat.TabBar.addButton({ id: 'members-list', title: t('User_Info'), icon: 'icon-user', template: 'membersList', order: 2 })
else
RocketChat.TabBar.addButton({ id: 'members-list', title: t('Members_List'), icon: 'icon-users', template: 'membersList', order: 2 })
RocketChat.TabBar.addButton({ id: 'uploaded-files-list', title: t('Room_uploaded_file_list'), icon: 'icon-download', template: 'uploadedFilesList', order: 3 })

# update user's room subscription
if ChatSubscription.findOne({rid: room._id})?.open is false
Expand Down
33 changes: 33 additions & 0 deletions client/views/app/tabBar/uploadedFilesList.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
roomFiles = new Mongo.Collection 'room_files'

Template.uploadedFilesList.helpers
files: ->
return roomFiles.find().fetch()

hasFiles: ->
return roomFiles.find().count() > 0

getFileIcon: (type) ->
if type.match(/^image\/.+$/)
return 'icon-picture'

return 'icon-docs'

customClassForFileType: ->
if this.type.match(/^image\/.+$/)
return 'room-files-swipebox'


Template.uploadedFilesList.events
'click .room-file-item': (e, t) ->
if $(e.currentTarget).siblings('.icon-picture').length
e.preventDefault()


Template.uploadedFilesList.onCreated ->
instance = this
this.autorun ->
instance.subscribe 'roomFiles', Session.get('openedRoom')

Template.uploadedFilesList.onRendered ->
$('.room-files-swipebox').swipebox()
25 changes: 25 additions & 0 deletions client/views/app/tabBar/uploadedFilesList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template name="uploadedFilesList">
<div class="content">
<div class="list-view">
<div class="status">
<h2>{{_ "Room_uploaded_file_list"}}</h2>
</div>
{{#if Template.subscriptionsReady}}
{{#if hasFiles }}
<ul class='list clearfix lines'>
{{#each files}}
<li>
<i class="{{getFileIcon type}}"></i>
<a title="{{name}}" href="{{url}}" target="_blank" class="room-file-item {{customClassForFileType}}">{{name}}</a>
</li>
{{/each}}
</ul>
{{else}}
<h2>{{_ "Room_uploaded_file_list_empty"}}</h2>
{{/if}}
{{else}}
<span>{{_ "Loading..."}}</span>
{{/if}}
</div>
</div>
</template>
2 changes: 2 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@
"Room_name_changed" : "Room name changed to: <em>__room_name__</em> by <em>__user_by__</em>",
"Room_name_changed_successfully" : "Room name changed successfully",
"Room_not_found" : "Room not found",
"Room_uploaded_file_list" : "Files list",
"Room_uploaded_file_list_empty" : "No files available.",
"room_user_count" : "%s users",
"Rooms" : "Rooms",
"Save" : "Save",
Expand Down
2 changes: 2 additions & 0 deletions i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
"Room_name_changed" : "Nome da sala alterado para: <em>__room_name__</em> por <em>__user_by__</em>",
"Room_name_changed_successfully" : "Nome da sala alterado com sucesso",
"Room_not_found" : "Sala não encontrada",
"Room_uploaded_file_list" : "Lista de arquivos",
"Room_uploaded_file_list_empty" : "Nenhum arquivo disponível",
"room_user_count" : "%s usuários",
"Rooms" : "Salas",
"Save" : "Salvar",
Expand Down
27 changes: 27 additions & 0 deletions server/publications/roomFiles.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Meteor.publish 'roomFiles', (rid) ->
unless this.userId
return this.ready()

console.log '[publish] roomFiles'.green, rid

pub = this

fileQuery =
rid: rid
complete: true
uploading: false

fileOptions =
fields:
_id: 1
name: 1
type: 1
url: 1

cursorFileListHandle = fileCollection.find(fileQuery, fileOptions).observeChanges
added: (_id, record) ->
pub.added('room_files', _id, record)

this.ready()
this.onStop ->
cursorFileListHandle.stop()