s3manager-web/web/template/bucket.html.tmpl

239 lines
7.9 KiB
Cheetah
Raw Normal View History

2016-12-18 22:54:21 +01:00
{{ define "content" }}
2023-06-13 17:37:57 +02:00
<style>
.breadcrumb:before {
2023-06-20 07:18:56 +02:00
content: '/';
}
#notifications {
top: 20px;
right: 30px;
position: fixed;
z-index: 2
2023-06-13 17:37:57 +02:00
}
</style>
<nav class="nav-extended">
2017-05-08 23:07:07 +02:00
<div class="nav-wrapper container">
2023-06-13 17:37:57 +02:00
<a href="/buckets/{{$.BucketName}}" class="brand-logo center"><i class="material-icons">folder_open</i>{{ .BucketName }}</a>
2017-05-08 23:07:07 +02:00
{{ if not .Objects }}
2019-08-18 14:26:29 +02:00
<ul class="right">
<li>
<a class="waves-effect waves-light btn" href="#" onclick="deleteBucket({{ .BucketName }})">
Delete <i class="material-icons right">delete</i>
</a>
</li>
</ul>
2017-05-08 23:07:07 +02:00
{{ end }}
</div>
2016-12-21 00:32:40 +01:00
2023-06-13 17:37:57 +02:00
<div class="nav-wrapper container">
<a href="/buckets" class="breadcrumb"><i class="material-icons">arrow_back</i> buckets </a>
{{ $url := printf "/buckets/%s/" $.BucketName }}
<a href="{{ $url }}" class="breadcrumb">{{ $.BucketName }}</a>
{{ range $index, $path := .Paths }}
{{ $url = printf "%s%s/" $url $path }}
<a href="{{ $url }}" class="breadcrumb">{{ $path }}</a>
{{ end }}
</div>
</div>
</nav>
2016-12-21 00:32:40 +01:00
2023-06-20 07:18:56 +02:00
<div class="section" style="margin: 10px; position: relative;">
2017-05-08 23:07:07 +02:00
{{ if .Objects }}
2019-08-18 14:26:29 +02:00
<table class="striped">
2017-05-08 23:07:07 +02:00
<thead>
<tr>
<th>Key</th>
<th>Size</th>
<th>Owner</th>
<th>Last Modified</th>
2019-08-18 14:26:29 +02:00
<th style="min-width:165px;"></th>
2017-05-08 23:07:07 +02:00
</tr>
</thead>
2016-12-21 00:32:40 +01:00
2017-05-08 23:07:07 +02:00
<tbody>
{{ range $index, $object := .Objects }}
<tr>
2023-06-13 17:37:57 +02:00
<td
{{ if $object.IsFolder }}
onclick="location.href='/buckets/{{ $.BucketName }}/{{ $object.Key }}'"}
style="cursor:pointer;"
{{ end }}>
<i class="material-icons">{{ $object.Icon }}</i> {{ $object.DisplayName }}
</td>
<td>{{ $object.Size }} bytes</td>
<td>{{ $object.Owner }}</td>
<td>{{ $object.LastModified }}</td>
2017-05-08 23:07:07 +02:00
<td>
2023-06-20 07:18:56 +02:00
{{ if not $object.IsFolder }}
<button class="dropdown-trigger waves-effect waves-teal btn" data-target="actions-dropdown-{{ $index }}">
Actions <i class="material-icons right">arrow_drop_down</i>
</button>
<!-- Dropdown Structure -->
<ul id="actions-dropdown-{{ $index }}" class="dropdown-content">
<li><a target="_blank" href="/api/buckets/{{ $.BucketName }}/objects/{{ $object.Key }}">Download</a></li>
{{- if $.AllowDelete }}
<li><a href="#" onclick="deleteObject({{ $.BucketName }}, {{ $object.Key }})">Delete</a></li>
{{- end }}
</ul>
{{ end }}
2017-05-08 23:07:07 +02:00
</td>
</tr>
{{ end }}
</tbody>
</table>
{{ end }}
2016-12-21 00:32:40 +01:00
2017-05-08 23:07:07 +02:00
{{ if not .Objects }}
2023-06-20 07:18:56 +02:00
<p style="text-align:center;margin-top:2em;color:gray;">No objects in <strong>{{ .BucketName }}/{{ .CurrentPath }}</strong> yet</p>
2017-05-08 23:07:07 +02:00
{{ end }}
2016-12-21 00:32:40 +01:00
2023-06-20 07:18:56 +02:00
<div id="notifications">
<div id="notification-template" class="card" style="display: none;">
<div class="card-content" style="padding: 12px">
<span class="card-title">Uploading</span>
<p> I am a very simple card </p>
<div class="progress">
<div class="indeterminate"></div>
</div>
</div>
</div>
</div>
2016-12-21 00:32:40 +01:00
</div>
<div class="fixed-action-btn">
2023-07-16 15:09:13 +02:00
<button type="button" class="btn-floating btn-large red tooltipped" id="upload-file-btn" data-position="top" data-tooltip="Upload files">
2017-05-08 23:07:07 +02:00
<i class="large material-icons">add</i>
2019-08-18 14:26:29 +02:00
</button>
2023-06-20 07:18:56 +02:00
2023-07-16 15:09:13 +02:00
<button type="button" class="btn-floating btn-large red tooltipped" id="upload-folder-btn" data-position="top" data-tooltip="Upload folder">
2023-06-20 07:18:56 +02:00
<i class="large material-icons">create_new_folder</i>
</button>
2017-05-08 23:07:07 +02:00
2023-07-16 15:09:13 +02:00
<button type="button" class="btn-floating btn-large red modal-trigger tooltipped" data-target="modal-create-folder" data-position="top" data-tooltip="Change path">
<i class="large material-icons">create</i>
</button>
2016-12-21 00:32:40 +01:00
</div>
2016-12-18 22:54:21 +01:00
2023-07-16 15:09:13 +02:00
<input type="file" id="upload-folder-input" webkitdirectory multiple style="display: none;">
<input type="file" id="upload-file-input" name="file" multiple style="display: none;">
2023-06-20 07:18:56 +02:00
<div id="modal-create-folder" class="modal">
<form id="create-folder-form" enctype="multipart/form-data">
<div class="modal-content">
2023-07-16 15:09:13 +02:00
<h4>Change directory path</h4>
2023-06-20 07:18:56 +02:00
<br>
<div class="row">
<div class="col s6">
<div class="input-field">
<input name="new-path" id="new-path" type="text">
<label for="new-path">Path</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="modal-close waves-effect waves-green btn-flat">Cancel</button>
<button type="submit" class="modal-close waves-effect waves-green btn">Create</button>
</div>
</form>
</div>
2016-12-21 00:32:40 +01:00
<script>
2017-05-08 23:07:07 +02:00
function deleteObject(bucketName, objectName) {
2016-12-21 00:32:40 +01:00
$.ajax({
2017-05-08 23:07:07 +02:00
type: 'DELETE',
url: '/api/buckets/' + bucketName + '/objects/' + objectName,
success: function () { location.reload(); }
2016-12-21 00:32:40 +01:00
})
2017-05-08 23:07:07 +02:00
}
function deleteBucket(bucketName) {
2016-12-21 22:29:12 +01:00
$.ajax({
2017-05-08 23:07:07 +02:00
type: 'DELETE',
url: '/api/buckets/' + bucketName,
success: function () { window.location.replace('/buckets'); }
2016-12-21 22:29:12 +01:00
})
2017-05-08 23:07:07 +02:00
}
2023-06-20 07:18:56 +02:00
2023-07-16 15:09:13 +02:00
function handleUploadFiles(event) {
files = event.target.files
url = "/api/buckets/{{ .BucketName }}/objects"
uploadFiles(files, url);
}
2023-06-20 07:18:56 +02:00
function handleCreateFolder(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const newPath = formData.get("new-path")
let newHref = window.location.href + newPath
if(!newHref.endsWith("/")) {
newHref = newHref + "/"
}
window.location.href = newHref
}
2023-07-16 15:09:13 +02:00
function uploadFiles(files, url) {
uploadPromises = [];
for(file of files) {
uploadPromises.push(uploadFile(file, url));
}
Promise.all(uploadPromises).then(values => {
window.location.reload();
});
}
2023-06-20 07:18:56 +02:00
2023-07-16 15:09:13 +02:00
function uploadFile(file, url) {
const formData = new FormData();
formData.append('file', file);
if( !!file.webkitRelativePath ) {
formData.append('path', "{{ .CurrentPath }}" + file.webkitRelativePath );
} else {
formData.append('path', "{{ .CurrentPath }}" + file.name );
}
const notification = createNotification(file.name);
notifications = document.getElementById('notifications');
notifications.appendChild(notification);
return fetch(url, {
2023-06-20 07:18:56 +02:00
method: "POST",
body: formData
}).then(response => {
2023-07-16 15:09:13 +02:00
notifications.removeChild(notification);
2023-06-20 07:18:56 +02:00
})
}
function createNotification(fileName) {
notificationTemplate = document.getElementById('notification-template');
2023-07-16 15:09:13 +02:00
notification = notificationTemplate.cloneNode(true);
notification.getElementsByTagName('p')[0].setHTML(fileName);
notification.removeAttribute("id");
notification.removeAttribute("style");
return notification;
2023-06-20 07:18:56 +02:00
}
window.onload = (event) => {
2023-07-16 15:09:13 +02:00
$('#create-folder-form').submit(handleCreateFolder)
uploadFolderInput = $('#upload-folder-input');
$('#upload-folder-btn').click(event => uploadFolderInput.click());
uploadFolderInput.change(handleUploadFiles);
uploadFileInput = $('#upload-file-input');
$('#upload-file-btn').click(event => uploadFileInput.click());
uploadFileInput.change(handleUploadFiles);
$(document).ready(function(){
$('.tooltipped').tooltip();
});
2023-06-20 07:18:56 +02:00
};
2016-12-21 00:32:40 +01:00
</script>
2016-12-18 22:54:21 +01:00
{{ end }}