diff --git a/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js b/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js index d9288273d..2296d49f2 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/UserProfiles.js @@ -19,7 +19,6 @@ function newGovernanceReportsUserProfiles() { function addHTML() { thisObject.resultCounter = 0 - let HTML = '' let tableRecords = [] let table = 'userProfiles' let tableRecordDefinition = { @@ -69,141 +68,6 @@ function newGovernanceReportsUserProfiles() { tableRecords.push(tableRecord) } - /* - Get the sorting order for this table. - */ - let sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] - /* - Set the default sorting order for this table. - */ - if (sortingOrder === undefined) { - UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] = { - property: 'name', - order: 'ascending' - } - sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] - } - /* - Get the property type for the current sorting order. - */ - let propertyType - for (let i = 0; i < tableRecordDefinition.properties.length; i++) { - let property = tableRecordDefinition.properties[i] - if (property.name === sortingOrder.property) { - propertyType = property.type - break - } - } - /* - Apply the sorting order for this table. - */ - switch (propertyType) { - case 'string': { - switch (sortingOrder.order) { - case 'ascending': { - tableRecords.sort((a, b) => (a[sortingOrder.property].toLowerCase() > b[sortingOrder.property].toLowerCase()) ? 1 : -1) - break - } - case 'descending': { - tableRecords.sort((a, b) => (a[sortingOrder.property].toLowerCase() > b[sortingOrder.property].toLowerCase()) ? -1 : 1) - break - } - } - break - } - case 'number': { - switch (sortingOrder.order) { - case 'ascending': { - tableRecords.sort((a, b) => (a[sortingOrder.property] > b[sortingOrder.property]) ? 1 : -1) - break - } - case 'descending': { - tableRecords.sort((a, b) => (a[sortingOrder.property] > b[sortingOrder.property]) ? -1 : 1) - break - } - } - break - } - } - - /* - Build the HTML - */ - let odd = false - const upArrow = '↑' - const downArrow = '↓' - - HTML = HTML + '
' - - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' - for (let i = 0; i < tableRecordDefinition.properties.length; i++) { - let property = tableRecordDefinition.properties[i] - let newOrder - let orderArrow - /* - If the property is the one defining the order, then the new order will be - the opossite order. - */ - if (property.name === sortingOrder.property) { - if (sortingOrder.order === 'ascending') { - newOrder = 'descending' - orderArrow = upArrow - } else { - newOrder = 'ascending' - orderArrow = downArrow - } - } else { - orderArrow = "" - /* - If the property is not the current defininf the order, then the new order will - be the default order for that property. - */ - for (let i = 0; i < tableRecordDefinition.properties.length; i++) { - let propertyDefinition = tableRecordDefinition.properties[i] - if (property.name === propertyDefinition.name) { - newOrder = propertyDefinition.order - break - } - } - } - HTML = HTML + '' - } - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' - - for (let j = 0; j < tableRecords.length; j++) { - let tableRecord = tableRecords[j] - - if (odd === true) { - HTML = HTML + '' - odd = false - } else { - HTML = HTML + '' - odd = true - } - - /* - Iterate through tableRecord properties. - */ - for (var property in tableRecord) { - if (Object.prototype.hasOwnProperty.call(tableRecord, property)) { - HTML = HTML + '' - } - } - - thisObject.resultCounter++ - - HTML = HTML + '' - } - - HTML = HTML + '' - HTML = HTML + '
' + '' + property.label + ' ' + orderArrow +'' + '
' + tableRecord[property] + '
' - - HTML = HTML + '
' - - return HTML + return UI.projects.governance.utilities.tables.addHTML(table, tableRecords, tableRecordDefinition) } } \ No newline at end of file diff --git a/Projects/Governance/UI/Utilities/Tables.js b/Projects/Governance/UI/Utilities/Tables.js index 1fb1ef7ac..c0a4e9c2d 100644 --- a/Projects/Governance/UI/Utilities/Tables.js +++ b/Projects/Governance/UI/Utilities/Tables.js @@ -1,23 +1,146 @@ function newGovernanceUtilitiesTables() { let thisObject = { - onlyOneProgram: onlyOneProgram + addHTML: addHTML } return thisObject - function onlyOneProgram(userProfile, programNodeType) { + function addHTML(table, tableRecords, tableRecordDefinition) { + let HTML = '' /* - Find all the nodes representing the current program. - */ - let programs = UI.projects.foundations.utilities.branches.nodeBranchToArray(userProfile, programNodeType) - if (programs !== undefined) { - if (programs.length > 1) { - userProfile.payload.uiObject.setErrorMessage('Only one ' + programNodeType + ' is allowed.') - return + Get the sorting order for this table. + */ + let sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] + /* + Set the default sorting order for this table. + */ + if (sortingOrder === undefined) { + UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] = { + property: 'name', + order: 'ascending' } - if (programs.length === 1) { - return programs[0] + sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] + } + /* + Get the property type for the current sorting order. + */ + let propertyType + for (let i = 0; i < tableRecordDefinition.properties.length; i++) { + let property = tableRecordDefinition.properties[i] + if (property.name === sortingOrder.property) { + propertyType = property.type + break } } + /* + Apply the sorting order for this table. + */ + switch (propertyType) { + case 'string': { + switch (sortingOrder.order) { + case 'ascending': { + tableRecords.sort((a, b) => (a[sortingOrder.property].toLowerCase() > b[sortingOrder.property].toLowerCase()) ? 1 : -1) + break + } + case 'descending': { + tableRecords.sort((a, b) => (a[sortingOrder.property].toLowerCase() > b[sortingOrder.property].toLowerCase()) ? -1 : 1) + break + } + } + break + } + case 'number': { + switch (sortingOrder.order) { + case 'ascending': { + tableRecords.sort((a, b) => (a[sortingOrder.property] > b[sortingOrder.property]) ? 1 : -1) + break + } + case 'descending': { + tableRecords.sort((a, b) => (a[sortingOrder.property] > b[sortingOrder.property]) ? -1 : 1) + break + } + } + break + } + } + /* + Build the HTML + */ + let odd = false + const upArrow = '↑' + const downArrow = '↓' + + HTML = HTML + '
' + + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' + for (let i = 0; i < tableRecordDefinition.properties.length; i++) { + let property = tableRecordDefinition.properties[i] + let newOrder + let orderArrow + /* + If the property is the one defining the order, then the new order will be + the opossite order. + */ + if (property.name === sortingOrder.property) { + if (sortingOrder.order === 'ascending') { + newOrder = 'descending' + orderArrow = upArrow + } else { + newOrder = 'ascending' + orderArrow = downArrow + } + } else { + orderArrow = "" + /* + If the property is not the current defininf the order, then the new order will + be the default order for that property. + */ + for (let i = 0; i < tableRecordDefinition.properties.length; i++) { + let propertyDefinition = tableRecordDefinition.properties[i] + if (property.name === propertyDefinition.name) { + newOrder = propertyDefinition.order + break + } + } + } + HTML = HTML + '' + } + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' + + for (let j = 0; j < tableRecords.length; j++) { + let tableRecord = tableRecords[j] + + if (odd === true) { + HTML = HTML + '' + odd = false + } else { + HTML = HTML + '' + odd = true + } + + /* + Iterate through tableRecord properties. + */ + for (var property in tableRecord) { + if (Object.prototype.hasOwnProperty.call(tableRecord, property)) { + HTML = HTML + '' + } + } + + thisObject.resultCounter++ + + HTML = HTML + '' + } + + HTML = HTML + '' + HTML = HTML + '
' + '' + property.label + ' ' + orderArrow + '' + '
' + tableRecord[property] + '
' + + HTML = HTML + '
' + + return HTML } } \ No newline at end of file diff --git a/Projects/Governance/UI/Utilities/Validations.js b/Projects/Governance/UI/Utilities/Validations.js index e369bcbaa..4b23c27ce 100644 --- a/Projects/Governance/UI/Utilities/Validations.js +++ b/Projects/Governance/UI/Utilities/Validations.js @@ -1,4 +1,4 @@ -function newFoundationsUtilitiesValidations() { +function newGovernanceUtilitiesValidations () { let thisObject = { onlyOneProgram: onlyOneProgram }