add references and submitters

This commit is contained in:
Arno Kaimbacher 2018-10-29 14:24:41 +01:00
parent 14878a20c8
commit d788410cb5
6 changed files with 166 additions and 31 deletions

View File

@ -16,6 +16,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use App\Models\DatasetReference;
class IndexController extends Controller
{
@ -51,8 +52,11 @@ class IndexController extends Controller
// $persons = Person::where('status', 1)
// ->pluck('last_name', 'id');
$projects = Project::pluck('label', 'id');
$types = array('doi' => 'doi', 'handle' => 'handle', 'urn' => 'urn', 'std-doi' => 'std-doi',
'url' => 'url', 'isbn' => 'isbn', 'issn' => 'issn', 'rdr-id' => 'rdr-id');
$relations = array('updates' => 'updates', 'updated-by' => 'updated-by', 'other' => 'other');
return view('publish.create-step1', compact('licenses', 'languages', 'projects'));
return view('publish.create-step1', compact('licenses', 'languages', 'projects', 'types', 'relations'));
}
/**
@ -240,7 +244,7 @@ class IndexController extends Controller
if ($validator->passes()) {
//store dataset todo
//$data = $request->all();
$input = $request->except('files', 'licenses', 'abstract_main', 'title_main');
$input = $request->except('files', 'licenses', 'abstract_main', 'title_main', 'references');
// array_push($input, "Himbeere");
$dataset = new Dataset($input);
@ -280,6 +284,7 @@ class IndexController extends Controller
$dataset->licenses()->sync($licenses);
//store authors
if (isset($data['authors'])) {
$data_to_sync = [];
foreach ($request->get('authors') as $key => $person_id) {
$pivot_data = ['role' => 'author', 'sort_order' => $key + 1];
@ -287,14 +292,28 @@ class IndexController extends Controller
$data_to_sync[$person_id] = $pivot_data;
}
$dataset->persons()->sync($data_to_sync);
}
//store contributors
if (isset($data['contributors'])) {
$data_to_sync = [];
foreach ($request->get('contributors') as $key => $contributor_id) {
$pivot_data = ['role' => 'contributor', 'sort_order' => $key + 1];
$data_to_sync[$contributor_id] = $pivot_data;
}
$dataset->persons()->sync($data_to_sync);
}
//store submitters
if (isset($data['submitters'])) {
$data_to_sync = [];
foreach ($request->get('submitters') as $key => $submitter_id) {
$pivot_data = ['role' => 'submitter', 'sort_order' => $key + 1];
$data_to_sync[$submitter_id] = $pivot_data;
}
$dataset->persons()->sync($data_to_sync);
}
//save main title:
if (isset($data['title_main'])) {
@ -314,6 +333,14 @@ class IndexController extends Controller
$dataset->addMainAbstract($abstract);
}
//save references
if (isset($data['references'])) {
foreach ($request->get('references') as $key => $reference) {
$dataReference = new DatasetReference($reference);
$dataset->references()->save($dataReference);
}
}
// $error = 'Always throw this error';
// throw new \Exception($error);

View File

@ -163,6 +163,12 @@ class Dataset extends Model
return $this->hasMany(\App\Models\File::class, 'document_id', 'id');
}
public function references()
{
return $this->hasMany(\App\Models\DatasetReference::class, 'document_id', 'id');
}
/**
* Get the xml-cache record associated with the dataset.
*

View File

@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Dataset;
class DatasetReference extends Model
{
protected $table = 'document_references';
public $timestamps = false;
protected $fillable = ['value', 'label', 'type', 'relation'];
public function dataset()
{
return $this->belongsTo(Dataset::class, 'document_id', 'id');
}
}

File diff suppressed because one or more lines are too long

View File

@ -53,6 +53,7 @@ const app = new Vue({
fileCount: 0,
persons: [],
contributors: [],
submitters: [],
step: 1,
dataset: {
@ -76,7 +77,9 @@ const app = new Vue({
checkedAuthors: [],
checkedLicenses: [],// [],
files: [],
references: [],
checkedContributors: [],
checkedSubmitters: [],
}
}
},
@ -169,6 +172,17 @@ const app = new Vue({
for (var i = 0; i < this.dataset.checkedContributors.length; i++) {
formData.append('contributors[' + i + ']', this.dataset.checkedContributors[i]);
}
for (var i = 0; i < this.dataset.checkedSubmitters.length; i++) {
formData.append('submitters[' + i + ']', this.dataset.checkedSubmitters[i]);
}
for (var i = 0; i < this.dataset.references.length; i++) {
let reference = this.dataset.references[i];
formData.append('references[' + i + '][value]', reference.value);
formData.append('references[' + i + '][label]', reference.label);
formData.append('references[' + i + '][type]', reference.type);
formData.append('references[' + i + '][relation]', reference.relation);
}
/*
Make the request to the POST /multiple-files URL
@ -228,6 +242,17 @@ const app = new Vue({
/*
Handles a change on the file upload
*/
addReference() {
let newReference = { value: '', label: '', relation: 'updates', type: 'rdr-id' };
//this.dataset.files.push(uploadedFiles[i]);
this.dataset.references.push(newReference);
},
/*
Removes a selected reference
*/
removeReference(key) {
this.dataset.references.splice(key, 1);
},
filesChange(fieldName, fileList) {
// this.dataset.files = this.$refs.files.files;
let uploadedFiles = fileList;
@ -256,13 +281,21 @@ const app = new Vue({
}
},
onAddContributor(person) {
//if person is not in person array
//if (this.persons.includes(person) == false) {
//if person is not in contributors array
//if (this.contributors.includes(person) == false) {
if (this.contributors.filter(e => e.id === person.id).length == 0) {
this.contributors.push(person);
this.dataset.checkedContributors.push(person.id);
}
},
onAddSubmitter(person) {
//if person is not in submitters array
//if (this.submitters.includes(person) == false) {
if (this.submitters.filter(e => e.id === person.id).length == 0) {
this.submitters.push(person);
this.dataset.checkedSubmitters.push(person.id);
}
},
/*
Removes a select file the user has uploaded
*/

View File

@ -98,7 +98,7 @@
{{-- {{ Form::text('State', null, ['class' => 'pure-u-23-24', 'placeholder' => trans('validation.attributes.backend.pages.title'),
'v-model' => 'dataset.state', "v-validate" => "'required'", 'data-vv-scope' => 'step-2', 'readonly' => 'true']) }} --}}
<div class="select pure-u-23-24">
{!! Form::select( 'State', ['unpublished', 'inprogress'], null, ['id' => 'state',
{!! Form::select( 'State', ['unpublished' => 'unpublished', 'inprogress' => 'inprogress'], null, ['id' => 'state',
'placeholder' => '-- select server state --', 'v-model' => 'dataset.state', "v-validate" => "'required'", 'data-vv-scope' => 'step-2'] ) !!}
</div>
{{-- <div class="select pure-u-23-24">
@ -193,6 +193,42 @@
<span>Checked license: @{{ dataset.checkedLicenses }}</span>
</div>
</fieldset>
<fieldset id="fieldset-references">
<legend>Document references</legend>
<button class="pure-button button-small" @click.prevent="addReference()">Add Reference</button>
<table class="table table-hover" v-if="dataset.references.length">
<thead>
<tr>
<th style="width: 20px;">Value of the identifier</th>
<th>Type</th>
<th>Relation</th>
<th>Display text of the identifier</th>
<th style="width: 130px;"></th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in dataset.references">
<td>
<input name="Reference Value" class="form-control" v-model="item.value" v-validate="'required'" data-vv-scope="step-2" />
</td>
<td>
{!! Form::select('Reference[Type]', $types, null,
['placeholder' => '--no type--', 'v-model' => 'item.type', "v-validate" => "'required'", 'data-vv-scope' => 'step-2']) !!}
</td>
<td>
{!! Form::select('Reference[Relation]', $relations, null,
['placeholder' => '--no relation--', 'v-model' => 'item.relation', 'data-vv-scope' => 'step-2']) !!}
</td>
<td>
<input name="Reference Label" class="form-control" v-model="item.label" v-validate="'required'" data-vv-scope="step-2" />
</td>
<td>
<button class="pure-button button-small is-warning" @click.prevent="removeReference(index)">Remove</button>
</td>
</tr>
</tbody>
</table>
</fieldset>
<br />
<div class="pure-controls">
@ -215,7 +251,7 @@
</div>
<div v-if="step === 3" data-vv-scope="step-3">
<h1>Select authors, contributors</h1>
<h1>Select authors, contributors, submitters</h1>
<fieldset id="fieldset-general">
<legend>Authors</legend>
@ -261,7 +297,21 @@
<fieldset id="fieldset-general">
<legend>Submitters</legend>
<small id="submitterHelp" class="pure-form-message-inline">will come soon...</small>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2 pure-div">
<my-autocomplete title="searching active person table" @person="onAddSubmitter"></my-autocomplete>
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
<div class="pure-control-group checkboxlist">
<label v-for="(submitter, index) in submitters" :for="submitter.id" class="pure-checkbox">
<input type="checkbox" name="submitters" v-bind:value="submitter.id" v-model="dataset.checkedSubmitters" class="form-check-input" data-vv-scope="step-3">
@{{ submitter.full_name }}
</label>
<br />
<span>Checked Submitters: @{{ dataset.checkedSubmitters }}</span>
</div>
</div>
</div>
</fieldset>
<br />
<div class="pure-controls">
@ -296,7 +346,7 @@
@{{ item.name }} <i class="fa fa-remove"></i><span class="remove-file" v-on:click="removeFile(index)"> Remove</span>
</li>
</ul> --}}
<table class="table table-hover">
<table class="table table-hover" v-if="dataset.files.length">
<thead>
<tr>
<th style="width: 20px;">Sorting</th>