abnDK / personal-budget-2

For completing personal budget 2 project in Codecademy back engineer career path
0 stars 0 forks source link

Make budget view #36

Open abnDK opened 1 year ago

abnDK commented 1 year ago

Sketch for 3 layer budget.

image

Do use case analysis before final sketch and implementation.

Needs:

abnDK commented 1 year ago

Make us of grid or flex when designing this

abnDK commented 1 year ago

When changing / updating budget, you choose a start date

abnDK commented 1 year ago

Budget criteria:

Later version:

abnDK commented 1 year ago

For building the patent-child tree

https://medium.com/@lizhuohang.selina/building-a-hierarchical-tree-from-a-flat-list-an-easy-to-understand-solution-visualisation-19cb24bdfa33

abnDK commented 1 year ago

clean up code in "buildTree" function. Tænk over hvad formålet med funktionen er. Hvis det er at bygge træet, så er koden i virkeligheden meget simpel.

Lige pt. er implementering i budget viewet relativt simpelt, som blot skal bruge et træ. Der er derfor ikke pt. nødvendigt med dfs repræsentation af dataene.

refactor "getCategoriesAsTree" så træet ikke bygges backend og roder API koden sammen. Hent categories via /categories apien, og brug BuildTree funktionen i frontend koden. Lad det være en simpel kode, der ikke bruger dfs/bfs eller lign.

abnDK commented 1 year ago

make it possible to delete budget row

abnDK commented 1 year ago

Budget criteria:

  • UI like screenshot above
  • [x] Budget is pr. default "locked".

    • [x] shows categories as tree with parent/child relationsship
    • [x] categories has name and amount
    • [x] parent nodes has the sum of children
  • [x] Budget can be "unlocked" by clicking "edit"

    • [x] Editable budgets makes is possible to change name and amount of all categories
    • [ ] Categories can be added / [x] deleted
    • [x] Adding a category is done by button on parent
    • Delete a category is done by button on parent => changed to delete button is on row itself
    • [ ] Start date becomes editable. Pr. default will have 1/x-xxxx (1st of the current month)
  • "locking"/saving a budget does the following

    • [ ] every category is saved. If changes are made, there will be created new categories in db => reconsider this - how do we handle budget versions???
    • [ ] afterwards, a new budget is created with updated startdate. All categories will get id of this budget as their new budget_id

Later version:

  • parent node has field for "margin" that can both be in % or an amount. (they are interlocked)

/**

abnDK commented 1 year ago

delete row almost done - refactor to use async / await before doing "add budget row" functions...

abnDK commented 1 year ago

consider rewrite of rendering functions to be more verbose / write innerHTML when creating function...

abnDK commented 1 year ago

delete row almost done - refactor to use async / await before doing "add budget row" functions...

done

abnDK commented 1 year ago
  • Add budget row
  • [ ] Add new row on all 3 levels (parent, child, grandchild - and not grand-grandchild)
  • [ ] Save row to db on save. (might already happen if we just add row like when we populate budget)

TODO

abnDK commented 1 year ago

Fix deleterow:

abnDK commented 1 year ago

current foreign key constraint problem on constraint table:

abnDK commented 1 year ago

Finish function to update budget sums of category tree.

After this write render function that writes updated sums of each category in the tree to it's dom element. Make one for writing it into frozen format and editable format.

After these functions are run when we click save after editing, we can update the amounts to db, and use the returned category as source for updating parent_id in the category tree

Another potentially helpful function would be to render only rows to keep removing those that are set to be deleted upon save.

abnDK commented 1 year ago

We are still working on the above...

Next is to fix the function that populates the budget rows when domcontentloaded event is fired.

abnDK commented 1 year ago

Data binding

https://www.atmosera.com/blog/data-binding-pure-javascript/

abnDK commented 1 year ago

or https://gomakethings.com/two-way-data-binding-and-reactivity-with-15-lines-of-vanilla-javascript/

abnDK commented 1 year ago

Next: [] Refactor updateBudgetSums() to use makeCategory... from tree and the helper functions for calculating sums.

abnDK commented 1 year ago

refact deleteCategories. Make sure it deletes children before parents. Maybe lokk into dev.podcast on post ... something something... Or we could use BFS and reverse the array getting the last generation first and so forth

when re-rendering the dom with renderFrozenAll / renderEditableAll we should check if we recalculate levels also. Maybe when be synDB and get updated parent id's back from db.

abnDK commented 1 year ago

Refact budget structure so it hold the tree from a root node. Make the rendering where we convert from tree to array. We can also filter root out here then.

Also make recursive when calculating sums. Will then be a dfs search recursively to the leafs of the tree and then write that sum to parent

If we do this, we don't have to update parent id's before calcSum as the tre with children nodes enables us to calc sum of children

abnDK commented 1 year ago

BuildTree is initial function taking Category interface, and outputs CategoryRow

dfsTree runs on the CategoryRows

abnDK commented 1 year ago

BuildTree is done,

now refactor dfsTree and rendering function

abnDK commented 1 year ago

This is issue will be split into 3 seperate issues. When each of these are done, this issue can be closed as well. [ ] Toggle edit/save => https://github.com/abnDK/personal-budget-2/issues/49 [ ] Add new budget row => https://github.com/abnDK/personal-budget-2/issues/50 [ ] Edit existing budget row => https://github.com/abnDK/personal-budget-2/issues/51 [ ] Delete existing budget row => https://github.com/abnDK/personal-budget-2/issues/52