- add translated description

- creator required
- filesize vrom ini file
- correctly delete dataset in SubmitController
This commit is contained in:
Arno Kaimbacher 2019-07-03 18:32:41 +02:00
parent 4f8ef4fc30
commit a463cb9e4c
10 changed files with 79 additions and 29 deletions

View File

@ -271,7 +271,7 @@ class IndexController extends Controller
$files = count($request->file('files')) - 1; $files = count($request->file('files')) - 1;
foreach (range(0, $files) as $index) { foreach (range(0, $files) as $index) {
// $rules['files.' . $index] = 'image|max:2048'; // $rules['files.' . $index] = 'image|max:2048';
$rules['files.' . $index . '.file'] = ['required', 'file', new RdrFiletypes(), new RdrFilesize($index + 1)]; $rules['files.' . $index . '.file'] = ['required', new RdrFiletypes(), new RdrFilesize($index + 1)];
} }
} }
$validator = Validator::make($request->all(), $rules); $validator = Validator::make($request->all(), $rules);

View File

@ -98,16 +98,7 @@ class SubmitController extends Controller
public function delete($id): RedirectResponse public function delete($id): RedirectResponse
{ {
$dataset = Dataset::with('files')->findOrFail($id); $dataset = Dataset::with('files')->findOrFail($id);
if ($dataset->server_state != "inprogress" || $dataset->server_state != "rejected_editor") { if ($dataset->server_state == "inprogress" || $dataset->server_state == "rejected_editor") {
session()->flash(
'flash_message',
'You cannot delete this datastet!'
. ' There status of this dataset is '
. $dataset->server_state
. ' !'
);
return redirect()->route('settings.project');
} else {
if ($dataset->files->count() > 0) { if ($dataset->files->count() > 0) {
foreach ($dataset->files as $file) { foreach ($dataset->files as $file) {
if (isset($file->path_name)) { if (isset($file->path_name)) {
@ -117,7 +108,16 @@ class SubmitController extends Controller
} }
$dataset->delete(); $dataset->delete();
session()->flash('flash_message', 'You have deleted 1 dataset!'); session()->flash('flash_message', 'You have deleted 1 dataset!');
return redirect()->route('publish.workflow.index'); return redirect()->route('publish.workflow.submit.index');
} else {
session()->flash(
'flash_message',
'You cannot delete this datastet!'
. ' There status of this dataset is '
. $dataset->server_state
. ' !'
);
return redirect()->route('publish.workflow.submit.index');
} }
} }

View File

@ -16,7 +16,8 @@ class RdrFilesize implements Rule
*/ */
public function __construct($fileIndex) public function __construct($fileIndex)
{ {
$this->maxFileSize = Config::get('enums.max_filesize'); $this->maxFileSize = $this->maximumUploadSize();
//ini_get('upload_max_filesize');// Config::get('enums.max_filesize');//10240
$this->fileIndex = $fileIndex; $this->fileIndex = $fileIndex;
} }
@ -32,7 +33,7 @@ class RdrFilesize implements Rule
//return Rule::in($this->filetypes); //return Rule::in($this->filetypes);
// $upload_max_size = ini_get('upload_max_filesize'); // $upload_max_size = ini_get('upload_max_filesize');
$fileSize = filesize($value); $fileSize = filesize($value);
return $fileSize <= $this->maxFileSize * 1024; return $fileSize <= $this->maxFileSize;
// return $this->getSize($attribute, $value) <= $this->maxFileSize; // return $this->getSize($attribute, $value) <= $this->maxFileSize;
} }
@ -45,6 +46,51 @@ class RdrFilesize implements Rule
{ {
return 'file number '. $this->fileIndex .' is too large for the destination storage system.'; return 'file number '. $this->fileIndex .' is too large for the destination storage system.';
} }
/**
* The maximum file upload size by getting PHP settings
* @return integer|float file size limit in BYTES based
*/
private function maximumUploadSize()
{
static $upload_size = null;
if ($upload_size === null) {
$post_max_size = $this->returnBytes('post_max_size');
$upload_max_filesize = $this->returnBytes('upload_max_filesize');
$memory_limit = $this->returnBytes('memory_limit');
// Even though we disable all of variables in php.ini. These still use default value
// Nearly impossible but check for sure
if (empty($post_max_size) && empty($upload_max_filesize) && empty($memory_limit)) {
return false;
}
$upload_size = min($post_max_size, $upload_max_filesize, $memory_limit);
}
return $upload_size;
}
private function returnBytes($val)
{
$value = ini_get($val);
// Value must be a string.
if (!is_string($value)) {
return false;
}
preg_match('/^(?<value>\d+)(?<option>[K|M|G]*)$/i', $value, $matches);
$value = (int) $matches['value'];
$option = strtoupper($matches['option']);
if ($option) {
if ($option === 'K') {
$value *= 1024;
} elseif ($option === 'M') {
$value *= 1024 * 1024;
} elseif ($option === 'G') {
$value *= 1024 * 1024 * 1024;
}
}
return $value;
}
/** /**
* Get the size of an attribute. * Get the size of an attribute.

10
composer.lock generated
View File

@ -1039,16 +1039,16 @@
}, },
{ {
"name": "mcamara/laravel-localization", "name": "mcamara/laravel-localization",
"version": "1.3.19", "version": "1.3.20",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/mcamara/laravel-localization.git", "url": "https://github.com/mcamara/laravel-localization.git",
"reference": "cf89d2515d576292e65bfa5893a0efd1cc5a4064" "reference": "af8f9f30488a83533dda3870fcc335b55cf964e0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/mcamara/laravel-localization/zipball/cf89d2515d576292e65bfa5893a0efd1cc5a4064", "url": "https://api.github.com/repos/mcamara/laravel-localization/zipball/af8f9f30488a83533dda3870fcc335b55cf964e0",
"reference": "cf89d2515d576292e65bfa5893a0efd1cc5a4064", "reference": "af8f9f30488a83533dda3870fcc335b55cf964e0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1097,7 +1097,7 @@
"localization", "localization",
"php" "php"
], ],
"time": "2019-03-05T15:37:01+00:00" "time": "2019-06-28T16:04:56+00:00"
}, },
{ {
"name": "monolog/monolog", "name": "monolog/monolog",

View File

@ -24,6 +24,5 @@ return [
"htm|html" => "text/html", "htm|html" => "text/html",
"png" => "image/png", "png" => "image/png",
"jpg|jpeg|jpe" => "image/jpeg", "jpg|jpeg|jpe" => "image/jpeg",
], ]
'max_filesize' => 5120
]; ];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -114,7 +114,7 @@ const app = new Vue({
}); });
// add the required rule // add the required rule
VeeValidate.Validator.extend('translatedLanguage', { VeeValidate.Validator.extend('translatedLanguage', {
getMessage: field => 'The translated title must be in a language other than than the dataset language.', getMessage: field => 'The translated ' + field + ' must be in a language other than than the dataset language.',
validate: (value, [mainLanguage, type]) => { validate: (value, [mainLanguage, type]) => {
if (type == "translated") { if (type == "translated") {
return value !== mainLanguage; return value !== mainLanguage;

View File

@ -114,7 +114,7 @@
</td> </td>
<td> <td>
{!! Form::select('Title[Language]', $languages, null, {!! Form::select('Title[Language]', $languages, null,
['placeholder' => '[language]', 'v-model' => 'item.language', ['placeholder' => '[language]', 'v-model' => 'item.language', "data-vv-as" => "title",
"v-validate" => "{required: true, translatedLanguage: [dataset.language, item.type]}", "v-validate" => "{required: true, translatedLanguage: [dataset.language, item.type]}",
'data-vv-scope' => 'step-1']) !!} 'data-vv-scope' => 'step-1']) !!}
</td> </td>
@ -168,7 +168,11 @@
</td> </td>
<td> <td>
{!! Form::select('Description[Language]', $languages, null, {!! Form::select('Description[Language]', $languages, null,
['placeholder' => '[language]', 'v-model' => 'item.language', "v-validate" => "'required'", 'data-vv-scope' => 'step-1']) !!} ['placeholder' => '[language]',
'v-model' => 'item.language',
"data-vv-as" => "description",
"v-validate" => "{required: true, translatedLanguage: [dataset.language, item.type]}",
'data-vv-scope' => 'step-1']) !!}
</td> </td>
<td> <td>
<button class="pure-button button-small is-warning" @click.prevent="removeDescription(index)">-</button> <button class="pure-button button-small is-warning" @click.prevent="removeDescription(index)">-</button>
@ -202,6 +206,7 @@
{!! Form::label('additionalCreators', 'Add additional creator(s) if creator is not in database') !!} {!! Form::label('additionalCreators', 'Add additional creator(s) if creator is not in database') !!}
<button class="pure-button button-small" @click.prevent="addNewAuthor()">+</button> <button class="pure-button button-small" @click.prevent="addNewAuthor()">+</button>
</div> </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">
<table class="pure-table pure-table-horizontal" v-if="dataset.persons.length"> <table class="pure-table pure-table-horizontal" v-if="dataset.persons.length">
<thead> <thead>
<tr> <tr>
@ -680,7 +685,7 @@
@{{ index +1 }} @{{ index +1 }}
</td> </td>
<td> <td>
<input class="form-control" v-model="item.file.name" /> <input class="form-control" v-model="item.file.name" readonly />
</td> </td>
<td> <td>
<input class="form-control" v-model="item.label" /> <input class="form-control" v-model="item.label" />

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}"> <meta name="csrf-token" content="{{ csrf_token() }}">
<title>Admin PureRDR</title> <title>BACKEND RDR</title>
<link rel="shortcut icon" type="image/x-icon" href="{{ asset('favicon.ico') }}"> <link rel="shortcut icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">
{{-- <link rel='stylesheet' href="{{ asset('css/pure-min.css') }}" /> {{-- <link rel='stylesheet' href="{{ asset('css/pure-min.css') }}" />
@ -30,7 +30,7 @@
<div id="menu"> <div id="menu">
<nav class="pure-menu sidebar-menu"> <nav class="pure-menu sidebar-menu">
<h1 class="site-logo">Admin<strong>Rdr</strong></h1> <h1 class="site-logo">Backend<strong>RDR</strong></h1>
{{-- <div class="menu-item-divided"></div> --}} {{-- <div class="menu-item-divided"></div> --}}
{{-- <h2 class="pure-menu-heading">Home</h2> --}} {{-- <h2 class="pure-menu-heading">Home</h2> --}}