+ add new contributor

+ change sort_order of contributors
This commit is contained in:
Arno Kaimbacher 2019-07-24 09:28:04 +02:00
parent 9c210a0d96
commit 590c0812fe
5 changed files with 55 additions and 17 deletions

View File

@ -342,14 +342,27 @@ class IndexController extends Controller
}
//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()->attach($contributor_id, $pivot_data);
// }
// //$dataset->persons()->sync($data_to_sync);
// }
if (isset($data['contributors'])) {
//$data_to_sync = [];
foreach ($request->get('contributors') as $key => $contributor_id) {
foreach ($request->get('contributors') as $key => $contributor) {
$pivot_data = ['role' => 'contributor', 'sort_order' => $key + 1];
//$data_to_sync[$contributor_id] = $pivot_data;
$dataset->persons()->attach($contributor_id, $pivot_data);
if (isset($contributor['id'])) {
//$data_to_sync[$person['id']] = $pivot_data;
$dataset->persons()->attach($contributor['id'], $pivot_data);
} else {
$dataContributor = new Person($contributor);
$dataset->persons()->save($dataContributor, $pivot_data);
}
}
//$dataset->persons()->sync($data_to_sync);
}
//store submitters

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,6 @@
<template>
<div>
<h3 v-if="heading && personlist.length">{{ heading }}</h3>
<table class="pure-table pure-table-horizontal" v-if="personlist.length">
<thead class="thead-dark">
<tr>
@ -66,6 +68,7 @@
</tr>
</draggable>
</table>
</div>
</template>
<script>
@ -98,7 +101,8 @@ export default {
},
rowIndex: {
type: Number
}
},
heading: String
},
methods: {
itemAction(action, data, index) {

View File

@ -290,6 +290,10 @@ const app = new Vue({
formData.append('licenses[' + i + ']', this.dataset.checkedLicenses[i]);
}
// for (var i = 0; i < this.dataset.checkedAuthors.length; i++) {
// formData.append('authors[' + i + ']', this.dataset.checkedAuthors[i]);
// }
for (var i = 0; i < this.dataset.persons.length; i++) {
let person = this.dataset.persons[i];
formData.append('authors[' + i + '][first_name]', person.first_name);
@ -302,11 +306,19 @@ const app = new Vue({
}
}
// for (var i = 0; i < this.dataset.checkedAuthors.length; i++) {
// formData.append('authors[' + i + ']', this.dataset.checkedAuthors[i]);
// 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.checkedContributors.length; i++) {
formData.append('contributors[' + i + ']', this.dataset.checkedContributors[i]);
for (var i = 0; i < this.dataset.contributors.length; i++) {
let contributor = this.dataset.contributors[i];
formData.append('contributors[' + i + '][first_name]', contributor.first_name);
formData.append('contributors[' + i + '][last_name]', contributor.last_name);
formData.append('contributors[' + i + '][email]', contributor.email);
formData.append('contributors[' + i + '][identifier_orcid]', contributor.identifier_orcid);
formData.append('contributors[' + i + '][status]', contributor.status);
if (contributor.id !== undefined) {
formData.append('contributors[' + i + '][id]', contributor.id);
}
}
// for (var i = 0; i < this.dataset.checkedSubmitters.length; i++) {
// formData.append('submitters[' + i + ']', this.dataset.checkedSubmitters[i]);
@ -489,6 +501,10 @@ const app = new Vue({
this.dataset.checkedAuthors.push(person.id);
}
},
addNewContributor() {
let newContributor = { status: 0, first_name: '', last_name: '', email: '', academic_title: '', identifier_orcid: '' };
this.dataset.contributors.push(newContributor);
},
onAddContributor(person) {
//if person is not in contributors array
//if (this.contributors.includes(person) == false) {

View File

@ -206,28 +206,33 @@
{!! Form::label('additionalCreators', 'Add additional creator(s) if creator is not in database') !!}
<button class="pure-button button-small" @click.prevent="addNewAuthor()">+</button>
</div>
<input name="persons" v-model="dataset.persons" type="hidden" class="form-check-input" v-validate="'required'" data-vv-as="Creator" data-vv-scope="step-1">
<h3>Draggable table</h3>
<person-table name="persons" v-bind:personlist="dataset.persons"></person-table>
<input name="persons" v-model="dataset.persons" type="hidden" class="form-check-input" v-validate="'required'" data-vv-as="Creator" data-vv-scope="step-1">
<person-table name="persons" v-bind:heading="'creator table'" v-bind:personlist="dataset.persons"></person-table>
</fieldset>
<fieldset id="fieldset-contributors">
<legend>Contributors</legend>
<legend>Contributor(s)</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2 pure-div">
<my-autocomplete title="searching active person table" @person="onAddContributor"></my-autocomplete>
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{{-- <div class="pure-u-1 pure-u-md-1-2 pure-div">
<div class="pure-control-group checkboxlist">
<label v-for="(contributor, index) in dataset.contributors" :for="contributor.id" class="pure-checkbox">
<input type="checkbox" name="contributors" v-bind:value="contributor.id" v-model="dataset.checkedContributors" class="form-check-input" data-vv-scope="step-1">
@{{ contributor.full_name }}
</label>
<br />
{{-- <span>Checked Contributors: @{{ dataset.checkedContributors }}</span> --}}
<span>Checked Contributors: @{{ dataset.checkedContributors }}</span>
</div>
</div>
</div> --}}
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{!! Form::label('additionalContributors', 'Add additional contributor(s) if contributor is not in database') !!}
<button class="pure-button button-small" @click.prevent="addNewContributor()">+</button>
</div>
{{-- <h3>contributor table</h3> --}}
<person-table name="contributors" v-bind:heading="'contributor table'" v-bind:personlist="dataset.contributors"></person-table>
</fieldset>
<fieldset id="fieldset-publisher">