Grammalecte  Check-in [fd372b5786]

Overview
Comment:[fx] dictionaries manager: update
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | comdic
Files: files | file ages | folders
SHA3-256: fd372b578628dadfb933da6507517550c09760768d6fe57e444cba38caa67b2d
User & Date: olr on 2019-02-12 19:58:49
Other Links: branch diff | manifest | tags
Context
2019-02-13
19:53
[fx] dictionaries manager: update check-in: 50fe201fc1 user: olr tags: comdic, fx
2019-02-12
19:58
[fx] dictionaries manager: update check-in: fd372b5786 user: olr tags: comdic, fx
2019-02-10
00:31
[core][js] echo function for debugging check-in: bcd8a483d5 user: olr tags: comdic, core
Changes

Modified gc_lang/fr/webext/manifest.json from [8ca9ed57ec] to [f83d1e1e3e].

   128    128     ],
   129    129   
   130    130     "permissions": [
   131    131       "*://localhost/*",
   132    132       "*://dic.grammalecte.net/*",
   133    133       "activeTab",
   134    134       "contextMenus",
          135  +    "cookies",
   135    136       "downloads",
   136    137       "storage"
   137    138     ],
   138    139   
   139    140     "chrome_settings_overrides": {
   140    141       "search_provider": {
   141    142         "name": "Grammalecte",

Modified gc_lang/fr/webext/panel/dictionaries.css from [f2b5daf12c] to [11fa8484fe].

    29     29       width: 800px;
    30     30       margin: 20px auto 10px auto;
    31     31       padding: 10px 30px 30px 30px;
    32     32       background: hsl(0, 0%, 100%);
    33     33       border: 2px solid hsl(210, 0%, 90%);
    34     34       border-radius: 20px;
    35     35   }
           36  +
           37  +
           38  +#message_box {
           39  +    display: none;
           40  +    position: fixed;
           41  +    top: 33%;
           42  +    left: calc(50% - 325px);
           43  +}
           44  +#message {
           45  +    display: inline-block;
           46  +    padding: 1px 10px;
           47  +    width: 600px;
           48  +    background-color: hsl(0, 50%, 50%);
           49  +    color: hsl(0, 50%, 98%);
           50  +    border-style: solid;
           51  +    border-width: 2px 0 2px 2px;
           52  +    border-color: hsl(0, 50%, 40%);
           53  +    border-radius: 3px 0 0 3px;
           54  +}
           55  +#message_close_button {
           56  +    display: inline-block;
           57  +    padding: 1px 5px;
           58  +    background-color: hsl(0, 50%, 40%);
           59  +    color: hsl(0, 90%, 90%);
           60  +    border-style: solid;
           61  +    border-width: 2px 2px 2px 0;
           62  +    border-color: hsl(0, 50%, 30%);
           63  +    border-radius: 0 3px 3px 0;
           64  +    cursor: pointer;
           65  +}
           66  +
    36     67   
    37     68   h1 {
    38     69       margin: 5px 0 5px 0;
    39     70       color: hsl(210, 50%, 50%);
    40         -    font: bold 30px "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
    41         -    text-align: center;
           71  +    font: bold 24px "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
    42     72   }
    43     73   h2 {
    44     74       margin: 10px 0 2px 0;
    45     75       color: hsl(0, 50%, 50%);
    46     76       font: bold 20px "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif;
    47     77   }
    48     78   
    49     79   
    50         -/*
    51         -    Main buttons
    52         -*/
    53         -
    54         -ul {
    55         -    margin-left: 30px;
    56         -}
    57         -
    58     80   input[type=text].large {
    59     81       display: inline-block;
    60     82       width: 250px;
    61     83       padding: 5px 10px;
    62     84       border: 2px solid hsl(0, 0%, 80%);
    63     85       border-radius: 3px;
    64     86       height: 24px;
................................................................................
    79    101       color: hsl(0, 0%, 20%);
    80    102   }
    81    103   
    82    104   input[placeholder] {
    83    105       color: hsl(0, 0%, 50%);
    84    106   }
    85    107   
          108  +
          109  +#connect_panel {
          110  +    background-color: hsl(210, 50%, 90%);
          111  +    border-radius: 5px;
          112  +    padding: 3px 10px;
          113  +}
          114  +#submit_button {
          115  +    display: inline-block;
          116  +    padding: 1px 5px;
          117  +    background-color: hsl(210, 50%, 30%);
          118  +    color: hsl(210, 0%, 100%);
          119  +    border-radius: 3px;
          120  +    cursor: pointer;
          121  +}
          122  +
    86    123   
    87    124   .dic_button {
    88    125       margin: 2px;
    89    126       display: inline-block;
    90    127   }
    91    128   .dic_button_close {
    92    129       display: inline-block;

Modified gc_lang/fr/webext/panel/dictionaries.html from [2c8f4ed726] to [7f63251ae3].

     4      4       <link rel="stylesheet" type="text/css" href="dictionaries.css" />
     5      5       <title>Grammalecte · Dictionnaires communautaires</title>
     6      6       <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
     7      7     </head>
     8      8   
     9      9     <body>
    10     10   
    11         -    <div class="inbox">
           11  +    <div id="message_box">
           12  +      <div id="message">[néant]</div><div id="message_close_button">×</div>
           13  +    </div>
    12     14   
    13         -      <h1>Dictionnaires communautaires</h1>
           15  +    <div class="inbox">
           16  +      <h1>Grammalecte · Dictionnaires communautaires</h1>
    14     17   
    15         -        <div id="connect_panel">
    16         -            <div id="connect_form">
    17         -                <div>Inscription</div>
    18         -                <p>Vous n’êtes pas identifié.</p>
    19         -                <p>
    20         -                    <label value="E-mail"><input type="text" name="email"></label>
    21         -                    <label value="Mot de passe"><input type="password" name="pw"></label>
    22         -                    <div id="submit_button">Envoyer</div>
    23         -                </p>
    24         -            </div>
    25         -            <div id="connect_info">
    26         -                <p>
    27         -                    Identifiants : <span id="login_label"> </span>, <span id="email_label"> </span>
    28         -                </p>
    29         -            </div>
           18  +      <div id="connect_panel">
           19  +        <form id="connect_form" method="post" enctype="multipart/form-data">
           20  +          <p>
           21  +            Non connecté.
           22  +            <label for="email">E-mail : </label> <input type="text" id="email" name="email" />
           23  +            <label for="password">Mot de passe : </label> <input type="password" id="pw" name="pw" />
           24  +            <span id="submit_button">Se connecter</span>
           25  +            |
           26  +            <a href="http://dic.grammalecte.net" target="_blank">Inscription</a>
           27  +          </p>
           28  +        </form>
           29  +        <div id="connect_info">
           30  +          <p>
           31  +            Connecté. Identifiants : <span id="login_label"> </span>, <span id="email_label"> </span>
           32  +          </p>
    30     33           </div>
           34  +      </div>
    31     35   
    32         -        <div id="apply" class="apply">Appliquer les modifications</div>
    33         -        <h2>Dictionnaires sélectionnés</h2>
    34         -        <p id="dictionaries_list">[Aucun]<p>
           36  +      <h2>Dictionnaires sélectionnés</h2>
           37  +      <p id="dictionaries_list">[Aucun]<p>
    35     38   
    36         -
    37         -        <h2><span id="num_dic">0</span> dictionnaires disponibles</h2>
    38         -        <progress id="wait_progress" value="0"></progress>
    39         -        <table id="dictionaries_table">
    40         -        </table>
    41         -
    42         -    </div>
           39  +      <div id="apply" class="apply">Appliquer les modifications</div>
           40  +      <h2><span id="num_dic">0</span> dictionnaires disponibles</h2>
           41  +      <progress id="wait_progress" value="0"></progress>
           42  +      <table id="dictionaries_table">
           43  +      </table>
           44  +    </div> <!-- inbox -->
    43     45   
    44     46   
    45     47       <script src="../grammalecte/graphspell/helpers.js"></script>
    46     48       <script src="../grammalecte/graphspell/char_player.js"></script>
    47     49       <script src="../grammalecte/graphspell/str_transform.js"></script>
    48     50       <script src="../grammalecte/graphspell/dawg.js"></script>
    49     51       <script src="../grammalecte/graphspell/ibdawg.js"></script>
    50     52       <script src="../grammalecte/graphspell/dic_merger.js"></script>
    51     53       <script src="../grammalecte/graphspell/spellchecker.js"></script>
    52     54       <script src="dictionaries.js"></script>
    53     55     </body>
    54     56   
    55     57   </html>

Modified gc_lang/fr/webext/panel/dictionaries.js from [66c74db008] to [0bbd846388].

    54     54       let msgBuffer = new TextEncoder('utf-8').encode(sText);
    55     55       let hashBuffer = await crypto.subtle.digest(sAlgorithm, msgBuffer);
    56     56       let hashArray = Array.from(new Uint8Array(hashBuffer));
    57     57       return hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
    58     58   }
    59     59   
    60     60   
    61         -oConnect = {
           61  +const oMessage = {
           62  +    show: function (sMessage, nDelay=10000) {
           63  +        document.getElementById("message").textContent = sMessage;
           64  +        showElement("message_box");
           65  +        window.setTimeout(this.close, nDelay);
           66  +    },
           67  +
           68  +    listen: function () {
           69  +        document.getElementById("message_close_button").addEventListener("click", (xEvent) => { this.close(); });
           70  +    },
           71  +
           72  +    close: function () {
           73  +        hideElement("message_box");
           74  +    }
           75  +}
           76  +
           77  +
           78  +const oConnect = {
    62     79       bConnected: false,
    63     80   
    64     81       init: function () {
    65     82           if (bChrome) {
    66         -            browser.storage.local.get("credentials", this._init().bind(this));
           83  +            browser.cookies.getAll({ domain: "localhost" }, this._init.bind(this));
    67     84               return;
    68     85           }
    69         -        let xPromise = browser.storage.local.get("credentials");
           86  +        let xPromise = browser.cookies.getAll({ domain: "localhost" });
    70     87           xPromise.then(this._init.bind(this), showError);
    71     88       },
    72     89   
    73         -    _init: function (oData) {
    74         -        if (oData.hasOwnProperty("credentials")) {
    75         -            hideElement("connect_form");
    76         -            showElement("connect_info");
           90  +    _init: function (lData) {
           91  +        for (let xCookie of lData) {
           92  +            console.log(xCookie.name, xCookie.value);
    77     93               this.bConnected = true;
    78     94           }
    79         -        else {
           95  +        if (this.bConnected) {
    80     96               hideElement("connect_form");
    81     97               showElement("connect_info");
    82     98           }
           99  +        else {
          100  +            showElement("connect_form");
          101  +            hideElement("connect_info");
          102  +        }
    83    103       },
    84    104   
    85    105       listen: function () {
    86         -        document.getElementById("submit_button").addEventListener("click", (xEvent) => { this.connect() });
          106  +        document.getElementById("submit_button").addEventListener("click", (xEvent) => { this.connect(); });
    87    107       },
    88    108   
    89    109       connect: function () {
    90         -        let sEmail = document.getElementById("email").value;
    91         -        let sPassword = document.getElementById("password").value;
    92         -        console.log(sEmail, sPassword);
          110  +        let xForm = new FormData(document.getElementById('connect_form'));
          111  +        for (let [k, v] of xForm.entries()) {
          112  +            console.log("* ", k, v);
          113  +        }
          114  +        oMessage.show("TEST");
          115  +        fetch("http://localhost/connect/", {
          116  +            method: "POST", // *GET, POST, PUT, DELETE, etc.
          117  +            //mode: "cors", // no-cors, cors, *same-origin
          118  +            //cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
          119  +            /*headers: {
          120  +                "Content-Type": "multipart/form-data",  // text/plain, application/json
          121  +            },*/
          122  +            credentials: "omit", // include, *same-origin, omit
          123  +            body: xForm
          124  +        })
          125  +        .then((response) => {
          126  +            if (response.ok) {
          127  +                for (let param in response) {
          128  +                    console.log(param, response[param]);
          129  +                }
          130  +                console.log(response.body);
          131  +                return response.json();
          132  +            } else {
          133  +                for (let param in response) {
          134  +                    console.log(param, response[param]);
          135  +                }
          136  +                return null;
          137  +            }
          138  +        })
          139  +        .then((response) => {
          140  +            if (response) {
          141  +                console.log(response);
          142  +            } else {
          143  +                console.log(response);
          144  +            }
          145  +        })
          146  +        .catch((e) => {
          147  +            showError(e);
          148  +        });
    93    149       }
    94    150   }
    95    151   
    96    152   
    97    153   class Table {
    98    154   
    99    155       constructor (sNodeId, lColumn, sProgressBarId, sResultId="", bDeleteButtons=true, bActionButtons) {
................................................................................
   352    408           browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oDict}, dInfo: {} });
   353    409       }
   354    410   }
   355    411   
   356    412   const oDicTable = new Table("dictionaries_table", ["Nom", "Entrées", "Description", "Date"], "wait_progress", "num_dic", false, true);
   357    413   
   358    414   oDicTable.init();
          415  +
          416  +oMessage.listen();
   359    417   
   360    418   oConnect.init();
   361    419   oConnect.listen();