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

Simple search bar #410

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
23 changes: 23 additions & 0 deletions resources/views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,29 @@
</form>
<hr>
<h4>Total: <?= $numTranslations ?>, changed: <?= $numChanged ?></h4>
<form action="" method="GET">
<div class="row">
<div class="col-xs-6 col-md-4">
<div class="input-group">
<input type="text" class="form-control" value="<?= request()->keywords ?>" name="keywords" placeholder="Search"/>
<div class="input-group-btn">
<button class="btn btn-primary" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</div>
</div>
<div class="form-check">
<span><b>Search in</b></span>
<input type="hidden" name="searchKeys" value="false">
<input type="checkbox" name="searchKeys" value="true" <?= request()->searchKeys === 'false' ? '' : 'checked' ?> class="form-check-input" id="searchKeys">
<label class="form-check-label" for="searchKeys">Keys</label>
<input type="hidden" name="searchValues" value="false">
<input type="checkbox" name="searchValues" value="true" <?= request()->searchValues === 'false' ? '' : 'checked' ?> class="form-check-input" id="searchValues">
<label class="form-check-label" for="searchValues">Locales</label>
</div>
</form>
<table class="table">
<thead>
<tr>
Expand Down
13 changes: 12 additions & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ public function getIndex($group = null)
$groups = [''=>'Choose a group'] + $groups;
$numChanged = Translation::where('group', $group)->where('status', Translation::STATUS_CHANGED)->count();

$allTranslations = Translation::where('group', $group);
if($searchKeywords = request()->keywords){
$allTranslations->where(function ($query) use ($searchKeywords) {
$query->when(request()->searchKeys == 'true', function ($query) use ($searchKeywords) {
return $query->where('key', 'like', '%' . $searchKeywords . '%');
})
->when(request()->searchValues == 'true', function ($query) use ($searchKeywords) {
return $query->orWhere('value', 'like', '%' . $searchKeywords . '%');
});
});
}
$allTranslations = $allTranslations->orderBy('key', 'asc')->get();

$allTranslations = Translation::where('group', $group)->orderBy('key', 'asc')->get();
$numTranslations = count($allTranslations);
$translations = [];
foreach($allTranslations as $translation){
Expand Down