Skip to content

Commit

Permalink
Add metadata edit
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Dec 19, 2024
1 parent 78044e1 commit 9434d7c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/dashboard/src/appUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ export const apiHandler = {
newKey: encode(newKey),
});
},
updateMetadata: async (bucket, key, metadata) => {
updateMetadata: async (bucket, key, customMetadata, httpMetadata = {}) => {
let prefix = "";
if (key.includes("/")) {
prefix = key.replace(key.split("/").pop(), "");
}

const resp = await api.post(`/buckets/${bucket}/${encode(key)}`, {
customMetadata: metadata,
customMetadata: customMetadata,
httpMetadata: httpMetadata,
});

if (resp.status === 200) {
Expand Down
48 changes: 48 additions & 0 deletions packages/dashboard/src/components/files/FileOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@
</q-card-actions>
</q-card>
</q-dialog>

<q-dialog v-model="updateMetadataModal" @hide="reset">
<q-card style="min-width: 300px;">
<q-card-section class="row column" v-if="row">
<q-avatar class="q-mb-md" icon="edit" color="orange" text-color="white" />
<q-input v-model="updateContentType" label="Content type" />
</q-card-section>

<q-card-actions align="right">
<q-btn flat label="Cancel" color="primary" v-close-popup />
<q-btn flat label="Rename" color="orange" :loading="loading" @click="updateConfirm" />
</q-card-actions>
</q-card>
</q-dialog>
</template>

<script>
Expand All @@ -45,9 +59,11 @@ export default defineComponent({
deleteFolderContents: [],
deleteModal: false,
renameModal: false,
updateMetadataModal: false,
deleteFolderInnerFilesCount: null,
newFolderName: "",
renameInput: "",
updateContentType: "",
loading: false,
}),
methods: {
Expand All @@ -69,6 +85,12 @@ export default defineComponent({
// console.log(row)
this.renameInput = row.name;
},
updateMetadataObject: async function (row) {
console.log(row);
this.updateMetadataModal = true;
this.row = row;
this.updateContentType = row.httpMetadata?.contentType || "";
},
renameConfirm: async function () {
if (this.renameInput.length === 0) {
return;
Expand All @@ -91,6 +113,30 @@ export default defineComponent({
timeout: 2500, // we will timeout it in 2.5s
});
},
updateConfirm: async function () {
if (this.updateContentType.length === 0) {
return;
}
this.loading = true;
await apiHandler.updateMetadata(
this.selectedBucket,
this.row.key,
this.row.customMetadata,
{
...this.row.httpMetadata,
contentType: this.updateContentType,
},
);
this.$bus.emit("fetchFiles");
this.reset();
this.q.notify({
group: false,
icon: "done", // we add an icon
spinner: false, // we reset the spinner setting so the icon can be displayed
message: "File Updated!",
timeout: 2500, // we will timeout it in 2.5s
});
},
deleteConfirm: async function () {
if (this.row.type === "folder") {
// When deleting folders, first must copy the objects, because the popup close forces a reset on properties
Expand Down Expand Up @@ -145,7 +191,9 @@ export default defineComponent({
this.loading = false;
this.deleteModal = false;
this.renameModal = false;
this.updateMetadataModal = false;
this.renameInput = "";
this.updateContentType = "";
this.row = null;
this.deleteFolderInnerFilesCount = null;
this.deleteFolderContents = [];
Expand Down
6 changes: 6 additions & 0 deletions packages/dashboard/src/pages/files/FileContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<q-item clickable v-close-popup @click="renameObject" v-if="prop.row.type === 'file'">
<q-item-section>Rename</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="updateMetadataObject" v-if="prop.row.type === 'file'">
<q-item-section>Update Metadata</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="shareObject">
<q-item-section>Get sharable link</q-item-section>
</q-item>
Expand Down Expand Up @@ -45,6 +48,9 @@ export default {
renameObject: function () {
this.$emit("renameObject", this.prop.row);
},
updateMetadataObject: function () {
this.$emit("updateMetadataObject", this.prop.row);
},
openObject: function () {
this.$emit("openObject", this.prop.row);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/dashboard/src/pages/files/FilesFolderPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
touch-position
context-menu
>
<FileContextMenu :prop="prop" @openObject="openObject" @deleteObject="$refs.options.deleteObject" @renameObject="$refs.options.renameObject" />
<FileContextMenu :prop="prop" @openObject="openObject" @deleteObject="$refs.options.deleteObject" @renameObject="$refs.options.renameObject" @updateMetadataObject="$refs.options.updateMetadataObject" />
</q-menu>
</template>

<template v-slot:body-cell-options="prop">
<td class="text-right">
<q-btn round flat icon="more_vert" size="sm">
<q-menu>
<FileContextMenu :prop="prop" @openObject="openObject" @deleteObject="$refs.options.deleteObject" @renameObject="$refs.options.renameObject" />
<FileContextMenu :prop="prop" @openObject="openObject" @deleteObject="$refs.options.deleteObject" @renameObject="$refs.options.renameObject" @updateMetadataObject="$refs.options.updateMetadataObject" />
</q-menu>
</q-btn>
</td>
Expand Down

0 comments on commit 9434d7c

Please sign in to comment.