Skip to content

Commit

Permalink
Merge pull request #1 from queents/dev
Browse files Browse the repository at this point in the history
add slug
  • Loading branch information
3x1io authored Oct 6, 2022
2 parents b5ebec7 + d1cfa30 commit 03cfa3f
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 1 deletion.
1 change: 1 addition & 0 deletions Routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Route::get("/export", [$route['controller'], 'export'])->name('export');
Route::post("/import", [$route['controller'], 'import'])->name('import');
Route::get("/{id}/view", [$route['controller'], 'view'])->name('view');
Route::post("/{id}/action", [$route['controller'], 'action'])->name('action');
Route::get("/{id}", [$route['controller'], 'show'])->name('show');
Route::get("/{id}/edit", [$route['controller'], 'edit'])->name('edit');
Route::post("/{id}", [$route['controller'], 'update'])->name('update');
Expand Down
3 changes: 3 additions & 0 deletions Services/Components/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Modules\Base\Services\Concerns\HasType;
use Modules\Base\Services\Concerns\HasUrl;
use Modules\Base\Services\Concerns\IsCan;
use Modules\Base\Services\Concerns\IsConfirmed;

class Actions extends ComponentAbstract
{
Expand All @@ -23,6 +24,7 @@ class Actions extends ComponentAbstract
use HasAction;
use HasModal;
use HasUrl;
use IsConfirmed;
use IsCan;

public function get(): mixed
Expand All @@ -33,6 +35,7 @@ public function get(): mixed
->icon($this->icon)
->action($this->action)
->modal($this->modal)
->confirmed($this->confirmed)
->url($this->url)
->can($this->can);
}
Expand Down
2 changes: 2 additions & 0 deletions Services/Components/Base/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Modules\Base\Services\Concerns\HasType;
use Modules\Base\Services\Concerns\HasUrl;
use Modules\Base\Services\Concerns\IsCan;
use Modules\Base\Services\Concerns\IsConfirmed;
use Modules\Base\Services\Core\Abstracts\HasMake;


Expand All @@ -23,4 +24,5 @@ class Action extends HasMake
use HasUrl;
use HasClassType;
use IsCan;
use IsConfirmed;
}
2 changes: 2 additions & 0 deletions Services/Components/Base/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Modules\Base\Services\Concerns\HasModel;
use Modules\Base\Services\Concerns\HasRows;
use Modules\Base\Services\Concerns\HasType;
use Modules\Base\Services\Concerns\IsConfirmed;
use Modules\Base\Services\Core\Abstracts\HasMake;

class Filter extends HasMake
Expand All @@ -17,4 +18,5 @@ class Filter extends HasMake
use HasModel;
use HasRows;
use HasAction;
use IsConfirmed;
}
2 changes: 2 additions & 0 deletions Services/Components/Base/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Modules\Base\Services\Components\Base;

use Modules\Base\Services\Concerns\HasBody;
use Modules\Base\Services\Concerns\HasButton;
use Modules\Base\Services\Concerns\HasClassType;
use Modules\Base\Services\Concerns\HasIcon;
Expand All @@ -19,4 +20,5 @@ class Modal extends HasMake
use HasButton;
use HasClassType;
use HasRows;
use HasBody;
}
2 changes: 2 additions & 0 deletions Services/Components/Base/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Modules\Base\Services\Concerns\HasBulk;
use Modules\Base\Services\Concerns\HasBulks;
use Modules\Base\Services\Concerns\HasFilters;
use Modules\Base\Services\Concerns\HasRows;
use Modules\Base\Services\Concerns\HasSearch;
use Modules\Base\Services\Core\Abstracts\HasMake;

Expand All @@ -16,4 +17,5 @@ class Table extends HasMake
use HasBulks;
use HasBulk;
use HasSearch;
use HasRows;
}
3 changes: 3 additions & 0 deletions Services/Components/Modals.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Modules\Base\Services\Components\Abstracts\ComponentAbstract;
use Modules\Base\Services\Components\Base\Modal;
use Modules\Base\Services\Concerns\HasBody;
use Modules\Base\Services\Concerns\HasButton;
use Modules\Base\Services\Concerns\HasIcon;
use Modules\Base\Services\Concerns\HasLabel;
Expand All @@ -20,6 +21,7 @@ class Modals extends ComponentAbstract {
use HasIcon;
use HasButton;
use HasRows;
use HasBody;

public function get(): mixed
{
Expand All @@ -28,6 +30,7 @@ public function get(): mixed
->type($this->type)
->icon($this->icon)
->buttons($this->buttons)
->body($this->body)
->rows($this->rows);
}
}
4 changes: 3 additions & 1 deletion Services/Concerns/HasAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
trait HasAction
{
public ?string $action = null;
public ?string $actionMethod = null;

/**
* @param ?string $action
* @return static
*/
public function action(?string $action): static {
public function action(?string $action, ?string $actionMethod="post"): static {
$this->action = $action;
$this->actionMethod = $actionMethod;
return $this;
}
}
17 changes: 17 additions & 0 deletions Services/Concerns/HasBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Modules\Base\Services\Concerns;

trait HasBody
{
/**
* @var string | array | bool | null
*/
public string | array | bool | null $body = null;

public function body(string | array | bool | null $body): static
{
$this->body = $body;
return $this;
}
}
17 changes: 17 additions & 0 deletions Services/Concerns/HasView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Modules\Base\Services\Concerns;

trait HasView
{
/**
* @var string | null
*/
public string | null $viewType = "input";

public function viewType(string | null $viewType): static
{
$this->viewType = $viewType;
return $this;
}
}
20 changes: 20 additions & 0 deletions Services/Concerns/IsConfirmed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Modules\Base\Services\Concerns;

trait IsConfirmed
{
/**
* @var ?bool
*/
public ?bool $confirmed = false;

/**
* @return $this
*/
public function confirmed(bool $confirmed = true): static
{
$this->confirmed = $confirmed;
return $this;
}
}
51 changes: 51 additions & 0 deletions Services/Resource/Concerns/Actions/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Modules\Base\Services\Resource\Concerns\Actions;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Modules\Base\Services\Components\Base\Alert;

trait Action
{
/**
* @param Request $request
* @param $id
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Inertia\Response|void|null
*/
public function action(Request $request, $id)
{
/*
* Check if user has role to create a new record
*/
if ($this->checkRoles('canEdit') && !$this->isAPI($request)) {
return $this->checkRoles('canEdit');
}

/*
* Check Request validation
*/
$validator = Validator::make($request->all(), [
"action" => "required|string",
"value" => "required"
]);

if (!$validator->fails()) {

/*
* Select Record By ID
*/
$record = $this->model::find($id);

/*
* Process Select to be ID
*/
$record->{$request->get('action')} = $request->get('value');
$record->save();
/*
* Return Redirect Response if request is not API
*/
return Alert::make(__($this->generateName(true, true) . " Updated Success"))->fire();
}
}
}
1 change: 1 addition & 0 deletions Services/Resource/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Resource implements MustHasRows
use Actions\Bulk;
use Actions\Import;
use Actions\Export;
use Actions\Action;

/*
* Load Process
Expand Down
2 changes: 2 additions & 0 deletions Services/Rows/Abstracts/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Modules\Base\Services\Concerns\HasTrack;
use Modules\Base\Services\Concerns\HasType;
use Modules\Base\Services\Concerns\HasValidation;
use Modules\Base\Services\Concerns\HasView;
use Modules\Base\Services\Concerns\IsBadge;
use Modules\Base\Services\Concerns\IsDisabled;
use Modules\Base\Services\Concerns\IsMoney;
Expand Down Expand Up @@ -61,6 +62,7 @@ abstract class Base implements Component
use HasValidation;
use HasOptions;
use HasTrack;
use HasView;
use HasValidation;
use IsUrl;
use IsMulti;
Expand Down
20 changes: 20 additions & 0 deletions Services/Rows/Slug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Modules\Base\Services\Rows;

use Modules\Base\Services\Rows\Abstracts\Base;

class Slug extends Base
{

public string $vue = 'ViltSlug.vue';

/**
* @param string $name
* @return static
*/
public static function make(string $name): self
{
return (new self)->name($name);
}
}

0 comments on commit 03cfa3f

Please sign in to comment.