Unverified Commit 6ff4befb authored by davelopez's avatar davelopez
Browse files

Associate target history with each upload item when upload starts

This will ensure that when we change the current history in the middle of the upload each dataset goes where it was scheduled for the first time.
parent 640e0978
Loading
Loading
Loading
Loading
+6 −30
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
import { library } from "@fortawesome/fontawesome-svg-core";
import { faCopy, faEdit, faFolderOpen, faLaptop } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { watchImmediate } from "@vueuse/core";
import { BButton } from "bootstrap-vue";
import { filesDialog } from "utils/data";
import Vue, { computed, ref } from "vue";
@@ -85,7 +84,7 @@ const uploadCompleted = ref(0);
const uploadFile = ref(null);
const uploadItems = ref({});
const uploadSize = ref(0);
const queue = ref();
const queue = ref(createUploadQueue());

const counterNonRunning = computed(() => counterAnnounce.value + counterSuccess.value + counterError.value);
const enableBuild = computed(
@@ -101,13 +100,6 @@ const listExtensions = computed(() => props.effectiveExtensions.filter((ext) =>
const showHelper = computed(() => Object.keys(uploadItems.value).length === 0);
const uploadValues = computed(() => Object.values(uploadItems.value));

watchImmediate(
    () => props.historyId,
    () => {
        queue.value = initUploadQueue();
    }
);

function createUploadQueue() {
    return new UploadQueue({
        announce: eventAnnounce,
@@ -115,7 +107,6 @@ function createUploadQueue() {
        complete: eventComplete,
        error: eventError,
        get: (index) => uploadItems.value[index],
        historyId: historyId.value,
        multiple: props.multiple,
        progress: eventProgress,
        success: eventSuccess,
@@ -123,26 +114,6 @@ function createUploadQueue() {
    });
}

function initUploadQueue() {
    if (!queue.value) {
        return createUploadQueue();
    }

    if (queue.value.historyId !== historyId.value) {
        // The history has changed since the queue was created
        if (isRunning.value) {
            // The queue is running on the old history, so we need to create a new queue
            // that will target the new history
            return createUploadQueue();
        }
        // The queue is not running, so we can just update the target historyId and reuse the queue
        queue.value.historyId = historyId.value;
        return queue.value;
    }
    // Nothing has changed, so we can just return the existing queue
    return queue.value;
}

/** Add files to queue */
function addFiles(files, immediate = false) {
    if (!isRunning.value) {
@@ -295,6 +266,11 @@ function eventStart() {
        uploadValues.value.forEach((model) => {
            if (model.status === "init") {
                model.status = "queued";
                if (!model.targetHistoryId) {
                    // Associate with current history once upload starts
                    // This will not change if the current history is changed during upload
                    model.targetHistoryId = historyId.value;
                }
                uploadSize.value += model.fileSize;
            }
        });
+5 −9
Original line number Diff line number Diff line
@@ -66,14 +66,6 @@ export class UploadQueue {
        return this.queue.size;
    }

    get historyId() {
        return this.opts.historyId;
    }

    set historyId(historyId) {
        this.opts.historyId = historyId;
    }

    // Initiate upload process
    start() {
        if (!this.isRunning) {
@@ -104,7 +96,11 @@ export class UploadQueue {
            // Remove item from queue
            this.remove(index);
            // Collect upload request data
            const data = uploadPayload([this.opts.get(index)], this.opts.historyId);
            const item = this.opts.get(index);
            if (!item.targetHistoryId) {
                throw new Error(`Missing target history for upload item [${index}] ${item.fileName}`);
            }
            const data = uploadPayload([item], item.targetHistoryId);
            // Initiate upload request
            this._processSubmit(index, data);
        } catch (e) {