Grammalecte  Check-in [00eca59ea8]

Overview
Comment:[fx] update: lexicon editor
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 00eca59ea84e81acce02c741816ad09b5049af3273fb606607bf350a017fecfc
User & Date: olr on 2018-02-07 16:39:14
Other Links: manifest | tags
Context
2018-02-07
16:53
[graphspell] remove private useless vars from JSON dictionary files check-in: ad404457eb user: olr tags: trunk, graphspell
16:39
[fx] update: lexicon editor check-in: 00eca59ea8 user: olr tags: trunk, fx
16:38
[graphspell][js] update for dawg: export as JSON check-in: 29e54c7426 user: olr tags: trunk, graphspell
Changes

Modified gc_lang/fr/webext/panel/lex_editor.html from [eb294b7932] to [07c19d863f].

299
300
301
302
303
304
305

306
307
308
309
310
311
            </div>
        </div>


        <script src="../grammalecte/graphspell/helpers.js"></script>
        <script src="../grammalecte/graphspell/str_transform.js"></script>
        <script src="../grammalecte/graphspell/dawg.js"></script>

        <script src="../grammalecte/fr/conj.js"></script>
        <script src="lex_conj_data.js"></script>
        <script src="lex_editor.js"></script>
    </body>
    
</html>







>






299
300
301
302
303
304
305
306
307
308
309
310
311
312
            </div>
        </div>


        <script src="../grammalecte/graphspell/helpers.js"></script>
        <script src="../grammalecte/graphspell/str_transform.js"></script>
        <script src="../grammalecte/graphspell/dawg.js"></script>
        <script src="../grammalecte/graphspell/ibdawg.js"></script>
        <script src="../grammalecte/fr/conj.js"></script>
        <script src="lex_conj_data.js"></script>
        <script src="lex_editor.js"></script>
    </body>
    
</html>

Modified gc_lang/fr/webext/panel/lex_editor.js from [0ed08aafe8] to [8312ea2175].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


document.getElementById("lexicon_button").addEventListener("click", () => { oWidgets.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oWidgets.showPage("lemma"); }, false);

document.getElementById("table").addEventListener("click", (xEvent) => { oWidgets.onTableClick(xEvent); }, false);
document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);
document.getElementById("export_button").addEventListener("click", () => { oDict.export(); }, false);

document.getElementById("editor").addEventListener("click", (xEvent) => { oWidgets.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oWidgets.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oWidgets.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlexGen.update(); }, false);







|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


document.getElementById("lexicon_button").addEventListener("click", () => { oWidgets.showPage("lexicon"); }, false);
document.getElementById("add_word_button").addEventListener("click", () => { oWidgets.showPage("lemma"); }, false);

document.getElementById("table").addEventListener("click", (xEvent) => { oWidgets.onTableClick(xEvent); }, false);
document.getElementById("save_button").addEventListener("click", () => { oLexicon.save(); }, false);
document.getElementById("export_button").addEventListener("click", () => { oBinaryDict.export(); }, false);

document.getElementById("editor").addEventListener("click", (xEvent) => { oWidgets.onSelectionClick(xEvent); }, false);
document.getElementById("lemma").addEventListener("keyup", () => { oWidgets.onWrite(); }, false);
document.getElementById("lemma2").addEventListener("keyup", () => { oWidgets.onWrite2(); }, false);
document.getElementById("verb_pattern").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("flexion").addEventListener("keyup", () => { oFlexGen.update(); }, false);
document.getElementById("tags").addEventListener("keyup", () => { oFlexGen.update(); }, false);
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535






536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

608
609
610
611
612
613
614
615
616
617
618
619


620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
        let xPromise = browser.storage.local.get("oLexicon");
        xPromise.then(this._load.bind(this), showError);
    },

    _load: function (oResult) {
        if (oResult.hasOwnProperty("oLexicon")) {
            this.lFlexion = oResult.oLexicon.lEntry;
            oWidgets.setDictData(this.lFlexion, oResult.oLexicon.sDate);    
            oWidgets.displayTable(this.lFlexion);
        }
        if (this.lFlexion.length > 0) {
            oWidgets.showElement("export_button");
        } else {
            oWidgets.hideElement("export_button");
        }
    },







    addFlexions: function (lFlex) {
        let n = lFlex.length;
        for (let aFlex of lFlex) {
            this.lFlexion.push(aFlex);
        }
        this.nAddedEntries += n;
        this.nEntries += n;
        oWidgets.addEntriesToTable(n, lFlex);
    },

    deleteEntry: function (iEntry) {
        this.lFlexion[parseInt(iEntry)] = null;
        this.nDeletedEntries++;
        this.nEntries--;
    },

    resetData: function () {

        this.nAddedEntries = 0;
        this.nDeletedEntries = 0;
        this.nEntries = this.lFlexion.length;
    },

    save: function () {
        oWidgets.hideElement("save_button");
        let lEntry = [];
        for (let e of this.lFlexion) {
            if (e !== null) {
                lEntry.push(e);
            }
        }
        let sDate = this._getDate();
        browser.storage.local.set({ "oLexicon": {"lEntry": lEntry, "sDate": sDate} });
        this.lFlexion = lEntry;
        oDict.build(lEntry);
        this.resetData();
        oWidgets.displayTable(this.lFlexion);
        oWidgets.updateData();
        oWidgets.setDictData(lEntry.length, sDate);
    },

    _getDate: function () {
        let oDate = new Date();
        let sMonth = (oDate.getMonth() + 1).toString().padStart(2, "0"); // Month+1: Because JS always sucks somehow.
        let sDay = (oDate.getDay()).toString().padStart(2, "0");
        let sHours = (oDate.getHours()).toString().padStart(2, "0");
        let sMinutes = (oDate.getMinutes()).toString().padStart(2, "0");
        return `${oDate.getFullYear()}-${sMonth}-${sDay}, ${sHours}:${sMinutes}`;
    }
}


const oDict = {

    oJSON: null,

    load: function () {
        if (bChrome) {
            browser.storage.local.get("oDictionary", this._load);
            return;
        }
        let xPromise = browser.storage.local.get("oDictionary");
        xPromise.then(this._load.bind(this), showError);
    },

    _load: function (oResult) {
        if (oResult.hasOwnProperty("oDictionary")) {
            this.oJSON = oResult.oDictionary;
            oWidgets.showElement("export_button");
        } else {
            oWidgets.hideElement("export_button");
        }

    },

    build: function (lEntry) {
        oWidgets.showElement("build_progress");
        let xProgressNode = document.getElementById("build_progress");
        let oDAWG = new DAWG(lEntry, "Français - dictionnaire personnel", "S", xProgressNode);
        this.oJSON = oDAWG.createBinary(1);
        this.save();
        oWidgets.hideElement("build_progress");
        oWidgets.showElement("export_button");
        // debug
        let lMorph = oDAWG.morph("finis");


        console.log(lMorph);
    },

    save: function () {
        browser.storage.local.set({ "oDictionary": this.oJSON });
    },

    import: function () {
        // TO DO
    },

    export: function () {
        let xBlob = new Blob([ JSON.stringify(this.oJSON) ], {type: 'application/json'}); 
        let sURL = URL.createObjectURL(xBlob);
        browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true });
    }
}


oLexicon.load();







|








>
>
>
>
>
>

















|
>


<













|
|
















|
|


















>











|
>
>
|

















<
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
        let xPromise = browser.storage.local.get("oLexicon");
        xPromise.then(this._load.bind(this), showError);
    },

    _load: function (oResult) {
        if (oResult.hasOwnProperty("oLexicon")) {
            this.lFlexion = oResult.oLexicon.lEntry;
            oWidgets.setDictData(this.lFlexion.length, oResult.oLexicon.sDate);
            oWidgets.displayTable(this.lFlexion);
        }
        if (this.lFlexion.length > 0) {
            oWidgets.showElement("export_button");
        } else {
            oWidgets.hideElement("export_button");
        }
    },

    set: function (lFlexion) {
        this.lFlexion = lFlexion; // clear the array
        this.resetModif();
        oWidgets.displayTable(this.lFlexion);
    },

    addFlexions: function (lFlex) {
        let n = lFlex.length;
        for (let aFlex of lFlex) {
            this.lFlexion.push(aFlex);
        }
        this.nAddedEntries += n;
        this.nEntries += n;
        oWidgets.addEntriesToTable(n, lFlex);
    },

    deleteEntry: function (iEntry) {
        this.lFlexion[parseInt(iEntry)] = null;
        this.nDeletedEntries++;
        this.nEntries--;
    },

    resetModif: function () {
        this.nEntries = this.lFlexion.length;
        this.nAddedEntries = 0;
        this.nDeletedEntries = 0;

    },

    save: function () {
        oWidgets.hideElement("save_button");
        let lEntry = [];
        for (let e of this.lFlexion) {
            if (e !== null) {
                lEntry.push(e);
            }
        }
        let sDate = this._getDate();
        browser.storage.local.set({ "oLexicon": {"lEntry": lEntry, "sDate": sDate} });
        this.lFlexion = lEntry;
        oBinaryDict.build(lEntry);
        this.resetModif();
        oWidgets.displayTable(this.lFlexion);
        oWidgets.updateData();
        oWidgets.setDictData(lEntry.length, sDate);
    },

    _getDate: function () {
        let oDate = new Date();
        let sMonth = (oDate.getMonth() + 1).toString().padStart(2, "0"); // Month+1: Because JS always sucks somehow.
        let sDay = (oDate.getDay()).toString().padStart(2, "0");
        let sHours = (oDate.getHours()).toString().padStart(2, "0");
        let sMinutes = (oDate.getMinutes()).toString().padStart(2, "0");
        return `${oDate.getFullYear()}-${sMonth}-${sDay}, ${sHours}:${sMinutes}`;
    }
}


const oBinaryDict = {
    // 
    oJSON: null,

    load: function () {
        if (bChrome) {
            browser.storage.local.get("oDictionary", this._load);
            return;
        }
        let xPromise = browser.storage.local.get("oDictionary");
        xPromise.then(this._load.bind(this), showError);
    },

    _load: function (oResult) {
        if (oResult.hasOwnProperty("oDictionary")) {
            this.oJSON = oResult.oDictionary;
            oWidgets.showElement("export_button");
        } else {
            oWidgets.hideElement("export_button");
        }
        //oLexicon.set();
    },

    build: function (lEntry) {
        oWidgets.showElement("build_progress");
        let xProgressNode = document.getElementById("build_progress");
        let oDAWG = new DAWG(lEntry, "Français - dictionnaire personnel", "S", xProgressNode);
        this.oJSON = oDAWG.createBinary(1);
        this.save();
        oWidgets.hideElement("build_progress");
        oWidgets.showElement("export_button");
        // debug
        console.log(oDAWG.morph("finis"));
        let oIBDAWG = new IBDAWG(this.oJSON);
        let lEntry2 = oIBDAWG.select();
        console.log(lEntry2);
    },

    save: function () {
        browser.storage.local.set({ "oDictionary": this.oJSON });
    },

    import: function () {
        // TO DO
    },

    export: function () {
        let xBlob = new Blob([ JSON.stringify(this.oJSON) ], {type: 'application/json'}); 
        let sURL = URL.createObjectURL(xBlob);
        browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true });
    }
}


oBinaryDict.load();