Skip to content

Commit

Permalink
#22 FundLookUp table records viewed funds; updated logic to cycle thr…
Browse files Browse the repository at this point in the history
…ough funds
  • Loading branch information
katrina-cityofdetroit committed Jul 19, 2024
1 parent fd2e490 commit 02a4939
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/js/components/accordion/accordion.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

.accordion-table {
width: 100%;
font-size: 1.25em;
font-size: 1.2em;
/* border-collapse: separate; This is required for rounded corners */
}

Expand Down Expand Up @@ -49,7 +49,7 @@ span.amount {
}

.accordion-header button {
font-size: 0.8em;
font-size: 0.6em;
}

.btn-add-init {
Expand Down
8 changes: 7 additions & 1 deletion src/js/components/nav_buttons/nav_buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ function enable(button_id) {

const Next = {
disable : function() { disable('btn-next') },
enable : function() { enable('btn-next') }
enable : function() { enable('btn-next') },
addAction : function(fn) {
document.querySelector(`#btn-next`).addEventListener('click', fn);
},
removeAction : function(fn) {
document.querySelector(`#btn-next`).removeEventListener('click', fn);
},
}

const Last = {
Expand Down
18 changes: 10 additions & 8 deletions src/js/components/table/subcomponents/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ function loadFunds(){
// get list of funds from storage
const fundDict = FundLookupTable.retrieve();
// build out data in correct format
const resultArray = [];
for (const key in fundDict) {
if (fundDict.hasOwnProperty(key)) {
resultArray.push({
Fund: fundDict[key]['name'] // Use the value directly
});
const ret = [];
Object.keys(fundDict).forEach(key => {
// determine if the fund has already been edited
if (fundDict[key]['viewed']){
// todo: add a checkmark here
ret.push({'Fund' : fundDict[key]['name'] + ' (Edited)'});
} else {
ret.push({'Fund' : fundDict[key]['name']});
}
}
fillTable(resultArray);
});
fillTable(ret);
}


Expand Down
8 changes: 0 additions & 8 deletions src/js/utils/common_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ export function displayWithCommas(value) {
return formatCurrency(value).replace('$', '');
}

function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

export async function pauseExecution(seconds) {
await delay(seconds * 1000); // convert to milliseconds
}

export function cleanString(str){
return str.toLowerCase().replaceAll(' ', '-');
}
Expand Down
23 changes: 23 additions & 0 deletions src/js/utils/data_utils/budget_data_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ export const FundLookupTable = {
},
listFunds : function(){
return Object.keys(this.retrieve());
},
editFund : function(fund){
const table = this.retrieve();
if (table[fund]){
table[fund]['viewed'] = true;
this.save(table);
} else {
console.error('No fund selected.');
}

},
listUneditedFunds : function(){
const table = this.retrieve();
const ret = [];
this.listFunds().forEach(key => {
if (!table[key]['viewed']){
ret.push(key);
}
});
return ret;
},
fundsLeft : function(){
return (this.listUneditedFunds().length > 0);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/js/views/03_revenue/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { formatCurrency } from '../../utils/common_utils.js'
import { REVENUE } from '../../init.js'
import Body from '../../components/body/body.js'
import NavButtons from '../../components/nav_buttons/nav_buttons.js'
import { pauseAndContinue } from '../view_logic.js'
import { nextPage } from '../view_logic.js'
import Subtitle from '../../components/header/header.js'
import Modal from '../../components/modal/modal.js'
import Form from '../../components/form/form.js'
Expand All @@ -23,15 +23,15 @@ export function preparePageView(){

export function setUpNavButtons(){
// clicking 'confirm' will also take us to the next page
Prompt.Buttons.Left.addAction(pauseAndContinue);
Prompt.Buttons.Left.addAction(nextPage);
// TODO: allow user to edit revenue here
Modal.Link.add('option2');
handleErrorComment();
}

export function removeButtonEvents(){
// remove event listeners on prompt buttons
Prompt.Buttons.Left.removeAction(pauseAndContinue);
Prompt.Buttons.Left.removeAction(nextPage);
Modal.Link.remove('option2');
}

Expand Down
5 changes: 2 additions & 3 deletions src/js/views/06_nonpersonnel/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Table from "../../components/table/table.js";
import Body from "../../components/body/body.js";
import NavButtons from "../../components/nav_buttons/nav_buttons.js";
import Subtitle from "../../components/header/header.js";
import { FundLookupTable } from "../../utils/data_utils/budget_data_handlers.js";
import { CurrentFund } from "../../utils/data_utils/local_storage_handlers.js";

const nonPersonnelColumns = [
{ title: 'FY26 Request', className: 'request', isCost: true },
Expand All @@ -26,9 +28,6 @@ export function preparePageView(){
// update page text
Subtitle.update('Non-Personnel');
Prompt.Text.update('Select an action item for each non-personnel line item from last year.');

// just enable next for now
// TODO: only enable when all info is entered
NavButtons.Next.enable();
}

Expand Down
6 changes: 3 additions & 3 deletions src/js/views/07_new_initiatives/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Form from '../../components/form/form.js'
import Table from '../../components/table/table.js'
import Body from '../../components/body/body.js'
import NavButtons from '../../components/nav_buttons/nav_buttons.js'
import { pauseAndContinue } from '../view_logic.js'
import { nextPage } from '../view_logic.js'
import Subtitle from '../../components/header/header.js'
import Sidebar from '../../components/sidebar/sidebar.js'

Expand All @@ -28,7 +28,7 @@ export function initializePageView() {
Prompt.Buttons.Left.updateText('Yes');
Prompt.Buttons.Right.updateText('No');
// clicking 'no new initialitives' will also take us to the next page
Prompt.Buttons.Right.addAction(pauseAndContinue);
Prompt.Buttons.Right.addAction(nextPage);
Prompt.Buttons.Left.addAction(NavButtons.Next.enable);
}

Expand Down Expand Up @@ -114,7 +114,7 @@ export function removeModalLinks(){
}

export function removePromptButtonListeners(){
Prompt.Buttons.Right.removeAction(pauseAndContinue);
Prompt.Buttons.Right.removeAction(nextPage);
Prompt.Buttons.Left.removeAction(NavButtons.Next.enable);
Modal.clear();
}
25 changes: 14 additions & 11 deletions src/js/views/view_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { loadNonpersonnelPage } from './06_nonpersonnel/main.js';
import { loadBaselineLandingPage } from './02_baseline_landing_page/main.js';
import { cleanUpSummaryPage, loadSummaryPage } from './08_summary/main.js';
import { loadUploadPage } from './01_upload/main.js';
import { pauseExecution } from '../utils/common_utils.js';

import { CurrentPage } from '../utils/data_utils/local_storage_handlers.js';
import { CurrentPage, CurrentFund } from '../utils/data_utils/local_storage_handlers.js';
import { FundLookupTable } from '../utils/data_utils/budget_data_handlers.js';

export let PAGES = {
'welcome' : initializeWelcomePage,
Expand Down Expand Up @@ -50,10 +49,19 @@ export function nextPage(){

// clean up current page
if (CLEANUP[page_state]) { CLEANUP[page_state]() };

// Check if there is a next key

// if on non-personnel, circle back to fund selection unless all funds are edited
if (CurrentPage.load() == 'nonpersonnel'){
// mark fund as viewed/edited
FundLookupTable.editFund(CurrentFund.number());
// if any funds left to edit, go back to that page
if ( FundLookupTable.fundsLeft() ){
visitPage('baseline-landing');
return;
}
}
if (currentIndex >= 0 && currentIndex < keys.length - 1) {
// Get the next key
// Check if there is a next key, and get it
const nextKey = keys[currentIndex + 1];
// go to that page
visitPage(nextKey);
Expand All @@ -78,9 +86,4 @@ export function lastPage(){
// go to that page
visitPage(lastKey);
}
}

export async function pauseAndContinue(){
await pauseExecution(0.1);
nextPage();
}

0 comments on commit 02a4939

Please sign in to comment.