Commit 4c1b7c07 authored by Antonio Amaddio's avatar Antonio Amaddio 🚀
Browse files

temp commit

parent bbbe8087
......@@ -8,6 +8,7 @@
use App\Http\Requests\Admin\ResearchProject\IndexResearchProject;
use App\Http\Requests\Admin\ResearchProject\StoreResearchProject;
use App\Http\Requests\Admin\ResearchProject\UpdateResearchProject;
use App\Models\DataType;
use App\Models\ResearchProject;
use Brackets\AdminListing\Facades\AdminListing;
use Exception;
......@@ -38,12 +39,17 @@ public function index(IndexResearchProject $request)
// set columns to query
['id', 'project_title', 'responsible_researcher', 'department', 'data_type'],
// set columns to searchIn
['id', 'project_title', 'responsible_researcher', 'department', 'data_type', 'doi']
);
foreach($data->all() as $researchProject)
{
$researchProject->prepareDataTypeAttributeForIndex();
}
if ($request->ajax()) {
if ($request->has('bulk')) {
return [
'bulkItems' => $data->pluck('id')
......@@ -114,6 +120,7 @@ public function edit(ResearchProject $researchProject)
{
$this->authorize('admin.research-project.edit', $researchProject);
$researchProject->prepareDataTypeAttributeForEdit();
return view('admin.research-project.edit', [
'researchProject' => $researchProject,
......
......@@ -2,12 +2,41 @@
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use App\Http\Requests\Admin\ResearchProject\IndexResearchProject;
use App\Models\ResearchProject;
use Brackets\AdminListing\Facades\AdminListing;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function indexProjectOverview(IndexResearchProject $request){
// create and AdminListing instance for a specific model and
$data = AdminListing::create(ResearchProject::class)->processRequestAndGet(
// pass the request with params
$request,
// set columns to query
['id', 'project_title', 'responsible_researcher', 'department', 'data_type'],
// set columns to searchIn
['id', 'project_title', 'responsible_researcher', 'department', 'data_type', 'doi']
);
foreach($data->all() as $researchProject)
{
$researchProject->prepareDataTypeAttributeForIndex();
}
if ($request->ajax()) {
if ($request->has('bulk')) {
return [
'bulkItems' => $data->pluck('id')
];
}
return ['data' => $data];
}
return view('welcome', ['data' => $data]);
}
}
<?php
namespace App\Http\Controllers;
use App\Http\Requests\Admin\ResearchProject\IndexResearchProject;
use App\Models\ResearchProject;
use Brackets\AdminListing\Facades\AdminListing;
use Illuminate\Http\Request;
class GuestController extends Controller
{
public function welcome(IndexResearchProject $request)
{
// create and AdminListing instance for a specific model and
$data = AdminListing::create(ResearchProject::class)->processRequestAndGet(
// pass the request with params
$request,
// set columns to query
['id', 'project_title', 'responsible_researcher', 'department', 'data_type'],
// set columns to searchIn
['id', 'project_title', 'responsible_researcher', 'department', 'data_type', 'doi']
);
foreach($data->all() as $researchProject)
{
$researchProject->prepareDataTypeAttributeForIndex();
}
if ($request->ajax()) {
if ($request->has('bulk')) {
return [
'bulkItems' => $data->pluck('id')
];
}
return ['data' => $data];
}
return view('welcome', ['data' => $data]);
}
}
......@@ -12,10 +12,10 @@ class IndexResearchProject extends FormRequest
*
* @return bool
*/
public function authorize(): bool
{
return Gate::allows('admin.research-project.index');
}
// public function authorize(): bool
// {
// return Gate::allows('admin.research-project.index');
// }
/**
* Get the validation rules that apply to the request.
......@@ -25,7 +25,7 @@ public function authorize(): bool
public function rules(): array
{
return [
'orderBy' => 'in:id,department,data_type|nullable',
'orderBy' => 'in:id,responsible_researcher,department,data_type|nullable',
'orderDirection' => 'in:asc,desc|nullable',
'search' => 'string|nullable',
'page' => 'integer|nullable',
......@@ -33,4 +33,5 @@ public function rules(): array
];
}
}
......@@ -2,6 +2,7 @@
namespace App\Http\Requests\Admin\ResearchProject;
use App\Rules\ValidDataType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rule;
......@@ -26,12 +27,11 @@ public function authorize(): bool
public function rules(): array
{
return [
'data_type' => ['required', 'array', new ValidDataType()],
'department' => ['required', 'string'],
'doi' => ['nullable', 'string'],
'project_title' => ['required', 'string'],
'responsible_researcher' => ['required', 'string'],
'department' => ['required', 'string'],
'data_type' => ['required', 'string'],
'doi' => ['required', 'string'],
];
}
......@@ -44,7 +44,7 @@ public function getSanitized(): array
{
$sanitized = $this->validated();
//Add your code for manipulation with request data here
$sanitized['data_type'] = json_encode($sanitized['data_type']);
return $sanitized;
}
......
......@@ -2,6 +2,8 @@
namespace App\Http\Requests\Admin\ResearchProject;
use App\Rules\ValidDataType;
use App\Rules\ValidDepartment;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rule;
......@@ -26,11 +28,11 @@ public function authorize(): bool
public function rules(): array
{
return [
'data_type' => ['required', 'array', new ValidDataType()],
'department' => ['required', 'string', new ValidDepartment()],
'doi' => ['nullable', 'string'],
'project_title' => ['sometimes', 'string'],
'responsible_researcher' => ['sometimes', 'string'],
'department' => ['sometimes', 'string'],
'data_type' => ['sometimes', 'string'],
'doi' => ['sometimes', 'string'],
];
}
......
......@@ -9,14 +9,20 @@ class ResearchProject extends Model
protected $table = 'research_project';
protected $fillable = [
'project_title', 'responsible_researcher', 'department', 'data_type', 'doi'
'data_type',
'department',
'doi',
'project_title',
'responsible_researcher',
];
protected $dates = [
'created_at',
'updated_at',
];
public $timestamps = false;
protected $appends = ['resource_url'];
......@@ -26,4 +32,26 @@ public function getResourceUrlAttribute()
{
return url('/admin/research-projects/'.$this->getKey());
}
public function prepareDataTypeAttributeForIndex()
{
if (is_array($this->attributes['data_type'])){
$this->attributes['data_type'] = implode(', ', $this->attributes['data_type']);
}
$this->attributes['data_type'] = str_replace(['[', ']', '"'], '', $this->attributes['data_type']);
}
public function prepareDataTypeAttributeForEdit()
{
$string = str_replace(['[', ']', '"'], '', $this->attributes['data_type']);
if (str_contains($string, ','))
{
$this->attributes['data_type'] = explode(',', $string);
}else{
$this->attributes['data_type'] = array($string);
}
}
}
<?php
namespace App\Rules;
use App\Models\DataType;
use Illuminate\Contracts\Validation\Rule;
class ValidDataType implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$validDataTypes = Datatype::all()->pluck('name', 'name');
$allKeysFound = true;
if (is_array($value)){
foreach ($value as $arrValue)
{
if (!$validDataTypes->contains($arrValue))
{
$allKeysFound = false;
break;
}
}
}
else{
$allKeysFound = false;
}
return $allKeysFound;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'You must select at least one data type and all of them most.';
}
}
<?php
namespace App\Rules;
use App\Models\DataType;
use App\Models\Department;
use Illuminate\Contracts\Validation\Rule;
class ValidDepartment implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$validDepartments = Department::all()->pluck('name', 'name');
$allKeysFound = true;
return $validDepartments->contains($value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'You must select one department.';
}
}
......@@ -56,5 +56,19 @@
'updated_at' => $faker->dateTime,
];
});
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\Models\ResearchProject::class, static function (Faker\Generator $faker) {
return [
'created_at' => $faker->dateTime,
'data_type' => $faker->sentence,
'department' => $faker->sentence,
'doi' => $faker->text(),
'project_title' => $faker->text(),
'responsible_researcher' => $faker->sentence,
'updated_at' => $faker->dateTime,
];
});
......@@ -5326,11 +5326,11 @@ Vue.component('research-project-form', {
data: function data() {
return {
form: {
project_title: '',
responsible_researcher: '',
department: '',
data_type: '',
doi: ''
department: '',
doi: '',
project_title: '',
responsible_researcher: ''
}
};
}
......@@ -5,11 +5,11 @@ Vue.component('research-project-form', {
data: function() {
return {
form: {
project_title: '' ,
responsible_researcher: '' ,
department: '' ,
data_type: '' ,
department: '' ,
doi: '' ,
project_title: '' ,
responsible_researcher: '' ,
}
}
......
......@@ -82,5 +82,25 @@
],
],
'research-project' => [
'title' => 'Research Project',
'actions' => [
'index' => 'Research Project',
'create' => 'New Research Project',
'edit' => 'Edit :name',
],
'columns' => [
'id' => 'ID',
'data_type' => 'Data type',
'department' => 'Department',
'doi' => 'Doi',
'project_title' => 'Project title',
'responsible_researcher' => 'Responsible researcher',
],
],
// Do not delete me :) I'm used for auto-generation
];
\ No newline at end of file
......@@ -28,6 +28,10 @@
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.save') }}
</button>
<a class="btn btn-danger" :disabled="submiting" href="{{ url()->previous() }}">
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.cancel') }}
</a>
</div>
</form>
......
......@@ -30,6 +30,10 @@
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.save') }}
</button>
<a class="btn btn-danger" :disabled="submiting" href="{{ url()->previous() }}">
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.cancel') }}
</a>
</div>
</form>
......
......@@ -28,6 +28,10 @@
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.save') }}
</button>
<a class="btn btn-danger" :disabled="submiting" href="{{ url()->previous() }}">
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.cancel') }}
</a>
</div>
</form>
......
......@@ -30,6 +30,10 @@
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.save') }}
</button>
<a class="btn btn-danger" :disabled="submiting" href="{{ url()->previous() }}">
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.cancel') }}
</a>
</div>
</form>
......
......@@ -11,26 +11,27 @@
<div class="form-group row align-items-center" :class="{'has-danger': errors.has('responsible_researcher'), 'has-success': fields.responsible_researcher && fields.responsible_researcher.valid }">
<label for="responsible_researcher" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.research-project.columns.responsible_researcher') }}</label>
<div :class="isFormLocalized ? 'col-md-4' : 'col-md-9 col-xl-8'">
<div>
<textarea class="form-control" v-model="form.responsible_researcher" v-validate="'required'" id="responsible_researcher" name="responsible_researcher"></textarea>
</div>
<input type="text" v-model="form.responsible_researcher" v-validate="'required'" @input="validate($event)" class="form-control" :class="{'form-control-danger': errors.has('responsible_researcher'), 'form-control-success': fields.responsible_researcher && fields.responsible_researcher.valid}" id="responsible_researcher" name="responsible_researcher" placeholder="{{ trans('admin.research-project.columns.responsible_researcher') }}">
<div v-if="errors.has('responsible_researcher')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('responsible_researcher') }}</div>
</div>
</div>
<div class="form-group row align-items-center" :class="{'has-danger': errors.has('department'), 'has-success': fields.department && fields.department.valid }">
<label for="department" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.research-project.columns.department') }}</label>
<div class="form-group row align-items-center" :class="{'has-danger': errors.has('data_type'), 'has-success': fields.data_type && fields.data_type.valid }">
<label for="data_type" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.research-project.columns.data_type') }}</label>
<div :class="isFormLocalized ? 'col-md-4' : 'col-md-9 col-xl-8'">
<input type="text" v-model="form.department" v-validate="'required'" @input="validate($event)" class="form-control" :class="{'form-control-danger': errors.has('department'), 'form-control-success': fields.department && fields.department.valid}" id="department" name="department" placeholder="{{ trans('admin.research-project.columns.department') }}">
<div v-if="errors.has('department')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('department') }}</div>
<multiselect v-model="form.data_type" :options='[ "Online Survey", "EEG", "Behavioral", "Simulation", "MRI", "Video" ]' placeholder="Select data type" :multiple="true"></multiselect>
<div v-if="errors.has('data_type')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('data_type') }}</div>
</div>
</div>
<div class="form-group row align-items-center" :class="{'has-danger': errors.has('data_type'), 'has-success': fields.data_type && fields.data_type.valid }">
<label for="data_type" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.research-project.columns.data_type') }}</label>
<div class="form-group row align-items-center" :class="{'has-danger': errors.has('department'), 'has-success': fields.department && fields.department.valid }">
<label for="department" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.research-project.columns.department') }}</label>
<div :class="isFormLocalized ? 'col-md-4' : 'col-md-9 col-xl-8'">
<input type="text" v-model="form.data_type" v-validate="'required'" @input="validate($event)" class="form-control" :class="{'form-control-danger': errors.has('data_type'), 'form-control-success': fields.data_type && fields.data_type.valid}" id="data_type" name="data_type" placeholder="{{ trans('admin.research-project.columns.data_type') }}">
<div v-if="errors.has('data_type')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('data_type') }}</div>
{{-- <input type="text" v-model="form.department" v-validate="'required'" @input="validate($event)" class="form-control" :class="{'form-control-danger': errors.has('department'), 'form-control-success': fields.department && fields.department.valid}" id="department" name="department" placeholder="{{ trans('admin.research-project.columns.department') }}">--}}
<multiselect v-model="form.department" :options='[ "ARC", "LIP", "CHM", "HoE" ]' placeholder="Select department" :multiple="false"></multiselect>
<div v-if="errors.has('department')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('department') }}</div>
</div>
</div>
......@@ -38,7 +39,7 @@
<label for="doi" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.research-project.columns.doi') }}</label>
<div :class="isFormLocalized ? 'col-md-4' : 'col-md-9 col-xl-8'">
<div>
<input type="text" class="form-control" v-model="form.doi" id="doi" name="doi">
<textarea class="form-control" v-model="form.doi" v-validate="''" id="doi" name="doi"></textarea>
</div>
<div v-if="errors.has('doi')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('doi') }}</div>
</div>
......
......@@ -28,6 +28,10 @@
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.save') }}
</button>
<a class="btn btn-danger" :disabled="submiting" href="{{ url()->previous() }}">
<i class="fa" :class="submiting ? 'fa-spinner' : 'fa-download'"></i>
{{ trans('brackets/admin-ui::admin.btn.cancel') }}
</a>
</div>
</form>
......
......@@ -58,7 +58,7 @@
<th></th>
</tr>
<tr v-show="(clickedBulkItemsCount > 0) || isClickedAll">
<td class="bg-bulk-info d-table-cell text-center" colspan="5">
<td class="bg-bulk-info d-table-cell text-center" colspan="6">
<span class="align-middle font-weight-light text-dark">{{ trans('brackets/admin-ui::admin.listing.selected_items') }} @{{ clickedBulkItemsCount }}. <a href="#" class="text-primary" @click="onBulkItemsClickedAll('/admin/research-projects')" v-if="(clickedBulkItemsCount < pagination.state.total)"> <i class="fa" :class="bulkCheckingAllLoader ? 'fa-spinner' : ''"></i> {{ trans('brackets/admin-ui::admin.listing.check_all_items') }} @{{ pagination.state.total }}</a> <span class="text-primary">|</span> <a
href="#" class="text-primary" @click="onBulkItemsClickedAllUncheck()">{{ trans('brackets/admin-ui::admin.listing.uncheck_all_items') }}</a> </span>
......@@ -77,7 +77,7 @@
</label>
</td>
<td>@{{ item.id }}</td>
<td>@{{ item.id }}</td>
<td>@{{ item.project_title }}</td>
<td>@{{ item.responsible_researcher }}</td>
<td>@{{ item.department }}</td>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment