Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added simple search function #995

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions public/css/all.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/css/bootstrap.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/css/jquery-ui.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/js/bootstrap.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/js/jquery-3.2.1.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions public/js/jquery-ui.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions public/js/popper.min.js

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ $(document).on('click', '[data-display]', function() {
loadItems();
});

$(document).on('click', '#keyword-button', function() {
show_list = $(this).data('display');
loadItems();
});

$(document).on('click', '#keyword-reset-button', function() {
$('#keyword').val("");
show_list = $(this).data('display');
loadItems();
});

$(document).on('click', '[data-action]', function() {
window[$(this).data('action')]($(this).data('multiple') ? getSelectedItems() : getOneSelectedElement());
});
Expand Down Expand Up @@ -420,6 +431,7 @@ function createPagination(paginationSetting) {

function loadItems(page) {
loading(true);
var keyword = $('#keyword').val();
performLfmRequest('jsonitems', {show_list: show_list, sort_type: sort_type, page: page || 1}, 'html')
.done(function (data) {
selected = [];
Expand Down Expand Up @@ -786,7 +798,8 @@ function usingWysiwygEditor() {
function defaultParameters() {
return {
working_dir: $('#working_dir').val(),
type: $('#type').val()
type: $('#type').val(),
keyword: $('#keyword').val(),
};
}

Expand Down
36 changes: 32 additions & 4 deletions src/Controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace UniSharp\LaravelFilemanager\Controllers;

use Illuminate\Http\Request;

use UniSharp\LaravelFilemanager\Events\FileIsMoving;
use UniSharp\LaravelFilemanager\Events\FileWasMoving;
use UniSharp\LaravelFilemanager\Events\FolderIsMoving;
Expand All @@ -14,17 +16,30 @@ class ItemsController extends LfmController
*
* @return mixed
*/
public function getItems()
public function getItems(Request $request)
{
$currentPage = self::getCurrentPageFromRequest();

$perPage = $this->helper->getPaginationPerPage();
$items = array_merge($this->lfm->folders(), $this->lfm->files());

$items = array_map(function ($item) {
return $item->fill()->attributes;
}, $items);

$keyword = $request->keyword;
if (!empty($keyword)) {
$items = array_values(array_filter($items, function ($item) use ($keyword) {
if ($this->like_match("%".$keyword."%", $item['name'])) {
return true;
} else {
return false;
}
}));
}

return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)),
'items' => array_slice($items, ($currentPage - 1) * $perPage, $perPage),
'paginator' => [
'current_page' => $currentPage,
'total' => count($items),
Expand All @@ -35,6 +50,13 @@ public function getItems()
];
}


public function like_match($pattern, $subject)
{
$pattern = str_replace('%', '.*', preg_quote($pattern, '/'));
return (bool) preg_match("/^{$pattern}$/i", $subject);
}

public function move()
{
$items = request('items');
Expand Down Expand Up @@ -94,4 +116,10 @@ private static function getCurrentPageFromRequest()

return $currentPage;
}

private static function getKeywordFromRequest()
{
$keyword = request()->get('keyword', "");
return $keyword;
}
}
22 changes: 15 additions & 7 deletions src/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

<title>{{ trans('laravel-filemanager::lfm.title-page') }}</title>
<link rel="shortcut icon" type="image/png" href="{{ asset('vendor/laravel-filemanager/img/72px color.png') }}">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.css">
<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/all.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/jquery-ui.min.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/cropper.min.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/dropzone.min.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/laravel-filemanager/css/mime-icons.min.css') }}">
Expand Down Expand Up @@ -86,11 +86,19 @@
</ol>
</nav>


<div>
<input type="text" name="keyword" id="keyword" placeholder="keyword">
<button type="button" id="keyword-button" >Search</button>
<button type="button" id="keyword-reset-button" >Reset</button>
</div>

<div id="empty" class="d-none">
<i class="far fa-folder-open"></i>
{{ trans('laravel-filemanager::lfm.message-empty') }}
</div>


<div id="content"></div>
<div id="pagination"></div>

Expand Down Expand Up @@ -188,10 +196,10 @@
</a>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/jquery-3.2.1.min.js') }}"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/popper.min.js') }}"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/jquery-ui.min.js') }}"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/cropper.min.js') }}"></script>
<script src="{{ asset('vendor/laravel-filemanager/js/dropzone.min.js') }}"></script>
<script>
Expand Down