Skip to content
Snippets Groups Projects
Verified Commit 9a2d477f authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Add edit object modal to upload a new file

#15
parent ea1f8ae6
No related branches found
No related tags found
1 merge request!12Add direct S3 interaction
...@@ -118,6 +118,7 @@ const objectState = reactive({ ...@@ -118,6 +118,7 @@ const objectState = reactive({
bucketPermissionError: false, bucketPermissionError: false,
createdPermission: undefined, createdPermission: undefined,
deletedItem: "", deletedItem: "",
editObjectKey: "",
} as { } as {
objects: S3ObjectMetaInformation[]; objects: S3ObjectMetaInformation[];
loading: boolean; loading: boolean;
...@@ -125,6 +126,7 @@ const objectState = reactive({ ...@@ -125,6 +126,7 @@ const objectState = reactive({
bucketPermissionError: boolean; bucketPermissionError: boolean;
createdPermission: undefined | BucketPermission; createdPermission: undefined | BucketPermission;
deletedItem: string; deletedItem: string;
editObjectKey: string;
}); });
// Watcher // Watcher
...@@ -434,6 +436,11 @@ function deleteFolder(folderPath: string) { ...@@ -434,6 +436,11 @@ function deleteFolder(folderPath: string) {
}); });
} }
function getObjectFileName(key: string): string {
const splittedKey = key.split("/");
return splittedKey[splittedKey.length - 1];
}
watch( watch(
visibleObjects, visibleObjects,
(visObjs) => { (visObjs) => {
...@@ -545,6 +552,7 @@ watch( ...@@ -545,6 +552,7 @@ watch(
modalID="upload-object-modal" modalID="upload-object-modal"
modal-label="some-label" modal-label="some-label"
:key-prefix="currentSubFolders.join('/')" :key-prefix="currentSubFolders.join('/')"
:edit-object-file-name="undefined"
@object-created="objectUploaded" @object-created="objectUploaded"
/> />
<!-- Add folder button --> <!-- Add folder button -->
...@@ -739,6 +747,9 @@ watch( ...@@ -739,6 +747,9 @@ watch(
class="dropdown-item" class="dropdown-item"
type="button" type="button"
:disabled="!writeS3Permission" :disabled="!writeS3Permission"
data-bs-toggle="modal"
data-bs-target="#edit-object-modal"
@click="objectState.editObjectKey = obj.key"
> >
Edit Edit
</button> </button>
...@@ -797,6 +808,15 @@ watch( ...@@ -797,6 +808,15 @@ watch(
</tr> </tr>
</tbody> </tbody>
</table> </table>
<upload-object-modal
:bucket-name="props.bucketName"
:s3-client="client"
modalID="edit-object-modal"
modal-label="some-label"
:key-prefix="currentSubFolders.join('/')"
:edit-object-file-name="getObjectFileName(objectState.editObjectKey)"
@object-created="objectUploaded"
/>
</div> </div>
</div> </div>
</template> </template>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import type { S3Client } from "@aws-sdk/client-s3"; import type { S3Client } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage"; import { Upload } from "@aws-sdk/lib-storage";
import BootstrapModal from "@/components/Modals/BootstrapModal.vue"; import BootstrapModal from "@/components/Modals/BootstrapModal.vue";
import { computed, onMounted, reactive } from "vue"; import { computed, onMounted, reactive, watch } from "vue";
import type { ComputedRef } from "vue"; import type { ComputedRef } from "vue";
import type { S3ObjectMetaInformation } from "@/client"; import type { S3ObjectMetaInformation } from "@/client";
import dayjs from "dayjs"; import dayjs from "dayjs";
...@@ -15,6 +15,7 @@ const props = defineProps<{ ...@@ -15,6 +15,7 @@ const props = defineProps<{
bucketName: string; bucketName: string;
keyPrefix: string; keyPrefix: string;
s3Client: S3Client; s3Client: S3Client;
editObjectFileName: string | undefined;
}>(); }>();
const randomIDSuffix = Math.random().toString(16).substr(2, 8); const randomIDSuffix = Math.random().toString(16).substr(2, 8);
...@@ -30,6 +31,13 @@ const emit = defineEmits<{ ...@@ -30,6 +31,13 @@ const emit = defineEmits<{
(e: "object-created", object: S3ObjectMetaInformation): void; (e: "object-created", object: S3ObjectMetaInformation): void;
}>(); }>();
watch(
() => props.editObjectFileName,
(nextFileName) => {
formState.key = nextFileName ?? "";
}
);
const formState = reactive({ const formState = reactive({
file: {}, file: {},
key: "", key: "",
...@@ -48,6 +56,10 @@ const uploadProgress: ComputedRef<number> = computed(() => ...@@ -48,6 +56,10 @@ const uploadProgress: ComputedRef<number> = computed(() =>
Math.round((100 * formState.uploadDone) / formState.uploadTotal) Math.round((100 * formState.uploadDone) / formState.uploadTotal)
); );
const editObject: ComputedRef<boolean> = computed(
() => props.editObjectFileName !== undefined
);
async function uploadObject() { async function uploadObject() {
const key = const key =
props.keyPrefix.length > 0 props.keyPrefix.length > 0
...@@ -99,7 +111,9 @@ async function uploadObject() { ...@@ -99,7 +111,9 @@ async function uploadObject() {
// eslint-disable-next-line // eslint-disable-next-line
function fileChange(event: any) { function fileChange(event: any) {
formState.file = event.target.files[0]; formState.file = event.target.files[0];
formState.key = formState.file.name; if (!editObject.value) {
formState.key = formState.file.name;
}
} }
onMounted(() => { onMounted(() => {
...@@ -197,9 +211,13 @@ onMounted(() => { ...@@ -197,9 +211,13 @@ onMounted(() => {
> >
<input <input
type="text" type="text"
class="form-control" :class="{
'form-control-plaintext': editObject,
'form-control': !editObject,
}"
:id="'objectKey' + randomIDSuffix" :id="'objectKey' + randomIDSuffix"
required required
:disabled="editObject"
v-model="formState.key" v-model="formState.key"
/> />
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment