Improve currencies pages navigation

This commit is contained in:
Frederic Guillot 2017-01-08 21:08:33 -05:00
parent 1078cac70d
commit 47f4bceb1a
7 changed files with 101 additions and 67 deletions

View File

@ -14,6 +14,7 @@ Improvements:
* Display project analytics in modal box
* Display project exports in modal box
* Improve accordion component
* Improve currencies pages navigation
* Offer the possibility to define version compatibility from plugins
Version 1.0.36 (Dec 30, 2016)

View File

@ -11,21 +11,33 @@ namespace Kanboard\Controller;
class CurrencyController extends BaseController
{
/**
* Display all currency rates and form
* Display all currency rates
*
* @access public
*/
public function show()
{
$this->response->html($this->helper->layout->config('currency/show', array(
'application_currency' => $this->configModel->get('application_currency'),
'rates' => $this->currencyModel->getAll(),
'currencies' => $this->currencyModel->getCurrencies(),
'title' => t('Settings').' > '.t('Currency rates'),
)));
}
/**
* Add or change currency rate
*
* @access public
* @param array $values
* @param array $errors
*/
public function index(array $values = array(), array $errors = array())
public function create(array $values = array(), array $errors = array())
{
$this->response->html($this->helper->layout->config('currency/index', array(
'config_values' => array('application_currency' => $this->configModel->get('application_currency')),
$this->response->html($this->helper->layout->config('currency/create', array(
'values' => $values,
'errors' => $errors,
'rates' => $this->currencyModel->getAll(),
'currencies' => $this->currencyModel->getCurrencies(),
'title' => t('Settings').' > '.t('Currency rates'),
)));
}
@ -34,7 +46,7 @@ class CurrencyController extends BaseController
*
* @access public
*/
public function create()
public function save()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->currencyValidator->validateCreation($values);
@ -42,13 +54,34 @@ class CurrencyController extends BaseController
if ($valid) {
if ($this->currencyModel->create($values['currency'], $values['rate'])) {
$this->flash->success(t('The currency rate have been added successfully.'));
return $this->response->redirect($this->helper->url->to('CurrencyController', 'index'));
$this->response->redirect($this->helper->url->to('CurrencyController', 'show'), true);
return;
} else {
$this->flash->failure(t('Unable to add this currency rate.'));
}
}
return $this->index($values, $errors);
$this->create($values, $errors);
}
/**
* Change reference currency
*
* @access public
* @param array $values
* @param array $errors
*/
public function change(array $values = array(), array $errors = array())
{
if (empty($values)) {
$values['application_currency'] = $this->configModel->get('application_currency');
}
$this->response->html($this->helper->layout->config('currency/change', array(
'values' => $values,
'errors' => $errors,
'currencies' => $this->currencyModel->getCurrencies(),
)));
}
/**
@ -56,7 +89,7 @@ class CurrencyController extends BaseController
*
* @access public
*/
public function reference()
public function update()
{
$values = $this->request->getValues();
@ -66,6 +99,6 @@ class CurrencyController extends BaseController
$this->flash->failure(t('Unable to save your settings.'));
}
$this->response->redirect($this->helper->url->to('CurrencyController', 'index'));
$this->response->redirect($this->helper->url->to('CurrencyController', 'show'), true);
}
}

View File

@ -24,8 +24,8 @@
<li <?= $this->app->checkMenuSelection('LinkController') ?>>
<?= $this->url->link(t('Link settings'), 'LinkController', 'index') ?>
</li>
<li <?= $this->app->checkMenuSelection('CurrencyController', 'index') ?>>
<?= $this->url->link(t('Currency rates'), 'CurrencyController', 'index') ?>
<li <?= $this->app->checkMenuSelection('CurrencyController', 'show') ?>>
<?= $this->url->link(t('Currency rates'), 'CurrencyController', 'show') ?>
</li>
<li <?= $this->app->checkMenuSelection('ConfigController', 'integrations') ?>>
<?= $this->url->link(t('Integrations'), 'ConfigController', 'integrations') ?>

View File

@ -0,0 +1,9 @@
<div class="page-header">
<h2><?= t('Change reference currency') ?></h2>
</div>
<form method="post" action="<?= $this->url->href('CurrencyController', 'update') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Reference currency'), 'application_currency') ?>
<?= $this->form->select('application_currency', $currencies, $values, $errors) ?>
<?= $this->modal->submitButtons() ?>
</form>

View File

@ -0,0 +1,11 @@
<div class="page-header">
<h2><?= t('Add or change currency rate') ?></h2>
</div>
<form method="post" action="<?= $this->url->href('CurrencyController', 'save') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Currency'), 'currency') ?>
<?= $this->form->select('currency', $currencies, $values, $errors) ?>
<?= $this->form->label(t('Rate'), 'rate') ?>
<?= $this->form->text('rate', $values, $errors, array('autofocus'), 'form-numeric') ?>
<?= $this->modal->submitButtons() ?>
</form>

View File

@ -1,54 +0,0 @@
<div class="page-header">
<h2><?= t('Currency rates') ?></h2>
</div>
<?php if (! empty($rates)): ?>
<table class="table-striped">
<tr>
<th class="column-35"><?= t('Currency') ?></th>
<th><?= t('Rate') ?></th>
</tr>
<?php foreach ($rates as $rate): ?>
<tr>
<td>
<strong><?= $this->text->e($rate['currency']) ?></strong>
</td>
<td>
<?= n($rate['rate']) ?>
</td>
</tr>
<?php endforeach ?>
</table>
<hr/>
<h3><?= t('Change reference currency') ?></h3>
<?php endif ?>
<form method="post" action="<?= $this->url->href('CurrencyController', 'reference') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Reference currency'), 'application_currency') ?>
<?= $this->form->select('application_currency', $currencies, $config_values, $errors) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
</div>
</form>
<hr/>
<h3><?= t('Add a new currency rate') ?></h3>
<form method="post" action="<?= $this->url->href('CurrencyController', 'create') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Currency'), 'currency') ?>
<?= $this->form->select('currency', $currencies, $values, $errors) ?>
<?= $this->form->label(t('Rate'), 'rate') ?>
<?= $this->form->text('rate', $values, $errors, array(), 'form-numeric') ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
</div>
</form>

View File

@ -0,0 +1,34 @@
<div class="page-header">
<h2><?= t('Currency rates') ?></h2>
<ul>
<li>
<?= $this->modal->medium('plus', t('Add or change currency rate'), 'CurrencyController', 'create') ?>
</li>
<li>
<?= $this->modal->medium('edit', t('Change reference currency'), 'CurrencyController', 'change') ?>
</li>
</ul>
</div>
<div class="panel">
<strong><?= t('Reference currency: %s', $application_currency) ?></strong>
</div>
<?php if (! empty($rates)): ?>
<table class="table-striped">
<tr>
<th class="column-35"><?= t('Currency') ?></th>
<th><?= t('Rate') ?></th>
</tr>
<?php foreach ($rates as $rate): ?>
<tr>
<td>
<strong><?= $this->text->e($rate['currency']) ?></strong>
</td>
<td>
<?= n($rate['rate']) ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>