From 6367967e2e49a1d60b7b9f7ed75999c1d4219575 Mon Sep 17 00:00:00 2001 From: Giovanni Stroppa Date: Sat, 12 Feb 2022 01:13:39 -0300 Subject: [PATCH 1/5] 71 Implements migrations for fields and form_fields - updates documents table --- ...21_10_16_173902_create_documents_table.php | 1 + .../2022_01_23_041212_create_forms_table.php | 34 +++++++++++++++++ ..._01_23_043110_create_form_fields_table.php | 37 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 database/migrations/2022_01_23_041212_create_forms_table.php create mode 100644 database/migrations/2022_01_23_043110_create_form_fields_table.php diff --git a/database/migrations/2021_10_16_173902_create_documents_table.php b/database/migrations/2021_10_16_173902_create_documents_table.php index d0d940a..f5ddfe7 100644 --- a/database/migrations/2021_10_16_173902_create_documents_table.php +++ b/database/migrations/2021_10_16_173902_create_documents_table.php @@ -18,6 +18,7 @@ public function up() $table->text('file_path'); $table->text('content'); $table->unsignedBigInteger('organization_id'); + $table->foreign('organization_id')->references('id')->on('organizations'); $table->timestamps(); }); } diff --git a/database/migrations/2022_01_23_041212_create_forms_table.php b/database/migrations/2022_01_23_041212_create_forms_table.php new file mode 100644 index 0000000..6c5a1cc --- /dev/null +++ b/database/migrations/2022_01_23_041212_create_forms_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('slug'); + $table->unsignedBigInteger('organization_id'); + $table->foreign('organization_id')->references('id')->on('organizations'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('forms'); + } +} diff --git a/database/migrations/2022_01_23_043110_create_form_fields_table.php b/database/migrations/2022_01_23_043110_create_form_fields_table.php new file mode 100644 index 0000000..4ffd5e8 --- /dev/null +++ b/database/migrations/2022_01_23_043110_create_form_fields_table.php @@ -0,0 +1,37 @@ +id(); + $table->string('slug'); + $table->string('label'); + $table->string('widget'); + $table->json('ui_data')->nullable(); + $table->unsignedBigInteger('form_id'); + $table->foreign('form_id')->references('id')->on('forms'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('form_fields'); + } +} From a06541a682201e4ad04cc4e345c8c5ed31791965 Mon Sep 17 00:00:00 2001 From: Giovanni Stroppa Date: Sat, 12 Feb 2022 01:16:19 -0300 Subject: [PATCH 2/5] 71 Implements seeders for forms and form_fileds - updates DatabaseSeeder --- database/seeders/DatabaseSeeder.php | 2 + database/seeders/FormFieldSeeder.php | 254 +++++++++++++++++++++++++++ database/seeders/FormSeeder.php | 45 +++++ 3 files changed, 301 insertions(+) create mode 100644 database/seeders/FormFieldSeeder.php create mode 100644 database/seeders/FormSeeder.php diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 38fb67c..1c60f80 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -26,5 +26,7 @@ public function run() $this->call(\Database\Seeders\IssuesSeeder::class); $this->call(\Database\Seeders\CardSeeder::class); $this->call(\Database\Seeders\NewsSeeder::class); + $this->call(\Database\Seeders\FormSeeder::class); + $this->call(\Database\Seeders\FormFieldSeeder::class); } } diff --git a/database/seeders/FormFieldSeeder.php b/database/seeders/FormFieldSeeder.php new file mode 100644 index 0000000..e324fb7 --- /dev/null +++ b/database/seeders/FormFieldSeeder.php @@ -0,0 +1,254 @@ + 'subject', + 'label' => 'Assunto', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '1', + ], + [ + 'slug' => 'date_document', + 'label' => 'Data da edicão', + 'widget' => FormField::DATETIME_WIDGET, + 'ui_data' => '', + 'form_id' => '1', + ], + [ + 'slug' => 'duration_document', + 'label' => 'Duração', + 'widget' => FormField::DATETIME_WIDGET, + 'ui_data' => '', + 'form_id' => '1', + ], + [ + 'slug' => 'abstract', + 'label' => 'Resumo', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '1', + ], + [ + 'slug' => 'comment', + 'label' => 'Comentário', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '1', + ], + [ + 'slug' => 'document', + 'label' => 'Documento', + 'widget' => FormField::SELECT_WIDGET, + 'ui_data' => '', + 'form_id' => '1', + ], + [ + 'slug' => 'content', + 'label' => 'Conteúdo', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '2', + ], + [ + 'slug' => 'feedback-admin', + 'label' => 'Comentário do editor', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '2', + ], + [ + 'slug' => 'feedback-admin-status', + 'label' => 'Status da avaliação do editor', + 'widget' => FormField::SELECT_WIDGET, + 'ui_data' => '', + 'form_id' => '2', + ], + [ + 'slug' => 'title', + 'label' => 'Título da notícia', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '3', + ], + [ + 'slug' => 'subtitle', + 'label' => 'Subtítulo da notícia', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '3', + ], + [ + 'slug' => 'content', + 'label' => 'Conteúdo', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '3', + ], + [ + 'slug' => 'status', + 'label' => 'Status', + 'widget' => FormField::SELECT_WIDGET, + 'ui_data' => '', + 'form_id' => '3', + ], + [ + 'slug' => 'name', + 'label' => 'Nome', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '4', + ], + [ + 'slug' => 'email', + 'label' => 'Email', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '4', + ], + [ + 'slug' => 'password', + 'label' => 'Senha', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '4', + ], + [ + 'slug' => 'subject', + 'label' => 'Assunto', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '5', + ], + [ + 'slug' => 'date_document', + 'label' => 'Data da edicão', + 'widget' => FormField::DATETIME_WIDGET, + 'ui_data' => '', + 'form_id' => '5', + ], + [ + 'slug' => 'duration_document', + 'label' => 'Duração', + 'widget' => FormField::DATETIME_WIDGET, + 'ui_data' => '', + 'form_id' => '5', + ], + [ + 'slug' => 'abstract', + 'label' => 'Resumo', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '5', + ], + [ + 'slug' => 'comment', + 'label' => 'Comentário', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '5', + ], + [ + 'slug' => 'document', + 'label' => 'Documento', + 'widget' => FormField::SELECT_WIDGET, + 'ui_data' => '', + 'form_id' => '5', + ], + [ + 'slug' => 'content', + 'label' => 'Conteúdo', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '6', + ], + [ + 'slug' => 'feedback-admin', + 'label' => 'Comentário do editor', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '6', + ], + [ + 'slug' => 'feedback-admin-status', + 'label' => 'Status da avaliação do editor', + 'widget' => FormField::SELECT_WIDGET, + 'ui_data' => '', + 'form_id' => '6', + ], + [ + 'slug' => 'title', + 'label' => 'Título da notícia', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '7', + ], + [ + 'slug' => 'subtitle', + 'label' => 'Subtítulo da notícia', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '7', + ], + [ + 'slug' => 'content', + 'label' => 'Conteúdo', + 'widget' => FormField::TEXT_AREA_WIDGET, + 'ui_data' => '', + 'form_id' => '7', + ], + [ + 'slug' => 'status', + 'label' => 'Status', + 'widget' => FormField::SELECT_WIDGET, + 'ui_data' => '', + 'form_id' => '7', + ], + [ + 'slug' => 'name', + 'label' => 'Nome', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '8', + ], + [ + 'slug' => 'email', + 'label' => 'Email', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '8', + ], + [ + 'slug' => 'password', + 'label' => 'Senha', + 'widget' => FormField::TEXT_WIDGET, + 'ui_data' => '', + 'form_id' => '8', + ], + ]; + + public function run() + { + foreach (self::FIELDS as $field) + { + $form = FormField::build($field['slug'], $field['label'], $field['widget'], $field['form_id']); + $form->ui_data = $field['ui_data']; + $form->save(); + } + } +} diff --git a/database/seeders/FormSeeder.php b/database/seeders/FormSeeder.php new file mode 100644 index 0000000..4c01a72 --- /dev/null +++ b/database/seeders/FormSeeder.php @@ -0,0 +1,45 @@ + 'card', + ], + [ + 'slug' => 'contribution', + ], + [ + 'slug' => 'news', + ], + [ + 'slug' => 'user', + ], + ]; + foreach ($forms as $formData) + { + $organization = Organization::find(1); + $form = Form::build($formData['slug'], $organization); + $form->save(); + } + foreach ($forms as $formData) + { + $organization = Organization::find(2); + $form = Form::build($formData['slug'], $organization); + $form->save(); + } + } +} From 9cb975288d338940821ea6711087b6a21a78fdab Mon Sep 17 00:00:00 2001 From: Giovanni Stroppa Date: Sat, 12 Feb 2022 01:22:21 -0300 Subject: [PATCH 3/5] 71 Implements Form FormField models - updates organization --- app/Models/Form.php | 37 +++++++++++++++++++++++++++++++ app/Models/FormField.php | 44 +++++++++++++++++++++++++++++++++++++ app/Models/Organization.php | 5 +++++ 3 files changed, 86 insertions(+) create mode 100644 app/Models/Form.php create mode 100644 app/Models/FormField.php diff --git a/app/Models/Form.php b/app/Models/Form.php new file mode 100644 index 0000000..8ab9879 --- /dev/null +++ b/app/Models/Form.php @@ -0,0 +1,37 @@ +where('organization_id', $organization->id) + ->first(); + + if (!$form) + { + $form = new self; + $form->slug = $slug; + $form->organization_id = $organization->id; + } + + return $form; + } + + public function formFields(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(\App\Models\FormField::class); + } +} diff --git a/app/Models/FormField.php b/app/Models/FormField.php new file mode 100644 index 0000000..dcdbeca --- /dev/null +++ b/app/Models/FormField.php @@ -0,0 +1,44 @@ + 'array' + ]; + + static public function build(?string $slug = null, ?string $label = null, ?string $widget = null, ?string $form_id = null): self + { + $formField = self::where('slug', $slug) + ->where('label', $label) + ->where('widget', $widget) + ->where('form_id', $form_id) + ->first(); + + if (!$formField) + { + $formField = new self; + $formField->slug = $slug; + $formField->label = $label; + $formField->widget = $widget; + $formField->form_id = $form_id; + } + + return $formField; + } + +} diff --git a/app/Models/Organization.php b/app/Models/Organization.php index 5e04965..3d4f38a 100644 --- a/app/Models/Organization.php +++ b/app/Models/Organization.php @@ -35,6 +35,11 @@ public function cards(): \Illuminate\Database\Eloquent\Relations\HasMany return $this->hasMany(\App\Models\Card::class); } + public function forms(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(\App\Models\Form::class); + } + public function news(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(\App\Models\News::class); From 07918612448824af39e9abc65c6599e3385e1066 Mon Sep 17 00:00:00 2001 From: Giovanni Stroppa Date: Sat, 12 Feb 2022 01:23:58 -0300 Subject: [PATCH 4/5] 71 Implements Form and FormField controllers --- app/Http/Controllers/FormController.php | 85 ++++++++++++++++++++ app/Http/Controllers/FormFieldController.php | 85 ++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 app/Http/Controllers/FormController.php create mode 100644 app/Http/Controllers/FormFieldController.php diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php new file mode 100644 index 0000000..db6fa9d --- /dev/null +++ b/app/Http/Controllers/FormController.php @@ -0,0 +1,85 @@ + Date: Sat, 12 Feb 2022 01:38:53 -0300 Subject: [PATCH 5/5] 71 Implements Form and FormFields Resource --- app/Http/Resources/FormFieldsResource.php | 29 +++++++++++++++++++++++ app/Http/Resources/FormsResource.php | 26 ++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 app/Http/Resources/FormFieldsResource.php create mode 100644 app/Http/Resources/FormsResource.php diff --git a/app/Http/Resources/FormFieldsResource.php b/app/Http/Resources/FormFieldsResource.php new file mode 100644 index 0000000..c8e7bd8 --- /dev/null +++ b/app/Http/Resources/FormFieldsResource.php @@ -0,0 +1,29 @@ + $this->id, + 'type' => 'FormFields', + 'attributes' => [ + 'slug' => $this->slug, + 'label' => $this->label, + 'widget' => $this->widget, + 'ui_data' => $this->ui_data, + 'form_id' => $this->form_id, + ] + ]; + } +} diff --git a/app/Http/Resources/FormsResource.php b/app/Http/Resources/FormsResource.php new file mode 100644 index 0000000..711929a --- /dev/null +++ b/app/Http/Resources/FormsResource.php @@ -0,0 +1,26 @@ + $this->id, + 'type' => 'Forms', + 'attributes' => [ + 'slug' => $this->slug, + 'organization_id' => $this->organization_id, + ] + ]; + } +}