diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index 6113c185..7e42feaf 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -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: diff --git a/ereuse_devicehub/static/css/devicehub.css b/ereuse_devicehub/static/css/devicehub.css new file mode 100644 index 00000000..e6ae1893 --- /dev/null +++ b/ereuse_devicehub/static/css/devicehub.css @@ -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; +} diff --git a/ereuse_devicehub/static/css/style.css b/ereuse_devicehub/static/css/style.css index 8e263853..1fd44f19 100644 --- a/ereuse_devicehub/static/css/style.css +++ b/ereuse_devicehub/static/css/style.css @@ -1,10 +1,10 @@ -/** -* Template Name: NiceAdmin - v2.2.0 -* Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/ -* Author: BootstrapMade.com -* License: https://bootstrapmade.com/license/ -*/ - +/** +* Template Name: NiceAdmin - v2.2.0 +* Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/ +* Author: BootstrapMade.com +* License: https://bootstrapmade.com/license/ +*/ + /*-------------------------------------------------------------- # General --------------------------------------------------------------*/ @@ -1081,4 +1081,4 @@ h1, h2, h3, h4, h5, h6 { text-align: center; font-size: 13px; color: #012970; -} \ No newline at end of file +} diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 34dd42c3..c230363d 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -320,28 +320,33 @@ async function processSelectedDevices() { * @param {Array} 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 = ` - `; - - const existLotList = selectedDevicesIDs.map(selected => lot.devices.includes(selected)); + const htmlTemplate = ` + `; 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("
  • Error feching devices and lots
    (see console for more details)
  • "); diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base.html b/ereuse_devicehub/templates/ereuse_devicehub/base.html index 8e147828..3b7c94bd 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base.html @@ -29,6 +29,7 @@ + {% endblock main %}