Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump actions/checkout from 2 to 3 #6

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@ updates:
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
labels:
- "dependencies"

- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
labels:
- "npm"
- "dependencies"
2 changes: 1 addition & 1 deletion .github/workflows/retype-action.yml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: retypeapp/action-build@latest

Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Update Changelog"

on:
release:
types: [released]

permissions:
contents: write

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
79 changes: 35 additions & 44 deletions Actions/GetRulesWithParamsAction.php
Original file line number Diff line number Diff line change
@@ -1,69 +1,61 @@
<?php



declare(strict_types=1);

namespace Modules\UI\Actions;

use ReflectionClass;
use ReflectionMethod;
use Illuminate\Support\Str;
use Spatie\QueueableAction\QueueableAction;
use Illuminate\Validation\Concerns\ValidatesAttributes;
use Spatie\QueueableAction\QueueableAction;

class GetRulesWithParamsAction
{
use QueueableAction;



public function execute(): array
{
$validatorClass = new ReflectionClass(ValidatesAttributes::class);
$validatorClass = new \ReflectionClass(ValidatesAttributes::class);

$r = collect($validatorClass->getMethods(ReflectionMethod::IS_PUBLIC))
$r = collect($validatorClass->getMethods(\ReflectionMethod::IS_PUBLIC))
->filter(function ($method) {
return Str::startsWith($method->name, 'validate');
})
->map(function ($method) {

//$param_names = collect($method->getParameters())->pluck('name', 'name')->except(['attribute', 'value']);

$method_name = str_replace('validate_', '', Str::snake($method->name));

$params = $this->getParamsType($method_name);

if (null != $params) {

$start = strpos($method->getDocComment(), 'Validate');
$end = strpos($method->getDocComment(), '@');

$comment = '';
if (is_int($start)) {
$comment = substr($method->getDocComment(), $start, $end - $start);
$comment = preg_replace('/\s\s+/', ' ', $comment);
$comment = str_replace('* ', '', $comment);
$comment = trim($comment);
->map(
function ($method) {
// $param_names = collect($method->getParameters())->pluck('name', 'name')->except(['attribute', 'value']);

$method_name = str_replace('validate_', '', Str::snake($method->name));

$params = $this->getParamsType($method_name);

if (null != $params) {
$start = strpos((string) $method->getDocComment(), 'Validate');
$end = strpos((string) $method->getDocComment(), '@');

$comment = '';
if (is_int($start)) {
$comment = substr((string) $method->getDocComment(), $start, $end - $start);
$comment = preg_replace('/\s\s+/', ' ', $comment);
$comment = str_replace('* ', '', (string) $comment);
$comment = trim($comment);
}

return [
'name' => $method_name,
'comment' => $comment,
'params' => $params,
];
}
})->filter(function ($v) {
return null !== $v;
})->toArray();

return [
'name' => $method_name,
'comment' => $comment,
'params' => $params
];
}
})->filter(function ($v) {
return $v !== null;
})->toArray();

//dd($r);
// dd($r);

return $r;
}

/**
* @param string $method_name
* @return array|null
*/
public function getParamsType(string $method_name)
Expand All @@ -83,14 +75,14 @@ public function getParamsType(string $method_name)
'date_equals' => ['date' => 'text'],
'decimal' => [
'min' => 'number',
'max' => 'number'
'max' => 'number',
],
'declined' => [''],
'different' => ['field' => 'text'],
'digits' => ['value' => 'number'],
'digits_between' => [
'min' => 'number',
'max' => 'number'
'max' => 'number',
],
'email' => [''],
'filled' => [''],
Expand Down Expand Up @@ -123,14 +115,13 @@ public function getParamsType(string $method_name)
'uppercase' => [''],
'url' => [''],
'uuid' => [''],

];

if (isset($parameters[$method_name])) {
return $parameters[$method_name];
}

return null;
//return ['json' => 'json'];
// return ['json' => 'json'];
}
}
17 changes: 10 additions & 7 deletions Actions/GetViewAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
use Modules\Xot\Services\FileService;
use Spatie\QueueableAction\QueueableAction;

class GetViewAction {
class GetViewAction
{
use QueueableAction;

/**
* PER ORA FUNZIONA SOLO CON LIVEWIRE.
*/
public function execute(string $tpl = ''): string {
public function execute(string $tpl = ''): string
{
$backtrace = debug_backtrace();
$file0 = FileService::fixpath($backtrace[0]['file'] ?? '');
$file0 = Str::after($file0, base_path());
Expand All @@ -29,12 +31,13 @@ public function execute(string $tpl = ''): string {
$mod = $arr[1];
$tmp = array_slice($arr, 3);

$tmp = collect($tmp)->map(function ($item) {
$item = str_replace('.php', '', $item);
$item = Str::slug(Str::snake($item));
$tmp = collect($tmp)->map(
function ($item) {
$item = str_replace('.php', '', $item);
$item = Str::slug(Str::snake($item));

return $item;
})->implode('.');
return $item;
})->implode('.');

$view = Str::lower($mod).'::'.$tmp;
if ('' != $tpl) {
Expand Down
28 changes: 23 additions & 5 deletions Datas/FieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;

class FieldData extends Data {
class FieldData extends Data
{
public string $name;
public ?string $label = null;
public ?string $name_dot = null;
Expand Down Expand Up @@ -58,19 +59,24 @@ public function __construct(
}
*/

public function getNameDot(): string {
public function getNameDot(): string
{
$this->name_dot = bracketsToDotted($this->name);

return $this->name_dot;
}

public function getLabel(): string {
public function getLabel(): string
{
if (null !== $this->label) {
return $this->label;
}
$trans_key = 'pub_theme::txt.'.$this->name.'.label';
$trans = trans($trans_key);
if ($trans != $trans_key) {
if (! is_string($trans)) {
throw new \Exception('['.__LINE__.']['.__FILE__.']');
}
$this->label = $trans;

return $trans;
Expand All @@ -79,20 +85,32 @@ public function getLabel(): string {
return $this->name;
}

public function getInputClass(): string {
public function getInputClass(): string
{
return 'form-control';
}

/**
* @return DataCollection<FieldData>
*/
public function getFields(?string $act = null): DataCollection {
public function getFields(?string $act = null): DataCollection
{
if (null == $act) {
$act = RouteService::getAct();
}
if (null == $this->fields) {
throw new \Exception('['.__LINE__.']['.__FILE__.']');
}

return $this->fields->filter(
/**
* @param FieldData $item
*/
function ($item) use ($act) {
if (! $item instanceof FieldData) {
throw new \Exception('['.__LINE__.']['.__FILE__.']');
}

return ! in_array($act, $item->except);
}
);
Expand Down
33 changes: 19 additions & 14 deletions Http/Livewire/Import/Xls/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Modules\UI\Http\Livewire\Import\Xls;

use Exception;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Collection;
use Livewire\Component;
Expand All @@ -21,7 +20,8 @@
*
* @property Collection $data
*/
class Model extends Component {
class Model extends Component
{
use WithFileUploads;

/**
Expand All @@ -42,7 +42,8 @@ class Model extends Component {
*
* @return void
*/
public function mount(string $modelClass, ?array $fields, ?array $trans) {
public function mount(string $modelClass, ?array $fields, ?array $trans)
{
$this->modelClass = $modelClass;
$this->fillable = app($modelClass)->getFillable();
$this->fillable = array_combine($this->fillable, $this->fillable);
Expand All @@ -59,7 +60,8 @@ public function mount(string $modelClass, ?array $fields, ?array $trans) {
/**
* Undocumented function.
*/
public function getDataProperty(): Collection {
public function getDataProperty(): Collection
{
$path = $this->myfile->getRealPath();

if (false !== $path) {
Expand All @@ -74,7 +76,8 @@ public function getDataProperty(): Collection {
/**
* Undocumented function.
*/
public function render(): Renderable {
public function render(): Renderable
{
/**
* @phpstan-var view-string
*/
Expand All @@ -89,7 +92,8 @@ public function render(): Renderable {
*
* @return void
*/
public function import() {
public function import()
{
$model = app($this->modelClass);

$rows = $this->data;
Expand All @@ -99,19 +103,20 @@ public function import() {
*/
$rows = $rows->filter(
function ($item) {
// if(!method_exists($item,'toArray')){
// throw new Exception('['.__LINE__.']['.__FILE__.']');
// }
/*if (! ($item instanceof Collection)) {
throw new \InvalidArgumentException('Il parametro $item non è una collezione');
}*/

try {
$items = $item->toArray();
} catch (\Exception $e) {
throw new \Exception('['.__LINE__.']['.__FILE__.']');
}
foreach ($items as $key => $value) {
if (null !== $value) {
return $item;
}
}
foreach ($items as $key => $value) {
if (null !== $value) {
return $item;
}
}
}
);

Expand Down
Loading