From 8ba2826a7ea05d5d4b77e5997ca510f204b31a8a Mon Sep 17 00:00:00 2001 From: Chaoyi Zha Date: Sat, 1 Oct 2016 20:30:06 -0400 Subject: [PATCH] Add user link Datatable --- app/Http/Controllers/AdminController.php | 10 ++++++---- public/js/AdminCtrl.js | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index ffc283a..04e88dd 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -72,8 +72,13 @@ class AdminController extends Controller { public function paginateUserLinks(Request $request) { self::ensureLoggedIn(); - $username = session('username'); + $username = session('username'); + $user_links = Link::where('creator', $username) + ->select(['short_url', 'long_url', 'clicks', 'created_at']); + + return Datatables::of($user_links) + ->make(true); } public function displayAdminPage(Request $request) { @@ -98,9 +103,6 @@ class AdminController extends Controller { return redirect(route('index'))->with('error', 'Invalid or disabled account.'); } - $user_links = Link::where('creator', $username) - ->paginate(15, ['*'], 'links_page'); - return view('admin', [ 'role' => $role, 'api_key' => $user->api_key, diff --git a/public/js/AdminCtrl.js b/public/js/AdminCtrl.js index ddbba93..28a80de 100644 --- a/public/js/AdminCtrl.js +++ b/public/js/AdminCtrl.js @@ -51,18 +51,16 @@ polr.controller('AdminCtrl', function($scope, $compile) { }, datatables_config)); } - // var user_links_table = $('#user_link_table').DataTable({ - // "processing": true, - // "serverSide": true, - // "ajax": BASE_API_PATH + 'admin/get_user_links', - // - // "columns": [ - // {data: 'username', name: 'username'}, - // {data: 'email', name: 'email'}, - // {data: 'created_at', name: 'created_at'}, - // {data: 'active', name: 'active'} - // ] - // }); + var user_links_table = $('#user_links_table').DataTable($.extend({ + "ajax": BASE_API_PATH + 'admin/get_user_links', + + "columns": [ + {className: 'wrap-text', data: 'short_url', name: 'short_url'}, + {className: 'wrap-text', data: 'long_url', name: 'long_url'}, + {data: 'clicks', name: 'clicks'}, + {data: 'created_at', name: 'created_at'} + ] + }, datatables_config)); }; $scope.appendModal = function(html, id) {