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(-)
@@ -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',
@@ -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.'
]);
}
}
@@ -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
@@ -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>
@@ -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>
@@ -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
@@ -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()) {
@@ -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');
@@ -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]);
}