Introduce some pre-commit hooks

This commit is contained in:
Benjamin Renard 2024-09-21 17:23:21 +02:00
parent 67a89bb091
commit 60b8e5cb53
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
10 changed files with 1275 additions and 1043 deletions

7
.phplint.yml Normal file
View file

@ -0,0 +1,7 @@
path: ./
jobs: 10
extensions:
- php
exclude:
- vendor
warning: true

26
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,26 @@
# Pre-commit hooks to run tests and ensure code is cleaned.
# See https://pre-commit.com for more information
---
repos:
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
hooks:
- id: yamllint
ignore: .github/
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
- repo: https://github.com/digitalpulp/pre-commit-php.git
rev: 1.4.0
hooks:
- id: php-stan
files: ^(?!example/).*\.(php)$
args: ["--configuration=phpstan.neon"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)

2
.prettierignore Normal file
View file

@ -0,0 +1,2 @@
/static/lib/*
/locales/*

9
.yamllint.yaml Normal file
View file

@ -0,0 +1,9 @@
extends: default
ignore: |
static/lib/*
rules:
line-length:
max: 100
level: warning

View file

@ -1,29 +1,29 @@
{ {
"name": "brenard/mysc", "name": "brenard/mysc",
"description": "My Sweetcase", "description": "My Sweetcase",
"type": "project", "type": "project",
"require": { "require": {
"brenard/eesyphp": "dev-master" "brenard/eesyphp": "dev-master"
}, },
"license": "GPL3", "license": "GPL3",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"MySC\\": "src/" "MySC\\": "src/"
}
},
"authors": [
{
"name": "Benjamin Renard",
"email": "brenard@zionetrix.net"
}
],
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"php-http/discovery": true
}
},
"require-dev": {
"phpstan/phpstan": "2.0.x-dev"
} }
},
"authors": [
{
"name": "Benjamin Renard",
"email": "brenard@zionetrix.net"
}
],
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"php-http/discovery": true
}
},
"require-dev": {
"phpstan/phpstan": "2.0.x-dev"
}
} }

View file

@ -116,8 +116,8 @@ db:
options: null options: null
# Date/Datetime format in database (strptime format) # Date/Datetime format in database (strptime format)
date_format: '%s' date_format: "%s"
datetime_format: '%s' datetime_format: "%s"
# Postgresql # Postgresql
#dsn: "pgsql:host=localhost;port=5432;dbname=items" #dsn: "pgsql:host=localhost;port=5432;dbname=items"

4
setup.cfg Normal file
View file

@ -0,0 +1,4 @@
[codespell]
ignore-words-list=fro,hass
exclude-file=.codespell-exclusions
quiet-level=2

View file

@ -1,8 +1,10 @@
body{ body {
margin-top: 4em; margin-top: 4em;
} }
div.panel-heading, li.list-group-item, a { div.panel-heading,
li.list-group-item,
a {
cursor: pointer; cursor: pointer;
} }
@ -19,7 +21,7 @@ div.panel-heading, li.list-group-item, a {
} }
.checkable:before { .checkable:before {
content: '\2713'; content: "\2713";
margin-right: 0.2em; margin-right: 0.2em;
font-style: italic; font-style: italic;
color: #999; color: #999;
@ -43,12 +45,14 @@ div.panel-heading, li.list-group-item, a {
font-size: 1.5em; font-size: 1.5em;
} }
.add_thing_label, #edit_thing_label { .add_thing_label,
#edit_thing_label {
width: 80%; width: 80%;
display: inline-block; display: inline-block;
} }
.add_thing_nb, #edit_thing_nb { .add_thing_nb,
#edit_thing_nb {
width: 18%; width: 18%;
display: inline-block; display: inline-block;
} }
@ -58,7 +62,8 @@ div.panel-heading, li.list-group-item, a {
background: rgba(66, 215, 252, 0.95); background: rgba(66, 215, 252, 0.95);
} }
.alertify .ajs-header, .alertify .ajs-footer { .alertify .ajs-header,
.alertify .ajs-footer {
background-color: #4e5d6c; background-color: #4e5d6c;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,61 +1,60 @@
function SCaseList() { function SCaseList() {
lastChange=0; lastChange = 0;
this.importExampleData=function() { this.importExampleData = function () {
var exampleData={ var exampleData = {
'Vacances': { Vacances: {
'Papier': { Papier: {
'color': '#f00', color: "#f00",
'things': [ things: [
{'label': 'Papier blanc', 'nb': 1 }, { label: "Papier blanc", nb: 1 },
{'label': 'Stylo', 'nb': 3 }, { label: "Stylo", nb: 3 },
{'label': "Carte d'identité", 'nb': 1 }, { label: "Carte d'identité", nb: 1 },
] ],
}, },
'Multimédia' : { Multimédia: {
'color': '#0f0', color: "#0f0",
'things': [ things: [
{'label': 'Montre', 'nb': 1 }, { label: "Montre", nb: 1 },
{'label': 'Chargeur montre', 'nb': 1 }, { label: "Chargeur montre", nb: 1 },
{'label': 'PC portable', 'nb': 1 }, { label: "PC portable", nb: 1 },
] ],
} },
} },
}; };
for (scaseName in exampleData) { for (scaseName in exampleData) {
var scase=this.newSCase(scaseName); var scase = this.newSCase(scaseName);
for (catName in exampleData[scaseName]) { for (catName in exampleData[scaseName]) {
var cat=scase.cats.newCat(catName); var cat = scase.cats.newCat(catName);
for (idx in exampleData[scaseName][catName].things) { for (idx in exampleData[scaseName][catName].things) {
cat.newThing(exampleData[scaseName][catName].things[idx]['label'],exampleData[scaseName][catName].things[idx]['nb']); cat.newThing(
exampleData[scaseName][catName].things[idx]["label"],
exampleData[scaseName][catName].things[idx]["nb"]
);
} }
} }
} }
} };
this.loadFromLocalStorage=function(data) { this.loadFromLocalStorage = function (data) {
if (jQuery.type(localStorage.scases)!='undefined') { if (jQuery.type(localStorage.scases) != "undefined") {
try { try {
return this.loadFromJsonData(JSON.parse(localStorage.scases)); return this.loadFromJsonData(JSON.parse(localStorage.scases));
} } catch (e) {
catch(e) {
return false; return false;
} }
} }
return null; return null;
} };
this.loadFromJsonData=function(data) { this.loadFromJsonData = function (data) {
try { try {
this.lastChange=data.lastChange; this.lastChange = data.lastChange;
for (el in data.scases) { for (el in data.scases) {
this[el]=new SCase(false,false,data.scases[el]); this[el] = new SCase(false, false, data.scases[el]);
} }
return true; return true;
} } catch (e) {
catch(e) {
for (el in this) { for (el in this) {
if (this.isSCase(this[el])) { if (this.isSCase(this[el])) {
delete this[el]; delete this[el];
@ -63,179 +62,181 @@ function SCaseList() {
} }
} }
return false; return false;
} };
this.export=function() { this.export = function () {
return { return {
'lastChange': this.lastChange, lastChange: this.lastChange,
'scases': this.each(function(idx,scase) { scases: this.each(function (idx, scase) {
return scase.export(); return scase.export();
}) }),
}; };
} };
this.import=function(data) { this.import = function (data) {
ret={}; ret = {};
for (el in this) { for (el in this) {
if (this.isSCase(this[el])) { if (this.isSCase(this[el])) {
delete ret[el]; delete ret[el];
} }
} }
this.lastChange=data.lastChange; this.lastChange = data.lastChange;
for (el in data.scases) { for (el in data.scases) {
this[el]=new SCase(false,false,data.scases[el]); this[el] = new SCase(false, false, data.scases[el]);
} }
return true; return true;
} };
this.save=function() { this.save = function () {
localStorage.scases=JSON.stringify(this.export()); localStorage.scases = JSON.stringify(this.export());
} };
this.each=function(fct) { this.each = function (fct) {
var idx=0; var idx = 0;
var ret={}; var ret = {};
for (el in this) { for (el in this) {
if(this.isSCase(this[el])) { if (this.isSCase(this[el])) {
ret[el]=fct(idx++,this[el]); ret[el] = fct(idx++, this[el]);
} }
} }
return ret; return ret;
} };
this.count=function() { this.count = function () {
len=0; len = 0;
this.each(function(idx,scase) { this.each(function (idx, scase) {
len=len+1; len = len + 1;
}); });
return len; return len;
} };
this.isSCase=function(el) { this.isSCase = function (el) {
return (jQuery.type(el)=='object' && jQuery.type(el.isSCase)=='function' && el.isSCase()); return (
} jQuery.type(el) == "object" &&
jQuery.type(el.isSCase) == "function" &&
el.isSCase()
);
};
this.byName=function(name) { this.byName = function (name) {
for (el in this) { for (el in this) {
if(this.isSCase(this[el])) { if (this.isSCase(this[el])) {
if (this[el].name==name) { if (this[el].name == name) {
return this[el]; return this[el];
} }
} }
} }
return false; return false;
} };
this.byUUID=function(uuid) { this.byUUID = function (uuid) {
return this.isCase(this[uuid]) ? this[uuid] : null; return this.isCase(this[uuid]) ? this[uuid] : null;
} };
this.removeSCase=function(name) { this.removeSCase = function (name) {
for (el in this) { for (el in this) {
if (this.isSCase(this[el]) && this[el].name==name) { if (this.isSCase(this[el]) && this[el].name == name) {
this[el].remove(); this[el].remove();
return true; return true;
} }
} }
return false; return false;
} };
this.newSCase=function(name) { this.newSCase = function (name) {
if (this.byName(this[name])) { if (this.byName(this[name])) {
var scase=this.byName(name); var scase = this.byName(name);
if (scase.removed) { if (scase.removed) {
scase.restore(); scase.restore();
return true; return true;
} }
} else {
} var uuid = uuid || generate_uuid();
else { this[uuid] = new SCase(uuid, name);
var uuid=uuid||generate_uuid();
this[uuid]=new SCase(uuid,name);
return this[uuid]; return this[uuid];
} }
return false; return false;
} };
this.renameSCase=function(name,newname) { this.renameSCase = function (name, newname) {
var scase=this.byName(name); var scase = this.byName(name);
if (scase && !this.byName(newname)) { if (scase && !this.byName(newname)) {
scase.name=newname; scase.name = newname;
scase.lastChange=new Date().getTime(); scase.lastChange = new Date().getTime();
return scase; return scase;
} }
return false; return false;
} };
this.copySCase=function(name,newname) { this.copySCase = function (name, newname) {
var orig_scase=this.byName(name); var orig_scase = this.byName(name);
if (this.isSCase(orig_scase) && !this.byName(newname)) { if (this.isSCase(orig_scase) && !this.byName(newname)) {
var uuid=uuid||generate_uuid(); var uuid = uuid || generate_uuid();
this[uuid]=new SCase(false,false,orig_scase.export()); this[uuid] = new SCase(false, false, orig_scase.export());
this[uuid].uuid=uuid; this[uuid].uuid = uuid;
this[uuid].lastChange=new Date().getTime(); this[uuid].lastChange = new Date().getTime();
this[uuid].name=newname; this[uuid].name = newname;
return this[uuid]; return this[uuid];
} }
return false; return false;
} };
this.resetSCase=function(name) { this.resetSCase = function (name) {
for (el in this) { for (el in this) {
if (this.isSCase(this[el]) && this[el].name==name) { if (this.isSCase(this[el]) && this[el].name == name) {
return this[el].reset(); return this[el].reset();
} }
} }
return false; return false;
} };
} }
function SCase(uuid,name,data) { function SCase(uuid, name, data) {
this.uuid=uuid||generate_uuid(); this.uuid = uuid || generate_uuid();
this.name=name; this.name = name;
this.cats=new CatList(); this.cats = new CatList();
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
this.removed=false; this.removed = false;
this.isSCase=function() { this.isSCase = function () {
return true; return true;
} };
this.import=function(data) { this.import = function (data) {
this.uuid=data.uuid || generate_uuid(); this.uuid = data.uuid || generate_uuid();
this.lastChange=data.lastChange || new Date().getTime(); this.lastChange = data.lastChange || new Date().getTime();
this.name=decodeURIComponent(data.name); this.name = decodeURIComponent(data.name);
this.removed=data.removed||false; this.removed = data.removed || false;
if (jQuery.type(data.cats) == 'object') { if (jQuery.type(data.cats) == "object") {
this.cats=new CatList(data.cats); this.cats = new CatList(data.cats);
} }
return true; return true;
} };
this.export=function() { this.export = function () {
return { return {
'uuid': this.uuid, uuid: this.uuid,
'lastChange': this.lastChange, lastChange: this.lastChange,
'name': encodeURIComponent(this.name), name: encodeURIComponent(this.name),
'removed': this.removed, removed: this.removed,
'cats': this.cats.export() cats: this.cats.export(),
}; };
} };
this.byName=function(name) { this.byName = function (name) {
for (idx in this.cats) { for (idx in this.cats) {
if (name==this.cats[idx].name) { if (name == this.cats[idx].name) {
return this.cats[idx]; return this.cats[idx];
} }
} }
return false; return false;
} };
this.stats=function() { this.stats = function () {
var cats=0; var cats = 0;
var things=0; var things = 0;
var things_done=0; var things_done = 0;
this.cats.each(function(cidx,cat) { this.cats.each(function (cidx, cat) {
if (cat.removed) { if (cat.removed) {
return true; return true;
} }
@ -251,399 +252,405 @@ function SCase(uuid,name,data) {
} }
}); });
return { return {
'cats': cats, cats: cats,
'things': things, things: things,
'done': things_done done: things_done,
} };
} };
this.reset=function() { this.reset = function () {
this.cats.each(function(idx,cat) { this.cats.each(function (idx, cat) {
for (idx in cat.things) { for (idx in cat.things) {
if (cat.things[idx].checked) { if (cat.things[idx].checked) {
cat.things[idx].checked=false; cat.things[idx].checked = false;
} }
} }
}); });
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
return true; return true;
} };
this.remove=function() { this.remove = function () {
this.removed=true; this.removed = true;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
} };
this.restore=function() { this.restore = function () {
this.removed=false; this.removed = false;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
} };
/* /*
* Contructor * Contructor
*/ */
if (jQuery.type(data)=='object') { if (jQuery.type(data) == "object") {
try { try {
this.import(data); this.import(data);
} } catch (e) {
catch (e) {
console.log(e); console.log(e);
alert('Une erreur est survenue en chargeant la valise '+this.name+' depuis le cache'); alert(
"Une erreur est survenue en chargeant la valise " +
this.name +
" depuis le cache"
);
} }
} }
} }
function CatList(data) { function CatList(data) {
this.export=function() { this.export = function () {
return this.each(function(idx,cat) { return this.each(function (idx, cat) {
return cat.export(); return cat.export();
}); });
} };
this.import=function(data) { this.import = function (data) {
for (el in this) { for (el in this) {
if (this.isCat(this[el])) { if (this.isCat(this[el])) {
delete this[el]; delete this[el];
} }
} }
for (el in data) { for (el in data) {
this[el]=new Cat(el,false,false,data[el]); this[el] = new Cat(el, false, false, data[el]);
} }
return true; return true;
} };
this.each=function(fct) { this.each = function (fct) {
var idx=0; var idx = 0;
var ret={}; var ret = {};
for (el in this) { for (el in this) {
if(this.isCat(this[el])) { if (this.isCat(this[el])) {
ret[el]=fct(idx++,this[el]); ret[el] = fct(idx++, this[el]);
} }
} }
return ret; return ret;
} };
this.count=function() { this.count = function () {
len=0; len = 0;
this.each(function(idx,cat) { this.each(function (idx, cat) {
len=len+1; len = len + 1;
}); });
return len; return len;
} };
this.isCat=function(el) { this.isCat = function (el) {
return (jQuery.type(el)=='object' && jQuery.type(el.isCat)=='function' && el.isCat()); return (
} jQuery.type(el) == "object" &&
jQuery.type(el.isCat) == "function" &&
el.isCat()
);
};
this.byName=function(name) { this.byName = function (name) {
for (el in this) { for (el in this) {
if(this.isCat(this[el])) { if (this.isCat(this[el])) {
if (this[el].name==name) { if (this[el].name == name) {
return this[el]; return this[el];
} }
} }
} }
return false; return false;
} };
this.byUUID=function(uuid) { this.byUUID = function (uuid) {
return this.isCas(this[uuid]) ? this[uuid] : null; return this.isCas(this[uuid]) ? this[uuid] : null;
} };
this.newCat=function(name) { this.newCat = function (name) {
if (this.byName(name)) { if (this.byName(name)) {
var cat=this.byName(name); var cat = this.byName(name);
if (cat.removed) { if (cat.removed) {
cat.restore(); cat.restore();
return true; return true;
} }
} } else {
else { var uuid = uuid || generate_uuid();
var uuid=uuid||generate_uuid(); this[uuid] = new Cat(uuid, name);
this[uuid]=new Cat(uuid,name);
return this[uuid]; return this[uuid];
} }
return false; return false;
} };
this.renameCat=function(name,newname) { this.renameCat = function (name, newname) {
var cat=this.byName(name); var cat = this.byName(name);
if (cat && !this.byName(newname)) { if (cat && !this.byName(newname)) {
cat.name=newname; cat.name = newname;
cat.lastChange=new Date().getTime(); cat.lastChange = new Date().getTime();
return cat; return cat;
} }
return false; return false;
} };
this.removeCat=function(name) { this.removeCat = function (name) {
for (el in this) { for (el in this) {
if (this.isCat(this[el]) && this[el].name==name) { if (this.isCat(this[el]) && this[el].name == name) {
this[el].remove(); this[el].remove();
return true; return true;
} }
} }
return false; return false;
} };
this.restoreCat=function(name) { this.restoreCat = function (name) {
for (el in this) { for (el in this) {
if (this.isCat(this[el]) && this[el].name==name && this[el].removed) { if (this.isCat(this[el]) && this[el].name == name && this[el].removed) {
this[el].restore(); this[el].restore();
return true; return true;
} }
} }
return false; return false;
} };
/* /*
* Contructor * Contructor
*/ */
if (jQuery.type(data)=='object') { if (jQuery.type(data) == "object") {
try { try {
this.import(data); this.import(data);
} } catch (e) {
catch (e) {
console.log(e); console.log(e);
alert('Une erreur est survenue en chargeant la liste de catégorie depuis le cache'); alert(
"Une erreur est survenue en chargeant la liste de catégorie depuis le cache"
);
} }
} }
} }
function Cat(uuid,name,color,data) { function Cat(uuid, name, color, data) {
this.uuid=generate_uuid(); this.uuid = generate_uuid();
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
this.name=name; this.name = name;
this.color=color || '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6); this.color =
this.things={}; color ||
this.removed=false; "#" + (0x1000000 + Math.random() * 0xffffff).toString(16).substr(1, 6);
this.things = {};
this.removed = false;
this.isCat=function() { this.isCat = function () {
return true; return true;
} };
this.import=function(data) { this.import = function (data) {
this.uuid=data.uuid || generate_uuid(); this.uuid = data.uuid || generate_uuid();
this.lastChange=data.lastChange||new Date().getTime(); this.lastChange = data.lastChange || new Date().getTime();
this.name=decodeURIComponent(data.name); this.name = decodeURIComponent(data.name);
this.color=data.color; this.color = data.color;
this.removed=data.removed||false; this.removed = data.removed || false;
if (jQuery.type(data.things) == 'object') { if (jQuery.type(data.things) == "object") {
for (tuuid in data.things) { for (tuuid in data.things) {
this.things[tuuid]=new Thing(tuuid); this.things[tuuid] = new Thing(tuuid);
this.things[tuuid].import(data.things[tuuid]); this.things[tuuid].import(data.things[tuuid]);
} }
} }
return true; return true;
} };
this.export=function() { this.export = function () {
var things={}; var things = {};
for (tuuid in this.things) { for (tuuid in this.things) {
things[tuuid]=this.things[tuuid].export(); things[tuuid] = this.things[tuuid].export();
} }
return { return {
'uuid': this.uuid, uuid: this.uuid,
'lastChange': this.lastChange, lastChange: this.lastChange,
'name': encodeURIComponent(this.name), name: encodeURIComponent(this.name),
'color': this.color, color: this.color,
'removed': this.removed, removed: this.removed,
'things': things things: things,
}; };
} };
this.byLabel=function(label) { this.byLabel = function (label) {
for (idx in this.things) { for (idx in this.things) {
if (label==this.things[idx].label) { if (label == this.things[idx].label) {
return this.things[idx]; return this.things[idx];
} }
} }
return false; return false;
} };
this.count=function() { this.count = function () {
return keys(this.things).length; return keys(this.things).length;
} };
this.stats=function() { this.stats = function () {
var count=0; var count = 0;
var done=0; var done = 0;
for (idx in this.things) { for (idx in this.things) {
if (this.things[idx].removed) { if (this.things[idx].removed) {
continue; continue;
} }
if (this.things[idx].checked) { if (this.things[idx].checked) {
done+=1; done += 1;
} }
count+=1; count += 1;
} }
return { return {
'things': count, things: count,
'done': done done: done,
}; };
} };
this.newThing=function(label,nb) { this.newThing = function (label, nb) {
if (this.byLabel(label)) { if (this.byLabel(label)) {
var thing=this.byLabel(label); var thing = this.byLabel(label);
if (thing.removed) { if (thing.removed) {
thing.restore(); thing.restore();
thing.setChecked(false); thing.setChecked(false);
thing.setNb(nb); thing.setNb(nb);
return true; return true;
} }
} } else {
else { var uuid = generate_uuid();
var uuid=generate_uuid(); this.things[uuid] = new Thing(uuid, label, nb);
this.things[uuid]=new Thing(uuid,label,nb);
return true; return true;
} }
return false; return false;
} };
this.renameThing=function(label,newlabel) { this.renameThing = function (label, newlabel) {
var thing=this.byLabel(label); var thing = this.byLabel(label);
if (thing && !this.byLabel(newlabel)) { if (thing && !this.byLabel(newlabel)) {
thing.label=newlabel; thing.label = newlabel;
thing.lastChange=new Date().getTime(); thing.lastChange = new Date().getTime();
return thing; return thing;
} }
return false; return false;
} };
this.removeThing=function(label) { this.removeThing = function (label) {
for (idx in this.things) { for (idx in this.things) {
if (this.things[idx].label==label) { if (this.things[idx].label == label) {
this.things[idx].remove(); this.things[idx].remove();
return true; return true;
} }
} }
return false; return false;
} };
this.restoreThing=function(label) { this.restoreThing = function (label) {
for (idx in this.things) { for (idx in this.things) {
if (this.things[idx].label==label && this.things[idx].removed) { if (this.things[idx].label == label && this.things[idx].removed) {
this.things[idx].restore(); this.things[idx].restore();
return true; return true;
} }
} }
return false; return false;
} };
this.remove=function() { this.remove = function () {
this.removed=true; this.removed = true;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
} };
this.restore=function() {
this.removed=false;
this.lastChange=new Date().getTime();
}
this.restore = function () {
this.removed = false;
this.lastChange = new Date().getTime();
};
/* /*
* Contructor * Contructor
*/ */
if (jQuery.type(data)=='object') { if (jQuery.type(data) == "object") {
try { try {
this.import(data); this.import(data);
} } catch (e) {
catch (e) {
console.log(e); console.log(e);
alert('Une erreur est survenue en chargeant la catégorie catégorie '+this.name+' depuis le cache'); alert(
"Une erreur est survenue en chargeant la catégorie catégorie " +
this.name +
" depuis le cache"
);
} }
} }
} }
function Thing(uuid,label,nb,checked) { function Thing(uuid, label, nb, checked) {
this.uuid=uuid||generate_uuid(); this.uuid = uuid || generate_uuid();
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
this.label=label; this.label = label;
this.nb=nb || 1; this.nb = nb || 1;
this.checked=checked; this.checked = checked;
this.removed=false; this.removed = false;
this.import=function(data) { this.import = function (data) {
this.uuid=data.uuid||generate_uuid(); this.uuid = data.uuid || generate_uuid();
this.lastChange=data.lastChange||new Date().getTime(); this.lastChange = data.lastChange || new Date().getTime();
this.label=decodeURIComponent(data.label), (this.label = decodeURIComponent(data.label)), (this.nb = data.nb || 1);
this.nb=data.nb||1; this.checked = data.checked;
this.checked=data.checked; this.removed = data.removed || false;
this.removed=data.removed||false; };
}
this.export=function() { this.export = function () {
return { return {
'uuid': this.uuid, uuid: this.uuid,
'lastChange': this.lastChange, lastChange: this.lastChange,
'label': encodeURIComponent(this.label), label: encodeURIComponent(this.label),
'nb': this.nb, nb: this.nb,
'checked': this.checked, checked: this.checked,
'removed': this.removed, removed: this.removed,
}; };
} };
this.setNb=function(nb) { this.setNb = function (nb) {
this.nb=nb; this.nb = nb;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
} };
this.setChecked=function(value) { this.setChecked = function (value) {
this.checked=value; this.checked = value;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
console.log(`Thing<${this.uuid}>.setChecked(${this.checked}): ${this.lastChange}`); console.log(
} `Thing<${this.uuid}>.setChecked(${this.checked}): ${this.lastChange}`
);
};
this.remove=function() { this.remove = function () {
this.removed=true; this.removed = true;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
} };
this.restore=function() { this.restore = function () {
this.removed=false; this.removed = false;
this.lastChange=new Date().getTime(); this.lastChange = new Date().getTime();
} };
} }
function User() { function User() {
this.username = null; this.username = null;
this.name = null; this.name = null;
this.token = null; this.token = null;
this.loadFromLocalStorage=function() { this.loadFromLocalStorage = function () {
if (jQuery.type(localStorage.user) == 'undefined') if (jQuery.type(localStorage.user) == "undefined") return;
return;
try { try {
var data=JSON.parse(localStorage.user); var data = JSON.parse(localStorage.user);
this.username = data.username; this.username = data.username;
this.name = data.name; this.name = data.name;
this.token = data.token; this.token = data.token;
} } catch (e) {
catch(e) { alert(
alert('Erreur en chargeant vos informations de connexion. Merci de vous reconnecter.'); "Erreur en chargeant vos informations de connexion. Merci de vous reconnecter."
);
} }
}; };
this.connected=function() { this.connected = function () {
return this.username && this.token; return this.username && this.token;
} };
this.reset=function() { this.reset = function () {
this.username = null; this.username = null;
this.name = null; this.name = null;
this.token = null; this.token = null;
} };
this.save=function() { this.save = function () {
localStorage.user = JSON.stringify({ localStorage.user = JSON.stringify({
username: this.username, username: this.username,
name: this.name, name: this.name,
token: this.token, token: this.token,
}); });
} };
} }