Skip to content

Commit

Permalink
Merge pull request #60 from kwheelan/49-reorg
Browse files Browse the repository at this point in the history
49 reorg
  • Loading branch information
kwheelan authored Jul 29, 2024
2 parents f4b27ad + b0a647d commit f093b81
Show file tree
Hide file tree
Showing 58 changed files with 1,238 additions and 1,334 deletions.
6 changes: 3 additions & 3 deletions src/js/components/accordion/accordion.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import './accordion.css'

import { Baseline, CurrentFund, Fund, Supplemental } from "../../utils/data_utils/local_storage_handlers.js";

import {Baseline, CurrentFund, Fund, Supplemental, FundLookupTable} from '../../models'
import { formatCurrency, cleanString } from "../../utils/common_utils.js";
import Table from "../table/table.js";
import { FundLookupTable } from "../../utils/data_utils/budget_data_handlers.js";
import { visitPage } from '../../views/view_logic.js';
import { TARGET } from '../../init.js';
import { TARGET } from '../../constants/';

function redirectForEdit(){
const row = document.querySelector(`.active-editing`);
Expand Down
5 changes: 3 additions & 2 deletions src/js/components/body/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ function resetPage() {
Accordion.hide();
FileUpload.hide();
Tooltip.hide();
// disable next button
NavButtons.Next.disable();

Table.adjustWidth('100%');

Prompt.Buttons.reset();
// disable submit button
Modal.Submit.deinit();
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/file_upload/file_upload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './file_upload.css';

import { processWorkbook } from "../../utils/data_utils/XLSX_handlers.js";
import { processWorkbook } from "../../utils/XLSX_handlers.js";
import Sidebar from '../sidebar/sidebar.js';

export const FileUpload = {
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/header/header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './header.css';

import { CurrentFund } from "../../utils/data_utils/local_storage_handlers.js";
import CurrentFund from '../../models/current_fund';

export const Subtitle = {
update : function(subtitle){
Expand Down
1 change: 0 additions & 1 deletion src/js/components/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import './modal.css';
function clearModal(){
updateModalTitle('');
document.getElementById('modal-body').innerHTML = '';
//removeAllModalLinks()
}

function hideModal(modal_id) {
Expand Down
1 change: 0 additions & 1 deletion src/js/components/nav_buttons/nav_buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function initializeNavButtons(){
// initialize next button
const next_btn = document.getElementById('btn-next');
next_btn.addEventListener('click', nextPage);
disable('btn-next');
}

function hideNavButtons() {
Expand Down
5 changes: 3 additions & 2 deletions src/js/components/sidebar/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import './sidebar.css'

import { formatCurrency } from "../../utils/common_utils.js";
import { TARGET } from "../../init.js";
import { Baseline, Supplemental } from "../../utils/data_utils/local_storage_handlers.js";
import { TARGET } from '../../constants/';
import {Baseline, Supplemental} from '../../models/';


// Assuming you have a CSS variable --main-color defined on the :root
const root = document.documentElement;
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/table/subcomponents/cells.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatCurrency, displayWithCommas } from "../../../utils/common_utils.js";
import { Services } from "../../../utils/data_utils/budget_data_handlers.js";
import Services from "../../../models/services.js";
import Dropdown from "../../form/subcomponents/dropdown.js";

// return cell value attribute or 0 if it does not exist
Expand Down
23 changes: 12 additions & 11 deletions src/js/components/table/subcomponents/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FundLookupTable } from "../../../utils/data_utils/budget_data_handlers.js";
import { CurrentFund, CurrentPage, loadTableData, saveTableData } from "../../../utils/data_utils/local_storage_handlers.js";
import FundLookupTable from '../../../models/fund_lookup_table.js';
import CurrentFund from '../../../models/current_fund.js'
import CurrentPage from '../../../models/current_page.js'

function fillTable(data) {
try {
Expand Down Expand Up @@ -33,24 +34,24 @@ function fillTable(data) {
} catch(error) {
console.error('No table saved in localStorage:', error);
}
saveTableData();
}

async function loadFromStorage(){
// look up table in storage and pass to table load function\
// look up table name in storage
if (CurrentFund.number()){
var key = `${CurrentPage.load()}_${CurrentFund.number()}`;
} else {
var key = CurrentPage.load();
}
const data = await loadTableData(key);
if (!data){
// if no table in storage, return 0
// load from local storage
const data = localStorage.getItem(key);
// if nothing in storage, return a zero
if ( !data ) {
return 0;
} else {
fillTable(data);
return 1;
}
};
// otherwise, fill table in HTML and return success (1)
fillTable(await JSON.parse(data));
return 1;
}


Expand Down
31 changes: 23 additions & 8 deletions src/js/components/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ 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 { saveTableData } from '../../utils/data_utils/local_storage_handlers.js'
import Tooltip from '../tooltip/tooltip.js';
import { convertToJSON } from "../../utils/JSON_data_handlers.js";
import Sidebar from '../sidebar/sidebar.js';
import CurrentFund from '../../models/current_fund.js';
import CurrentPage from '../../models/current_page.js';

function adjustTableWidth(width_pct){
const table = document.getElementById('main-table');
Expand All @@ -31,6 +34,24 @@ function hideTable(){
Buttons.AddRow.hide();
}

function saveTableData() {
// remove the detail text
Tooltip.unlink();
// get table
var table = document.getElementById('main-table');
// determine save_as name
if (CurrentFund.number()) {
var save_as = `${CurrentPage.load()}_${CurrentFund.number()}`;
} else {
var save_as = CurrentPage.load();
}
localStorage.setItem(save_as, convertToJSON(table, ['Edit']));
// update sidebar with new data
Sidebar.updateTotals();
// relink, depending on page
Tooltip.linkAll();
}

const Table = {
Buttons : Buttons,
Cell : Cell,
Expand All @@ -45,13 +66,7 @@ const Table = {
clear : clearTable,
hide : hideTable,
show : showTable,
save : async function() {
// remove the detail text
Tooltip.unlink();
saveTableData();
// relink, depending on page
Tooltip.linkAll();
}
save : saveTableData
}

export default Table;
5 changes: 3 additions & 2 deletions src/js/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FISCAL_YEAR } from '../../init';
import { FISCAL_YEAR } from '../../constants/';
import Cell from '../table/subcomponents/cells';
import { formatCurrency } from '../../utils/common_utils';
import CurrentPage from '../../models/current_page';

import './tooltip.css'
import { CurrentFund, CurrentPage } from '../../utils/data_utils/local_storage_handlers';

function hideTooltip() {
document.getElementById('tooltip').style.visibility = 'hidden';
Expand Down
5 changes: 5 additions & 0 deletions src/js/constants/app_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// temporary hard-coding
export let TARGET = 10000000;

// Set to equal current fiscal year
export var FISCAL_YEAR = '26';
21 changes: 21 additions & 0 deletions src/js/constants/excel_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// sheets to expect on detail sheet
export const SHEETS = {
'FTE, Salary-Wage, & Benefits' : 'personnel' ,
'Overtime & Other Personnel' : 'overtime',
'Non-Personnel Operating' : 'nonpersonnel',
'Revenue' : 'revenue'
}

export const OBJ_CATEGORIES = {
list : [
// 'Salaries & Wages',
// 'Employee Benefits',
'Professional & Contractual Services',
'Operating Supplies',
'Operating Services',
'Equipment Acquisition',
'Capital Outlays',
'Fixed Charges',
'Other Expenses'
]
}
2 changes: 2 additions & 0 deletions src/js/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './app_constants';
export * from './excel_constants';
16 changes: 1 addition & 15 deletions src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@
import '../css/common.css';

// import functions
import { CurrentPage } from './utils/data_utils/local_storage_handlers.js';

// temporary hard-coding
export let REVENUE = 0;
export let TARGET = 10000000;
// Set to equal current fiscal year
export var FISCAL_YEAR = '26';

// sheets to expect on detail sheet
export const SHEETS = {
'FTE, Salary-Wage, & Benefits' : 'personnel' ,
'Overtime & Other Personnel' : 'overtime',
'Non-Personnel Operating' : 'nonpersonnel',
'Revenue' : 'revenue'
}
import CurrentPage from './models/current_page.js';

document.addEventListener('DOMContentLoaded', function () {
CurrentPage.visit();
Expand Down
43 changes: 43 additions & 0 deletions src/js/models/account_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


export const AccountString = {
getNumber: function(input) {
// isolate the numerical part of a appropriation/cost center/object
const match = input.match(/^\d+/);
return match ? match[0] : null;
},

build : function(approp, cc, obj = null, fund = null) {
// put together account string fund-approp-costcenter[-obj] (w optional object)
if (!fund) { fund = CurrentFund.number() };
// hits error here
approp = this.getNumber(approp);
cc = this.getNumber(cc);
var string = `${fund}-${approp}-${cc}`;
string = obj ? `${string}-${this.getNumber(obj)}` : string;
return string;
},

getAccountStringSection : function(account_string, section) {
const sections = account_string.split("-");
return sections.length > section ? sections[section] : null;
},

fund : function(account_string) {
return this.getAccountStringSection(account_string, 0)
},

approp : function(account_string) {
return this.getAccountStringSection(account_string, 1)
},

costCenter : function(account_string) {
return this.getAccountStringSection(account_string, 2)
},

object : function(account_string) {
return this.getAccountStringSection(account_string, 3)
},
}

export default AccountString;
45 changes: 45 additions & 0 deletions src/js/models/baseline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Fund from "./fund.js";
import FundLookupTable from "./fund_lookup_table.js";


export class Baseline {
// baseline will just contain a list of funds, each with
// running tallies for their budgets
constructor() {
const allFunds = FundLookupTable.listFunds();
this.funds = [];
allFunds.forEach((fund) => {
this.funds.push(new Fund(fund));
});
}

personnel() {
let total = 0;
this.funds.forEach(fund => {
total += fund.getPersonnelCost();
});
return total;
}

nonpersonnel() {
let total = 0;
this.funds.forEach(fund => {
total += fund.getNonPersonnelCost();
});
return total;
}

revenue() {
let total = 0;
this.funds.forEach(fund => {
total += fund.getRevenue();
});
return total;
}

total() {
return this.nonpersonnel() + this.personnel() - this.revenue();
}
}

export default Baseline;
19 changes: 19 additions & 0 deletions src/js/models/current_fund.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import FundLookupTable from "./fund_lookup_table";

export const CurrentFund = {
update : function(fund){
localStorage.setItem('fund', fund);
},
number : function(){
return localStorage.getItem("fund");
},
name : function(){
return FundLookupTable.getName( this.number());
},
reset : function() {
this.update('');
}
}

export default CurrentFund;
16 changes: 16 additions & 0 deletions src/js/models/current_page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { visitPage } from "../views/view_logic";

export const CurrentPage = {
update : function(page){
localStorage.setItem('page_state', page);
},
load : function(){
const pageState = localStorage.getItem('page_state');
return pageState !== null ? pageState : 'welcome';
},
visit : function(){
visitPage(this.load());
}
}

export default CurrentPage;
Loading

0 comments on commit f093b81

Please sign in to comment.