From 4aba44d87fc5744350a5cf2701184a99d89a4fe2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 16 Jul 2021 18:39:57 +0200 Subject: [PATCH] Filters working at User Profiles --- Client/WebServer/css/governance.css | 2 +- .../UI/Spaces/Reports-Space/FiltersHeader.js | 23 +++++----- .../UI/Spaces/Reports-Space/ReportsPage.js | 28 +++++++----- .../UI/Spaces/Reports-Space/UserProfiles.js | 45 ++++++++++++++++++- 4 files changed, 75 insertions(+), 23 deletions(-) diff --git a/Client/WebServer/css/governance.css b/Client/WebServer/css/governance.css index 24af73dad..5d6898106 100644 --- a/Client/WebServer/css/governance.css +++ b/Client/WebServer/css/governance.css @@ -793,7 +793,7 @@ vertical-align: middle; } - .governance-search-input { + .governance-filter-input { width: 95%; height: 45px; margin: 0 20px; diff --git a/Projects/Governance/UI/Spaces/Reports-Space/FiltersHeader.js b/Projects/Governance/UI/Spaces/Reports-Space/FiltersHeader.js index 2b4d652d2..965e2ed32 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/FiltersHeader.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/FiltersHeader.js @@ -8,6 +8,8 @@ function newGovernanceReportsFiltersHeader() { finalize: finalize } + let lastFilters = '' + return thisObject function initialize() { @@ -22,7 +24,7 @@ function newGovernanceReportsFiltersHeader() { let HTML = '' HTML = HTML + '
' HTML = HTML + '
' - HTML = HTML + '
' + HTML = HTML + '
' HTML = HTML + '
' let docsContentDiv = document.getElementById('governance-content-div') docsContentDiv.innerHTML = HTML + UI.projects.education.spaces.docsSpace.footer.addFooter() @@ -37,7 +39,7 @@ function newGovernanceReportsFiltersHeader() { HTML = HTML + '
' HTML = HTML + '
' HTML = HTML + '
' - HTML = HTML + '' + HTML = HTML + '' HTML = HTML + '
' HTML = HTML + '
' @@ -45,24 +47,25 @@ function newGovernanceReportsFiltersHeader() { } function detectEnterOnFiltersBox() { - const element = document.getElementsByClassName("governance-search-input")[0] + const element = document.getElementsByClassName("governance-filter-input")[0] if (UI.projects.education.spaces.docsSpace.commandInterface.command !== undefined) { element.value = UI.projects.education.spaces.docsSpace.commandInterface.command } element.addEventListener("keyup", function (event) { if (event.key === "Enter" || event.keyCode === 13) { - UI.projects.education.spaces.docsSpace.exitEditMode() - UI.projects.education.spaces.docsSpace.currentBookBeingRendered = undefined - UI.projects.education.spaces.docsSpace.currentDocumentBeingRendered = undefined - UI.projects.education.spaces.docsSpace.contextMenu.removeContextMenuFromScreen() - UI.projects.education.spaces.docsSpace.commandInterface.command = element.value.trim() - UI.projects.education.spaces.docsSpace.commandInterface.detectCommands() + lastFilters = element.value.trim() + UI.projects.governance.spaces.reportsSpace.reportsPage.render(undefined, lastFilters) + /* + UI.projects.education.spaces.docsSpace.commandInterface.command = element.value.trim() + UI.projects.education.spaces.docsSpace.commandInterface.detectCommands() + */ } }); } function setFocusOnFiltersBox() { - const element = document.getElementsByClassName("governance-search-input")[0] + const element = document.getElementsByClassName("governance-filter-input")[0] + element.value = lastFilters element.focus() } } \ No newline at end of file diff --git a/Projects/Governance/UI/Spaces/Reports-Space/ReportsPage.js b/Projects/Governance/UI/Spaces/Reports-Space/ReportsPage.js index e43748963..d4b2d608c 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/ReportsPage.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/ReportsPage.js @@ -5,6 +5,7 @@ function newGovernanceReportsReportsPage() { finalize: finalize } + let lastTabIndex return thisObject function initialize() { @@ -15,8 +16,15 @@ function newGovernanceReportsReportsPage() { } - function render(tabIndex) { - + function render(tabIndex, filters) { + + /* Setup tabIndex */ + if (tabIndex === undefined) { + tabIndex = lastTabIndex + } else { + lastTabIndex = tabIndex + } + let resultsArary = [] let initialTime = new Date() buildHTML() @@ -49,49 +57,49 @@ function newGovernanceReportsReportsPage() { switch (tab) { case 'Profiles': { - let response = UI.projects.governance.spaces.reportsSpace.userProfiles.addHTML(1) + let response = UI.projects.governance.spaces.reportsSpace.userProfiles.addHTML(1, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Referrals': { - let response = UI.projects.governance.spaces.reportsSpace.referrals.addHTML(2) + let response = UI.projects.governance.spaces.reportsSpace.referrals.addHTML(2, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Supporters': { - let response = UI.projects.governance.spaces.reportsSpace.supports.addHTML(3) + let response = UI.projects.governance.spaces.reportsSpace.supports.addHTML(3, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Mentors': { - let response = UI.projects.governance.spaces.reportsSpace.mentors.addHTML(4) + let response = UI.projects.governance.spaces.reportsSpace.mentors.addHTML(4, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Pools': { - let response = UI.projects.governance.spaces.reportsSpace.pools.addHTML(5) + let response = UI.projects.governance.spaces.reportsSpace.pools.addHTML(5, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Assets': { - let response = UI.projects.governance.spaces.reportsSpace.assets.addHTML(6) + let response = UI.projects.governance.spaces.reportsSpace.assets.addHTML(6, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Features': { - let response = UI.projects.governance.spaces.reportsSpace.features.addHTML(7) + let response = UI.projects.governance.spaces.reportsSpace.features.addHTML(7, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break } case 'Positions': { - let response = UI.projects.governance.spaces.reportsSpace.positions.addHTML(8) + let response = UI.projects.governance.spaces.reportsSpace.positions.addHTML(8, filters) HTML = HTML + response.HTML resultCounter = response.resultCounter break diff --git a/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js b/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js index ef98dafab..c6be35f48 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js @@ -15,8 +15,20 @@ function newGovernanceReportsUserProfiles() { } - function addHTML(tabIndex) { + function addHTML(tabIndex, filters) { + /* + Setup Filters + */ + let filtersObject + if (filters !== undefined) { + try { + filtersObject = JSON.parse(filters) + } catch (err) { } + } + /* + Other Variables + */ let tableRecords = [] let table = 'userProfiles' let tableRecordDefinition = { @@ -71,7 +83,36 @@ function newGovernanceReportsUserProfiles() { "tokenPower": userProfile.payload.tokenPower | 0 } - tableRecords.push(tableRecord) + /* Apply Filters */ + let passedFilters = true + if (filtersObject !== undefined) { + for (var property in tableRecord) { + if (Object.prototype.hasOwnProperty.call(tableRecord, property)) { + let fiter = filtersObject[property] + if (fiter === undefined) { continue } + let value = tableRecord[property] + let condition = eval(fiter) + if (condition === false) { + passedFilters = false + } + } + } + } else { + /* + We will assume the filter is a string and that needs to be applied to the property name. + */ + if ( + filters !== undefined && + filters !== "" && + tableRecord.name.indexOf(filters) < 0 + ) { + passedFilters = false + } + } + + if (passedFilters === true) { + tableRecords.push(tableRecord) + } } /* Get the sorting order for this table.