🏡 index : ~doyle/zpan.git

author Jordan Doyle <jordan@doyle.wf> 2016-06-26 15:40:44.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-06-26 15:40:44.0 +01:00:00
commit
a3883122f763da35b4c9f124ebf41ccf9b7ad3fa [patch]
tree
edc1694eec4a2b35a60dded617069c5eed33187f
parent
e9dbabcbab4a8bfa91147811bf8884ca5ba433ef
download
a3883122f763da35b4c9f124ebf41ccf9b7ad3fa.tar.gz

Finish timezone switcher



Diff

 app/Http/routes.php                                             |  8 ++++++++
 app/Http/Controllers/SettingsController.php                     | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 resources/assets/sass/_misc.sass                                |  9 +++++++++
 resources/views/events/book-slot.blade.php                      |  2 +-
 resources/views/layouts/nav.blade.php                           |  2 ++
 resources/views/settings/timezone.blade.php                     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 app/Http/Controllers/DJ/TimetableController.php                 |  2 +-
 app/Http/Controllers/Event/TimetableController.php              | 35 ++++++++++++++++++++++++++++++++++-
 app/Http/Controllers/Event/Senior/EventsTimetableController.php | 13 +++++++++++++
 9 files changed, 162 insertions(+), 8 deletions(-)

diff --git a/app/Http/routes.php b/app/Http/routes.php
index 5a6dcaf..c7d5024 100644
--- a/app/Http/routes.php
+++ a/app/Http/routes.php
@@ -75,6 +75,14 @@
    });

    Route::group([
        'as' => 'settings::',
        'prefix' => 'settings'
    ], function () {
        Route::get('timezone', ['as' => 'timezone', 'uses' => 'SettingsController@timezoneForm']);
        Route::put('timezone', ['as' => 'timezone.update', 'uses' => 'SettingsController@updateTimezone']);
    });

    Route::group([
        'as' => 'senior-events::',
        'prefix' => 'senior-events',
        'namespace' => 'Event\Senior',
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
new file mode 100644
index 0000000..78c5937 100644
--- /dev/null
+++ a/app/Http/Controllers/SettingsController.php
@@ -1,0 +1,51 @@
<?php
namespace App\Http\Controllers;

use App\Models\Timezone;
use App\Models\User;
use DateTimeZone;
use Illuminate\Http\Request;

/**
 * Allow the user to update their settings.
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class SettingsController extends Controller
{
    /**
     * Show the form for the user to update their timezone
     *
     * @return mixed
     */
    public function timezoneForm()
    {
        return view('settings.timezone', [
            'timezones' => DateTimeZone::listIdentifiers()
        ]);
    }

    /**
     * Update the user's timezone and return back to the form.
     *
     * @param Request $request
     * @return mixed
     */
    public function updateTimezone(Request $request)
    {
        $timezones = DateTimeZone::listIdentifiers();

        $this->validate($request, [
            'timezone' => 'required|in:' . implode(',', $timezones)
        ]);

        $timezone = Timezone::firstOrCreate(['user_id' => auth()->user()->userid]);
        $timezone->timezone = $request->get('timezone');
        $timezone->save();

        return redirect()->back()->with('msg', [
            'type' => 'success',
            'msg' => 'Successfully updated your timezone.'
        ]);
    }
}
diff --git a/resources/assets/sass/_misc.sass b/resources/assets/sass/_misc.sass
index 2c09faa..4c6320c 100644
--- a/resources/assets/sass/_misc.sass
+++ a/resources/assets/sass/_misc.sass
@@ -81,3 +81,12 @@
  background: linear-gradient(to right, #ea2fc7 0%, #7a2cc5 20%, #61b8c9 40%, #69c343 60%, #f2c61d 80%, #e9980f 100%)
  -webkit-background-clip: text
  -webkit-text-fill-color: transparent

.mdl-menu__outline.mdl-menu--bottom-left
  max-height: 400px

.mdl-menu.mdl-menu--bottom-left.mdl-js-menu
  max-height: 384px
  overflow-x: hidden
  clip: auto !important
  overflow-y: scroll
diff --git a/resources/views/events/book-slot.blade.php b/resources/views/events/book-slot.blade.php
index cf2489f..1c028dc 100644
--- a/resources/views/events/book-slot.blade.php
+++ a/resources/views/events/book-slot.blade.php
@@ -25,7 +25,7 @@
                    <label for="event-type" class="mdl-textfield__label">Type</label>

                    <ul for="event-type" class="mdl-menu mdl-menu--bottom-left mdl-js-menu">
                        @foreach(App\Models\EventType::all() as $type)
                        @foreach(App\Models\EventType::orderBy('name', 'asc')->get() as $type)
                            <li class="mdl-menu__item">{{ $type->name }}</li>
                        @endforeach
                    </ul>
diff --git a/resources/views/layouts/nav.blade.php b/resources/views/layouts/nav.blade.php
index 15e6abd..708235b 100644
--- a/resources/views/layouts/nav.blade.php
+++ a/resources/views/layouts/nav.blade.php
@@ -13,6 +13,8 @@

            <div class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect"
                for="user-menu-lower-right">
                <a class="mdl-menu__item" href="{{ route('dashboard::settings::timezone') }}">Change Timezone</a>
                <span class="mdl-menu__item" data-mdl-disabled>Change Language</span>
                <a class="mdl-menu__item" href="{{ route('auth::logout') }}">Logout</a>
            </div>
        </nav>
diff --git a/resources/views/settings/timezone.blade.php b/resources/views/settings/timezone.blade.php
new file mode 100644
index 0000000..5d05d31 100644
--- /dev/null
+++ a/resources/views/settings/timezone.blade.php
@@ -1,0 +1,48 @@
@extends(Request::ajax() ? 'layouts.ajax-main' : 'layouts.main')

@section('title'){{ _('Update Timezone') }} @endsection
@section('page-title')Settings <i class="material-icons">chevron_right</i> Update Timezone @endsection

@section('content')
    <div class="mdl-card mdl-cell mdl-cell--12-col mdl-shadow--2dp" style="overflow: visible">
        <div class="mdl-card__supporting-text" style="overflow: visible">
            <h4>{{ _('Update Timezone') }}</h4>

            <p>{{ _('Here you can update the timezone used throughout the panel, this will reflect on every time displayed on the panel.') }}</p>

            <form role="form" method="POST" action="{{ route('dashboard::settings::timezone.update') }}">
                {{ csrf_field() }}
                {{ method_field('put') }}

                <fieldset
                    class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label getmdl-select getmdl-select__fullwidth {{ $errors->has('timezone') ? 'is-invalid' : '' }}">
                    <input class="mdl-textfield__input" name="timezone" type="text" id="timezone"
                           value="{{ old('timezone') }}" required readonly>

                    <label for="timezone">
                        <i class="mdl-icon-toggle__label material-icons">keyboard_arrow_down</i>
                    </label>

                    <label for="timezone" class="mdl-textfield__label">Timezone</label>

                    <ul for="timezone" class="mdl-menu mdl-menu--bottom-left mdl-js-menu">
                        @foreach($timezones as $timezone)
                            <li class="mdl-menu__item">{{ $timezone }}</li>
                        @endforeach
                    </ul>

                    @if ($errors->has('timezone'))
                        <span class="mdl-textfield__error">{{ $errors->first('timezone') }}</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/app/Http/Controllers/DJ/TimetableController.php b/app/Http/Controllers/DJ/TimetableController.php
index f2d91e8..7040643 100644
--- a/app/Http/Controllers/DJ/TimetableController.php
+++ a/app/Http/Controllers/DJ/TimetableController.php
@@ -41,7 +41,7 @@
            Carbon::now()->year,
            Carbon::now()->weekOfYear,
            $request->get('day')
        )->setTime($request->get('hour'), 0);
        )->setTime($request->get('hour'), 0)->tz(config('app.timezone'));

        if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
            if ($request->ajax()) {
diff --git a/app/Http/Controllers/Event/TimetableController.php b/app/Http/Controllers/Event/TimetableController.php
index 528faa6..bbdabab 100644
--- a/app/Http/Controllers/Event/TimetableController.php
+++ a/app/Http/Controllers/Event/TimetableController.php
@@ -56,10 +56,33 @@
            'room_id' => 'required|integer|regex:/^[\d]{8,8}$/'
        ]);

        $carbon = Carbon::now(auth()->user()->getTimezone())->setISODate(
            Carbon::now()->year,
            Carbon::now()->weekOfYear,
            $request->get('day')
        )->setTime($request->get('hour'), 0)->tz(config('app.timezone'));

        if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
            if ($request->ajax()) {
                return [
                    'error' => true,
                    'msg' => _('This slot will be unbooked when the timetable is cleared on Monday at 00:00 GMT.')
                ];
            } else {
                return redirect()
                    ->back()
                    ->with('msg', [
                        'type' => 'danger',
                        'msg' => _('This slot will be unbooked when the timetable is cleared on Monday at 00:00 GMT.')
                    ])
                    ->with('tab', $request->get('day'));
            }
        }

        $slot = Event::where('week', Carbon::now()->weekOfYear)
            ->where('year', Carbon::now()->year)
            ->where('day', $request->get('day'))
            ->where('hour', $request->get('hour'))
            ->where('day', $carbon->dayOfWeek)
            ->where('hour', $carbon->hour)
            ->where('approved', true)
            ->take(1)
            ->count();
@@ -81,8 +104,8 @@

        $slot = Event::where('week', Carbon::now()->weekOfYear)
            ->where('year', Carbon::now()->year)
            ->where('day', $request->get('day'))
            ->where('hour', $request->get('hour'))
            ->where('day', $carbon->dayOfWeek)
            ->where('hour', $carbon->hour)
            ->where('user', auth()->user()->userid)
            ->where('approved', false)
            ->count();
@@ -108,8 +131,8 @@
        $slot = new Event;
        $slot->year = Carbon::now()->year;
        $slot->week = Carbon::now()->weekOfYear;
        $slot->day = $request->get('day');
        $slot->hour = $request->get('hour');
        $slot->day = $carbon->dayOfWeek;
        $slot->hour = $carbon->hour;
        $slot->event_type_id = EventType::whereName($request->get('event_type'))->firstOrFail()->id;
        $slot->user = auth()->user()->userid;
        $slot->room_id = $request->get('room_id');
diff --git a/app/Http/Controllers/Event/Senior/EventsTimetableController.php b/app/Http/Controllers/Event/Senior/EventsTimetableController.php
index 094cee8..788a816 100644
--- a/app/Http/Controllers/Event/Senior/EventsTimetableController.php
+++ a/app/Http/Controllers/Event/Senior/EventsTimetableController.php
@@ -20,6 +20,19 @@
            ->orderBy('id', 'desc')
            ->get();

        foreach ($unapproved as $event)
        {
            // translate to the user's set timezone
            $carbon = Carbon::now()->setISODate(
                Carbon::now()->year,
                Carbon::now()->weekOfYear,
                $event->day
            )->setTime($event->hour, 0)->tz(auth()->user()->getTimezone());

            $event->day = $carbon->dayOfWeek;
            $event->hour = $carbon->hour;
        }

        return view('events.senior.events-timetable', ['unapproved' => $unapproved]);
    }