Skip to content

Commit 3161213

Browse files
Add file deletion locally
1 parent 7437c15 commit 3161213

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

src/components/storage/StorageFiles.vue

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<th style="text-transform:none;"><span style="color:#000;"> File Hash </span></th>
5353
<!-- <th style="text-transform:none;"><span style="color:#000;"> Merkle Hash </span></th> -->
5454
<th style="width:130px; text-transform:none;"> <span style="color:#000;"> Size </span></th>
55+
<th style="width:60px; text-transform:none;"> <span uk-icon="cog" style="color:#000;"> </span></th>
5556
</tr>
5657
</thead>
5758
<tbody>
@@ -66,16 +67,15 @@
6667
<td class="normal-txt uk-text-truncate">
6768
<span style="cursor: pointer;" @click="copyClipboard(f.hash)" uk-tooltip="Copy" uk-icon="icon:copy; ratio:0.9;"></span> {{ f.hash }}
6869
</td>
69-
<!-- <td class="uk-text-truncate">
70-
<span>
71-
{{ f.merkle_root_hash }}
72-
</span>
73-
</td> -->
7470
<td class="normal-txt">
7571
<span>
7672
{{ $filters.formatsize(f.size) }}
7773
</span>
7874
</td>
75+
<td class="uk-text-truncate">
76+
<span @click="showFileDeleteModal(f.key)" uk-tooltip="Delete item locally" style="color:red; cursor: pointer;" uk-icon="close">
77+
</span>
78+
</td>
7979
</tr>
8080
</tbody>
8181
</table>
@@ -113,6 +113,29 @@
113113
</div>
114114
</div>
115115

116+
<div id="modal-deletefile" uk-modal="container: #files-container; esc-close:false; bg-close:false;">
117+
<div style="padding-top: 17px; width: 60%; padding-bottom: 20px;" class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical">
118+
<button id="close-modal-create" class="uk-modal-close-default" type="button" uk-close></button>
119+
<h2 class="modal-header">Delete File</h2>
120+
121+
<div class="normal-txt" style="margin-top:15px;">
122+
Are you sure you want to delete this file?
123+
</div>
124+
<div style="padding:0px 10px; margin-top:10px;">
125+
<div v-if="fileDeleteError != ''" style="margin-top:10px; text-align: center;">
126+
<span class="uk-text-small uk-text-danger"> <span style="margin-right:5px;"
127+
uk-icon="icon: warning;"></span> {{ fileDeleteError }} </span>
128+
</div>
129+
</div>
130+
<div style="padding:8px 0px;" class="uk-modal-footer uk-text-right">
131+
<button @click="deleteFile(tmpFileKey)" class="uk-button ffg-button"
132+
style="text-transform: none; width:150px; height: 40px;">
133+
Delete
134+
<span class="uk-icon" uk-icon="icon: close"></span>
135+
</button>
136+
</div>
137+
</div>
138+
</div>
116139

117140
</div>
118141
</template>
@@ -134,6 +157,8 @@ export default {
134157
},
135158
data() {
136159
return {
160+
tmpFileKey: "",
161+
fileDeleteError: "",
137162
loadingFiles: false,
138163
pagination: {},
139164
nodeAddress: "",
@@ -234,13 +259,44 @@ export default {
234259
paginator.paginate({ rows: this.files, count: response.data.result.total });
235260
let pl = paginator.payload();
236261
this.pagination = { ...pl };
237-
262+
238263
} catch (e) {
239264
alert(e.message)
240265
} finally {
241266
this.loadingFiles = false;
242267
}
243268
},
269+
showFileDeleteModal(key) {
270+
this.tmpFileKey = key;
271+
const myModal = document.getElementById('modal-deletefile');
272+
const modal = window.UIkit.modal(myModal);
273+
modal.show();
274+
},
275+
hideFileDeleteModal(key) {
276+
this.tmpFileKey = key;
277+
const myModal = document.getElementById('modal-deletefile');
278+
const modal = window.UIkit.modal(myModal);
279+
modal.hide();
280+
},
281+
async deleteFile(fileKey) {
282+
try {
283+
this.fileDeleteError = "";
284+
const data = {
285+
jsonrpc: '2.0',
286+
method: "storage.DeleteUploadedFile",
287+
params: [{ key: fileKey, access_token: this.globalState.jwtAccessToken }],
288+
id: 1
289+
};
290+
291+
let response = await axios.post(localNodeEndpoint, data);
292+
if (response.data.result.success) {
293+
this.hideFileDeleteModal()
294+
this.reload()
295+
}
296+
} catch (e) {
297+
alert(e.message)
298+
}
299+
},
244300
}
245301
}
246302
</script>

src/main.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,15 @@ const app = createApp(App)
168168
app.config.globalProperties.$filters = {
169169
firstletter(val) {
170170
const trimmedString = val.trim();
171-
const regex = /^[A-Za-z]/; // Regular expression to match the first alphabetical character
172-
171+
const regex = /^[A-Za-z]/;
173172
const match = trimmedString.match(regex);
174173

175174
if (match) {
176175
const firstLetter = match[0];
177176
return firstLetter.toUpperCase();
178177
}
179-
180-
// If no match found using the previous regular expression,
181-
// fallback to extracting the first letter using a workaround
178+
182179
const letterMatch = trimmedString.match(/\p{L}/u);
183-
184180
if (letterMatch) {
185181
const firstLetter = letterMatch[0];
186182
return firstLetter.toUpperCase();

0 commit comments

Comments
 (0)