Skip to content

Commit

Permalink
Merge pull request #2207 from Blair2004/v5.0.x
Browse files Browse the repository at this point in the history
V5.0.x
  • Loading branch information
Blair2004 authored Jan 13, 2025
2 parents d5b30b0 + 0d21d97 commit 5287bc0
Show file tree
Hide file tree
Showing 170 changed files with 10,825 additions and 9,606 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"git.confirmSync": false,
"git.enableCommitSigning": true,
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
Expand Down
2 changes: 1 addition & 1 deletion app/Casts/AccountingCategoryCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function get( Model|CrudEntry $model, string $key, mixed $value, array $a
$accountReference = $accounting[ $value ] ?? null;

if ( $accountReference ) {
return $accountReference[ 'label' ]();
return $accountReference[ 'label' ];
}

return $value;
Expand Down
3 changes: 2 additions & 1 deletion app/Casts/ProductHistoryActionCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Casts;

use App\Classes\Hook;
use App\Models\ProductHistory;
use App\Services\CrudEntry;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function get( Model|CrudEntry $model, string $key, mixed $value, array $a
ProductHistory::ACTION_ADJUSTMENT_SALE => __( 'Adjustment Sale' ),
ProductHistory::ACTION_CONVERT_IN => __( 'Incoming Conversion' ),
ProductHistory::ACTION_CONVERT_OUT => __( 'Outgoing Conversion' ),
default => __( 'Unknown Action' ),
default => Hook::filter( 'ns-products-history-label', __( 'Unknown Action' ), $value ),
};
}

Expand Down
17 changes: 10 additions & 7 deletions app/Casts/ProductTypeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ public function get( Model|CrudEntry $model, string $key, mixed $value, array $a
default => 'text-info-tertiary'
};

$value = match ( $value ) {
'materialized' => __( 'Materialized' ),
'dematerialized' => __( 'Dematerialized' ),
'grouped' => __( 'Grouped' ),
default => Hook::filter( 'ns-product-type-label', sprintf( __( 'Unknown Type: %s' ), $value ), $value ),
};
$productTypes = Hook::filter( 'ns-products-type', [
'materialized' => __( 'Materialized Product' ),
'dematerialized' => __( 'Dematerialized Product' ),
'grouped' => __( 'Grouped Product' ),
]);

return '<strong class="' . $class . ' ">' . $value . '</strong>';
if ( isset( $productTypes[ $value ] ) ) {
return '<strong class="' . $class . ' ">' . $productTypes[ $value ] . '</strong>';
} else {
return '<strong class="' . $class . ' ">' . sprintf( __( 'Unknown Type: %s' ), $value ) . '</strong>';
}
}

/**
Expand Down
32 changes: 18 additions & 14 deletions app/Classes/CrudInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class CrudInput
{
public static function text( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $type = 'text' )
public static function text( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $type = 'text', $errors = [] )
{
return compact( 'label', 'name', 'value', 'validation', 'description', 'disabled', 'type' );
return compact( 'label', 'name', 'value', 'validation', 'description', 'disabled', 'type', 'errors' );
}

public static function password( $label, $name, $value = '', $validation = '', $description = '', $disabled = false )
Expand Down Expand Up @@ -35,7 +35,7 @@ public static function email( $label, $name, $value = '', $validation = '', $des
);
}

public static function number( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $type = 'number' )
public static function number( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $errors = [] )
{
return self::text(
label: $label,
Expand All @@ -44,7 +44,8 @@ public static function number( $label, $name, $value = '', $validation = '', $de
description: $description,
disabled: $disabled,
type: 'number',
value: $value
value: $value,
errors: $errors
);
}

Expand All @@ -61,7 +62,7 @@ public static function tel( $label, $name, $value = '', $validation = '', $descr
);
}

public static function hidden( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $type = 'hidden' )
public static function hidden( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $errors = [] )
{
return self::text(
label: $label,
Expand All @@ -74,7 +75,7 @@ public static function hidden( $label, $name, $value = '', $validation = '', $de
);
}

public static function date( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $type = 'date' )
public static function date( $label, $name, $value = '', $validation = '', $description = '', $disabled = false )
{
return self::text(
label: $label,
Expand All @@ -87,12 +88,12 @@ public static function date( $label, $name, $value = '', $validation = '', $desc
);
}

public static function select( $label, $name, $options, $value = '', $validation = '', $description = '', $disabled = false, $type = 'select', $component = '', $props = [], $refresh = false )
public static function select( $label, $name, $options, $value = '', $validation = '', $description = '', $disabled = false, $type = 'select', $component = '', $props = [], $refresh = false, $errors = [] )
{
return compact( 'label', 'name', 'validation', 'options', 'value', 'description', 'disabled', 'type', 'component', 'props', 'refresh' );
return compact( 'label', 'name', 'validation', 'options', 'value', 'description', 'disabled', 'type', 'component', 'props', 'refresh', 'errors' );
}

public static function searchSelect( $label, $name, $value = '', $options = [], $validation = '', $description = '', $disabled = false, $component = '', $props = [], $refresh = false )
public static function searchSelect( $label, $name, $value = '', $options = [], $validation = '', $description = '', $disabled = false, $component = '', $props = [], $refresh = false, $errors = [] )
{
return self::select(
label: $label,
Expand All @@ -105,7 +106,8 @@ public static function searchSelect( $label, $name, $value = '', $options = [],
component: $component,
props: $props,
disabled: $disabled,
refresh: $refresh
refresh: $refresh,
errors: $errors
);
}

Expand Down Expand Up @@ -182,7 +184,7 @@ public static function selectAudio( $label, $name, $value, $options, $validation
);
}

public static function switch( $label, $name, $options, $value = '', $validation = '', $description = '', $disabled = false )
public static function switch( $label, $name, $options, $value = '', $validation = '', $description = '', $disabled = false, $errors = [] )
{
return self::select(
label: $label,
Expand All @@ -192,11 +194,12 @@ public static function switch( $label, $name, $options, $value = '', $validation
value: $value,
description: $description,
disabled: $disabled,
type: 'switch'
type: 'switch',
errors: $errors
);
}

public static function media( $label, $name, $value = '', $validation = '', $description = '', $disabled = false )
public static function media( $label, $name, $value = '', $validation = '', $description = '', $disabled = false, $errors = [] )
{
return self::text(
label: $label,
Expand All @@ -205,7 +208,8 @@ public static function media( $label, $name, $value = '', $validation = '', $des
description: $description,
disabled: $disabled,
type: 'media',
value: $value
value: $value,
errors: $errors
);
}

Expand Down
33 changes: 33 additions & 0 deletions app/Classes/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace App\Classes;

class Model
{
/**
* Define a dependant relationship.
*/
public static function dependant( string $local_name, string $foreign_index, string $foreign_name = null, array $related = [], string $local_index = 'id' )
{
return [
'local_index' => $local_index,
'local_name' => $local_name,
'foreign_index' => $foreign_index,
'foreign_name' => $foreign_name,
'related' => $related,
];
}

/**
* Define a related relationship.
*/
public static function related( string $model, string $foreign_index, string $local_name, callable| null $prefix = null, string $local_index = 'id' )
{
return [
'model' => $model,
'local_index' => $local_index,
'foreign_index' => $foreign_index,
'local_name' => $local_name,
'prefix' => $prefix,
];
}
}
51 changes: 51 additions & 0 deletions app/Console/Commands/ModuleKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Console\Commands;

use App\Services\ModulesService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\View;

class ModuleKernel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'modules:kernel {module} {--force}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate kernel file for the selected module.';

/**
* Execute the console command.
*/
public function handle()
{
$moduleService = app()->make( ModulesService::class );
$moduleIdentifier = $this->argument('module');

$modulePath = base_path('modules/' . $moduleIdentifier);

if ( ! $module = $moduleService->get( $moduleIdentifier ) ) {
$this->error('Module not found.');
}

$filePath = $modulePath . '/Console/Kernel.php';

if ( file_exists( $filePath ) && ! $this->option( 'force' ) ) {
return $this->error('Kernel file not found for the module.');
}

$content = View::make( 'generate.modules.kernel', compact( 'module' ) )->render();

file_put_contents( $filePath, $content );

$this->info( sprintf( 'Kernel file generated successfully at %s.', $filePath ) );
}
}
Loading

0 comments on commit 5287bc0

Please sign in to comment.