add references and submitters
This commit is contained in:
parent
14878a20c8
commit
d788410cb5
|
@ -16,6 +16,7 @@ use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Response;
|
use Illuminate\Support\Facades\Response;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use App\Models\DatasetReference;
|
||||||
|
|
||||||
class IndexController extends Controller
|
class IndexController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -51,8 +52,11 @@ class IndexController extends Controller
|
||||||
// $persons = Person::where('status', 1)
|
// $persons = Person::where('status', 1)
|
||||||
// ->pluck('last_name', 'id');
|
// ->pluck('last_name', 'id');
|
||||||
$projects = Project::pluck('label', '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()) {
|
if ($validator->passes()) {
|
||||||
//store dataset todo
|
//store dataset todo
|
||||||
//$data = $request->all();
|
//$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");
|
// array_push($input, "Himbeere");
|
||||||
$dataset = new Dataset($input);
|
$dataset = new Dataset($input);
|
||||||
|
|
||||||
|
@ -280,6 +284,7 @@ class IndexController extends Controller
|
||||||
$dataset->licenses()->sync($licenses);
|
$dataset->licenses()->sync($licenses);
|
||||||
|
|
||||||
//store authors
|
//store authors
|
||||||
|
if (isset($data['authors'])) {
|
||||||
$data_to_sync = [];
|
$data_to_sync = [];
|
||||||
foreach ($request->get('authors') as $key => $person_id) {
|
foreach ($request->get('authors') as $key => $person_id) {
|
||||||
$pivot_data = ['role' => 'author', 'sort_order' => $key + 1];
|
$pivot_data = ['role' => 'author', 'sort_order' => $key + 1];
|
||||||
|
@ -287,14 +292,28 @@ class IndexController extends Controller
|
||||||
$data_to_sync[$person_id] = $pivot_data;
|
$data_to_sync[$person_id] = $pivot_data;
|
||||||
}
|
}
|
||||||
$dataset->persons()->sync($data_to_sync);
|
$dataset->persons()->sync($data_to_sync);
|
||||||
|
}
|
||||||
|
|
||||||
//store contributors
|
//store contributors
|
||||||
|
if (isset($data['contributors'])) {
|
||||||
$data_to_sync = [];
|
$data_to_sync = [];
|
||||||
foreach ($request->get('contributors') as $key => $contributor_id) {
|
foreach ($request->get('contributors') as $key => $contributor_id) {
|
||||||
$pivot_data = ['role' => 'contributor', 'sort_order' => $key + 1];
|
$pivot_data = ['role' => 'contributor', 'sort_order' => $key + 1];
|
||||||
$data_to_sync[$contributor_id] = $pivot_data;
|
$data_to_sync[$contributor_id] = $pivot_data;
|
||||||
}
|
}
|
||||||
$dataset->persons()->sync($data_to_sync);
|
$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:
|
//save main title:
|
||||||
if (isset($data['title_main'])) {
|
if (isset($data['title_main'])) {
|
||||||
|
@ -314,6 +333,14 @@ class IndexController extends Controller
|
||||||
$dataset->addMainAbstract($abstract);
|
$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';
|
// $error = 'Always throw this error';
|
||||||
// throw new \Exception($error);
|
// throw new \Exception($error);
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,12 @@ class Dataset extends Model
|
||||||
return $this->hasMany(\App\Models\File::class, 'document_id', 'id');
|
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.
|
* Get the xml-cache record associated with the dataset.
|
||||||
*
|
*
|
||||||
|
|
19
app/Models/DatasetReference.php
Normal file
19
app/Models/DatasetReference.php
Normal 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
|
@ -53,6 +53,7 @@ const app = new Vue({
|
||||||
fileCount: 0,
|
fileCount: 0,
|
||||||
persons: [],
|
persons: [],
|
||||||
contributors: [],
|
contributors: [],
|
||||||
|
submitters: [],
|
||||||
|
|
||||||
step: 1,
|
step: 1,
|
||||||
dataset: {
|
dataset: {
|
||||||
|
@ -76,7 +77,9 @@ const app = new Vue({
|
||||||
checkedAuthors: [],
|
checkedAuthors: [],
|
||||||
checkedLicenses: [],// [],
|
checkedLicenses: [],// [],
|
||||||
files: [],
|
files: [],
|
||||||
|
references: [],
|
||||||
checkedContributors: [],
|
checkedContributors: [],
|
||||||
|
checkedSubmitters: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -169,6 +172,17 @@ const app = new Vue({
|
||||||
for (var i = 0; i < this.dataset.checkedContributors.length; i++) {
|
for (var i = 0; i < this.dataset.checkedContributors.length; i++) {
|
||||||
formData.append('contributors[' + i + ']', this.dataset.checkedContributors[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
|
Make the request to the POST /multiple-files URL
|
||||||
|
@ -228,6 +242,17 @@ const app = new Vue({
|
||||||
/*
|
/*
|
||||||
Handles a change on the file upload
|
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) {
|
filesChange(fieldName, fileList) {
|
||||||
// this.dataset.files = this.$refs.files.files;
|
// this.dataset.files = this.$refs.files.files;
|
||||||
let uploadedFiles = fileList;
|
let uploadedFiles = fileList;
|
||||||
|
@ -256,13 +281,21 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onAddContributor(person) {
|
onAddContributor(person) {
|
||||||
//if person is not in person array
|
//if person is not in contributors array
|
||||||
//if (this.persons.includes(person) == false) {
|
//if (this.contributors.includes(person) == false) {
|
||||||
if (this.contributors.filter(e => e.id === person.id).length == 0) {
|
if (this.contributors.filter(e => e.id === person.id).length == 0) {
|
||||||
this.contributors.push(person);
|
this.contributors.push(person);
|
||||||
this.dataset.checkedContributors.push(person.id);
|
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
|
Removes a select file the user has uploaded
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
{{-- {{ Form::text('State', null, ['class' => 'pure-u-23-24', 'placeholder' => trans('validation.attributes.backend.pages.title'),
|
{{-- {{ 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']) }} --}}
|
'v-model' => 'dataset.state', "v-validate" => "'required'", 'data-vv-scope' => 'step-2', 'readonly' => 'true']) }} --}}
|
||||||
<div class="select pure-u-23-24">
|
<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'] ) !!}
|
'placeholder' => '-- select server state --', 'v-model' => 'dataset.state', "v-validate" => "'required'", 'data-vv-scope' => 'step-2'] ) !!}
|
||||||
</div>
|
</div>
|
||||||
{{-- <div class="select pure-u-23-24">
|
{{-- <div class="select pure-u-23-24">
|
||||||
|
@ -193,6 +193,42 @@
|
||||||
<span>Checked license: @{{ dataset.checkedLicenses }}</span>
|
<span>Checked license: @{{ dataset.checkedLicenses }}</span>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</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 />
|
<br />
|
||||||
<div class="pure-controls">
|
<div class="pure-controls">
|
||||||
|
@ -215,7 +251,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="step === 3" data-vv-scope="step-3">
|
<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">
|
<fieldset id="fieldset-general">
|
||||||
<legend>Authors</legend>
|
<legend>Authors</legend>
|
||||||
|
@ -261,7 +297,21 @@
|
||||||
|
|
||||||
<fieldset id="fieldset-general">
|
<fieldset id="fieldset-general">
|
||||||
<legend>Submitters</legend>
|
<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>
|
</fieldset>
|
||||||
<br />
|
<br />
|
||||||
<div class="pure-controls">
|
<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>
|
@{{ item.name }} <i class="fa fa-remove"></i><span class="remove-file" v-on:click="removeFile(index)"> Remove</span>
|
||||||
</li>
|
</li>
|
||||||
</ul> --}}
|
</ul> --}}
|
||||||
<table class="table table-hover">
|
<table class="table table-hover" v-if="dataset.files.length">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 20px;">Sorting</th>
|
<th style="width: 20px;">Sorting</th>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user