(Account Card) Add info to account card

This commit is contained in:
Julien Calixte
2019-09-29 10:59:49 +02:00
parent 6b1719987a
commit c113420756
5 changed files with 8 additions and 68 deletions

5
package-lock.json generated
View File

@@ -3484,11 +3484,6 @@
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
"integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=" "integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc="
}, },
"chartist": {
"version": "0.11.4",
"resolved": "https://registry.npmjs.org/chartist/-/chartist-0.11.4.tgz",
"integrity": "sha512-H4AimxaUD738/u9Mq8t27J4lh6STsLi4BQHt65nOtpLk3xyrBPaLiLMrHw7/WV9CmsjGA02WihjuL5qpSagLYw=="
},
"check-types": { "check-types": {
"version": "8.0.3", "version": "8.0.3",
"resolved": "https://registry.npmjs.org/check-types/-/check-types-8.0.3.tgz", "resolved": "https://registry.npmjs.org/check-types/-/check-types-8.0.3.tgz",

View File

@@ -18,7 +18,6 @@
"bulma-checkradio": "^2.1.0", "bulma-checkradio": "^2.1.0",
"bulma-pricingtable": "^0.2.0", "bulma-pricingtable": "^0.2.0",
"bulma-switch": "^2.0.0", "bulma-switch": "^2.0.0",
"chartist": "^0.11.4",
"crypto-js": "^3.1.9-1", "crypto-js": "^3.1.9-1",
"lightness": "^1.0.0", "lightness": "^1.0.0",
"lodash-es": "^4.17.15", "lodash-es": "^4.17.15",

View File

@@ -31,7 +31,7 @@ export default class BaseAccount extends Vue {
public async getData(docIds?: string[]): Promise<void> { public async getData(docIds?: string[]): Promise<void> {
throw new Error( throw new Error(
`abstract method, need to be override ${docIds && docIds.join(', ')}` `abstract method needs to be overrided ${docIds && docIds.join(', ')}`
) )
} }
} }

View File

@@ -13,8 +13,7 @@
<div v-if="account.isPublic"> <div v-if="account.isPublic">
<awe-icon icon="users" /> <awe-icon icon="users" />
</div> </div>
<div :id="`chart-${account._id}`" class="ct-chart ct-golden-section"></div> <div class="numeric">{{ totalCost | moneypad(account.mainCurrency) }}</div>
<br />
{{ account.users && account.users.map((u) => u.alias).join(', ') }} {{ account.users && account.users.map((u) => u.alias).join(', ') }}
</div> </div>
</template> </template>
@@ -28,8 +27,7 @@ import IAccount from '@/models/IAccount'
import IColor from '@/models/IColor' import IColor from '@/models/IColor'
import FabButton from '@/components/FabButton.vue' import FabButton from '@/components/FabButton.vue'
import ITransaction from '../models/ITransaction' import ITransaction from '../models/ITransaction'
import TransactionService from '../services/TransactionService' import transactionService from '../services/TransactionService'
import Chartist from 'chartist'
import TransactionType from '../enums/TransactionType' import TransactionType from '../enums/TransactionType'
import colors from '../data/colors' import colors from '../data/colors'
@@ -40,29 +38,9 @@ export default class AccountCard extends Vue {
public transactions: ITransaction[] = [] public transactions: ITransaction[] = []
public async mounted() { public async mounted() {
this.transactions = await TransactionService.getAllByAccountId( this.transactions = await transactionService.getAllByAccountId(
this.account._id this.account._id
) )
const data = {
labels: this.labels,
series: [this.sumOfTransactions]
}
const chartId = `#chart-${this.account._id}`
// tslint:disable-next-line:no-unused-expression
new Chartist.Bar(chartId, data, {})
setTimeout(() => {
const color = colors.find((c) => c.value === this.account.color)
if (!color) {
return
}
const bars = document.querySelectorAll(
`${chartId} .ct-bar`
) as NodeListOf<HTMLElement>
bars.forEach((bar) => (bar.style.stroke = color.darkValue || 'red'))
}, 500)
} }
public findDarkValue(color: string): string | null { public findDarkValue(color: string): string | null {
@@ -83,48 +61,17 @@ export default class AccountCard extends Vue {
} }
} }
public get amounts(): ITransaction[] { private get totalCost(): number {
return this.transactions.filter( return transactionService.getTotalCost(
(transaction) => transaction.transactionType === TransactionType.normal this.transactions,
this.account.mainCurrency.name
) )
} }
public get labels(): string[] {
const dates = this.amounts.map((transaction) =>
this.dateToLabel(new Date(transaction.date))
)
return [...new Set(dates)]
}
public get sumOfTransactions(): number[] {
const sortedTransactions = [...this.amounts].sort((a, b) =>
a.date < b.date ? -1 : 1
)
const groups = sortedTransactions.reduce(
(group: { [key: string]: number }, transaction: ITransaction) => {
const date = this.dateToLabel(new Date(transaction.date))
if (!(date in group)) {
group[date] = 0
}
group[date] += transaction.amount
return group
},
{}
)
return Object.values(groups)
}
private dateToLabel(date: Date): string {
return `${(date.getMonth() + 1)
.toString()
.padStart(2, '0')}/${date.getFullYear()}`
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '../styles/variables'; @import '../styles/variables';
@import '~chartist/dist/chartist.min.css';
.ct-chart { .ct-chart {
.ct-series-a { .ct-series-a {

View File

@@ -37,7 +37,6 @@ export default class AccountList extends Vue {
public user!: IUser | null public user!: IUser | null
@Prop({ type: Boolean, default: false }) @Prop({ type: Boolean, default: false })
public archived!: boolean public archived!: boolean
public accounts: IAccount[] = [] public accounts: IAccount[] = []
public fetched: boolean = false public fetched: boolean = false
public textColor: string = '' public textColor: string = ''