fix menu with parent data and remove action google sheet not available feature
This commit is contained in:
@@ -22,7 +22,8 @@ class MenusController extends Controller
|
|||||||
$query = $query->where("name", "like", "%".$request->get("search")."%");
|
$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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,6 +14,16 @@ class MenuResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray(Request $request): array
|
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
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,7 @@ class Menu extends Model
|
|||||||
public function children(){
|
public function children(){
|
||||||
return $this->hasMany(Menu::class,'parent_id');
|
return $this->hasMany(Menu::class,'parent_id');
|
||||||
}
|
}
|
||||||
|
public function parent(){
|
||||||
|
return $this->belongsTo(Menu::class,'parent_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ class GoogleSheets {
|
|||||||
tableContainer.innerHTML = "";
|
tableContainer.innerHTML = "";
|
||||||
|
|
||||||
// Get user permissions from data attributes
|
// Get user permissions from data attributes
|
||||||
let canUpdate = tableContainer.getAttribute("data-updater") === "1";
|
// let canUpdate = tableContainer.getAttribute("data-updater") === "1";
|
||||||
let canDelete = tableContainer.getAttribute("data-destroyer") === "1";
|
// let canDelete = tableContainer.getAttribute("data-destroyer") === "1";
|
||||||
|
|
||||||
this.table = new Grid({
|
this.table = new Grid({
|
||||||
columns: [
|
columns: [
|
||||||
@@ -65,25 +65,25 @@ class GoogleSheets {
|
|||||||
</a>
|
</a>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (canUpdate) {
|
// if (canUpdate) {
|
||||||
buttons += `
|
// buttons += `
|
||||||
<a href="#" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
|
// <a href="#" class="btn btn-yellow btn-sm d-inline-flex align-items-center justify-content-center">
|
||||||
<i class='bx bx-edit'></i>
|
// <i class='bx bx-edit'></i>
|
||||||
</a>
|
// </a>
|
||||||
`;
|
// `;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (canDelete) {
|
// if (canDelete) {
|
||||||
buttons += `
|
// buttons += `
|
||||||
<button data-id="${cell}" class="btn btn-sm btn-red btn-delete-google-sheet d-inline-flex align-items-center justify-content-center">
|
// <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>
|
// <i class='bx bxs-trash'></i>
|
||||||
</button>
|
// </button>
|
||||||
`;
|
// `;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!canUpdate && !canDelete) {
|
// if (!canUpdate && !canDelete) {
|
||||||
buttons = `<span class="text-muted">No Privilege</span>`;
|
// buttons = `<span class="text-muted">No Privilege</span>`;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return gridjs.html(
|
return gridjs.html(
|
||||||
`<div class="d-flex justify-content-center gap-2">${buttons}</div>`
|
`<div class="d-flex justify-content-center gap-2">${buttons}</div>`
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class Menus {
|
|||||||
"Name",
|
"Name",
|
||||||
"Url",
|
"Url",
|
||||||
"Icon",
|
"Icon",
|
||||||
"ParentID",
|
"Parent Name",
|
||||||
"Sort Order",
|
"Sort Order",
|
||||||
{
|
{
|
||||||
name: "Action",
|
name: "Action",
|
||||||
@@ -97,16 +97,22 @@ class Menus {
|
|||||||
.getAttribute("content")}`,
|
.getAttribute("content")}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
then: (data) =>
|
then: (data) => {
|
||||||
data.data.map((item) => [
|
console.log("Full API Response:", data); // Log the full response
|
||||||
item.id,
|
|
||||||
item.name,
|
return data.data.map((item, index) => {
|
||||||
item.url,
|
console.log(`Item ${index + 1}:`, item); // Log each item
|
||||||
item.icon,
|
return [
|
||||||
item.parent_id,
|
item.id,
|
||||||
item.sort_order,
|
item.name,
|
||||||
item.id,
|
item.url,
|
||||||
]),
|
item.icon,
|
||||||
|
item.parent?.name,
|
||||||
|
item.sort_order,
|
||||||
|
item.id,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
},
|
||||||
total: (data) => data.total,
|
total: (data) => data.total,
|
||||||
},
|
},
|
||||||
}).render(tableContainer);
|
}).render(tableContainer);
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
<div class="card w-100">
|
<div class="card w-100">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="d-flex flex-wrap justify-content-end align-items-center mb-2">
|
<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>
|
<a href="#" class="btn btn-success btn-sm d-block d-sm-inline w-auto">Create</a>
|
||||||
@endif
|
@endif -->
|
||||||
</div>
|
</div>
|
||||||
<div id="table-data-google-sheets"
|
<div id="table-data-google-sheets"
|
||||||
data-updater="{{ $user_menu_permission['allow_update'] }}"
|
data-updater="{{ $user_menu_permission['allow_update'] }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user