Skip to content

Commit

Permalink
front/: select a specific delay for visit and log
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesGuilleus committed Jun 29, 2020
1 parent 9aac1a2 commit 763c588
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 4 deletions.
45 changes: 43 additions & 2 deletions front/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ var Deskop;
return t.querySelector('tbody');
}
Deskop.table = table;
function activeDate(f) {
document.getElementById('dateSelect').hidden = false;
if (Deskop.lister !== f) {
document.getElementById('dateYear').checked = true;
document.getElementById('dateMount').checked = true;
document.getElementById('dateDay').checked = false;
Deskop.lister = f;
}
}
Deskop.activeDate = activeDate;
function reset() {
var groups = ['edit', 'table'];
groups
Expand All @@ -183,6 +193,7 @@ var Deskop;
.map(function (g) { return document.getElementById(g); })
.forEach(function (e) { return e.hidden = true; });
document.getElementById('create').hidden = true;
document.getElementById('dateSelect').hidden = true;
}
function error(m) {
if (!m) {
Expand Down Expand Up @@ -224,6 +235,11 @@ document.addEventListener("DOMContentLoaded", function () {
document.getElementById('createVisit').addEventListener('click', Visit.create);
var s = document.querySelector('input[type=search]');
s.addEventListener('input', function () { return search(s.value); });
document.getElementById('dateGo').addEventListener('click', function () {
if (Deskop.lister) {
Deskop.lister();
}
});
}, { once: true });
function search(pattern) {
pattern = pattern.toLowerCase();
Expand All @@ -242,6 +258,28 @@ function $(html) {
div.remove();
return e;
}
function selectDate() {
var r = '?';
var d = new Date(document.getElementById('dateDate').value
|| new Date());
function getUncheck(id) {
return !document.getElementById(id)
.checked;
}
if (getUncheck('dateYear')) {
return r;
}
r += 'y=' + d.getFullYear();
if (getUncheck('dateMount')) {
return r;
}
r += '&m=' + (d.getMonth() + 1);
if (getUncheck('dateDay')) {
return r;
}
r += '&d=' + d.getDate();
return r;
}
var Edit;
(function (Edit) {
function create(name, end) {
Expand Down Expand Up @@ -424,7 +462,8 @@ var Log;
switch (_a.label) {
case 0:
tbody = Deskop.table(['Opération', 'Acteur', 'Date', 'Valeurs']);
return [4, fetch('/log/list')];
Deskop.activeDate(list);
return [4, fetch('/log/list' + selectDate())];
case 1: return [4, (_a.sent()).json()];
case 2:
l = (_a.sent())
Expand Down Expand Up @@ -590,10 +629,12 @@ var Visit;
switch (_a.label) {
case 0:
tbody = Deskop.table(['ID', 'Pseudo', 'Email', 'Admin', 'Application']);
return [4, fetch('/visit/list')];
Deskop.activeDate(list);
return [4, fetch('/visit/list' + selectDate())];
case 1: return [4, (_a.sent()).json()];
case 2:
(_a.sent())
.sort(function (v1, v2) { return v1.id < v2.id; })
.forEach(function (v) { return tbody.insertAdjacentHTML('beforeend', "<tr>\n\t\t\t\t<td>" + v.id + "</td>\n\t\t\t\t<td>" + v.pseudo + "</td>\n\t\t\t\t<td>" + v.email + "</td>\n\t\t\t\t<td>" + v.author + "</td>\n\t\t\t\t<td>" + v.app + "</td>\n\t\t\t</tr>"); });
return [2];
}
Expand Down
11 changes: 11 additions & 0 deletions front/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
</nav>

<div id=edit class="container pb-5"></div>
<div id=dateSelect class="container mb-4 p-3 bg-light" hidden>
<input type=date id=dateDate class="mr-3">
<input type=checkbox id=dateYear>
<label class="mr-3" for=dateYear>Année</label>
<input type=checkbox id=dateMount>
<label class="mr-3" for=dateMount>Mois</label>
<input type=checkbox id=dateDay>
<label class="mr-3" for=dateDay>Jour</label>
<button type=button id=dateGo
class="btn btn-success btn-sm">Recherche</button>
</div>
<table id=table class="table table-hover container"></table>
<div id=create class="container-sm my-5" hidden>
<h1 class="my-5">Création</h1>
Expand Down
50 changes: 50 additions & 0 deletions front/ts/deskop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.

namespace Deskop {
export var lister: () => void;
// Clear all grousp and display #list.
export function create() {
reset();
Expand Down Expand Up @@ -30,6 +31,17 @@ namespace Deskop {
'</tr></thead><tbody></tbody>');
return t.querySelector('tbody');
}
// Enable selecting date
export function activeDate(f: () => void) {
document.getElementById('dateSelect').hidden = false;
if (lister !== f) {
(<HTMLInputElement>document.getElementById('dateYear')).checked = true;
(<HTMLInputElement>document.getElementById('dateMount')).checked = true;
(<HTMLInputElement>document.getElementById('dateDay')).checked = false;
lister = f;
}
}
// Clean the deskop
function reset() {
const groups = ['edit', 'table'];

Expand All @@ -42,6 +54,7 @@ namespace Deskop {
.forEach(e => e.hidden = true);

document.getElementById('create').hidden = true;
document.getElementById('dateSelect').hidden = true;
}
// Display an error
export function error(m: string) {
Expand Down Expand Up @@ -70,6 +83,11 @@ document.addEventListener("DOMContentLoaded", () => {
document.getElementById('createVisit').addEventListener('click', Visit.create);
let s: HTMLInputElement = document.querySelector('input[type=search]');
s.addEventListener('input', () => search(s.value));
document.getElementById('dateGo').addEventListener('click', () => {
if (Deskop.lister) {
Deskop.lister();
}
});
}, { once: true, });

// Make a search into #table.
Expand All @@ -92,3 +110,35 @@ function $(html: string): Element {
div.remove();
return e;
}

// Select a date to make a request params
function selectDate(): string {
let r = '?';

const d = new Date(
(<HTMLInputElement>document.getElementById('dateDate')).value
|| new Date()
);

function getUncheck(id: string): boolean {
return !(<HTMLInputElement>document.getElementById(id))
.checked;
}

if (getUncheck('dateYear')) {
return r;
}
r += 'y=' + d.getFullYear();

if (getUncheck('dateMount')) {
return r;
}
r += '&m=' + (d.getMonth() + 1);

if (getUncheck('dateDay')) {
return r;
}
r += '&d=' + d.getDate();

return r;
}
3 changes: 2 additions & 1 deletion front/ts/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Log {
// Display log in #table.
export async function list() {
let tbody = Deskop.table(['Opération', 'Acteur', 'Date', 'Valeurs']);
let l: Event[] = (await (await fetch('/log/list')).json())
Deskop.activeDate(list);
let l: Event[] = (await (await fetch('/log/list' + selectDate())).json())
.map(e => {
e.date = new Date(e.date);
return e;
Expand Down
4 changes: 3 additions & 1 deletion front/ts/visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Visit {
export async function list() {
let tbody = Deskop.table(['ID', 'Pseudo', 'Email', 'Admin', 'Application']);
(await (await fetch('/visit/list')).json())
Deskop.activeDate(list);
(await (await fetch('/visit/list' + selectDate())).json())
.sort((v1, v2) => v1.id < v2.id)
.forEach(v => tbody.insertAdjacentHTML('beforeend', `<tr>
<td>${v.id}</td>
<td>${v.pseudo}</td>
Expand Down

0 comments on commit 763c588

Please sign in to comment.