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 @@ -