AreYouScared
AreYouScared
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Object of class Valet\Server could not be converted to string I might just leave it alone, getting deep into the "idk what im doing" territory
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
No description
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Okay, i'll pass it on to the other guys and we can see what we can figure out, thanks!
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Okay. Im not the one whom made the "simple" pages and everything. My scope of programming and how filament works is more of a going with the flow.
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Could we get the resource/record from the url? the servers has a server_id column and its in the url, so /app/3/startup is server with the server_id of 3
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
https://github.com/pelican-dev/panel/blob/issue/353/app/Filament/App/Pages/Startup.php#L78-L140 Is the file in question on the "App" the one that has no record/resource
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
If you're bored... its all in this repo... https://github.com/pelican-dev/panel/tree/issue/353
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
So we have two "PanelProviders" ones called Admin other called App
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Its it's "own" panel? not sure how to explain it. Like the admin panel is /app/Filament/ then the "front end" is /app/Filament/App
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
On the admin side, the record is the server.
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Right, we are setting the "server" with
/** @var Server $server */
$server = Filament::getTenant();
/** @var Server $server */
$server = Filament::getTenant();
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
wdym? The repeater works as intended on the admin panel.
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
I guess the proper term would be styled, not formatted.
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
No description
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Well we have an admin panel, and a "regular" panel i guess or "app" for the front end thats using Tenants, When i do ->relationship('serverVariables') we get Call to a member function serverVariables() on null
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
I guess I'm not understanding.
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
No description
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
On the "front end" i had to use a Section instead of the repeater...
Section::make('Server Variables')
->columnSpanFull()
->columns([
'default' => 1,
'lg' => 2,
])
->schema(function () {
/** @var Server $server */
$server = Filament::getTenant();
$variableComponents = [];

/** @var ServerVariable $serverVariable */
foreach ($server->serverVariables->sortBy(fn ($serverVariable) => $serverVariable->variable->sort) as $serverVariable) {
if (!$serverVariable->variable->user_viewable) {
continue;
}

$text = TextInput::make($serverVariable->variable->name)
->hidden(fn (Component $component) => $this->shouldHideComponent($serverVariable, $component))
->disabled(fn () => !$serverVariable->variable->user_editable)
->required(fn () => in_array('required', explode('|', $serverVariable->variable->rules)))
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) {
$validator = Validator::make(['validatorkey' => $value], [
'validatorkey' => $serverVariable->variable->rules,
]);

if ($validator->fails()) {
$message = str($validator->errors()->first())->replace('validatorkey', $serverVariable->variable->name);

$fail($message);
}
},
]);

$select = Select::make($serverVariable->variable->name)
->hidden(fn (Component $component) => $this->shouldHideComponent($serverVariable, $component))
->disabled(fn () => !$serverVariable->variable->user_editable) // TODO: find better way, doesn't look so nice
->options(fn () => $this->getSelectOptionsFromRules($serverVariable))
->selectablePlaceholder(false);

$components = [$text, $select];

foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
->afterStateUpdated(function ($state) use ($serverVariable) {
$this->update($state, $serverVariable->variable->env_variable);
})
->hintIcon('tabler-code')
->label(fn () => $serverVariable->variable->name)
->default(fn () => $serverVariable->variable_value ?? $serverVariable->variable->default_value)
->hintIconTooltip(fn () => $serverVariable->variable->rules)
->prefix(fn () => '{{' . $serverVariable->variable->env_variable . '}}')
->helperText(fn () => empty($serverVariable->variable->description) ? '—' : $serverVariable->variable->description);
}

$variableComponents = array_merge($variableComponents, $components);
}

return $variableComponents;
}),
]);
Section::make('Server Variables')
->columnSpanFull()
->columns([
'default' => 1,
'lg' => 2,
])
->schema(function () {
/** @var Server $server */
$server = Filament::getTenant();
$variableComponents = [];

/** @var ServerVariable $serverVariable */
foreach ($server->serverVariables->sortBy(fn ($serverVariable) => $serverVariable->variable->sort) as $serverVariable) {
if (!$serverVariable->variable->user_viewable) {
continue;
}

$text = TextInput::make($serverVariable->variable->name)
->hidden(fn (Component $component) => $this->shouldHideComponent($serverVariable, $component))
->disabled(fn () => !$serverVariable->variable->user_editable)
->required(fn () => in_array('required', explode('|', $serverVariable->variable->rules)))
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) {
$validator = Validator::make(['validatorkey' => $value], [
'validatorkey' => $serverVariable->variable->rules,
]);

if ($validator->fails()) {
$message = str($validator->errors()->first())->replace('validatorkey', $serverVariable->variable->name);

$fail($message);
}
},
]);

$select = Select::make($serverVariable->variable->name)
->hidden(fn (Component $component) => $this->shouldHideComponent($serverVariable, $component))
->disabled(fn () => !$serverVariable->variable->user_editable) // TODO: find better way, doesn't look so nice
->options(fn () => $this->getSelectOptionsFromRules($serverVariable))
->selectablePlaceholder(false);

$components = [$text, $select];

foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
->afterStateUpdated(function ($state) use ($serverVariable) {
$this->update($state, $serverVariable->variable->env_variable);
})
->hintIcon('tabler-code')
->label(fn () => $serverVariable->variable->name)
->default(fn () => $serverVariable->variable_value ?? $serverVariable->variable->default_value)
->hintIconTooltip(fn () => $serverVariable->variable->rules)
->prefix(fn () => '{{' . $serverVariable->variable->env_variable . '}}')
->helperText(fn () => empty($serverVariable->variable->description) ? '—' : $serverVariable->variable->description);
}

$variableComponents = array_merge($variableComponents, $components);
}

return $variableComponents;
}),
]);
33 replies
FFilament
Created by AreYouScared on 8/15/2024 in #❓┊help
Repeaters... How to feed them custom data?
Forms\Components\Repeater::make('server_variables')
->relationship('serverVariables')
->grid()
->mutateRelationshipDataBeforeSaveUsing(function (array &$data): array {
foreach ($data as $key => $value) {
if (!isset($data['variable_value'])) {
$data['variable_value'] = '';
}
}

return $data;
})
->reorderable(false)->addable(false)->deletable(false)
->schema(function () {

$text = Forms\Components\TextInput::make('variable_value')
->hidden($this->shouldHideComponent(...))
->required(fn (ServerVariable $serverVariable) => in_array('required', explode('|', $serverVariable->variable->rules)))
->rules([
fn (ServerVariable $serverVariable): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) {
$validator = Validator::make(['validatorkey' => $value], [
'validatorkey' => $serverVariable->variable->rules,
]);

if ($validator->fails()) {
$message = str($validator->errors()->first())->replace('validatorkey', $serverVariable->variable->name);

$fail($message);
}
},
]);

$select = Forms\Components\Select::make('variable_value')
->hidden($this->shouldHideComponent(...))
->options($this->getSelectOptionsFromRules(...))
->selectablePlaceholder(false);

$components = [$text, $select];

foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
->hintIcon('tabler-code')
->label(fn (ServerVariable $serverVariable) => $serverVariable->variable->name)
->hintIconTooltip(fn (ServerVariable $serverVariable) => $serverVariable->variable->rules)
->prefix(fn (ServerVariable $serverVariable) => '{{' . $serverVariable->variable->env_variable . '}}')
->helperText(fn (ServerVariable $serverVariable) => empty($serverVariable->variable->description) ? '—' : $serverVariable->variable->description);
}

return $components;
})
->columnSpan(6),
Forms\Components\Repeater::make('server_variables')
->relationship('serverVariables')
->grid()
->mutateRelationshipDataBeforeSaveUsing(function (array &$data): array {
foreach ($data as $key => $value) {
if (!isset($data['variable_value'])) {
$data['variable_value'] = '';
}
}

return $data;
})
->reorderable(false)->addable(false)->deletable(false)
->schema(function () {

$text = Forms\Components\TextInput::make('variable_value')
->hidden($this->shouldHideComponent(...))
->required(fn (ServerVariable $serverVariable) => in_array('required', explode('|', $serverVariable->variable->rules)))
->rules([
fn (ServerVariable $serverVariable): Closure => function (string $attribute, $value, Closure $fail) use ($serverVariable) {
$validator = Validator::make(['validatorkey' => $value], [
'validatorkey' => $serverVariable->variable->rules,
]);

if ($validator->fails()) {
$message = str($validator->errors()->first())->replace('validatorkey', $serverVariable->variable->name);

$fail($message);
}
},
]);

$select = Forms\Components\Select::make('variable_value')
->hidden($this->shouldHideComponent(...))
->options($this->getSelectOptionsFromRules(...))
->selectablePlaceholder(false);

$components = [$text, $select];

foreach ($components as &$component) {
$component = $component
->live(onBlur: true)
->hintIcon('tabler-code')
->label(fn (ServerVariable $serverVariable) => $serverVariable->variable->name)
->hintIconTooltip(fn (ServerVariable $serverVariable) => $serverVariable->variable->rules)
->prefix(fn (ServerVariable $serverVariable) => '{{' . $serverVariable->variable->env_variable . '}}')
->helperText(fn (ServerVariable $serverVariable) => empty($serverVariable->variable->description) ? '—' : $serverVariable->variable->description);
}

return $components;
})
->columnSpan(6),
33 replies
FFilament
Created by AreYouScared on 7/29/2024 in #❓┊help
ToggleButton Overflow not handled?
We changed them to inline, and seems to be working fine. Thanks again!
6 replies