add crud general settings
This commit is contained in:
@@ -1,36 +1,108 @@
|
||||
import { Grid } from "gridjs/dist/gridjs.umd.js";
|
||||
import gridjs from 'gridjs/dist/gridjs.umd.js'
|
||||
import 'gridjs/dist/gridjs.umd.js'
|
||||
import gridjs from "gridjs/dist/gridjs.umd.js";
|
||||
import "gridjs/dist/gridjs.umd.js";
|
||||
import GlobalConfig from "../../global-config.js";
|
||||
|
||||
class SyncronizeTask {
|
||||
init(){
|
||||
this.initTableGeneralSettings();
|
||||
}
|
||||
initTableGeneralSettings(){
|
||||
new Grid({
|
||||
columns: [
|
||||
"ID", "Key", "Value", "Description", "Created",
|
||||
],
|
||||
pagination: {
|
||||
limit: 10,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}?page=${page}`
|
||||
}
|
||||
},
|
||||
sort: true,
|
||||
search: {
|
||||
server: {
|
||||
url: (prev, page, keyword) => `${prev}?page=${page}&search=${keyword}`
|
||||
}
|
||||
},
|
||||
server: {
|
||||
url: `${GlobalConfig.apiHost}/api/global-settings`,
|
||||
then: data => data.data.map((item) => [item.id, item.key, item.value, item.description, item.created_at])
|
||||
}
|
||||
}).render(document.getElementById("general-setting-table"));
|
||||
}
|
||||
init() {
|
||||
this.initTableGeneralSettings();
|
||||
}
|
||||
initTableGeneralSettings() {
|
||||
const table = new Grid({
|
||||
columns: [
|
||||
"ID",
|
||||
"Key",
|
||||
"Value",
|
||||
"Description",
|
||||
"Created",
|
||||
{
|
||||
name: "Actions",
|
||||
width: "120px",
|
||||
formatter: function (cell) {
|
||||
console.log("cell data", cell);
|
||||
return gridjs.html(`
|
||||
<div class="d-flex justify-items-end gap-10">
|
||||
<a href="/settings/general/${cell}/edit" class="btn btn-warning me-2">Update</a>
|
||||
<button class="btn btn-delete btn-delete-global-settings" data-id="${cell}">Delete</button>
|
||||
</div>
|
||||
`);
|
||||
},
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
limit: 15,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}?page=${page}`,
|
||||
},
|
||||
},
|
||||
sort: true,
|
||||
search: {
|
||||
server: {
|
||||
url: (prev, page, keyword) =>
|
||||
`${prev}?page=${page}&search=${keyword}`,
|
||||
},
|
||||
},
|
||||
server: {
|
||||
url: `${GlobalConfig.apiHost}/api/global-settings`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${document
|
||||
.querySelector('meta[name="csrf-token"]')
|
||||
.getAttribute("content")}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
then: (data) =>
|
||||
data.data.map((item) => [
|
||||
item.id,
|
||||
item.key,
|
||||
item.value,
|
||||
item.description,
|
||||
item.created_at,
|
||||
item.id,
|
||||
]),
|
||||
},
|
||||
});
|
||||
table.render(document.getElementById("general-setting-table"));
|
||||
|
||||
document.addEventListener("click", this.handleDelete);
|
||||
}
|
||||
handleDelete(event) {
|
||||
if (event.target.classList.contains("btn-delete-global-settings")) {
|
||||
event.preventDefault();
|
||||
const id = event.target.getAttribute("data-id");
|
||||
|
||||
if (confirm("Are you sure you want to delete this item?")) {
|
||||
fetch(`/settings/general/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": document
|
||||
.querySelector('meta[name="csrf-token"]')
|
||||
.getAttribute("content"),
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
alert("Item deleted successfully!");
|
||||
window.location.reload();
|
||||
} else {
|
||||
return response.json().then((error) => {
|
||||
throw new Error(
|
||||
error.message || "Failed to delete item."
|
||||
);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error deleting item:", error);
|
||||
alert("Something went wrong. Please try again.");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', function (e) {
|
||||
new SyncronizeTask().init();
|
||||
});
|
||||
document.addEventListener("click", function (e) {
|
||||
handleDelete(e); // Call the function on click event
|
||||
});
|
||||
document.addEventListener("DOMContentLoaded", function (e) {
|
||||
new SyncronizeTask().init();
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<div class="collapse" id="sidebarSettings">
|
||||
<ul class="nav sub-navbar-nav">
|
||||
<li class="sub-nav-item">
|
||||
<a class="sub-nav-link" href="{{ route ('settings.general' ) }}">General</a>
|
||||
<a class="sub-nav-link" href="{{ route ('general.index' ) }}">General</a>
|
||||
</li>
|
||||
<li class="sub-nav-item">
|
||||
<a class="sub-nav-link" href="{{ route ('settings.syncronize' ) }}">Syncronize</a>
|
||||
@@ -78,6 +78,22 @@
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link menu-arrow" href="#sidebarSettings" data-bs-toggle="collapse" role="button"
|
||||
aria-expanded="false" aria-controls="sidebarSettings">
|
||||
<span class="nav-icon">
|
||||
<iconify-icon icon="mingcute:task-line"></iconify-icon>
|
||||
</span>
|
||||
<span class="nav-text">Request Assignment</span>
|
||||
</a>
|
||||
<div class="collapse" id="sidebarSettings">
|
||||
<ul class="nav sub-navbar-nav">
|
||||
<li class="sub-nav-item">
|
||||
<a class="sub-nav-link" href="{{ route ('request-assignments.index' ) }}">Task</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@extends('layouts.vertical', ['subtitle' => 'Master'])\
|
||||
@extends('layouts.vertical', ['subtitle' => 'Master'])
|
||||
|
||||
@section('css')
|
||||
@vite(['node_modules/gridjs/dist/theme/mermaid.min.css'])
|
||||
|
||||
@@ -1,3 +1,23 @@
|
||||
<div>
|
||||
<!-- The biggest battle is the war against ignorance. - Mustafa Kemal Atatürk -->
|
||||
@extends('layouts.vertical', ['subtitle' => 'Request Assignments'])
|
||||
|
||||
@section('css')
|
||||
@vite(['node_modules/gridjs/dist/theme/mermaid.min.css'])
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
@include('layouts.partials/page-title', ['title' => 'Request Assignment', 'subtitle' => 'Task'])
|
||||
|
||||
<div class="row">
|
||||
<div>
|
||||
<h1>Request Assignment Page</h1>
|
||||
</div>
|
||||
<div>
|
||||
<div id="table-import-datasources"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
@endsection
|
||||
@@ -5,22 +5,46 @@
|
||||
@include('layouts.partials/page-title', ['title' => 'Se', 'subtitle' => 'Syncronize'])
|
||||
|
||||
<div class="row">
|
||||
@if (session('error'))
|
||||
<div class="alert alert-danger">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
<div class="columns-md">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form>
|
||||
<div class="mb-3">
|
||||
<label for="keyInput" class="form-label">Key</label>
|
||||
<input type="text" id="simpleinput" class="form-control">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="valueInput" class="form-label">Value</label>
|
||||
<input type="text" id="simpleinput" class="form-control">
|
||||
</div>
|
||||
<button type="button" class="btn btn-outline-success width-lg">Create</button>
|
||||
</form>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form action="{{ route('general.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="mb-3">
|
||||
<label for="key" class="form-label">Key</label>
|
||||
<input type="text" id="key" class="form-control" name="key">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="value" class="form-label">Value</label>
|
||||
<input type="text" id="value" class="form-control" name="value">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="type" class="form-label">Type</label>
|
||||
<input type="text" id="type" class="form-control" name="type">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<input type="text" id="description" class="form-control" name="description">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success width-lg">Create</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
56
resources/views/settings/general/edit.blade.php
Normal file
56
resources/views/settings/general/edit.blade.php
Normal file
@@ -0,0 +1,56 @@
|
||||
@extends('layouts.vertical', ['subtitle' => 'Create User'])
|
||||
|
||||
@section('content')
|
||||
|
||||
@include('layouts.partials/page-title', ['title' => 'Se', 'subtitle' => 'Syncronize'])
|
||||
|
||||
<div class="row">
|
||||
@if (session('error'))
|
||||
<div class="alert alert-danger">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
<div class="columns-md">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form action="{{ route('general.update', $data->id) }}" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="mb-3">
|
||||
<label for="key" class="form-label">Key</label>
|
||||
<input type="text" id="key" class="form-control" name="key" value="{{ $data->key }}" readonly>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="value" class="form-label">Value</label>
|
||||
<input type="text" id="value" class="form-control" name="value" value="{{ $data->value }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="type" class="form-label">Type</label>
|
||||
<input type="text" id="type" class="form-control" name="type" value="{{ $data->type }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<input type="text" id="description" class="form-control" name="description" value="{{ $data->description }}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success width-lg">Update</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
@vite(['resources/js/tables/common-table.js'])
|
||||
@endsection
|
||||
@@ -9,12 +9,12 @@
|
||||
@include('layouts.partials/page-title', ['title' => 'Settings', 'subtitle' => 'Syncronize'])
|
||||
|
||||
<div class="row">
|
||||
<div class="d-flex justify-content-end pb-3">
|
||||
<button type="button" class="btn btn-outline-success width-lg">Create</button>
|
||||
</div>
|
||||
<div>
|
||||
<div id="general-setting-table"></div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end pb-3">
|
||||
<a href="{{ route('general.create') }}" class="btn btn-success width-lg">Create</a>
|
||||
</div>
|
||||
<div>
|
||||
<div id="general-setting-table"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user