Skip to content

Commit

Permalink
Display operation types
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeHiro committed Sep 1, 2015
1 parent bd08c4b commit 4f722aa
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 58 deletions.
17 changes: 17 additions & 0 deletions client/Helpers.js
Expand Up @@ -33,6 +33,8 @@ export function NYI() {

export const NONE_CATEGORY_ID = '-1';

export const NONE_OPERATION_TYPE_ID = '-1';

var translator = null;
var alertMissing = null;
export function setTranslator(polyglotInstance) {
Expand All @@ -55,3 +57,18 @@ export function translate(format, bindings) {

return ret;
}

export const DEFAULT_TYPE_LABELS = {
"type.none": "None",
"type.unknown": "Unknown",
"type.transfer": "Transfer",
"type.order": "Order",
"type.check": "Check",
"type.deposit": "Deposit",
"type.payback": "Payback",
"type.withdrawal": "Withdrawal",
"type.card": "Card",
"type.loan_payment": "Loan payment",
"type.bankfee": "Bank fee",
"type.cash_deposit": "Cash deposit",
}
11 changes: 10 additions & 1 deletion client/Models.js
@@ -1,4 +1,4 @@
import {has, assert, maybeHas, NONE_CATEGORY_ID} from './Helpers';
import {has, assert, maybeHas, NONE_CATEGORY_ID, NONE_OPERATION_TYPE_ID} from './Helpers';

export class Bank {
constructor(arg) {
Expand Down Expand Up @@ -47,6 +47,7 @@ export class Operation {
this.dateImport = (maybeHas(arg, 'dateImport') && new Date(arg.dateImport)) || 0;
this.id = has(arg, 'id') && arg.id;
this.categoryId = arg.categoryId || NONE_CATEGORY_ID;
this.type = (maybeHas(arg, 'operationTypeID') && arg.operationTypeID) || NONE_OPERATION_TYPE_ID
}
}

Expand All @@ -72,3 +73,11 @@ export class Setting {
this.val = has(arg, 'value') && arg.value;
}
}

export class OperationType {
constructor(arg) {
this.name = has(arg, 'name') && arg.name;
this.id = has(arg, 'id') && arg.id;
this.weboobvalue = has(arg, 'weboobvalue') && arg.weboobvalue;
}
}
9 changes: 7 additions & 2 deletions client/components/OperationList.js
@@ -1,7 +1,7 @@
import React from 'react';

// Constants
import {has, maybeHas, translate as t} from '../Helpers';
import {has, maybeHas, translate as t, DEFAULT_TYPE_LABELS} from '../Helpers';

import {Category} from '../Models';

Expand Down Expand Up @@ -108,6 +108,7 @@ class OperationDetails extends React.Component {
<ul>
<li><T k='operations.full_label'>Full label:</T> {op.raw}</li>
<li><T k='operations.amount'>Amount:</T> {op.amount}</li>
<li><T k='operations.type'>Type:</T> {store.operationTypeToLabel(op.type)}</li>
<li><T k='operations.category'>Category:</T> <CategorySelectComponent operation={op} /></li>
{maybeAttachment}
</ul>
Expand Down Expand Up @@ -168,9 +169,11 @@ class OperationComponent extends React.Component {
<a href="#" className="toggle-btn" onClick={this.toggleDetails.bind(this)}> </a>
</td>
<td>{op.date.toLocaleDateString()}</td>
<td>{store.operationTypeToLabel(op.type)}</td>
<td className="text-uppercase">{label}</td>
<td>{op.amount}</td>
<td><CategorySelectComponent operation={op} /></td>

</tr>
);
}
Expand Down Expand Up @@ -364,10 +367,12 @@ export default class OperationsComponent extends React.Component {
<thead>
<tr>
<th></th>
<th className="col-sm-2"><T k='operations.column_date'>Date</T></th>
<th className="col-sm-1"><T k='operations.column_date'>Date</T></th>
<th className="col-sm-1"><T k='operations.column_type'>Type</T></th>
<th className="col-sm-7"><T k='operations.column_name'>Transaction</T></th>
<th className="col-sm-1"><T k='operations.column_amount'>Amount</T></th>
<th className="col-sm-2"><T k='operations.column_category'>Category</T></th>

</tr>
</thead>
<tbody>
Expand Down
5 changes: 4 additions & 1 deletion client/components/Similarity.js
Expand Up @@ -72,7 +72,8 @@ class SimilarityPairComponent extends React.Component {
<th className="col-xs-3"><T k="similarity.label">Label</T></th>
<th className="col-xs-1"><T k="similarity.amount">Amount</T></th>
<th className="col-xs-2"><T k="similarity.category">Category</T></th>
<th className="col-xs-3"><T k="similarity.imported_on">Imported on</T></th>
<th className="col-xs-1"><T k="similarity.type">Type</T></th>
<th className="col-xs-2"><T k="similarity.imported_on">Imported on</T></th>
<th className="col-xs-1"><T k="similarity.merge">Merge</T></th>
</tr>
</thead>
Expand All @@ -83,6 +84,7 @@ class SimilarityPairComponent extends React.Component {
<td>{this.props.a.title}</td>
<td>{this.props.a.amount}</td>
<td>{store.categoryToLabel(this.props.a.categoryId)}</td>
<td>{store.operationTypeToLabel(this.props.a.type)}</td>
<td>{new Date(this.props.a.dateImport).toLocaleString()}</td>
<td rowSpan={2}>
<button className="btn btn-primary" onClick={this.onMerge.bind(this)}>
Expand All @@ -96,6 +98,7 @@ class SimilarityPairComponent extends React.Component {
<td>{this.props.b.title}</td>
<td>{this.props.b.amount}</td>
<td>{store.categoryToLabel(this.props.b.categoryId)}</td>
<td>{store.operationTypeToLabel(this.props.b.type)}</td>
<td>{new Date(this.props.b.dateImport).toLocaleString()}</td>
</tr>

Expand Down
22 changes: 20 additions & 2 deletions client/locales/fr.js
Expand Up @@ -30,6 +30,7 @@ module.exports = {
title: 'Catégories',
label: 'Libellé'
},


changepasswordmodal: {
not_empty: "Le mot de passe est obligatoire !",
Expand Down Expand Up @@ -103,6 +104,7 @@ module.exports = {
column_name: 'Opération',
column_amount: 'Montant',
column_category: 'Catégorie',
column_type: 'Type',

current_balance: 'Balance en cours',
as_of: 'À la date du',
Expand All @@ -113,7 +115,7 @@ module.exports = {
attached_file: 'Télécharger le fichier associé',

full_label: 'Libellé complet :',
category: 'Catégorie',
category: 'Catégorie :',
kresus_init_title: "Veuillez patienter pendant l'initialisation de Kresus",
kresus_init_content: "Kresus est en train de télécharger de la magie, accrochez-vous !",

Expand All @@ -122,6 +124,7 @@ module.exports = {
syncing: 'Récupération de vos dernières opérations en cours...',

title: 'Opérations',
type: 'Type :',
},

search: {
Expand Down Expand Up @@ -157,7 +160,7 @@ module.exports = {

tab_accounts: 'Comptes bancaires',
tab_about: 'À propos',
tab_backup: 'Sauvegarde et restoration',
tab_backup: 'Sauvegarde et restauration',
tab_defaults: 'Paramètres par défaut',
tab_weboob: 'Gestion de Weboob',

Expand Down Expand Up @@ -186,6 +189,7 @@ module.exports = {
category: "Catégorie",
imported_on: "Importé le",
merge: "Fusionner",
type: "Type",
},

sync: {
Expand All @@ -196,4 +200,18 @@ module.exports = {
unknown_module: "Votre banque utilise un module non supporté par Kresus (et Weboob). Essayez de mettre à jour Weboob ou contactez un mainteneur.",
unknown_error: "Erreur inattendue: %{content}",
},
type: {
none: "Aucun",
unknown: "Inconnu",
transfer: "Virement",
order: "Prélevement",
check: "Chèque",
deposit: "Dépot",
payback: "Remboursement",
withdrawal: "Retrait",
card: "Carte",
loan_payment: "Remboursement d'emprunt",
bankfee: "Frais bancaire",
cash_deposit: "Dépôt d'éspèces",
}
}
39 changes: 35 additions & 4 deletions client/store.js
Expand Up @@ -5,9 +5,9 @@ import './locales/fr';

import {EventEmitter as EE} from 'events';

import {assert, debug, maybeHas, has, translate as t, NONE_CATEGORY_ID,
setTranslator, setTranslatorAlertMissing} from './Helpers';
import {Account, Bank, Category, Operation} from './Models';
import {assert, debug, maybeHas, has, translate as t, NONE_CATEGORY_ID,NONE_OPERATION_TYPE_ID,
setTranslator, setTranslatorAlertMissing, DEFAULT_TYPE_LABELS} from './Helpers';
import {Account, Bank, Category, Operation, OperationType} from './Models';

import flux from './flux/dispatcher';

Expand All @@ -28,7 +28,8 @@ var data = {
// (Each bank has an "account" field which is a map (id -> account),
// each account has an "operation" field which is an array of Operation).
banks: new Map,

operationtypes:[],
operationTypesLabel: new Map(), //Maps operation types to labels
/* Contains static information about banks (name/uuid) */
StaticBanks: []
};
Expand Down Expand Up @@ -223,6 +224,8 @@ store.setupKresus = function(cb) {

has(world, 'categories');
store.setCategories(world.categories);
has(world, 'operationtypes');
store.setOperationTypes(world.operationtypes);
cb && cb();
}).catch((err) => {
alert('Error when setting up Kresus: ' + err.toString());
Expand Down Expand Up @@ -603,6 +606,34 @@ store.changeAccessPassword = function(accessId, password) {
backend.updateAccess(accessId, {password});
}


//OPERATION TYPES
store.setOperationTypes = function(operationtypes){
var NONE_OPERATION_TYPE = new OperationType ({
id: NONE_OPERATION_TYPE_ID,
name: 'type.none',
weboobvalue: 0});
data.operationtypes = [NONE_OPERATION_TYPE].concat(operationtypes).map((type)=>new OperationType(type));
resetOperationTypesLabel();
}

function resetOperationTypesLabel(){
data.operationTypesLabel = new Map();
for (var i = 0; i < data.operationtypes.length; i++) {
var c = data.operationtypes[i];
has(c, 'id');
has(c, 'name');
data.operationTypesLabel.set(c.id, t(c.name) || DEFAULT_TYPE_LABELS[c.name]);
}
}

store.operationTypeToLabel = function(id){
assert(data.operationTypesLabel.has(id),
'operationTypeToLabel lookup failed for id: ' + id);
return data.operationTypesLabel.get(id);
}


/*
* EVENTS
*/
Expand Down
47 changes: 26 additions & 21 deletions server/controllers/all.coffee
@@ -1,11 +1,12 @@
Bank = require '../models/bank'
Access = require '../models/access'
Account = require '../models/account'
Category = require '../models/category'
Operation = require '../models/operation'
Config = require '../models/kresusconfig'
Cozy = require '../models/cozyinstance'
h = require './helpers'
Bank = require '../models/bank'
Access = require '../models/access'
Account = require '../models/account'
Category = require '../models/category'
Operation = require '../models/operation'
OperationType = require '../models/operationtype'
Config = require '../models/kresusconfig'
Cozy = require '../models/cozyinstance'
h = require './helpers'

async = require 'async'

Expand Down Expand Up @@ -33,19 +34,23 @@ GetAllData = (cb) ->
Operation.all (err, ops) ->
if err? then return errorFunc err, 'operations'
ret.operations = ops

Category.all (err, cats) ->
if err? then return errorFunc err, 'categories'
ret.categories = cats

Config.all (err, configs) ->
if err? then return errorFunc err, 'configs'
ret.settings = configs

Cozy.all (err, cozy) ->
if err? then return errorFunc err, 'cozy'
ret.cozy = cozy
cb null, ret

OperationType.all (err, types) ->
if err? then return errorFunc err, 'operationtypes'
ret.operationtypes = types

Category.all (err, cats) ->
if err? then return errorFunc err, 'categories'
ret.categories = cats

Config.all (err, configs) ->
if err? then return errorFunc err, 'configs'
ret.settings = configs

Cozy.all (err, cozy) ->
if err? then return errorFunc err, 'cozy'
ret.cozy = cozy
cb null, ret

module.exports.all = (req, res) ->
GetAllData (err, ret) ->
Expand Down
11 changes: 11 additions & 0 deletions server/lib/sources/mock.coffee
@@ -1,6 +1,8 @@
# This modules mocks output generated by weboob.
moment = require 'moment'

OperationType = require '../../models/operationtype'

log = (require 'printit')(
prefix: 'sources/mock'
date: true
Expand Down Expand Up @@ -92,12 +94,18 @@ randomLabelsPositive = [
rand = (low, high) ->
return low + (Math.random() * (high - low) | 0)

randInt = (low, high) ->
return ((low + (Math.random() * (high - low))) | 0)

randomLabel = () ->
return randomLabels[rand 0, randomLabels.length]

randomLabelPositive = () ->
return randomLabelsPositive[rand 0, randomLabelsPositive.length]

randomType = () ->
return randInt(0,10)

generateDate = (lowDay, highDay, lowMonth, highMonth) ->
moment()
.month(rand(lowMonth, highMonth))
Expand All @@ -117,6 +125,7 @@ generateOne = (account) ->
"amount": "-300"
"rdate": generateDate 4, 4, now.month(), now.month()
"account": account
"type": randomType()
}

if n < 15
Expand All @@ -129,6 +138,7 @@ generateOne = (account) ->
amount: amount.toString()
rdate: rdate
account: account
type: randomType()
}

[label, raw] = randomLabel()
Expand All @@ -140,6 +150,7 @@ generateOne = (account) ->
amount: amount.toString()
rdate: rdate
account: account
type: randomType()
}

selectRandomAccount = (uuid) ->
Expand Down

0 comments on commit 4f722aa

Please sign in to comment.