Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0a76d33
update sidebar block
PhilReinking Sep 21, 2024
e12687d
wip logic
PhilReinking Sep 23, 2024
0d72fd0
wip
PhilReinking Sep 26, 2024
7e0d4da
wip
PhilReinking Oct 2, 2024
16bdf52
wip
PhilReinking Oct 4, 2024
d894986
fix linter
PhilReinking Oct 4, 2024
73c6596
add first draft of logic backend
PhilReinking Oct 4, 2024
e662c9c
load blocks logics from backend in workbench
PhilReinking Oct 4, 2024
7b23eda
wip
PhilReinking Oct 5, 2024
58f635e
wip
PhilReinking Oct 5, 2024
1904ad4
better rule ui
PhilReinking Oct 8, 2024
84f41b4
fix removing unsaved rule
PhilReinking Oct 10, 2024
b2a0ee3
show validation
PhilReinking Oct 11, 2024
4fdeac2
improve validation display
PhilReinking Oct 12, 2024
970198a
show id on storyboard block
PhilReinking Oct 12, 2024
200f0af
wip show rules in sidebar
PhilReinking Oct 14, 2024
89960d4
wip
PhilReinking Oct 17, 2024
e47d5d8
fix ui of block logic in sidebar
PhilReinking Oct 18, 2024
564353d
add new block menu to group
PhilReinking Oct 18, 2024
809cdf6
improve logic editor cancel
PhilReinking Oct 18, 2024
0f27add
fix eslint error
PhilReinking Oct 18, 2024
351ab7e
update action to also push docker on PR
PhilReinking Oct 18, 2024
2b28123
fix login
PhilReinking Oct 18, 2024
a46fb10
add login protection
PhilReinking Oct 20, 2024
9125513
wip frontend logic rules
PhilReinking Oct 24, 2024
b0ca8af
remove pre
PhilReinking Oct 24, 2024
74a978f
fix nested button markup
PhilReinking Oct 25, 2024
b1304ca
fix navigator and transition bug
PhilReinking Oct 25, 2024
98db4c9
add show hide logic evaluation
PhilReinking Oct 31, 2024
c5d5fe7
add goto settings for logic in sidebar
PhilReinking Nov 1, 2024
98aeed1
remove debug output
PhilReinking Nov 1, 2024
605cd46
fix bug with overridden logix
PhilReinking Nov 1, 2024
7fa1340
refactor hide show logic evaluation
PhilReinking Nov 1, 2024
f3ccfd2
further refactoring
PhilReinking Nov 1, 2024
9b9cb7f
add goto logic in conversation
PhilReinking Nov 1, 2024
8858079
add goto logic to conversation
PhilReinking Nov 1, 2024
b7793d4
fix prose classes
PhilReinking Feb 6, 2025
5794062
migrate to mise-en-place
PhilReinking Feb 6, 2025
84aa868
delete makefile
PhilReinking Feb 6, 2025
f64822a
remove unused import
PhilReinking Feb 6, 2025
aad188f
update packages
PhilReinking Feb 6, 2025
a6e9c09
fix conversation top level await
PhilReinking Feb 6, 2025
4618487
fix goto action
PhilReinking Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: ${{ github.event_name != 'pull_request' }}
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
Expand All @@ -48,6 +48,14 @@ jobs:
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
Expand All @@ -57,7 +65,7 @@ jobs:
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand Down
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ We are using [Laravel Sail](https://laravel.com/docs/master/sail) to develop Inp

- [Docker](https://www.docker.com/get-started/)
- [NodeJS](https://nodejs.org/) (v16 LTS preferred)
- [mise-en-place](https://mise.jdx.dev/) (for task automation)

### Download

Expand All @@ -39,10 +40,10 @@ cp .env.dev.example .env

### Running

Make sure that your Docker agent is running. There are several steps necessary to build the app for the first time. To simplify these tasks, we have a Makefile in place. Just run the following command, and all build steps will run automatically:
Make sure that your Docker agent is running. There are several steps necessary to build the app for the first time. To simplify these tasks, we use mise-en-place. Just run the following command, and all build steps will run automatically:

```bash
make up
mise task up
```

### Webpack (Mix)
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/Api/FormBlockLogicController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers\Api;

use App\Models\FormBlock;
use App\Models\FormBlockLogic;
use App\Http\Controllers\Controller;
use App\Http\Requests\FormBlockLogicRequest;

class FormBlockLogicController extends Controller
{
public function create(FormBlockLogicRequest $request, FormBlock $block)
{
return response()->json($block->formBlockLogics()->create($request->validated()), 201);
}

public function update(FormBlockLogicRequest $request, FormBlockLogic $logic)
{
return response()->json($logic->update($request->validated()));
}

public function delete(FormBlockLogic $logic)
{
$logic->delete();

return response()->json(null, 200);
}
}
50 changes: 50 additions & 0 deletions app/Http/Requests/FormBlockLogicRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class FormBlockLogicRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'conditions' => 'required|array',
'conditions.*.source' => 'required|string',
'conditions.*.operator' => 'required|string|in:equals,equalsNot,contains,containsNot,isLowerThan,isGreaterThan',
'conditions.*.value' => 'required|string',
'conditions.*.chainOperator' => 'required|string|in:and,or',
'action' => 'required|string|in:hide,show,goto',
'action_payload' => 'nullable|string',
'evaluate' => 'required|string|in:before,after',
];
}

public function messages()
{
return [
'name.required' => 'The name is required.',
'conditions.required' => 'At least one condition is required.',
'conditions.*.source.required' => 'The source block for your #:position condition is required.',
'conditions.*.value.required' => 'The value for your #:position condition is required.',
'conditions.*.operator.required' => 'The operator for the #:position condition is required.',
'conditions.*.chainOperator.required' => 'The chain operator for the #:position condition is required.',
'action.required' => 'The action is required.',
'evaluate.required' => 'The evaluate is required.',
];
}
}
26 changes: 26 additions & 0 deletions app/Http/Resources/PublicFormBlockLogicResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PublicFormBlockLogicResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->uuid,
'name' => $this->name,
'action' => $this->action,
'evaluate' => $this->evaluate,
'conditions' => $this->conditions,
'action_payload' => $this->action_payload,
];
}
}
3 changes: 3 additions & 0 deletions app/Http/Resources/PublicFormBlockResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\PublicFormBlockLogicResource;

class PublicFormBlockResource extends JsonResource
{
Expand All @@ -14,6 +15,7 @@ class PublicFormBlockResource extends JsonResource
*/
public function toArray($request)
{
$logics = $this->formBlockLogics;
$interactions = $this->activeInteractions;

if ($this->options && $this->options['randomize_responses'] === true) {
Expand All @@ -34,6 +36,7 @@ public function toArray($request)
'is_required' => $this->is_required,
'parent_block' => $this->parent_block,
'interactions' => PublicFormBlockInteractionResource::collection($interactions),
'logics' => PublicFormBlockLogicResource::collection($logics),
];
}
}
23 changes: 18 additions & 5 deletions app/Models/FormBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Models;

use App\Enums\FormBlockInteractionType;
use App\Enums\FormBlockType;
use App\Scopes\Sequence;
use Hashids\Hashids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Scopes\Sequence;
use Webpatser\Uuid\Uuid;
use App\Enums\FormBlockType;
use App\Models\FormBlockLogic;
use App\Enums\FormBlockInteractionType;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class FormBlock extends BaseModel
{
Expand All @@ -26,7 +27,7 @@ class FormBlock extends BaseModel

protected $guarded = [];

protected $with = ['formBlockInteractions'];
protected $with = ['formBlockInteractions', 'formBlockLogics'];

protected $casts = [
'is_required' => 'boolean',
Expand All @@ -38,10 +39,12 @@ class FormBlock extends BaseModel

protected $appends = [
'interactions',
'logics',
];

protected $hidden = [
'formBlockInteractions',
'formBlockLogics',
];

protected static function boot()
Expand Down Expand Up @@ -93,6 +96,11 @@ public function formBlockInteractions()
return $this->hasMany(FormBlockInteraction::class, 'form_block_id');
}

public function formBlockLogics()
{
return $this->hasMany(FormBlockLogic::class, 'form_block_id');
}

public function activeInteractions()
{
return $this->hasMany(FormBlockInteraction::class, 'form_block_id')
Expand All @@ -106,6 +114,11 @@ public function getInteractionsAttribute()
return $this->formBlockInteractions;
}

public function getLogicsAttribute()
{
return $this->formBlockLogics;
}

public function getSessionCountAttribute()
{
return $this->formSessionResponses()->selectRaw('COUNT(DISTINCT form_session_id) as count')->first()->count;
Expand Down
33 changes: 33 additions & 0 deletions app/Models/FormBlockLogic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Models;

use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class FormBlockLogic extends Model
{
use HasFactory;

protected $guarded = [];

protected $casts = [
'conditions' => 'array',
'action_payload' => 'array',
];

protected static function boot()
{
parent::boot();

self::creating(function ($model) {
$model->uuid = (string) Str::orderedUuid();
});
}

public function formBlock()
{
return $this->belongsTo(FormBlock::class);
}
}
36 changes: 36 additions & 0 deletions database/factories/FormBlockLogicFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Database\Factories;

use App\Models\FormBlock;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\FormBlockLogic>
*/
class FormBlockLogicFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->name(),
'action' => 'hide',
'evaluate' => 'before',
'conditions' => [
[
'source' => $this->faker->uuid,
'operator' => 'equals',
'value' => 'test',
'chainOperator' => 'and',
]
],
'action_payload' => [],
'form_block_id' => FormBlock::factory(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('form_block_logics', function (Blueprint $table) {
$table->bigIncrements('id');
$table->char('uuid', 36);
$table->string('name');
$table->json('conditions');
$table->string('action');
$table->json('actionPayload')->nullable();
$table->string('evaluate')->default('before');
$table->unsignedBigInteger('form_block_id');
$table->timestamps();
});
}
};
17 changes: 17 additions & 0 deletions database/migrations/2024_11_01_155436_fix_wrong_attribute_name.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('form_block_logics', function (Blueprint $table) {
$table->renameColumn('actionPayload', 'action_payload');
});
}
};
12 changes: 12 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tools]
node = "18"

[tasks.up]
run = [
"docker run --rm -u \"$(id -u):$(id -g)\" -v \"$(pwd):/var/www/html\" -w \"/var/www/html\" laravelsail/php83-composer:latest composer install --ignore-platform-reqs",
"./vendor/bin/sail up -d",
"./vendor/bin/sail artisan migrate",
"./vendor/bin/sail artisan key:generate",
"npm ci",
"npm run dev",
]
Loading