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

Add multiple file/directory deletion in the filemanager #544

Merged
merged 15 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions public/themes/pterodactyl/css/pterodactyl.css
Expand Up @@ -295,3 +295,25 @@ input.form-autocomplete-stop[readonly] {
background: white;
box-shadow: none !important;
}

.dropdown-massactions {
min-width: 80px;
}

.select-all-files {
position: relative;
bottom: 1px;
margin-right: 7px !important;
}

.select-file {
position: relative;
bottom: 1px;
margin-right: 2px !important;
}

.select-folder {
position: relative;
bottom: 1px;
margin-right: 5px !important;
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

118 changes: 115 additions & 3 deletions public/themes/pterodactyl/js/frontend/files/src/actions.js
Expand Up @@ -292,12 +292,17 @@ class ActionsClass {
showLoaderOnConfirm: true
}, () => {
$.ajax({
type: 'DELETE',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/f/${delPath}${delName}`,
type: 'POST',
headers: {
'X-Access-Token': Pterodactyl.server.daemonSecret,
'X-Access-Server': Pterodactyl.server.uuid,
}
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/delete`,
timeout: 10000,
data: JSON.stringify({
items: [`${delPath}${delName}`]
}),
}).done(data => {
nameBlock.parent().addClass('warning').delay(200).fadeOut();
swal({
Expand All @@ -316,6 +321,113 @@ class ActionsClass {
});
}

toggleHighlight(event) {
const parent = $(event.target).closest('tr');

if(!$(event.target).is(':checked')) {
parent.removeClass('warning').delay(200);
} else {
parent.addClass('warning').delay(200);
}
}

highlightAll(event) {
let parent;

if(!$(event.target).is(':checked')) {
$('#file_listing input[type=checkbox]').prop('checked', false);
$('#file_listing input[data-action="addSelection"]').each(function() {
parent = $(this).closest('tr');
parent.removeClass('warning').delay(200);
});
} else {
$('#file_listing input[type=checkbox]').prop('checked', true);
$('#file_listing input[data-action="addSelection"]').each(function() {
parent = $(this).closest('tr');
parent.addClass('warning').delay(200);
});
}
}

deleteSelected() {
let selectedItems = [];
let selectedItemsElements = [];
let parent;
let nameBlock;
let delLocation;

$('#file_listing input[data-action="addSelection"]:checked').each(function() {
parent = $(this).closest('tr');
nameBlock = $(parent).find('td[data-identifier="name"]');
delLocation = decodeURIComponent(nameBlock.data('path')) + decodeURIComponent(nameBlock.data('name'));

selectedItems.push(delLocation);
selectedItemsElements.push(parent);
});

if (selectedItems.length != 0)
{
let formattedItems = "";
$.each(selectedItems, function(key, value) {
formattedItems += ("<code>" + value + "</code>, ");
})

formattedItems = formattedItems.slice(0, -2);

swal({
type: 'warning',
title: '',
text: 'Are you sure you want to delete:' + formattedItems + '? There is <strong>no</strong> reversing this action.',
html: true,
showCancelButton: true,
showConfirmButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true
}, () => {
$.ajax({
type: 'POST',
headers: {
'X-Access-Token': Pterodactyl.server.daemonSecret,
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/delete`,
timeout: 10000,
data: JSON.stringify({
items: selectedItems
}),
}).done(data => {
$('#file_listing input:checked').each(function() {
$(this).prop('checked', false);
});

$.each(selectedItemsElements, function() {
$(this).addClass('warning').delay(200).fadeOut();
})

swal({
type: 'success',
title: 'Files Deleted'
});
}).fail(jqXHR => {
console.error(jqXHR);
swal({
type: 'error',
title: 'Whoops!',
html: true,
text: 'An error occured while attempting to delete these files. Please try again.',
});
});
});
} else {
swal({
type: 'warning',
title: '',
text: 'Please select files/folders to delete.',
});
}
}

decompress() {
const nameBlock = $(this.element).find('td[data-identifier="name"]');
const compPath = decodeURIComponent(nameBlock.data('path'));
Expand Down
21 changes: 21 additions & 0 deletions public/themes/pterodactyl/js/frontend/files/src/index.js
Expand Up @@ -45,6 +45,9 @@ class FileManager {
ContextMenu.run();
this.reloadFilesButton();
this.addFolderButton();
this.selectItem();
this.selectAll();
this.selectiveDeletion();
if (_.isFunction(next)) {
return next();
}
Expand Down Expand Up @@ -83,6 +86,24 @@ class FileManager {
});
}

selectItem() {
$('[data-action="addSelection"]').on('change', event => {
new ActionsClass().toggleHighlight(event);
});
}

selectAll() {
$('[data-action="selectAll"]').on('change', event => {
new ActionsClass().highlightAll(event);
});
}

selectiveDeletion() {
$('[data-action="selective-deletion"]').on('mousedown', event => {
new ActionsClass().deleteSelected();
});
}

addFolderButton() {
$('[data-action="add-folder"]').unbind().on('click', () => {
new ActionsClass().folder($('#file_listing').data('current-dir') || '/');
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/server.php
Expand Up @@ -213,6 +213,8 @@
'last_modified' => 'Last Modified',
'add_new' => 'Add New File',
'add_folder' => 'Add New Folder',
'mass_actions' => 'Mass actions',
'delete' => 'Delete',
'edit' => [
'header' => 'Edit File',
'header_sub' => 'Make modifications to a file from the web.',
Expand Down
22 changes: 15 additions & 7 deletions resources/themes/pterodactyl/server/files/list.blade.php
Expand Up @@ -21,6 +21,14 @@
<div class="box-header with-border">
<h3 class="box-title">/home/container{{ $directory['header'] }}</h3>
<div class="box-tools pull-right">
<div class="btn-group">
<button type="button" class="btn btn-sm btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@lang('server.files.mass_actions') <span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-massactions">
<li><a href="#" id="selective-deletion" data-action="selective-deletion">@lang('server.files.delete') <i class="fa fa-fw fa-trash-o"></i></a></li>
</ul>
</div>
<button class="btn btn-sm btn-success btn-icon" data-action="add-folder">
<i class="fa fa-fw fa-folder-open-o"></i>
</button>
Expand All @@ -38,13 +46,13 @@
<table class="table table-hover" id="file_listing" data-current-dir="{{ $directory['header'] }}">
<thead>
<tr>
<th style="width:2%;" class="middle text-center">
<i class="fa fa-refresh muted muted-hover use-pointer" data-action="reload-files" style="font-size:14px;"></i>
<th style="width:4%;" class="middle">
<input type="checkbox" class="select-all-files" data-action="selectAll"><i class="fa fa-refresh muted muted-hover use-pointer" data-action="reload-files" style="font-size:14px;"></i>
</th>
<th style="width:55%">@lang('server.files.file_name')</th>
<th style="width:15%" class="hidden-xs">@lang('server.files.size')</th>
<th style="width:20%" class="hidden-xs">@lang('server.files.last_modified')</th>
<th style="width:8%"></th>
<th style="width:6%"></th>
</tr>
</thead>
<tbody id="append_files_to">
Expand All @@ -70,7 +78,7 @@
@endif
@foreach ($folders as $folder)
<tr data-type="folder">
<td data-identifier="type" class="middle"><i class="fa fa-folder" style="margin-left: 0.859px;"></i></td>
<td data-identifier="type" class="middle"><input type="checkbox" class="select-folder" data-action="addSelection"><i class="fa fa-folder" style="margin-left: 0.859px;"></i></td>
<td data-identifier="name" data-name="{{ rawurlencode($folder['entry']) }}" data-path="@if($folder['directory'] !== ''){{ rawurlencode($folder['directory']) }}@endif/">
<a href="/server/{{ $server->uuidShort }}/files" data-action="directory-view">{{ $folder['entry'] }}</a>
</td>
Expand All @@ -85,12 +93,12 @@
{{ $carbon->diffForHumans() }}
@endif
</td>
<td><button class="btn btn-xxs btn-default disable-menu-hide" data-action="toggleMenu" style="padding:2px 6px 0px;"><i class="fa fa-ellipsis-h disable-menu-hide"></i></button></td>
<td><button class="btn btn-xxs btn-default disable-menu-hide" data-action="toggleMenu" style="padding:2px 6px 0px;"><i class="fa fa-ellipsis-h disable-menu-hide"></i></td>
</tr>
@endforeach
@foreach ($files as $file)
<tr data-type="file" data-mime="{{ $file['mime'] }}">
<td data-identifier="type" class="middle">
<td data-identifier="type" class="middle"><input type="checkbox" class="select-file" data-action="addSelection">
{{-- oh boy --}}
@if(in_array($file['mime'], [
'application/x-7z-compressed',
Expand Down Expand Up @@ -162,7 +170,7 @@
{{ $carbon->diffForHumans() }}
@endif
</td>
<td><button class="btn btn-xxs btn-default disable-menu-hide" data-action="toggleMenu" style="padding:2px 6px 0px;"><i class="fa fa-ellipsis-h disable-menu-hide"></i></button></td>
<td><button class="btn btn-xxs btn-default disable-menu-hide" data-action="toggleMenu" style="padding:2px 6px 0px;"><i class="fa fa-ellipsis-h disable-menu-hide"></i></td>
</tr>
@endforeach
</tbody>
Expand Down