Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2016-05-22 10:44:31 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
be517de7dc49dcf0524588f6b971e9ea9d5cd118
be517de7
1 parent
23ab1f0c
Added pagination, sorting & searching to users list
As requested on #113
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
119 additions
and
13 deletions
app/Http/Controllers/UserController.php
app/Repos/UserRepo.php
app/helpers.php
resources/assets/sass/_lists.scss
resources/assets/sass/_text.scss
resources/views/settings/roles/index.blade.php
resources/views/users/index.blade.php
app/Http/Controllers/UserController.php
View file @
be517de
...
...
@@ -31,14 +31,21 @@ class UserController extends Controller
/**
* Display a listing of the users.
* @param Request $request
* @return Response
*/
public
function
index
()
public
function
index
(
Request
$request
)
{
$this
->
checkPermission
(
'users-manage'
);
$users
=
$this
->
userRepo
->
getAllUsers
();
$listDetails
=
[
'order'
=>
$request
->
has
(
'order'
)
?
$request
->
get
(
'order'
)
:
'asc'
,
'search'
=>
$request
->
has
(
'search'
)
?
$request
->
get
(
'search'
)
:
''
,
'sort'
=>
$request
->
has
(
'sort'
)
?
$request
->
get
(
'sort'
)
:
'name'
,
];
$users
=
$this
->
userRepo
->
getAllUsersPaginatedAndSorted
(
20
,
$listDetails
);
$this
->
setPageTitle
(
'Users'
);
return
view
(
'users/index'
,
[
'users'
=>
$users
]);
$users
->
appends
(
$listDetails
);
return
view
(
'users/index'
,
[
'users'
=>
$users
,
'listDetails'
=>
$listDetails
]);
}
/**
...
...
app/Repos/UserRepo.php
View file @
be517de
...
...
@@ -52,6 +52,27 @@ class UserRepo
}
/**
* Get all the users with their permissions in a paginated format.
* @param int $count
* @param $sortData
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public
function
getAllUsersPaginatedAndSorted
(
$count
=
20
,
$sortData
)
{
$query
=
$this
->
user
->
with
(
'roles'
,
'avatar'
)
->
orderBy
(
$sortData
[
'sort'
],
$sortData
[
'order'
]);
if
(
$sortData
[
'search'
])
{
$term
=
'%'
.
$sortData
[
'search'
]
.
'%'
;
$query
->
where
(
function
(
$query
)
use
(
$term
)
{
$query
->
where
(
'name'
,
'like'
,
$term
)
->
orWhere
(
'email'
,
'like'
,
$term
);
});
}
return
$query
->
paginate
(
$count
);
}
/**
* Creates a new user and attaches a role to them.
* @param array $data
* @return User
...
...
app/helpers.php
View file @
be517de
...
...
@@ -59,3 +59,35 @@ function setting($key, $default = false)
$settingService
=
app
(
'BookStack\Services\SettingService'
);
return
$settingService
->
get
(
$key
,
$default
);
}
/**
* Generate a url with multiple parameters for sorting purposes.
* Works out the logic to set the correct sorting direction
* Discards empty parameters and allows overriding.
* @param $path
* @param array $data
* @param array $overrideData
* @return string
*/
function
sortUrl
(
$path
,
$data
,
$overrideData
=
[])
{
$queryStringSections
=
[];
$queryData
=
array_merge
(
$data
,
$overrideData
);
// Change sorting direction is already sorted on current attribute
if
(
isset
(
$overrideData
[
'sort'
])
&&
$overrideData
[
'sort'
]
===
$data
[
'sort'
])
{
$queryData
[
'order'
]
=
(
$data
[
'order'
]
===
'asc'
)
?
'desc'
:
'asc'
;
}
else
{
$queryData
[
'order'
]
=
'asc'
;
}
foreach
(
$queryData
as
$name
=>
$value
)
{
$trimmedVal
=
trim
(
$value
);
if
(
$trimmedVal
===
''
)
continue
;
$queryStringSections
[]
=
urlencode
(
$name
)
.
'='
.
urlencode
(
$trimmedVal
);
}
if
(
count
(
$queryStringSections
)
===
0
)
return
$path
;
return
$path
.
'?'
.
implode
(
'&'
,
$queryStringSections
);
}
\ No newline at end of file
...
...
resources/assets/sass/_lists.scss
View file @
be517de
...
...
@@ -266,6 +266,7 @@ ul.pagination {
display
:
inline-block
;
list-style
:
none
;
margin
:
$-m
0
;
padding-left
:
1px
;
li
{
float
:
left
;
}
...
...
@@ -300,6 +301,10 @@ ul.pagination {
}
}
.compact
ul
.pagination
{
margin
:
0
;
}
.entity-list
{
>
div
{
padding
:
$-m
0
;
...
...
resources/assets/sass/_text.scss
View file @
be517de
...
...
@@ -297,6 +297,12 @@ span.sep {
display
:
block
;
}
.action-header
{
h1
{
margin-top
:
$-m
;
}
}
/**
* Icons
*/
...
...
resources/views/settings/roles/index.blade.php
View file @
be517de
...
...
@@ -6,11 +6,15 @@
<div
class=
"container small"
>
<div
class=
"row action-header"
>
<div
class=
"col-sm-8"
>
<h1>
User Roles
</h1>
<p>
<a
href=
"/settings/roles/new"
class=
"text-pos"
><i
class=
"zmdi zmdi-lock-open"
></i>
Add new role
</a>
</p>
</div>
<div
class=
"col-sm-4"
>
<p></p>
<a
href=
"/settings/roles/new"
class=
"button float right pos"
><i
class=
"zmdi zmdi-lock-open"
></i>
Add new role
</a>
</div>
</div>
<table
class=
"table"
>
<tr>
...
...
resources/views/users/index.blade.php
View file @
be517de
...
...
@@ -7,17 +7,42 @@
<div
class=
"container small"
ng-non-bindable
>
<div
class=
"row action-header"
>
<div
class=
"col-sm-8"
>
<h1>
Users
</h1>
</div>
<div
class=
"col-sm-4"
>
<p></p>
@if(userCan('users-manage'))
<p>
<a
href=
"/settings/users/create"
class=
"text-pos"
><i
class=
"zmdi zmdi-account-add"
></i>
Add new user
</a>
</p>
<a
href=
"/settings/users/create"
class=
"pos button float right"
><i
class=
"zmdi zmdi-account-add"
></i>
Add new user
</a>
@endif
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-8"
>
<div
class=
"compact"
>
{!! $users->links() !!}
</div>
</div>
<div
class=
"col-sm-4"
>
<form
method=
"get"
class=
"float right"
action=
"/settings/users"
>
@foreach(collect($listDetails)->except('search') as $name => $val)
<input
type=
"hidden"
name=
"{{$name}}"
value=
"{{$val}}"
>
@endforeach
<input
type=
"text"
name=
"search"
placeholder=
"Search Users"
@
if
($
listDetails
['
search
'])
value=
"{{$listDetails['search']}}"
@
endif
>
</form>
</div>
</div>
<div
class=
"text-center"
>
</div>
<table
class=
"table"
>
<tr>
<th></th>
<th>
Name
</th>
<th>
Email
</th>
<th>
<a
href=
"{{ sortUrl('/settings/users', $listDetails, ['sort' => 'name']) }}"
>
Name
</a>
</th>
<th>
<a
href=
"{{ sortUrl('/settings/users', $listDetails, ['sort' => 'email']) }}"
>
Email
</a>
</th>
<th>
User Roles
</th>
</tr>
@foreach($users as $user)
...
...
@@ -42,11 +67,17 @@
@endif
</td>
<td>
<small>
{{ $user->roles->implode('display_name', ', ') }}
</small>
@foreach($user->roles as $index => $role)
<small><a
href=
"/settings/roles/{{$role->id}}"
>
{{$role->display_name}}
</a>
@if($index !== count($user->roles) -1),@endif
</small>
@endforeach
</td>
</tr>
@endforeach
</table>
<div>
{!! $users->links() !!}
</div>
</div>
@stop
...
...
Please
register
or
sign in
to post a comment