Skip to content

Missing API stuff #1033

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

Merged
merged 3 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Datagrids/Bulks/AttributeTemplateBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ class AttributeTemplateBulk extends Bulk
'entity_image',
'entity_header',
];

protected $booleans = [
'is_enabled',
];
}
1 change: 1 addition & 0 deletions app/Datagrids/Filters/AttributeTemplateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function build()
'placeholder' => __('crud.placeholders.parent'),
'model' => AttributeTemplate::class,
])
->add('is_enabled')
->isPrivate()
->template()
->hasAttributes()
Expand Down
13 changes: 12 additions & 1 deletion app/Models/AttributeTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AttributeTemplate extends MiscModel
'attribute_template_id',
'entity_type_id',
'is_private',
'is_enabled',
];

/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public function getParentKeyName()
public function scopePreparedSelect(Builder $query): Builder
{
return $query
->select([$this->getTable() . '.id', $this->getTable() . '.name', $this->getTable() . '.is_private', 'attribute_template_id', 'entity_type_id']);
->select([$this->getTable() . '.id', $this->getTable() . '.name', $this->getTable() . '.is_private', $this->getTable() . '.is_enabled', 'attribute_template_id', 'entity_type_id']);
}

/**
Expand All @@ -103,6 +104,15 @@ public function scopePreparedWith(Builder $query): Builder
]);
}

/**
* Performance with for datagrids
*/
public function scopeEnabled(Builder $query): Builder
{
return $query
->where('is_enabled', true);
}

/**
* Apply a template to an entity
* todo: move to service
Expand Down Expand Up @@ -216,6 +226,7 @@ public function filterableColumns(): array
{
return [
'attribute_template_id',
'is_enabled',
];
}

Expand Down
3 changes: 2 additions & 1 deletion app/Services/AttributeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function updateVisibility(bool $privateAttributes): self
public function applyEntityTemplates(Entity $entity, int $order = 0): int
{
$typeId = $entity->typeId();
$templates = AttributeTemplate::has('entity')->where(['entity_type_id' => $typeId])->get();
$templates = AttributeTemplate::has('entity')->enabled()->where(['entity_type_id' => $typeId])->get();
/** @var AttributeTemplate $template */
foreach ($templates as $template) {
$order = $template->apply($entity, $order);
Expand Down Expand Up @@ -242,6 +242,7 @@ public function templateList(): array

// Campaign templates
$campaignTemplates = AttributeTemplate::has('entity')
->enabled()
->orderBy('name', 'ASC')
->pluck('name', 'id');
$key = __('attributes/templates.list.campaign');
Expand Down
1 change: 1 addition & 0 deletions app/Services/Attributes/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ protected function templates(): array

// Campaign templates
$campaignTemplates = AttributeTemplate::has('entity')
->enabled()
->orderBy('name', 'ASC')
->pluck('name', 'id');
$key = __('attributes/templates.list.campaign');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('attribute_templates', function (Blueprint $table) {
$table->boolean('is_enabled')->default(true);
$table->index('is_enabled');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('attribute_templates', function (Blueprint $table) {
$table->dropIndex('attribute_templates_is_enabled_index');
$table->dropColumn('is_enabled');
});
}
};
3 changes: 3 additions & 0 deletions lang/en/attribute_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
'fields' => [
'attributes' => 'Attributes',
'auto_apply' => 'Auto-apply',
'is_enabled' => 'Is enabled',
],
'hints' => [
'automatic' => 'The following :count attributes were automatically applied from :link.',
'automatic_apply' => '{1} The following :count attribute was automatically applied from :link | [2,] The following :count attributes were automatically applied from :link.',
'entity_type' => 'Automatically apply this template\'s attributes to new entities of the selected type.',
'parent_attribute_template' => 'This attribute template can be a child of another attribute template. When applying this attribute template, it and all of its parents will be applied.',
'is_enabled' => 'Enable this template for use when creating an entity.',
'is_disabled' => 'This template is disabled.'
],
'placeholders' => [
'name' => 'Name of the Attribute Template',
Expand Down
11 changes: 11 additions & 0 deletions resources/views/attribute_templates/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
},
'field' => 'entity_type_id'
],
[
'label' => __('attribute_templates.fields.is_enabled'),
'field' => 'is_enabled',
'render' => function($model) {
if ($model->is_enabled) {
return '<i class="fa-solid fa-check" title="' . __('attribute_templates.fields.is_enabled') . '"></i>';
}
return '';
},

],
[
'type' => 'is_private',
]
Expand Down
9 changes: 9 additions & 0 deletions resources/views/attribute_templates/form/_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
'model' => (isset($model) && $model->entityType ? $model->entityType : FormCopy::field('entityType')->related())
], 'label' => 'attribute_templates.fields.auto_apply'])
</x-forms.field>

<x-forms.field field="enabled" :label=" __('attribute_templates.fields.is_enabled')">
<input type="hidden" name="is_enabled" value="0" />
<x-checkbox :text="__('attribute_templates.hints.is_enabled')">
<input type="checkbox" name="is_enabled" value="1" @if (isset($model) && !$model->is_enabled) @else checked="checked" @endif />
</x-checkbox>
</x-forms.field>


</x-grid>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
</div>
@endif

<div class="element profile-is-enabled">
<div class="title text-uppercase text-xs">{{ __('attribute_templates.fields.is_enabled') }}</div>
@if ($child->is_enabled)
{{ __('general.yes')}}
@else
{{ __('general.no')}}
@endif
</div>

@if (!empty($child->entityType))
<div class="element profile-entity-type">
<div class="title text-uppercase text-xs">{{ __('attribute_templates.fields.auto_apply') }}</div>
Expand Down
Loading