better frontend with dataset files

This commit is contained in:
Arno Kaimbacher 2018-11-05 16:44:25 +01:00
parent d788410cb5
commit 3b005f4555
13 changed files with 399 additions and 89 deletions

View File

@ -28,9 +28,28 @@ class PagesController extends Controller
*/ */
public function show($id): View public function show($id): View
{ {
$document = Dataset::findOrFail($id); $dataset = Dataset::findOrFail($id);
$document->load('titles'); $dataset->load('titles');
$document->load('abstracts'); $dataset->load('abstracts');
return view('frontend.dataset.show', compact('document'));
$authors = $dataset->authors()
->orderBy('link_documents_persons.sort_order', 'desc')
->get();
$contributors = $dataset->contributors()
->orderBy('link_documents_persons.sort_order', 'desc')
->get();
$submitters = $dataset->persons()
->wherePivot('role', 'submitter')
->orderBy('link_documents_persons.sort_order', 'desc')
->get();
// $authors = $dataset->persons()
// ->wherePivot('role', 'author')
// ->orderBy('link_documents_persons.sort_order', 'desc')
// ->get();
return view('frontend.dataset.show', compact('dataset', 'authors', 'contributors', 'submitters'));
} }
} }

View File

@ -376,7 +376,180 @@ class IndexController extends Controller
return response()->json(array( return response()->json(array(
'success' => true, 'success' => true,
'redirect' => route('settings.document', ['state' => $dataset->server_state]), //'redirect' => route('settings.document.edit', ['id' => $dataset->server_state]),
'redirect' => route('settings.document.edit', ['id' => $dataset->id]),
));
} else {
//TODO Handle validation error
//pass validator errors as errors object for ajax response
return response()->json([
'success' => false,
'errors' => $validator->errors()->all(),
], 422);
}
}
public function storeTest1(Request $request)
{
$data = $request->all();
// $validatedData = $this->validate($request, [
// 'type' => 'required|min:4',
// 'rights' => 'required|boolean|in:1',
// ]);
$rules = [
'server_state' => 'required',
'type' => 'required|min:5',
'rights' => 'required|boolean|in:1',
'belongs_to_bibliography' => 'required|boolean',
'title_main.value' => 'required|min:5',
'title_main.language' => 'required',
'abstract_main.value' => 'required|min:5',
'abstract_main.language' => 'required',
];
if (null != $request->file('files')) {
$files = count($request->file('files')) - 1;
foreach (range(0, $files) as $index) {
// $rules['files.' . $index] = 'image|max:2048';
$rules['files.' . $index . '.file'] = ['required', 'file', new RdrFiletypes(), new RdrFilesize()];
}
}
$validator = Validator::make($request->all(), $rules);
if ($validator->passes()) {
//store dataset todo
//$data = $request->all();
$input = $request->except('files', 'licenses', 'abstract_main', 'title_main', 'references');
// array_push($input, "Himbeere");
$dataset = new Dataset($input);
DB::beginTransaction(); //Start transaction!
try {
// $dataset->save();
//store related files
if (isset($data['files'])) {
foreach ($data['files'] as $uploadedFile) {
$file = $uploadedFile['file'];
$label = urldecode($uploadedFile['label']);
$sorting = $uploadedFile['sorting'];
$fileName = "file-" . time() . '.' . $file->getClientOriginalExtension();
$mimeType = $file->getMimeType();
$datasetFolder = 'files/' . $dataset->id;
// $path = $file->storeAs($datasetFolder, $fileName);
// $size = Storage::size($path);
//$path = Storage::putFile('files', $image, $fileName);
// $file = new File([
// 'path_name' => $path,
// 'file_size' => $size,
// 'mime_type' => $mimeType,
// 'label' => $label,
// 'sort_order' => $sorting,
// 'visible_in_frontdoor' => 1,
// 'visible_in_oai' => 1
// ]);
//$test = $file->path_name;
// $dataset->files()->save($file);
// $file->createHashValues();
}
}
//store licenses:
$licenses = $request->input('licenses');
// $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];
// if ($galery_id == $request->get('mainPicture')) $pivot_data = ['main' => 1];
$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'])) {
$formTitle = $request->input('title_main');
$title = new Title();
$title->value = $formTitle['value'];
$title->language = $formTitle['language'];
// $dataset->addMainTitle($title);
}
//save main abstract:
if (isset($data['abstract_main'])) {
$formAbstract = $request->input('abstract_main');
$abstract = new Title();
$abstract->value = $formAbstract['value'];
$abstract->language = $formAbstract['language'];
// $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);
// all good//commit everything
// DB::commit();
} catch (\Exception $e) {
DB::rollback();
if (isset($datasetFolder)) {
Storage::deleteDirectory($datasetFolder);
}
return response()->json([
'success' => false,
'error' => [
'code' => $e->getCode(),
'message' => $e->getMessage(),
],
], 422);
//throw $e;
} catch (\Throwable $e) {
DB::rollback();
if (isset($datasetFolder)) {
Storage::deleteDirectory($datasetFolder);
}
return response()->json([
'success' => false,
'error' => [
'code' => $e->getCode(),
'message' => $e->getMessage(),
],
], 422);
//throw $e;
}
return response()->json(array(
'success' => true,
'redirect' => route('settings.document.edit', ['id' => $dataset->server_state]),
)); ));
} else { } else {
//TODO Handle validation error //TODO Handle validation error

View File

@ -9,6 +9,7 @@ use App\Models\Project;
use App\Models\Title; use App\Models\Title;
use App\Models\Person; use App\Models\Person;
use App\Models\XmlCache; use App\Models\XmlCache;
use App\Models\File;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Dataset extends Model class Dataset extends Model
@ -160,7 +161,7 @@ class Dataset extends Model
public function files() public function files()
{ {
return $this->hasMany(\App\Models\File::class, 'document_id', 'id'); return $this->hasMany(File::class, 'document_id', 'id');
} }
public function references() public function references()

File diff suppressed because one or more lines are too long

View File

@ -474,8 +474,8 @@ a:hover { text-decoration: none; }*/
} }
/*table { width: 100%; margin: 2em 0; }*/ /*table { width: 100%; margin: 2em 0; }*/
.pure-table a { .pure-table a {
color: #333; color: #005F6A;
text-decoration:underline; text-decoration:none;
} }
.pure-table a:hover { .pure-table a:hover {

View File

@ -608,7 +608,7 @@ a:hover { text-decoration: none; }*/
} }
/*table { width: 100%; margin: 2em 0; }*/ /*table { width: 100%; margin: 2em 0; }*/
.pure-table a { .pure-table a {
color: #333; color: #005F6A;
text-decoration: none; text-decoration: none;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,44 @@
<script>
import Vue from "vue";
let dataset = new Vue({
data: function() {
return {
type: "",
state: "",
rights: null,
project_id: "",
creating_corporation: "GBA",
embargo_date: "",
belongs_to_bibliography: 0,
title_main: {
value: "",
language: ""
},
abstract_main: {
value: "",
language: ""
},
checkedAuthors: [],
checkedLicenses: [], // [],
files: [],
references: [],
checkedContributors: [],
checkedSubmitters: [],
persons: [],
contributors: [],
submitters: []
};
},
created() {
let json = JSON.stringify(this.$data);
this.reset = () => {
Object.assign(this.$data, JSON.parse(json));
};
}
});
export { dataset };
</script>

View File

@ -30,6 +30,7 @@ import axios from 'axios';
//Vue.component('my-autocomplete', require('./components/MyAutocomplete.vue')); //Vue.component('my-autocomplete', require('./components/MyAutocomplete.vue'));
import MyAutocomplete from './components/MyAutocomplete.vue'; import MyAutocomplete from './components/MyAutocomplete.vue';
import VeeValidate from 'vee-validate'; import VeeValidate from 'vee-validate';
import { dataset } from './components/Dataset';
// import { Validator } from 'vee-validate'; // import { Validator } from 'vee-validate';
Vue.use(VeeValidate); Vue.use(VeeValidate);
@ -46,41 +47,42 @@ const app = new Vue({
// { qty: 2, value: "Something else", language: 20, type: "additional", sort_order: 0 }, // { qty: 2, value: "Something else", language: 20, type: "additional", sort_order: 0 },
], ],
serrors: [], serrors: [],
uploadedFiles: [], uploadedFiles: [],
uploadError: null, uploadError: null,
currentStatus: null, currentStatus: null,
uploadFieldName: 'photos', uploadFieldName: 'photos',
fileCount: 0, fileCount: 0,
persons: [], redirectLink : null,
contributors: [],
submitters: [],
step: 1, step: 1,
dataset: { dataset : dataset
type: '', // dataset: {
state: '', // type: '',
rights: null, // state: '',
project_id: '', // rights: null,
// project_id: '',
creating_corporation: "GBA", // creating_corporation: "GBA",
embargo_date: '', // embargo_date: '',
belongs_to_bibliography: 0, // belongs_to_bibliography: 0,
title_main: { // title_main: {
value: '', // value: '',
language: '' // language: ''
}, // },
abstract_main: { // abstract_main: {
value: '', // value: '',
language: '' // language: ''
}, // },
checkedAuthors: [], // checkedAuthors: [],
checkedLicenses: [],// [], // checkedLicenses: [],// [],
files: [], // files: [],
references: [], // references: [],
checkedContributors: [], // checkedContributors: [],
checkedSubmitters: [], // checkedSubmitters: [],
} // }
} }
}, },
created: function () { created: function () {
@ -121,6 +123,11 @@ const app = new Vue({
this.currentStatus = STATUS_INITIAL; this.currentStatus = STATUS_INITIAL;
this.uploadedFiles = []; this.uploadedFiles = [];
this.uploadError = null; this.uploadError = null;
this.dataset.reset();//reset methods will trigger property changed.
this.step = 1;
},
editNewDataset() {
window.location = this.redirectLink;
}, },
resetDropbox() { resetDropbox() {
// reset form to initial state // reset form to initial state
@ -128,7 +135,9 @@ const app = new Vue({
this.dataset.files = []; this.dataset.files = [];
}, },
save() { save() {
// upload data to the server
var _this = this; var _this = this;
this.currentStatus = STATUS_SAVING;
this.serrors = []; this.serrors = [];
/* /*
Initialize the form data Initialize the form data
@ -201,14 +210,15 @@ const app = new Vue({
// this.items = response.data; // this.items = response.data;
//Vue.set(app.skills, 1, "test55"); //Vue.set(app.skills, 1, "test55");
_this.currentStatus = STATUS_SUCCESS; _this.currentStatus = STATUS_SUCCESS;
_this.redirectLink = response.data.redirect;
if (response.data.redirect) { // if (response.data.redirect) {
window.location = response.data.redirect; // window.location = response.data.redirect;
} // }
}) })
.catch((error) => { .catch((error) => {
// this.loading = false; // this.loading = false;
// console.log("test"); this.uploadError = error.response;
console.log('FAILURE!!');
let errorObject = JSON.parse(JSON.stringify(error)); let errorObject = JSON.parse(JSON.stringify(error));
// console.log(errorObject); // console.log(errorObject);
if (errorObject.response.data.errors) { if (errorObject.response.data.errors) {
@ -254,6 +264,7 @@ const app = new Vue({
this.dataset.references.splice(key, 1); this.dataset.references.splice(key, 1);
}, },
filesChange(fieldName, fileList) { filesChange(fieldName, fileList) {
this.fileCount = fileList.length
// this.dataset.files = this.$refs.files.files; // this.dataset.files = this.$refs.files.files;
let uploadedFiles = fileList; let uploadedFiles = fileList;
@ -275,24 +286,24 @@ const app = new Vue({
onAddAuthor(person) { onAddAuthor(person) {
//if person is not in person array //if person is not in person array
//if (this.persons.includes(person) == false) { //if (this.persons.includes(person) == false) {
if (this.persons.filter(e => e.id === person.id).length == 0) { if (this.dataset.persons.filter(e => e.id === person.id).length == 0) {
this.persons.push(person); this.dataset.persons.push(person);
this.dataset.checkedAuthors.push(person.id); this.dataset.checkedAuthors.push(person.id);
} }
}, },
onAddContributor(person) { onAddContributor(person) {
//if person is not in contributors array //if person is not in contributors array
//if (this.contributors.includes(person) == false) { //if (this.contributors.includes(person) == false) {
if (this.contributors.filter(e => e.id === person.id).length == 0) { if (this.dataset.contributors.filter(e => e.id === person.id).length == 0) {
this.contributors.push(person); this.dataset.contributors.push(person);
this.dataset.checkedContributors.push(person.id); this.dataset.checkedContributors.push(person.id);
} }
}, },
onAddSubmitter(person) { onAddSubmitter(person) {
//if person is not in submitters array //if person is not in submitters array
//if (this.submitters.includes(person) == false) { //if (this.submitters.includes(person) == false) {
if (this.submitters.filter(e => e.id === person.id).length == 0) { if (this.dataset.submitters.filter(e => e.id === person.id).length == 0) {
this.submitters.push(person); this.dataset.submitters.push(person);
this.dataset.checkedSubmitters.push(person.id); this.dataset.checkedSubmitters.push(person.id);
} }
}, },

View File

@ -2,7 +2,7 @@
@section('content') @section('content')
<h1 class="title">Documents</h1> <h1 class="title">Datasets</h1>
<br><br> <br><br>
@ -10,7 +10,7 @@
<thead> <thead>
<th>id</th> <th>id</th>
<th>document type</th> <th>dataset type</th>
<!-- <th>Category</th> <!-- <th>Category</th>
<th>Shelf</th> --> <th>Shelf</th> -->
@ -18,11 +18,13 @@
<tbody> <tbody>
@foreach($documents as $document) @foreach($documents as $dataset)
<tr> <tr>
<td>{{ $document->id }}</td> <td>
<td>{{ $document->type }}</td> <a href="{{ route('frontend.dataset.show', ['id' => $dataset->id]) }}"> {{ $dataset->id }} </a>
</td>
<td>{{ $dataset->type }}</td>
<!-- <td> <!-- <td>
if($book->stock > 0) if($book->stock > 0)
Available Available

View File

@ -1,33 +1,70 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<div> <div>
<div id="titlemain-wrapper">
<div class="frontdoor_pagination">
{{-- <a id="pagination-link-hitlist" href="{{ route('settings.document') }}">BACK</a> --}}
<a href="{{ route('frontend.datasets') }}" class="pure-button">
<span class="glyphicon glyphicon-chevron-left" ></span> BACK
</a>
<section class="post">
<header class="post-header">
</header>
<div class="blog-meta">
created: <?= $dataset->created_at->toDayDateTimeString() ?>
</div> </div>
@foreach ($document->titles as $title) <div class="post-description">
<h2 class="titlemain"> {{ $title->value }}</h2> {{-- @foreach ($dataset->authors as $author)
<em>Author: {{ $author->full_name }}</em>
<br />
@endforeach --}}
@foreach ($dataset->titles as $title)
<em>Main Title: {{ $title->value }}</em>
<br />
@endforeach @endforeach
</div> @foreach ($dataset->abstracts as $abstract)
<em>Abstract: {{ $abstract->value }}</em>
<div id="result-data"> <br />
<div id="abstract">
<ul>
@foreach ($document->abstracts as $abstract)
<li class="abstract preserve-spaces"> {{ $abstract->value }}</p>
@endforeach @endforeach
</ul> @foreach ($authors as $author)
</div> <em>Author: {{ $author->full_name }}</em>
<br />
@endforeach
@foreach ($contributors as $contributor)
<em>Contributor: {{ $contributors->full_name }}</em>
<br />
@endforeach
@foreach ($submitters as $submitter)
<em>Contributor: {{ $submitter->full_name }}</em>
<br />
@endforeach
<table id="items" class="pure-table pure-table-horizontal">
<thead>
<tr>
<th>Path Name</th>
<th>Label</th>
</tr>
</thead>
<tbody>
@foreach($dataset->files as $key => $file)
<tr>
<td>
@if($file->exists() === true)
<a href="{{ route('settings.file.download', ['id' => $file->id]) }}"> {{ $file->path_name }} </a>
@else
<span class="alert">missing file: {{ $file->path_name }}</span>
@endif
</td>
<td> {{ $file->label }} </td>
</tr>
@endforeach
</tbody>
</table>
</div> </div>
</section>
</div>
</div>
@stop @stop

View File

@ -16,7 +16,7 @@
<main class="steps pure-form" enctype="multipart/form-data"> <main class="steps pure-form" enctype="multipart/form-data">
{{ csrf_field() }} {{ csrf_field() }}
<div v-if="step === 1" data-vv-scope="step-1"> <div v-if="step === 1 && isInitial" data-vv-scope="step-1">
<h1>Step One</h1> <h1>Step One</h1>
<div class="form-group"> <div class="form-group">
@ -71,7 +71,7 @@
</div> </div>
</div> </div>
<div v-if="step === 2" data-vv-scope="step-2"> <div v-if="step === 2 && isInitial" data-vv-scope="step-2">
<h1>Step Two</h1> <h1>Step Two</h1>
<fieldset id="fieldset-general"> <fieldset id="fieldset-general">
<legend>General</legend> <legend>General</legend>
@ -250,7 +250,7 @@
</div> </div>
</div> </div>
<div v-if="step === 3" data-vv-scope="step-3"> <div v-if="step === 3 && isInitial" data-vv-scope="step-3">
<h1>Select authors, contributors, submitters</h1> <h1>Select authors, contributors, submitters</h1>
<fieldset id="fieldset-general"> <fieldset id="fieldset-general">
@ -263,7 +263,7 @@
</div> </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"> <div class="pure-control-group checkboxlist">
<label v-for="(person, index) in persons" :for="person.id" class="pure-checkbox"> <label v-for="(person, index) in dataset.persons" :for="person.id" class="pure-checkbox">
<input type="checkbox" name="persons" v-bind:value="person.id" v-model="dataset.checkedAuthors" class="form-check-input" data-vv-scope="step-3"> <input type="checkbox" name="persons" v-bind:value="person.id" v-model="dataset.checkedAuthors" class="form-check-input" data-vv-scope="step-3">
@{{ person.full_name }} @{{ person.full_name }}
</label> </label>
@ -284,7 +284,7 @@
</div> </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"> <div class="pure-control-group checkboxlist">
<label v-for="(contributor, index) in contributors" :for="contributor.id" class="pure-checkbox"> <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-3"> <input type="checkbox" name="contributors" v-bind:value="contributor.id" v-model="dataset.checkedContributors" class="form-check-input" data-vv-scope="step-3">
@{{ contributor.full_name }} @{{ contributor.full_name }}
</label> </label>
@ -303,7 +303,7 @@
</div> </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"> <div class="pure-control-group checkboxlist">
<label v-for="(submitter, index) in submitters" :for="submitter.id" class="pure-checkbox"> <label v-for="(submitter, index) in dataset.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"> <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 }} @{{ submitter.full_name }}
</label> </label>
@ -327,7 +327,7 @@
</div> </div>
</div> </div>
<div v-if="step === 4" data-vv-scope="step-4"> <div v-if="step === 4 && (isInitial || isSaving)" data-vv-scope="step-4">
<h1>File Upload</h1> <h1>File Upload</h1>
<div class="dropbox"> <div class="dropbox">
@ -383,12 +383,35 @@
</div> </div>
<!--SUCCESS-->
<div v-if="isSuccess">
<h2>Uploaded @{{ dataset.files.length }} file(s) successfully.</h2>
<p>
<a href="javascript:void(0)" @click="reset()" class="pure-button button-small">Upload new Dataset</a>
</p>
<p>
<a href="javascript:void(0)" @click="editNewDataset()" class="pure-button button-small">@{{ redirectLink }}</a>
</p>
<ul class="list-unstyled">
{{-- <li v-for="item in uploadedFiles">
<img :src="item.url" class="img-responsive img-thumbnail" :alt="item.originalName">
</li> --}}
</ul>
</div>
<!--ERROR-->
<div v-if="isFailed">
<h2>Uploaded failed.</h2>
<p>
<a href="javascript:void(0)" @click="reset()">Try again</a>
</p>
<div v-if="serrors.length > 0"> <div v-if="serrors.length > 0">
<b>Please correct the following server error(s):</b> <b>Please correct the following server error(s):</b>
<ul class="alert validation-summary-errors"> <ul class="alert validation-summary-errors">
<li style="margin-left:5px;" v-for="error in serrors">@{{ error }}</li> <li style="margin-left:5px;" v-for="error in serrors">@{{ error }}</li>
</ul> </ul>
</div> </div>
</div>
</main> </main>