Changeset 35959


Ignore:
Timestamp:
2022-01-11T14:46:55+13:00 (2 years ago)
Author:
cstephen
Message:

Implement file drag and drop

Location:
main/trunk/model-interfaces-dev/atea/ocr/src/components
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/ocr/src/components/ImageMagnifier.vue

    r35958 r35959  
    33
    44export default {
    5     name: "OcrImageDisplay",
     5    name: "ImageMagnifier",
    66    props: {
    77        imageUrl: String,
     
    139139<div ref="magContainer" class="image-container">
    140140    <div ref="magnifier" class="magnifier" @mousemove="moveMagnifier" :style="{ 'visibility': enableMagnifier ? 'visible' : 'collapse' }" />
    141     <img v-if="!showThresholdedImage" ref="imageRef" class="image" :src="imageUrl" />
     141    <img ref="imageRef" class="image" :src="imageUrl" />
    142142</div>
    143143</template>
  • main/trunk/model-interfaces-dev/atea/ocr/src/components/MainPage.vue

    r35958 r35959  
    22import { mapState } from "vuex";
    33import EditPage from "./editor/EditPage.vue";
    4 import OcrImageDisplay from "./ImageMagnifier.vue"
     4import ImageMagnifier from "./ImageMagnifier.vue"
    55import { ModalController } from "./ModalDialog.vue"
    66import { SnackController } from "./Snackbar.vue"
     
    1414    components: {
    1515        EditPage,
    16         OcrImageDisplay
     16        ImageMagnifier
    1717    },
    1818    data() {
     
    7171    },
    7272    methods: {
    73         uploadFile() {
     73        openFilePicker() {
    7474            this.$refs.fileInput.click();
    7575        },
     
    8383            this.imageBuffer = await files[0].arrayBuffer();
    8484            this.imageType = files[0].type;
     85        },
     86        /**
     87         * Invoked when a drop event occurs on the file upload panel.
     88         * @param {DragEvent} ev The drop event.
     89         */
     90        async onFilesDropped(ev) {
     91            ev.preventDefault();
     92
     93            if (ev.dataTransfer.items && ev.dataTransfer.items.length > 0) {
     94                let index = 0;
     95                while (ev.dataTransfer.items[index].kind !== "file") {
     96                    index++;
     97                }
     98
     99                const file = ev.dataTransfer.items[0].getAsFile();
     100                this.imageBuffer = await file.arrayBuffer();
     101                this.imageType = file.type;
     102            }
     103            else if (ev.dataTransfer.files.length > 0) {
     104                const file = ev.dataTransfer.files[0];
     105                this.imageBuffer = await file.arrayBuffer();
     106                this.imageType = file.type;
     107            }
    85108        },
    86109
     
    228251
    229252    <div class="paper root-container" :class="{ 'root-container-image-state': imageUrl !== null }">
    230         <div v-if="imageUrl === null" class="upload-area" @click="uploadFile">
     253        <div v-if="imageUrl === null" class="upload-area"
     254            @click="openFilePicker" @drop="onFilesDropped" @dragover="$event.preventDefault()">
    231255            <span class="heading1">{{ translations.get("Title") }}</span>
    232256            <span class="material-icons mdi-xl">upload_file</span>
     
    293317
    294318            <div class="main-content-columns">
    295                 <ocr-image-display
     319                <image-magnifier
    296320                    v-if="!showThresholdedImage"
    297321                    :imageUrl="imageUrl"
     
    299323                    :magnifierZoom="magnifierZoom" />
    300324
    301                 <ocr-image-display
     325                <image-magnifier
    302326                    v-else
    303327                    :imageUrl="thresholdedImageUrl"
     
    312336                    :disabled="!isValidOcrResult || ocrInProgress"
    313337                    autocomplete="off"
    314                     :spellcheck="enableSpellcheck"/>
     338                    :spellcheck="enableSpellcheck" />
    315339            </div>
    316340        </div>
Note: See TracChangeset for help on using the changeset viewer.