add workflow actions for manipulating server_state

This commit is contained in:
Arno Kaimbacher 2019-02-21 14:07:00 +01:00
parent b7b04a61d6
commit c86c9fe9f4
14 changed files with 141 additions and 24 deletions

View File

@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Validator;
use App\Models\DatasetReference; use App\Models\DatasetReference;
use App\Models\GeolocationBox; use App\Models\GeolocationBox;
use App\Models\Page; use App\Models\Page;
use Illuminate\Support\Facades\Auth;
class IndexController extends Controller class IndexController extends Controller
{ {
@ -277,7 +278,11 @@ class IndexController extends Controller
$input = $request->except('files', 'licenses', 'abstract_main', 'title_main', 'references', 'titles'); $input = $request->except('files', 'licenses', 'abstract_main', 'title_main', 'references', 'titles');
// array_push($input, "Himbeere"); // array_push($input, "Himbeere");
// $input += ['server_state' => 'created' ]; // $input += ['server_state' => 'created' ];
$input['server_state'] = 'unpublished'; if (isset($data['server_state'])) {
$input['server_state'] = $data['server_state'];
} else {
$input['server_state'] = 'inprogress';
}
$dataset = new Dataset($input); $dataset = new Dataset($input);
DB::beginTransaction(); //Start transaction! DB::beginTransaction(); //Start transaction!
@ -398,6 +403,10 @@ class IndexController extends Controller
} }
} }
// Create relation between Dataset and actual User.
$user = Auth::user();
$dataset->user()->associate($user)->save();
// $error = 'Always throw this error'; // $error = 'Always throw this error';
// throw new \Exception($error); // throw new \Exception($error);

View File

@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
// use Illuminate\Http\Request; // use Illuminate\Http\Request;
use App\Models\Dataset; use App\Models\Dataset;
use Illuminate\View\View; use Illuminate\View\View;
use Illuminate\Support\Facades\Auth;
class WorkflowController extends Controller class WorkflowController extends Controller
{ {
@ -21,14 +22,27 @@ class WorkflowController extends Controller
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function index() public function review()
{ {
$builder = Dataset::query(); $builder = Dataset::query();
$datasets = $builder $datasets = $builder
//->where('server_state', 'inprogress') //->where('server_state', 'inprogress')
->whereIn('server_state', ['unpublished']) ->whereIn('server_state', ['unpublished'])
->get(); ->get();
return view('workflow.index', compact('datasets')); 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) public function changestate($id, $targetState)
@ -51,10 +65,11 @@ class WorkflowController extends Controller
//$this->_sendNotification($document, $form); //$this->_sendNotification($document, $form);
$time = new \Illuminate\Support\Carbon(); $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(); $dataset->save();
session()->flash('flash_message', 'You have puplished 1 dataset!'); return redirect()->back();
return redirect()->route('settings.review.index'); //return redirect()->route('settings.review.index');
} catch (Exception $e) { } catch (Exception $e) {
//return $this->_redirectTo('index', array('failure' => $e->getMessage()), 'documents', 'admin'); //return $this->_redirectTo('index', array('failure' => $e->getMessage()), 'documents', 'admin');
} }

View File

@ -5,6 +5,7 @@ namespace App\Models;
use App\Library\Xml\DatasetExtension; use App\Library\Xml\DatasetExtension;
use App\Models\Collection; use App\Models\Collection;
use App\Models\License; use App\Models\License;
use App\Models\User;
use App\Models\Project; use App\Models\Project;
use App\Models\Description; use App\Models\Description;
use App\Models\Title; use App\Models\Title;
@ -78,6 +79,14 @@ class Dataset extends Model
return $this->belongsTo(Project::class, 'project_id', 'id'); return $this->belongsTo(Project::class, 'project_id', 'id');
} }
/**
* Get the account that the dataset belongs to
*/
public function user()
{
return $this->belongsTo(User::class, 'account_id', 'id');
}
public function collections() public function collections()
{ {
return $this return $this

View File

@ -7,6 +7,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait; use Zizaco\Entrust\Traits\EntrustUserTrait;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use App\Models\Dataset;
class User extends Authenticatable class User extends Authenticatable
{ {
@ -39,6 +40,12 @@ class User extends Authenticatable
*/ */
protected $hidden = ['password', 'remember_token']; protected $hidden = ['password', 'remember_token'];
public function datasets()
{
//model, foreign key on the User model is account_id, local id of user
return $this->hasMany(Dataset::class, 'account_id', 'id');
}
public function setPasswordAttribute($password) public function setPasswordAttribute($password)
{ {
if ($password) { if ($password) {
@ -46,6 +53,7 @@ class User extends Authenticatable
} }
} }
public function getAvatarUrl() public function getAvatarUrl()
{ {
return "https://www.gravatar.com/avatar/" . md5($this->email) . "?d=mm"; return "https://www.gravatar.com/avatar/" . md5($this->email) . "?d=mm";

12
composer.lock generated
View File

@ -3566,16 +3566,16 @@
}, },
{ {
"name": "phpunit/php-timer", "name": "phpunit/php-timer",
"version": "2.0.0", "version": "2.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git", "url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059",
"reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3587,7 +3587,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.0-dev" "dev-master": "2.1-dev"
} }
}, },
"autoload": { "autoload": {
@ -3611,7 +3611,7 @@
"keywords": [ "keywords": [
"timer" "timer"
], ],
"time": "2018-02-01T13:07:23+00:00" "time": "2019-02-20T10:12:59+00:00"
}, },
{ {
"name": "phpunit/php-token-stream", "name": "phpunit/php-token-stream",

View File

@ -15,7 +15,7 @@ class CreateDocumentsTable extends Migration
Schema::create('documents', function (Blueprint $table) { Schema::create('documents', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('type', 100); $table->string('type', 100);
$table->string('publication_state', 100)->default('draft');; $table->string('publication_state', 100)->default('draft');
$table->boolean('belongs_to_bibliography')->default('0'); $table->boolean('belongs_to_bibliography')->default('0');
$table->timestamps(); $table->timestamps();
}); });

File diff suppressed because one or more lines are too long

View File

@ -337,9 +337,22 @@
<xsl:apply-templates select="@Language" mode="oai_dc" /> <xsl:apply-templates select="@Language" mode="oai_dc" />
<!-- dc:rights --> <!-- dc:rights -->
<xsl:apply-templates select="Licence" mode="oai_dc" /> <xsl:apply-templates select="Licence" mode="oai_dc" />
<!-- dc:coverage -->
<xsl:apply-templates select="GeolocationBox" mode="oai_dc" />
</oai_dc:dc> </oai_dc:dc>
</xsl:template> </xsl:template>
<xsl:template match="GeolocationBox" mode="oai_dc">
<dc:coverage>
<xsl:value-of select="concat(
'SOUTH-BOUND LATITUDE: ', @Xmin,
' * WEST-BOUND LONGITUDE: ', @Ymin,
' * NORTH-BOUND LATITUDE: ', @Xmax,
' * EAST-BOUND LONGITUDE: ', @Ymax
)" />
</dc:coverage>
</xsl:template>
<xsl:template match="TitleMain" mode="oai_dc"> <xsl:template match="TitleMain" mode="oai_dc">
<dc:title> <dc:title>
<xsl:value-of select="@Value"/> <xsl:value-of select="@Value"/>

View File

@ -152,7 +152,7 @@ const app = new Vue({
this.currentStatus = STATUS_INITIAL; this.currentStatus = STATUS_INITIAL;
this.dataset.files = []; this.dataset.files = [];
}, },
save() { save(status) {
// upload data to the server // upload data to the server
var _this = this; var _this = this;
this.currentStatus = STATUS_SAVING; this.currentStatus = STATUS_SAVING;
@ -177,6 +177,7 @@ const app = new Vue({
/* /*
Additional POST Data Additional POST Data
*/ */
formData.append('server_state', status);
formData.append('type', this.dataset.type); formData.append('type', this.dataset.type);
// formData.append('server_state', this.dataset.state); // formData.append('server_state', this.dataset.state);
formData.append('rights', Number(this.dataset.rights)); formData.append('rights', Number(this.dataset.rights));
@ -395,10 +396,10 @@ const app = new Vue({
} }
return true; return true;
}, },
submit() { submit(status) {
// alert('Submit to blah and show blah and etc.'); // alert('Submit to blah and show blah and etc.');
// save it // save it
this.save(); this.save(status);
} }
} }
}); });

View File

@ -487,9 +487,13 @@
<i class="fa fa-arrow-left"></i> <i class="fa fa-arrow-left"></i>
<span>Zurück</span> <span>Zurück</span>
</button> </button>
<button @click.prevent="submit()" class="pure-button button-small"> <button @click.prevent="submit('inprogress')" class="pure-button button-small">
<i class="fa fa-save"></i> <i class="fa fa-save"></i>
<span>Create Dataset</span> <span>Save Dataset</span>
</button>
<button @click.prevent="submit('unpublished')" class="pure-button button-small">
<i class="fa fa-upload"></i>
<span>Release Dataset</span>
</button> </button>
</div> </div>

View File

@ -95,8 +95,11 @@
<li class="pure-menu-item {{ Route::is('publish.dataset.create') ? 'active' : '' }}"> <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> <a class="pure-menu-link" href="{{ URL::route('publish.dataset.create') }}"><i class="fa fa-upload"></i> Create</a>
</li> </li>
<li class="pure-menu-item {{ Route::is('settings.review') ? 'active' : '' }}"> <li class="pure-menu-item {{ Route::is('settings.workflow.release') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('settings.review.index') }}"><i class="fa fa-upload"></i> Release unpublished datasets</a> <a class="pure-menu-link" href="{{ URL::route('settings.workflow.release') }}"><i class="fa fa-upload"></i> Release pending datasets</a>
</li>
<li class="pure-menu-item {{ Route::is('settings.workflow.review') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ URL::route('settings.workflow.review') }}"><i class="fa fa-upload"></i> Review/Publish unpublished datasets</a>
</li> </li>
</ul> </ul>
</li> </li>

View File

@ -0,0 +1,51 @@
@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>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('settings.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>
@stop

View File

@ -2,7 +2,7 @@
@section('content') @section('content')
<div class="header"> <div class="header">
<h3 class="header-title"> <h3 class="header-title">
<i class="fa fa-file"></i> Datasets to be processed <i class="fa fa-file"></i> Review unpblished datasets
</h3> </h3>
</div> </div>
@ -14,6 +14,7 @@
<th>Dataset Title</th> <th>Dataset Title</th>
<th>ID</th> <th>ID</th>
<th>Server State</th> <th>Server State</th>
<th></th>
</thead> </thead>
<tbody> <tbody>

View File

@ -120,10 +120,13 @@ Route::group(
// //For DataTables // //For DataTables
Route::get('pages/get', ['uses' => 'PagesTableController@get'])->name('page.get'); Route::get('pages/get', ['uses' => 'PagesTableController@get'])->name('page.get');
Route::get('review', [ Route::get('workflow/review', [
'as' => 'review.index', 'uses' => 'WorkflowController@index', 'as' => 'workflow.review', 'uses' => 'WorkflowController@review',
]); ]);
Route::get('review/changestate/{id}/changestate/{targetState}', [ Route::get('workflow/release', [
'as' => 'workflow.release', 'uses' => 'WorkflowController@release',
]);
Route::get('workflow/changestate/{id}/changestate/{targetState}', [
'as' => 'review.changestate', 'uses' => 'WorkflowController@changestate', 'as' => 'review.changestate', 'uses' => 'WorkflowController@changestate',
]); ]);
} }