From 4c4c0760d8cb28663d6e092222256e691af7da62 Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Mon, 27 May 2019 18:52:44 +0200 Subject: [PATCH] edit page for editor: - fields for coverage --- .../Controllers/Publish/EditorController.php | 123 +++++++++++------- .../Controllers/Publish/IndexController.php | 8 +- composer.lock | 10 +- .../views/workflow/editor/_form.blade.php | 123 ++++++++++++++---- 4 files changed, 185 insertions(+), 79 deletions(-) diff --git a/app/Http/Controllers/Publish/EditorController.php b/app/Http/Controllers/Publish/EditorController.php index 847d0ab..ad41744 100644 --- a/app/Http/Controllers/Publish/EditorController.php +++ b/app/Http/Controllers/Publish/EditorController.php @@ -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,53 +125,86 @@ class EditorController extends Controller */ public function update(DocumentRequest $request, $id): RedirectResponse { - $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(); + $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); + $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'); - //$licenses = $input['licenses']; - $dataset->licenses()->sync($licenses); + //save the titles: + $titles = $request->input('titles'); + 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: - $titles = $request->input('titles'); - 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 abstracts: + $abstracts = $request->input('abstracts'); + if (is_array($abstracts) && count($abstracts) > 0) { + foreach ($abstracts as $key => $formAbstract) { + $abstract = Description::findOrFail($key); + $abstract->value = $formAbstract['value']; + $abstract->language = $formAbstract['language']; + $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'); } } - - //save the abstracts: - $abstracts = $request->input('abstracts'); - if (is_array($abstracts) && count($abstracts) > 0) { - foreach ($abstracts as $key => $formAbstract) { - $abstract = Description::findOrFail($key); - $abstract->value = $formAbstract['value']; - $abstract->language = $formAbstract['language']; - $abstract->save(); - } - } - - 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 { + //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')); } diff --git a/app/Http/Controllers/Publish/IndexController.php b/app/Http/Controllers/Publish/IndexController.php index f665bc9..aaa33e0 100644 --- a/app/Http/Controllers/Publish/IndexController.php +++ b/app/Http/Controllers/Publish/IndexController.php @@ -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+)?)$/' ], diff --git a/composer.lock b/composer.lock index 37017b7..6794f17 100755 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/resources/views/workflow/editor/_form.blade.php b/resources/views/workflow/editor/_form.blade.php index baceaf6..0194723 100644 --- a/resources/views/workflow/editor/_form.blade.php +++ b/resources/views/workflow/editor/_form.blade.php @@ -9,20 +9,6 @@ -
- {!! 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']) !!} - -
- -
- {!! 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']) !!} - -
-
{!! Form::label('project_id', 'Project..') !!}
@@ -31,10 +17,19 @@ project is optional
- {{--
- {!! Form::label('shelf_id', 'Shelf..') !!} - {!! Form::select('shelf_id', $shelves, null, ['id' => 'shelf_id']) !!} -
--}} +
+ {!! 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']) !!} + +
+ +
+ {!! 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']) !!} + +
{!! Form::label('embargo_date', 'Embargo Date') !!} @@ -44,6 +39,86 @@
+
+ Coverage: Geolocation, Elevation, Depth, Time +
+
+ {!! Form::label('xmin', 'xmin: ') !!} + {!! Form::text('coverage[xmin]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.xmin']) !!} +
+
+ {!! Form::label('ymin', 'ymin: ') !!} + {!! Form::text('coverage[ymin]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.ymin']) !!} +
+ +
+ {!! Form::label('xmax', 'xmax: ') !!} + {!! Form::text('coverage[xmax]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.xmax']) !!} +
+
+ {!! Form::label('ymax', 'ymax: ') !!} + {!! Form::text('coverage[ymax]', null, ['class' => 'pure-u-23-24', 'v-model' => 'dataset.coverage.ymax']) !!} +
+ + @if (isset($dataset->elevation_absolut)) +
+ {!! 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' : '' " ]) !!} +
+ @elseif (isset($dataset->elevation_min) && isset($dataset->elevation_max)) +
+ {!! 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' : '' "]) !!} +
+
+ {!! 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' : '' "]) !!} +
+ @endif + + @if (isset($dataset->depth_absolut)) +
+ {!! 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' : '' " ]) !!} +
+ @elseif (isset($dataset->elevation_min) && isset($dataset->elevation_max)) +
+ {!! 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' : '' "]) !!} +
+
+ {!! 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' : '' "]) !!} +
+ @endif + + @if (isset($dataset->depth_absolut)) +
+ {!! 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' : '' " ]) !!} +
+ @elseif (isset($dataset->elevation_min) && isset($dataset->elevation_max)) +
+ {!! 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' : '' "]) !!} +
+
+ {!! 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' : '' "]) !!} +
+ @endif, +
+
+
Title
@@ -55,10 +130,8 @@ {{ Form::text('titles['.$title->id.'][value]', $title->value, ['class' => 'pure-u-23-24']) }}
- {{ Form::label('language', 'Language..') }} -
- {{ Form::select('titles['.$title->id.'][language]', $languages, $title->language, ['placeholder' => '--no language--']) }} -
+ {{ Form::label('language', 'Language..') }} + {{ Form::text('titles['.$title->id.'][language]', $title->language, ['placeholder' => '--no language--', 'class' => 'pure-u-23-24', 'readonly']) }}
@endforeach @@ -76,10 +149,8 @@ {{ Form::textarea('abstracts['.$abstract->id.'][value]', $abstract->value, ['class' => 'pure-u-23-24', 'size' => '70x6']) }}
- {{ Form::label('language', 'Language..') }} -
- {{ Form::select('abstracts['.$abstract->id.'][language]', $languages, $abstract->language, ['placeholder' => '--no language--']) }} -
+ {{ Form::label('language', 'Language..') }} + {{ Form::text('abstracts['.$abstract->id.'][language]', $abstract->language, ['placeholder' => '--no language--', 'class' => 'pure-u-23-24', 'readonly']) }}
@endforeach