aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@cloudron.io>2017-02-07 16:26:17 +0100
committerJohannes Zellner <johannes@cloudron.io>2017-02-07 16:26:19 +0100
commite628921a338684a4bc3f196c5c39beba8b8f9b68 (patch)
treea4112c316e69b4d0a302af23f5bb8f4396c15c30 /frontend
parent4b6cf0add4f4f89671f4553a9672a01fbb485df1 (diff)
downloadSurfer-e628921a338684a4bc3f196c5c39beba8b8f9b68.tar.gz
Surfer-e628921a338684a4bc3f196c5c39beba8b8f9b68.tar.zst
Surfer-e628921a338684a4bc3f196c5c39beba8b8f9b68.zip
Add rename functionality
This also break backwardscompat since PUT is now POST and PUT is used for renaming
Diffstat (limited to 'frontend')
-rw-r--r--frontend/index.html35
-rw-r--r--frontend/js/app.js40
2 files changed, 67 insertions, 8 deletions
diff --git a/frontend/index.html b/frontend/index.html
index e9775e8..cbbd85e 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -41,7 +41,7 @@
41 </div> 41 </div>
42 <div class="modal-body"> 42 <div class="modal-body">
43 <h5 v-show="deleteData.isFile">Really delete <span style="font-weight: bold;">{{ deleteData.filePath }}</span>?</h5> 43 <h5 v-show="deleteData.isFile">Really delete <span style="font-weight: bold;">{{ deleteData.filePath }}</span>?</h5>
44 <h5 v-show="deleteData.isDirectory">Really delete directory <span style="font-weight: bold;">{{ deleteData.filePath }}</span> and all its content?</h5> 44 <h5 v-show="deleteData.isDirectory">Really delete folder <span style="font-weight: bold;">{{ deleteData.filePath }}</span> and all its content?</h5>
45 </div> 45 </div>
46 <div class="modal-footer"> 46 <div class="modal-footer">
47 <button type="button" class="btn btn-default" data-dismiss="modal">No</button> 47 <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
@@ -51,12 +51,36 @@
51 </div> 51 </div>
52 </div> 52 </div>
53 53
54 <div class="modal fade" tabindex="-1" role="dialog" id="modalRename" v-cloak>
55 <div class="modal-dialog">
56 <div class="modal-content">
57 <div class="modal-header">
58 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
59 <h4 class="modal-title">Rename {{ renameData.entry.filePath }}</h4>
60 </div>
61 <div class="modal-body">
62 <form v-on:submit.prevent="rename(renameData)">
63 <div class="form-group" v-bind:class="{ 'has-error': renameData.error }">
64 <input type="text" class="form-control" v-model="renameData.newFilePath" placeholder="Name" autofocus="true">
65 <label class="control-label">{{ renameData.error }}</label>
66 </div>
67 <button type="submit" style="display: none;"></button>
68 </form>
69 </div>
70 <div class="modal-footer">
71 <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
72 <button type="button" class="btn btn-success" v-on:click="rename(renameData)">Yes</button>
73 </div>
74 </div>
75 </div>
76 </div>
77
54 <div class="modal fade" tabindex="-1" role="dialog" id="modalcreateDirectory" v-cloak> 78 <div class="modal fade" tabindex="-1" role="dialog" id="modalcreateDirectory" v-cloak>
55 <div class="modal-dialog"> 79 <div class="modal-dialog">
56 <div class="modal-content"> 80 <div class="modal-content">
57 <div class="modal-header"> 81 <div class="modal-header">
58 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 82 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
59 <h4 class="modal-title">New Directory Name</h4> 83 <h4 class="modal-title">New directory name</h4>
60 </div> 84 </div>
61 <div class="modal-body"> 85 <div class="modal-body">
62 <form v-on:submit.prevent="createDirectory(createDirectoryData)"> 86 <form v-on:submit.prevent="createDirectory(createDirectoryData)">
@@ -135,7 +159,7 @@
135 <a href="{{ part.link }}">{{ part.name }}</a> 159 <a href="{{ part.link }}">{{ part.name }}</a>
136 </li> 160 </li>
137 <li>{{ pathParts.slice(-1)[0].name }}</li> 161 <li>{{ pathParts.slice(-1)[0].name }}</li>
138 <button class="btn btn-default btn-sm pull-right" v-on:click="createDirectoryAsk()">Create Directory</button> 162 <button class="btn btn-default btn-sm pull-right" v-on:click="createDirectoryAsk()">Create Folder</button>
139 </ol> 163 </ol>
140 </div> 164 </div>
141 <div class="col-lg-12"> 165 <div class="col-lg-12">
@@ -150,6 +174,9 @@
150 </tr> 174 </tr>
151 </thead> 175 </thead>
152 <tbody> 176 <tbody>
177 <tr v-show="entries.length === 0">
178 <th><i>Empty folder</i></th>
179 </tr>
153 <tr v-for="entry in entries" v-on:click="open(entry)" class="hand"> 180 <tr v-for="entry in entries" v-on:click="open(entry)" class="hand">
154 <th> 181 <th>
155 <img v-bind:src="entry.previewUrl" height="48px" width="48px"/> 182 <img v-bind:src="entry.previewUrl" height="48px" width="48px"/>
@@ -159,7 +186,7 @@
159 <th><span v-my-tooltip="foobar" data-toggle="tooltip" title="{{ entry.mtime }}">{{ entry.mtime | prettyDate }}</span></th> 186 <th><span v-my-tooltip="foobar" data-toggle="tooltip" title="{{ entry.mtime }}">{{ entry.mtime | prettyDate }}</span></th>
160 <th style="text-align: right;"> 187 <th style="text-align: right;">
161 <span class="entry-toolbar"> 188 <span class="entry-toolbar">
162 <!-- <button class="btn btn-sm btn-default" v-on:click.stop="renameAsk(entry)" title="Rename"><i class="fa fa-pencil"></i></button> --> 189 <button class="btn btn-sm btn-default" v-on:click.stop="renameAsk(entry)" title="Rename"><i class="fa fa-pencil"></i></button>
163 <button class="btn btn-sm btn-danger" v-on:click.stop="delAsk(entry)" title="Delete"><i class="fa fa-trash"></i></button> 190 <button class="btn btn-sm btn-danger" v-on:click.stop="delAsk(entry)" title="Delete"><i class="fa fa-trash"></i></button>
164 </span> 191 </span>
165 </th> 192 </th>
diff --git a/frontend/js/app.js b/frontend/js/app.js
index e0464f8..078473a 100644
--- a/frontend/js/app.js
+++ b/frontend/js/app.js
@@ -141,7 +141,7 @@ function upload() {
141 var formData = new FormData(); 141 var formData = new FormData();
142 formData.append('file', file); 142 formData.append('file', file);
143 143
144 superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) { 144 superagent.post('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) {
145 if (result && result.statusCode === 401) return logout(); 145 if (result && result.statusCode === 401) return logout();
146 if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode); 146 if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode);
147 if (error) console.error(error); 147 if (error) console.error(error);
@@ -149,8 +149,6 @@ function upload() {
149 app.uploadStatus.done += 1; 149 app.uploadStatus.done += 1;
150 app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.count * 100); 150 app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.count * 100);
151 151
152 console.log(Math.round(app.uploadStatus.done / app.uploadStatus.count * 100))
153
154 if (app.uploadStatus.done >= app.uploadStatus.count) { 152 if (app.uploadStatus.done >= app.uploadStatus.count) {
155 app.uploadStatus = { 153 app.uploadStatus = {
156 busy: false, 154 busy: false,
@@ -198,6 +196,33 @@ function del(entry) {
198 }); 196 });
199} 197}
200 198
199function renameAsk(entry) {
200 app.renameData.entry = entry;
201 app.renameData.error = null;
202 app.renameData.newFilePath = entry.filePath;
203
204 $('#modalRename').modal('show');
205}
206
207function rename(data) {
208 app.busy = true;
209
210 var path = encode(sanitize(app.path + '/' + data.entry.filePath));
211 var newFilePath = sanitize(app.path + '/' + data.newFilePath);
212
213 superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send({ newFilePath: newFilePath }).end(function (error, result) {
214 app.busy = false;
215
216 if (result && result.statusCode === 401) return logout();
217 if (result && result.statusCode !== 200) return console.error('Error renaming file: ', result.statusCode);
218 if (error) return console.error(error);
219
220 refresh();
221
222 $('#modalRename').modal('hide');
223 });
224}
225
201function createDirectoryAsk() { 226function createDirectoryAsk() {
202 $('#modalcreateDirectory').modal('show'); 227 $('#modalcreateDirectory').modal('show');
203 app.createDirectoryData = ''; 228 app.createDirectoryData = '';
@@ -210,7 +235,7 @@ function createDirectory(name) {
210 235
211 var path = encode(sanitize(app.path + '/' + name)); 236 var path = encode(sanitize(app.path + '/' + name));
212 237
213 superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password, directory: true }).end(function (error, result) { 238 superagent.post('/api/files' + path).query({ username: app.session.username, password: app.session.password, directory: true }).end(function (error, result) {
214 app.busy = false; 239 app.busy = false;
215 240
216 if (result && result.statusCode === 401) return logout(); 241 if (result && result.statusCode === 401) return logout();
@@ -258,6 +283,11 @@ var app = new Vue({
258 }, 283 },
259 loginData: {}, 284 loginData: {},
260 deleteData: {}, 285 deleteData: {},
286 renameData: {
287 entry: {},
288 error: null,
289 newFilePath: ''
290 },
261 createDirectoryData: '', 291 createDirectoryData: '',
262 createDirectoryError: null, 292 createDirectoryError: null,
263 entries: [] 293 entries: []
@@ -271,6 +301,8 @@ var app = new Vue({
271 upload: upload, 301 upload: upload,
272 delAsk: delAsk, 302 delAsk: delAsk,
273 del: del, 303 del: del,
304 renameAsk: renameAsk,
305 rename: rename,
274 createDirectoryAsk: createDirectoryAsk, 306 createDirectoryAsk: createDirectoryAsk,
275 createDirectory: createDirectory 307 createDirectory: createDirectory
276 } 308 }