From 1f50faaea70b58d26d3f67b2d78c5712c76daf5f Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 12 Jul 2020 19:36:12 +0100 Subject: [PATCH] Add ability to preview application --- app/Http/Controllers/FormController.php | 9 ++- app/View/Components/Form.php | 33 ++++++++ public/img/preview.svg | 1 + resources/views/components/form.blade.php | 32 ++++++++ .../administration/formpreview.blade.php | 79 +++++++++++++++++++ .../dashboard/administration/forms.blade.php | 2 +- .../application-rendering/apply.blade.php | 32 +------- routes/web.php | 3 + 8 files changed, 159 insertions(+), 32 deletions(-) create mode 100644 app/View/Components/Form.php create mode 100644 public/img/preview.svg create mode 100644 resources/views/components/form.blade.php create mode 100644 resources/views/dashboard/administration/formpreview.blade.php diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index bc95730..deeeee0 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -87,7 +87,7 @@ class FormController extends Controller { $deletable = false; } - + if ($deletable) { $form->delete(); @@ -103,4 +103,11 @@ class FormController extends Controller } + public function preview(Request $request, Form $form) + { + return view('dashboard.administration.formpreview') + ->with('form', json_decode($form->formStructure, true)) + ->with('title', $form->formName); + } + } diff --git a/app/View/Components/Form.php b/app/View/Components/Form.php new file mode 100644 index 0000000..06e868d --- /dev/null +++ b/app/View/Components/Form.php @@ -0,0 +1,33 @@ +disableFields = $disableFields; + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\View\View|string + */ + public function render() + { + return view('components.form'); + } +} diff --git a/public/img/preview.svg b/public/img/preview.svg new file mode 100644 index 0000000..008b3f5 --- /dev/null +++ b/public/img/preview.svg @@ -0,0 +1 @@ +design_feedback \ No newline at end of file diff --git a/resources/views/components/form.blade.php b/resources/views/components/form.blade.php new file mode 100644 index 0000000..41e10b8 --- /dev/null +++ b/resources/views/components/form.blade.php @@ -0,0 +1,32 @@ +@foreach($form['fields'] as $fieldName => $field) + + @switch ($field['type']) + + @case('textarea') + +
+ + + + +
+ + @break + + @case('textbox') + +
+ + + + + +
+ + @break + + @endswitch + +@endforeach diff --git a/resources/views/dashboard/administration/formpreview.blade.php b/resources/views/dashboard/administration/formpreview.blade.php new file mode 100644 index 0000000..3c00ddd --- /dev/null +++ b/resources/views/dashboard/administration/formpreview.blade.php @@ -0,0 +1,79 @@ +@extends('adminlte::page') + +@section('title', 'Raspberry Network | Application Form Preview') + +@section('content_header') + +

Administration / Form Builder / Preview

+ +@stop + + +@section('js') + + + +@stop + + +@section('content') + +
+ +
+ + Form preview illustration + +
+ +
+ +
+ +
+
+ +
This is how your form looks like to applicants
+ +

+ You may edit it and add more fields later. +

+ +
+
+ +
+ +
+ +
+ +
+ +
+ +

{{ $title }}'s form

+ +
+ +
+ + @component('components.form', ['form' => $form, 'disableFields' => true]) + + @endcomponent + +
+ + + +
+ +
+ +
+ +@stop diff --git a/resources/views/dashboard/administration/forms.blade.php b/resources/views/dashboard/administration/forms.blade.php index 8505dcc..2ddf00b 100644 --- a/resources/views/dashboard/administration/forms.blade.php +++ b/resources/views/dashboard/administration/forms.blade.php @@ -59,7 +59,7 @@ - + diff --git a/resources/views/dashboard/application-rendering/apply.blade.php b/resources/views/dashboard/application-rendering/apply.blade.php index 236b520..5d57f2b 100644 --- a/resources/views/dashboard/application-rendering/apply.blade.php +++ b/resources/views/dashboard/application-rendering/apply.blade.php @@ -93,38 +93,10 @@
@csrf - @foreach($preprocessedForm['fields'] as $fieldName => $field) - @switch ($field['type']) + @component('components.form', ['form' => $preprocessedForm, 'disableFields' => false]) - @case('textarea') - -
- - - - -
- - @break - - @case('textbox') - -
- - - - - -
- - @break - - @endswitch - - @endforeach + @endcomponent
diff --git a/routes/web.php b/routes/web.php index d3e88cc..05681b8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -194,6 +194,9 @@ Route::group(['middleware' => ['auth', 'forcelogout']], function(){ Route::get('forms', 'FormController@index') ->name('showForms'); + Route::get('forms/preview/{form}', 'FormController@preview') + ->name('previewForm'); + Route::get('devtools', 'DevToolsController@index') ->name('devTools');