Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Js/fix eslint #413

Merged
merged 7 commits into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
rules: {
strict: [ 'error', 'safe' ],
'no-cond-assign': [ 'error', 'always' ],
indent: [ 'warn', 4 ],
indent: [ 'warn', 2 ],
'array-bracket-spacing': [ 'warn', 'always' ],
'no-const-assign': 'error',
radix: 'error',
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ quantitées dans les tickets de caisse papier
- [#393](https://github.com/mart1ver/oressource/issues/393) Tenir un carnet
des changements apporté au logiciel


### version 0.2.0 et antérieur

Très grosse refonte générale, changement sur la base de donnée, corrections de
bugs.

9 changes: 1 addition & 8 deletions js/numpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//
// Inspired from https://github.com/declandewet/common-tags/ lib
function stripIndent(html) {
// remove the shortest leading indentation from each line
const indent = Math.min(...html[0].match(/^[ \t]*(?=\S)/gm).map(el => el.length));
return html[0].replace(new RegExp('^[ \\t]{' + indent + '}', 'gm'), '');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it ended up eating CPU in the wild.


function number_write(x) {
const text_box = document.getElementById("number");
Expand Down Expand Up @@ -52,7 +45,7 @@ class NumPad {

const div = document.createElement('div');
div.setAttribute('class', 'panel panel-info');
div.innerHTML = stripIndent`
div.innerHTML = `
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know why I found that cool back in 2015...

<div id="saisie" class="panel-heading input-group">
<input type="text" class="form-control" placeholder="Masse" id="number" name="num">
</div>
Expand Down
40 changes: 20 additions & 20 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ const fillItems = (div, types, push) => {
*/
function ticketUpdateUI(container, totalUI, bag, value) {
// Constitution du panier
const { _, nom, couleur, id_last_insert, ticket } = bag;
const {
_, nom, couleur, id_last_insert, ticket,
} = bag;
const li = document.createElement('li');
li.setAttribute('class', 'list-group-item');
const span = '<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>';
Expand Down Expand Up @@ -316,7 +318,7 @@ function recycleurReset() {
element.selected = false;
});
Array.from(document.getElementById('list_evac').children)
.forEach(btn => btn.setAttribute('style', 'display: none; visibility: hidden'));
.forEach((btn) => btn.setAttribute('style', 'display: none; visibility: hidden'));
}

/** Fonction de remise à zéro de l'interface graphique et des tickets en cours.
Expand Down Expand Up @@ -385,16 +387,16 @@ function login(onSuccess = undefined) {
const form = new FormData(document.getElementById('formLogin'));
const username = form.get('mail');
const password = form.get('pass');
const fetchPromise = fetch('../moteur/login_post.php', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetchPromise was never read.

fetch('../moteur/login_post.php', {
method: 'POST',
credidentials: 'include',
headers: {
'Accept': 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({ username, password }),
}).then(status)
.then((json) => {
.then((_) => {
container.setAttribute('style', 'visibility: hidden; opacity: 0;');
if (onSuccess) {
onSuccess();
Expand Down Expand Up @@ -459,7 +461,7 @@ function post_data(url, getData, onFinalise, onImpress = (_, a) => a) {
credentials: 'include',
method: 'POST',
headers: {
'Accept': 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(data),
Expand Down Expand Up @@ -557,12 +559,12 @@ const dashBreak = '<p>-----------------------------------</p>';
* - window.OressourceEnv.types_evac
* - window.OressourceEnv.types_dechet
*/
function showTickets(data, unit = 'kg') {
function showTickets(data) {
const item = (data.hasOwnProperty('items') && data.items.length > 0
? `<p>Ventes</p>${dashBreak}${showTicket(data.items, window.OressourceEnv.types_dechet, unit)}`
? `<p>Ventes</p>${dashBreak}${showTicket(data.items, window.OressourceEnv.types_dechet)}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit was passed around and in showTicketlink to fct it wasn't read at all.

: '');
return item + (data.hasOwnProperty('evacs') && data.evacs.length > 0
? `<p>Matériaux</p>${dashBreak}${showTicket(data.evacs, window.OressourceEnv.types_evac, unit)}`
? `<p>Matériaux</p>${dashBreak}${showTicket(data.evacs, window.OressourceEnv.types_evac)}`
: '');
}

Expand Down Expand Up @@ -593,9 +595,9 @@ function showTicket(data, types) {
* @param {number} moyenId moyenId represente un id valide de moyen de paiement.
* @returns {string} Nom du moyen de paiement ou "Moyen de paiement inconnu!"
*/
const showMoyen = (moyens, moyenId) => {
return moyens.find(({id}) => id === moyenId).nom || "moyen de paiement inconnu!";
}
const showMoyen = (moyens, moyenId) => (
moyens.find(({id}) => id === moyenId).nom || "moyen de paiement inconnu!"
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just little trick to remove {} and return since it's an expression.


/**
* Represente un moyen de paiement comme une chaine de caractère.
Expand All @@ -606,7 +608,7 @@ const showMoyen = (moyens, moyenId) => {
const showPaiement = (moyenId) => {
const moyens = window.OressourceEnv.moyens_paiement || null;
return (moyens ? `<p>Payé en ${showMoyen(moyens, moyenId)}</p>` : '');
}
};

/**
* Cette fonction construit une <IFrame/> et l'imprime et l'iframe est détruite
Expand All @@ -620,7 +622,7 @@ const showPaiement = (moyenId) => {
* @globals window.OressourceEnv.adresse
* @global moment bibliothèque d'internationnalisation des dates
*/
function impressionTicket(data, response, unit = 'kg', tvaStuff = () => '', sumFunc = sumMasseTickets) {
function impressionTicket(data, response, tvaStuff = () => '') {
const title = classeToName(data.classe);
// Hack affreux pour gérer les ventes car on utilise pas un objet si global dans leur gestion.
const html = `
Expand All @@ -639,24 +641,22 @@ function impressionTicket(data, response, unit = 'kg', tvaStuff = () => '', sumF
${showPaiement(data.id_moyen)}
<p>Ticket client à conserver.</p>
<p>Date d'édition du ticket : ${moment().format('DD/MM/YYYY - HH:mm')}</p>
${showTickets(data, unit)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was never read in showTickets

${showTickets(data)}
</body>
</html>`;

const iframe = document.createElement('iframe');
function closePrint() {
document.body.removeChild(this.__container__);
}

function setPrint() {
iframe.onload = function () {
this.contentWindow.__container__ = this;
this.contentWindow.onbeforeunload = closePrint;
this.contentWindow.onafterprint = closePrint;
this.contentWindow.focus();
this.contentWindow.print();
}

const iframe = document.createElement('iframe');
iframe.onload = setPrint;
};
iframe.style.visibility = 'hidden';
iframe.style.position = 'fixed';
iframe.style.right = 0;
Expand Down
2 changes: 1 addition & 1 deletion js/ventes.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ document.addEventListener('DOMContentLoaded', () => {

const url = '../api/ventes.php';
const ventePrint = (
(d, r) => impressionTicket(d, r, '€', printTva, (t) => t.sum_prix())
(d, r) => impressionTicket(d, r, printTva)
);

const send = post_data(url, encaisse_vente, reset);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Oressource",
"name": "oressource",
"version": "0.3.0",
"description": "Webapplication de gestion de ressourceries.",
"license": "AGPL-3.0",
Expand Down