Skip to content

Commit

Permalink
Implement the delete all files
Browse files Browse the repository at this point in the history
Plus an indicator of hoy much files are displayed
  • Loading branch information
danilomiranda committed Jul 1, 2017
1 parent b618894 commit 176781a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 45 deletions.
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@
"Yes_unarchive_it": "Yes, unarchive it!",
"Yes_clear_all": "Yes, clear all!",
"Yes_delete_it": "Yes, delete it!",
"Yes_delete_all_it": "Yes, delete all it!",
"Yes_hide_it": "Yes, hide it!",
"Yes_leave_it": "Yes, leave it!",
"Yes_mute_user": "Yes, mute user!",
Expand Down Expand Up @@ -1716,10 +1717,12 @@
"You_should_name_it_to_easily_manage_your_integrations": "You should name it to easily manage your integrations.",
"You_will_not_be_able_to_recover": "You will not be able to recover this message!",
"You_will_not_be_able_to_recover_file": "You will not be able to recover this file!",
"You_will_not_be_able_to_recover_all_files": "You will not be able to recover all files!",
"You_wont_receive_email_notifications_because_you_have_not_verified_your_email": "You won't receive email notifications because you have not verified your email.",
"Your_email_has_been_queued_for_sending": "Your email has been queued for sending",
"Your_entry_has_been_deleted": "Your entry has been deleted.",
"Your_file_has_been_deleted": "Your file has been deleted.",
"Your_files_are_been_deleted": "Your files are been deleted.",
"Your_mail_was_sent_to_s": "Your mail was sent to %s",
"your_message": "your message",
"your_message_optional": "your message (optional)",
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-theme/client/imports/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -3264,7 +3264,7 @@ body:not(.is-cordova) {
font-weight: 600;
}

& .see-all {
& .see-all, & .delete-all {
float: right;
border-width: 0;
text-decoration: underline;
Expand Down
68 changes: 41 additions & 27 deletions packages/rocketchat-ui-flextab/client/tabs/uploadedFilesList.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
<template name="uploadedFilesList">
<div class="content">
<div class="list-view uploaded-files-list">
<div class="title">
<h2>{{_ "Room_uploaded_file_list"}}</h2>
</div>
<ul class="list clearfix lines">
{{#each files}}
<li>
{{#if canDelete}}
<i class="icon-trash file-delete"></i>
{{#with uploadedFiles}}
<div class="title">
<h2>{{_ "Room_uploaded_file_list"}}</h2>
{{#if Template.subscriptionsReady}}
{{#unless files}}
{{else}}
<p>
Showing: {{totalFiles}} files
{{#if showDeleteAll}}
<button class="delete-all icon-trash">Delete All</button>
{{/if}}
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="file-download" download="">
<i class="icon-download file-download"></i>
</a>
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="room-file-item file-name {{customClassForFileType}}">
<i class="{{getFileIcon type}}"></i>
<p>{{name}}</p>
</a>
</li>
{{/each}}
</ul>
{{#if hasMore}}
<div class="load-more">
{{> loading}}
</p>

{{/unless}}
{{/if}}
</div>
{{/if}}
{{#if Template.subscriptionsReady}}
{{#unless hasFiles}}
<h2>{{_ "Room_uploaded_file_list_empty"}}</h2>
{{/unless}}
{{/if}}
<ul class="list clearfix lines">
{{#each files}}
<li>
{{#if canDelete}}
<i class="icon-trash file-delete"></i>
{{/if}}
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="file-download" download="">
<i class="icon-download file-download"></i>
</a>
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="room-file-item file-name {{customClassForFileType}}">
<i class="{{getFileIcon type}}"></i>
<p>{{name}}</p>
</a>
</li>
{{/each}}
</ul>
{{#if hasMore}}
<div class="load-more">
{{> loading}}
</div>
{{/if}}
{{#if Template.subscriptionsReady}}
{{#unless files}}
<h2>{{_ "Room_uploaded_file_list_empty"}}</h2>
{{/unless}}
{{/if}}
{{/with}}
</div>
</div>
</template>
61 changes: 44 additions & 17 deletions packages/rocketchat-ui-flextab/client/tabs/uploadedFilesList.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
/* globals chatMessages*/
const roomFiles = new Mongo.Collection('room_files');

const removeFiles = (upload, msg) => {
RocketChat.models.Uploads.remove(upload._id, function() {
if (msg) {
return chatMessages[Session.get('openedRoom')].deleteMsg(msg);
} else {
return Meteor.call('deleteFileMessage', upload._id, function(error) {
if (error) {
return handleError(error);
}
});
}
});
};

Template.uploadedFilesList.helpers({
files() {
return roomFiles.find({ rid: this.rid }, { sort: { uploadedAt: -1 } });

uploadedFiles() {
const files = roomFiles.find({ rid: this.rid }, { sort: { uploadedAt: -1 } });
const totalFiles = files.count();
const showDeleteAll = totalFiles > 1 ;
return {
totalFiles,
showDeleteAll,
files
};
},

hasFiles() {
Expand Down Expand Up @@ -74,38 +96,43 @@ Template.uploadedFilesList.events({

'click .icon-trash'() {
const self = this;
const deleteText = self._id ?
TAPi18n.__('You_will_not_be_able_to_recover_file') :
TAPi18n.__('You_will_not_be_able_to_recover_all_files');
const deleteConfirm = self._id ?
TAPi18n.__('Yes_delete_it') :
TAPi18n.__('Yes_delete_all_it');
const successText = self._id ?
TAPi18n.__('Your_file_has_been_deleted') :
TAPi18n.__('Your_files_are_been_deleted');
return swal({
title: TAPi18n.__('Are_you_sure'),
text: TAPi18n.__('You_will_not_be_able_to_recover_file'),
text: deleteText,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: TAPi18n.__('Yes_delete_it'),
confirmButtonText: deleteConfirm,
cancelButtonText: TAPi18n.__('Cancel'),
closeOnConfirm: false,
html: false
}, function() {
swal({
title: TAPi18n.__('Deleted'),
text: TAPi18n.__('Your_file_has_been_deleted'),
text: successText,
type: 'success',
timer: 1000,
showConfirmButton: false
});

// Check if the upload message for this file is currently loaded
const msg = ChatMessage.findOne({ file: { _id: self._id } });
return RocketChat.models.Uploads.remove(self._id, function() {
if (msg) {
return chatMessages[Session.get('openedRoom')].deleteMsg(msg);
} else {
return Meteor.call('deleteFileMessage', self._id, function(error) {
if (error) {
return handleError(error);
}
});
}
});
if (!self._id) {

self.files.map((file) => {
return removeFiles(file, msg);
});
} else {
return removeFiles(self, msg);
}
});
},

Expand Down

0 comments on commit 176781a

Please sign in to comment.