-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated API controller to correctly work for group attribute list.
- Loading branch information
1 parent
817e248
commit 97a78d3
Showing
8 changed files
with
282 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,148 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
use App\RadiusCheck; | ||
use Illuminate\Http\Request; | ||
use App\RadiusAccount; | ||
use App\RadiusUserGroup; | ||
use App\RadiusGroupCheck; | ||
use App\RadiusGroupReply; | ||
|
||
class GroupController extends Controller { | ||
public function index(Request $request) { | ||
$groupList = RadiusUserGroup::selectRaw('groupname, count(groupname) as count') | ||
->groupBy('groupname') | ||
->paginate(); | ||
$filter = $request->input('filter', ''); | ||
|
||
return view()->make( | ||
'pages.group.index', | ||
[ | ||
'groupList' => $groupList, | ||
'filter' => $filter | ||
] | ||
); | ||
} | ||
|
||
public function show($id) { | ||
public function show(Request $request, $groupname) { | ||
$group = RadiusUserGroup::selectRaw('groupname, count(groupname) as count') | ||
->where('groupname', $groupname) | ||
->groupBy('groupname') | ||
->first(); | ||
$groupUserList = RadiusUserGroup::select(['username']) | ||
->where('groupname', $groupname) | ||
->get() | ||
->toArray(); | ||
$userList = RadiusCheck::getUserList() | ||
->whereIn('radcheck.username', $groupUserList) | ||
->paginate(); | ||
$check = RadiusGroupCheck::where('groupname', $groupname) | ||
->get() | ||
->toArray(); | ||
$reply = RadiusGroupReply::where('groupname', $groupname) | ||
->get() | ||
->toArray(); | ||
|
||
return view()->make( | ||
'pages.group.show', | ||
[ | ||
'group' => $group, | ||
'check' => $check, | ||
'reply' => $reply, | ||
'userList' => $userList, | ||
] | ||
); | ||
} | ||
|
||
public function edit($id) { | ||
public function edit(Request $request, $groupname) { | ||
$group = RadiusUserGroup::selectRaw('groupname, count(groupname) as count') | ||
->where('groupname', $groupname) | ||
->groupBy('groupname') | ||
->first(); | ||
|
||
return view()->make( | ||
'pages.group.edit', | ||
[ | ||
'group' => $group, | ||
] | ||
); | ||
} | ||
|
||
public function create() { | ||
$group = new RadiusUserGroup(); | ||
|
||
return view()->make( | ||
'pages.group.edit', | ||
[ | ||
'new' => true, | ||
'group' => $group, | ||
] | ||
); | ||
} | ||
|
||
public function save(Request $request) { | ||
$groupName = $request->input('groupName', ''); | ||
|
||
$group = new RadiusUserGroup(); | ||
$group->groupname = $request->input('groupName'); | ||
$group->username = $request->input('username'); | ||
$group->save(); | ||
|
||
$attributes = $request->input('attributes', []); | ||
foreach(['check', 'reply'] as $type) { | ||
if (array_key_exists($type, $attributes)) { | ||
foreach($attributes[$type] as $attribute => $values) { | ||
$attributeID = $values['id']; | ||
if ($attributeID === '0') { | ||
$record = ($type === 'check') ? new RadiusGroupCheck() : new RadiusGroupReply(); | ||
$record->groupname = $group->groupname; | ||
} else { | ||
$record = ($type === 'check') ? RadiusGroupCheck::find($attributeID) : RadiusGroupReply::find($attributeID); | ||
} | ||
|
||
$record->attribute = $attribute; | ||
$record->op = $values['op']; | ||
$record->value = $values['value']; | ||
$record->save(); | ||
} | ||
} | ||
} | ||
|
||
return redirect(route('group::show', $group->groupname)); | ||
} | ||
|
||
public function store(Request $request, $id = null) { | ||
public function store(Request $request, $groupname = null) { | ||
$attributes = $request->input('attributes', []); | ||
$deletedAttributes = $request->input('deleted', []); | ||
foreach(['check', 'reply'] as $type) { | ||
if (array_key_exists($type, $deletedAttributes)) { | ||
foreach ($deletedAttributes[$type] as $attributeID) { | ||
if ($type === 'check') { | ||
RadiusGroupCheck::where('id', $attributeID) | ||
->delete(); | ||
} else { | ||
RadiusGroupReply::where('id', $attributeID) | ||
->delete(); | ||
} | ||
} | ||
} | ||
|
||
if (array_key_exists($type, $attributes)) { | ||
foreach($attributes[$type] as $attribute => $values) { | ||
$attributeID = $values['id']; | ||
if ($attributeID === '0') { | ||
$record = ($type === 'check') ? new RadiusGroupCheck() : new RadiusGroupReply(); | ||
$record->groupname = $groupname; | ||
} else { | ||
$record = ($type === 'check') ? RadiusGroupCheck::find($attributeID) : RadiusGroupReply::find($attributeID); | ||
} | ||
|
||
$record->attribute = $attribute; | ||
$record->op = $values['op']; | ||
$record->value = $values['value']; | ||
$record->save(); | ||
} | ||
} | ||
} | ||
|
||
return redirect(route('group::show', $groupname)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@extends("master") | ||
|
||
@section('pageTitle', $group->groupname) | ||
|
||
@push('breadcrumbs') | ||
<li><a href="{{ route('group::index') }}"><i class="fa fa-groups"></i> Group</a></li> | ||
<li>Edit</li> | ||
<li><a href="{{ route('group::show', $group->groupname) }}">{{ $group->groupname }}</a></li> | ||
@endpush | ||
|
||
@section('content') | ||
@if(isset($new) && $new) | ||
{!! BootForm::open()->action(route('group::save')) !!} | ||
{!! BootForm::text('Group name', 'groupName')->value($group->groupname) !!} | ||
{!! BootForm::text('Assigned User', 'username') !!} | ||
@else | ||
{!! BootForm::open()->action(route('group::update', $group->groupname)) !!} | ||
{!! BootForm::text('Group name', 'groupName')->value($group->groupname)->disabled() !!} | ||
<input type="hidden" name="_method" value="PUT"> | ||
@endif | ||
|
||
<div class="box"> | ||
<div class="box-header"> | ||
<h4>Group Attributes</h4> | ||
</div> | ||
|
||
<div class="box-body" ng-app="attributeApp"> | ||
@include( | ||
'widgets.attribute-editor', | ||
[ | ||
'title' => 'Check', | ||
'type' => 'check', | ||
'username' => '', | ||
'groupName' => $group->groupname | ||
] | ||
) | ||
|
||
@include( | ||
'widgets.attribute-editor', | ||
[ | ||
'title' => 'Reply', | ||
'type' => 'reply', | ||
'username' => '', | ||
'groupName' => $group->groupname | ||
] | ||
) | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-md-12 text-right"> | ||
<a class="btn btn-lg btn-danger" href="{{ route('group::show', $group->groupname) }}">Cancel</a> | ||
{!! BootForm::submit('Submit')->addClass('btn-primary btn-lg') !!} | ||
</div> | ||
</div> | ||
|
||
{!! BootForm::close() !!} | ||
@endsection | ||
|
||
@push('scripts') | ||
<script src="{{ asset('/js/angular.min.js') }}"></script> | ||
<script src="{{ asset('/js/widgets/attribute-editor.js') }}"></script> | ||
@endpush |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@extends("master") | ||
|
||
@section('pageTitle', 'Group List') | ||
@section('pageDescription', '') | ||
@push('breadcrumbs') | ||
<li><a href="{{ route('nas::index') }}"><i class="fa fa-groups"></i> Group</a></li> | ||
@endpush | ||
|
||
@section("content") | ||
@include( | ||
'partials.table.crud-list', | ||
[ | ||
'title' => '', | ||
'createLink' => route('group::create'), | ||
'createLinkName' => 'New Group', | ||
'filterPlaceHolder' => 'Group Name', | ||
'filterAction' => route('group::index'), | ||
'filterValue' => $filter, | ||
'headers' => ['Group Name', 'User Count'], | ||
'dataSet' => $groupList, | ||
'dataPartial' => 'pages.group.partials.index-table-data', | ||
] | ||
) | ||
@endsection |
6 changes: 6 additions & 0 deletions
6
resources/views/pages/group/partials/index-table-data.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@foreach($dataSet as $data) | ||
<tr> | ||
<td><a href="{{ route('group::show', $data->groupname) }}">{{ $data->groupname }}</a></td> | ||
<td><a href="{{ route('group::show', $data->groupname) }}">{{ $data->count }}</a></td> | ||
</tr> | ||
@endforeach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@extends("master") | ||
|
||
@section('pageTitle', $group->groupname) | ||
|
||
@push('breadcrumbs') | ||
<li><a href="{{ route('group::index') }}"><i class="fa fa-groups"></i> Group</a></li> | ||
<li><a href="{{ route('group::show', $group->groupname) }}">{{ $group->groupname }}</a></li> | ||
@endpush | ||
|
||
@section('content') | ||
<div class="box"> | ||
<div class="box-header"> | ||
<h3>Group Information <a href="{{ route("group::edit", $group->groupname) }}">(edit)</a></h3> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
@include( | ||
'widgets.table', | ||
[ | ||
'title' => 'Group Check', | ||
'headers' => ['ID', 'GroupName', 'Attribute', 'OP', 'Value'], | ||
'dataSet' => $check, | ||
'colWidth' => 6 | ||
] | ||
) | ||
|
||
@include( | ||
'widgets.table', | ||
[ | ||
'title' => 'Group Reply', | ||
'headers' => ['ID', 'GroupName', 'Attribute', 'OP', 'Value'], | ||
'dataSet' => $reply, | ||
'colWidth' => 6 | ||
] | ||
) | ||
</div> | ||
|
||
@include( | ||
'partials.table.crud-list', | ||
[ | ||
'title' => 'Group User List', | ||
'createLink' => route('user::create'), | ||
'createLinkName' => '', | ||
'disableFilter' => true, | ||
'filterPlaceHolder' => '', | ||
'filterAction' => '', | ||
'filterValue' => '', | ||
'headers' => ['ID', 'Username', 'Password', 'Status', 'Primary Group'], | ||
'dataSet' => $userList, | ||
'dataPartial' => 'pages.user.partials.index-table-data', | ||
] | ||
) | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters