Compare commits

..

5 Commits

Author SHA1 Message Date
dc41296015 Framework and javascript dependancies update
All checks were successful
Create Docker Image / Test Application (x86_64) (push) Successful in 28s
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 1m25s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 2m36s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
2025-06-21 13:44:59 +10:00
61538e681d Update README with v2.2 updates, as well as updating the home page 2025-06-21 13:44:59 +10:00
ab33c2dce9 Enable disabling internal templates, as well as having custom templates 2025-06-21 13:11:33 +10:00
b3b3fc6ac1 Change our internal template keys to be prefixed with an underscore for easier identification 2025-06-21 13:11:33 +10:00
d6ec080ecf Working JS Template Engine with a basic functionality 2025-06-21 13:11:33 +10:00
4 changed files with 22 additions and 70 deletions

View File

@ -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);

View File

@ -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())

View File

@ -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>

View File

@ -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')