Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexis AOUN
third-party
Commits
9e7a737c
Commit
9e7a737c
authored
Jun 11, 2021
by
Damien Moulard
Committed by
Alexis Aoun
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] linting
parent
7a034324
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
82 deletions
+99
-82
reception_index.js
reception/static/js/reception_index.js
+65
-58
reception_produits.js
reception/static/js/reception_produits.js
+34
-24
No files found.
reception/static/js/reception_index.js
View file @
9e7a737c
...
...
@@ -42,7 +42,7 @@ function group_goto(group_index) {
// Find order data
for
(
let
order
of
orders
)
{
if
(
order
.
id
==
order_groups
.
groups
[
group_index
][
i
])
{
order_data
=
order
order_data
=
order
;
}
}
...
...
@@ -55,7 +55,7 @@ function group_goto(group_index) {
/**
* 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
*/
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
(()
=>
{
if
(
go_to_order
===
true
)
{
goto
(
order_data
.
id
)
goto
(
order_data
.
id
)
;
}
})
.
catch
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
// Create if doesn't exist
if
(
err
.
status
===
404
)
{
let
order_doc
=
{
...
order_data
};
order_doc
.
_id
=
order_doc_id
;
dbc
.
put
(
order_doc
,
(
err
)
=>
{
if
(
!
err
)
{
if
(
go_to_order
===
true
)
{
goto
(
order_data
.
id
)
if
(
err
.
status
===
404
)
{
let
order_doc
=
{
...
order_data
};
order_doc
.
_id
=
order_doc_id
;
dbc
.
put
(
order_doc
,
(
err
)
=>
{
if
(
!
err
)
{
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 */
...
...
@@ -96,7 +97,7 @@ function create_order_doc(order_data, go_to_order = false) {
/**
* Validate all prices of an order
*/
function
validatePrices
()
{
function
validatePrices
()
{
// Loading on
openModal
();
...
...
@@ -119,15 +120,15 @@ function create_order_doc(order_data, go_to_order = false) {
dbc
.
get
(
`order_
${
order
[
'id'
]}
`
).
then
((
doc
)
=>
{
return
dbc
.
remove
(
doc
);
})
.
then
(()
=>
{
callback_update
=
true
;
reload
();
})
.
catch
((
err
)
=>
{
.
then
(()
=>
{
callback_update
=
true
;
reload
();
})
.
catch
((
err
)
=>
{
// No doc found
console
.
log
(
err
);
reload
();
});
console
.
log
(
err
);
reload
();
});
},
error
:
function
()
{
closeModal
();
...
...
@@ -168,7 +169,7 @@ function create_order_doc(order_data, go_to_order = false) {
/**
* Action fired when orders are grouped (new group)
* @returns
* @returns
*/
function
group_action
()
{
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() {
if
(
!
err
)
{
goto
(
group_ids
[
0
]);
}
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
);
}
});
...
...
@@ -210,35 +211,35 @@ function group_action() {
/**
* 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
()
{
if
(
table_orders
!==
null
)
{
let
groups_display_content
=
"<ul>"
;
for
(
let
group_index
in
order_groups
.
groups
)
{
let
group_orders
=
[];
// Extract every order in the groups from the orders table
for
(
group_order_id
of
order_groups
.
groups
[
group_index
])
{
// Look for order in datatable"
for
(
let
i
=
0
;
i
<
table_orders
.
rows
().
data
().
length
;
i
++
)
{
if
(
group_order_id
==
table_orders
.
rows
(
i
).
data
()[
0
].
id
)
{
var
order
=
table_orders
.
rows
(
i
).
data
()[
0
];
group_orders
.
push
(
order
);
// remove table row
table_orders
.
rows
(
i
).
remove
()
.
draw
();
}
}
}
// Display group
document
.
getElementById
(
"container_groups"
).
hidden
=
false
;
let
group_row
=
`<li class="group_line"> Commandes de `
;
for
(
let
i
in
group_orders
)
{
if
(
i
==
group_orders
.
length
-
1
)
{
// last element of list
group_row
+=
"<b>"
+
group_orders
[
i
].
partner
+
"</b> du "
+
group_orders
[
i
].
date_order
+
" : "
;
...
...
@@ -246,7 +247,7 @@ function display_grouped_orders() {
group_row
+=
"<b>"
+
group_orders
[
i
].
partner
+
"</b> du "
+
group_orders
[
i
].
date_order
+
", "
;
}
}
if
(
group_orders
[
0
].
reception_status
==
'False'
)
{
group_row
+=
"<button class='btn--primary' onClick='group_goto("
+
group_index
...
...
@@ -256,7 +257,7 @@ function display_grouped_orders() {
+
group_index
+
")'>Mettre à jour les prix</button>"
;
}
group_row
+=
"</li>"
;
groups_display_content
+=
group_row
;
}
...
...
@@ -436,7 +437,7 @@ $(document).ready(function() {
openModal
();
$
.
ajaxSetup
({
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)
}
});
// Init couchdb
// Init couchdb
dbc
=
new
PouchDB
(
couchdb_dbname
),
sync
=
PouchDB
.
sync
(
couchdb_dbname
,
couchdb_server
,
{
live
:
true
,
...
...
@@ -445,26 +446,32 @@ $(document).ready(function() {
});
// 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
// Get or create order groups doc
dbc
.
get
(
"grouped_orders"
).
then
((
doc
)
=>
{
order_groups
=
doc
;
})
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
if
(
err
.
status
===
404
)
{
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
if
(
err
.
status
===
404
)
{
// Create if doesn't exist
dbc
.
put
(
order_groups
,
(
err
,
result
)
=>
{
if
(
!
err
)
{
order_groups
.
_rev
=
result
.
rev
;
}
else
{
console
.
log
(
"document pour les groupes déjà créé"
);
console
.
log
(
err
);
}
});
}
});
dbc
.
put
(
order_groups
,
(
err
,
result
)
=>
{
if
(
!
err
)
{
order_groups
.
_rev
=
result
.
rev
;
}
else
{
console
.
log
(
"document pour les groupes déjà créé"
);
console
.
log
(
err
);
}
});
}
});
// Set date format for DataTable so date ordering can work
$
.
fn
.
dataTable
.
moment
(
'D/M/Y'
);
...
...
reception/static/js/reception_produits.js
View file @
9e7a737c
...
...
@@ -112,13 +112,13 @@ function select_product_from_bc(barcode) {
/**
* Update couchdb order
* @param {int} order_id
* @param {int} order_id
*/
function
update_distant_order
(
order_id
)
{
// TODO insert fingerprint & timestamp
console
.
log
(
order_id
);
dbc
.
put
(
orders
[
order_id
],
(
err
,
result
)
=>
{
dbc
.
put
(
orders
[
order_id
],
(
err
,
result
)
=>
{
if
(
!
err
&&
result
!==
undefined
)
{
orders
[
order_id
].
_rev
=
result
.
rev
;
}
else
{
...
...
@@ -417,7 +417,7 @@ function initLists() {
orders
[
data
.
id_po
][
'valid_products'
]
=
[];
}
orders
[
data
.
id_po
][
'valid_products'
].
push
(
data
[
'id'
]);
update_distant_order
(
data
.
id_po
)
update_distant_order
(
data
.
id_po
)
;
// Reset search
document
.
getElementById
(
'search_input'
).
value
=
''
;
...
...
@@ -1205,9 +1205,9 @@ function send() {
}
// 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
;
}
else
{
// group
}
else
{
// group
document
.
getElementById
(
"success_order_name_container"
).
hidden
=
true
;
document
.
getElementById
(
"success_orders_name_container"
).
hidden
=
false
;
...
...
@@ -1322,7 +1322,7 @@ function send() {
traditional
:
true
,
contentType
:
"application/json; charset=utf-8"
,
data
:
JSON
.
stringify
(
updates
),
success
:
function
(
data
)
{},
success
:
function
()
{},
error
:
function
()
{
closeModal
();
alert
(
'Erreur dans l
\'
envoi du rapport.'
);
...
...
@@ -1395,7 +1395,7 @@ function saveErrorReport() {
// Save comments in all orders
for
(
order_id
of
Object
.
keys
(
orders
))
{
orders
[
order_id
].
user_comments
=
user_comments
;
update_distant_order
(
order_id
)
update_distant_order
(
order_id
)
;
}
document
.
getElementById
(
"search_input"
).
focus
();
...
...
@@ -1410,8 +1410,8 @@ var get_barcodes = async function() {
/**
* 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
)
{
// Grouped orders
...
...
@@ -1597,7 +1597,7 @@ $(document).ready(function() {
let
pathArray
=
window
.
location
.
pathname
.
split
(
'/'
);
let
id
=
pathArray
[
pathArray
.
length
-
1
];
// Init couchdb
// Init couchdb
dbc
=
new
PouchDB
(
couchdb_dbname
),
sync
=
PouchDB
.
sync
(
couchdb_dbname
,
couchdb_server
,
{
live
:
true
,
...
...
@@ -1606,6 +1606,12 @@ $(document).ready(function() {
});
// 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
// Disable alert errors from datatables
...
...
@@ -1670,7 +1676,8 @@ $(document).ready(function() {
/* Get order info from couchdb */
// Get order groups
let
order_groups
=
[]
let
order_groups
=
[];
dbc
.
get
(
"grouped_orders"
).
then
((
doc
)
=>
{
order_groups
=
doc
.
groups
;
...
...
@@ -1695,8 +1702,9 @@ $(document).ready(function() {
}).
then
(
function
(
result
)
{
// for each order in the group
for
(
let
order_id
of
group_ids
)
{
// find order
// find order
let
order
=
result
.
rows
.
find
(
el
=>
el
.
id
==
'order_'
+
order_id
);
order
=
order
.
doc
;
orders
[
order_id
]
=
order
;
...
...
@@ -1725,9 +1733,22 @@ $(document).ready(function() {
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
)
{
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
);
report_JS_error
(
err
,
'reception'
);
...
...
@@ -1735,15 +1756,4 @@ $(document).ready(function() {
alert
(
"Erreur au chargement de cette commande. Vous allez être redirigé."
);
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
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment