mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-23 04:46:44 +00:00
Fixed upload form, made a new form element, added some processing.
This commit is contained in:
@@ -7,6 +7,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Input;
|
||||||
|
use League\Csv\Reader;
|
||||||
|
use Redirect;
|
||||||
|
use Session;
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,13 +29,64 @@ class CsvController extends Controller
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
View::share('title', 'CSV');
|
View::share('title', trans('firefly.csv'));
|
||||||
View::share('mainTitleIcon', 'fa-file-text-o');
|
View::share('mainTitleIcon', 'fa-file-text-o');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view('csv.index');
|
$subTitle = trans('firefly.csv_import');
|
||||||
|
|
||||||
|
// can actually upload?
|
||||||
|
$uploadPossible = !is_writable(storage_path('upload'));
|
||||||
|
$path = storage_path('upload');
|
||||||
|
|
||||||
|
|
||||||
|
return view('csv.index', compact('subTitle', 'uploadPossible', 'path'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function upload(Request $request)
|
||||||
|
{
|
||||||
|
if (!$request->hasFile('csv')) {
|
||||||
|
Session::flash('warning', 'No file uploaded.');
|
||||||
|
|
||||||
|
|
||||||
|
return Redirect::route('csv.index');
|
||||||
|
}
|
||||||
|
$hasHeaders = intval(Input::get('has_headers')) === 1;
|
||||||
|
$reader = Reader::createFromPath($request->file('csv')->getRealPath());
|
||||||
|
$data = $reader->query();
|
||||||
|
$data->next(); // go to first row:
|
||||||
|
if ($hasHeaders) {
|
||||||
|
|
||||||
|
// first row = headers.
|
||||||
|
$headers = $data->current();
|
||||||
|
} else {
|
||||||
|
$count = count($data->current());
|
||||||
|
$headers = [];
|
||||||
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
|
$headers[] = trans('firefly.csv_row') . ' #' . $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// example data is always the second row:
|
||||||
|
$data->next();
|
||||||
|
$example = $data->current();
|
||||||
|
|
||||||
|
var_dump($headers);
|
||||||
|
var_dump($example);
|
||||||
|
|
||||||
|
// store file somewhere temporary?
|
||||||
|
|
||||||
|
|
||||||
|
exit;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -224,6 +224,7 @@ Route::group(
|
|||||||
* CSV controller
|
* CSV controller
|
||||||
*/
|
*/
|
||||||
Route::get('/csv', ['uses' => 'CsvController@index', 'as' => 'csv.index']);
|
Route::get('/csv', ['uses' => 'CsvController@index', 'as' => 'csv.index']);
|
||||||
|
Route::post('/csv/upload', ['uses' => 'CsvController@upload', 'as' => 'csv.upload']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currency Controller
|
* Currency Controller
|
||||||
|
@@ -347,6 +347,24 @@ class ExpandedForm
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param null $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function file($name, array $options = [])
|
||||||
|
{
|
||||||
|
$label = $this->label($name, $options);
|
||||||
|
$options = $this->expandOptionArray($name, $label, $options);
|
||||||
|
$classes = $this->getHolderClasses($name);
|
||||||
|
$html = View::make('form.file', compact('classes', 'name', 'label', 'options'))->render();
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param null $value
|
* @param null $value
|
||||||
|
@@ -28,7 +28,8 @@
|
|||||||
"illuminate/html": "~5.0",
|
"illuminate/html": "~5.0",
|
||||||
"league/commonmark": "0.7.*",
|
"league/commonmark": "0.7.*",
|
||||||
"rcrowe/twigbridge": "0.7.x@dev",
|
"rcrowe/twigbridge": "0.7.x@dev",
|
||||||
"zizaco/entrust": "dev-laravel-5"
|
"zizaco/entrust": "dev-laravel-5",
|
||||||
|
"league/csv": "^7.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-debugbar": "@stable",
|
"barryvdh/laravel-debugbar": "@stable",
|
||||||
|
2415
composer.lock
generated
2415
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -145,12 +145,12 @@ return [
|
|||||||
'ExpandedForm' => [
|
'ExpandedForm' => [
|
||||||
'is_safe' => [
|
'is_safe' => [
|
||||||
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
||||||
'multiRadio'
|
'multiRadio','file'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Form' => [
|
'Form' => [
|
||||||
'is_safe' => [
|
'is_safe' => [
|
||||||
'input', 'select', 'checkbox', 'model', 'open', 'radio', 'textarea'
|
'input', 'select', 'checkbox', 'model', 'open', 'radio', 'textarea','file'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@@ -21,6 +21,13 @@ return [
|
|||||||
|
|
||||||
// csv import:
|
// csv import:
|
||||||
'csv_import' => 'Import CSV file',
|
'csv_import' => 'Import CSV file',
|
||||||
|
'csv' => 'CSV',
|
||||||
|
'csv_index_text' => 'Here be explanation.',
|
||||||
|
'csv_upload_form' => 'Upload form',
|
||||||
|
'upload_csv_file' => 'Upload CSV file',
|
||||||
|
'csv_header_help' => 'Check this when bla bla',
|
||||||
|
'csv_row' => 'row',
|
||||||
|
'upload_not_writeable' => 'Cannot write to the path mentioned here. Cannot upload',
|
||||||
|
|
||||||
// create new stuff:
|
// create new stuff:
|
||||||
'create_new_withdrawal' => 'Create new withdrawal',
|
'create_new_withdrawal' => 'Create new withdrawal',
|
||||||
|
@@ -45,6 +45,8 @@ return [
|
|||||||
'under' => 'Under',
|
'under' => 'Under',
|
||||||
'symbol' => 'Symbol',
|
'symbol' => 'Symbol',
|
||||||
'code' => 'Code',
|
'code' => 'Code',
|
||||||
|
'csv' => 'CSV file',
|
||||||
|
'has_headers' => 'Headers',
|
||||||
|
|
||||||
'store_new_withdrawal' => 'Store new withdrawal',
|
'store_new_withdrawal' => 'Store new withdrawal',
|
||||||
'store_new_deposit' => 'Store new deposit',
|
'store_new_deposit' => 'Store new deposit',
|
||||||
|
@@ -20,7 +20,14 @@ return [
|
|||||||
'search_results_for' => 'Zoekresultaten voor ":query"',
|
'search_results_for' => 'Zoekresultaten voor ":query"',
|
||||||
|
|
||||||
// csv import:
|
// csv import:
|
||||||
'csv_import' => 'Import CSV file',
|
'csv_import' => 'Importeer CSV-bestand',
|
||||||
|
'csv' => 'CSV',
|
||||||
|
'csv_index_text' => 'Hier komt uitleg.',
|
||||||
|
'csv_upload_form' => 'Upload formulier',
|
||||||
|
'upload_csv_file' => 'Upload CSV-bestand',
|
||||||
|
'csv_header_help' => 'Check dit als bla bla',
|
||||||
|
'csv_row' => 'rij',
|
||||||
|
'upload_not_writeable' => 'Cannot write to the path mentioned here. Cannot upload',
|
||||||
|
|
||||||
// create new stuff:
|
// create new stuff:
|
||||||
'create_new_withdrawal' => 'Nieuwe uitgave',
|
'create_new_withdrawal' => 'Nieuwe uitgave',
|
||||||
|
@@ -45,6 +45,8 @@ return [
|
|||||||
'under' => 'Onder',
|
'under' => 'Onder',
|
||||||
'symbol' => 'Symbool',
|
'symbol' => 'Symbool',
|
||||||
'code' => 'Code',
|
'code' => 'Code',
|
||||||
|
'csv' => 'CSV-bestand',
|
||||||
|
'has_headers' => 'Eerste rij zijn kolomnamen',
|
||||||
|
|
||||||
'store_new_withdrawal' => 'Nieuwe uitgave opslaan',
|
'store_new_withdrawal' => 'Nieuwe uitgave opslaan',
|
||||||
'store_new_deposit' => 'Nieuwe inkomsten opslaan',
|
'store_new_deposit' => 'Nieuwe inkomsten opslaan',
|
||||||
|
@@ -7,6 +7,81 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
Bla bla.
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'csv'|_ }}</h3>
|
||||||
|
|
||||||
|
<!-- ACTIONS MENU -->
|
||||||
|
<div class="box-tools pull-right">
|
||||||
|
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
{{ 'csv_index_text'|_ }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'csv_upload_form'|_ }}</h3>
|
||||||
|
|
||||||
|
<!-- ACTIONS MENU -->
|
||||||
|
<div class="box-tools pull-right">
|
||||||
|
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
|
||||||
|
<form class="form-horizontal" action="{{ route('csv.upload') }}" method="post" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
|
||||||
|
|
||||||
|
{{ ExpandedForm.checkbox('has_headers',false,null,{helpText: 'csv_header_help'|_}) }}
|
||||||
|
|
||||||
|
{{ ExpandedForm.file('csv') }}
|
||||||
|
|
||||||
|
{% if uploadPossible %}
|
||||||
|
<div class="form-group" id="csv_holder">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<button type="submit" class="btn btn-success">
|
||||||
|
{{ 'upload_csv_file'|_ }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="form-group" id="csv_holder">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<pre>{{ path }}</pre>
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ 'upload_not_writeable'|_ }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
{{ Form.checkbox(name, value, options.checked, options) }}
|
{{ Form.checkbox(name, value, options.checked, options) }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
{% include 'form/help.twig' %}
|
||||||
{% include 'form/feedback.twig' %}
|
{% include 'form/feedback.twig' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
9
resources/twig/form/file.twig
Normal file
9
resources/twig/form/file.twig
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<div class="{{ classes }}" id="{{ name }}_holder">
|
||||||
|
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
|
||||||
|
|
||||||
|
<div class="col-sm-8">
|
||||||
|
{{ Form.file(name, options) }}
|
||||||
|
{% include 'form/help.twig' %}
|
||||||
|
{% include 'form/feedback.twig' %}
|
||||||
|
</div>
|
||||||
|
</div>
|
2
storage/upload/.gitignore
vendored
Normal file
2
storage/upload/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
Reference in New Issue
Block a user