fix menu with parent data and remove action google sheet not available feature

This commit is contained in:
arifal
2025-03-21 14:54:18 +07:00
parent f36f250700
commit d7bff86741
6 changed files with 54 additions and 34 deletions

View File

@@ -22,7 +22,8 @@ class MenusController extends Controller
$query = $query->where("name", "like", "%".$request->get("search")."%");
}
return response()->json($query->paginate(config('app.paginate_per_page', 50)));
// return response()->json($query->paginate(config('app.paginate_per_page', 50)));
return MenuResource::collection($query->paginate(config('app.paginate_per_page',50)));
}
/**

View File

@@ -14,6 +14,16 @@ class MenuResource extends JsonResource
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
// return parent::toArray($request);
return [
'id' => $this->id,
'name' => $this->name,
'icon' => $this->icon,
'url' => $this->url,
'sort_order' => $this->sort_order,
'parent' => $this->parent ? new MenuResource($this->parent) : null,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at
];
}
}

View File

@@ -22,4 +22,7 @@ class Menu extends Model
public function children(){
return $this->hasMany(Menu::class,'parent_id');
}
public function parent(){
return $this->belongsTo(Menu::class,'parent_id');
}
}

View File

@@ -41,8 +41,8 @@ class GoogleSheets {
tableContainer.innerHTML = "";
// Get user permissions from data attributes
let canUpdate = tableContainer.getAttribute("data-updater") === "1";
let canDelete = tableContainer.getAttribute("data-destroyer") === "1";
// let canUpdate = tableContainer.getAttribute("data-updater") === "1";
// let canDelete = tableContainer.getAttribute("data-destroyer") === "1";
this.table = new Grid({
columns: [
@@ -65,25 +65,25 @@ class GoogleSheets {
</a>
`;
if (canUpdate) {
buttons += `
<a href="#" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
<i class='bx bx-edit'></i>
</a>
`;
}
// if (canUpdate) {
// buttons += `
// <a href="#" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
// <i class='bx bx-edit'></i>
// </a>
// `;
// }
if (canDelete) {
buttons += `
<button data-id="${cell}" class="btn btn-sm btn-red btn-delete-google-sheet d-inline-flex align-items-center justify-content-center">
<i class='bx bxs-trash'></i>
</button>
`;
}
// if (canDelete) {
// buttons += `
// <button data-id="${cell}" class="btn btn-sm btn-red btn-delete-google-sheet d-inline-flex align-items-center justify-content-center">
// <i class='bx bxs-trash'></i>
// </button>
// `;
// }
if (!canUpdate && !canDelete) {
buttons = `<span class="text-muted">No Privilege</span>`;
}
// if (!canUpdate && !canDelete) {
// buttons = `<span class="text-muted">No Privilege</span>`;
// }
return gridjs.html(
`<div class="d-flex justify-content-center gap-2">${buttons}</div>`

View File

@@ -39,7 +39,7 @@ class Menus {
"Name",
"Url",
"Icon",
"ParentID",
"Parent Name",
"Sort Order",
{
name: "Action",
@@ -97,16 +97,22 @@ class Menus {
.getAttribute("content")}`,
"Content-Type": "application/json",
},
then: (data) =>
data.data.map((item) => [
then: (data) => {
console.log("Full API Response:", data); // Log the full response
return data.data.map((item, index) => {
console.log(`Item ${index + 1}:`, item); // Log each item
return [
item.id,
item.name,
item.url,
item.icon,
item.parent_id,
item.parent?.name,
item.sort_order,
item.id,
]),
];
});
},
total: (data) => data.total,
},
}).render(tableContainer);

View File

@@ -15,9 +15,9 @@
<div class="card w-100">
<div class="card-body">
<div class="d-flex flex-wrap justify-content-end align-items-center mb-2">
@if ($user_menu_permission['allow_create'])
<!-- @if ($user_menu_permission['allow_create'])
<a href="#" class="btn btn-success btn-sm d-block d-sm-inline w-auto">Create</a>
@endif
@endif -->
</div>
<div id="table-data-google-sheets"
data-updater="{{ $user_menu_permission['allow_update'] }}"