diff --git a/projet/front/element-style.js b/projet/front/element-style.js index dbb99c553fa70625ad0210d4880523c8e467d6ae..e61144cb28e5056ef6d00b6d5a21b55d99a81399 100644 --- a/projet/front/element-style.js +++ b/projet/front/element-style.js @@ -1,5 +1,5 @@ function new_file(file_name, file_id) { - content = ` + content = ` <div class="file" id="${file_id}"> <p> <button> @@ -9,17 +9,19 @@ function new_file(file_name, file_id) { </p> </div> ` - document.getElementById("drive").append(content); + document.getElementById("content-drive").innerHTML += content; } -function new_folder (folder_name) { +function new_folder (folder_name, path) { content = ` <div class="folder"> <p> - <button><img src="/images/folder_img.png" height="50px"></button> + <button onclick="change_path('${path}')"> + <img src="/images/folder_img.png" height="50px"> + </button> <p>${folder_name}</p> </p> </div> `; - document.getElementById("drive").append(content); + document.getElementById("content-drive").innerHTML += content; } \ No newline at end of file diff --git a/projet/front/index.html b/projet/front/index.html index 06ad4f90a449e2535bfb1f1d6478ccf8b1ef14fa..fd89ca14eeb248b5888b47eb1b8d15628fb3b96c 100644 --- a/projet/front/index.html +++ b/projet/front/index.html @@ -6,6 +6,7 @@ <link rel="stylesheet" type="text/css" href="/styles/style.css"> <script src="jquery-3.4.1.min.js"></script> <script src="element-style.js"></script> + <script src="show-content.js"></script> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> @@ -14,13 +15,16 @@ <div id="hyperdrive"> <div id="menu"> <h3>Menu</h3> - <button><img src="/images/file_img.png" height="50px"></button> + <input type="text" id="username"> + <input type="password" id="passwd"> + <button onclick="login()">Login</button> </div> <div id="drive"> <h3>Drive</h3> - <script type="javascript"> - - </script> + <p id="dir_name"></p> + <div id="content-drive"> + + </div> </div> <div id="info"> <h3>Infos</h3> diff --git a/projet/front/show-content.js b/projet/front/show-content.js new file mode 100644 index 0000000000000000000000000000000000000000..3c0c1542e671729cb4a2439544e514b9724cd2b9 --- /dev/null +++ b/projet/front/show-content.js @@ -0,0 +1,32 @@ +"use strict"; + +function change_path(path){ + document.getElementById("content-drive").innerHTML = ""; + $.ajax({url: 'change-path'+path, success: function(result){ + console.log(result); + document.getElementById("dir_name").innerHTML = "Directory : " + path; + for (let i in result){ + if (result[i].file_id){ + new_file(result[i].file_name, result[i].file_id); + } else { + if (path !== result[i].paths){ + let name = result[i].paths.split("/"); + new_folder(name[name.length-1], result[i].paths); + } + } + } + }}); +} + +function login() { + let username = document.getElementById("username").value + let passwd = document.getElementById("passwd").value + console.log("login", + username, + passwd + ); + let log_ok = true; + if (log_ok) { + change_path('/' + username) + } +} \ No newline at end of file diff --git a/projet/hyperdrive-rest.js b/projet/hyperdrive-rest.js index e90e775a604eba5b46309ba6c97a109d8b402383..376ebcef1451733d02268fe82da3bae6d1b17be5 100644 --- a/projet/hyperdrive-rest.js +++ b/projet/hyperdrive-rest.js @@ -254,8 +254,11 @@ app.get('/download/:file_id', (req, res) => { */ app.get('/change-path*', (req, res) => { - sql.changeDirectory('a', req.params['0']); - res.send(`Request for a change path (${req.params['0']})`) + content = sql.changeDirectory('a', req.params['0'], + (content) => { + res.send(content); + }); + // res.send(`Request for a change path (${req.params['0']})`) }) app.get('/create-path*', (req, res) => { diff --git a/projet/sql-request.js b/projet/sql-request.js index 635716ef39df77ed4eafa67d9aa7f9437278b7a7..133dc8bcdc10db8855039ceb0abddc063599a789 100644 --- a/projet/sql-request.js +++ b/projet/sql-request.js @@ -123,31 +123,32 @@ async function changeDirectory(login, path, callback){ } console.log(content); + return callback(content, "Change dir success"); }); - return [ - { - path: '/a/coucou', - login: 'a', - parent: '/a', - file_id: 'abnnnnn', - file_name: 'deux' - }, - { - path: '/a/coucou', - login: 'a', - parent: '/a', - file_id: 'accb', - file_name: 'trois' - }, - { - path: '/a/coucou/test', - login: 'a', - parent: '/a/coucou', - file_id: 'NULL', - file_name: 'NULL' - } - ]; + // return [ + // { + // path: '/a/coucou', + // login: 'a', + // parent: '/a', + // file_id: 'abnnnnn', + // file_name: 'deux' + // }, + // { + // path: '/a/coucou', + // login: 'a', + // parent: '/a', + // file_id: 'accb', + // file_name: 'trois' + // }, + // { + // path: '/a/coucou/test', + // login: 'a', + // parent: '/a/coucou', + // file_id: 'NULL', + // file_name: 'NULL' + // } + // ]; } exports.addUser = addUser;