Files
citrus-cms/resources/views/admin-ajax/document-history.blade.php
T
2026-04-28 21:15:09 +03:00

330 lines
9.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* @api-readonly
* Returns document history
*/
use App\Models\DocumentHistory;
$request = request();
$table = $request->input('table');
$column = $request->input('column');
$row_id = $request->input('row_id');
$file_name = $request->input('file_name');
// Document history verilerini DocumentHistory modelinden çek
$query = DocumentHistory::query();
if ($file_name) {
// File name'e göre arama
$file_name = str_replace(".pdf", "", $file_name);
$query->where('file_name', 'LIKE', '%' . $file_name . '%');
} else {
// Table, column, row_id'ye göre arama
$query->where('table_name', $table)
->where('column_name', $column)
->where('row_id', $row_id);
}
$documentHistory = $query->orderBy('action_date', 'DESC')
->get()
->map(function($item) {
return [
'id' => $item->id,
'user_name' => $item->user_name,
'action' => $item->action,
'file_name' => $item->file_name,
'file_size' => $item->file_size,
'moved_from' => $item->moved_from,
'moved_to' => $item->moved_to,
'action_date' => $item->action_date,
'file_path' => $item->file_path,
'notes' => $item->notes
];
})
->toArray();
$historyJson = json_encode($documentHistory);
?>
<style>
.document-history-container {
padding: 10px;
}
.history-info {
background: #f8f9fa;
padding: 10px;
border-radius: 5px;
margin-bottom: 15px;
font-size: 14px;
}
.action-buttons {
display: flex;
gap: 5px;
}
.btn-action {
padding: 3px 8px;
font-size: 11px;
border-radius: 3px;
text-decoration: none;
color: white;
}
.btn-view {
background-color: #17a2b8;
}
.btn-download {
background-color: #28a745;
}
.btn-view:hover {
background-color: #138496;
color: white;
}
.btn-download:hover {
background-color: #218838;
color: white;
}
#documentHistoryGrid {
height: 400px;
margin-top: 10px;
width: 100%;
}
.document-history-container {
width: 100%;
max-width: 100%;
}
.document-history-container .dx-datagrid {
width: 100% !important;
}
</style>
<div class="document-history-container">
<div class="history-info">
@if($file_name)
<strong>Document History for File:</strong> {{ $file_name }}
@else
<strong>Document History for:</strong> {{ $table }}.{{ $column }} (Row ID: {{ $row_id }})
@endif
</div>
<div id="documentHistoryGrid"></div>
</div>
<script>
$(document).ready(function() {
var historyData = {!! $historyJson !!};
$("#documentHistoryGrid").dxDataGrid({
dataSource: historyData,
keyExpr: "id",
allowColumnResizing: true,
allowColumnReordering: true,
showBorders: true,
showRowLines: true,
rowAlternationEnabled: true,
searchPanel: {
visible: true,
width: 240,
placeholder: "Search in history..."
},
headerFilter: {
visible: true
},
filterRow: {
visible: true
},
paging: {
pageSize: 10
},
pager: {
showPageSizeSelector: true,
allowedPageSizes: [5, 10, 20, 50],
showInfo: true
},
columnAutoWidth: false,
columnResizingMode: 'widget',
columns: [
{
dataField: "id",
caption: "ID",
width: 60,
minWidth: 50,
alignment: "center"
},
{
dataField: "user_name",
caption: "User",
width: 120,
minWidth: 80
},
{
dataField: "action",
caption: "Action",
width: 80,
minWidth: 70,
cellTemplate: function(container, options) {
var action = options.value;
var badgeClass = '';
switch(action) {
case 'Upload':
badgeClass = 'badge-success';
break;
case 'Download':
badgeClass = 'badge-primary';
break;
case 'Archive':
badgeClass = 'badge-warning';
break;
case 'Delete':
badgeClass = 'badge-danger';
break;
default:
badgeClass = 'badge-secondary';
}
container.html('<span class="badge ' + badgeClass + '">' + action + '</span>');
}
},
{
dataField: "file_name",
caption: "File Name",
width: 250,
minWidth: 150
},
{
dataField: "file_size",
caption: "Size",
width: 80,
minWidth: 60,
alignment: "center"
},
{
dataField: "moved_from",
caption: "From",
width: 80,
minWidth: 60,
alignment: "center"
},
{
dataField: "moved_to",
caption: "To",
width: 80,
minWidth: 60,
alignment: "center"
},
{
dataField: "action_date",
caption: "Date & Time",
width: 140,
minWidth: 120,
dataType: "datetime",
format: "dd/MM/yyyy HH:mm"
},
{
dataField: "notes",
caption: "Notes",
width: 200,
minWidth: 100
},
{
caption: "Actions",
width: 100,
minWidth: 80,
allowSorting: false,
allowFiltering: false,
cellTemplate: function(container, options) {
var data = options.data;
var actionsHtml = '<div class="action-buttons">';
// View button
actionsHtml += '<a href="#" class="btn-action btn-view" onclick="viewDocument(\'' + data.file_path + '\', \'' + data.file_name + '\')" title="View Document">';
actionsHtml += '<i class="fa fa-eye"></i>';
actionsHtml += '</a>';
// Download button
actionsHtml += '<a href="#" class="btn-action btn-download" onclick="downloadDocument(\'' + data.file_path + '\', \'' + data.file_name + '\')" title="Download Document">';
actionsHtml += '<i class="fa fa-download"></i>';
actionsHtml += '</a>';
actionsHtml += '</div>';
container.html(actionsHtml);
}
}
],
onRowPrepared: function(e) {
if (e.rowType === "data") {
// Silinen dosyalar için farklı stil
if (e.data.action === "Delete") {
e.rowElement.css("background-color", "#ffe6e6");
}
}
}
});
});
// Document view function
function viewDocument(filePath, fileName) {
// Doğru URL oluştur
var viewUrl = buildFileUrl(filePath);
// PDF viewer modal açma
Swal.fire({
title: 'View Document: ' + fileName,
html: '<iframe src="' + viewUrl + '" width="100%" height="500px" frameborder="0"></iframe>',
width: '90%',
showCloseButton: true,
showConfirmButton: false,
customClass: {
popup: 'pdf-viewer-popup'
}
});
}
// Document download function
function downloadDocument(filePath, fileName) {
// Doğru URL oluştur
var downloadUrl = buildFileUrl(filePath);
// Download işlemi
var link = document.createElement('a');
link.href = downloadUrl;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// Success message
Swal.fire({
icon: 'success',
title: 'Download Started',
text: fileName + ' is being downloaded.',
timer: 2000,
showConfirmButton: false
});
}
// Helper function to build correct file URL
function buildFileUrl(filePath) {
// Base URL'i temizle
var cleanPath = filePath.replace(/^\/+/, '');
// Eğer dosya yolu zaten storage/documents/ ile başlıyorsa
if (cleanPath.startsWith('storage/documents/')) {
return "{{ url('/') }}/" + cleanPath;
}
// Tüm dosya yollarını storage/documents/ altında organize et
else {
return "{{ url('storage/documents') }}/" + cleanPath;
}
}
</script>