/
index.html.pasta
195 lines (183 loc) · 8.04 KB
/
index.html.pasta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<i:arg name="buckets"
type="List"/>
<i:arg name="baseUrl"
type="String"/>
<i:arg name="accessKey"
type="String"/>
<i:arg name="secretKey"
type="String"/>
<t:page title="Start">
<i:block name="breadcrumbs"/>
<i:block name="page-header">
<i:invoke template="/templates/header.html.pasta"
title="S3 ninja"
subtitle="@toUserString(config('product.tagLine'))"/>
</i:block>
<script type="text/javascript">
function resolveTextfield() {
return document.querySelector('#create-bucket div input[name=bucketName]')
}
function checkBucketName() {
return new Promise((resolve, reject) => {
// make sure we have the text field
const textfield = resolveTextfield();
if (!textfield) {
reject(undefined);
}
// make sure we have a proper name
// https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
const name = textfield.value;
if (!name || name.trim() !== name || !/^[a-z\d][a-z\d\-.]{1,61}[a-z\d]$/.test(name)) {
reject(name);
}
resolve(name);
});
}
/**
* Checks the form for errors and styles the input accordingly.
*/
function checkForm() {
checkBucketName().then(name => {
// remove style class `error`
const textfield = resolveTextfield();
if (textfield) {
textfield.classList.remove('sci-border-red');
}
}).catch(name => {
// add style class `error` unless empty
const textfield = resolveTextfield();
if (textfield) {
textfield.classList.remove('sci-border-red');
if (name) {
textfield.classList.add('sci-border-red');
}
}
});
}
/**
* Checks the form for errors and submits the form if everything is fine.
*/
function submitForm() {
checkBucketName().then(name => {
location.href = '/ui/' + encodeURIComponent(name) + '?create'
}).catch(() => {
// ignore, error has already been indicated while typing
});
}
</script>
<div class="row">
<div class="col-md-4">
<div class="card shadow-sm mb-4">
<div class="card-body">
<dl class="mb-3">
<dt>Storage Path</dt>
<dd class="mb-0">
<small>@baseUrl</small>
</dd>
</dl>
<dl class="mb-3">
<dt>Access Key</dt>
<dd class="mb-0">
<small>@accessKey</small>
</dd>
</dl>
<dl class="mb-0">
<dt>Secret Key</dt>
<dd class="mb-0">
<small>@secretKey</small>
</dd>
</dl>
</div>
</div>
</div>
<div class="col-md-8">
<div class="card shadow-sm mb-4">
<div class="card-body">
<div class="row">
<div class="col-8 col-xl-9">
<form id="create-bucket"
onsubmit="submitForm(); return false;">
<div class="input-group">
<input type="text"
name="bucketName"
class="form-control"
placeholder="New Bucket…"
autofocus
oninput="checkForm();"/>
<a class="btn btn-outline-secondary"
onclick="submitForm();">
<i class="fa-solid fa-plus"></i></a>
</div>
</form>
</div>
<div class="col-4 col-xl-3 d-flex flex-row justify-content-end">
<a class="btn btn-outline-secondary"
href="/ui">
<i class="fa-solid fa-arrows-rotate"></i>
</a>
</div>
</div>
</div>
</div>
<div class="card shadow-sm">
<div class="card-body">
<table class="table mb-0">
<thead>
<tr>
<th>
Bucket
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<i:if test="buckets.isEmpty()">
<tr>
<td colspan="2"
class="border-0 border-bottom text-muted">
(No buckets)
</td>
</tr>
</i:if>
<i:for type="ninja.Bucket"
var="bucket"
items="buckets">
<tr class="@if(bucket.isPrivate()) { sci-left-border-red } else { sci-left-border-green }">
<td class="border-0 border-top">
<a class="@if(bucket.isPrivate()) { sci-text-red } else { sci-text-green }"
href="/ui/@bucket.getEncodedName()">@bucket.getName()</a><br>
<i:if test="bucket.isPrivate()">
<small class="text-muted small">private</small>
<i:else>
<small class="text-muted small">public</small>
</i:else>
</i:if>
</td>
<td class="border-0 border-top text-end pe-0">
<t:additionalActions label="Actions">
<i:if test="bucket.isPrivate()">
<t:dropdownItem url="@apply('/ui/%s?make-public&return=%%2Fui', bucket.getEncodedName())"
icon="fa-solid fa-lock-open"
label="Make public" />
<i:else>
<t:dropdownItem url="@apply('/ui/%s?make-private&return=%%2Fui', bucket.getEncodedName())"
icon="fa-solid fa-lock"
label="Make private" />
</i:else>
</i:if>
<t:dropdownDeleteItem url="@apply('/ui/%s?delete', bucket.getEncodedName())" />
</t:additionalActions>
</td>
</tr>
</i:for>
</tbody>
</table>
</div>
</div>
</div>
</div>
<i:block name="footer">
<i:invoke template="/templates/footer.html.pasta"/>
</i:block>
</t:page>