forked from deck9/input
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b311de2
commit b5f46ca
Showing
13 changed files
with
188 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\Form; | ||
use App\Models\User; | ||
use App\Models\FormBlock; | ||
use App\Models\FormSession; | ||
use Illuminate\Support\Str; | ||
use App\Enums\FormBlockType; | ||
use Illuminate\Database\Seeder; | ||
use App\Models\FormBlockInteraction; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class SimpleFormSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
$user = User::first(); | ||
|
||
$form = Form::factory()->create([ | ||
'name' => 'Simple Form', | ||
'description' => 'This form is for testing purposes.', | ||
'brand_color' => '#000000', | ||
'user_id' => $user ? $user->id : User::factory()->create()->id, | ||
]); | ||
|
||
$sessions = FormSession::factory(5)->create([ | ||
'form_id' => $form | ||
]); | ||
|
||
FormBlock::factory()->create([ | ||
'message' => 'Block with no message', | ||
'form_id' => $form->id, | ||
]); | ||
|
||
$this->buildCheckbox($form, $sessions); | ||
$this->buildRadio($form, $sessions); | ||
$this->buildInput($form, $sessions, FormBlockType::short); | ||
$this->buildInput($form, $sessions, FormBlockType::number); | ||
$this->buildInput($form, $sessions, FormBlockType::email); | ||
$this->buildInput($form, $sessions, FormBlockType::phone); | ||
$this->buildInput($form, $sessions, FormBlockType::link); | ||
} | ||
|
||
public function buildCheckbox(Form $form, Collection $sessions) | ||
{ | ||
// build checkbox block | ||
$block = FormBlock::factory()->create([ | ||
'form_id' => $form->id, | ||
'type' => FormBlockType::checkbox, | ||
'message' => 'Checkbox block', | ||
]); | ||
|
||
$checkboxInteractions = FormBlockInteraction::factory(4)->create([ | ||
'type' => $block->getInteractionType(), | ||
'form_block_id' => $block->id, | ||
]); | ||
|
||
$sessions->each(function ($session) use ($block, $checkboxInteractions) { | ||
for ($i = rand(1, 3); $i > 0; $i--) { | ||
$action = $checkboxInteractions->shuffle()->shift(); | ||
|
||
$session->responses()->create([ | ||
'value' => $action->label, | ||
'form_block_id' => $block->id, | ||
'form_block_interaction_id' => $action->id, | ||
]); | ||
} | ||
}); | ||
} | ||
|
||
public function buildRadio(Form $form, Collection $sessions) | ||
{ | ||
// build checkbox block | ||
$block = FormBlock::factory()->create([ | ||
'form_id' => $form->id, | ||
'type' => FormBlockType::radio, | ||
'message' => 'Radio block', | ||
]); | ||
|
||
$checkboxInteractions = FormBlockInteraction::factory(4)->create([ | ||
'type' => $block->getInteractionType(), | ||
'form_block_id' => $block->id, | ||
]); | ||
|
||
$sessions->each(function ($session) use ($block, $checkboxInteractions) { | ||
$action = $checkboxInteractions->shuffle()->shift(); | ||
|
||
$session->responses()->create([ | ||
'value' => $action->label, | ||
'form_block_id' => $block->id, | ||
'form_block_interaction_id' => $action->id, | ||
]); | ||
}); | ||
} | ||
|
||
public function buildInput(Form $form, Collection $sessions, FormBlockType $type) | ||
{ | ||
// build checkbox block | ||
$block = FormBlock::factory()->create([ | ||
'form_id' => $form->id, | ||
'type' => $type, | ||
'message' => $type->value . ' block', | ||
]); | ||
|
||
$action = FormBlockInteraction::factory()->create([ | ||
'type' => $block->getInteractionType(), | ||
'form_block_id' => $block->id, | ||
]); | ||
|
||
$sessions->each(function ($session) use ($block, $action) { | ||
$session->responses()->create([ | ||
'value' => Str::random(16), | ||
'form_block_id' => $block->id, | ||
'form_block_interaction_id' => $action->id, | ||
]); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
resources/js/components/Factory/Results/BlockResultItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters