Compare commits
5 Commits
735b1c542f
...
dc41296015
Author | SHA1 | Date | |
---|---|---|---|
dc41296015 | |||
61538e681d | |||
ab33c2dce9 | |||
b3b3fc6ac1 | |||
d6ec080ecf |
@ -16,15 +16,10 @@ class Template
|
|||||||
private array $template;
|
private array $template;
|
||||||
private(set) bool $invalid = FALSE;
|
private(set) bool $invalid = FALSE;
|
||||||
private(set) string $reason = '';
|
private(set) string $reason = '';
|
||||||
private Collection $on_change_target;
|
|
||||||
private Collection $on_change_attribute;
|
|
||||||
private bool $on_change_processed = FALSE;
|
|
||||||
|
|
||||||
public function __construct(string $file)
|
public function __construct(string $file)
|
||||||
{
|
{
|
||||||
$td = Storage::disk(config('pla.template.dir'));
|
$td = Storage::disk(config('pla.template.dir'));
|
||||||
$this->on_change_attribute = collect();
|
|
||||||
$this->on_change_target = collect();
|
|
||||||
|
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
|
|
||||||
@ -58,70 +53,34 @@ class Template
|
|||||||
return array_key_exists($key,$this->template);
|
return array_key_exists($key,$this->template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onChange(string $attribute): Collection|NULL
|
|
||||||
{
|
|
||||||
if (! $this->on_change_processed)
|
|
||||||
$this->onChangeProcessing();
|
|
||||||
|
|
||||||
return $this->on_change_attribute
|
|
||||||
->get(strtolower($attribute));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this attribute's value populated by any onChange processing rules
|
|
||||||
*
|
|
||||||
* @param string $attribute
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function onChangeAttribute(string $attribute): bool
|
|
||||||
{
|
|
||||||
if (! $this->on_change_processed)
|
|
||||||
$this->onChangeProcessing();
|
|
||||||
|
|
||||||
return $this->on_change_attribute
|
|
||||||
->has(strtolower($attribute));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the onchange JavaScript for attribute
|
* Return the onchange JavaScript for attribute
|
||||||
*
|
*
|
||||||
|
* @param string $attribute
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
private function onChangeProcessing(): void
|
public function onChange(string $attribute): Collection
|
||||||
{
|
{
|
||||||
foreach (Arr::get($this->template,'attributes',[]) as $attribute => $detail) {
|
$attr = collect($this->template['attributes'])
|
||||||
$result = collect();
|
->filter(fn($item,$key)=>! strcasecmp($key,$attribute))
|
||||||
|
->pop();
|
||||||
|
|
||||||
foreach (Arr::get($detail,'onchange',[]) as $item) {
|
if (! $attr)
|
||||||
list($command,$args) = preg_split('/^=([a-zA-Z]+)\((.+)\)$/',$item,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
return collect();
|
||||||
|
|
||||||
switch ($command) {
|
$result = collect();
|
||||||
case 'autoFill':
|
|
||||||
$result->push($this->autofill($args));
|
foreach (Arr::get($attr,'onchange',[]) as $item) {
|
||||||
break;
|
list($command,$args) = preg_split('/^=([a-zA-Z]+)\((.+)\)$/',$item,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||||
}
|
|
||||||
|
switch ($command) {
|
||||||
|
case 'autoFill':
|
||||||
|
$result->push($this->autofill($args));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result->count())
|
|
||||||
$this->on_change_attribute->put(strtolower($attribute),$result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->on_change_processed = TRUE;
|
return $result;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this attribute's value populated by any onChange processing rules
|
|
||||||
*
|
|
||||||
* @param string $attribute
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function onChangeTarget(string $attribute): bool
|
|
||||||
{
|
|
||||||
if (! $this->on_change_processed)
|
|
||||||
$this->onChangeProcessing();
|
|
||||||
|
|
||||||
return $this->on_change_target
|
|
||||||
->has(strtolower($attribute));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,8 +128,6 @@ class Template
|
|||||||
|
|
||||||
// $attr has our attribute to update, $string is the format to use when updating it
|
// $attr has our attribute to update, $string is the format to use when updating it
|
||||||
list($attr,$string) = preg_split('(([^,]+);(.*))',$arg,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
list($attr,$string) = preg_split('(([^,]+);(.*))',$arg,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||||
$this->on_change_target->put(strtolower($attr),$string);
|
|
||||||
|
|
||||||
$output = $string;
|
$output = $string;
|
||||||
//$result .= sprintf("\n// %s\n",$arg);
|
//$result .= sprintf("\n// %s\n",$arg);
|
||||||
|
|
||||||
|
@ -7,13 +7,8 @@
|
|||||||
<span class="d-flex justify-content-between">
|
<span class="d-flex justify-content-between">
|
||||||
<span style="width: 20em;">
|
<span style="width: 20em;">
|
||||||
<strong class="align-middle"><abbr title="{{ $o->description }}">{{ $o->name }}</abbr></strong>
|
<strong class="align-middle"><abbr title="{{ $o->description }}">{{ $o->name }}</abbr></strong>
|
||||||
@if($new)
|
@if($new && $template?->onChange($o->name)->count())
|
||||||
@if($template?->onChangeAttribute($o->name_lc))
|
<sup data-bs-toggle="tooltip" title="@lang('Value calculated by template')"><i class="fas fa-wand-magic-sparkles"></i></sup>
|
||||||
<sup data-bs-toggle="tooltip" title="@lang('Value triggers an update to another attribute by template')"><i class="fas fa-keyboard"></i></sup>
|
|
||||||
@endif
|
|
||||||
@if ($template?->onChangeTarget($o->name_lc))
|
|
||||||
<sup data-bs-toggle="tooltip" title="@lang('Value calculated by template')"><i class="fas fa-wand-magic-sparkles"></i></sup>
|
|
||||||
@endif
|
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if($o->hints->count())
|
@if($o->hints->count())
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
@php($up=(session()->get('updated') ?: collect()))
|
@php($up=(session()->pull('updated') ?: collect()))
|
||||||
|
|
||||||
@foreach($o->getVisibleAttributes()->filter(fn($item)=>$template->attributes->map('strtolower')->contains($item->name_lc)) as $ao)
|
@foreach($o->getVisibleAttributes()->filter(fn($item)=>$template->attributes->map('strtolower')->contains($item->name_lc)) as $ao)
|
||||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template" :updated="$up->contains($ao->name)"/>
|
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template" :updated="$up->contains($ao->name_lc)"/>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -101,7 +101,7 @@
|
|||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
@php($up=(session()->pull('updated') ?: collect()))
|
@php($up=(session()->pull('updated') ?: collect()))
|
||||||
@foreach($o->getVisibleAttributes() as $ao)
|
@foreach($o->getVisibleAttributes() as $ao)
|
||||||
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template ?? NULL" :updated="$up->contains($ao->name)"/>
|
<x-attribute-type :o="$ao" :edit="TRUE" :new="FALSE" :template="$template ?? NULL" :updated="$up->contains($ao->name_lc)"/>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
@include('fragment.dn.add_attr')
|
@include('fragment.dn.add_attr')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user