First commit
This commit is contained in:
253
resources/views/admin/documents/chunks.blade.php
Normal file
253
resources/views/admin/documents/chunks.blade.php
Normal file
@@ -0,0 +1,253 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', 'Chunk Review — ' . Str::limit($document->title, 40))
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item"><a href="{{ route('admin.documents.index') }}">Dokumen</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('admin.documents.show', $document) }}">{{ Str::limit($document->title, 30) }}</a></li>
|
||||
<li class="breadcrumb-item active">Chunk Review v{{ $version->version_number }}</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
{{-- Header --}}
|
||||
<div class="d-flex align-items-start justify-content-between mb-3 flex-wrap gap-2">
|
||||
<div>
|
||||
<h4 class="mb-0 fw-bold">Chunk Review</h4>
|
||||
<p class="text-muted small mb-0">
|
||||
{{ $document->title }} — Versi {{ $version->version_number }}
|
||||
@if($version->page_count)
|
||||
· {{ $version->page_count }} muka surat
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
<a href="{{ route('admin.documents.show', $document) }}" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>Kembali ke Dokumen
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- Flash Messages --}}
|
||||
@if(session('success'))
|
||||
<div class="alert alert-success alert-dismissible fade show py-2" role="alert">
|
||||
<i class="bi bi-check-circle me-1"></i>{{ session('success') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
@endif
|
||||
@if(session('error'))
|
||||
<div class="alert alert-danger alert-dismissible fade show py-2" role="alert">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>{{ session('error') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- Status Summary Pills --}}
|
||||
<div class="d-flex flex-wrap gap-2 mb-3">
|
||||
<a href="{{ route('admin.documents.chunks', ['document' => $document, 'version' => $version]) }}"
|
||||
class="btn btn-sm {{ !$statusFilter ? 'btn-dark' : 'btn-outline-dark' }}">
|
||||
Semua <span class="badge bg-secondary ms-1">{{ array_sum($statusCounts) }}</span>
|
||||
</a>
|
||||
|
||||
@php
|
||||
$statusDef = [
|
||||
\App\Models\DocumentChunk::STATUS_INDEXED => ['label' => 'Diindex', 'class' => 'btn-success'],
|
||||
\App\Models\DocumentChunk::STATUS_NEEDS_REINDEX => ['label' => 'Perlu Reindex', 'class' => 'btn-warning'],
|
||||
\App\Models\DocumentChunk::STATUS_NEEDS_REVIEW => ['label' => 'Perlu Semak', 'class' => 'btn-info'],
|
||||
\App\Models\DocumentChunk::STATUS_PENDING => ['label' => 'Menunggu', 'class' => 'btn-light border'],
|
||||
\App\Models\DocumentChunk::STATUS_EXCLUDED => ['label' => 'Dikecualikan', 'class' => 'btn-secondary'],
|
||||
\App\Models\DocumentChunk::STATUS_SUPERSEDED => ['label' => 'Digantikan', 'class' => 'btn-dark'],
|
||||
\App\Models\DocumentChunk::STATUS_FAILED_EMBEDDING => ['label' => 'Gagal Embed', 'class' => 'btn-danger'],
|
||||
];
|
||||
@endphp
|
||||
|
||||
@foreach($statusDef as $statusKey => $def)
|
||||
@if(isset($statusCounts[$statusKey]) && $statusCounts[$statusKey] > 0)
|
||||
<a href="{{ route('admin.documents.chunks', ['document' => $document, 'version' => $version, 'status' => $statusKey]) }}"
|
||||
class="btn btn-sm {{ $statusFilter === $statusKey ? $def['class'] : 'btn-outline-' . str_replace('btn-', '', $def['class']) }}">
|
||||
{{ $def['label'] }}
|
||||
<span class="badge bg-white text-dark ms-1">{{ $statusCounts[$statusKey] }}</span>
|
||||
</a>
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
{{-- Chunk List --}}
|
||||
@forelse($chunks as $chunk)
|
||||
<div class="card border-0 shadow-sm mb-2 {{ $chunk->isSuperseded() ? 'opacity-50' : '' }}">
|
||||
<div class="card-body py-2 px-3">
|
||||
<div class="row align-items-center g-2">
|
||||
|
||||
{{-- Metadata --}}
|
||||
<div class="col-12 col-md-7">
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
{{-- Status badge --}}
|
||||
<span class="badge {{ $chunk->getStatusBadgeClass() }}" style="font-size:.7rem">
|
||||
{{ $chunk->getStatusLabel() }}
|
||||
</span>
|
||||
|
||||
{{-- Chunk number --}}
|
||||
<span class="badge bg-light text-dark border fw-normal" style="font-size:.7rem">
|
||||
#{{ $chunk->chunk_index + 1 }}
|
||||
</span>
|
||||
|
||||
{{-- Edited badge --}}
|
||||
@if($chunk->is_edited)
|
||||
<span class="badge bg-primary-subtle text-primary border border-primary" style="font-size:.65rem">
|
||||
<i class="bi bi-pencil me-1"></i>Edited
|
||||
</span>
|
||||
@endif
|
||||
|
||||
{{-- Split badge --}}
|
||||
@if($chunk->parent_chunk_id)
|
||||
<span class="badge bg-warning-subtle text-warning border border-warning" style="font-size:.65rem">
|
||||
<i class="bi bi-scissors me-1"></i>Split
|
||||
</span>
|
||||
@endif
|
||||
|
||||
@if($chunk->childChunks->count() > 0)
|
||||
<span class="badge bg-dark-subtle text-dark border" style="font-size:.65rem">
|
||||
<i class="bi bi-diagram-2 me-1"></i>{{ $chunk->childChunks->count() }} anak
|
||||
</span>
|
||||
@endif
|
||||
|
||||
{{-- Metadata kecil --}}
|
||||
@if($chunk->page_number)
|
||||
<span class="text-muted" style="font-size:.75rem">ms.{{ $chunk->page_number }}</span>
|
||||
@endif
|
||||
|
||||
@if($chunk->section_heading)
|
||||
<span class="text-muted text-truncate" style="font-size:.75rem;max-width:200px"
|
||||
title="{{ $chunk->section_heading }}">
|
||||
{{ Str::limit($chunk->section_heading, 40) }}
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
{{-- Preview teks --}}
|
||||
<p class="text-muted mb-0 mt-1" style="font-size:.8rem;line-height:1.4">
|
||||
{{ Str::limit($chunk->getEmbeddableText(), 150) }}
|
||||
</p>
|
||||
|
||||
{{-- Editor info --}}
|
||||
@if($chunk->is_edited && $chunk->editor)
|
||||
<p class="mb-0 mt-1" style="font-size:.7rem;color:#aaa">
|
||||
Diedit oleh {{ $chunk->editor->name }}
|
||||
{{ $chunk->edited_at?->diffForHumans() }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
{{-- Actions --}}
|
||||
<div class="col-12 col-md-5">
|
||||
<div class="d-flex gap-1 flex-wrap justify-content-md-end">
|
||||
|
||||
{{-- View detail --}}
|
||||
<a href="{{ route('admin.chunks.show', $chunk) }}"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-eye"></i> Detail
|
||||
</a>
|
||||
|
||||
@if(!$chunk->isSuperseded())
|
||||
|
||||
{{-- Split --}}
|
||||
<a href="{{ route('admin.chunks.split', $chunk) }}"
|
||||
class="btn btn-sm btn-outline-warning"
|
||||
title="Split chunk ini">
|
||||
<i class="bi bi-scissors"></i>
|
||||
</a>
|
||||
|
||||
{{-- Exclude / Include --}}
|
||||
@if($chunk->exclude_from_index)
|
||||
<form method="POST" action="{{ route('admin.chunks.include', $chunk) }}" class="d-inline">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-sm btn-outline-success"
|
||||
title="Kembalikan ke indexing"
|
||||
onclick="return confirm('Kembalikan chunk ini ke indexing?')">
|
||||
<i class="bi bi-check-circle"></i>
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<form method="POST" action="{{ route('admin.chunks.exclude', $chunk) }}" class="d-inline">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary"
|
||||
title="Kecualikan dari indexing"
|
||||
onclick="return confirm('Kecualikan chunk #{{ $chunk->chunk_index + 1 }} dari indexing?')">
|
||||
<i class="bi bi-slash-circle"></i>
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
{{-- Reindex --}}
|
||||
@if($chunk->isIndexable())
|
||||
<form method="POST" action="{{ route('admin.chunks.reindex', $chunk) }}" class="d-inline">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-sm btn-outline-info"
|
||||
title="Trigger reindex"
|
||||
onclick="return confirm('Reindex chunk #{{ $chunk->chunk_index + 1 }} sekarang?')">
|
||||
<i class="bi bi-arrow-repeat"></i>
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
@else
|
||||
{{-- Superseded — tunjukkan link ke children --}}
|
||||
@if($chunk->childChunks->count() > 0)
|
||||
<span class="text-muted small">
|
||||
<i class="bi bi-arrow-down-right me-1"></i>
|
||||
{{ $chunk->childChunks->count() }} chunk baharu
|
||||
</span>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- Child chunks inline (jika chunk ini pernah di-split) --}}
|
||||
@if($chunk->childChunks->count() > 0)
|
||||
<div class="mt-2 ps-3 border-start border-2 border-warning">
|
||||
<p class="text-muted mb-1" style="font-size:.72rem">
|
||||
<i class="bi bi-diagram-2 me-1"></i>Dipecahkan kepada:
|
||||
</p>
|
||||
@foreach($chunk->childChunks as $child)
|
||||
<div class="d-flex align-items-center gap-2 mb-1">
|
||||
<span class="badge {{ $child->getStatusBadgeClass() }}" style="font-size:.65rem">
|
||||
{{ $child->getStatusLabel() }}
|
||||
</span>
|
||||
<span class="text-muted" style="font-size:.75rem">#{{ $child->chunk_index + 1 }}</span>
|
||||
<span class="text-muted text-truncate" style="font-size:.75rem">
|
||||
{{ Str::limit($child->getEmbeddableText(), 80) }}
|
||||
</span>
|
||||
<a href="{{ route('admin.chunks.show', $child) }}"
|
||||
class="btn btn-sm btn-link p-0 ms-auto" style="font-size:.72rem">
|
||||
Lihat →
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<div class="text-center py-5 text-muted">
|
||||
<i class="bi bi-collection display-6 d-block mb-2"></i>
|
||||
@if($statusFilter)
|
||||
Tiada chunk dengan status "{{ $statusFilter }}".
|
||||
<a href="{{ route('admin.documents.chunks', ['document' => $document, 'version' => $version]) }}">
|
||||
Lihat semua
|
||||
</a>
|
||||
@else
|
||||
Tiada chunk untuk versi ini.
|
||||
@endif
|
||||
</div>
|
||||
@endforelse
|
||||
|
||||
{{-- Pagination --}}
|
||||
@if($chunks->hasPages())
|
||||
<div class="mt-3">
|
||||
{{ $chunks->links() }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@endsection
|
||||
180
resources/views/admin/documents/create.blade.php
Normal file
180
resources/views/admin/documents/create.blade.php
Normal file
@@ -0,0 +1,180 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', 'Upload Dokumen')
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item"><a href="{{ route('admin.documents.index') }}">Dokumen</a></li>
|
||||
<li class="breadcrumb-item active">Upload Baru</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white border-bottom">
|
||||
<h5 class="mb-0 fw-bold"><i class="bi bi-upload me-2"></i>Upload Dokumen PDF</h5>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ route('admin.documents.store') }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Kategori <span class="text-danger">*</span></label>
|
||||
<select name="category_id" class="form-select @error('category_id') is-invalid @enderror" required>
|
||||
<option value="">— Pilih Kategori —</option>
|
||||
@foreach($categories as $cat)
|
||||
<option value="{{ $cat->id }}" {{ old('category_id') == $cat->id ? 'selected' : '' }}>
|
||||
{{ $cat->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('category_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Tajuk Dokumen <span class="text-danger">*</span></label>
|
||||
<input type="text" name="title" class="form-control @error('title') is-invalid @enderror"
|
||||
value="{{ old('title') }}" placeholder="Contoh: Garis Panduan Pelesenan Perniagaan 2024" required>
|
||||
@error('title')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Fail PDF <span class="text-danger">*</span></label>
|
||||
<input type="file" name="file" id="fileInput"
|
||||
class="form-control @error('file') is-invalid @enderror"
|
||||
accept=".pdf" required>
|
||||
<div class="form-text">
|
||||
Hanya fail PDF dibenarkan. Saiz maksimum:
|
||||
{{ round(config('knowledgebase.upload.max_file_size', 20480) / 1024) }}MB
|
||||
</div>
|
||||
@error('file')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
<div id="filePreview" class="mt-2 d-none">
|
||||
<div class="alert alert-info py-2 mb-0 small">
|
||||
<i class="bi bi-file-pdf me-1"></i>
|
||||
<span id="fileName"></span> —
|
||||
<span id="fileSize"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Deskripsi</label>
|
||||
<textarea name="description" class="form-control" rows="2"
|
||||
placeholder="Deskripsi ringkas dokumen ini...">{{ old('description') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Tarikh Kuat Kuasa</label>
|
||||
<input type="date" name="effective_date" class="form-control @error('effective_date') is-invalid @enderror"
|
||||
value="{{ old('effective_date') }}">
|
||||
@error('effective_date')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Tarikh Luput</label>
|
||||
<input type="date" name="expiry_date" class="form-control @error('expiry_date') is-invalid @enderror"
|
||||
value="{{ old('expiry_date') }}">
|
||||
@error('expiry_date')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Bahasa</label>
|
||||
<select name="language" class="form-select">
|
||||
<option value="ms" {{ old('language', 'ms') == 'ms' ? 'selected' : '' }}>Bahasa Melayu</option>
|
||||
<option value="en" {{ old('language') == 'en' ? 'selected' : '' }}>English</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Tag</label>
|
||||
<input type="text" id="tagsInput" class="form-control"
|
||||
placeholder="Taip dan tekan Enter..."
|
||||
value="{{ old('tags') ? implode(', ', old('tags')) : '' }}">
|
||||
<div id="tagsContainer" class="mt-1"></div>
|
||||
<input type="hidden" name="tags" id="tagsHidden">
|
||||
<div class="form-text">Tekan Enter atau koma untuk tambah tag.</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Nota Upload</label>
|
||||
<input type="text" name="change_notes" class="form-control"
|
||||
value="{{ old('change_notes', 'Versi pertama.') }}"
|
||||
placeholder="Nota ringkas tentang upload ini...">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2 mt-4 pt-3 border-top">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-upload me-1"></i>Upload & Proses
|
||||
</button>
|
||||
<a href="{{ route('admin.documents.index') }}" class="btn btn-outline-secondary">
|
||||
Batal
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-light border mt-3 small">
|
||||
<i class="bi bi-info-circle me-2 text-info"></i>
|
||||
Dokumen akan diproses secara <strong>background</strong> selepas upload. Proses extraction, chunking dan embedding mungkin mengambil masa beberapa minit bergantung pada saiz fail.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
// Preview fail yang dipilih
|
||||
$('#fileInput').on('change', function() {
|
||||
const file = this.files[0];
|
||||
if (file) {
|
||||
const size = file.size < 1048576
|
||||
? (file.size / 1024).toFixed(1) + ' KB'
|
||||
: (file.size / 1048576).toFixed(1) + ' MB';
|
||||
$('#fileName').text(file.name);
|
||||
$('#fileSize').text(size);
|
||||
$('#filePreview').removeClass('d-none');
|
||||
}
|
||||
});
|
||||
|
||||
// Tag input
|
||||
let tags = [];
|
||||
|
||||
function renderTags() {
|
||||
const container = $('#tagsContainer');
|
||||
container.empty();
|
||||
tags.forEach((tag, i) => {
|
||||
container.append(
|
||||
`<span class="badge bg-secondary me-1 mb-1">${tag}
|
||||
<i class="bi bi-x-circle ms-1" style="cursor:pointer" data-i="${i}"></i></span>`
|
||||
);
|
||||
});
|
||||
$('#tagsHidden').val(tags.map((t, i) => `tags[${i}]=${t}`).join('&'));
|
||||
// Rebuild hidden inputs properly
|
||||
$('[name^="tags["]').remove();
|
||||
tags.forEach((tag, i) => {
|
||||
$('form').append(`<input type="hidden" name="tags[${i}]" value="${tag}">`);
|
||||
});
|
||||
}
|
||||
|
||||
$('#tagsInput').on('keydown', function(e) {
|
||||
if (e.key === 'Enter' || e.key === ',') {
|
||||
e.preventDefault();
|
||||
const val = $(this).val().trim().replace(/,$/, '');
|
||||
if (val && !tags.includes(val)) {
|
||||
tags.push(val);
|
||||
renderTags();
|
||||
}
|
||||
$(this).val('');
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '.bi-x-circle', function() {
|
||||
const i = $(this).data('i');
|
||||
tags.splice(i, 1);
|
||||
renderTags();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
80
resources/views/admin/documents/edit.blade.php
Normal file
80
resources/views/admin/documents/edit.blade.php
Normal file
@@ -0,0 +1,80 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', 'Edit Dokumen')
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item"><a href="{{ route('admin.documents.index') }}">Dokumen</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('admin.documents.show', $document) }}">{{ Str::limit($document->title, 30) }}</a></li>
|
||||
<li class="breadcrumb-item active">Edit</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white border-bottom">
|
||||
<h5 class="mb-0 fw-bold"><i class="bi bi-pencil me-2"></i>Edit Maklumat Dokumen</h5>
|
||||
<small class="text-muted">Untuk upload fail PDF baru, gunakan butang "Upload Versi Baru" pada halaman dokumen.</small>
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ route('admin.documents.update', $document) }}">
|
||||
@csrf @method('PUT')
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Kategori <span class="text-danger">*</span></label>
|
||||
<select name="category_id" class="form-select" required>
|
||||
@foreach($categories as $cat)
|
||||
<option value="{{ $cat->id }}"
|
||||
{{ old('category_id', $document->category_id) == $cat->id ? 'selected' : '' }}>
|
||||
{{ $cat->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Tajuk <span class="text-danger">*</span></label>
|
||||
<input type="text" name="title" class="form-control @error('title') is-invalid @enderror"
|
||||
value="{{ old('title', $document->title) }}" required>
|
||||
@error('title')<div class="invalid-feedback">{{ $message }}</div>@enderror
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Deskripsi</label>
|
||||
<textarea name="description" class="form-control" rows="2">{{ old('description', $document->description) }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Tarikh Kuat Kuasa</label>
|
||||
<input type="date" name="effective_date" class="form-control"
|
||||
value="{{ old('effective_date', $document->effective_date?->toDateString()) }}">
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Tarikh Luput</label>
|
||||
<input type="date" name="expiry_date" class="form-control"
|
||||
value="{{ old('expiry_date', $document->expiry_date?->toDateString()) }}">
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label fw-semibold">Bahasa</label>
|
||||
<select name="language" class="form-select">
|
||||
<option value="ms" {{ old('language', $document->language) == 'ms' ? 'selected' : '' }}>BM</option>
|
||||
<option value="en" {{ old('language', $document->language) == 'en' ? 'selected' : '' }}>EN</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2 mt-4 pt-3 border-top">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-save me-1"></i>Kemaskini
|
||||
</button>
|
||||
<a href="{{ route('admin.documents.show', $document) }}" class="btn btn-outline-secondary">Batal</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
153
resources/views/admin/documents/index.blade.php
Normal file
153
resources/views/admin/documents/index.blade.php
Normal file
@@ -0,0 +1,153 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', 'Dokumen')
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item active">Dokumen PDF</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex align-items-center justify-content-between mb-4">
|
||||
<h4 class="mb-0 fw-bold">Dokumen PDF</h4>
|
||||
<a href="{{ route('admin.documents.create') }}" class="btn btn-primary">
|
||||
<i class="bi bi-upload me-1"></i>Upload Dokumen
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- Filter --}}
|
||||
<div class="card border-0 shadow-sm mb-4">
|
||||
<div class="card-body py-3">
|
||||
<form method="GET" class="row g-2 align-items-end">
|
||||
<div class="col-md-4">
|
||||
<input type="text" name="search" class="form-control form-control-sm"
|
||||
placeholder="Cari tajuk..." value="{{ request('search') }}">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<select name="category_id" class="form-select form-select-sm">
|
||||
<option value="">Semua Kategori</option>
|
||||
@foreach($categories as $cat)
|
||||
<option value="{{ $cat->id }}" {{ request('category_id') == $cat->id ? 'selected' : '' }}>
|
||||
{{ $cat->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select name="status" class="form-select form-select-sm">
|
||||
<option value="">Semua Status</option>
|
||||
<option value="active" {{ request('status') == 'active' ? 'selected' : '' }}>Aktif</option>
|
||||
<option value="processing" {{ request('status') == 'processing' ? 'selected' : '' }}>Sedang Diproses</option>
|
||||
<option value="inactive" {{ request('status') == 'inactive' ? 'selected' : '' }}>Tidak Aktif</option>
|
||||
<option value="failed" {{ request('status') == 'failed' ? 'selected' : '' }}>Gagal</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-search me-1"></i>Tapis
|
||||
</button>
|
||||
@if(request()->hasAny(['search', 'category_id', 'status']))
|
||||
<a href="{{ route('admin.documents.index') }}" class="btn btn-sm btn-link text-muted">Reset</a>
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Table --}}
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="ps-3">Tajuk</th>
|
||||
<th>Kategori</th>
|
||||
<th>Versi</th>
|
||||
<th>Status</th>
|
||||
<th>Tarikh</th>
|
||||
<th class="text-end pe-3">Tindakan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($documents as $doc)
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
<div class="fw-semibold">{{ $doc->title }}</div>
|
||||
@if($doc->description)
|
||||
<small class="text-muted text-truncate d-block" style="max-width:300px">{{ $doc->description }}</small>
|
||||
@endif
|
||||
@if($doc->tags)
|
||||
@foreach(array_slice($doc->tags, 0, 3) as $tag)
|
||||
<span class="badge bg-light text-dark border me-1" style="font-size:.65rem">{{ $tag }}</span>
|
||||
@endforeach
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge" style="background: {{ $doc->category->color ?? '#6c757d' }}">
|
||||
{{ $doc->category->name }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-light text-dark border">
|
||||
v{{ $doc->currentVersion?->version_number ?? '—' }}
|
||||
</span>
|
||||
@if($doc->versions_count > 1)
|
||||
<small class="text-muted">({{ $doc->versions_count }} versi)</small>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@php
|
||||
$statusMap = [
|
||||
'active' => ['class' => 'bg-success', 'label' => 'Aktif'],
|
||||
'inactive' => ['class' => 'bg-secondary', 'label' => 'Tidak Aktif'],
|
||||
'processing' => ['class' => 'badge-processing', 'label' => 'Diproses'],
|
||||
'draft' => ['class' => 'bg-light text-dark border', 'label' => 'Draf'],
|
||||
'failed' => ['class' => 'badge-failed', 'label' => 'Gagal'],
|
||||
];
|
||||
$s = $statusMap[$doc->status] ?? ['class' => 'bg-light', 'label' => $doc->status];
|
||||
@endphp
|
||||
<span class="badge {{ $s['class'] }}">{{ $s['label'] }}</span>
|
||||
@if($doc->currentVersion && $doc->currentVersion->processing_status !== 'indexed' && $doc->status == 'processing')
|
||||
<br><small class="text-muted" style="font-size:.65rem">{{ $doc->currentVersion->processing_status }}</small>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<small class="text-muted">{{ $doc->created_at->format('d/m/Y') }}</small>
|
||||
@if($doc->effective_date)
|
||||
<br><small class="text-muted">Kuat kuasa: {{ $doc->effective_date->format('d/m/Y') }}</small>
|
||||
@endif
|
||||
</td>
|
||||
<td class="text-end pe-3">
|
||||
<a href="{{ route('admin.documents.show', $doc) }}"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-eye"></i>
|
||||
</a>
|
||||
@if($doc->status !== 'processing')
|
||||
<form method="POST" action="{{ route('admin.documents.toggle-status', $doc) }}" class="d-inline">
|
||||
@csrf @method('PATCH')
|
||||
<button type="submit" class="btn btn-sm {{ $doc->is_active ? 'btn-outline-warning' : 'btn-outline-success' }}"
|
||||
title="{{ $doc->is_active ? 'Nyahaktifkan' : 'Aktifkan' }}">
|
||||
<i class="bi {{ $doc->is_active ? 'bi-pause-circle' : 'bi-play-circle' }}"></i>
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted py-5">
|
||||
<i class="bi bi-file-pdf fs-2 d-block mb-2 opacity-25"></i>
|
||||
Tiada dokumen ditemui.
|
||||
<a href="{{ route('admin.documents.create') }}">Upload yang pertama.</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@if($documents->hasPages())
|
||||
<div class="card-footer bg-white border-top py-3">
|
||||
{{ $documents->links() }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endsection
|
||||
223
resources/views/admin/documents/show.blade.php
Normal file
223
resources/views/admin/documents/show.blade.php
Normal file
@@ -0,0 +1,223 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', $document->title)
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item"><a href="{{ route('admin.documents.index') }}">Dokumen</a></li>
|
||||
<li class="breadcrumb-item active">{{ Str::limit($document->title, 40) }}</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex align-items-start justify-content-between mb-4">
|
||||
<div>
|
||||
<h4 class="mb-1 fw-bold">{{ $document->title }}</h4>
|
||||
<div class="d-flex gap-2 align-items-center flex-wrap">
|
||||
<span class="badge" style="background:{{ $document->category->color }}">{{ $document->category->name }}</span>
|
||||
@php
|
||||
$statusMap = [
|
||||
'active' => 'bg-success',
|
||||
'inactive' => 'bg-secondary',
|
||||
'processing' => 'bg-warning',
|
||||
'failed' => 'bg-danger',
|
||||
];
|
||||
@endphp
|
||||
<span class="badge {{ $statusMap[$document->status] ?? 'bg-light text-dark' }}">{{ ucfirst($document->status) }}</span>
|
||||
@if($document->effective_date)
|
||||
<small class="text-muted">Kuat kuasa: {{ $document->effective_date->format('d/m/Y') }}</small>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<a href="{{ route('admin.documents.edit', $document) }}" class="btn btn-outline-secondary btn-sm">
|
||||
<i class="bi bi-pencil me-1"></i>Edit
|
||||
</a>
|
||||
@if(auth()->user()->isAdmin())
|
||||
<form method="POST" action="{{ route('admin.documents.reindex', $document) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-outline-info btn-sm"
|
||||
onclick="return confirm('Adakah anda pasti untuk reindex dokumen ini?')">
|
||||
<i class="bi bi-arrow-repeat me-1"></i>Reindex
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
<form method="POST" action="{{ route('admin.documents.toggle-status', $document) }}">
|
||||
@csrf @method('PATCH')
|
||||
<button type="submit" class="btn btn-sm {{ $document->is_active ? 'btn-warning' : 'btn-success' }}">
|
||||
@if($document->is_active)
|
||||
<i class="bi bi-pause-circle me-1"></i>Nyahaktif
|
||||
@else
|
||||
<i class="bi bi-play-circle me-1"></i>Aktifkan
|
||||
@endif
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
{{-- Info Dokumen --}}
|
||||
<div class="col-lg-4">
|
||||
<div class="card border-0 shadow-sm mb-3">
|
||||
<div class="card-header bg-white border-bottom"><h6 class="mb-0 fw-semibold">Maklumat Dokumen</h6></div>
|
||||
<div class="card-body small">
|
||||
@if($document->description)
|
||||
<p>{{ $document->description }}</p>
|
||||
@endif
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-5 text-muted">Bahasa</dt>
|
||||
<dd class="col-7">{{ $document->language == 'ms' ? 'Bahasa Melayu' : 'English' }}</dd>
|
||||
@if($document->expiry_date)
|
||||
<dt class="col-5 text-muted">Tarikh Luput</dt>
|
||||
<dd class="col-7">{{ $document->expiry_date->format('d/m/Y') }}</dd>
|
||||
@endif
|
||||
<dt class="col-5 text-muted">Dicipta</dt>
|
||||
<dd class="col-7">{{ $document->created_at->format('d/m/Y H:i') }}</dd>
|
||||
</dl>
|
||||
@if($document->tags)
|
||||
<div class="mt-2">
|
||||
@foreach($document->tags as $tag)
|
||||
<span class="badge bg-light text-dark border me-1">{{ $tag }}</span>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Upload versi baru --}}
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white border-bottom">
|
||||
<h6 class="mb-0 fw-semibold">Upload Versi Baru</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ route('admin.documents.upload-version', $document) }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
<div class="mb-2">
|
||||
<input type="file" name="file" class="form-control form-control-sm" accept=".pdf" required>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<input type="text" name="change_notes" class="form-control form-control-sm"
|
||||
placeholder="Nota perubahan (optional)">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-sm btn-primary w-100">
|
||||
<i class="bi bi-upload me-1"></i>Upload Versi Baru
|
||||
</button>
|
||||
</form>
|
||||
<small class="text-muted mt-1 d-block">Versi lama tidak akan dipadam.</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Senarai Versi --}}
|
||||
<div class="col-lg-8">
|
||||
<div class="card border-0 shadow-sm mb-3">
|
||||
<div class="card-header bg-white border-bottom">
|
||||
<h6 class="mb-0 fw-semibold">Sejarah Versi</h6>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover align-middle mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="ps-3">Versi</th>
|
||||
<th>Fail</th>
|
||||
<th>Status</th>
|
||||
<th>Diupload</th>
|
||||
<th class="text-end pe-3">Tindakan</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($document->versions->sortByDesc('version_number') as $version)
|
||||
<tr class="{{ $version->is_current ? 'table-primary' : '' }}">
|
||||
<td class="ps-3">
|
||||
<span class="badge bg-light text-dark border">v{{ $version->version_number }}</span>
|
||||
@if($version->is_current)
|
||||
<span class="badge bg-success-subtle text-success border border-success ms-1">Semasa</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<div class="small">{{ $version->original_filename }}</div>
|
||||
<small class="text-muted">{{ $version->file_size_formatted }}</small>
|
||||
@if($version->page_count)
|
||||
<small class="text-muted"> · {{ $version->page_count }} ms.</small>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@php
|
||||
$ps = [
|
||||
'indexed' => ['bg-success', 'Selesai'],
|
||||
'processing' => ['bg-warning', 'Diproses'],
|
||||
'embedding' => ['bg-warning', 'Embedding'],
|
||||
'extraction_failed' => ['bg-danger', 'Gagal Extract'],
|
||||
'failed' => ['bg-danger', 'Gagal'],
|
||||
'pending' => ['bg-secondary', 'Menunggu'],
|
||||
];
|
||||
$pInfo = $ps[$version->processing_status] ?? ['bg-light text-dark', $version->processing_status];
|
||||
@endphp
|
||||
<span class="badge {{ $pInfo[0] }}">{{ $pInfo[1] }}</span>
|
||||
@if($version->hasFailed() && $version->processing_error)
|
||||
<br><small class="text-danger d-block" style="max-width:200px"
|
||||
title="{{ $version->processing_error }}">
|
||||
{{ Str::limit($version->processing_error, 50) }}
|
||||
</small>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<small>{{ $version->created_at->format('d/m/Y') }}</small>
|
||||
@if($version->uploader)
|
||||
<br><small class="text-muted">{{ $version->uploader->name }}</small>
|
||||
@endif
|
||||
</td>
|
||||
<td class="text-end pe-3">
|
||||
@if($version->processing_status === 'indexed')
|
||||
<a href="{{ route('admin.documents.chunks', [$document, $version]) }}"
|
||||
class="btn btn-sm btn-outline-secondary"
|
||||
title="Lihat Chunk">
|
||||
<i class="bi bi-list-ul"></i>
|
||||
</a>
|
||||
@endif
|
||||
<a href="{{ route('admin.documents.download', [$document, $version]) }}"
|
||||
class="btn btn-sm btn-outline-primary" title="Muat Turun">
|
||||
<i class="bi bi-download"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Preview Chunks (versi semasa) --}}
|
||||
@if($document->currentVersion && $document->currentVersion->processing_status === 'indexed')
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header bg-white border-bottom d-flex align-items-center justify-content-between">
|
||||
<h6 class="mb-0 fw-semibold">Chunk Terkini ({{ $document->currentVersion->chunks->count() }} preview)</h6>
|
||||
<a href="{{ route('admin.documents.chunks', [$document, $document->currentVersion]) }}"
|
||||
class="btn btn-sm btn-link p-0 text-muted">Lihat semua</a>
|
||||
</div>
|
||||
<div class="list-group list-group-flush">
|
||||
@foreach($document->currentVersion->chunks->take(5) as $chunk)
|
||||
<div class="list-group-item py-2 px-3">
|
||||
<div class="d-flex align-items-center gap-2 mb-1">
|
||||
<span class="badge bg-light text-dark border" style="font-size:.65rem">
|
||||
Chunk #{{ $chunk->chunk_index + 1 }}
|
||||
</span>
|
||||
@if($chunk->page_number)
|
||||
<span class="badge bg-light text-dark border" style="font-size:.65rem">
|
||||
ms. {{ $chunk->page_number }}
|
||||
</span>
|
||||
@endif
|
||||
@if($chunk->section_heading)
|
||||
<span class="text-muted small text-truncate">{{ $chunk->section_heading }}</span>
|
||||
@endif
|
||||
<span class="badge {{ $chunk->is_embedded ? 'bg-success-subtle text-success' : 'bg-warning-subtle text-warning' }} ms-auto" style="font-size:.65rem">
|
||||
{{ $chunk->is_embedded ? 'Embedded' : 'Belum Embed' }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="mb-0 small text-muted" style="white-space:pre-wrap">{{ Str::limit($chunk->content, 200) }}</p>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user