Commit a9b8bc13 authored by Antoine's avatar Antoine Committed by Antoine
Browse files

Use the customLabel when it exists instead of title when displaying accounts. Fixes #762

parent 3f729c6f
......@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { get } from '../../store';
import { displayLabel } from '../../helpers';
const AccountListItem = connect((state, props) => {
let account = get.accountById(state, props.accountId);
......@@ -19,7 +20,7 @@ const AccountListItem = connect((state, props) => {
return (
<li key={`account-details-account-list-item-${accountId}`}>
<NavLink to={newPathname} activeClassName="active">
<span>{account.customLabel || account.title}</span>
<span>{displayLabel(account)}</span>
<span className={`amount ${color}`}>{accountBalance}</span>
</NavLink>
</li>
......
......@@ -3,7 +3,12 @@ import { connect } from 'react-redux';
import { actions, get } from '../../../store';
import { translate as $t, NONE_CATEGORY_ID, UNKNOWN_OPERATION_TYPE } from '../../../helpers';
import {
translate as $t,
NONE_CATEGORY_ID,
UNKNOWN_OPERATION_TYPE,
displayLabel
} from '../../../helpers';
import CategorySelect from '../../operations/category-select';
import OperationTypeSelect from '../../operations/type-select';
......@@ -84,15 +89,16 @@ const AddOperationModal = connect(
};
render() {
let accountTitle = displayLabel(this.props.account);
let title = $t('client.addoperationmodal.add_operation', {
account: this.props.account.title
account: accountTitle
});
let body = (
<React.Fragment>
<span>
{$t('client.addoperationmodal.description', {
account: this.props.account.title
account: accountTitle
})}
</span>
......
import React from 'react';
import { connect } from 'react-redux';
import { translate as $t } from '../../../helpers';
import { translate as $t, displayLabel } from '../../../helpers';
import { get, actions } from '../../../store';
import { registerModal } from '../../ui/modal';
......@@ -14,7 +14,7 @@ const ConfirmDeleteModal = connect(
state => {
let accountId = get.modal(state).state;
let account = get.accountById(state, accountId);
let title = account ? account.title : null;
let title = account ? displayLabel(account) : null;
return {
accountId,
title
......
import React from 'react';
import { connect } from 'react-redux';
import { translate as $t } from '../../../helpers';
import { translate as $t, displayLabel } from '../../../helpers';
import { actions, get } from '../../../store';
import { registerModal } from '../../ui/modal';
......@@ -12,7 +12,7 @@ const SyncBalanceModal = connect(
state => {
let accountId = get.modal(state).state;
let account = get.accountById(state, accountId);
let title = account ? account.title : null;
let title = account ? displayLabel(account) : null;
return {
title,
accountId
......
......@@ -2,6 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { get } from '../../../store';
import { displayLabel } from '../../../helpers';
const AccountSelector = connect(
state => {
......@@ -15,7 +16,7 @@ const AccountSelector = connect(
let account = get.accountById(state, accountId);
pairs.push({
key: account.id,
val: `${access.name}${account.title}`
val: `${access.name}${displayLabel(account)}`
});
}
}
......
......@@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { assert, translate as $t } from '../../../helpers';
import { assert, translate as $t, displayLabel } from '../../../helpers';
import { actions, get } from '../../../store';
import DeleteAlertButton from './confirm-delete-alert';
......@@ -41,7 +41,7 @@ class AlertItem extends React.Component {
return (
<tr>
<td className="col-md-3">{`${access.name}${account.title}`}</td>
<td className="col-md-3">{`${access.name}${displayLabel(account)}`}</td>
<td className="col-md-3">
<span className="condition">{this.props.sendIfText}</span>
</td>
......
......@@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { assert, assertHas, translate as $t } from '../../../helpers';
import { displayLabel, assert, assertHas, translate as $t } from '../../../helpers';
import { actions, get } from '../../../store';
import DeleteAlertButton from './confirm-delete-alert';
......@@ -24,7 +24,7 @@ class ReportItem extends React.Component {
return (
<tr>
<td className="col-md-3">{`${access.name}${account.title}`}</td>
<td className="col-md-3">{`${access.name}${displayLabel(account)}`}</td>
<td className="col-md-3">
<span className="condition">{$t('client.settings.emails.send_report')}</span>
</td>
......
......@@ -16,7 +16,8 @@ import {
UNKNOWN_ACCOUNT_TYPE as UNKNOWN_ACCOUNT_TYPE_,
UNKNOWN_OPERATION_TYPE as UNKNOWN_OPERATION_TYPE_,
formatDate as formatDate_,
MIN_WEBOOB_VERSION as MIN_WEBOOB_VERSION_
MIN_WEBOOB_VERSION as MIN_WEBOOB_VERSION_,
displayLabel as displayLabel_
} from '../shared/helpers.js';
export const assert = assert_;
......@@ -31,6 +32,7 @@ export const UNKNOWN_ACCOUNT_TYPE = UNKNOWN_ACCOUNT_TYPE_;
export const UNKNOWN_OPERATION_TYPE = UNKNOWN_OPERATION_TYPE_;
export const formatDate = formatDate_;
export const MIN_WEBOOB_VERSION = MIN_WEBOOB_VERSION_;
export const displayLabel = displayLabel_;
export const AlertTypes = ['balance', 'transaction'];
......
......@@ -9,7 +9,8 @@ import {
UNKNOWN_OPERATION_TYPE as UNKNOWN_OPERATION_TYPE_,
UNKNOWN_ACCOUNT_TYPE as UNKNOWN_ACCOUNT_TYPE_,
formatDate as formatDate_,
MIN_WEBOOB_VERSION as MIN_WEBOOB_VERSION_
MIN_WEBOOB_VERSION as MIN_WEBOOB_VERSION_,
displayLabel as displayLabel_
} from './shared/helpers.js';
import errors from './shared/errors.json';
......@@ -24,6 +25,7 @@ export const UNKNOWN_ACCOUNT_TYPE = UNKNOWN_ACCOUNT_TYPE_;
export const setupTranslator = setupTranslator_;
export const formatDate = formatDate_;
export const MIN_WEBOOB_VERSION = MIN_WEBOOB_VERSION_;
export const displayLabel = displayLabel_;
export function makeLogger(prefix) {
return new Logger(prefix);
......
......@@ -8,7 +8,15 @@ import Operation from '../models/operation';
import OperationType from '../models/operationtype';
import * as AccountType from '../models/accounttype';
import { KError, getErrorCode, makeLogger, translate as $t, currency, assert } from '../helpers';
import {
KError,
getErrorCode,
makeLogger,
translate as $t,
currency,
assert,
displayLabel
} from '../helpers';
import AsyncQueue from './async-queue';
import alertManager from './alert-manager';
......@@ -138,7 +146,7 @@ async function notifyNewOperations(access, newOperations, accountMap) {
/* eslint-disable camelcase */
let params = {
account_title: `${bank.name} - ${account.title}`,
account_title: `${bank.name} - ${displayLabel(account)}`,
smart_count: ops.length
};
......@@ -338,8 +346,8 @@ merging as per request`);
log.info('Updating accounts balances…');
for (let { account, balanceOffset } of accountMap.values()) {
if (balanceOffset) {
log.info(`Account ${account.title} initial balance is going to be resynced, by an
offset of ${balanceOffset}.`);
log.info(`Account ${account.title} initial balance is going
to be resynced, by an offset of ${balanceOffset}.`);
account.initialAmount -= balanceOffset;
await account.save();
}
......
......@@ -5,7 +5,7 @@ import Account from '../models/account';
import Alert from '../models/alert';
import Config from '../models/config';
import { makeLogger, translate as $t, currency } from '../helpers';
import { makeLogger, translate as $t, currency, displayLabel } from '../helpers';
let log = makeLogger('alert-manager');
......@@ -107,7 +107,11 @@ ${$t('server.email.signature')}
// Set the currency formatter
let curr = account.currency || defaultCurrency;
let formatCurrency = currency.makeFormat(curr);
let text = alert.formatAccountMessage(account.title, balance, formatCurrency);
let text = alert.formatAccountMessage(
displayLabel(account),
balance,
formatCurrency
);
await this.send({
subject: $t('server.alert.balance.title'),
text
......
......@@ -5,7 +5,8 @@ import {
currency,
formatDate,
POLLER_START_LOW_HOUR,
POLLER_START_HIGH_HOUR
POLLER_START_HIGH_HOUR,
displayLabel
} from '../helpers';
import Emailer from './emailer';
......@@ -160,7 +161,7 @@ class ReportManager {
for (let account of accounts) {
let lastCheck = formatDate.toShortString(account.lastCheck);
let balance = await account.computeBalance();
content += `\t* ${account.title} : `;
content += `\t* ${displayLabel(account)} : `;
content += `${account.formatCurrency(balance)} (`;
content += $t('server.email.report.last_sync');
content += ` ${lastCheck})\n`;
......@@ -184,7 +185,7 @@ class ReportManager {
return 1;
});
content += `\n${pair.account.title}:\n`;
content += `\n${displayLabel(pair.account)}:\n`;
for (let op of operations) {
let date = formatDate.toShortString(op.date);
content += `\t* ${date} - ${op.title} : `;
......
......@@ -136,6 +136,11 @@ export const currency = {
makeFormat: c => amount => currencyFormatter(amount, { code: c })
};
export function displayLabel(obj) {
assertHas(obj, 'title', 'The parameter of displayLabel shall have "title" property.');
return obj.customLabel || obj.title;
}
export const UNKNOWN_OPERATION_TYPE = 'type.unknown';
export const UNKNOWN_ACCOUNT_TYPE = 'account-type.unknown';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment