From 5193e4f5b5f52e129fe17bea7404ab4fa527fdbe Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Wed, 17 Apr 2019 16:01:38 +0200 Subject: [PATCH] code for review update --- .../Controllers/Publish/EditorController.php | 7 +- .../Controllers/Publish/ReviewController.php | 107 +++++++++++++++++- .../Controllers/Publish/SubmitController.php | 3 +- app/Library/Xml/DatasetExtension.php | 12 +- app/Library/Xml/Strategy.php | 31 +++++ app/Library/Xml/XmlModel.php | 2 +- public/backend/style.css | 9 +- public/web.config | 5 + .../views/workflow/editor/approve.blade.php | 2 +- .../views/workflow/editor/index.blade.php | 6 +- .../{accept.blade.php => receive.blade.php} | 12 +- .../views/workflow/review/index.blade.php | 2 +- .../views/workflow/review/review.blade.php | 77 +++++++++++++ .../views/workflow/submitter/index.blade.php | 4 +- routes/web.php | 20 +++- 15 files changed, 262 insertions(+), 37 deletions(-) rename resources/views/workflow/editor/{accept.blade.php => receive.blade.php} (90%) create mode 100644 resources/views/workflow/review/review.blade.php diff --git a/app/Http/Controllers/Publish/EditorController.php b/app/Http/Controllers/Publish/EditorController.php index 64538ce..56756c3 100644 --- a/app/Http/Controllers/Publish/EditorController.php +++ b/app/Http/Controllers/Publish/EditorController.php @@ -51,16 +51,16 @@ class EditorController extends Controller * @param int $id * @return \Illuminate\View\View */ - public function accept($id): View + public function receive($id): View { $dataset = Dataset::with('user:id,login')->findOrFail($id); - return view('workflow.editor.accept', [ + return view('workflow.editor.receive', [ 'dataset' => $dataset, ]); } - public function acceptUpdate(Request $request, $id) + public function receiveUpdate(Request $request, $id) { $dataset = Dataset::findOrFail($id); @@ -191,6 +191,7 @@ class EditorController extends Controller 'reviewers' => $reviewers, ]); } + public function approveUpdate(Request $request, $id) { // $dataset = Dataset::findOrFail($id); diff --git a/app/Http/Controllers/Publish/ReviewController.php b/app/Http/Controllers/Publish/ReviewController.php index 092def1..d47a747 100644 --- a/app/Http/Controllers/Publish/ReviewController.php +++ b/app/Http/Controllers/Publish/ReviewController.php @@ -32,6 +32,111 @@ class ReviewController extends Controller ->where('server_state', 'approved') ->where('reviewer_id', $userId) ->get(); - return view('workflow.review.index', compact('datasets')); + return view('workflow.review.index', [ + 'datasets' => $datasets + ]); + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\View\View + */ + public function review($id): View + { + $dataset = Dataset::with('user:id,login')->findOrFail($id); + $dataset->fetchValues(); + $fieldnames = $dataset->describe(); + $fields = []; + foreach ($fieldnames as $fieldName) { + $field = $dataset->getField($fieldName); + $modelClass = $field->getValueModelClass(); + $fieldValues = $field->getValue($fieldName); + $value = ""; + + if (null === $modelClass) { + $value = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', "\xEF\xBF\xBD ", $fieldValues); + } else { + // $fieldName = $field->getName(); + + + if (!is_array($fieldValues)) { + $fieldValues = array($fieldValues); + } + + foreach ($fieldValues as $fieldValue) { + // if a field has no value then is nothing more to do + // TODO maybe must be there an other solution + // FIXME remove code duplication (duplicates Opus_Model_Xml_Version*) + if (is_null($fieldValue)) { + continue; + } + + if ($fieldValue instanceof \Illuminate\Database\Eloquent\Model) { + //$this->_mapModelAttributes($value, $dom, $childNode); + $attributes = array_keys($fieldValue->getAttributes()); + foreach ($attributes as $property_name) { + $fieldName = self::convertColumnToFieldname($property_name); + // $field = new Field($fieldName); + $fieldval = $fieldValue->{$property_name}; + $value = $value . $fieldName . ": " . $fieldval . "; "; + } + } elseif ($fieldValue instanceof \Carbon\Carbon) { + $value = $value . " Year " . $fieldValue->year; + $value = $value . " Month " . $fieldValue->month; + $value = $value . " Day " . $fieldValue->day; + $value = $value . " Hour " . $fieldValue->hour; + $value = $value . " Minute " . $fieldValue->minute; + $value = $value . " Second " . $fieldValue->second; + $value = $value . " UnixTimestamp " . $fieldValue->timestamp; + $value = $value . " Timezone " . $fieldValue->tzName; + } elseif (is_array($fieldValue)) { + $attributes = $fieldValue; + $value = ""; + } + } + } + if ($value != "") { + $fields[$fieldName] = $value; + } + } + + return view('workflow.review.review', [ + 'dataset' => $dataset, + 'fields' => $fields + ]); + } + + + public function reviewUpdate(Request $request, $id) + { + $dataset = Dataset::findOrFail($id); + + + + $input = $request->all(); + $input['server_state'] = 'reviewed'; + + if ($dataset->update($input)) { + // event(new PageUpdated($page)); + return redirect() + ->route('publish.workflow.review.index') + ->with('flash_message', 'You have successfully reviewed one dataset!'); + } + throw new GeneralException(trans('exceptions.publish.review.update_error')); + } + + //snakeToCamel + public static function convertColumnToFieldname($columnname) + { + //return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $columnname)))); + return ucwords(str_replace(['-', '_'], ' ', $columnname)); } } diff --git a/app/Http/Controllers/Publish/SubmitController.php b/app/Http/Controllers/Publish/SubmitController.php index cb65de8..943c18d 100644 --- a/app/Http/Controllers/Publish/SubmitController.php +++ b/app/Http/Controllers/Publish/SubmitController.php @@ -25,7 +25,8 @@ class SubmitController extends Controller $builder = Dataset::query(); $myDatasets = $builder - ->whereIn('server_state', ['inprogress', 'released', 'editor_accepted', 'approved']) + ->orderBy('server_state') + ->whereIn('server_state', ['inprogress', 'released', 'editor_accepted', 'approved', 'reviewed']) ->where('account_id', $user_id) ->with('user:id,login') ->get(); diff --git a/app/Library/Xml/DatasetExtension.php b/app/Library/Xml/DatasetExtension.php index 2bc1f9a..50e68f0 100644 --- a/app/Library/Xml/DatasetExtension.php +++ b/app/Library/Xml/DatasetExtension.php @@ -43,7 +43,7 @@ trait DatasetExtension 'pivot' => array('role' => 'author'), //'sort_order' => array('sort_order' => 'ASC'), // <-- We need a sorted authors list. //'sort_field' => 'SortOrder', - 'relation' => 'authors', + 'relation' => 'persons', 'fetch' => 'eager' ), 'PersonContributor' => array( @@ -52,7 +52,7 @@ trait DatasetExtension 'pivot' => array('role' => 'contributor'), // 'sort_order' => array('sort_order' => 'ASC'), // <-- We need a sorted authors list. //'sort_field' => 'SortOrder', - 'relation' => 'contributors', + 'relation' => 'persons', 'fetch' => 'eager' ), 'Subject' => array( @@ -85,14 +85,9 @@ trait DatasetExtension { $fields = array( "Id", - "CompletedDate", "CompletedYear", "ContributingCorporation", "CreatingCorporation", - "ThesisDateAccepted", "ThesisYearAccepted", - "Edition", - "Issue", "Language", - "PageFirst", "PageLast", "PageNumber", "PublishedDate", "PublishedYear", "PublisherName", "PublisherPlace", "PublicationState", @@ -102,7 +97,6 @@ trait DatasetExtension "ServerDateDeleted", "ServerState", "Type", - "Volume", "BelongsToBibliography", "EmbargoDate" ); @@ -121,7 +115,7 @@ trait DatasetExtension // Initialize available date fields and set up date validator // if the particular field is present $dateFields = array( - 'ServerDateCreated', 'CompletedDate', 'PublishedDate', + 'ServerDateCreated', 'PublishedDate', 'ServerDateModified', 'ServerDatePublished', 'ServerDateDeleted', 'EmbargoDate' ); foreach ($dateFields as $fieldName) { diff --git a/app/Library/Xml/Strategy.php b/app/Library/Xml/Strategy.php index e244afd..624cac5 100644 --- a/app/Library/Xml/Strategy.php +++ b/app/Library/Xml/Strategy.php @@ -70,6 +70,37 @@ class Strategy return $this->_config->dom; } + public function getModelFieldValues(Dataset $model) + { + $fields = $model->describe(); + $excludeFields = $this->getConfig()->excludeFields; + if (count($excludeFields) > 0) { + $fieldsDiff = array_diff($fields, $excludeFields); + } else { + $fieldsDiff = $fields; + } + + foreach ($fieldsDiff as $fieldname) { + $field = $model->getField($fieldname); + $fieldValue = $this->getFieldValue($field); + } + } + + protected function getFieldValue(Field $field): string + { + $modelClass = $field->getValueModelClass(); + $fieldValues = $field->getValue(); + + if (null === $modelClass) { + $fieldName = $field->getName(); + $fieldValues = $this->getFieldValues($field); + + // Replace invalid XML-1.0-Characters by UTF-8 replacement character. + $fieldValues = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', "\xEF\xBF\xBD ", $fieldValues); + } + return fieldValues; + } + protected function _mapModel(Dataset $model, \DOMDocument $dom, \DOMNode $rootNode) { $fields = $model->describe(); diff --git a/app/Library/Xml/XmlModel.php b/app/Library/Xml/XmlModel.php index 976217f..186ab83 100644 --- a/app/Library/Xml/XmlModel.php +++ b/app/Library/Xml/XmlModel.php @@ -126,7 +126,7 @@ class XmlModel return $domDocument; } - //create xml: + //$domDocument == null -> create xml: $domDocument = $this->strategy->getDomDocument(); //if caching is not desired, return domDocument if (is_null($this->cache)) { diff --git a/public/backend/style.css b/public/backend/style.css index 5a50917..2347e4e 100644 --- a/public/backend/style.css +++ b/public/backend/style.css @@ -957,6 +957,10 @@ textarea.large, input.large { color: whitesmoke; } +.pure-table tr.reviewed { + padding: 0.8em; + background-color: #ffed4a; +} [v-cloak] > * { display:none; } [v-cloak]::before { content: "loading..."; } @@ -964,10 +968,13 @@ textarea.large, input.large { .help { display: block; - font-size: 0.75rem; + font-size: 12px; margin-top: 0.25rem; } .help.is-danger { color: #ff3860; } + .help.is-info { + color: #4dc0b5; + } \ No newline at end of file diff --git a/public/web.config b/public/web.config index 49a219f..13392d7 100644 --- a/public/web.config +++ b/public/web.config @@ -1,3 +1,8 @@ + diff --git a/resources/views/workflow/editor/approve.blade.php b/resources/views/workflow/editor/approve.blade.php index b9a463e..eb83960 100644 --- a/resources/views/workflow/editor/approve.blade.php +++ b/resources/views/workflow/editor/approve.blade.php @@ -38,7 +38,7 @@
diff --git a/resources/views/workflow/editor/index.blade.php b/resources/views/workflow/editor/index.blade.php index c8ae2ac..94a2aa0 100644 --- a/resources/views/workflow/editor/index.blade.php +++ b/resources/views/workflow/editor/index.blade.php @@ -52,14 +52,14 @@ @if ($dataset->server_state == "released") - + - Accept editor task + Receive editor task @elseif ($dataset->server_state == "editor_accepted") - Improve/Edit + Edit diff --git a/resources/views/workflow/editor/accept.blade.php b/resources/views/workflow/editor/receive.blade.php similarity index 90% rename from resources/views/workflow/editor/accept.blade.php rename to resources/views/workflow/editor/receive.blade.php index 5999c25..e61112b 100644 --- a/resources/views/workflow/editor/accept.blade.php +++ b/resources/views/workflow/editor/receive.blade.php @@ -2,13 +2,7 @@ @section('content')

- Accept released dataset -

-
- -
-

- Release your dataset for Editor + Receive released dataset

@@ -32,7 +26,7 @@ $message = 'If you are not the desired editor, you can still accept the dataset!!'; @endphp - {!! Form::model($dataset, [ 'method' => 'POST', 'route' => ['publish.workflow.acceptUpdate', $dataset->id], 'id' => 'acceptForm', + {!! Form::model($dataset, [ 'method' => 'POST', 'route' => ['publish.workflow.receiveUpdate', $dataset->id], 'id' => 'acceptForm', 'class' => 'pure-form', 'enctype' => 'multipart/form-data', 'v-on:submit.prevent' => 'checkForm']) !!}
General @@ -66,7 +60,7 @@
diff --git a/resources/views/workflow/review/index.blade.php b/resources/views/workflow/review/index.blade.php index 6ba0a7c..c4f7073 100644 --- a/resources/views/workflow/review/index.blade.php +++ b/resources/views/workflow/review/index.blade.php @@ -49,7 +49,7 @@ @if ($dataset->server_state == "approved") -
+ Review diff --git a/resources/views/workflow/review/review.blade.php b/resources/views/workflow/review/review.blade.php new file mode 100644 index 0000000..8e6bbca --- /dev/null +++ b/resources/views/workflow/review/review.blade.php @@ -0,0 +1,77 @@ +@extends('settings.layouts.app') +@section('content') +
+

+ Review approved dataset +

+
+ +
+ +
+ +
+ @php + // if ($dataset->editor->id == Auth::user()->id) { + // $userIsDesiredEditor = true; + // } else { + // $userIsDesiredEditor = false; + // $message = 'you are not the desired editor, but you can still accept the dataset'; + // } + $message = 'If you are not the desired editor, you can still accept the dataset!!'; + @endphp + + {!! Form::model($dataset, [ 'method' => 'POST', 'route' => ['publish.workflow.review.reviewUpdate', $dataset->id], 'id' => 'reviewForm', + 'class' => 'pure-form', 'enctype' => 'multipart/form-data', 'v-on:submit.prevent' => 'checkForm']) !!} +
+ Values +
+ + {{--
+ {!! Form::label('title', 'dataset title:') !!} + @if ($dataset->titles()->first()) + {{ $dataset->titles()->first()->value }} + @endif +
+
+ {!! Form::label('editor', 'editor:') !!} + {!! $dataset->editor->login !!} +
+
+ {!! Form::label('owner', 'dataset owner:') !!} + {!! $dataset->user->login !!} +
--}} + @foreach($fields as $field => $fieldValue) +
+ {{ Form::label($field, $field . ": ") }} + {!! $fieldValue !!} + +
+ @endforeach + +
+
+ +
+
+ +
+ + {!! Form::close() !!} +
+
+ +
+ +@stop + +@section('after-scripts') +@stop \ No newline at end of file diff --git a/resources/views/workflow/submitter/index.blade.php b/resources/views/workflow/submitter/index.blade.php index 1ecd2eb..9545ab3 100644 --- a/resources/views/workflow/submitter/index.blade.php +++ b/resources/views/workflow/submitter/index.blade.php @@ -31,7 +31,9 @@ $rowclass = 'editor_accepted'; } elseif ($dataset->server_state == 'approved') { $rowclass = 'approved'; - } + } elseif ($dataset->server_state == 'reviewed') { + $rowclass = 'reviewed'; + } @endphp diff --git a/routes/web.php b/routes/web.php index ad4d3fe..a289de8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -77,13 +77,13 @@ Route::group( 'middleware' => ['permission:dataset-editor-list'], 'as' => 'workflow.editor.index', 'uses' => 'EditorController@index', ]); - Route::get('workflow/accept/{id}', [ - 'middleware' => ['permission:dataset-accept'], - 'as' => 'workflow.accept', 'uses' => 'EditorController@accept', + Route::get('workflow/receive/{id}', [ + 'middleware' => ['permission:dataset-receive'], + 'as' => 'workflow.receive', 'uses' => 'EditorController@receive', ]); - Route::post('workflow/accept/{id}', [ - 'middleware' => ['permission:dataset-accept'], - 'as' => 'workflow.acceptUpdate', 'uses' => 'EditorController@acceptUpdate', + Route::post('workflow/receive/{id}', [ + 'middleware' => ['permission:dataset-receive'], + 'as' => 'workflow.receiveUpdate', 'uses' => 'EditorController@receiveUpdate', ]); Route::get('workflow/edit/{id}', [ 'middleware' => ['permission:dataset-editor-update'], @@ -107,6 +107,14 @@ Route::group( 'middleware' => ['permission:dataset-review-list'], 'as' => 'workflow.review.index', 'uses' => 'ReviewController@index', ]); + Route::get('workflow/review/{id}', [ + 'middleware' => ['permission:dataset-review'], + 'as' => 'workflow.review.review', 'uses' => 'ReviewController@review', + ]); + Route::post('workflow/review/{id}', [ + 'middleware' => ['permission:dataset-review'], + 'as' => 'workflow.review.reviewUpdate', 'uses' => 'ReviewController@reviewUpdate', + ]); Route::get('workflow/changestate/{id}/changestate/{targetState}', [ 'as' => 'review.changestate', 'uses' => 'SubmitController@changestate',