Changeset 35762 for main/trunk/model-interfaces-dev
- Timestamp:
- 2021-11-30T14:06:55+13:00 (2 years ago)
- Location:
- main/trunk/model-interfaces-dev/atea
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/ocr/src/App.vue
r35743 r35762 9 9 <main-page class="content" /> 10 10 </div> 11 12 <modal-dialog ref="modalDialog" /> 11 13 </template> 12 14 … … 57 59 import { mapState } from "vuex"; 58 60 import MainPage from "./components/MainPage.vue" 61 import ModalDialog, { ModalController } from "./components/ModalDialog.vue" 59 62 60 63 export default { 61 64 name: "App", 62 65 components: { 63 MainPage 66 MainPage, 67 ModalDialog 64 68 }, 65 69 computed: { … … 67 71 translations: state => state.translations 68 72 }) 73 }, 74 mounted() { 75 ModalController.setModal(this.$refs.modalDialog); 69 76 } 70 77 } -
main/trunk/model-interfaces-dev/atea/ocr/src/components/EditPage.vue
r35751 r35762 2 2 <div class="edit-page-root"> 3 3 <div class="control-panel"> 4 <edit-action :description="translations.get('EditPage_Discard')" @action=" $emit('closeAndDiscard')" icon="cancel" />5 <edit-action :description="translations.get('EditPage_InvertColour')" @action="invert = !invert" icon="invert_colors" />4 <edit-action :description="translations.get('EditPage_Discard')" @action="closeAndDiscard" icon="cancel" /> 5 <edit-action :description="translations.get('EditPage_InvertColour')" @action="invertColours" icon="invert_colors" /> 6 6 <edit-action :description="translations.get('EditPage_Rotate')" v-model="rotateMode" icon="crop_rotate" toggleMode /> 7 7 <edit-action :description="translations.get('EditPage_Save')" @action="closeAndSave" icon="save" /> … … 165 165 import { mapState } from "vuex"; 166 166 import EditAction from "./EditAction.vue" 167 import { ModalController } from "./ModalDialog.vue" 167 168 168 169 export default { … … 181 182 rotation: 0, 182 183 rotateMode: false, 183 allowRotation: false 184 allowRotation: false, 185 edited: false 184 186 } 185 187 }, … … 205 207 }, 206 208 methods: { 209 closeAndDiscard(force) { 210 if (force || !this.edited) { 211 this.$emit("closeAndDiscard"); 212 return; 213 } 214 215 const that = this; 216 217 ModalController.open( 218 this.translations.get("DiscardEditsModal_Title"), 219 this.translations.get("DiscardEditsModal_Description"), 220 [ 221 this.translations.get("DiscardEditsModal_ButtonContinue"), 222 this.translations.get("DiscardEditsModal_ButtonCancel") 223 ], 224 async function(buttonName) { 225 if (buttonName === that.translations.get("DiscardEditsModal_ButtonContinue")) { 226 that.closeAndDiscard(true); 227 } 228 } 229 ); 230 }, 207 231 async closeAndSave() { 208 232 const Jimp = await import("jimp/es"); … … 225 249 226 250 this.$emit("closeAndSave", modifiedBuffer, Jimp.MIME_PNG); 251 }, 252 253 invertColours() { 254 this.invert = !this.invert; 255 this.edited = true; 227 256 }, 228 257 … … 263 292 this.rotation -= 360; 264 293 } 294 295 this.edited = true; 265 296 }, 266 297 onDocumentMouseUp() { -
main/trunk/model-interfaces-dev/atea/ocr/src/components/MainPage.vue
r35759 r35762 1 1 <template> 2 2 <div class="main-page-root"> 3 <modal-dialog v-if="modal.show" :title="modal.title" :description="modal.description" :buttons="modal.buttons" @close="onModalClose" />4 3 <edit-page v-if="showEditor" class="image-editor" :src="imageUrl" :imageBuffer="imageBuffer" 5 4 @closeAndDiscard="onEditorCloseRequested" @closeAndSave="onEditorSave" /> … … 42 41 43 42 <textarea class="text-container" v-model="ocrResult" :placeholder="translations.get('MainPage_OCRHint')" 44 @input=" modalChecks.ocrTextEdited = true" :disabled="!isValidOcrResult" />43 @input="ocrTextEdited = true" :disabled="!isValidOcrResult || ocrInProgress" /> 45 44 </div> 46 45 </div> … … 144 143 import { mapState } from "vuex"; 145 144 import EditPage from "./EditPage.vue"; 146 import ModalDialogfrom "./ModalDialog.vue"145 import { ModalController } from "./ModalDialog.vue" 147 146 import OcrService, { OcrOptions } from "../js/OcrService" 148 147 import { log } from "../js/Util"; … … 153 152 name: "MainPage", 154 153 components: { 155 EditPage, 156 ModalDialog 154 EditPage 157 155 }, 158 156 data() { … … 165 163 ocrResult: null, 166 164 showEditor: false, 167 modal: { 168 show: false, 169 title: "", 170 description: "", 171 buttons: [] 172 }, 173 modalChecks: { 174 ocrTextEdited: false, 175 pendingReset: false 176 } 165 ocrTextEdited: false 177 166 } 178 167 }, … … 216 205 217 206 async doOcr() { 218 if (this.modalChecks.ocrTextEdited) {219 this.modal.title = this.translations.get("OCREditedModal_Title");220 this.modal.description = this.translations.get("OCREditedModal_Description");221 this.modal.buttons = [222 this.translations.get("OCREditedModal_ButtonContinue"),223 this.translations.get("OCREditedModal_ButtonCancel")224 ];225 this.modal.show = true;226 227 return;228 }229 230 207 try { 208 if (this.ocrTextEdited) { 209 this.confirmOcr(); 210 return; 211 } 212 231 213 this.ocrInProgress = true; 232 214 … … 243 225 244 226 this.ocrResult = result[0].text; 245 this. modalChecks.ocrTextEdited = false;227 this.ocrTextEdited = false; 246 228 } 247 229 catch (ex) { … … 253 235 this.ocrInProgress = false; 254 236 } 237 }, 238 confirmOcr() { 239 const that = this; 240 241 ModalController.open( 242 this.translations.get("OCREditedModal_Title"), 243 this.translations.get("OCREditedModal_Description"), 244 [ 245 this.translations.get("OCREditedModal_ButtonContinue"), 246 this.translations.get("OCREditedModal_ButtonCancel") 247 ], 248 async function(buttonName) { 249 if (buttonName === that.translations.get("OCREditedModal_ButtonContinue")) { 250 that.ocrTextEdited = false; 251 await that.doOcr(); 252 } 253 } 254 ); 255 255 }, 256 256 … … 272 272 reset(hard) { 273 273 if (!hard) { 274 this.modalChecks.pendingReset = true; 275 276 this.modal.title = this.translations.get("NewImageModal_Title"); 277 this.modal.description = this.translations.get("NewImageModal_Description"); 278 this.modal.buttons = [ 279 this.translations.get("NewImageModal_ButtonContinue"), 280 this.translations.get("NewImageModal_ButtonCancel") 281 ]; 282 this.modal.show = true; 274 const that = this; 275 276 ModalController.open( 277 this.translations.get("NewImageModal_Title"), 278 this.translations.get("NewImageModal_Description"), 279 [ 280 this.translations.get("NewImageModal_ButtonContinue"), 281 this.translations.get("NewImageModal_ButtonCancel") 282 ], 283 function(buttonName) { 284 if (buttonName === that.translations.get("NewImageModal_ButtonContinue")) { 285 that.reset(true); 286 } 287 } 288 ); 283 289 284 290 return; … … 290 296 this.ocrResult = null; 291 297 this.showEditor = false; 298 this.ocrTextEdited = false; 292 299 this.$refs.fileInput.value = ""; 293 },294 295 async onModalClose(button) {296 this.modal.show = false;297 298 if (this.modalChecks.pendingReset) {299 console.log("reset is indeed pending");300 if (button === "Continue") {301 this.reset(true);302 }303 304 this.modalChecks.pendingReset = false;305 }306 else if (this.modalChecks.ocrTextEdited) {307 if (button === "Continue") {308 this.modalChecks.ocrTextEdited = false;309 await this.doOcr();310 }311 }312 300 }, 313 301 -
main/trunk/model-interfaces-dev/atea/ocr/src/components/ModalDialog.vue
r35752 r35762 1 1 <template> 2 <div class="background-cover" >2 <div class="background-cover" :class="{ 'hidden': !isShowing }"> 3 3 <div class="paper modal"> 4 4 <span class="heading3">{{ title }}</span> … … 8 8 9 9 <div class="buttons"> 10 <button v-for="name in buttons" :key="name" class="btn-primary" @click=" $emit('close',name)">{{ name }}</button>10 <button v-for="name in buttons" :key="name" class="btn-primary" @click="close(name)">{{ name }}</button> 11 11 </div> 12 12 </div> … … 19 19 height: 100%; 20 20 width: 100%; 21 top: 0; 22 left: 0; 21 23 22 24 display: flex; … … 39 41 } 40 42 43 .hidden { 44 display: none; 45 } 46 41 47 hr { 42 48 margin: 0.5em 0; … … 48 54 export default { 49 55 name: "ModalDialog", 50 props: { 51 title: String, 52 description: String, 53 buttons: Array 56 data() { 57 return { 58 id: null, 59 title: null, 60 description: null, 61 buttons: null, 62 callback: null, 63 isShowing: false 64 } 54 65 }, 55 emits: [ "close" ] 66 methods: { 67 show(title, description, buttons, callback, id) { 68 this.id = id; 69 this.title = title; 70 this.description = description; 71 this.buttons = buttons; 72 this.callback = callback; 73 74 this.isShowing = true; 75 }, 76 close(buttonName) { 77 this.isShowing = false; 78 this.callback(buttonName, this.id); 79 } 80 } 81 } 82 83 export class ModalController { 84 static modal = null; 85 static queue = []; 86 static waitingOnClose = false; 87 88 static setModal(modal) { 89 this.modal = modal; 90 } 91 92 static open(title, description, buttons, callback, id) { 93 this.queue.push({ 94 title: title, 95 description: description, 96 buttons: buttons, 97 callback: callback, 98 id: id 99 }); 100 101 this.showModals(); 102 } 103 104 static showModals() { 105 if (this.waitingOnClose || this.queue.length === 0) { 106 return; 107 } 108 109 this.waitingOnClose = true; 110 const item = this.queue.shift(); 111 const that = this; 112 113 this.modal.show( 114 item.title, 115 item.description, 116 item.buttons, 117 function(buttonName, id) { 118 that.waitingOnClose = false; 119 that.showModals(); 120 item.callback(buttonName, id); 121 }, 122 item.id 123 ); 124 } 56 125 } 57 126 </script> -
main/trunk/model-interfaces-dev/atea/resources/interface_atea.properties
r35761 r35762 68 68 atea.ocr.OCREditedModal_Description=It looks like you've edited the OCR result, and running it again will remove these edits. 69 69 atea.ocr.OCREditedModal_Title=Are you sure? 70 71 atea.ocr.DiscardEditsModal_ButtonCancel=Cancel 72 atea.ocr.DiscardEditsModal_ButtonContinue=Continue 73 atea.ocr.DiscardEditsModal_Description=You have edited the image. Are you sure you want to discard your changes? 74 atea.ocr.DiscardEditsModal_Title=Discard Changes?
Note:
See TracChangeset
for help on using the changeset viewer.