Merge branch 'testing' into filter-in-out-trades

This commit is contained in:
Santiago L 2022-04-25 18:35:02 +02:00
commit c6bc695881
6 changed files with 84 additions and 30 deletions

View File

@ -12,7 +12,7 @@ name: ESLint
on:
push:
branches: [master, testing]
pull_request:
pull_request_target:
branches: [master, testing]
jobs:
@ -45,8 +45,9 @@ jobs:
- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@1.2.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
repo-token: ${{ secrets.GITHUB_TOKEN }}
report-json: "eslint_report.json"
only-pr-files: true
- name: Upload ESLint report
uses: actions/upload-artifact@v2
with:

View File

@ -0,0 +1,25 @@
/**
* eReuse CSS
*/
/*--------------------------------------------------------------
# LotsSelector
--------------------------------------------------------------*/
#dropDownLotsSelector {
max-height: 500px;
}
#dropDownLotsSelector>ul#LotsSelector {
list-style-type: none;
margin: 0;
padding: 0;
min-width: max-content;
max-height: 380px;
overflow-y: auto;
}
#dropDownLotsSelector #ApplyDeviceLots {
padding-top: 0px;
padding-bottom: 5px;
}

View File

@ -320,28 +320,33 @@ async function processSelectedDevices() {
* @param {Array<number>} selectedDevicesIDs
* @param {HTMLElement} target
*/
function templateLot(lotID, lot, selectedDevicesIDs, elementTarget, actions) {
function templateLot(lot, elementTarget, actions) {
elementTarget.innerHTML = ""
const {id, name, state} = lot;
const htmlTemplate = `<input class="form-check-input" type="checkbox" id="${lotID}" style="width: 20px; height: 20px; margin-right: 7px;">
<label class="form-check-label" for="${lotID}">${lot.name}</label>`;
const existLotList = selectedDevicesIDs.map(selected => lot.devices.includes(selected));
const htmlTemplate = `<input class="form-check-input" type="checkbox" id="${id}" style="width: 20px; height: 20px; margin-right: 7px;">
<label class="form-check-label" for="${id}">${name}</label>`;
const doc = document.createElement("li");
doc.innerHTML = htmlTemplate;
if (selectedDevicesIDs.length <= 0) {
doc.children[0].disabled = true;
} else if (existLotList.every(value => value == true)) {
doc.children[0].checked = true;
} else if (existLotList.every(value => value == false)) {
doc.children[0].checked = false;
} else {
doc.children[0].indeterminate = true;
switch (state) {
case "true":
doc.children[0].checked = true;
break;
case "false":
doc.children[0].checked = false;
break;
case "indetermined":
doc.children[0].indeterminate = true;
break;
default:
console.warn("This shouldn't be happend: Lot without state: ", lot);
break;
}
doc.children[0].addEventListener("mouseup", (ev) => actions.manage(ev, lotID, selectedDevicesIDs));
doc.children[1].addEventListener("mouseup", (ev) => actions.manage(ev, lotID, selectedDevicesIDs));
doc.children[0].addEventListener("mouseup", (ev) => actions.manage(ev, id, selectedDevicesIDs));
doc.children[1].addEventListener("mouseup", (ev) => actions.manage(ev, id, selectedDevicesIDs));
elementTarget.append(doc);
}
@ -371,11 +376,31 @@ async function processSelectedDevices() {
lot.devices = devices
.filter(device => device.lots.filter(devicelot => devicelot.id == lot.id).length > 0)
.map(device => parseInt(device.id));
switch (lot.devices.length) {
case 0:
lot.state = "false";
break;
case selectedDevicesIDs.length:
lot.state = "true";
break;
default:
lot.state = "indetermined";
break;
}
return lot;
})
let lotsList = [];
lotsList.push(lots.filter(lot => lot.state == "true").sort((a,b) => a.name.localeCompare(b.name)));
lotsList.push(lots.filter(lot => lot.state == "indetermined").sort((a,b) => a.name.localeCompare(b.name)));
lotsList.push(lots.filter(lot => lot.state == "false").sort((a,b) => a.name.localeCompare(b.name)));
lotsList = lotsList.flat(); // flat array
listHTML.html("");
lots.forEach(lot => templateLot(lot.id, lot, selectedDevicesIDs, listHTML, actions));
lotsList.forEach(lot => templateLot(lot, listHTML, actions));
} catch (error) {
console.log(error);
listHTML.html("<li style=\"color: red; text-align: center\">Error feching devices and lots<br>(see console for more details)</li>");

View File

@ -29,6 +29,7 @@
<!-- Template Main CSS File -->
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/devicehub.css') }}" rel="stylesheet">
<!-- =======================================================
* Template Name: NiceAdmin - v2.2.0

View File

@ -79,9 +79,9 @@
<span class="caret"></span>
</button>
<span class="d-none" id="activeTradeModal" data-bs-toggle="modal" data-bs-target="#tradeLotModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnLots" style="width: 300px;" id="dropDownLotsSelector">
<ul class="dropdown-menu" aria-labelledby="btnLots" id="dropDownLotsSelector">
<h6 class="dropdown-header">Select some devices to manage lots</h6>
<ul style="list-style-type: none; margin: 0; padding: 0;" class="mx-3" id="LotsSelector"></ul>
<ul class="mx-3" id="LotsSelector"></ul>
<li><hr /></li>
<li>
<a href="#" class="dropdown-item" id="ApplyDeviceLots">
@ -407,7 +407,9 @@
<!-- Custom Code -->
<script>
const table = new simpleDatatables.DataTable("table")
const table = new simpleDatatables.DataTable("table", {
perPage: 20
})
</script>
<script src="{{ url_for('static', filename='js/main_inventory.js') }}"></script>
{% endblock main %}