Skip to content

Commit 4d922b6

Browse files
committed
Clean up file adding and listing
1 parent 81dc74a commit 4d922b6

File tree

2 files changed

+75
-50
lines changed

2 files changed

+75
-50
lines changed

app/Http/Controllers/Server/AjaxController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ public function postDirectoryList(Request $request, $uuid)
115115

116116
// Determine if we should show back links in the file browser.
117117
// This code is strange, and could probably be rewritten much better.
118-
$goBack = explode('/', rtrim($this->directory, '/'));
119-
if (isset($goBack[2]) && !empty($goBack[2])) {
118+
$goBack = explode('/', trim($this->directory, '/'));
119+
if (!empty(array_filter($goBack)) && count($goBack) >= 2) {
120120
$prevDir['show'] = true;
121-
$prevDir['link'] = '/' . trim(str_replace(end($goBack), '', $this->directory), '/');
122-
$prevDir['link_show'] = trim($prevDir['link'], '/');
121+
array_pop($goBack);
122+
$prevDir['link'] = '/' . implode('/', $goBack);
123+
$prevDir['link_show'] = implode('/', $goBack) . '/';
123124
}
124125

125126
$controller = new Repositories\Daemon\FileRepository($uuid);

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

Lines changed: 70 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
@section('scripts')
2727
@parent
28-
<script src="{{ asset('js/binaryjs.js') }}"></script>
28+
{!! Theme::js('js/binaryjs.js') !!}
29+
{!! Theme::js('js/vendor/lodash/lodash.js') !!}
2930
@endsection
3031

3132
@section('content')
@@ -36,56 +37,72 @@
3637
</ul>
3738
<div class="tab-content">
3839
<div class="tab-pane active" id="create">
39-
<div id="write_status" style="display:none;width: 100%; margin: 10px 0 5px;"></div>
40-
<form method="post" id="new_file">
41-
<h4>/home/container/{{ $directory }} <input type="text" id="file_name" class="filename" value="newfile.txt" /></h4>
42-
<div class="form-group">
43-
<div id="fileContents" style="height:500px;"></div>
40+
<div class="row" style="margin: 15px 0 0;">
41+
<div class="col-md-8" style="padding-left:0;">
42+
<div class="input-group" style="margin-bottom:5px;">
43+
<span class="input-group-addon">Save As:</span>
44+
<input type="text" class="form-control" id="file_name" placeholder="filename.json" value="{{ $directory}}">
45+
</div>
46+
<small><p class="text-muted">All files are saved relative to <code>/home/container</code>. You can enter more of the path into the Save As field to save the file into a specific folder.</p></small>
4447
</div>
45-
<div class="form-group">
46-
<div class="row">
47-
<div class="col-md-8">
48-
<button class="btn btn-primary btn-sm" id="create_file">{{ trans('strings.save') }}</button>
49-
<button class="btn btn-default btn-sm" onclick="window.location='/server/{{ $server->uuidShort }}/files?dir=/{{ $directory }}';return false;">{{ trans('server.files.back') }}</button>
50-
</div>
51-
<div class="col-md-4 pull-right">
52-
<select name="aceMode" id="aceMode" class="form-control">
53-
<option value="assembly_x86">Assembly x86</option>
54-
<option value="c_cpp">C/C++</option>
55-
<option value="coffee">CoffeeScript</option>
56-
<option value="csharp">C#</option>
57-
<option value="css">CSS</option>
58-
<option value="golang">Go</option>
59-
<option value="haml">HAML</option>
60-
<option value="html">HTML</option>
61-
<option value="ini">INI</option>
62-
<option value="java">Java</option>
63-
<option value="javascript">JavaScript</option>
64-
<option value="json">JSON</option>
65-
<option value="lua">Lua</option>
66-
<option value="markdown">Markdown</option>
67-
<option value="mysql">MySQL</option>
68-
<option value="objectivec">Objective-C</option>
69-
<option value="perl">Perl</option>
70-
<option value="php">PHP</option>
71-
<option value="properties">Properties</option>
72-
<option value="python">Python</option>
73-
<option value="ruby">Ruby</option>
74-
<option value="rust">Rust</option>
75-
<option value="smarty">Smarty</option>
76-
<option value="textile" selected="selected">Plain Text</option>
77-
<option value="xml">XML</option>
78-
<option value="yaml">YAML</option>
79-
</select>
80-
</div>
48+
</div>
49+
<div class="row">
50+
<div class="col-md-12">
51+
<div class="form-group">
52+
<div id="fileContents" style="height:500px;"></div>
8153
</div>
8254
</div>
83-
</form>
55+
</div>
56+
<div class="row">
57+
<div class="col-md-8">
58+
<button class="btn btn-primary btn-sm" id="create_file">{{ trans('strings.save') }}</button>
59+
<button class="btn btn-default btn-sm" onclick="window.location='/server/{{ $server->uuidShort }}/files?dir=/{{ $directory }}';return false;">{{ trans('server.files.back') }}</button>
60+
</div>
61+
<div class="col-md-4 pull-right">
62+
<select name="aceMode" id="aceMode" class="form-control">
63+
<option value="assembly_x86">Assembly x86</option>
64+
<option value="c_cpp">C/C++</option>
65+
<option value="coffee">CoffeeScript</option>
66+
<option value="csharp">C#</option>
67+
<option value="css">CSS</option>
68+
<option value="golang">Go</option>
69+
<option value="haml">HAML</option>
70+
<option value="html">HTML</option>
71+
<option value="ini">INI</option>
72+
<option value="java">Java</option>
73+
<option value="javascript">JavaScript</option>
74+
<option value="json">JSON</option>
75+
<option value="lua">Lua</option>
76+
<option value="markdown">Markdown</option>
77+
<option value="mysql">MySQL</option>
78+
<option value="objectivec">Objective-C</option>
79+
<option value="perl">Perl</option>
80+
<option value="php">PHP</option>
81+
<option value="properties">Properties</option>
82+
<option value="python">Python</option>
83+
<option value="ruby">Ruby</option>
84+
<option value="rust">Rust</option>
85+
<option value="smarty">Smarty</option>
86+
<option value="textile" selected="selected">Plain Text</option>
87+
<option value="xml">XML</option>
88+
<option value="yaml">YAML</option>
89+
</select>
90+
</div>
91+
</div>
8492
</div>
8593
@can('upload-files', $server)
8694
<div class="tab-pane" id="upload">
87-
<h4>/home/container/&nbsp;&nbsp;<input type="text" id="u_file_name" value="{{ $directory }}" style='outline: none;width:450px;background: transparent;margin-left:-5px;padding:0;border: 0px;font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;font-weight: 250;line-height: 1.1;color: inherit;font-size: 19px;'/></h4>
88-
<div class="alert alert-warning">Please edit the path location above <strong>before you upload files</strong>. They will automatically be placed in the directory you specify above. Simply click next to <code>/home/container/</code> and begin typing. You can change this each time you upload a new file without having to press anything else.</div>
95+
<div class="row" style="margin: 15px 0 0;">
96+
<div class="col-md-8" style="padding-left:0;">
97+
<div class="input-group" style="margin-bottom:5px;">
98+
<span class="input-group-addon">Upload Directory:</span>
99+
<input type="text" class="form-control" id="u_file_name" placeholder="logs/" value="{{ $directory}}">
100+
</div>
101+
<small><p class="text-muted">All files are saved relative to <code>/home/container</code>. You can enter more of the path into the Save As field to save the file into a specific folder.</p></small>
102+
</div>
103+
</div>
104+
105+
<div class="alert alert-warning">Edit the path location above <strong>before you upload files</strong>. They will automatically be placed in the directory you specify above. You can change this each time you upload a new file without having to press anything else.</div>
89106
<div class="alert alert-danger" id="upload_error" style="display: none;"></div>
90107
<input type="file" id="fileinput" name="fileUpload[]" multiple="" style="display:none;"/>
91108
<div id="uploader_box" class="well well-sm" style="cursor:pointer;">
@@ -227,7 +244,14 @@ function doNothing (e){
227244
});
228245
229246
function save() {
230-
var fileName = $('input[name="file"]').val();
247+
if (_.isEmpty($('#file_name').val())) {
248+
$.notify({
249+
message: 'No filename was passed.'
250+
}, {
251+
type: 'danger'
252+
});
253+
return;
254+
}
231255
$('#create_file').append(' <i class="fa fa-spinner fa fa-spin"></i>').addClass('disabled');
232256
$.ajax({
233257
type: 'POST',

0 commit comments

Comments
 (0)