From 576c963b24fa7a035628659f6e72912ed3914088 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 28 Jul 2021 10:40:44 +0200 Subject: [PATCH] Governance Github Program Finished --- Client/WebServer/css/governance.css | 3 +- .../UI/Function-Libraries/GithubProgram.js | 20 +-- Projects/Governance/UI/Globals/Reports.js | 2 +- .../UI/Spaces/Reports-Space/Github.js | 139 ++++++++++++++++++ .../UI/Spaces/Reports-Space/ReportsPage.js | 8 +- .../UI/Spaces/Reports-Space/ReportsSpace.js | 6 + .../UI/Spaces/Reports-Space/Staking.js | 15 +- .../Spaces/User-Profile-Space/UserProfile.js | 6 +- 8 files changed, 171 insertions(+), 28 deletions(-) create mode 100644 Projects/Governance/UI/Spaces/Reports-Space/Github.js diff --git a/Client/WebServer/css/governance.css b/Client/WebServer/css/governance.css index 198c2feb0..d9be1c182 100644 --- a/Client/WebServer/css/governance.css +++ b/Client/WebServer/css/governance.css @@ -885,7 +885,8 @@ #governance-tab10:checked ~ .governance-search-result-content #content10, #governance-tab11:checked ~ .governance-search-result-content #content11, #governance-tab12:checked ~ .governance-search-result-content #content12, - #governance-tab13:checked ~ .governance-search-result-content #content13 { + #governance-tab13:checked ~ .governance-search-result-content #content13, + #governance-tab14:checked ~ .governance-search-result-content #content14 { display: block; } diff --git a/Projects/Governance/UI/Function-Libraries/GithubProgram.js b/Projects/Governance/UI/Function-Libraries/GithubProgram.js index 3fe817e10..5aacc90b2 100644 --- a/Projects/Governance/UI/Function-Libraries/GithubProgram.js +++ b/Projects/Governance/UI/Function-Libraries/GithubProgram.js @@ -120,14 +120,14 @@ function newGovernanceFunctionLibraryGithubProgram() { return } let githubUsername = profileSignature.message - node.payload.githubProgram.hasStar = UI.projects.governance.spaces.userProfileSpace.githubStars.get(githubUsername) - node.payload.githubProgram.hasWatch = UI.projects.governance.spaces.userProfileSpace.githubWatchers.get(githubUsername) - node.payload.githubProgram.hasFork = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) + node.payload.githubProgram.starsCount = UI.projects.governance.spaces.userProfileSpace.githubStars.get(githubUsername) + node.payload.githubProgram.watchersCount = UI.projects.governance.spaces.userProfileSpace.githubWatchers.get(githubUsername) + node.payload.githubProgram.forksCount = UI.projects.governance.spaces.userProfileSpace.githubForks.get(githubUsername) node.payload.githubProgram.engagement = 0 - if (node.payload.githubProgram.hasStar === true) { node.payload.githubProgram.engagement++ } - if (node.payload.githubProgram.hasWatch === true) { node.payload.githubProgram.engagement++ } - if (node.payload.githubProgram.hasFork === true) { node.payload.githubProgram.engagement++ } + if (node.payload.githubProgram.starsCount > 0) { node.payload.githubProgram.engagement = node.payload.githubProgram.engagement + node.payload.githubProgram.starsCount } + if (node.payload.githubProgram.watchersCount > 0) { node.payload.githubProgram.engagement = node.payload.githubProgram.engagement + node.payload.githubProgram.watchersCount } + if (node.payload.githubProgram.forksCount > 0) { node.payload.githubProgram.engagement = node.payload.githubProgram.engagement + node.payload.githubProgram.forksCount } if ( node.payload.githubProgram.engagement > 0) { @@ -171,7 +171,7 @@ function newGovernanceFunctionLibraryGithubProgram() { return } const MAX_ENGAGEMENT = 3 - programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio * programNode.payload.githubProgram.engagement / MAX_ENGAGEMENT + programNode.payload.githubProgram.awarded.tokens = programNode.payload.githubProgram.ownPower / totalPowerRewardRatio * programNode.payload.githubProgram.engagement / MAX_ENGAGEMENT drawProgram(programNode) } @@ -199,13 +199,13 @@ function newGovernanceFunctionLibraryGithubProgram() { node.tokensAwarded.payload.uiObject.statusAtAngle = false let extraText = '' - if (node.payload.githubProgram.hasStar === true) { + if (node.payload.githubProgram.starsCount > 0) { extraText = extraText + ' + 1 Star' } - if (node.payload.githubProgram.hasWatch === true) { + if (node.payload.githubProgram.watchersCount > 0) { extraText = extraText + ' + 1 Watch' } - if (node.payload.githubProgram.hasFork === true) { + if (node.payload.githubProgram.forksCount > 0) { extraText = extraText + ' + 1 Fork' } diff --git a/Projects/Governance/UI/Globals/Reports.js b/Projects/Governance/UI/Globals/Reports.js index ca77e47d6..93a611302 100644 --- a/Projects/Governance/UI/Globals/Reports.js +++ b/Projects/Governance/UI/Globals/Reports.js @@ -1,6 +1,6 @@ function newGovernanceGlobalsReports() { let thisObject = { - REPORTS_SPACE_WIDTH: 1150 + REPORTS_SPACE_WIDTH: 1250 } return thisObject } \ No newline at end of file diff --git a/Projects/Governance/UI/Spaces/Reports-Space/Github.js b/Projects/Governance/UI/Spaces/Reports-Space/Github.js new file mode 100644 index 000000000..a6fa5411c --- /dev/null +++ b/Projects/Governance/UI/Spaces/Reports-Space/Github.js @@ -0,0 +1,139 @@ +function newGovernanceReportsGithub() { + let thisObject = { + addHTML: addHTML, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function initialize() { + + } + + function finalize() { + + } + + function addHTML(tabIndex, filters) { + /* + Parameters + */ + let table = 'github' + let programName = 'Github Program' + let programPropertyName = 'githubProgram' + /* + Setup Filters + */ + let filtersObject + if (filters !== undefined) { + try { + filtersObject = JSON.parse(filters) + } catch (err) { } + } + /* + Other Variables + */ + let tableRecords = [] + let tableRecordDefinition = { + "properties": [ + { + "name": "name", + "label": "User Profile", + "type": "string", + "order": "ascending", + "textAlign": "left" + }, + { + "name": "githubPower", + "label": "Github Power", + "type": "number", + "order": "descending", + "textAlign": "center", + "format": "2 decimals" + }, + { + "name": "stars", + "label": "Stars", + "type": "number", + "order": "descending", + "textAlign": "center", + "format": "integer" + }, + { + "name": "watching", + "label": "Watching", + "type": "number", + "order": "descending", + "textAlign": "center", + "format": "integer" + }, + { + "name": "forks", + "label": "Forks", + "type": "number", + "order": "descending", + "textAlign": "center", + "format": "integer" + }, + { + "name": "tokensAwarded", + "label": "Awarded", + "type": "number", + "order": "descending", + "textAlign": "center", + "format": "2 decimals" + } + ] + } + /* + Here we get from the workspace all User Profiles. + */ + let userProfiles = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByNodeType('User Profile') + /* + Transform the result array into table records. + */ + for (let j = 0; j < userProfiles.length; j++) { + let userProfile = userProfiles[j] + + if (userProfile.tokenPowerSwitch === undefined) { continue } + let program = UI.projects.governance.utilities.validations.onlyOneProgram(userProfile, programName) + if (program === undefined) { continue } + if (program.payload === undefined) { continue } + + let tableRecord = { + "name": userProfile.name, + "githubPower": program.payload[programPropertyName].ownPower | 0, + "stars": program.payload[programPropertyName].starsCount | 0, + "watching": program.payload[programPropertyName].watchersCount | 0, + "forks": program.payload[programPropertyName].forksCount | 0, + "tokensAwarded": program.payload[programPropertyName].awarded.tokens | 0 + } + + if (UI.projects.governance.utilities.filters.applyFilters(filters, filtersObject, tableRecord) === true) { + 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: 'tokensAwarded', + order: 'descending' + } + sortingOrder = UI.projects.governance.spaces.reportsSpace.tablesSortingOrders[table] + } + return UI.projects.governance.utilities.tables.addHTML( + table, + tableRecords, + tableRecordDefinition, + sortingOrder, + tabIndex + ) + } +} \ 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 d21e3d7ce..bc6815f2c 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/ReportsPage.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/ReportsPage.js @@ -30,7 +30,7 @@ function newGovernanceReportsReportsPage() { buildHTML() function buildHTML() { - const tabs = ['Profiles', 'Referrals', 'Supporters', 'Mentors', 'Claims', 'Votes', 'Staking', 'Delegation', 'Pools', 'Assets', 'Features', 'Positions', 'Mining'] + const tabs = ['Profiles', 'Referrals', 'Supporters', 'Mentors', 'Claims', 'Votes', 'Staking', 'Delegation', 'Github', 'Pools', 'Assets', 'Features', 'Positions', 'Mining'] let HTML = '' HTML = HTML + '
' HTML = HTML + UI.projects.governance.spaces.reportsSpace.filtersHeader.addFilterHeader() @@ -104,6 +104,12 @@ function newGovernanceReportsReportsPage() { resultCounter = response.resultCounter break } + case 'Github': { + let response = UI.projects.governance.spaces.reportsSpace.github.addHTML(8, filters) + HTML = HTML + response.HTML + resultCounter = response.resultCounter + break + } case 'Pools': { let response = UI.projects.governance.spaces.reportsSpace.pools.addHTML(9, filters) HTML = HTML + response.HTML diff --git a/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js b/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js index dc95dcf31..76a440bcd 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/ReportsSpace.js @@ -15,6 +15,7 @@ function newGobernanceReportsSpace() { votes: undefined, staking: undefined, delegations: undefined, + github: undefined, pools: undefined, assets: undefined, features: undefined, @@ -85,6 +86,9 @@ function newGobernanceReportsSpace() { thisObject.delegation.finalize() thisObject.delegation = undefined + thisObject.github.finalize() + thisObject.github = undefined + thisObject.pools.finalize() thisObject.pools = undefined @@ -131,6 +135,7 @@ function newGobernanceReportsSpace() { thisObject.votes = newGovernanceReportsVotes() thisObject.staking = newGovernanceReportsStaking() thisObject.delegation = newGovernanceReportsDelegation() + thisObject.github = newGovernanceReportsGithub() thisObject.pools = newGovernanceReportsPools() thisObject.assets = newGovernanceReportsAssets() thisObject.features = newGovernanceReportsFeatures() @@ -147,6 +152,7 @@ function newGobernanceReportsSpace() { thisObject.votes.initialize() thisObject.staking.initialize() thisObject.delegation.initialize() + thisObject.github.initialize() thisObject.pools.initialize() thisObject.assets.initialize() thisObject.features.initialize() diff --git a/Projects/Governance/UI/Spaces/Reports-Space/Staking.js b/Projects/Governance/UI/Spaces/Reports-Space/Staking.js index 48b044c72..8417167e3 100644 --- a/Projects/Governance/UI/Spaces/Reports-Space/Staking.js +++ b/Projects/Governance/UI/Spaces/Reports-Space/Staking.js @@ -45,16 +45,8 @@ function newGovernanceReportsStaking() { "textAlign": "left" }, { - "name": "ownPower", - "label": "Own Power", - "type": "number", - "order": "descending", - "textAlign": "center", - "format": "2 decimals" - }, - { - "name": "incoming", - "label": "Incoming", + "name": "stakingPower", + "label": "Staking Power", "type": "number", "order": "descending", "textAlign": "center", @@ -87,8 +79,7 @@ function newGovernanceReportsStaking() { let tableRecord = { "name": userProfile.name, - "ownPower": program.payload[programPropertyName].ownPower | 0, - "incoming": program.payload[programPropertyName].incomingPower | 0, + "stakingPower": program.payload[programPropertyName].ownPower | 0, "tokensAwarded": program.payload[programPropertyName].awarded.tokens | 0 } diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 250d5b8e1..5a6ddaae7 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -103,7 +103,7 @@ function newGovernanceUserProfileSpace() { for (let i = 0; i < githubStarsArray.length; i++) { let githubUsername = githubStarsArray[i] - thisObject.githubStars.set(githubUsername, true) + thisObject.githubStars.set(githubUsername, 1) } requestWatchers() @@ -116,7 +116,7 @@ function newGovernanceUserProfileSpace() { for (let i = 0; i < githubWatchersArray.length; i++) { let githubUsername = githubWatchersArray[i] - thisObject.githubWatchers.set(githubUsername, true) + thisObject.githubWatchers.set(githubUsername, 1) } requestForks() @@ -129,7 +129,7 @@ function newGovernanceUserProfileSpace() { for (let i = 0; i < githubForksArray.length; i++) { let githubUsername = githubForksArray[i] - thisObject.githubForks.set(githubUsername, true) + thisObject.githubForks.set(githubUsername, 1) } } }