workflow releasing datasets

This commit is contained in:
Arno Kaimbacher 2019-04-08 18:31:40 +02:00
parent ec127b9457
commit de80de9d88
18 changed files with 355 additions and 107 deletions

View File

@ -1,14 +1,19 @@
<?php
namespace App\Http\Controllers\Publish;
use App\Http\Controllers\Controller;
use App\Exceptions\GeneralException;
// use App\Http\Requests\ProjectRequest;
// use App\Models\Project;
// use Illuminate\Http\RedirectResponse;
// use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Dataset;
use Illuminate\View\View;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
class WorkflowController extends Controller
{
@ -17,34 +22,122 @@ class WorkflowController extends Controller
//$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function review()
{
$builder = Dataset::query();
$datasets = $builder
//->where('server_state', 'inprogress')
->whereIn('server_state', ['unpublished'])
->get();
return view('workflow.review', compact('datasets'));
}
public function release()
public function index(): View
{
$user = Auth::user();
$user_id = $user->id;
$builder = Dataset::query();
$datasets = $builder
->where('server_state', 'inprogress')
->where('account_id', $user_id)
->get();
return view('workflow.release', compact('datasets'));
$myDatasets = $builder
->whereIn('server_state', ['inprogress', 'released'])
->where('account_id', $user_id)
->with('user:id,login')
->get();
return view('workflow.index', [
'datasets' => $myDatasets,
]);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function release($id): View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
// $editors = User::whereHas('roles', function ($q) {
// $q->where('login', 'admin');
// })->pluck('login', 'id');
$editors = User::with(['roles' => function ($query) {
$query->where('name', 'reviewer');
}])
->pluck('login', 'id');
//$editors = Role::where('name', 'reviewer')->first()->users;
return view('workflow.release', [
'dataset' => $dataset,
'editors' => $editors,
]);
}
public function releaseUpdate(Request $request, $id)
{
$dataset = Dataset::findOrFail($id);
$input = $request->all();
$input['server_state'] = 'released';
if ($dataset->update($input)) {
// event(new PageUpdated($page));
return redirect()
->route('publish.workflow.index')
->with('flash_message', 'You have released your dataset!');
}
throw new GeneralException(trans('exceptions.publish.release.update_error'));
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function delete($id): RedirectResponse
{
$dataset = Dataset::with('files')->findOrFail($id);
if ($dataset->server_state != "inprogress") {
session()->flash(
'flash_message',
'You cannot delete this datastet!'
. ' There status of this dataset is '
. $dataset->server_state
. ' !'
);
return redirect()->route('settings.project');
} else {
if ($dataset->files->count() > 0) {
foreach ($dataset->files as $file) {
if (isset($file->path_name)) {
Storage::delete($file->path_name);
}
}
}
$dataset->delete();
session()->flash('flash_message', 'You have been deleted 1 dataset!');
return redirect()->route('publish.workflow.index');
}
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function indexReleased()
{
$builder = Dataset::query();
$datasets = $builder
//->where('server_state', 'inprogress')
->whereIn('server_state', ['released'])
->get();
return view('workflow.review', compact('datasets'));
}
// public function release()
// {
// $user = Auth::user();
// $user_id = $user->id;
// $builder = Dataset::query();
// $datasets = $builder
// ->where('server_state', 'inprogress')
// ->where('account_id', $user_id)
// ->get();
// return view('workflow.release', compact('datasets'));
// }
public function changestate($id, $targetState)
{
// $docId = $this->getRequest()->getParam('docId');
@ -64,7 +157,7 @@ class WorkflowController extends Controller
if ($targetState == 'published') {
//$this->_sendNotification($document, $form);
$time = new \Illuminate\Support\Carbon();
$dataset->server_date_published = $time;
$dataset->server_date_published = $time;
session()->flash('flash_message', 'You have puplished 1 dataset!');
}
$dataset->save();

View File

@ -36,6 +36,7 @@ class Dataset extends Model
'project_id',
'embargo_date',
'belongs_to_bibliography',
'editor_id'
];
//protected $guarded = [];
/**
@ -94,6 +95,14 @@ class Dataset extends Model
return $this->belongsTo(User::class, 'account_id', 'id');
}
/**
* Get the account that the dataset belongs to
*/
public function editor()
{
return $this->belongsTo(User::class, 'editor_id', 'id');
}
public function collections()
{
return $this

24
composer.lock generated
View File

@ -3183,20 +3183,20 @@
},
{
"name": "myclabs/deep-copy",
"version": "1.8.1",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8"
"reference": "78af75148f9fdd34ea727c8b529a9b4a8f7b740c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8",
"reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/78af75148f9fdd34ea727c8b529a9b4a8f7b740c",
"reference": "78af75148f9fdd34ea727c8b529a9b4a8f7b740c",
"shasum": ""
},
"require": {
"php": "^7.1"
"php": "^7.2"
},
"replace": {
"myclabs/deep-copy": "self.version"
@ -3204,6 +3204,8 @@
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/common": "^2.6",
"phpstan/phpstan": "^0.9.2",
"phpstan/phpstan-phpunit": "^0.9.4",
"phpunit/phpunit": "^7.1"
},
"type": "library",
@ -3227,7 +3229,7 @@
"object",
"object graph"
],
"time": "2018-06-11T23:09:50+00:00"
"time": "2018-10-30T00:14:44+00:00"
},
{
"name": "phar-io/manifest",
@ -4501,16 +4503,16 @@
},
{
"name": "theseer/tokenizer",
"version": "1.1.0",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/theseer/tokenizer.git",
"reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b"
"reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b",
"reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b",
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8",
"reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8",
"shasum": ""
},
"require": {
@ -4537,7 +4539,7 @@
}
],
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"time": "2017-04-07T12:08:54+00:00"
"time": "2019-04-04T09:56:43+00:00"
},
{
"name": "webmozart/assert",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -935,4 +935,23 @@ textarea.large, input.large {
cursor: pointer;
/* float: right; */
}
.pure-table tr.inprogress {
padding: 0.8em;
background-color: paleturquoise;
}
.pure-table tr.released {
background-color: greenyellow;
}
.help {
display: block;
font-size: 0.75rem;
margin-top: 0.25rem;
}
.help.is-danger {
color: #ff3860;
}

21
public/css/styles.css vendored
View File

@ -1259,24 +1259,3 @@ h2.post-title {
width: 10em;
margin: 0 1em 0 0;*/
}
/*.sidebar-simplesearch {
position: relative;
margin-bottom: 2.5em;
white-space: nowrap;
}
.sidebar-simplesearch input[type=text] {
padding: 0.25em 0.3em;
color: #666;
}*/
/*.sidebar-simplesearch button {
padding: 0.25em 0.3em;
border: none;
background: none;
position: absolute;
right: 0.25em;
color: #666;
}*/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
{
"/backend/publish/datasetPublish.js": "/backend/publish/datasetPublish.js",
"/backend/publish/releaseDataset.js": "/backend/publish/releaseDataset.js",
"/js/app.js": "/js/app.js",
"/js/lib.js": "/js/lib.js",
"/js/dataTable.js": "/js/dataTable.js"

View File

@ -0,0 +1,32 @@
// releaseDataset.js
import Vue from 'vue';
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);
const app = new Vue({
el: '#app1',
data() {
return {
dataset: {
firstName: '',
editor_id: ''
},
submitted: false
}
},
methods: {
checkForm(e) {
// Log entire model to console
// console.log(this.dataset);
this.submitted = true;
this.$validator.validate().then(result => {
if (result) {
console.log('From Submitted!');
document.getElementById("releaseForm").submit();
return;
}
});
}
}
});

View File

@ -12,6 +12,11 @@ return [
| found in a intuitive way.
|
*/
'publish' => [
'release' => [
'update_error' => 'There was a problem rleasing this dataset. Please try again.',
],
],
'backend' => [

View File

@ -95,12 +95,18 @@
<li class="pure-menu-item {{ Route::is('publish.dataset.create') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.dataset.create') }}"><i class="fa fa-upload"></i> Create</a>
</li>
<li class="pure-menu-item {{ Route::is('publish.workflow.release') ? 'active' : '' }}">
<li class="pure-menu-item {{ Route::is('publish.workflow.index') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.index') }}"><i class="fa fa-upload"></i> All my datasets</a>
</li>
<li class="pure-menu-item {{ Route::is('publish.workflow.indexreleased') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.indexReleased') }}"><i class="fa fa-upload"></i> All released datasets</a>
</li>
{{-- <li class="pure-menu-item {{ Route::is('publish.workflow.release') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.release') }}"><i class="fa fa-upload"></i> Release pending datasets</a>
</li>
<li class="pure-menu-item {{ Route::is('publish.workflow.review') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('publish.workflow.review') }}"><i class="fa fa-upload"></i> Review/Publish unpublished datasets</a>
</li>
</li> --}}
</ul>
</li>
@endpermission

View File

@ -53,8 +53,9 @@
<td>{{ $person->documents->count() }}</td>
<td>
<a class="edit" href="{{ route('settings.person.edit', $person->id) }}"><span>&nbsp;</span></a>
<a class="delete" href="{{ route('settings.person.delete', $person->id) }}"><span>&nbsp;</span></a>
@if($person->documents->count() == 0)
<a class="delete" href="{{ route('settings.person.delete', $person->id) }}"><span>&nbsp;</span></a>
@endif
</td>
</tr>

View File

@ -0,0 +1,70 @@
@extends('settings.layouts.app')
@section('content')
<div class="header">
<h3 class="header-title">
<i class="fa fa-file"></i> Release saved datasets
</h3>
</div>
<div class="pure-g box-content">
<div class="pure-u-1">
<table class="pure-table pure-table-horizontal">
<thead>
<th>Dataset Title</th>
<th>Owner</th>
<th>Server State</th>
<th></th>
</thead>
<tbody>
@foreach($datasets as $dataset)
@php
//if userid changed from last iteration, store new userid and change color
// $lastid = $detail->payment->userid;
if ($dataset->server_state == 'inprogress') {
$rowclass = 'inprogress';
} elseif ($dataset->server_state == 'released') {
$rowclass = 'released';
}
@endphp
<tr class="{{ $rowclass }}">
<td>
@if ($dataset->titles()->first())
{{ $dataset->titles()->first()->value }}
@else
no title
@endif
</td>
<td>
{{ $dataset->user->login }}
</td>
{{-- <td>
{{ optional($dataset->editor)->login }}
</td> --}}
<td>
{{ $dataset->server_state }}
</td>
<td>
@if ($dataset->server_state == "inprogress")
<a href="{{ URL::route('publish.workflow.release', $dataset->id) }}" class="pure-button">
<i class="fa fa-share"></i>
<span>Release</span>
</a>
<a href="{{ URL::route('publish.workflow.delete', $dataset->id) }}" class="pure-button">
<i class="fa fa-trash"></i>
<span>Delete</span>
</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@stop

View File

@ -2,50 +2,65 @@
@section('content')
<div class="header">
<h3 class="header-title">
<i class="fa fa-file"></i> Release saved datasets
<i class="fa fa-share"></i> Release saved datasets
</h3>
</div>
<div class="pure-g box-content">
<div class="pure-u-1">
<table class="pure-table pure-table-horizontal">
<thead>
<th>Dataset Title</th>
<th>ID</th>
<th>Server State</th>
<th></th>
</thead>
<tbody>
@foreach($datasets as $dataset)
<tr>
<td>
@if ($dataset->titles()->first())
{{ $dataset->titles()->first()->value }}
@else
no title
@endif
</td>
<td>
{{ $dataset->id }}
</td>
<td>
{{ $dataset->server_state }}
</td>
<td>
@if ($dataset->server_state == "inprogress")
<a href="{{ URL::route('publish.review.changestate',['id' => $dataset->id, 'targetState' => 'unpublished']) }}" class="pure-button button-small is-success">Release</a>
{{-- <a href="" class="pure-button button-small is-success">Restrict</a> --}}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="header">
<h3 class="header-title">
Release your dataset for Editor
</h3>
</div>
<div class="pure-g box-content">
<div class="pure-u-1 pure-u-md-1">
<div>
<a href="{{ route('publish.workflow.index') }}" class="pure-button button-small">
<i class="fa fa-chevron-left"></i>
<span>BACK</span>
</a>
</div>
<div id="app1">
{!! Form::model($dataset, [ 'method' => 'POST', 'route' => ['publish.workflow.releaseUpdate', $dataset->id], 'id' => 'releaseForm',
'class' => 'pure-form', 'enctype' => 'multipart/form-data', 'v-on:submit.prevent' => 'checkForm']) !!}
<fieldset id="fieldset-General">
<legend>General</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('editor_id', 'preferred editor:') !!}
<div class="select pure-u-23-24">
{!! Form::select('editor_id', $editors, null, ['id' => 'editor_id', 'placeholder' => '-- select editor --', 'v-model' =>
'dataset.editor_id', "v-validate" => "'required'"]) !!}
</div>
<span class="help is-danger" v-if="errors.has('editor_id')" v-text="errors.first('editor_id')"></span>
</div>
</div>
</fieldset>
<br />
<div class="pure-controls">
<button :disabled="errors.any()" type="submit" class="pure-button">
<i class="fa fa-share"></i>
<span>Release</span>
</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@stop
@section('after-scripts') {{--
<script type="text/javascript" src="{{ asset('js/lib.js') }}"></script> --}} {{--
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>--}} {{--
<script type="text/javascript" src="{{ resource_path('assets\js\datasetPublish.js') }}"></script> --}}
<script type="text/javascript" src="{{ asset('backend/publish/releaseDataset.js') }}"></script>
@stop

View File

@ -46,12 +46,27 @@ Route::group(
// Route::get('dataset/create-step3', ['as' => 'dataset.create3', 'uses' => 'IndexController@createStep3']);
Route::post('dataset/store', ['as' => 'dataset.store', 'uses' => 'IndexController@store']);
Route::get('workflow/review', [
'as' => 'workflow.review', 'uses' => 'WorkflowController@review',
Route::get('workflow/index', [
'as' => 'workflow.index', 'uses' => 'WorkflowController@index',
]);
Route::get('workflow/release', [
Route::get('workflow/release/{id}', [
'as' => 'workflow.release', 'uses' => 'WorkflowController@release',
]);
Route::post('workflow/release/{id}', [
'as' => 'workflow.releaseUpdate', 'uses' => 'WorkflowController@releaseUpdate',
]);
Route::get('workflow/delete/{id}', [
'as' => 'workflow.delete', 'uses' => 'WorkflowController@delete',
]);
Route::get('workflow/release/{id}', [
'as' => 'workflow.release', 'uses' => 'WorkflowController@release',
]);
Route::get('workflow/indexreleased', [
'as' => 'workflow.indexReleased', 'uses' => 'WorkflowController@indexReleased',
]);
Route::get('workflow/changestate/{id}/changestate/{targetState}', [
'as' => 'review.changestate', 'uses' => 'WorkflowController@changestate',
]);
@ -129,7 +144,6 @@ Route::group(
]);
// //For DataTables
Route::get('pages/get', ['uses' => 'PagesTableController@get'])->name('page.get');
}
);

View File

@ -17,6 +17,7 @@ let mix = require('laravel-mix');
mix.js('resources/assets/js/datasetPublish.js', 'public/backend/publish')
.js('resources/assets/js/app.js', 'public/js')
.js('resources/assets/js/lib.js', 'public/js')
.js('resources/assets/js/releaseDataset.js', 'public/backend/publish')
.scripts([
'node_modules/datatables.net/js/jquery.dataTables.js',
'node_modules/datatables.net-buttons/js/dataTables.buttons.js',