@@ -2,17 +2,24 @@ import { addImageOcclusionNotes } from "./lib";
22import { getAnswerMaskColor } from "./tools/lib" ;
33import { noteFieldsData , tagsWritable } from "./store" ;
44import { get } from "svelte/store" ;
5+ import Toast from "./Toast.svelte" ;
6+ import * as tr from "@tslib/ftl" ;
57
6- let divData = [ "type" , "left" , "top" , "width" , "height" , "fill" , "stroke" , "strokeWidth" , "angle" , "radius" , "startAngle" , "endAngle" , "rx" , "ry" , "points" ] ;
8+ let divData = [ "type" , "left" , "top" , "width" , "height" , "fill" , "stroke" , "strokeWidth" , "angle" , "radius" , "startAngle" , "endAngle" , "rx" , "ry" , "points" , "text" , "fontSize" , "fontFamily" ] ;
79
810export function generate ( imagePath : string , generateTye : string , deckId : number ) : void {
911 let canvas = globalThis . canvas ;
1012 let canvasObjects = canvas . getObjects ( ) ;
13+ if ( canvasObjects . length < 1 ) {
14+ return ;
15+ }
1116
1217 let occlusionNotes = `<div id='io_cloze' data-answer-mask-color='${ getAnswerMaskColor ( ) } '>` ;
1318 let clozeDiv = "" ;
19+ let count = 0 ;
1420
1521 canvasObjects . forEach ( ( object , index ) => {
22+ count ++ ;
1623 let obJson = object . toJSON ( ) ;
1724 if ( obJson . type === "group" ) {
1825 clozeDiv += getGroupCloze ( object , index , generateTye ) ;
@@ -24,7 +31,7 @@ export function generate(imagePath: string, generateTye: string, deckId: number)
2431 occlusionNotes += clozeDiv + "</div>" ;
2532 console . log ( occlusionNotes ) ;
2633
27- saveImageNotes ( imagePath , occlusionNotes , deckId ) ;
34+ saveImageNotes ( imagePath , occlusionNotes , deckId , count ) ;
2835}
2936
3037const getCloze = ( object , index , generateTye , relativePos ) => {
@@ -74,6 +81,7 @@ const saveImageNotes = async function (
7481 imagePath : string ,
7582 occlusions : string ,
7683 deckId : number ,
84+ count : number ,
7785) {
7886 const fieldsData = get ( noteFieldsData ) ;
7987 const tags = get ( tagsWritable ) ;
@@ -90,5 +98,25 @@ const saveImageNotes = async function (
9098 notes = textArea . value ; ;
9199 }
92100
93- await addImageOcclusionNotes ( imagePath , deckId , occlusions , header , notes , tags ) ;
101+ let result = await addImageOcclusionNotes ( imagePath , deckId , occlusions , header , notes , tags ) ;
102+ showResult ( result , count ) ;
94103} ;
104+
105+ // show toast message
106+ const showResult = ( result , count ) => {
107+ const toastComponent = new Toast ( {
108+ target : document . body ,
109+ props : {
110+ message : "" ,
111+ type : "error" ,
112+ }
113+ } ) ;
114+
115+ if ( result . note ) {
116+ let msg = tr . importingNoteAdded ( { count : count } ) ;
117+ toastComponent . $set ( { message : msg , type : "success" , showToast : true } ) ;
118+ } else {
119+ let msg = tr . editingErrorGeneratingCloze ( ) ;
120+ toastComponent . $set ( { message : msg , showToast : true } ) ;
121+ }
122+ }
0 commit comments