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: on:
push: push:
branches: [master, testing] branches: [master, testing]
pull_request: pull_request_target:
branches: [master, testing] branches: [master, testing]
jobs: jobs:
@ -45,8 +45,9 @@ jobs:
- name: Annotate Code Linting Results - name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@1.2.0 uses: ataylorme/eslint-annotate-action@1.2.0
with: with:
repo-token: "${{ secrets.GITHUB_TOKEN }}" repo-token: ${{ secrets.GITHUB_TOKEN }}
report-json: "eslint_report.json" report-json: "eslint_report.json"
only-pr-files: true
- name: Upload ESLint report - name: Upload ESLint report
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: 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 {Array<number>} selectedDevicesIDs
* @param {HTMLElement} target * @param {HTMLElement} target
*/ */
function templateLot(lotID, lot, selectedDevicesIDs, elementTarget, actions) { function templateLot(lot, elementTarget, actions) {
elementTarget.innerHTML = "" 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;"> 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="${lotID}">${lot.name}</label>`; <label class="form-check-label" for="${id}">${name}</label>`;
const existLotList = selectedDevicesIDs.map(selected => lot.devices.includes(selected));
const doc = document.createElement("li"); const doc = document.createElement("li");
doc.innerHTML = htmlTemplate; doc.innerHTML = htmlTemplate;
if (selectedDevicesIDs.length <= 0) { switch (state) {
doc.children[0].disabled = true; case "true":
} else if (existLotList.every(value => value == true)) { doc.children[0].checked = true;
doc.children[0].checked = true; break;
} else if (existLotList.every(value => value == false)) { case "false":
doc.children[0].checked = false; doc.children[0].checked = false;
} else { break;
doc.children[0].indeterminate = true; 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); elementTarget.append(doc);
} }
@ -371,11 +376,31 @@ async function processSelectedDevices() {
lot.devices = devices lot.devices = devices
.filter(device => device.lots.filter(devicelot => devicelot.id == lot.id).length > 0) .filter(device => device.lots.filter(devicelot => devicelot.id == lot.id).length > 0)
.map(device => parseInt(device.id)); .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; 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(""); listHTML.html("");
lots.forEach(lot => templateLot(lot.id, lot, selectedDevicesIDs, listHTML, actions)); lotsList.forEach(lot => templateLot(lot, listHTML, actions));
} catch (error) { } catch (error) {
console.log(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>"); 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 --> <!-- Template Main CSS File -->
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet"> <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 * Template Name: NiceAdmin - v2.2.0

View File

@ -79,9 +79,9 @@
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<span class="d-none" id="activeTradeModal" data-bs-toggle="modal" data-bs-target="#tradeLotModal"></span> <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> <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><hr /></li>
<li> <li>
<a href="#" class="dropdown-item" id="ApplyDeviceLots"> <a href="#" class="dropdown-item" id="ApplyDeviceLots">
@ -407,7 +407,9 @@
<!-- Custom Code --> <!-- Custom Code -->
<script> <script>
const table = new simpleDatatables.DataTable("table") const table = new simpleDatatables.DataTable("table", {
perPage: 20
})
</script> </script>
<script src="{{ url_for('static', filename='js/main_inventory.js') }}"></script> <script src="{{ url_for('static', filename='js/main_inventory.js') }}"></script>
{% endblock main %} {% endblock main %}