Skip to content

Commit

Permalink
search result changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalbabu422 committed Feb 5, 2025
1 parent e5318f5 commit 76e6002
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 81 deletions.
15 changes: 11 additions & 4 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ public function autoComplete(Request $request)

public function basicSearch(Request $request)
{
$item = $request->input('item');
$item = $request->input('term'); // Get the search term from the request

$searchResults = ContentCatalogue::where('title', 'like', '%' . $item . '%')->get();
// Perform the search query with pagination
$searchResults = ContentCatalogue::where('title', 'like', '%' . $item . '%')->paginate(1); // Adjust pagination size

$view = view('search.basicsearch', compact('searchResults'))->render();
if ($request->ajax()) {
// Render the content part (search results) alone
$view = view('search.basicsearch', compact('searchResults'))->render();

return response()->json($view);
return response()->json($view);
}

// If it's not an AJAX request, return the normal view
return view('search.basicsearch', compact('searchResults'));
}
}
4 changes: 0 additions & 4 deletions resources/css/search-main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,3 @@ legend {
object-fit: fit;
margin-bottom: 10px;
}

.card-body {
text-align: center;
}
18 changes: 2 additions & 16 deletions resources/views/file/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<div class="row mt-4">
<div class="col-1">
<button type="submit" class="btn btn-primary btn-lg">Submit</button>
<button type="submit" class="btn btn-primary btn-lg" >Submit</button>
</div>
<div class="col-1">
<button class="btn btn-light btn-lg" type="reset" id="reset-button">Reset</button>
Expand Down Expand Up @@ -104,21 +104,7 @@
$('#reset-button').click(function () {
$('#file-upload-form').validate().resetForm();
});
@if (session('success'))
toastr.success("{{ session('success') }}", "Success", {
closeButton: true,
progressBar: true,
timeOut: 5000 // Time in milliseconds (5 seconds)
});
@elseif(session('error'))
toastr.error("{{ session('error') }}", "Error", {
closeButton: true,
progressBar: true,
timeOut: 5000 // Time in milliseconds (5 seconds)
});
@endif
</script>

<!--File Upload Scripts Ends-->
Expand Down
93 changes: 65 additions & 28 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@
<title>{{ config('app.name', 'KMS') }}</title>

<!-- Scripts -->
@vite(['resources/css/feather/feather.css', 'resources/css/vertical-layout-light/style.css',
'resources/css/mdi/css/materialdesignicons.min.css', 'resources/css/toastr.min.css',
'resources/css/dataTables.dataTables.min.css', 'resources/css/bootstrap.min.css', 'resources/css/search-main.css',
'resources/css/jquery-ui.min.css'])
@vite(['resources/css/feather/feather.css', 'resources/css/vertical-layout-light/style.css', 'resources/css/mdi/css/materialdesignicons.min.css', 'resources/css/bootstrap.min.css', 'resources/css/toastr.min.css', 'resources/css/dataTables.dataTables.min.css', 'resources/css/search-main.css', 'resources/css/jquery-ui.min.css'])

<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" />
<link rel="shortcut icon" href="{{ Vite::asset('resources/images/search.png') }}" />

<script src="{{ Vite::asset('resources/js/jquery.min.js') }}"></script>
<script src="{{ Vite::asset('resources/js/bootstrap.bundle.min.js') }}"></script>
<script src="{{ Vite::asset('resources/js/vendor.bundle.base.js') }}"></script>
<script src="{{ Vite::asset('resources/js/template.js') }}"></script>
<script src="{{ Vite::asset('resources/js/dashboard.js') }}"></script>
<script src="{{ Vite::asset('resources/js/jquery.validate.min.js') }}"></script>
<script src="{{ Vite::asset('resources/js/toastr.min.js') }}"></script>
<script src="{{ Vite::asset('resources/js/dataTables.min.js') }}"></script>
<script src="{{ Vite::asset('resources/js/bootstrap.bundle.min.js') }}"></script>
<script src="{{ Vite::asset('resources/js/jquery-ui.min.js') }}"></script>
</head>

Expand Down Expand Up @@ -68,21 +65,37 @@
<!-- container-scroller -->
</body>
<script>
$(document).ready(function () {
$(document).ready(function() {
@if (session('success'))
toastr.success("{{ session('success') }}", "Success", {
closeButton: true,
progressBar: true,
timeOut: 5000 // Time in milliseconds (5 seconds)
});
@elseif (session('error'))
toastr.error("{{ session('error') }}", "Error", {
closeButton: true,
progressBar: true,
timeOut: 5000 // Time in milliseconds (5 seconds)
});
@endif
// Initialize DataTables
$('.table').DataTable();
// Autocomplete setup
$('#search').autocomplete({
source: function (request, response) {
source: function(request, response) {
$.ajax({
url: "{{ route('search.autocomplete') }}", // Adjust the route as per your requirement
data: {
term: request.term // Send search term to server
},
success: function (data) {
success: function(data) {
// Populate autocomplete suggestions
response($.map(data, function (item) {
response($.map(data, function(item) {
return {
label: item
.title, // Display text in the autocomplete dropdown
Expand All @@ -97,30 +110,54 @@
});
// Handle form submission on Enter key press
$('#search').on('keydown', function (event) {
$('#search').on('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
if ($('#search').val().length > 0) {
$.ajax({
url: "{{ route('search.search') }}", // Replace with the route to handle the selected item
method: 'POST',
data: {
term: $('#search').val(),
_token: '{{ csrf_token() }}' // CSRF token for security in Laravel
},
success: function(response) {
$('#container').html(response);
},
error: function(error) {
console.error("Error:", error);
}
});
} else {
toastr.error("Please enter document title for search!", "Error", {
closeButton: true,
progressBar: true,
timeOut: 5000
});
}
}
$.ajax({
url: "{{ route('search.search') }}", // Replace with the route to handle the selected item
method: 'POST',
data: {
term: $('#search').val(),
_token: '{{ csrf_token() }}' // CSRF token for security in Laravel
},
success: function (response) {
console.log("Item selected:", response);
$('#container').html(response)
},
error: function (error) {
console.error("Error:", error);
}
});
});
});
$(document).on('click', '.pagination a', function(e) {
e.preventDefault(); // Prevent default behavior of pagination
var url = $(this).attr('href');
var term = $('#search').val();
// Make an AJAX request to fetch the next page
$.ajax({
url: url,
type: 'POST',
data: {
term: term, // Pass the search term in the request,
_token: '{{ csrf_token() }}' // CSRF token for security in Laravel
},
success: function(response) {
$('#container').html(response);
}
});
});
</script>



</html>
</html>
50 changes: 23 additions & 27 deletions resources/views/search/basicsearch.blade.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
<div class="container mt-5">
<!-- Search Results -->
<div class="row">
<!-- Example of a single card result -->
<div class="col-md-3 mb-4">
<div class="card">
<img src="{{ Vite::asset('resources/images/pdf-icon.svg') }}" alt="File icon"
class="search-file-icon mt-2">
<div class="card-body">
<h5 class="card-title">Document 1</h5>
<p class="card-text">PDF Document</p>
<p class="card-text"><small class="text-muted">Last modified: Feb 5, 2025</small></p>
@if (!empty($searchResults))
@foreach ($searchResults as $searchItems)
<!-- Example of a single card result -->
<div class="col-md-3 mb-4">
<div class="card">
<img src="{{ Vite::asset('resources/images/pdf-icon.svg') }}" alt="File icon"
class="search-file-icon mt-2">
<div class="card-body">
<h5 class="card-title">{{ $searchItems->title }}</h5>
<p class="card-text">PDF Document</p>
<p class="card-text"><small class="text-muted">Last modified: Feb 5, 2025</small></p>
</div>
</div>
</div>
@endforeach
<!-- Pagination Links -->
<div class="d-flex justify-content-center">
{!! $searchResults->links() !!}
</div>
</div>

<!-- Another example of a file result -->
<div class="col-md-3 mb-4">
<div class="card">
<img src="{{ Vite::asset('resources/images/pdf-icon.svg') }}" alt="File icon"
class="search-file-icon mt-2">
<div class="card-body">
<h5 class="card-title">Document 1</h5>
<p class="card-text">PDF Document</p>
<p class="card-text"><small class="text-muted">Last modified: Feb 5, 2025</small></p>
</div>
@else
<!-- Example of an empty result (if no search results) -->
<div class="col-12">
<p>No results found.</p>
</div>
</div>

<!-- Example of an empty result (if no search results) -->
<div class="col-12">
<p>No results found.</p>
</div>
@endif

</div>
</div>

4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
Route::get('/Download/{filename}', [FileController::class, 'download'])->name('File.download');

Route::get('/Directory', [DirectoryController::class, 'index'])->name('directory.index');

Route::get('/Search/Listings', [SearchController::class, 'autoComplete'])->name('search.autocomplete');
Route::post('/Search/basicSearch', [SearchController::class, 'basicSearch'])->name('search.search');
Route::match(['get', 'post'],'/Search/basicSearch', [SearchController::class, 'basicSearch'])->name('search.search');
});

require __DIR__ . '/auth.php';

0 comments on commit 76e6002

Please sign in to comment.