Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NuwanJ committed Jan 6, 2025
1 parent 80deb00 commit 3455d03
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
39 changes: 22 additions & 17 deletions app/Http/Controllers/Backend/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,30 @@ public function update(Request $request, Taxonomy $taxonomy)
}
private function validateProperties(array $original, array $updated): bool
{
// Ensure existing items are not modified
foreach ($original as $index => $originalItem) {
if (!isset($updated[$index])) {
return false; // Missing an existing property
}
// $originalMap = [];
// $updatedMap = [];
// foreach ($original as $item) $originalMap[$item->code] = $item;
// foreach ($updated as $item) $updatedMap[$item->code] = $item;

$updatedItem = $updated[$index];
if (
$originalItem->code !== $updatedItem->code ||
$originalItem->name !== $updatedItem->name ||
$originalItem->data_type !== $updatedItem->data_type
) {
dd($originalItem->code,$updatedItem->code);
return false; // An existing property was altered
}
}
// // Ensure existing items are not modified
// foreach ($originalMap as $code => $originalItem) {
// if (!isset($updatedMap[$code])) {
// // TODO Let allow to delete if not used in any term
// return false; // Missing an existing property
// }

// $updatedItem = $updatedMap[$code];
// if (
// $originalItem->data_type !== $updatedItem->data_type
// ) {
// // An existing property data type was altered
// // TODO Let allow to delete if not used in any term
// return false;
// }
// }

// Allow additional properties
return count($updated) >= count($original);
// Allow changes for now
return true;
}
/**
* Confirm to delete the specified resource from storage.
Expand Down
8 changes: 5 additions & 3 deletions resources/views/backend/taxonomy/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@section('title', __('Edit Taxonomy'))

@section('content')
<div x-data="{ properties: {{ json_encode($taxonomy->properties)}}, is_editable: {{ $taxonomy->terms()->count() > 0 ? '0' : '1' }} }">
<div x-data="{ properties: {{ json_encode($taxonomy->properties) }}, is_editable: '1' }">
{!! Form::model($taxonomy, [
'url' => route('dashboard.taxonomy.update', $taxonomy->id),
'method' => 'PUT',
Expand Down Expand Up @@ -73,7 +73,7 @@
<div class="card-body">
<h5 class="card-title" style="text-align: left; text-decoration: none;">Properties</h5>

<div x-show="is_editable=='0'">
<div>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="exclamation-triangle-fill" fill="currentColor" viewBox="0 0 16 16">
<path
Expand All @@ -88,7 +88,9 @@
</svg>

<div>
<b>Edit</b> and <b>Delete</b> options not available since already have <a href="{{ route('dashboard.taxonomy.terms.index', $taxonomy) }}">taxonomy terms</a>.<br> Please remove all of them to enable the <b>Edit</b> and <b>Delete</b> options.
<b>Edit</b> and <b>Delete</b> options should be carefully used since already have <a
href="{{ route('dashboard.taxonomy.terms.index', $taxonomy) }}">taxonomy
terms</a>.<br>
</div>
</div>
</div>
Expand Down

0 comments on commit 3455d03

Please sign in to comment.