Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 2, 2023
1 parent 5f18b68 commit 9a33920
Show file tree
Hide file tree
Showing 137 changed files with 999 additions and 1,603 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<form {{ $attrs }}>
<form method="POST" action="{{ $url }}">
@csrf
@method($method)
<div class="form-group-stack form-group-stack--bordered form-group-container">
@foreach($fields as $field)
{!! $field !!}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class="form-group--row form-group--row:vertical-start"
<div class="editor">
<template x-if="editor()">
<div class="editor__controls">
@include('root::form.fields.editor.heading')
@include('root::form.fields.editor.format')
@include('root::form.fields.editor.align')
@include('root::form.fields.editor.list')
@include('root::form.fields.editor.link')
@include('root::fields.editor.heading')
@include('root::fields.editor.format')
@include('root::fields.editor.align')
@include('root::fields.editor.list')
@include('root::fields.editor.link')
@isset($media)
{!! $media !!}
@endisset
@include('root::form.fields.editor.blocks')
@include('root::form.fields.editor.history')
@include('root::fields.editor.blocks')
@include('root::fields.editor.history')
</div>
</template>
<div class="editor__body" x-ref="editor"></div>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<button
type="button"
class="btn btn--primary btn--icon"
x-bind:disabled="processing || options.length >= {{ $max }}"
x-bind:disabled="processing || options.length >= {{ $max ?: 'Infinity' }}"
x-on:click="add"
>
{{ $addNewLabel }}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 0 additions & 27 deletions resources/views/form/form.blade.php

This file was deleted.

32 changes: 29 additions & 3 deletions resources/views/resources/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,40 @@

{{-- Content --}}
@section('content')
{!! $form !!}
@if($errors->isNotEmpty())
<x-root::alert type="danger">
{{ __('Some error occurred when submitting the form!') }}
</x-root::alert>
@endif

<form id="{{ $key }}" method="POST" action="{{ $action }}" autocomplete="off">
@csrf
@method($method)

<div class="l-row l-row--sidebar">
<div class="l-row__column">
<div class="app-card app-card--edit">
<div class="app-card__header">
<h2 class="app-card__title">General</h2>
</div>
<div class="app-card__body">
<div class="form-group-stack form-group-stack--bordered form-group-container">
@foreach($fields as $field)
{!! $field !!}
@endforeach
</div>
</div>
</div>
</div>
</div>
</form>

<div class="app-actions app-actions--sidebar">
<div class="app-actions__column">
<button type="submit" class="btn btn--primary" form="{{ $form->getAttribute('id') }}">Save</button>
<button type="submit" class="btn btn--primary" form="{{ $key }}">Save</button>
<button class="btn btn--light">Cancel</button>
</div>
@if($form->model->exists)
@if($model->exists)
<div class="app-actions__column">
<form method="POST" action="#">
@csrf
Expand Down
2 changes: 1 addition & 1 deletion resources/views/resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
</div>
@endif

{!! $table !!}
@include('root::resources.table.table')
@endsection
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<form {{ $attrs }}>
@if($search)
{!! $search !!}
@endif
@if(! empty($fields))
<form method="GET" action="{{ URL::full() }}" id="{{ $key }}-filters" class="app-card__actions">
@if(! empty($filters))
<div class="data-table-filter" x-data="{ open: false }" x-on:click.outside="open = false">
<button
type="button"
Expand All @@ -11,22 +8,22 @@ class="btn btn--light btn--icon btn--counter data-table-filter__toggle"
x-on:click="open = ! open"
>
<x-root::icon name="filter" class="btn__icon" />
@if($attrs->get('data-active'))
<span class="btn__counter">{{ $attrs->get('data-active') }}</span>
@if($activeFilters > 0)
<span class="btn__counter">{{ $activeFilters }}</span>
@endif
</button>
<div class="context-menu context-menu--inline-end" x-bind:class="{ 'is-open': open }">
<div class="form-group-stack form-group-stack--bordered form-group-container">
@foreach($fields as $field)
{!! $field !!}
@foreach($filters as $filter)
{!! $filter !!}
@endforeach
<div class="data-table-filter__actions">
<button type="submit" class="btn btn--primary btn--sm">
{{ __('Filter') }}
</button>
<button type="reset" class="btn btn--light btn--sm">
<a href="{{ $url }}" class="btn btn--light btn--sm">
{{ __('Reset') }}
</button>
</a>
</div>
</div>
</div>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="app-card" x-data="{ selection: [], all: false }">
<div class="app-card__header">
<h2 class="app-card__title">{{ $title }} </h2>
{!! $form !!}
<h2 class="app-card__title">{{ $title }}</h2>
@include('root::resources.table.filters')
</div>
<div class="app-card__body">
<div class="data-table">
Expand All @@ -16,9 +16,9 @@
</tr>
</thead>
<tbody>
@foreach($items as $item)
@foreach($data as $row)
<tr>
@foreach($item['cells'] as $cell)
@foreach($row['cells'] as $cell)
{!! $cell !!}
@endforeach
</tr>
Expand All @@ -29,30 +29,30 @@
<div class="data-table__footer">
<div class="data-table__footer-column">
<div class="form-group">
<label class="sr-only" for="{{ $attrs->get('id') }}:per_page">
<label class="sr-only" for="{{ $key }}:per_page">
{{ __('Number of results') }}
</label>
<select
form="{{ $form->getAttribute('id') }}"
form="{{ $key }}"
class="form-control form-control--sm"
id="{{ $attrs->get('id') }}:per_page"
name="{{ $attrs->get('id') }}:per_page"
id="{{ $key }}:per_page"
name="{{ $key }}:per_page"
>
@foreach($perPageOptions as $option)
<option value="{{ $option }}" @selected($option === $items->perPage())>
<option value="{{ $option }}" @selected($option === $data->perPage())>
{{ $option }}
</option>
@endforeach
@if(! in_array($items->perPage(), $perPageOptions))
<option value="{{ $items->perPage() }}" selected>
{{ __('Custom (:perPage)', ['perPage' => $items->perPage()]) }}
@if(! in_array($data->perPage(), $perPageOptions))
<option value="{{ $data->perPage() }}" selected>
{{ __('Custom (:perPage)', ['perPage' => $data->perPage()]) }}
</option>
@endif
</select>
</div>
<p>{{ __('Showing :from to :to of :total results', ['from' => $items->firstItem(), 'to' => $items->lastItem(), 'total' => $items->total()]) }}</p>
<p>{{ __('Showing :from to :to of :total results', ['from' => $data->firstItem(), 'to' => $data->lastItem(), 'total' => $data->total()]) }}</p>
</div>
{!! $items->links('root::table.pagination') !!}
{!! $data->links('root::resources.table.pagination') !!}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
Route::apiResource('notifications', NotificationsController::class)->except(['store']);

// Resource Fields
Route::any('/{resource}/form/fields/{field}', ResourceFieldController::class)->where('field', '.*');
Route::any('/{resource}/fields/{field}', ResourceFieldController::class)->where('field', '.*');
90 changes: 59 additions & 31 deletions src/Table/Actions/Action.php → src/Actions/Action.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php

namespace Cone\Root\Table\Actions;
namespace Cone\Root\Actions;

use Cone\Root\Form\Form;
use Cone\Root\Interfaces\AsForm;
use Cone\Root\Fields\Field;
use Cone\Root\Interfaces\Form;
use Cone\Root\Support\Alert;
use Cone\Root\Support\Element;
use Cone\Root\Table\Table;
use Cone\Root\Traits\AsForm;
use Cone\Root\Traits\Authorizable;
use Cone\Root\Traits\Makeable;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\Response;

abstract class Action extends Element implements AsForm, Responsable
abstract class Action extends Element implements Form, Responsable
{
use AsForm;
use Authorizable;
use Makeable;

Expand All @@ -39,17 +40,14 @@ abstract class Action extends Element implements AsForm, Responsable
protected bool $confirmable = false;

/**
* The table instance.
* The Eloquent query.
*/
protected Table $table;
protected ?Builder $query = null;

/**
* Create a new action instance.
* The API URI.
*/
public function __construct(Table $table)
{
$this->table = $table;
}
protected ?string $apiUri = null;

/**
* Handle the action.
Expand Down Expand Up @@ -85,7 +83,45 @@ public function getName(): string
*/
public function getModalKey(): string
{
return sprintf('%s-action-%s', $this->table->getAttribute('id'), $this->getKey());
return sprintf('action-%s', $this->getKey());
}

/**
* Set the API URI.
*/
public function setApiUri(string $apiUri): static
{
$this->apiUri = $apiUri;

return $this;
}

/**
* Get the API URI.
*/
public function getApiUri(): ?string
{
return $this->apiUri;
}

/**
* Set the Eloquent query.
*/
public function setQuery(Builder $query): static
{
$this->query = $query;

return $this;
}

/**
* Handle the callback for the field resolution.
*/
protected function resolveField(Request $request, Field $field): void
{
$field->setForm($this);
$field->setApiUri(sprintf('/%s/fields/%s', $this->getApiUri(), $field->getUriKey()));
$field->setAttribute('form', $this->getKey());
}

/**
Expand Down Expand Up @@ -129,13 +165,11 @@ public function isConfirmable(): bool
*/
public function perform(Request $request): Response
{
$query = $this->table->resolveFilteredQuery($request);

$this->toForm($request, $query->getModel())->handle($request);
$this->validateFormRequest($request);

$this->handle(
$request,
$request->boolean('all') ? $query->get() : $query->findMany($request->input('models', []))
$request->boolean('all') ? $this->query->get() : $this->query->findMany($request->input('models', []))
);

return Redirect::back()->with(
Expand All @@ -144,14 +178,6 @@ public function perform(Request $request): Response
);
}

/**
* Convert the object to a form using the request and the model.
*/
public function toForm(Request $request, Model $model): Form
{
return new ActionForm($model, '');
}

/**
* {@inheritdoc}
*/
Expand All @@ -165,9 +191,13 @@ public function toArray(): array
'destructive' => $this->isDestructive(),
'key' => $this->getKey(),
'name' => $this->getName(),
'url' => null,
'url' => $this->getApiUri(),
'modalKey' => $this->getModalKey(),
'form' => $this->toForm($request, $this->table->getQuery()->getModel()),
'fields' => $this->resolveFields($request)
->each(function (Field $field): void {
$field->setModel($this->query->getModel());
})
->all(),
];
})
);
Expand All @@ -180,8 +210,6 @@ public function toArray(): array
*/
public function toResponse($request): Response
{
return match ($request->method()) {
default => $this->perform($request),
};
return $this->perform($request);
}
}
Loading

0 comments on commit 9a33920

Please sign in to comment.