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\Support\Facades\Auth;
use Illuminate\View\View; use Illuminate\View\View;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
// use App\Models\Coverage;
use Illuminate\Support\Facades\Validator;
class EditorController extends Controller class EditorController extends Controller
{ {
@ -87,7 +89,7 @@ class EditorController extends Controller
public function edit($id): View public function edit($id): View
{ {
$dataset = Dataset::findOrFail($id); $dataset = Dataset::findOrFail($id);
$dataset->load('licenses', 'titles', 'abstracts', 'files'); $dataset->load('licenses', 'titles', 'abstracts', 'files', 'coverage');
$projects = Project::pluck('label', 'id'); $projects = Project::pluck('label', 'id');
@ -123,53 +125,86 @@ class EditorController extends Controller
*/ */
public function update(DocumentRequest $request, $id): RedirectResponse public function update(DocumentRequest $request, $id): RedirectResponse
{ {
$dataset = Dataset::findOrFail($id); $rules = [
//$input = $request->all(); 'type' => 'required|min:5',
$input = $request->except('abstracts', 'licenses', 'titles', '_method', '_token'); 'coverage.xmin' => [
// foreach ($input as $key => $value) { 'nullable',
// $dataset[$key] = $value; 'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'
// } ],
//$dataset->update($input); 'coverage.ymin' => [
// $dataset->type = $input['type']; 'nullable',
// $dataset->thesis_year_accepted = $input['thesis_year_accepted']; 'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'
// $dataset->project_id = $input['project_id']; ],
// $dataset->save(); '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);
$data = $request->all();
$input = $request->except('abstracts', 'licenses', 'titles', 'coverage', '_method', '_token');
$licenses = $request->input('licenses');
//$licenses = $input['licenses'];
$dataset->licenses()->sync($licenses);
$licenses = $request->input('licenses'); //save the titles:
//$licenses = $input['licenses']; $titles = $request->input('titles');
$dataset->licenses()->sync($licenses); if (is_array($titles) && count($titles) > 0) {
foreach ($titles as $key => $formTitle) {
$title = Title::findOrFail($key);
$title->value = $formTitle['value'];
$title->language = $formTitle['language'];
$title->save();
}
}
//save the titles: //save the abstracts:
$titles = $request->input('titles'); $abstracts = $request->input('abstracts');
if (is_array($titles) && count($titles) > 0) { if (is_array($abstracts) && count($abstracts) > 0) {
foreach ($titles as $key => $formTitle) { foreach ($abstracts as $key => $formAbstract) {
$title = Title::findOrFail($key); $abstract = Description::findOrFail($key);
$title->value = $formTitle['value']; $abstract->value = $formAbstract['value'];
$title->language = $formTitle['language']; $abstract->language = $formAbstract['language'];
$title->save(); $abstract->save();
}
}
// 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);
}
// $dataset->save();
if ($dataset->update($input)) {
//event(new DatasetUpdated($dataset));
session()->flash('flash_message', 'You have updated 1 dataset!');
return redirect()->route('publish.workflow.editor.index');
} }
} }
else {
//save the abstracts: //TODO Handle validation error
$abstracts = $request->input('abstracts'); //pass validator errors as errors object for ajax response
if (is_array($abstracts) && count($abstracts) > 0) { // return response()->json([
foreach ($abstracts as $key => $formAbstract) { // 'success' => false,
$abstract = Description::findOrFail($key); // 'errors' => $validator->errors()->all(),
$abstract->value = $formAbstract['value']; // ], 422);
$abstract->language = $formAbstract['language']; return back()
$abstract->save(); ->withErrors($validator->errors()->all());
}
}
if (!$dataset->isDirty(dataset::UPDATED_AT)) {
$time = new \Illuminate\Support\Carbon();
$dataset->setUpdatedAt($time);
}
// $dataset->save();
if ($dataset->update($input)) {
//event(new DatasetUpdated($dataset));
session()->flash('flash_message', 'You have updated 1 dataset!');
return redirect()->route('publish.workflow.editor.index');
} }
throw new GeneralException(trans('exceptions.backend.dataset.update_error')); throw new GeneralException(trans('exceptions.backend.dataset.update_error'));
} }

View File

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

10
composer.lock generated
View File

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

View File

@ -9,20 +9,6 @@
</div> </div>
</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"> <div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('project_id', 'Project..') !!} {!! Form::label('project_id', 'Project..') !!}
<div class="select pure-u-23-24"> <div class="select pure-u-23-24">
@ -31,10 +17,19 @@
<small id="projectHelp" class="pure-form-message-inline">project is optional</small> <small id="projectHelp" class="pure-form-message-inline">project is optional</small>
</div> </div>
{{-- <div class="pure-control-group"> <div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('shelf_id', 'Shelf..') !!} {!! Form::label('server_state', 'Status..') !!}
{!! Form::select('shelf_id', $shelves, null, ['id' => 'shelf_id']) !!} {{-- {!! Form::select('server_state', Config::get('enums.server_states'), null, ['id' => 'server_state', 'placeholder' => '-- select server state --']) !!} --}}
</div> --}} {!! 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"> <div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('embargo_date', 'Embargo Date') !!} {!! Form::label('embargo_date', 'Embargo Date') !!}
@ -44,6 +39,86 @@
</div> </div>
</fieldset> </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"> <fieldset id="fieldset-titles">
<legend>Title</legend> <legend>Title</legend>
<div class="pure-g"> <div class="pure-g">
@ -55,10 +130,8 @@
{{ Form::text('titles['.$title->id.'][value]', $title->value, ['class' => 'pure-u-23-24']) }} {{ Form::text('titles['.$title->id.'][value]', $title->value, ['class' => 'pure-u-23-24']) }}
</div> </div>
<div class="pure-u-1 pure-u-md-1-2 pure-div"> <div class="pure-u-1 pure-u-md-1-2 pure-div">
{{ Form::label('language', 'Language..') }} {{ Form::label('language', 'Language..') }}
<div class="select pure-u-23-24"> {{ Form::text('titles['.$title->id.'][language]', $title->language, ['placeholder' => '--no language--', 'class' => 'pure-u-23-24', 'readonly']) }}
{{ Form::select('titles['.$title->id.'][language]', $languages, $title->language, ['placeholder' => '--no language--']) }}
</div>
</div> </div>
@endforeach @endforeach
@ -76,10 +149,8 @@
{{ Form::textarea('abstracts['.$abstract->id.'][value]', $abstract->value, ['class' => 'pure-u-23-24', 'size' => '70x6']) }} {{ Form::textarea('abstracts['.$abstract->id.'][value]', $abstract->value, ['class' => 'pure-u-23-24', 'size' => '70x6']) }}
</div> </div>
<div class="pure-u-1 pure-u-md-1-2 pure-div"> <div class="pure-u-1 pure-u-md-1-2 pure-div">
{{ Form::label('language', 'Language..') }} {{ Form::label('language', 'Language..') }}
<div class="select pure-u-23-24"> {{ Form::text('abstracts['.$abstract->id.'][language]', $abstract->language, ['placeholder' => '--no language--', 'class' => 'pure-u-23-24', 'readonly']) }}
{{ Form::select('abstracts['.$abstract->id.'][language]', $languages, $abstract->language, ['placeholder' => '--no language--']) }}
</div>
</div> </div>
@endforeach @endforeach