- licence name_long varchar 200

- remove and add authors and creators in edit form
- EditDataset.js
- add authors array to Dataset.ts
- use id in PersonTable.vue
- remove active styles from create-step1.blade.php
This commit is contained in:
Arno Kaimbacher 2020-01-09 18:42:09 +01:00
parent f6442b5f7a
commit a8ea6120fd
17 changed files with 146 additions and 28 deletions

View File

@ -23,6 +23,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use App\Models\Person;
class SubmitController extends Controller class SubmitController extends Controller
{ {
@ -59,7 +60,7 @@ class SubmitController extends Controller
public function edit($id): \Illuminate\Contracts\View\View public function edit($id): \Illuminate\Contracts\View\View
{ {
$dataset = Dataset::findOrFail($id); $dataset = Dataset::findOrFail($id);
$dataset->load('licenses', 'titles', 'abstracts', 'files', 'coverage', 'subjects', 'references'); $dataset->load('licenses', 'authors', 'contributors', 'titles', 'abstracts', 'files', 'coverage', 'subjects', 'references');
$titleTypes = ['Main' => 'Main', 'Sub' => 'Sub', 'Alternative' => 'Alternative', 'Translated' => 'Translated', 'Other' => 'Other']; $titleTypes = ['Main' => 'Main', 'Sub' => 'Sub', 'Alternative' => 'Alternative', 'Translated' => 'Translated', 'Other' => 'Other'];
$descriptionTypes = ['Abstract' => 'Abstract', 'Methods' => 'Methods', 'Series_information' => 'Series_information', 'Technical_info' => 'Technical_info', 'Translated' => 'Translated', 'Other' => 'Other']; $descriptionTypes = ['Abstract' => 'Abstract', 'Methods' => 'Methods', 'Series_information' => 'Series_information', 'Technical_info' => 'Technical_info', 'Translated' => 'Translated', 'Other' => 'Other'];
@ -168,6 +169,50 @@ class SubmitController extends Controller
//$licenses = $input['licenses']; //$licenses = $input['licenses'];
$dataset->licenses()->sync($licenses); $dataset->licenses()->sync($licenses);
$dataset->authors()->sync([]);
//store authors
if (isset($data['authors'])) {
// $data_to_sync = [];
$index = 0;
foreach ($request->get('authors') as $key => $person) {
$pivot_data = ['role' => 'author', 'sort_order' => $index + 1, 'allow_email_contact' => false];
// if ($galery_id == $request->get('mainPicture')) $pivot_data = ['main' => 1];
if (isset($person['id'])) {
// $data_to_sync[$person['id']] = $pivot_data;
$dataset->persons()->attach($person['id'], $pivot_data);
} else {
$dataPerson = new Person($person);
$dataPerson->status = true;
$dataPerson->name_type = "Organizational";
$dataset->persons()->save($dataPerson, $pivot_data);
}
$index++;
}
// $dataset->persons()->sync($data_to_sync);
}
$dataset->contributors()->sync([]);
//store contributors
if (isset($data['contributors'])) {
// $data_to_sync = [];
$index = 0;
foreach ($request->get('contributors') as $key => $person) {
$pivot_data = ['role' => 'contributor', 'sort_order' => $index + 1, 'allow_email_contact' => false];
// if ($galery_id == $request->get('mainPicture')) $pivot_data = ['main' => 1];
if (isset($person['id'])) {
// $data_to_sync[$person['id']] = $pivot_data;
$dataset->persons()->attach($person['id'], $pivot_data);
} else {
$dataPerson = new Person($person);
$dataPerson->status = true;
$dataPerson->name_type = "Organizational";
$dataset->persons()->save($dataPerson, $pivot_data);
}
$index++;
}
// $dataset->persons()->sync($data_to_sync);
}
//save the titles: //save the titles:
$titles = $request->input('titles'); $titles = $request->input('titles');
if (is_array($titles) && count($titles) > 0) { if (is_array($titles) && count($titles) > 0) {

View File

@ -150,7 +150,8 @@ class Dataset extends Model
public function authors() public function authors()
{ {
return $this return $this
->belongsToMany(Person::class, 'link_documents_persons', 'document_id', 'person_id') ->persons()
//->belongsToMany(Person::class, 'link_documents_persons', 'document_id', 'person_id')
->wherePivot('role', 'author'); ->wherePivot('role', 'author');
} }
@ -174,7 +175,8 @@ class Dataset extends Model
public function contributors() public function contributors()
{ {
return $this return $this
->belongsToMany(Person::class, 'link_documents_persons', 'document_id', 'person_id') ->persons()
// ->belongsToMany(Person::class, 'link_documents_persons', 'document_id', 'person_id')
->wherePivot('role', 'contributor'); ->wherePivot('role', 'contributor');
} }

View File

@ -24,7 +24,7 @@ class CreateLicencesTable extends Migration
$table->string('link_logo', 200)->nullable(); $table->string('link_logo', 200)->nullable();
$table->string('link_sign', 200)->nullable(); $table->string('link_sign', 200)->nullable();
$table->string('mime_type', 30)->nullable(); $table->string('mime_type', 30)->nullable();
$table->string('name_long', 100); $table->string('name_long', 200);
$table->boolean('pod_allowed')->default(false); $table->boolean('pod_allowed')->default(false);
$table->tinyInteger('sort_order'); $table->tinyInteger('sort_order');
}); });

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,11 +4,18 @@ import VeeValidate from 'vee-validate';
Vue.use(VeeValidate); Vue.use(VeeValidate);
import LocationsMap from './components/locations-map.vue'; import LocationsMap from './components/locations-map.vue';
import Dataset from './components/Dataset'; import Dataset from './components/Dataset';
import PersonTable from './components/PersonTable.vue';
import MyAutocomplete from './components/MyAutocomplete.vue';
import VueToast from 'vue-toast-notification';
import 'vue-toast-notification/dist/index.css';
Vue.use(VueToast);
@Component({ @Component({
components: { components: {
LocationsMap, LocationsMap,
datetime datetime,
PersonTable,
MyAutocomplete
} }
}) })
export default class EditDataset extends Vue { export default class EditDataset extends Vue {
@ -91,6 +98,26 @@ export default class EditDataset extends Vue {
} }
}); });
const isUnique = (value, [objectArray, index, attribute]) =>
new Promise(resolve => {
setTimeout(() => {
if (objectArray.some((item, i) => item[attribute] === value && index !== i)) {
return resolve({
valid: false,
data: {
message: value + ' is already taken.'
}
});
}
return resolve({
valid: true
});
}, 200);
});
VeeValidate.Validator.extend("unique", {
getMessage: (field, params, data) => field + ' ' + data.message,
validate: isUnique,
});
} }
mounted() { mounted() {
@ -259,4 +286,24 @@ export default class EditDataset extends Vue {
this.form.abstracts.splice(key, 1); this.form.abstracts.splice(key, 1);
} }
onAddAuthor(person) {
//if person is not in person array
//if (this.persons.includes(person) == false) {
if (this.form.authors.filter(e => e.id === person.id).length > 0) {
this.$toast.error("person is already defined as author");
} else if (this.form.contributors.filter(e => e.id === person.id).length > 0) {
this.$toast.error("person is already defined as contributor");
}
else {
//person.sort_order = this.dataset.persons.length;
this.form.authors.push(person);
// this.dataset.checkedAuthors.push(person.id);
this.$toast.success("person has been successfully added as author");
}
// else if (this.dataset.contributors.filter(e => e.id === person.id).length > 0) {
// this.$toast.error("person is already defined as contributor");
// }
}
} }

View File

@ -114,6 +114,7 @@ export default class Dataset extends Vue {
checkedContributors = []; checkedContributors = [];
// checkedSubmitters: [], // checkedSubmitters: [],
authors = [];
persons = []; persons = [];
contributors = []; contributors = [];
// submitters: [] // submitters: []

View File

@ -5,6 +5,7 @@
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col">#</th> <th scope="col">#</th>
<th scope="col">ID</th>
<th scope="col">First Name</th> <th scope="col">First Name</th>
<th scope="col">Last Name</th> <th scope="col">Last Name</th>
<th scope="col">Email</th> <th scope="col">Email</th>
@ -21,12 +22,19 @@
<tr <tr
v-for="(item, index) in personlist" v-for="(item, index) in personlist"
v-bind:key="item.id" v-bind:key="item.id"
v-bind:class="[item.status==1 ? 'activeClass' : 'inactiveClass']" v-bind:class="[item.status==true ? 'activeClass' : 'inactiveClass']"
> >
<td scope="row">{{ index + 1 }}</td> <td scope="row">{{ index + 1 }}</td>
<td> <input
v-bind:name="heading+'['+item.id+'][id]'"
class="form-control"
v-model="item.id"
v-bind:readonly="item.status==1"
data-vv-scope="step-1"
/></td>
<td> <td>
<input <input
name="first_name" v-bind:name="heading+'['+item.id+'][first_name]'"
class="form-control" class="form-control"
placeholder="[FIRST NAME]" placeholder="[FIRST NAME]"
v-model="item.first_name" v-model="item.first_name"
@ -37,7 +45,7 @@
</td> </td>
<td> <td>
<input <input
name="last_name" v-bind:name="heading+'['+item.id+'][last_name]'"
class="form-control" class="form-control"
placeholder="[LAST NAME]" placeholder="[LAST NAME]"
v-model="item.last_name" v-model="item.last_name"
@ -49,7 +57,7 @@
<td> <td>
<!-- v-validate="'required|email'" --> <!-- v-validate="'required|email'" -->
<input <input
name="email" v-bind:name="heading+'['+item.id+'][email]'"
class="form-control" class="form-control"
placeholder="[EMAIL]" placeholder="[EMAIL]"
v-model="item.email" v-model="item.email"
@ -60,7 +68,7 @@
</td> </td>
<td> <td>
<input <input
name="identifier_orcid" v-bind:name="heading+'['+item.id+'][identifier_orcid]'"
class="form-control" class="form-control"
placeholder="[ORCID optional]" placeholder="[ORCID optional]"
v-model="item.identifier_orcid" v-model="item.identifier_orcid"
@ -144,4 +152,10 @@ export default class PersonTable extends Vue {
.custom-actions button.ui.button > i.icon { .custom-actions button.ui.button > i.icon {
margin: auto !important; margin: auto !important;
} }
.activeClass {
background-color: aquamarine;
}
.inactiveClass {
background-color: orange;
}
</style> </style>

View File

@ -723,13 +723,6 @@
.has-error .help-block { .has-error .help-block {
display: block; display: block;
} }
.activeClass {
background-color: aquamarine;
}
.inactiveClass {
background-color: orange;
}
</style> </style>

View File

@ -64,6 +64,22 @@
</div> </div>
</fieldset> </fieldset>
<fieldset id="fieldset-creator">
<legend>Creator(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" v-on:person="onAddAuthor"></my-autocomplete>
</div>
</div>
<div class="pure-u-1 pure-u-md-1-2 pure-div">
{{-- {!! 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="authors" v-model="form.authors" type="hidden" class="form-check-input" v-validate="'required'" data-vv-as="Author">
<person-table name="authors" v-bind:heading="'authors'" v-bind:personlist="form.authors"></person-table>
<person-table name="contributors" v-bind:heading="'contributors'" v-bind:personlist="form.contributors"></person-table>
</fieldset>
<fieldset id="fieldset-titles"> <fieldset id="fieldset-titles">
<legend>Title</legend> <legend>Title</legend>
<div> <div>
@ -568,7 +584,7 @@
<fieldset id="fieldset-keywords"> <fieldset id="fieldset-keywords">
<legend>Dataset Keywords</legend> <legend>Dataset Keywords</legend>
<label name="SubjectLabel">Add Reference </label> <label name="SubjectLabel">Add Keyword </label>
<button class="pure-button button-small" @click.prevent="addKeyword()"><i class="fas fa-plus-circle"></i></button> <button class="pure-button button-small" @click.prevent="addKeyword()"><i class="fas fa-plus-circle"></i></button>
@if ($dataset->subjects->count() > 0) @if ($dataset->subjects->count() > 0)
<table id="keywords" class="pure-table pure-table-horizontal"> <table id="keywords" class="pure-table pure-table-horizontal">