-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from forevermatt/develop
Release 0.3.0
- Loading branch information
Showing
21 changed files
with
346 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script> | ||
import CategoryGraph from './CategoryGraph.svelte' | ||
import { budget, sortBudgetByCategory } from '../data/budget' | ||
import { categories } from '../data/categories' | ||
import { getCurrentYearMonthString } from '../helpers/dates' | ||
import { dangerIfNegative, formatAmount, formatAmountAsWholeNumber } from '../helpers/numbers' | ||
$: sortedBudget = sortBudgetByCategory($budget, $categories) | ||
</script> | ||
|
||
<style> | ||
.category-amount { | ||
white-space: nowrap; | ||
text-align: right; | ||
} | ||
.category-available.danger { | ||
color: red; | ||
} | ||
.category-available > sup { | ||
margin-left: 0.5ex; | ||
margin-right: 0.25ex; | ||
} | ||
.category-budgeted { | ||
color: #999; | ||
font-size: 0.8rem; | ||
vertical-align: bottom; | ||
} | ||
.category-list td { | ||
border: none; | ||
vertical-align: middle; | ||
} | ||
.category-name { | ||
white-space: nowrap; | ||
} | ||
.width-10 { | ||
width: 10%; | ||
} | ||
.width-80 { | ||
width: 80%; | ||
} | ||
</style> | ||
|
||
<table class="category-list table table-sm"> | ||
<tbody> | ||
{#each sortedBudget as {budgeted, remaining, name, uuid} } | ||
<tr> | ||
<td class="category-name width-10"> | ||
<a href="#/category/{ uuid }" | ||
class="btn btn-outline-secondary">{ name }</a> | ||
</td> | ||
<td class="width-80"> | ||
<CategoryGraph {budgeted} {remaining} /> | ||
</td> | ||
<td class="category-amount width-10"> | ||
<div class="category-available { dangerIfNegative(remaining) }"> | ||
<sup>$</sup>{ formatAmount(remaining) } | ||
</div> | ||
<div class="category-budgeted"><span>/ { formatAmountAsWholeNumber(budgeted) }</span></div> | ||
</td> | ||
</tr> | ||
{/each} | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script> | ||
import { dangerIfNegative } from '../helpers/numbers' | ||
export let budgeted | ||
export let remaining | ||
const getStatus = (remaining, total) => { | ||
if (remaining == undefined) { | ||
return ''; | ||
} else if (remaining < 0) { | ||
return 'danger'; | ||
} else if (remaining < (total / 4)) { | ||
return 'warning'; | ||
} | ||
return 'success'; | ||
} | ||
const calculageWidth = (remaining, total) => { | ||
if (remaining < 0) { | ||
return 0; | ||
} else if (total === 0) { | ||
return (remaining > 0) ? 100 : 0; | ||
} | ||
return (remaining / total) * 100; | ||
} | ||
</script> | ||
|
||
<style> | ||
.category-graph { | ||
box-shadow: 0px 0px 1px 0px rgba(0, 0, 0, 0.75); | ||
} | ||
.category-graph.danger { | ||
box-shadow: 0px 0px 0px 1px rgba(255, 0, 0, 0.75); | ||
} | ||
.category-graph, | ||
.category-graph-line { | ||
border-radius: 4px; | ||
} | ||
.category-graph .danger { | ||
background-color: red; | ||
} | ||
.category-graph .success { | ||
background-color: green; | ||
} | ||
.category-graph .warning { | ||
background-color: orange; | ||
} | ||
.category-graph-line { | ||
height: 6px; | ||
margin: auto 0; | ||
} | ||
</style> | ||
|
||
<div class="category-graph { dangerIfNegative(remaining) }"> | ||
<div class="category-graph-line { getStatus(remaining, budgeted) }" | ||
style="width: { calculageWidth(remaining, budgeted) }%;"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { getCategoryFrom } from './categories' | ||
import { addToList, updateInObject } from '../helpers/data-store-helpers' | ||
import { getCurrentYearMonthString } from '../helpers/dates' | ||
import { getObjectFromStorage, saveToStorage } from './storage' | ||
import { get, writable } from 'svelte/store' | ||
|
||
const BUDGET = 'budget' | ||
|
||
const budgetStore = writable({}) | ||
export {budgetStore as budget} | ||
|
||
const addCategoryToBudget = (categoryUuid, budgeted) => { | ||
updateBudget(categoryUuid, { | ||
budgeted: budgeted, | ||
remaining: budgeted, | ||
refilled: getCurrentYearMonthString() | ||
}) | ||
} | ||
|
||
const isExistingCategory = uuid => get(budgetStore).hasOwnProperty(uuid) | ||
|
||
export const loadBudget = () => { | ||
budgetStore.set(getObjectFromStorage(BUDGET)) | ||
} | ||
|
||
const saveBudget = () => saveToStorage(BUDGET, get(budgetStore)) | ||
|
||
export const setBudgetedForCategory = (uuid, budgeted) => { | ||
const budget = get(budgetStore) | ||
if (isExistingCategory(uuid)) { | ||
updateBudgetedForExistingCategory(uuid, budgeted) | ||
} else { | ||
addCategoryToBudget(uuid, budgeted) | ||
} | ||
} | ||
|
||
export const sortBudgetByCategory = (budget, categories) => { | ||
let list = [] | ||
for (var uuid in budget) { | ||
if (budget.hasOwnProperty(uuid)) { | ||
let category = getCategoryFrom(uuid, categories) | ||
list.push({ | ||
budgeted: budget[uuid].budgeted, | ||
remaining: budget[uuid].remaining, | ||
name: category.name, | ||
uuid: category.uuid, | ||
}); | ||
} | ||
} | ||
return list.sort((a, b) => (a.name || '').localeCompare(b.name || '')); | ||
} | ||
|
||
export const updateBudget = (categoryUuid, changes) => { | ||
updateInObject(categoryUuid, changes, budgetStore) | ||
saveBudget() | ||
} | ||
|
||
const updateBudgetedForExistingCategory = (categoryUuid, budgeted) => { | ||
const budget = get(budgetStore) | ||
let categoryAmounts = budget[categoryUuid] | ||
let previousBudgeted = categoryAmounts.budgeted | ||
let previousRemaining = categoryAmounts.remaining | ||
let remaining = previousRemaining + (budgeted - previousBudgeted) | ||
updateBudget(categoryUuid, {budgeted, remaining}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
export const addToList = (item, store) => { | ||
store.update(list => [item, ...list]) | ||
} | ||
|
||
export const updateInList = (idField, id, changes, store) => { | ||
store.update(list => { | ||
const itemToUpdate = list.find(item => item[idField] === id) | ||
const updatedItem = Object.assign({}, itemToUpdate, changes) | ||
|
||
let found = false; | ||
for (let i = 0; i < list.length; i++) { | ||
if (list[i][idField] === id) { | ||
found = true | ||
list[i] = updatedItem | ||
break | ||
} | ||
} | ||
|
||
if (!found) { | ||
list.push(updatedItem) | ||
} | ||
|
||
return list | ||
}) | ||
} | ||
|
||
export const updateInObject = (property, changes, store) => { | ||
store.update(data => { | ||
if (data.hasOwnProperty(property)) { | ||
data[property] = Object.assign(data[property], changes) | ||
} else { | ||
data[property] = changes | ||
} | ||
return data | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
export const getCurrentYearMonthString = () => { | ||
return getYearMonthStringForMonthsBefore(0, new Date()) | ||
} | ||
|
||
const getYearMonthStringForMonthsBefore = (numMonthsAgo, when) => { | ||
var currentYear = when.getFullYear() | ||
var currentMonth = when.getMonth() // 0 to 11 | ||
var desiredDate = new Date(currentYear, currentMonth - numMonthsAgo) | ||
var fullYear = desiredDate.getFullYear() | ||
var desiredMonth = (desiredDate.getMonth() + 1) // 1 to 12 | ||
return fullYear + '-' + String('0' + desiredMonth).slice(-2) | ||
} |
Oops, something went wrong.