Commit 9e7a737c by Damien Moulard Committed by Alexis Aoun

[WIP] linting

parent 7a034324
...@@ -42,7 +42,7 @@ function group_goto(group_index) { ...@@ -42,7 +42,7 @@ function group_goto(group_index) {
// Find order data // Find order data
for (let order of orders) { for (let order of orders) {
if (order.id == order_groups.groups[group_index][i]) { if (order.id == order_groups.groups[group_index][i]) {
order_data = order order_data = order;
} }
} }
...@@ -55,7 +55,7 @@ function group_goto(group_index) { ...@@ -55,7 +55,7 @@ function group_goto(group_index) {
/** /**
* Create a couchdb document for an order if it doesn't exist * Create a couchdb document for an order if it doesn't exist
* @param {Object} order_data * @param {Object} order_data
* @param {Boolean} goto if true, go to order page * @param {Boolean} goto if true, go to order page
*/ */
function create_order_doc(order_data, go_to_order = false) { function create_order_doc(order_data, go_to_order = false) {
...@@ -63,32 +63,33 @@ function create_order_doc(order_data, go_to_order = false) { ...@@ -63,32 +63,33 @@ function create_order_doc(order_data, go_to_order = false) {
dbc.get(order_doc_id).then(() => { dbc.get(order_doc_id).then(() => {
if (go_to_order === true) { if (go_to_order === true) {
goto(order_data.id) goto(order_data.id);
} }
}) })
.catch(function (err) { .catch(function (err) {
// Create if doesn't exist // Create if doesn't exist
if (err.status === 404) { if (err.status === 404) {
let order_doc = { ... order_data }; let order_doc = { ...order_data };
order_doc._id = order_doc_id;
order_doc._id = order_doc_id;
dbc.put(order_doc, (err) => {
if (!err) { dbc.put(order_doc, (err) => {
if (go_to_order === true) { if (!err) {
goto(order_data.id) if (go_to_order === true) {
goto(order_data.id);
}
} else {
error = {
msg: 'Erreur dans la creation de la commande dans couchdb',
ctx: 'validatePrices',
details: err
};
report_JS_error(error, 'reception');
console.log(error);
} }
} else { });
error = { }
msg: 'Erreur dans la creation de la commande dans couchdb', });
ctx: 'validatePrices',
details: err
};
report_JS_error(error, 'reception');
console.log(error);
}
});
}
});
} }
/* ACTIONS */ /* ACTIONS */
...@@ -96,7 +97,7 @@ function create_order_doc(order_data, go_to_order = false) { ...@@ -96,7 +97,7 @@ function create_order_doc(order_data, go_to_order = false) {
/** /**
* Validate all prices of an order * Validate all prices of an order
*/ */
function validatePrices() { function validatePrices() {
// Loading on // Loading on
openModal(); openModal();
...@@ -119,15 +120,15 @@ function create_order_doc(order_data, go_to_order = false) { ...@@ -119,15 +120,15 @@ function create_order_doc(order_data, go_to_order = false) {
dbc.get(`order_${order['id']}`).then((doc) => { dbc.get(`order_${order['id']}`).then((doc) => {
return dbc.remove(doc); return dbc.remove(doc);
}) })
.then(() => { .then(() => {
callback_update = true; callback_update = true;
reload(); reload();
}) })
.catch((err) => { .catch((err) => {
// No doc found // No doc found
console.log(err); console.log(err);
reload(); reload();
}); });
}, },
error: function() { error: function() {
closeModal(); closeModal();
...@@ -168,7 +169,7 @@ function create_order_doc(order_data, go_to_order = false) { ...@@ -168,7 +169,7 @@ function create_order_doc(order_data, go_to_order = false) {
/** /**
* Action fired when orders are grouped (new group) * Action fired when orders are grouped (new group)
* @returns * @returns
*/ */
function group_action() { function group_action() {
let pswd = prompt('Merci de demander à un.e salarié.e le mot de passe pour fusionner ces commandes.'); let pswd = prompt('Merci de demander à un.e salarié.e le mot de passe pour fusionner ces commandes.');
...@@ -194,7 +195,7 @@ function group_action() { ...@@ -194,7 +195,7 @@ function group_action() {
if (!err) { if (!err) {
goto(group_ids[0]); goto(group_ids[0]);
} else { } else {
alert("Une erreur est survenue lors de la création du groupe. Veuillez ré-essayer plus tard svp.") alert("Une erreur est survenue lors de la création du groupe. Veuillez ré-essayer plus tard svp.");
console.log(err); console.log(err);
} }
}); });
...@@ -210,35 +211,35 @@ function group_action() { ...@@ -210,35 +211,35 @@ function group_action() {
/** /**
* Display the order groups. * Display the order groups.
* Remove the grouped orders from the order table to prevent grouping in multiple groups. * Remove the grouped orders from the order table to prevent grouping in multiple groups.
*/ */
function display_grouped_orders() { function display_grouped_orders() {
if (table_orders !== null) { if (table_orders !== null) {
let groups_display_content = "<ul>"; let groups_display_content = "<ul>";
for (let group_index in order_groups.groups) { for (let group_index in order_groups.groups) {
let group_orders = []; let group_orders = [];
// Extract every order in the groups from the orders table // Extract every order in the groups from the orders table
for (group_order_id of order_groups.groups[group_index]) { for (group_order_id of order_groups.groups[group_index]) {
// Look for order in datatable" // Look for order in datatable"
for (let i = 0; i < table_orders.rows().data().length; i++) { for (let i = 0; i < table_orders.rows().data().length; i++) {
if (group_order_id == table_orders.rows(i).data()[0].id) { if (group_order_id == table_orders.rows(i).data()[0].id) {
var order = table_orders.rows(i).data()[0]; var order = table_orders.rows(i).data()[0];
group_orders.push(order); group_orders.push(order);
// remove table row // remove table row
table_orders.rows(i).remove() table_orders.rows(i).remove()
.draw(); .draw();
} }
} }
} }
// Display group // Display group
document.getElementById("container_groups").hidden = false; document.getElementById("container_groups").hidden = false;
let group_row = `<li class="group_line"> Commandes de `; let group_row = `<li class="group_line"> Commandes de `;
for (let i in group_orders) { for (let i in group_orders) {
if (i == group_orders.length-1) { // last element of list if (i == group_orders.length-1) { // last element of list
group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + " : "; group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + " : ";
...@@ -246,7 +247,7 @@ function display_grouped_orders() { ...@@ -246,7 +247,7 @@ function display_grouped_orders() {
group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + ", "; group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + ", ";
} }
} }
if (group_orders[0].reception_status == 'False') { if (group_orders[0].reception_status == 'False') {
group_row += "<button class='btn--primary' onClick='group_goto(" group_row += "<button class='btn--primary' onClick='group_goto("
+ group_index + group_index
...@@ -256,7 +257,7 @@ function display_grouped_orders() { ...@@ -256,7 +257,7 @@ function display_grouped_orders() {
+ group_index + group_index
+ ")'>Mettre à jour les prix</button>"; + ")'>Mettre à jour les prix</button>";
} }
group_row += "</li>"; group_row += "</li>";
groups_display_content += group_row; groups_display_content += group_row;
} }
...@@ -436,7 +437,7 @@ $(document).ready(function() { ...@@ -436,7 +437,7 @@ $(document).ready(function() {
openModal(); openModal();
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } }); $.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
// Init couchdb // Init couchdb
dbc = new PouchDB(couchdb_dbname), dbc = new PouchDB(couchdb_dbname),
sync = PouchDB.sync(couchdb_dbname, couchdb_server, { sync = PouchDB.sync(couchdb_dbname, couchdb_server, {
live: true, live: true,
...@@ -445,26 +446,32 @@ $(document).ready(function() { ...@@ -445,26 +446,32 @@ $(document).ready(function() {
}); });
// TODO sync on change : get data, update data & dom // TODO sync on change : get data, update data & dom
sync.on('change', function (info) {
console.log(info);
}).on('error', function (err) {
console.log(err);
});
// TODO on button click to access order: verif fingerprint & timestamp // TODO on button click to access order: verif fingerprint & timestamp
// Get or create order groups doc // Get or create order groups doc
dbc.get("grouped_orders").then((doc) => { dbc.get("grouped_orders").then((doc) => {
order_groups = doc; order_groups = doc;
}) })
.catch(function (err) { .catch(function (err) {
console.log(err); console.log(err);
if (err.status === 404) { if (err.status === 404) {
// Create if doesn't exist // Create if doesn't exist
dbc.put(order_groups, (err, result) => { dbc.put(order_groups, (err, result) => {
if (!err) { if (!err) {
order_groups._rev = result.rev; order_groups._rev = result.rev;
} else { } else {
console.log("document pour les groupes déjà créé"); console.log("document pour les groupes déjà créé");
console.log(err); console.log(err);
} }
}); });
} }
}); });
// Set date format for DataTable so date ordering can work // Set date format for DataTable so date ordering can work
$.fn.dataTable.moment('D/M/Y'); $.fn.dataTable.moment('D/M/Y');
......
...@@ -112,13 +112,13 @@ function select_product_from_bc(barcode) { ...@@ -112,13 +112,13 @@ function select_product_from_bc(barcode) {
/** /**
* Update couchdb order * Update couchdb order
* @param {int} order_id * @param {int} order_id
*/ */
function update_distant_order(order_id) { function update_distant_order(order_id) {
// TODO insert fingerprint & timestamp // TODO insert fingerprint & timestamp
console.log(order_id); console.log(order_id);
dbc.put(orders[order_id], (err, result) => { dbc.put(orders[order_id], (err, result) => {
if (!err && result !== undefined) { if (!err && result !== undefined) {
orders[order_id]._rev = result.rev; orders[order_id]._rev = result.rev;
} else { } else {
...@@ -417,7 +417,7 @@ function initLists() { ...@@ -417,7 +417,7 @@ function initLists() {
orders[data.id_po]['valid_products'] = []; orders[data.id_po]['valid_products'] = [];
} }
orders[data.id_po]['valid_products'].push(data['id']); orders[data.id_po]['valid_products'].push(data['id']);
update_distant_order(data.id_po) update_distant_order(data.id_po);
// Reset search // Reset search
document.getElementById('search_input').value = ''; document.getElementById('search_input').value = '';
...@@ -1205,9 +1205,9 @@ function send() { ...@@ -1205,9 +1205,9 @@ function send() {
} }
// Set order(s) name in popup DOM // Set order(s) name in popup DOM
if (Object.keys(orders).length === 1) { // Single order if (Object.keys(orders).length === 1) { // Single order
document.getElementById("order_ref").innerHTML = orders[Object.keys(orders)[0]].name; document.getElementById("order_ref").innerHTML = orders[Object.keys(orders)[0]].name;
} else { // group } else { // group
document.getElementById("success_order_name_container").hidden = true; document.getElementById("success_order_name_container").hidden = true;
document.getElementById("success_orders_name_container").hidden = false; document.getElementById("success_orders_name_container").hidden = false;
...@@ -1322,7 +1322,7 @@ function send() { ...@@ -1322,7 +1322,7 @@ function send() {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(updates), data: JSON.stringify(updates),
success: function(data) {}, success: function() {},
error: function() { error: function() {
closeModal(); closeModal();
alert('Erreur dans l\'envoi du rapport.'); alert('Erreur dans l\'envoi du rapport.');
...@@ -1395,7 +1395,7 @@ function saveErrorReport() { ...@@ -1395,7 +1395,7 @@ function saveErrorReport() {
// Save comments in all orders // Save comments in all orders
for (order_id of Object.keys(orders)) { for (order_id of Object.keys(orders)) {
orders[order_id].user_comments = user_comments; orders[order_id].user_comments = user_comments;
update_distant_order(order_id) update_distant_order(order_id);
} }
document.getElementById("search_input").focus(); document.getElementById("search_input").focus();
...@@ -1410,8 +1410,8 @@ var get_barcodes = async function() { ...@@ -1410,8 +1410,8 @@ var get_barcodes = async function() {
/** /**
* Init the page according to order(s) data (texts, colors, events...) * Init the page according to order(s) data (texts, colors, events...)
* *
* @param {Array} partners_display_data * @param {Array} partners_display_data
*/ */
function init_dom(partners_display_data) { function init_dom(partners_display_data) {
// Grouped orders // Grouped orders
...@@ -1597,7 +1597,7 @@ $(document).ready(function() { ...@@ -1597,7 +1597,7 @@ $(document).ready(function() {
let pathArray = window.location.pathname.split('/'); let pathArray = window.location.pathname.split('/');
let id = pathArray[pathArray.length-1]; let id = pathArray[pathArray.length-1];
// Init couchdb // Init couchdb
dbc = new PouchDB(couchdb_dbname), dbc = new PouchDB(couchdb_dbname),
sync = PouchDB.sync(couchdb_dbname, couchdb_server, { sync = PouchDB.sync(couchdb_dbname, couchdb_server, {
live: true, live: true,
...@@ -1606,6 +1606,12 @@ $(document).ready(function() { ...@@ -1606,6 +1606,12 @@ $(document).ready(function() {
}); });
// TODO on sync change : redirect (cf order_helper) // TODO on sync change : redirect (cf order_helper)
sync.on('change', function (info) {
console.log(info);
}).on('error', function (err) {
console.log(err);
});
// TODO insert fingerprint & timestamp on access to order // TODO insert fingerprint & timestamp on access to order
// Disable alert errors from datatables // Disable alert errors from datatables
...@@ -1670,7 +1676,8 @@ $(document).ready(function() { ...@@ -1670,7 +1676,8 @@ $(document).ready(function() {
/* Get order info from couchdb */ /* Get order info from couchdb */
// Get order groups // Get order groups
let order_groups = [] let order_groups = [];
dbc.get("grouped_orders").then((doc) => { dbc.get("grouped_orders").then((doc) => {
order_groups = doc.groups; order_groups = doc.groups;
...@@ -1695,8 +1702,9 @@ $(document).ready(function() { ...@@ -1695,8 +1702,9 @@ $(document).ready(function() {
}).then(function (result) { }).then(function (result) {
// for each order in the group // for each order in the group
for (let order_id of group_ids) { for (let order_id of group_ids) {
// find order // find order
let order = result.rows.find(el => el.id == 'order_' + order_id); let order = result.rows.find(el => el.id == 'order_' + order_id);
order = order.doc; order = order.doc;
orders[order_id] = order; orders[order_id] = order;
...@@ -1725,9 +1733,22 @@ $(document).ready(function() { ...@@ -1725,9 +1733,22 @@ $(document).ready(function() {
init_dom(partners_display_data); init_dom(partners_display_data);
}) })
.catch(function (e) {
let msg = ('message' in e && 'name' in e) ? e.name + ' : ' + e.message : '';
err = {msg, ctx: 'page init - get orders from couchdb', details: e};
console.error(err);
report_JS_error(err, 'reception');
// Should be there, redirect
alert("Erreur au chargement de cette commande. Vous allez être redirigé.");
back();
});
})
.catch(function (e) { .catch(function (e) {
let msg = ('message' in e && 'name' in e) ? e.name + ' : ' + e.message : ''; let msg = ('message' in e && 'name' in e) ? e.name + ' : ' + e.message : '';
err = {msg, ctx: 'page init - get orders from couchdb', details: e};
err = {msg, ctx: 'page init - get grouped orders', details: e};
console.error(err); console.error(err);
report_JS_error(err, 'reception'); report_JS_error(err, 'reception');
...@@ -1735,15 +1756,4 @@ $(document).ready(function() { ...@@ -1735,15 +1756,4 @@ $(document).ready(function() {
alert("Erreur au chargement de cette commande. Vous allez être redirigé."); alert("Erreur au chargement de cette commande. Vous allez être redirigé.");
back(); back();
}); });
})
.catch(function (e) {
let msg = ('message' in e && 'name' in e) ? e.name + ' : ' + e.message : '';
err = {msg, ctx: 'page init - get grouped orders', details: e};
console.error(err);
report_JS_error(err, 'reception');
// Should be there, redirect
alert("Erreur au chargement de cette commande. Vous allez être redirigé.");
back();
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment