edit page for editor:

- fields for coverage
This commit is contained in:
Arno Kaimbacher 2019-05-27 18:52:44 +02:00
parent fed2fafd55
commit 4c4c0760d8
4 changed files with 185 additions and 79 deletions

View File

@ -15,6 +15,8 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Illuminate\Support\Facades\DB;
// use App\Models\Coverage;
use Illuminate\Support\Facades\Validator;
class EditorController extends Controller
{
@ -87,7 +89,7 @@ class EditorController extends Controller
public function edit($id): View
{
$dataset = Dataset::findOrFail($id);
$dataset->load('licenses', 'titles', 'abstracts', 'files');
$dataset->load('licenses', 'titles', 'abstracts', 'files', 'coverage');
$projects = Project::pluck('label', 'id');
@ -123,17 +125,30 @@ class EditorController extends Controller
*/
public function update(DocumentRequest $request, $id): RedirectResponse
{
$rules = [
'type' => 'required|min:5',
'coverage.xmin' => [
'nullable',
'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'
],
'coverage.ymin' => [
'nullable',
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'
],
'coverage.xmax' => [
'nullable',
'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'
],
'coverage.ymax' => [
'nullable',
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'
],
];
$validator = Validator::make($request->all(), $rules);
if ($validator->passes()) {
$dataset = Dataset::findOrFail($id);
//$input = $request->all();
$input = $request->except('abstracts', 'licenses', 'titles', '_method', '_token');
// foreach ($input as $key => $value) {
// $dataset[$key] = $value;
// }
//$dataset->update($input);
// $dataset->type = $input['type'];
// $dataset->thesis_year_accepted = $input['thesis_year_accepted'];
// $dataset->project_id = $input['project_id'];
// $dataset->save();
$data = $request->all();
$input = $request->except('abstracts', 'licenses', 'titles', 'coverage', '_method', '_token');
$licenses = $request->input('licenses');
//$licenses = $input['licenses'];
@ -161,6 +176,15 @@ class EditorController extends Controller
}
}
// save coverage
if (isset($data['coverage'])) {
$formCoverage = $request->input('coverage');
$coverage = $dataset->coverage()->updateOrCreate(
['dataset_id' => $dataset->id],
$formCoverage
);
}
if (!$dataset->isDirty(dataset::UPDATED_AT)) {
$time = new \Illuminate\Support\Carbon();
$dataset->setUpdatedAt($time);
@ -171,6 +195,17 @@ class EditorController extends Controller
session()->flash('flash_message', 'You have updated 1 dataset!');
return redirect()->route('publish.workflow.editor.index');
}
}
else {
//TODO Handle validation error
//pass validator errors as errors object for ajax response
// return response()->json([
// 'success' => false,
// 'errors' => $validator->errors()->all(),
// ], 422);
return back()
->withErrors($validator->errors()->all());
}
throw new GeneralException(trans('exceptions.backend.dataset.update_error'));
}

View File

@ -252,19 +252,19 @@ class IndexController extends Controller
'title_main.language' => 'required',
'abstract_main.value' => 'required|min:4',
'abstract_main.language' => 'required',
'geolocation.xmin' => [
'coverage.xmin' => [
'nullable',
'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'
],
'geolocation.ymin' => [
'coverage.ymin' => [
'nullable',
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'
],
'geolocation.xmax' => [
'coverage.xmax' => [
'nullable',
'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'
],
'geolocation.ymax' => [
'coverage.ymax' => [
'nullable',
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'
],

10
composer.lock generated
View File

@ -1180,16 +1180,16 @@
},
{
"name": "nikic/php-parser",
"version": "v4.2.1",
"version": "v4.2.2",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "5221f49a608808c1e4d436df32884cbc1b821ac0"
"reference": "1bd73cc04c3843ad8d6b0bfc0956026a151fc420"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/5221f49a608808c1e4d436df32884cbc1b821ac0",
"reference": "5221f49a608808c1e4d436df32884cbc1b821ac0",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bd73cc04c3843ad8d6b0bfc0956026a151fc420",
"reference": "1bd73cc04c3843ad8d6b0bfc0956026a151fc420",
"shasum": ""
},
"require": {
@ -1227,7 +1227,7 @@
"parser",
"php"
],
"time": "2019-02-16T20:54:15+00:00"
"time": "2019-05-25T20:07:01+00:00"
},
{
"name": "paragonie/random_compat",

View File

@ -9,20 +9,6 @@
</div>
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('server_state', 'Status..') !!}
{{-- {!! Form::select('server_state', Config::get('enums.server_states'), null, ['id' => 'server_state', 'placeholder' => '-- select server state --']) !!} --}}
{!! Form::text('server_state', null, ['class'=>'pure-u-23-24','readonly']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('reject_reviewer_note', 'reviewer note..') !!}
{{-- {!! Form::select('server_state', Config::get('enums.server_states'), null, ['id' => 'server_state', 'placeholder' => '-- select server state --']) !!} --}}
{!! Form::textarea('reject_reviewer_note', null, ['class'=>'pure-u-23-24','readonly']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('project_id', 'Project..') !!}
<div class="select pure-u-23-24">
@ -31,10 +17,19 @@
<small id="projectHelp" class="pure-form-message-inline">project is optional</small>
</div>
{{-- <div class="pure-control-group">
{!! Form::label('shelf_id', 'Shelf..') !!}
{!! Form::select('shelf_id', $shelves, null, ['id' => 'shelf_id']) !!}
</div> --}}
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('server_state', 'Status..') !!}
{{-- {!! Form::select('server_state', Config::get('enums.server_states'), null, ['id' => 'server_state', 'placeholder' => '-- select server state --']) !!} --}}
{!! Form::text('server_state', null, ['class'=>'pure-u-23-24','readonly']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('reject_reviewer_note', 'reviewer reject note..') !!}
{{-- {!! Form::select('server_state', Config::get('enums.server_states'), null, ['id' => 'server_state', 'placeholder' => '-- select server state --']) !!} --}}
{!! Form::textarea('reject_reviewer_note', null, ['class'=>'pure-u-23-24','readonly']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('embargo_date', 'Embargo Date') !!}
@ -44,6 +39,86 @@
</div>
</fieldset>
<fieldset id="fieldset-geolocation">
<legend>Coverage: Geolocation, Elevation, Depth, Time</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('xmin', 'xmin: ') !!}
{!! Form::text('coverage[xmin]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.xmin']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('ymin', 'ymin: ') !!}
{!! Form::text('coverage[ymin]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.ymin']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('xmax', 'xmax: ') !!}
{!! Form::text('coverage[xmax]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.xmax']) !!}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('ymax', 'ymax: ') !!}
{!! Form::text('coverage[ymax]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.ymax']) !!}
</div>
@if (isset($dataset->elevation_absolut))
<div v-show="elevation === 'absolut'" class="pure-u-1 pure-u-md-1">
{!! Form::label('elevation_absolut', 'elevation absolut: ') !!}
{!! Form::text('coverage[elevation_absolut]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.elevation_absolut', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationAbsolut ? 'required|integer' : '' " ]) !!}
</div>
@elseif (isset($dataset->elevation_min) && isset($dataset->elevation_max))
<div v-show="elevation === 'range'" class="pure-u-1 pure-u-md-1">
{!! Form::label('elevation_min', 'elevation min: ') !!}
{!! Form::text('coverage[elevation_min]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.elevation_min', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationRange ? 'required|integer' : '' "]) !!}
</div>
<div v-show="elevation === 'range'" class="pure-u-1 pure-u-md-1">
{!! Form::label('elevation_max', 'elevation max: ') !!}
{!! Form::text('coverage[elevation_max]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.elevation_max', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationRange ? 'required|integer' : '' "]) !!}
</div>
@endif
@if (isset($dataset->depth_absolut))
<div v-show="elevation === 'absolut'" class="pure-u-1 pure-u-md-1">
{!! Form::label('depth_absolut', 'depth absolut: ') !!}
{!! Form::text('coverage[depth_absolut]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.depth_absolut', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationAbsolut ? 'required|integer' : '' " ]) !!}
</div>
@elseif (isset($dataset->elevation_min) && isset($dataset->elevation_max))
<div v-show="elevation === 'range'" class="pure-u-1 pure-u-md-1">
{!! Form::label('depth_min', 'depth min: ') !!}
{!! Form::text('coverage[depth_min]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.depth_min', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationRange ? 'required|integer' : '' "]) !!}
</div>
<div v-show="elevation === 'range'" class="pure-u-1 pure-u-md-1">
{!! Form::label('depth_max', 'depth max: ') !!}
{!! Form::text('coverage[depth_max]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.depth_max', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationRange ? 'required|integer' : '' "]) !!}
</div>
@endif
@if (isset($dataset->depth_absolut))
<div v-show="elevation === 'absolut'" class="pure-u-1 pure-u-md-1">
{!! Form::label('time_absolut', 'time absolut: ') !!}
{!! Form::text('coverage[time_absolut]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.time_absolut', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationAbsolut ? 'required|integer' : '' " ]) !!}
</div>
@elseif (isset($dataset->elevation_min) && isset($dataset->elevation_max))
<div v-show="elevation === 'range'" class="pure-u-1 pure-u-md-1">
{!! Form::label('time_min', 'time min: ') !!}
{!! Form::text('coverage[time_min]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.time_min', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationRange ? 'required|integer' : '' "]) !!}
</div>
<div v-show="elevation === 'range'" class="pure-u-1 pure-u-md-1">
{!! Form::label('time_max', 'time max: ') !!}
{!! Form::text('coverage[time_max]', null,
['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.time_max', 'data-vv-scope' => 'step-2', "v-validate" => "this.isElevationRange ? 'required|integer' : '' "]) !!}
</div>
@endif,
</div>
</fieldset>
<fieldset id="fieldset-titles">
<legend>Title</legend>
<div class="pure-g">
@ -56,9 +131,7 @@
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{{ Form::label('language', 'Language..') }}
<div class="select pure-u-23-24">
{{ Form::select('titles['.$title->id.'][language]', $languages, $title->language, ['placeholder' => '--no language--']) }}
</div>
{{ Form::text('titles['.$title->id.'][language]', $title->language, ['placeholder' => '--no language--', 'class' => 'pure-u-23-24', 'readonly']) }}
</div>
@endforeach
@ -77,9 +150,7 @@
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{{ Form::label('language', 'Language..') }}
<div class="select pure-u-23-24">
{{ Form::select('abstracts['.$abstract->id.'][language]', $languages, $abstract->language, ['placeholder' => '--no language--']) }}
</div>
{{ Form::text('abstracts['.$abstract->id.'][language]', $abstract->language, ['placeholder' => '--no language--', 'class' => 'pure-u-23-24', 'readonly']) }}
</div>
@endforeach