Skip to content

Commit

Permalink
Merge pull request #63 from kwheelan/55-adjust-target-logic
Browse files Browse the repository at this point in the history
55 adjust target logic
  • Loading branch information
kwheelan authored Jul 31, 2024
2 parents 2aad965 + dbb4cfe commit 6a3576a
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 93 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ jspm_packages/
.env
.env.test
node_modules

# excel temp files
~$*
Binary file modified sample_data/FY26 Detail Sheet - v3.0 Prototype.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion src/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
font-size: 14px;
/* spacing */
--header-height : 125px;
--sidebar-width: 250px;
--sidebar-width: 300px;
}

/* Button styling */
Expand Down
44 changes: 5 additions & 39 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,45 +123,11 @@ <h3 id="supp-title" class="accordion-title">
<br>
<h4 id="sidebar-title">Summary</h4>
<br>
<h6 id="section-header"><strong>Baseline</strong></h6>
<div id="baseline-stats">
<div class='sidebar-stat-line' id="target">
<span class="stat-label">FY26 target:</span>
<span class="stat"></span>
</div>
<div class='sidebar-stat-line' id="baseline-revenue">
<span class="stat-label">Projected revenues:</span>
<span class="stat"></span>
</div>
<div class='sidebar-stat-line' id="baseline-personnel">
<span class="stat-label">Personnel cost:</span>
<span class="stat"></span>
</div>
<div class='sidebar-stat-line' id="baseline-nonpersonnel">
<span class="stat-label">Non-personnel cost:</span>
<span class="stat"></span>
</div>
<div class='sidebar-stat-line' id="baseline-total">
<span class="stat-label">Total baseline:</span>
<span class="stat"></span>
</div>
</div>
<br>
<h6 id="section-header"><strong>Supplemental</strong></h6>
<div id="supp-stats">
<div class='sidebar-stat-line' id="supp-revenue">
<span class="stat-label">Estimated revenues:</span>
<span class="stat"></span>
</div>
<div class='sidebar-stat-line' id="supp-expenses">
<span class="stat-label">Esimated expenditures:</span>
<span class="stat"></span>
</div>
<div class='sidebar-stat-line' id="supp-total">
<span class="stat-label">Total supplemental:</span>
<span class="stat"></span>
</div>
</div>
<h5 class="section-header"><strong>Baseline</strong></h5>
<div id="baseline-stats"></div>
<!-- Supplemental data -->
<h5 class="section-header"><strong>Supplemental</strong></h5>
<div id="supp-stats"></div>
</div>
</div>

Expand Down
44 changes: 44 additions & 0 deletions src/js/components/sidebar/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,48 @@
color: var(--darkGray);
font-weight: bold;
border-bottom: 1px solid var(--citygreen);
}

hr {
margin-top: -5px;
margin-bottom: 8px;
}

h6 {
font-weight: 600;
}

.section-header {
background-color: var(--mediumGray);
}

.sidebar-stat-line {
display: flex;
align-items: center;
justify-content: space-between; /* Distribute space between children */
padding: 2px;
border-bottom: 1px solid #ddd;
}

.edit-icon {
color: var(--spiritgreen);
cursor: pointer;
font-size: 16px; /* Adjust the size as needed */
margin-left: 10px;
}

.edit-icon:hover {
color: var(--citygreen);
}

.stat-label {
margin-right: auto; /* Push next elements to the right */
}

.stat {
margin-left: 5px; /* Optional: Add some space between currency and edit icon */
}

.sidebar-stat-line.fund-total .stat {
margin-right: 05px; /* 25px lines up with lines above (with edit symbol) */
}
59 changes: 7 additions & 52 deletions src/js/components/sidebar/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import './sidebar.css'
import { BaselineSection } from './subcomponents/baseline_section';

import { formatCurrency } from "../../utils/common_utils.js";
import {Baseline, Supplemental} from '../../models/';
import SuppSection from './subcomponents/supp_section'


// Assuming you have a CSS variable --main-color defined on the :root
// fetch CSS variables saved in :root
const root = document.documentElement;
const sideBarWidth = getComputedStyle(root).getPropertyValue('--sidebar-width').trim();

Expand All @@ -26,9 +25,6 @@ function showSidebar() {
mainPanel.style.width = `${contentWidth - parseInt(sideBarWidth, 10)}px`;
header.style.width = `${contentWidth - parseInt(sideBarWidth, 10)}px`;

// add target to sidebar
addTarget(Baseline.target());

// add event listener to resize content if window is adjusted
window.addEventListener('resize', showSidebar);
}
Expand All @@ -37,51 +33,9 @@ function updateSidebarTitle(new_title){
document.getElementById('sidebar-title').textContent = new_title;
}

function replaceSidebarStat(stat_id, new_figure){
const span = document.querySelector(`#${stat_id} .stat`);
span.setAttribute('value', new_figure);
span.textContent = formatCurrency(new_figure);
}

function fetchStat(stat_id){
const stat = document.querySelector(`#${stat_id} .stat`);
return parseFloat(stat.getAttribute('value')) || 0;
}


function addTarget(target){
replaceSidebarStat('target', target);
}

// update all stats based on saved data
async function updateBaseline(){
// gather info and update sidebar accordingly
var baseline = new Baseline();
replaceSidebarStat('baseline-revenue', baseline.revenue());
replaceSidebarStat('baseline-personnel', baseline.personnel());
replaceSidebarStat('baseline-nonpersonnel', baseline.nonpersonnel());
replaceSidebarStat('baseline-total', baseline.total());

// color code based on target
var target = fetchStat('target');
if(baseline.total() <= target){
document.querySelector('#baseline-total .stat').style.color = "green";
}
if(baseline.total() > target){
document.querySelector('#baseline-total .stat').style.color = "red";
}
}

function updateSupp(){
var supp = new Supplemental;
replaceSidebarStat('supp-revenue', supp.revenue());
replaceSidebarStat('supp-expenses', supp.expenses());
replaceSidebarStat('supp-total', supp.total());
}

function updateTotals(){
updateBaseline();
updateSupp();
SuppSection.update();
BaselineSection.update();
}

function resetAll(){
Expand All @@ -91,10 +45,11 @@ function resetAll(){
}

const Sidebar = {
SuppSection : SuppSection,
BaselineSection : BaselineSection,
hide: hideSidebar,
show: showSidebar,
updateTitle: updateSidebarTitle,
addTarget: addTarget,
updateTotals: updateTotals,
reset: resetAll
};
Expand Down
106 changes: 106 additions & 0 deletions src/js/components/sidebar/subcomponents/baseline_section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { FISCAL_YEAR } from "../../../constants";
import { Baseline, FundLookupTable, Fund, CurrentFund } from "../../../models";
import { formatCurrency } from "../../../utils/common_utils";
import { visitPage } from "../../../views/view_logic";

export const BaselineSection = {
_data: new Baseline(),
_genFund : new Fund(1000),

get data() {
this._data = new Baseline();
return this._data;
},

set data(newData) {
this._data = newData;
},

get genFund() {
this._genFund = new Fund(1000);
return this._genFund;
},

set genFund(newFund) {
this._genFund = newFund;
},

target_html() {
return `
<div class='sidebar-stat-line' id="baseline-total">
<span class="stat-label">Baseline total:</span>
<span class="stat">${formatCurrency(this.data.total())}</span>
</div>
<div class='sidebar-stat-line' id="target">
<span class="stat-label">FY${FISCAL_YEAR} GF target:</span>
<span class="stat">${formatCurrency(Baseline.target())}</span>
</div>
<div class='sidebar-stat-line' id="GF-total">
<span class="stat-label">Current GF total:</span>
<span class="stat">${formatCurrency(this.genFund.getTotal())}</span>
</div>
<br>`;
},

fund_html(fund) {
return `
<h6>${FundLookupTable.getName(fund.fund)}</h6>
<hr>
<div class='sidebar-stat-line revenue'>
<span class="stat-label">Projected revenues:</span>
<span class="stat">${formatCurrency(fund.getRevenue())}</span>
<i class="fas fa-edit edit-icon" title="Edit"></i>
</div>
<div class='sidebar-stat-line personnel'>
<span class="stat-label">Personnel cost:</span>
<span class="stat">${formatCurrency(fund.getPersonnelCost())}</span>
<i class="fas fa-edit edit-icon" title="Edit"></i>
</div>
<div class='sidebar-stat-line nonpersonnel'>
<span class="stat-label">Non-personnel cost:</span>
<span class="stat">${formatCurrency(fund.getNonPersonnelCost())}</span>
<i class="fas fa-edit edit-icon" title="Edit"></i>
</div>
<div class='sidebar-stat-line fund-total'>
<span class="stat-label">Fund total:</span>
<span class="stat">${formatCurrency(fund.getTotal())}</span>
</div>
<br>`;
},

linkEditBtns() {
let btns = document.querySelectorAll('.edit-icon');
btns.forEach((btn) => {
// Get the fund from the div the button is in
let fund = btn.closest('.fund-div').id.replace('fund_', '');
let page = btn.closest('.sidebar-stat-line').classList[1];

btn.addEventListener('click', function(event) {
CurrentFund.update(fund);
visitPage(page);
});
});
},

update() {
const baselineDiv = document.querySelector('#baseline-stats');
baselineDiv.innerHTML = this.target_html();

this.data.funds.forEach((fund) => {
var fundDiv = document.createElement('div');
fundDiv.id = `fund_${fund.fund}`;
fundDiv.classList.add('fund-div');
fundDiv.innerHTML = this.fund_html(fund);
baselineDiv.appendChild(fundDiv);
});

if(this.genFund.getTotal() <= Baseline.target()){
document.querySelector('#GF-total .stat').style.color = "green";
document.querySelector('#fund_100 sidebar-stat-line.fund-total .stat').style.color = "green";
} else {
document.querySelector('#GF-total .stat').style.color = "red";
document.querySelector('#fund_1000 .sidebar-stat-line:last-of-type .stat').style.color = "red";
}
this.linkEditBtns();
}
};
28 changes: 28 additions & 0 deletions src/js/components/sidebar/subcomponents/supp_section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Supplemental } from "../../../models";
import { formatCurrency } from "../../../utils/common_utils";

export const SuppSection = {
html() {
var supp = new Supplemental;
return `
<div class='sidebar-stat-line' id="supp-revenue">
<span class="stat-label">Estimated revenues:</span>
<span class="stat">${formatCurrency(supp.revenue())}</span>
</div>
<div class='sidebar-stat-line' id="supp-expenses">
<span class="stat-label">Esimated expenditures:</span>
<span class="stat">${formatCurrency(supp.expenses())}</span>
</div>
<div class='sidebar-stat-line' id="supp-total">
<span class="stat-label">Total supplemental:</span>
<span class="stat">${formatCurrency(supp.total())}</span>
</div>`
},

update() {
const suppDiv = document.querySelector('#supp-stats');
suppDiv.innerHTML = this.html();
}
}

export default SuppSection;
2 changes: 1 addition & 1 deletion src/js/models/supplemental.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import Initiative from "./initiative.js";
import { colSum } from "../utils/common_utils.js";
import { colSum, formatCurrency } from "../utils/common_utils.js";

// data structure to hold supplemental requests
export class Supplemental {
Expand Down

0 comments on commit 6a3576a

Please sign in to comment.