Skip to content

Commit

Permalink
fixed issues with sidebar tallying
Browse files Browse the repository at this point in the history
  • Loading branch information
katrina-cityofdetroit committed Jul 16, 2024
1 parent 299fc8a commit e87470c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
1 change: 0 additions & 1 deletion js/components/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Columns from './subcomponents/columns.js'
import Header from './subcomponents/headers.js'
import Rows from './subcomponents/rows.js'
import Data from './subcomponents/data.js'
import { unformatCurrency } from '../../utils/common_utils.js'
import { saveTableData } from '../../utils/data_utils/local_storage_handlers.js'

function adjustTableWidth(width_pct){
Expand Down
11 changes: 5 additions & 6 deletions js/utils/data_utils/local_storage_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export function saveTableData() {
var save_as = CurrentPage.load();
}
localStorage.setItem(save_as, convertToJSON(table, ['Edit']));
console.log('uncomment this line');
//Sidebar.updateTotals();
Sidebar.updateTotals();
}

function deleteTable(name){
Expand Down Expand Up @@ -93,25 +92,25 @@ class StoredTable {
}
getSum() {
// fill with zero until there is something saved in storage
return colSum(this.table, this.totalCol());
return colSum(this.table, this.totalCol(), this.name);
}

}

function colSum(table, colName) {
function colSum(table, colName, name) {
// fill with zero until there is something saved in storage
if(!table || table == ''){
return 0;
}
const headers = Object.keys(table[0]);
if (headers.includes(colName)) {
let sum = 0;
for (let i = 1; i < table.length; i++){
for (let i = 0; i < table.length; i++){
sum += Math.round(parseFloat(table[i][colName]));
}
return sum;
} else {
console.error('Could not find expected total column in saved data. See StoredTable.totalCol() switch.');
console.error(`Could not find expected total column in saved data for ${name}. Returning 0. See StoredTable.totalCol() switch.`);
return 0;
}

Expand Down
8 changes: 7 additions & 1 deletion js/views/04_personnel/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Prompt from "../../components/prompt/prompt.js";
import Table from '../../components/table/table.js'
import Sidebar from "../../components/sidebar/sidebar.js";
import { Services } from "../../utils/data_utils/budget_data_handlers.js";
import { convertToJSON } from "../../utils/data_utils/JSON_data_handlers.js";

import { Baseline, loadTableData } from "../../utils/data_utils/local_storage_handlers.js";

export function preparePageView(){
// prepare page view
Expand Down Expand Up @@ -54,7 +57,6 @@ export async function initializePersonnelTable(){
await Table.Data.load();
//after table is loaded, show it
Table.show();
Table.Columns.addAtEnd('0', 'Total Cost');
Table.Columns.addAtEnd(Table.Buttons.edit_confirm_btns, 'Edit');
assignClasses();
// add up the baseline costs and update sidebar
Expand Down Expand Up @@ -87,8 +89,12 @@ function updateDisplayandTotals(){

// update total column
Table.Cell.updateValue(rows[i], 'total-baseline', total_baseline_cost);

}

// Save the table after all updates are done
Table.save();

}


Expand Down
20 changes: 18 additions & 2 deletions js/views/05_nonpersonnel/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ import Body from "../../components/body/body.js";
import NavButtons from "../../components/nav_buttons/nav_buttons.js";
import Subtitle from "../../components/header/header.js";

// "Vendor": "Law Firm LLC",
// "CPA #" : "765421",
// "Account String": "1000-29320-320010",
// "Object Name": "Consulting",
// "End of Contract": "12/31/2024",
// "Amount Remaining" : 50000,
// "FY26 Request": 100000

const nonPersonnelColumns = [
{ title: 'FY26 Request', className: 'request', isCost: true },
{ title: 'Amount Remaining', className: 'remaining', isCost: true },
{ title: 'Amount Remaining on Contract', className: 'remaining', isCost: true },
{ title: 'Service', className : 'service' },
{ title: 'Edit', className : 'edit' },
{ title : 'Account String', className : 'account-string'},
{ title : 'CPA #', className : 'cpa'},
{ title : 'End of Contract', className : 'contract-end'},
{ title: 'Recurring or One-Time', className: 'recurring'}

];

export function preparePageView(){
Expand All @@ -30,7 +45,7 @@ export async function initializeNonpersonnelTable(){
await Table.Data.load();
//after table is loaded, fill it
Table.show();
Table.Columns.addAtEnd(Table.Buttons.edit_confirm_btns, " ");
Table.Columns.addAtEnd(Table.Buttons.edit_confirm_btns, "Edit");
// assign cost classes
Table.Columns.assignClasses(nonPersonnelColumns);
// enable editing
Expand All @@ -40,5 +55,6 @@ export async function initializeNonpersonnelTable(){
function nonPersonnelRowOnEdit(){
// make it editable
Table.Cell.createTextbox('request');
Table.Cell.createServiceDropdown();
}

0 comments on commit e87470c

Please sign in to comment.