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

Add pagination feature #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions config/translation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
'middleware' => 'auth',
],

/**
* Enable pagination of translations
*
* @type boolean
*/
'pagination_enabled' => false,


/**
* Define number of translations per page
*
* @type integer
*/
'per_page' => 40,

/**
* Enable deletion of translations
*
Expand Down
1 change: 1 addition & 0 deletions resources/views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class="glyphicon glyphicon-trash"></span></a>
<?php endforeach; ?>
</tbody>
</table>
<?php if ($paginationEnabled) echo $translations->links()->toHtml(); ?>
<?php else: ?>
<fieldset>
<legend>Supported locales</legend>
Expand Down
23 changes: 20 additions & 3 deletions src/Controller.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php namespace Barryvdh\TranslationManager;
<?php

namespace Barryvdh\TranslationManager;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Routing\Controller as BaseController;
use Tanmuhittin\LaravelGoogleTranslate\Commands\TranslateFilesCommand;

class Controller extends BaseController
Expand Down Expand Up @@ -40,6 +43,19 @@ public function getIndex($group = null)
$translations[$translation->key][$translation->locale] = $translation;
}

if ($this->manager->getConfig('pagination_enabled')) {
$total = count($translations);
$page = request()->get('page', 1);
$per_page = $this->manager->getConfig('per_page');
$offSet = ($page * $per_page) - $per_page;
$itemsForCurrentPage = array_slice($translations, $offSet, $per_page, true);
$prefix = $this->manager->getConfig('route')['prefix'];
$path = url("$prefix/view/$group");

$paginator = new LengthAwarePaginator($itemsForCurrentPage, $total, $per_page, $page);
$translations = $paginator->withPath($path);
}

return view('translation-manager::index')
->with('translations', $translations)
->with('locales', $locales)
Expand All @@ -48,6 +64,7 @@ public function getIndex($group = null)
->with('numTranslations', $numTranslations)
->with('numChanged', $numChanged)
->with('editUrl', action('\Barryvdh\TranslationManager\Controller@postEdit', [$group]))
->with('paginationEnabled', $this->manager->getConfig('pagination_enabled'))
->with('deleteEnabled', $this->manager->getConfig('delete_enabled'));
}

Expand Down