🏡 index : ~doyle/zpan.git

author Jordan Doyle <jordan@doyle.wf> 2016-06-19 3:36:24.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-06-19 3:36:24.0 +01:00:00
commit
7faac22a20797677c772f0646612724121517564 [patch]
tree
a176f9ccf8a201cadd5a8b1c8473151a52f2e82c
parent
29eda078a67d1e6f8e76721ee7f57441b5f735d6
download
7faac22a20797677c772f0646612724121517564.tar.gz

Add events types modification for management



Diff

 app/Http/routes.php                                     |  5 ++++-
 app/Models/Event.php                                    |  2 +-
 resources/views/layouts/nav.blade.php                   |  5 +++++
 resources/views/management/event-types-form.blade.php   | 37 +++++++++++++++++++++++++++++++++++++
 resources/views/management/event-types.blade.php        | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 app/Http/Controllers/Management/EventTypeController.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 171 insertions(+), 2 deletions(-)

diff --git a/app/Http/routes.php b/app/Http/routes.php
index 467d109..8f9f0bd 100644
--- a/app/Http/routes.php
+++ a/app/Http/routes.php
@@ -92,7 +92,10 @@
        'namespace' => 'Management',
        'middleware' => 'is:management'
    ], function () {

        Route::get('event-type', ['as' => 'event-type', 'uses' => 'EventTypeController@index']);
        Route::get('event-type/add', ['as' => 'event-type.form', 'uses' => 'EventTypeController@form']);
        Route::put('event-type', ['as' => 'event-type.add', 'uses' => 'EventTypeController@add']);
        Route::delete('event-type/{id}', ['as' => 'event-type.delete', 'uses' => 'eventtypecontroller@delete']);
    });

    Route::group([
diff --git a/app/Models/Event.php b/app/Models/Event.php
index 31e1840..654a076 100644
--- a/app/Models/Event.php
+++ a/app/Models/Event.php
@@ -30,7 +30,7 @@
 * @method static Builder|Event whereYear($value)
 * @method static Builder|Event whereDay($value)
 * @method static Builder|Event whereHour($value)
 * @method static Builder|Event whereEventTypesId($value)
 * @method static Builder|Event whereEventTypeId($value)
 * @method static Builder|Event whereCreatedAt($value)
 * @method static Builder|Event whereUpdatedAt($value)
 * @method static Builder|Event whereDeletedAt($value)
diff --git a/resources/views/layouts/nav.blade.php b/resources/views/layouts/nav.blade.php
index 7b47ca4..878f9b8 100644
--- a/resources/views/layouts/nav.blade.php
+++ a/resources/views/layouts/nav.blade.php
@@ -79,6 +79,11 @@
            <div class="zpan-drawer-separator"></div>

            <span class="mdl-navigation__link" href>Management</span>

            <a class="mdl-navigation__link {{ is_route('dashboard::management::event-type') ? 'is-active' : '' }}"
               href="{{ route('dashboard::management::event-type') }}">
                <i class="material-icons">settings_applications</i> Event Types
            </a>
        @endif

        @if(auth()->user()->isAdmin())
diff --git a/resources/views/management/event-types-form.blade.php b/resources/views/management/event-types-form.blade.php
new file mode 100644
index 0000000..61cb1c9 100644
--- /dev/null
+++ a/resources/views/management/event-types-form.blade.php
@@ -1,0 +1,37 @@
@extends(Request::ajax() ? 'layouts.ajax-main' : 'layouts.main')

@section('title'){{ _('Add Request Line Ban') }} @endsection
@section('page-title')Management <i class="material-icons">chevron_right</i> Event Types <i
    class="material-icons">chevron_right</i> Add @endsection

@section('content')
    <div class="mdl-card mdl-cell mdl-cell--12-col mdl-shadow--2dp">
        <div class="mdl-card__supporting-text">
            <h4>{{ _('Add Event Type') }}</h4>

            <p>{{ _('Here you can new event types for the events staff to use.') }}</p>

            <form role="form" method="POST" action="{{ route('dashboard::management::event-type.add') }}">
                {{ csrf_field() }}
                {{ method_field('put') }}

                <fieldset
                    class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label {{ $errors->has('name') ? 'is-invalid' : '' }}">
                    <input type="text" class="mdl-textfield__input" id="name" name="name"
                           value="{{ old('name') }}">
                    <label class="mdl-textfield__label" for="name">Name</label>
                    @if ($errors->has('name'))
                        <span class="mdl-textfield__error">{{ $errors->first('name') }}</span>
                    @endif
                </fieldset>

                <fieldset class="form-group">
                    <button type="submit"
                            class="mdl-button mdl-button--raised mdl-button--colored mdl-js-button mdl-js-ripple-effect">
                        <i class="fa fa-btn fa-plus"></i> {{ _('Save') }}
                    </button>
                </fieldset>
            </form>
        </div>
    </div>
@endsection
diff --git a/resources/views/management/event-types.blade.php b/resources/views/management/event-types.blade.php
new file mode 100644
index 0000000..2a959e5 100644
--- /dev/null
+++ a/resources/views/management/event-types.blade.php
@@ -1,0 +1,50 @@
@extends(Request::ajax() ? 'layouts.ajax-main' : 'layouts.main')

@section('title'){{ _('Event Types') }} @endsection
@section('page-title')Management <i class="material-icons">chevron_right</i> Event Types @endsection

@section('content')
    <div class="table-responsive">
        {!! $types->links() !!}

        <table class="mdl-data-table mdl-js-data-table mdl-cell mdl-cell--12-col mdl-shadow--2dp">
            <thead>
            <tr>
                <th class="mdl-data-table__cell--non-numeric">#</th>
                <th class="mdl-data-table__cell--non-numeric">Name</th>
                <th class="mdl-data-table__cell--non-numeric">Amount of Events</th>
                <th class="mdl-data-table__cell--non-numeric">Added</th>
                <th></th>
            </tr>
            </thead>

            <tbody>
            @foreach($types as $type)
                <tr>
                    <td class="mdl-data-table__cell--non-numeric">{{ $type->id }}</td>
                    <td class="mdl-data-table__cell--non-numeric">{{ $type->name }}</td>
                    <td class="mdl-data-table__cell--non-numeric">{{ App\Models\Event::whereEventTypeId($type->id)->count() }}</td>
                    <td class="mdl-data-table__cell--non-numeric">{{ $type->created_at->diffForHumans() }}</td>
                    <td>
                        <form action="{{ route('dashboard::management::event-type.delete', $type->id) }}" method="post">
                            {{ csrf_field() }}
                            {{ method_field('delete') }}

                            <button class="mdl-button mdl-js-button mdl-button--icon mdl-button--colored">
                                <i class="material-icons delete">delete forever</i>
                            </button>
                        </form>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>

        {!! $types->links() !!}
    </div>

    <a class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored" id="add"
       href="{{ route('dashboard::management::event-type.form') }}">
        <i class="material-icons">add</i>
    </a>
@endsection
diff --git a/app/Http/Controllers/Management/EventTypeController.php b/app/Http/Controllers/Management/EventTypeController.php
new file mode 100644
index 0000000..a6a9f80 100644
--- /dev/null
+++ a/app/Http/Controllers/Management/EventTypeController.php
@@ -1,0 +1,74 @@
<?php
namespace App\Http\Controllers\Management;

use App\Http\Controllers\Controller;
use App\Models\EventType;
use Illuminate\Http\Request;

/**
 * Allow management to add and remove event types.
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class EventTypeController extends Controller
{
    /**
     * Show the manager a list of types.
     *
     * @return mixed
     */
    public function index()
    {
        return view('management.event-types', [
            'types' => EventType::orderBy('id', 'desc')->paginate(15)
        ]);
    }

    /**
     * Show the manager a form to add a new event type.
     *
     * @return mixed
     */
    public function form()
    {
        return view('management.event-types-form');
    }

    /**
     * Add an event type
     *
     * @param Request $request
     * @return mixed
     */
    public function add(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|min:3'
        ]);

        $ban = new EventType();
        $ban->name = $request->get('name');
        $ban->save();

        return redirect()->route('dashboard::management::event-type')->with('msg', [
            'type' => 'success',
            'msg' => _('Successfully added a new event type.')
        ]);
    }

    /**
     * Remove an event type.
     *
     * @param int $id id of the event type to delete.
     * @return mixed
     */
    public function delete(int $id)
    {
        EventType::findOrFail($id)->delete();

        return redirect()->back()->with('msg', [
            'type' => 'success',
            'msg' => _('Successfully removed the event type.')
        ]);
    }
}