mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
Initial code for preparing bunq import #714
This commit is contained in:
@@ -13,6 +13,7 @@ namespace FireflyIII\Http\Controllers\Import;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Support\Import\Prerequisites\PrerequisitesInterface;
|
||||
|
||||
class BankController extends Controller
|
||||
{
|
||||
@@ -22,6 +23,24 @@ class BankController extends Controller
|
||||
*/
|
||||
public function prerequisites(string $bank)
|
||||
{
|
||||
$class = config(sprintf('firefly.import_pre.%s', $bank));
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
$object->setUser(auth()->user());
|
||||
|
||||
if ($object->hasPrerequisites()) {
|
||||
$view = $object->getView();
|
||||
$parameters = $object->getViewParameters();
|
||||
return view($view, $parameters);
|
||||
}
|
||||
|
||||
if (!$object->hasPrerequisites()) {
|
||||
echo 'redirect to import form.';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function postPrerequisites() {
|
||||
|
||||
}
|
||||
|
||||
|
71
app/Support/Import/Prerequisites/BunqPrerequisites.php
Normal file
71
app/Support/Import/Prerequisites/BunqPrerequisites.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* BunqPrerequisites.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Import\Prerequisites;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class BunqPrerequisites
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Prerequisites
|
||||
*/
|
||||
class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string
|
||||
{
|
||||
return 'import.bunq.prerequisites';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this import method has any special prerequisites such as config
|
||||
* variables or other things.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPrerequisites(): bool
|
||||
{
|
||||
$apiKey = Preferences::getForUser($this->user, 'bunq_api_key', false);
|
||||
|
||||
return ($apiKey->data === false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
47
app/Support/Import/Prerequisites/PrerequisitesInterface.php
Normal file
47
app/Support/Import/Prerequisites/PrerequisitesInterface.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* PrerequisitesInterface.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Import\Prerequisites;
|
||||
|
||||
|
||||
use FireflyIII\User;
|
||||
|
||||
interface PrerequisitesInterface
|
||||
{
|
||||
/**
|
||||
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void;
|
||||
|
||||
/**
|
||||
* Returns view name that allows user to fill in prerequisites.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getView(): string;
|
||||
|
||||
/**
|
||||
* Returns any values required for the prerequisites-view.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters(): array;
|
||||
|
||||
/**
|
||||
* Returns if this import method has any special prerequisites such as config
|
||||
* variables or other things.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPrerequisites(): bool;
|
||||
}
|
@@ -39,6 +39,9 @@ return [
|
||||
'import_processors' => [
|
||||
'csv' => 'FireflyIII\Import\FileProcessor\CsvProcessor',
|
||||
],
|
||||
'import_pre' => [
|
||||
'bunq' => 'FireflyIII\Support\Import\Prerequisites\BunqPrerequisites',
|
||||
],
|
||||
'default_export_format' => 'csv',
|
||||
'default_import_format' => 'csv',
|
||||
'bill_periods' => ['weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
|
||||
|
43
resources/views/import/bunq/prerequisites.twig
Normal file
43
resources/views/import/bunq/prerequisites.twig
Normal file
@@ -0,0 +1,43 @@
|
||||
{% extends "./layout/default" %}
|
||||
|
||||
{% block breadcrumbs %}
|
||||
{{ Breadcrumbs.renderIfExists }}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<form class="form-horizontal" id="report-form" action="{{ route('import.bank.prerequisites.post',['bunq']) }}" method="post">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ trans('bank.prerequisites_for_import_title') }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<p>
|
||||
{{ trans('bank.prerequisites_for_import_text') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
{{ ExpandedForm.text('api_key') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn pull-right btn-success">
|
||||
{{ ('submit')|_ }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
{% endblock %}
|
||||
{% block styles %}
|
||||
{% endblock %}
|
@@ -28,12 +28,10 @@
|
||||
Import a (CSV) file
|
||||
</a>
|
||||
{# bunq import #}
|
||||
{#
|
||||
<a href="{{ route('import.bank.prerequisites', ['bunq']) }}" class="btn btn-app">
|
||||
<img src="images/logos/bunq.png" alt="bunq"/><br />
|
||||
Import from bunq
|
||||
</a>
|
||||
#}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -400,6 +400,7 @@ Route::group(
|
||||
|
||||
// banks:
|
||||
Route::get('bank/{bank}/prerequisites', ['uses' => 'Import\BankController@prerequisites', 'as' => 'bank.prerequisites']);
|
||||
Route::post('bank/{bank}/prerequisites', ['uses' => 'Import\BankController@postPrerequisites', 'as' => 'bank.prerequisites.post']);
|
||||
}
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user