Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ARC-Support
public projects
lou-server
Commits
4c4d402a
Commit
4c4d402a
authored
Oct 01, 2021
by
Maik Messerschmidt
Browse files
Added admin input routes, index and create page (working).
parent
3e1de366
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/InputController.php
0 → 100644
View file @
4c4d402a
<?php
namespace
App\Http\Controllers
;
use
App\Input
;
use
Illuminate\Http\Request
;
use
App\Http\Requests\StoreInput
;
class
InputController
extends
Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public
function
index
()
{
return
view
(
'inputs.index'
,
[
"inputs"
=>
Input
::
without
(
'data'
)
->
get
()]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public
function
create
()
{
return
view
(
'inputs.create'
);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public
function
store
(
StoreInput
$request
)
{
Input
::
create
(
$request
->
all
());
return
redirect
()
->
route
(
'inputs.index'
);
}
/**
* Show form to import from CSV.
*/
public
function
show_csv_import
()
{
// return view('inputs.csv_import');
}
/**
* Do the csv import.
*/
public
function
csv_import
()
{
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
show
(
Input
$input
)
{
$json
=
json_decode
(
$input
->
data
);
if
(
$json
)
return
response
()
->
json
(
$json
);
else
return
$input
->
data
;
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
edit
(
$id
)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
update
(
Request
$request
,
$id
)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
destroy
(
$id
)
{
//
}
}
app/Http/Requests/StoreInput.php
0 → 100644
View file @
4c4d402a
<?php
namespace
App\Http\Requests
;
use
App\Input
;
use
Illuminate\Validation\Rule
;
use
Illuminate\Foundation\Http\FormRequest
;
use
Str
;
class
StoreInput
extends
FormRequest
{
private
$messages
=
[];
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
protected
function
prepareForValidation
()
:
void
{
if
(
$this
->
id
===
null
)
{
$this
->
merge
([
// add an id, if none was provided
'id'
=>
Str
::
random
(
$this
->
id_length
),
]);
$this
->
messages
[
'id.unique'
]
=
'Generated uid has already been taken. '
.
'Try again or increase uid length.'
;
}
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
"id"
=>
'required|unique:inputs'
,
"id_length"
=>
'required|integer|gt:0'
,
"max_uses"
=>
'integer|gte:0'
,
"increments"
=>
Rule
::
in
(
Input
::
INCREMENT_MODES
),
"data"
=>
$this
->
get
(
'format'
)
===
'json'
?
'required|JSON'
:
'required'
];
}
public
function
messages
()
{
return
array_merge
(
$this
->
messages
,
[
"data.j_s_o_n"
=>
"Data payload must be valid JSON"
]);
}
}
app/Input.php
0 → 100644
View file @
4c4d402a
<?php
namespace
App
;
use
Illuminate\Database\Eloquent\Model
;
class
Input
extends
Model
{
// This tells Eloquent, that we're using uids instead of incrementing integers.
// https://laravel.com/docs/6.x/eloquent#eloquent-model-conventions
public
$incrementing
=
false
;
// Choices for 'increments'
const
INCREMENT_MODES
=
[
'auto'
,
'manual'
,
'never'
,
];
protected
$fillable
=
[
'id'
,
'increments'
,
'uses'
,
'max_uses'
,
'listed'
,
'data'
,
];
}
resources/views/inputs/create.blade.php
0 → 100644
View file @
4c4d402a
@
extends
(
'layouts.app'
)
@
section
(
'content'
)
<
h1
>
Upload
experiment
data
as
CSV
</
h1
>
{{
Form
::
open
([
'route'
=>
'inputs.store'
])
}}
<
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
.
(
Leaving
this
empty
will
generate
one
for
you
.
)
</
small
>
@
error
(
'id'
)
<
div
class
=
"text-danger"
>
{{
$message
}}
</
div
>
@
enderror
</
div
>
<
div
class
=
"form-group"
>
{{
Form
::
label
(
'id_length'
,
'Unique id length'
,
[
'class'
=>
'control-label'
])
}}
{{
Form
::
number
(
'id_length'
,
old
(
'id_length'
,
8
),
[
'min'
=>
1
,
'class'
=>
'form-control'
])
}}
<
small
id
=
"id_length-help"
class
=
"form-text text-muted"
>
The
length
of
the
UID
,
if
generated
.
</
small
>
@
error
(
'id_length'
)
<
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
(
'listed'
,
'Should this entry be listed?'
,
[
'class'
=>
'control-label'
])
}}
{{
Form
::
select
(
'listed'
,
[
true
=>
'listed'
,
false
=>
'unlisted'
],
old
(
'listed'
),
[
'min'
=>
0
,
'class'
=>
'form-control'
])
}}
<
small
id
=
"max_uses-help"
class
=
"form-text text-muted"
>
Decide
,
whether
this
entry
should
be
listed
.
<
ul
>
<
li
>
A
'listed'
entry
can
be
requested
by
the
client
without
knowledge
of
the
unique
id
by
simply
asking
the
server
for
"some input"
.
</
li
>
<
li
>
An
'unlisted'
entry
can
only
be
requested
by
knowing
the
unique
id
.
</
li
>
</
ul
>
Note
:
This
doesn
't change, whether this entry is visible in the admin interface.
</small>
@error('
max_uses
')
<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('
Create
', ['
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
resources/views/inputs/index.blade.php
0 → 100644
View file @
4c4d402a
@
extends
(
'layouts.app'
)
@
section
(
'content'
)
<
table
class
=
"table"
>
<
thead
>
<
tr
>
<
th
scope
=
"col"
>
uid
</
th
>
<
th
scope
=
"col"
>
uploaded
on
</
th
>
<
th
scope
=
"col"
>
uses
</
th
>
<
th
scope
=
"col"
>
max
uses
</
th
>
<
th
scope
=
"col"
>
listed
</
th
>
<
th
scope
=
"col"
>
use
count
increments
</
th
>
<
th
scope
=
"col"
><!--
actions
column
--></
th
>
</
tr
>
</
thead
>
<
tbody
>
@
foreach
(
$inputs
as
$input
)
<
tr
>
<
td
>
{{
$input
->
id
}}
</
td
>
<
td
>
{{
$input
->
created_at
}}
</
td
>
<
td
>
{{
$input
->
uses
}}
</
td
>
<
td
>
{{
$input
->
max_uses
}}
</
td
>
<
td
>
{{
$input
->
listed
?
"yes"
:
"no"
}}
</
td
>
<
td
>
{{
$input
->
increments
}}
</
td
>
<
td
>
<
a
href
=
"{{ route('inputs.show',
$input
) }}"
title
=
"Show the input data payload"
>
<
i
class
=
"fa fa-eye"
></
i
>
</
a
>
<
a
href
=
"_blank"
class
=
"confirm-delete"
title
=
"Remove these results"
data
-
form
-
id
=
"remove-form-
{
{$input->id}
}
"
data
-
message
=
"Do you really want to delete this result?"
>
<
i
class
=
"fa fa-remove"
></
i
>
</
a
>
{{
Form
::
open
([
'url'
=>
route
(
'inputs.destroy'
,
$input
),
'method'
=>
'delete'
,
'style'
=>
'display: none'
,
'id'
=>
"remove-form-
{
$input
->
id
}
"
])
}}
{{
Form
::
submit
(
'send'
)
}}
{{
Form
::
close
()
}}
</
td
>
</
tr
>
@
endforeach
</
tbody
>
</
table
>
<
a
href
=
"{{ route('inputs.create')}}"
>
Create
a
new
entry
</
a
>
@
endsection
resources/views/layouts/app.blade.php
View file @
4c4d402a
...
...
@@ -36,7 +36,7 @@
<ul
class=
"navbar-nav mr-auto"
>
@auth
<li
class=
"nav-item"
>
<a
class=
"nav-link"
href=
"{{ route('
experimen
ts.index') }}"
>
Experimen
t data
</a>
<a
class=
"nav-link"
href=
"{{ route('
inpu
ts.index') }}"
>
Manage inpu
t data
</a>
</li>
<li
class=
"nav-item"
>
...
...
routes/web.php
View file @
4c4d402a
...
...
@@ -22,6 +22,13 @@ Route::middleware(['web', 'auth'])->group(function() {
->
name
(
'experiments.reset'
);
Route
::
resource
(
'/admin/experiments'
,
'ExperimentController'
);
Route
::
get
(
'/admin/inputs/csv-import'
,
'InputController@show_csv_import'
)
->
name
(
'inputs.show_csv_import'
);
Route
::
post
(
'/admin/inputs/csv-import'
,
'InputController@csv_import'
)
->
name
(
'inputs.csv_import'
);
Route
::
resource
(
'/admin/inputs'
,
'InputController'
);
Route
::
get
(
'/admin/results/show-json/{result}'
,
'ResultController@showJson'
)
->
name
(
'results.show-json'
);
Route
::
get
(
'/admin/results/show-all-csv'
,
'ResultController@showAllCSV'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment