Commit 983b0430 by Damien Moulard

linting

parent e3a79bad
......@@ -23,8 +23,8 @@ var orders = [],
* @param {Date} date2
* @returns difference object
*/
function dates_diff(date1, date2) {
var diff = {}
function dates_diff(date1, date2) {
var diff = {};
var tmp = date2 - date1;
tmp = Math.floor(tmp/1000);
......@@ -57,23 +57,25 @@ function reload() {
*/
function check_before_goto(id) {
const order_doc_id = 'order_' + id;
dbc.get(order_doc_id).then((doc) => {
if (doc.last_update.fingerprint !== null && doc.last_update.fingerprint !== fingerprint) {
time_diff = dates_diff(new Date(doc.last_update.timestamp), new Date())
diff_str = ``
time_diff = dates_diff(new Date(doc.last_update.timestamp), new Date());
diff_str = ``;
if (time_diff.days !== 0) {
diff_str += `${time_diff.days} jour(s), `
diff_str += `${time_diff.days} jour(s), `;
}
if (time_diff.hours !== 0) {
diff_str += `${time_diff.hours} heure(s), `
diff_str += `${time_diff.hours} heure(s), `;
}
if (time_diff.min !== 0) {
diff_str += `${time_diff.min} min, `
diff_str += `${time_diff.min} min, `;
}
diff_str += `${time_diff.sec}s`
diff_str += `${time_diff.sec}s`;
let modal_order_access = $('#templates #modal_order_access');
modal_order_access.find(".order_last_update").text(diff_str);
openModal(
......@@ -89,7 +91,7 @@ function check_before_goto(id) {
})
.catch((err) => {
console.log(err);
})
});
}
function goto(id) {
......@@ -140,14 +142,15 @@ function create_order_doc(order_data, go_to_order = false) {
order_doc._id = order_doc_id;
order_doc.last_update = {
timestamp: Date.now(),
fingerprint: fingerprint,
fingerprint: fingerprint
};
dbc.put(order_doc).then(() => {
if (go_to_order === true) {
goto(order_data.id);
}
}).catch((err) => {
})
.catch((err) => {
error = {
msg: 'Erreur dans la creation de la commande dans couchdb',
ctx: 'create_order_doc',
......@@ -525,6 +528,7 @@ $(document).ready(function() {
sync.on('change', function (info) {
// If important data changed somewhere else, update local data
let need_to_reload = false;
if (info.direction === "pull") {
for (let doc of info.change.docs) {
if (doc._id === "grouped_orders") {
......@@ -547,6 +551,7 @@ $(document).ready(function() {
} else {
// Find updated order in local orders & update it if reception status changed
let index = orders.findIndex(order => order.id == doc.id);
if (index !== -1 && orders[index].reception_status !== doc.reception_status) {
orders[index] = doc;
need_to_reload = true;
......
......@@ -122,7 +122,7 @@ function select_product_from_bc(barcode) {
function update_distant_order(order_id) {
orders[order_id].last_update = {
timestamp: Date.now(),
fingerprint: fingerprint,
fingerprint: fingerprint
};
dbc.put(orders[order_id], (err, result) => {
......@@ -139,11 +139,11 @@ function update_distant_order(order_id) {
* Update distant orders with local data
* @param {int} order_id
*/
function update_distant_orders() {
function update_distant_orders() {
for (let order_id in orders) {
orders[order_id].last_update = {
timestamp: Date.now(),
fingerprint: fingerprint,
fingerprint: fingerprint
};
}
......@@ -151,12 +151,13 @@ function update_distant_order(order_id) {
// Update rev of current orders after their update
for (let doc of response) {
let order_id = doc.id.split('_')[1];
orders[order_id]._rev = doc.rev
orders[order_id]._rev = doc.rev;
}
})
.catch((err) => {
console.log(err);
})
});
}
/* INIT */
......@@ -846,7 +847,7 @@ function clearLineEdition() {
document.getElementById('product_uom').innerHTML = '';
}
/**
/**
* Update a product info : qty or unit price
* @param {Object} productToEdit
* @param {Float} value if set, use it as new value
......@@ -975,7 +976,7 @@ function setAllQties() {
.draw();
// Batch update orders
update_distant_orders()
update_distant_orders();
}
/* ACTIONS */
......@@ -1298,17 +1299,17 @@ function send() {
/* Not last step: update distant data */
for (let order_id in orders) {
// Save current step updated data
orders[order_id].previous_steps_data = {}
orders[order_id].previous_steps_data = {};
orders[order_id].previous_steps_data[reception_status] = {
updated_products: orders[order_id].updated_products || []
}
};
orders[order_id].reception_status = updateType;
// Unlock order
orders[order_id].last_update = {
timestamp: null,
fingerprint: null,
}
fingerprint: null
};
// Delete temp data
delete orders[order_id].valid_products;
......@@ -1317,7 +1318,7 @@ function send() {
dbc.bulkDocs(Object.values(orders)).catch((err) => {
console.log(err);
})
});
} else {
// Print etiquettes with new prices
if (updatedProducts.length > 0) {
......@@ -1347,6 +1348,7 @@ function send() {
let groups_doc = doc;
let first_order_id = parseInt(Object.keys(orders)[0]);
for (let i in groups_doc.groups) {
if (groups_doc.groups[i].includes(first_order_id)) {
groups_doc.groups.splice(i, 1);
......@@ -1360,7 +1362,7 @@ function send() {
return dbc.bulkDocs(couchdb_update_data);
})
.catch(function (err) {
console.log(err)
console.log(err);
});
}
......@@ -1414,7 +1416,7 @@ function confirm_all_left_is_good() {
.draw();
// Batch update orders
update_distant_orders()
update_distant_orders();
closeModal();
}
......@@ -1473,7 +1475,7 @@ function init_dom(partners_display_data) {
for (let order_id in orders) {
orders[order_id].last_update = {
timestamp: null,
fingerprint: null,
fingerprint: null
};
}
......@@ -1482,8 +1484,8 @@ function init_dom(partners_display_data) {
})
.catch((err) => {
console.log(err);
})
})
});
});
// Grouped orders
if (Object.keys(orders).length > 1) {
......@@ -1812,7 +1814,7 @@ $(document).ready(function() {
user_comments = orders[Object.keys(orders)[0]].user_comments || "";
// Indicate that these orders are used in this navigator
update_distant_orders()
update_distant_orders();
// Fetch orders data
fetch_data();
......
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