Skip to content

Commit

Permalink
Added group section (full crud)
Browse files Browse the repository at this point in the history
Updated API controller to correctly work for group attribute list.
  • Loading branch information
QuackenbushDev committed Aug 21, 2016
1 parent 817e248 commit 97a78d3
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 11 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function connectionCount(Request $request) {
* @return string
*/
public function attributes(Request $request) {
$username = $request->input('username', null);
$groupName = $request->input('groupName', null);
$username = $request->input('username', '');
$groupName = $request->input('groupName', '');
$type = $request->input('type');

if ($username !== null) {
if (!empty($username)) {
if ($type === 'check') {
$data = RadiusCheck::getUserAttributes($username)
->get()
Expand All @@ -85,7 +85,7 @@ public function attributes(Request $request) {
->get()
->toArray();
}
} elseif($groupName !== null) {
} elseif(!empty($groupName)) {
if ($type === 'check') {
$data = RadiusGroupCheck::where('groupname', $groupName)
->get()
Expand Down
130 changes: 126 additions & 4 deletions app/Http/Controllers/GroupController.php
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));
}
}
6 changes: 4 additions & 2 deletions public/js/widgets/attribute-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ angular.module('attributeApp', [])
$scope.type = type;
if (username.length == 0 && groupName.length == 0) {
console.error('Both username and group name are empty.');
return;
}

$.ajax({
url: '/api/attributes?type=' + type + '&username=' + username + "&groupName=" + groupName
}).done(function(data) {
console.log(data);
$scope.attributes = data;
if (data != 'missing_username_or_group_name') {
$scope.attributes = data;
}
});
};

Expand Down
63 changes: 63 additions & 0 deletions resources/views/pages/group/edit.blade.php
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
24 changes: 24 additions & 0 deletions resources/views/pages/group/index.blade.php
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
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
54 changes: 54 additions & 0 deletions resources/views/pages/group/show.blade.php
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
2 changes: 1 addition & 1 deletion resources/views/pages/nas/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@push('breadcrumbs')
<li><a href="{{ route('nas::index') }}"><i class="fa fa-server"></i> Nas</a></li>
<li><a href="{{ route('nas::show', $nas->id) }}">$nas->shortname</a></li>
<li><a href="{{ route('nas::show', $nas->id) }}">{{ $nas->shortname }}</a></li>
@endpush

@section('content')
Expand Down

0 comments on commit 97a78d3

Please sign in to comment.