Files
think-greaterchiangmai/think-backend.greaterchiangmai.com/resources/views2/backend/document/index.blade.php
2025-11-11 14:55:29 +07:00

439 lines
24 KiB
PHP

@extends('layouts.backendTemplate')
@section('content')
<style>
.link-container {
display: flex;
/* Use flexbox for alignment */
align-items: center;
/* Center items vertically */
justify-content: space-between;
/* Space between the URL and button */
}
.file-url {
flex: 1;
/* Allow the URL to take up available space */
color: #007bff;
/* Link color */
text-decoration: none;
/* Remove underline */
overflow: hidden;
/* Hide overflow */
white-space: nowrap;
/* Prevent text wrapping */
text-overflow: ellipsis;
/* Add ellipsis for overflow */
margin-right: 10px;
/* Space between text and button */
}
</style>
<!--begin::Main-->
<div class="app-main flex-column flex-row-fluid" id="kt_app_main">
<div class="d-flex flex-column flex-column-fluid">
@include('uc.breadcrumbList', [
'title' => 'Document Management',
'pageName' => 'Document Management',
])
<div id="kt_app_content" class="app-content flex-column-fluid">
<div id="kt_app_content_container" class="app-container container-xxl">
<div class="card">
@if (Session::has('messageSuccess'))
<div class="card-body">
@include('uc/messageSuccess')
</div>
@endif
@if (Session::has('messageFail'))
<div class="card-body">
@include('uc/messageFail')
</div>
@endif
<div class="card-header border-0 pt-6">
<div class="d-flex align-items-center position-relative my-1">
</div>
@if (Auth::user()->role != 2)
<div class="card-toolbar">
<div class="d-flex justify-content-end" style="margin-right: 5px;"
data-kt-customer-table-toolbar="base">
<a href="{{ url('document/add-folder') }}" class="btn btn-light-primary me-3"
id="kt_file_manager_new_folder">New
Folder</a>
</div>
<div class="d-flex justify-content-end" data-kt-customer-table-toolbar="base">
<a href="{{ url('document/add') }}" class="btn btn-primary">Add </a>
</div>
</div>
@endif
</div>
<div class="card-header border-0 pt-5">
<div class="card-title">
<div class="d-flex align-items-center position-relative my-1">
<span class="svg-icon svg-icon-1 position-absolute ms-4">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg">
<rect opacity="0.5" x="17.0365" y="15.1223" width="8.15546" height="2"
rx="1" transform="rotate(45 17.0365 15.1223)" fill="currentColor">
</rect>
<path
d="M11 19C6.55556 19 3 15.4444 3 11C3 6.55556 6.55556 3 11 3C15.4444 3 19 6.55556 19 11C19 15.4444 15.4444 19 11 19ZM11 5C7.53333 5 5 7.53333 5 11C5 14.4667 7.53333 17 11 17C14.4667 17 17 14.4667 17 11C17 7.53333 14.4667 5 11 5Z"
fill="currentColor"></path>
</svg>
</span>
<input type="text" table-filter="search"
class="form-control form-control-solid w-250px ps-15" placeholder="Search" />
</div>
</div>
</div>
<div class="card-body py-4">
<!--begin::Table-->
<table class="table align-middle table-row-dashed fs-6 gy-5" id="data-table">
<!--begin::Table head-->
<thead>
<!--begin::Table row-->
<tr class="text-start text-muted fw-bold fs-7 text-uppercase gs-0">
<th class="min-w-125px">Name</th>
<th class="min-w-125px">Created</th>
<th class="text-end min-w-100px">Manage</th>
</tr>
</thead>
<tbody class="text-gray-600 fw-semibold">
@foreach ($folderView as $obj)
<tr>
<td>
<div class="d-flex align-items-center">
<span class="svg-icon svg-icon-2x svg-icon-primary me-4">
<svg width="24" height="24" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.3" d="M10 4H21C21.6 4 22 4.4 22 5V7H10V4Z"
fill="currentColor"></path>
<path
d="M9.2 3H3C2.4 3 2 3.4 2 4V19C2 19.6 2.4 20 3 20H21C21.6 20 22 19.6 22 19V7C22 6.4 21.6 6 21 6H12L10.4 3.60001C10.2 3.20001 9.7 3 9.2 3Z"
fill="currentColor"></path>
</svg>
</span>
<a href="{{ url('document/folder/' . $obj->id) }}"
class="text-gray-800 text-hover-primary">
{{ $obj->name }}</a>
</div>
</td>
<td>
{{ Carbon\Carbon::parse($obj['created_at'])->format('d, M Y') }}
</td>
<td class="min-w-100px text-end">
{{-- Edit --}}
<a href="{{ url('document/edit-folder/' . $obj['id']) }}"
class="btn btn-icon btn-bg-light btn-active-color-primary btn-sm me-1">
<span class="svg-icon svg-icon-3">
<svg width="24" height="24" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.3"
d="M21.4 8.35303L19.241 10.511L13.485 4.755L15.643 2.59595C16.0248 2.21423 16.5426 1.99988 17.0825 1.99988C17.6224 1.99988 18.1402 2.21423 18.522 2.59595L21.4 5.474C21.7817 5.85581 21.9962 6.37355 21.9962 6.91345C21.9962 7.45335 21.7817 7.97122 21.4 8.35303ZM3.68699 21.932L9.88699 19.865L4.13099 14.109L2.06399 20.309C1.98815 20.5354 1.97703 20.7787 2.03189 21.0111C2.08674 21.2436 2.2054 21.4561 2.37449 21.6248C2.54359 21.7934 2.75641 21.9115 2.989 21.9658C3.22158 22.0201 3.4647 22.0084 3.69099 21.932H3.68699Z"
fill="currentColor" />
<path
d="M5.574 21.3L3.692 21.928C3.46591 22.0032 3.22334 22.0141 2.99144 21.9594C2.75954 21.9046 2.54744 21.7864 2.3789 21.6179C2.21036 21.4495 2.09202 21.2375 2.03711 21.0056C1.9822 20.7737 1.99289 20.5312 2.06799 20.3051L2.696 18.422L5.574 21.3ZM4.13499 14.105L9.891 19.861L19.245 10.507L13.489 4.75098L4.13499 14.105Z"
fill="currentColor" />
</svg>
</span>
</a>
{{-- Delete --}}
<a href="#" data-id="{{ $obj['id'] }}"
class="btn btn-icon btn-bg-light btn-active-color-primary btn-sm delete-folder-item">
<span class="svg-icon svg-icon-3">
<svg width="24" height="24" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M5 9C5 8.44772 5.44772 8 6 8H18C18.5523 8 19 8.44772 19 9V18C19 19.6569 17.6569 21 16 21H8C6.34315 21 5 19.6569 5 18V9Z"
fill="currentColor" />
<path opacity="0.5"
d="M5 5C5 4.44772 5.44772 4 6 4H18C18.5523 4 19 4.44772 19 5V5C19 5.55228 18.5523 6 18 6H6C5.44772 6 5 5.55228 5 5V5Z"
fill="currentColor" />
<path opacity="0.5"
d="M9 4C9 3.44772 9.44772 3 10 3H14C14.5523 3 15 3.44772 15 4V4H9V4Z"
fill="currentColor" />
</svg>
</span>
</a>
</td>
</tr>
@endforeach
@foreach ($itemView as $obj)
<tr>
<td>
<div class="d-flex align-items-center">
<a href="#" class="text-gray-800 text-hover-primary">
@if (isset($obj['name']) && Str::endsWith($obj['name'], ['.pdf']))
<img alt="PDF Icon" class="w-30px me-3"
src="{{ url('assets/media/svg/files/pdf.svg') }}">
@elseif (isset($obj['name']) && Str::endsWith($obj['name'], ['.doc', '.docx']))
<img alt="DOC Icon" class="w-30px me-3"
src="{{ url('assets/media/svg/files/doc.svg') }}">
@else
<span class="svg-icon svg-icon-2x svg-icon-primary me-4">
<svg width="24" height="24" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.3"
d="M19 22H5C4.4 22 4 21.6 4 21V3C4 2.4 4.4 2 5 2H14L20 8V21C20 21.6 19.6 22 19 22Z"
fill="currentColor"></path>
<path d="M15 8H20L14 2V7C14 7.6 14.4 8 15 8Z"
fill="currentColor"></path>
</svg>
</span>
@endif
{{ $obj['name'] }}
</a>
</div>
</td>
<td>
{{ Carbon\Carbon::parse($obj['created_at'])->format('d, M Y') }}
</td>
<td class="min-w-100px text-end">
{{-- Download --}}
<a href="{{ env('R2_SCHEMA_URL') . $obj['name'] }}" target="_blank"
class="btn btn-sm btn-icon btn-light btn-active-light-primary"
type="button" data-bs-toggle="tooltip" aria-label="Coming soon"
data-bs-original-title="Coming soon" data-kt-initialized="1">
<i class="bi bi-download fs-3"></i>
</a>
{{-- Copy --}}
<button type="button" data-action="copy"
data-url="{{ env('R2_SCHEMA_URL') . $obj['name'] }}"
class="btn btn-sm btn-icon btn-light btn-active-light-primary copy-button">
<span class="svg-icon svg-icon-2">
<svg width="24" height="24" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.5"
d="M18 2H9C7.34315 2 6 3.34315 6 5H8C8 4.44772 8.44772 4 9 4H18C18.5523 4 19 4.44772 19 5V16C19 16.5523 18.5523 17 18 17V19C19.6569 19 21 17.6569 21 16V5C21 3.34315 19.6569 2 18 2Z"
fill="currentColor"></path>
<path fill-rule="evenodd" clip-rule="evenodd"
d="M14.7857 7.125H6.21429C5.62255 7.125 5.14286 7.6007 5.14286 8.1875V18.8125C5.14286 19.3993 5.62255 19.875 6.21429 19.875H14.7857C15.3774 19.875 15.8571 19.3993 15.8571 18.8125V8.1875C15.8571 7.6007 15.3774 7.125 14.7857 7.125ZM6.21429 5C4.43908 5 3 6.42709 3 8.1875V18.8125C3 20.5729 4.43909 22 6.21429 22H14.7857C16.5609 22 18 20.5729 18 18.8125V8.1875C18 6.42709 16.5609 5 14.7857 5H6.21429Z"
fill="currentColor"></path>
</svg>
</span>
<!--end::Svg Icon-->
</button>
{{-- Delete --}}
@if (Auth::user()->role != 2)
<a href="#" data-id="{{ $obj['id'] }}"
class="btn btn-icon btn-bg-light btn-active-color-primary btn-sm delete-item">
<span class="svg-icon svg-icon-3">
<svg width="24" height="24" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M5 9C5 8.44772 5.44772 8 6 8H18C18.5523 8 19 8.44772 19 9V18C19 19.6569 17.6569 21 16 21H8C6.34315 21 5 19.6569 5 18V9Z"
fill="currentColor" />
<path opacity="0.5"
d="M5 5C5 4.44772 5.44772 4 6 4H18C18.5523 4 19 4.44772 19 5V5C19 5.55228 18.5523 6 18 6H6C5.44772 6 5 5.55228 5 5V5Z"
fill="currentColor" />
<path opacity="0.5"
d="M9 4C9 3.44772 9.44772 3 10 3H14C14.5523 3 15 3.44772 15 4V4H9V4Z"
fill="currentColor" />
</svg>
</span>
</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
@stop
@section('script')
<script type="text/javascript">
const baseUrl = "{{ url('document') }}";
var datatable;
datatable = $("#data-table").DataTable({
"info": false,
"order": []
});
// Filter by search
const filterSearch = document.querySelector('[table-filter="search"]');
filterSearch.addEventListener('keyup', function(e) {
datatable.search(e.target.value).draw();
});
// filter by status
const filterStatus = document.querySelector('[table-filter="status"]');
$(filterStatus).on('change', e => {
let value = e.target.value;
if (value === 'all') {
value = '';
}
datatable.column(4).search(value).draw();
});
// Remove
$(document).on('click', '.delete-item', function() {
swal.fire({
allowOutsideClick: false,
text: "Are you sure you would like to Delete?",
icon: "warning",
buttonsStyling: false,
showDenyButton: true,
confirmButtonText: "Yes",
denyButtonText: 'No',
customClass: {
confirmButton: "btn btn-primary",
denyButton: "btn btn-light-danger"
}
}).then((result) => {
if (result.isConfirmed) {
alertLoading("Loading")
// set up ajax
initAjaxSetupToken();
const ajaxProp = {
url: "{{ url('document/delete') }}",
type: 'POST',
data: {
item_id: $(this).data('id')
},
};
$.ajax(ajaxProp).done(function(res) {
if (res.status) {
const url = "{{ url('document') }}";
alertSuccessWithUrl('Notice', "Delete success", url);
hideLoading();
} else {
alertFail('Notice', res.message ?? "Unsuccessfully");
hideLoading();
}
}).fail(function(xhr, status, error) {
logAjaxError(xhr, status, error);
alertFail('Notice', error.message ?? "Unsuccessfully");
hideLoading();
});
}
});
});
document.addEventListener('DOMContentLoaded', function() {
const copyButtons = document.querySelectorAll('.copy-button');
copyButtons.forEach(button => {
button.addEventListener('click', function() {
const urlToCopy = button.getAttribute('data-url');
// Copy the URL to the clipboard
navigator.clipboard.writeText(urlToCopy).then(() => {
alert(
'Link copied to clipboard!'
); // You can change this to a toast notification
}).catch(err => {
console.error('Could not copy text: ', err);
});
});
});
});
// Delete folder
$(document).on('click', '.delete-folder-item', function() {
swal.fire({
allowOutsideClick: false,
text: "Are you sure you would like to Delete?",
icon: "warning",
buttonsStyling: false,
showDenyButton: true,
confirmButtonText: "Yes",
denyButtonText: 'No',
customClass: {
confirmButton: "btn btn-primary",
denyButton: "btn btn-light-danger"
}
}).then((result) => {
if (result.isConfirmed) {
alertLoading("Loading")
// set up ajax
initAjaxSetupToken();
const ajaxProp = {
url: "{{ url('document/delete-folder') }}",
type: 'POST',
data: {
item_id: $(this).data('id')
},
};
$.ajax(ajaxProp).done(function(res) {
if (res.status) {
const url = "{{ url('document') }}";
alertSuccessWithUrl('Notice', "Delete success", url);
hideLoading();
} else {
alertFail('Notice', res.message ?? "Unsuccessfully");
hideLoading();
}
}).fail(function(xhr, status, error) {
logAjaxError(xhr, status, error);
alertFail('Notice', error.message ?? "Unsuccessfully");
hideLoading();
});
}
});
});
</script>
@endsection