Skip to content

Commit eca4e61

Browse files
committed
Add file/folder create support from dropdown menu
closes pterodactyl#126
1 parent 1d747ec commit eca4e61

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
66
## v0.5.0-pre.2 (Bodacious Boreopterus)
77

88
### Added
9-
* Adds support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
9+
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
10+
* Added support for creating new files and folders directly from the right-click dropdown menu.
1011

1112
### Changed
1213
* Support for sub-folders within the `getJavascript()` route for servers.

resources/views/server/files/list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<th style="width:15%">Size</th>
2626
<th style="width:20%">Last Modified</th>
2727
</tr>
28-
<tr>
28+
<tr id="headerTableRow" data-currentdir="{{ $directory['header'] }}">
2929
<th><i class="fa fa-folder-open"></i></th>
3030
<th colspan="3">
3131
<code>/home/container{{ $directory['header'] }}</code>

resources/views/server/js/filemanager/actions.blade.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,55 @@ class ActionsClass {
2929
this.element = undefined;
3030
}
3131

32+
folder() {
33+
const nameBlock = $(this.element).find('td[data-identifier="name"]');
34+
const currentName = decodeURIComponent(nameBlock.attr('data-name'));
35+
const currentPath = decodeURIComponent(nameBlock.data('path'));
36+
37+
let inputValue = `${currentPath}${currentName}/`;
38+
if ($(this.element).data('type') === 'file') {
39+
inputValue = currentPath;
40+
}
41+
swal({
42+
type: 'input',
43+
title: 'Create Folder',
44+
text: 'Please enter the path and folder name below.',
45+
showCancelButton: true,
46+
showConfirmButton: true,
47+
closeOnConfirm: false,
48+
showLoaderOnConfirm: true,
49+
inputValue: inputValue
50+
}, (val) => {
51+
$.ajax({
52+
type: 'POST',
53+
headers: {
54+
'X-Access-Token': '{{ $server->daemonSecret }}',
55+
'X-Access-Server': '{{ $server->uuid }}'
56+
},
57+
contentType: 'application/json; charset=utf-8',
58+
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/file/folder',
59+
timeout: 10000,
60+
data: JSON.stringify({
61+
path: val,
62+
}),
63+
}).done(data => {
64+
swal.close();
65+
Files.list();
66+
}).fail(jqXHR => {
67+
console.error(jqXHR);
68+
var error = 'An error occured while trying to process this request.';
69+
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
70+
error = jqXHR.responseJSON.error;
71+
}
72+
swal({
73+
type: 'error',
74+
title: '',
75+
text: error,
76+
});
77+
});
78+
});
79+
}
80+
3281
move() {
3382
const nameBlock = $(this.element).find('td[data-identifier="name"]');
3483
const currentName = decodeURIComponent(nameBlock.attr('data-name'));

resources/views/server/js/filemanager/contextmenu.blade.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,27 @@ class ContextMenuClass {
2929
this.rightClick();
3030
}
3131

32-
makeMenu() {
32+
makeMenu(parent) {
3333
$(document).find('#fileOptionMenu').remove();
3434
if (!_.isNull(this.activeLine)) this.activeLine.removeClass('active');
35+
36+
let newFilePath = $('#headerTableRow').attr('data-currentDir');
37+
if (parent.data('type') === 'folder') {
38+
const nameBlock = parent.find('td[data-identifier="name"]');
39+
const currentName = decodeURIComponent(nameBlock.attr('data-name'));
40+
const currentPath = decodeURIComponent(nameBlock.data('path'));
41+
newFilePath = `${currentPath}${currentName}`;
42+
}
3543
return '<ul id="fileOptionMenu" class="dropdown-menu" role="menu" style="display:none" > \
3644
<li data-action="move"><a tabindex="-1" href="#"><i class="fa fa-arrow-right"></i> Move</a></li> \
3745
<li data-action="copy"><a tabindex="-1" href="#"><i class="fa fa-clone"></i> Copy</a></li> \
3846
<li data-action="rename"><a tabindex="-1" href="#"><i class="fa fa-pencil-square-o"></i> Rename</a></li> \
3947
<li data-action="compress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-file-archive-o"></i> Compress</a></li> \
4048
<li data-action="decompress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-expand"></i> Decompress</a></li> \
4149
<li class="divider"></li> \
50+
<li data-action="file"><a href="/server/{{ $server->uuidShort }}/files/add/?dir=' + newFilePath + '" class="text-muted"><i class="fa fa-plus"></i> New File</a></li> \
51+
<li data-action="folder"><a tabindex="-1" href="#"><i class="fa fa-folder"></i> New Folder</a></li> \
52+
<li class="divider"></li> \
4253
<li data-action="download" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-download"></i> Download</a></li> \
4354
<li data-action="delete" class="bg-danger"><a tabindex="-1" href="#"><i class="fa fa-trash-o"></i> Delete</a></li> \
4455
</ul>';
@@ -48,7 +59,7 @@ class ContextMenuClass {
4859
$('#file_listing > tbody td').on('contextmenu', event => {
4960

5061
const parent = $(event.target).closest('tr');
51-
const menu = $(this.makeMenu());
62+
const menu = $(this.makeMenu(parent));
5263

5364
if (parent.data('type') === 'disabled') return;
5465
event.preventDefault();
@@ -102,6 +113,11 @@ class ContextMenuClass {
102113
Actions.decompress();
103114
});
104115

116+
$(menu).find('li[data-action="folder"]').unbind().on('click', e => {
117+
e.preventDefault();
118+
Actions.folder();
119+
});
120+
105121
$(menu).find('li[data-action="download"]').unbind().on('click', e => {
106122
e.preventDefault();
107123
Actions.download();

0 commit comments

Comments
 (0)