diff options
author | ache <ache@ache.one> | 2019-01-30 23:51:57 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2019-01-30 23:51:57 +0100 |
commit | d5608829b28e8e833435fe4ec93565a93a89d764 (patch) | |
tree | 763395f4777390f98d72934a5c127b71f54c7520 | |
parent | New base (diff) |
New code
-rw-r--r-- | package.json | 7 | ||||
-rw-r--r-- | src/app.mjs | 12 | ||||
-rw-r--r-- | src/views/index.html | 12 | ||||
-rw-r--r-- | static/synhestesis.js | 3 |
4 files changed, 20 insertions, 14 deletions
diff --git a/package.json b/package.json index 30810bb..7f83448 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A apprentissage tool", "main": "src/app.js", "scripts": { - "start": "node src/app.js", + "start": "node src/app.mjs", "pretest": "xo", "test": "ava" }, @@ -23,6 +23,9 @@ "xo": "^0.24.0" }, "dependencies": { - "expres": "0.0.5" + "expres": "0.0.5", + "express": "^4.16.4", + "fs": "0.0.1-security", + "mustache-express": "^1.2.8" } } diff --git a/src/app.mjs b/src/app.mjs index 2903c58..94e0604 100644 --- a/src/app.mjs +++ b/src/app.mjs @@ -1,5 +1,6 @@ 'use-strict'; +const fs = require('fs'); const express = require('express'); const mustache = require('mustache-express'); const path = require('path'); @@ -10,11 +11,18 @@ app.engine('html', mustache()); app.set('view engine', 'html'); app.set('views',path.join(__dirname, 'views')); -app.use(express.static('default')); +app.use('/default', express.static('default')); app.use(express.static('static')); app.get('/', (req, res) => { - res.render('index.html', {yourdata: 'Hello from Mustache Template'}); + + const listFile = fs.readdirSync("./default"); + const options = listFile.map( file => { + const text = file.replace('.json', ''); + return `<option value="${file}">${text}</option>`; + }); + console.log(options); + res.render('index', {listFile: options.join('')}); }); const server = app.listen(8100, () => { diff --git a/src/views/index.html b/src/views/index.html index f64e470..d501638 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -3,7 +3,6 @@ <head>
<meta charset="utf-8" />
<title>Synhestesis - Test</title>
- </head>
<style type="text/css">
div.fileinputs {
position: relative;
@@ -27,22 +26,17 @@ z-index: 2;
}
</style>
+ </head>
<body>
<div style="margin-top:5%;margin-left:auto;margin-right:auto;width:80%;height:100px;z-index:4;" id="onTop">
<span id="compteur"></span>
<span id="ratio"></span>
<div class="fileinputs">
- <input type="file" class="file" id="getFile" />
+ <input type="file" id="getFile" />
- <div class="fakefile">
- <input type="button" value="Open" />
- </div>
<select name="select" id="select">
- <option value="hiragana_romaji.json">Hiragana</option>
- <option value="katakana_romaji.json">Katakana</option>
- <option value="capitale_EU.json">Capitales Européennes</option>
- <option value="vocab_jap.json">Vocabulaire japonais</option>
+ {{{listFile}}}
</select>
</div>
</div>
diff --git a/static/synhestesis.js b/static/synhestesis.js index 3696c5a..209e896 100644 --- a/static/synhestesis.js +++ b/static/synhestesis.js @@ -29,12 +29,13 @@ function selectChange(evt) { resetButt.value = "Reset"; var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { loadFile(xmlHttp.responseText); } } - xmlHttp.open("GET", "http://ache.one/shared/synhestesis/" +select.options[select.selectedIndex].value, true); + xmlHttp.open("GET", "/default/" + select.options[select.selectedIndex].value, true); xmlHttp.send(null); } function loadFile( str ) { |