Commit cb116124 authored by Maik Messerschmidt's avatar Maik Messerschmidt
Browse files

Implemented inputs.edit

parent c87945c5
......@@ -8,6 +8,7 @@ use App\Logic\Decoder\Decoders;
use App\Logic\Encoder\Encoders;
use App\Http\Requests\StoreInput;
use App\Http\Requests\UpdateInput;
use App\Http\Requests\ImportInputs;
use Illuminate\Http\Request;
......@@ -166,9 +167,8 @@ class InputController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
public function edit(Input $input) {
return view('inputs.edit', ['input' => $input]);
}
/**
......@@ -178,9 +178,9 @@ class InputController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
public function update(UpdateInput $request, Input $input) {
$input->update($request->all());
return redirect()->route('inputs.index');
}
/**
......
<?php
namespace App\Http\Requests;
use App\Input;
use App\Http\Requests\StoreInput;
class UpdateInput extends StoreInput {
private $messages = [];
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
protected function prepareForValidation() : void {
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() {
return array_merge(parent::rules(), [
"id" => "required|unique:inputs,id,{$this->input->id}",
"id_length" => "",
]);
}
public function messages() {
return array_merge($this->messages, [
"data.j_s_o_n" => "Data payload must be valid JSON"
]);
}
}
@extends('layouts.app')
@section('content')
<h1>Upload new experiment input</h1>
{{ Form::model($input, [
'route' => ['inputs.update', $input],
'method' => 'patch'
]) }}
<div class="form-group">
{{ Form::label('id', 'Unique id', ['class' => 'control-label' ]) }}
{{ Form::text('id', old('id'), ['class' => 'form-control']) }}
<small id="id-help" class="form-text text-muted">
Unique id for this input data.
</small>
@error('id')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
{{ Form::label('max_uses', 'Maximum use count', ['class' => 'control-label' ]) }}
{{ Form::number('max_uses', old('max_uses', 1), ['min' => 0, 'class' => 'form-control']) }}
<small id="max_uses-help" class="form-text text-muted">
How often this input data can be used in total.
(Leave empty, for inifinite uses.)
</small>
@error('max_uses')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
{{ Form::label('group', 'Optional group name', ['class' => 'control-label' ]) }}
{{ Form::text('group', old('group'), ['class' => 'form-control']) }}
<small id="group-help" class="form-text text-muted">
This makes this input available by the given group name.
Useful, if you want to make multiple different inputs available via
the same URL.
</small>
@error('group')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
{{ Form::label('increments', 'Increment mode for the use count.', ['class' => 'control-label' ]) }}
{{ Form::select('increments', ['auto' => 'auto', 'manual' => 'manual', 'never' => 'never'], old('increments', 'auto'), ['class' => 'form-control']) }}
<small id="increments-help" class="form-text text-muted">
When to increment the use count:
<ul>
<li>auto - whenever the input data is requested</li>
<li>manual - when the experiment client requests the increment</li>
<li>never - never increment the use count</li>
</ul>
If you're unsure about this, you'll likely want 'auto'.
</small>
@error('increments')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
{{ Form::label('data', 'Input data payload', ['class' => 'control-label' ]) }}
{{ Form::textarea('data', old('data'), [
'placeholder' => 'Enter your data here',
'class' => 'form-control' ,
'cols' => 20,
'rows' =>10,
'required'
]) }}
@error('data')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="form-group">
{{ Form::label('format', 'Input data format', ['class' => 'control-label' ]) }}
{{ Form::select('format', ['json' => 'json', 'text' => 'text'], old('format'), ['class' => 'form-control']) }}
<small id="format-help" class="form-text text-muted">
This will run a quick check, whether the provided data is valid,
but otherwise have no effect on the saved input data.
</small>
@error('format')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<div class="row">
<div class="m-1">
{{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
{{ Form::close() }}
</div>
<div class="m-1">
<a href="{{ route('inputs.index') }}" class="btn btn-secondary">Cancel</a>
</div>
</div>
@endsection
......@@ -23,9 +23,13 @@
<td>{{ $input->max_uses ?? '∞'}}</td>
<td>{{ $input->increments }}</td>
<td>
<a href="{{ route('inputs.show', $input) }}"
<a href="{{ route('inputs.show', $input) }}"
title="Show the input data payload">
<i class="fa fa-eye"></i>
</a>
<a href="{{ route('inputs.edit', $input) }}"
title="Edit this input">
<i class="fa fa-edit"></i>
</a>
<a href="_blank" class="confirm-delete" title="Remove this entry"
......
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