Grammalecte  Check-in [84a72ba4e1]

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: 84a72ba4e1602ff8787da37b88acf9678a8a6b84a84d0e3fd5473898d7604263
User & Date: olr on 2018-02-07 13:58:39
Other Links: manifest | tags
Context
2018-02-07
14:49
[graphspell][js] ibdawg: constructor with data object check-in: 78b42e9b7f user: olr tags: trunk, graphspell
13:58
[fx] update: lexicon editor check-in: 84a72ba4e1 user: olr tags: trunk, fx
13:57
[graphspell][bug] dawg: conversion to binary string check-in: a25340628a user: olr tags: trunk, graphspell
Changes

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

271
272
273
274
275
276
277
278
279
280



281
282
283
284
285
286
287
288
289
290


291
292
293
294
295
296
297
271
272
273
274
275
276
277



278
279
280
281
282
283
284
285
286
287
288


289
290
291
292
293
294
295
296
297







-
-
-
+
+
+








-
-
+
+







                <h2>Votre lexique</h2>

                <div class="button_block">
                    <div id="save_button" class="fright">
                        Enregistrer
                    </div>
                    <h3>Lexique</h3>
                    <p>Nombre d’entrées ajoutées : <i id="num_added_entries">0</i>.</p>
                    <p>Nombre d’entrées supprimées : <i id="num_deleted_entries">0</i>.</p>
                    <p>Nombre d’entrées : <i id="num_entries">0</i>.</p>
                    <p>Nombre d’entrées ajoutées : <span id="num_added_entries">0</span>.</p>
                    <p>Nombre d’entrées supprimées : <span id="num_deleted_entries">0</span>.</p>
                    <p>Nombre d’entrées : <span id="num_entries">0</span>.</p>
                    <p><progress id="build_progress" value="0"></p>
                    <div id="export_button" class="fright">
                        Exporter
                    </div>
                    <div id="import_button" class="fright">
                        Importer
                    </div>
                    <h3>Dictionnaire enregistré</h3>
                    <p>Dernière sauvegarde : <i id="save_date">néant</i>.</p>
                    <p>Nombre d’entrées : <i id="num_entries_saved">0</i>.</p>
                    <p>Dernière sauvegarde : <span id="save_date">néant</span>.</p>
                    <p>Nombre d’entrées : <span id="num_entries_saved">0</span>.</p>
                </div>
                

                <p id="no_elem_line">Aucun élément.</p>

                <table id="table">
                    

Modified gc_lang/fr/webext/panel/lex_editor.js from [84567c7948] to [0ed08aafe8].

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
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", () => { oLexicon.export(); }, 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);
510
511
512
513
514
515
516
517

518
519
520

521
522
523
524
525
526
527




528
529
530
531
532
533
534
510
511
512
513
514
515
516

517
518
519

520
521
522
523




524
525
526
527
528
529
530
531
532
533
534







-
+


-
+



-
-
-
-
+
+
+
+







    lFlexion: [],
    nEntries: 0,
    nDeletedEntries: 0,
    nAddedEntries: 0,

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

    _load: function (dResult) {
        if (dResult.hasOwnProperty("lexicon")) {
            this.lFlexion = dResult.lexicon.lEntry;
            oWidgets.setDictData(this.lFlexion, dResult.lexicon.sDate);    
    _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");
        }
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
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 lEntry = [];
        for (let e of this.lFlexion) {
            if (e !== null) {
                lEntry.push(e);
            }
        }
        let sDate = this._getDate();
        browser.storage.local.set({ "lexicon": {"lEntry": lEntry, "sDate": sDate} });
        browser.storage.local.set({ "oLexicon": {"lEntry": lEntry, "sDate": sDate} });
        this.lFlexion = lEntry;
        this.build();
        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(); // Because JS always sucks somehow.
        let sMonth = (oDate.getMonth() + 1).toString().padStart(2, "0"); // Month+1: Because JS always sucks somehow.
        if (sMonth.length == 1) sMonth =  "0" + sMonth;
        let sDay = (oDate.getDay() < 10) ? "0"+oDate.getDay() : oDate.getDay();
        return `${oDate.getFullYear()}-${sMonth}-${sDay} (${oDate.getHours()}:${oDate.getMinutes()})`;
        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 () {
    build: function (lEntry) {
        oWidgets.showElement("build_progress");
        let xProgressNode = document.getElementById("build_progress");
        let oDAWG = new DAWG(this.lFlexion, "Français - dictionnaire personnel", "S", xProgressNode);
        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);
    },

    export: function () {
    save: function () {
        let xBlob = new Blob(['{ "app": "grammalecte", "data": ' + JSON.stringify(this.lFlexion) + ' }'], {type: 'application/json'}); 
        let sURL = URL.createObjectURL(xBlob);
        browser.downloads.download({ filename: "grammalecte_dictionnaire_personnel.json", url: sURL, saveAs: true });
        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();