🏡 index : ~doyle/zpan.git

author Jordan Doyle <jordan@doyle.wf> 2016-06-26 14:00:02.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-06-26 14:00:02.0 +01:00:00
commit
dcd5c8e71a8fc413c5a21a64229c72500b45df61 [patch]
tree
80afe844d273f2216cd6c0f0a297d7ed42ad3030
parent
cb1450e787d8a19d03f4b44083bc9c1d45ad549f
download
dcd5c8e71a8fc413c5a21a64229c72500b45df61.tar.gz

Users timezones, rainbow font, fix deleting event types, sort event type by name



Diff

 app/Http/routes.php                                                    |  2 +-
 app/Models/Timezone.php                                                | 40 ++++++++++++++++++++++++++++++++++++++++
 app/Models/User.php                                                    | 20 ++++++++++++++++++++
 database/migrations/2016_06_25_173046_create_users_timezones_table.php | 33 +++++++++++++++++++++++++++++++++
 resources/assets/sass/_misc.sass                                       |  6 ++++++
 app/Http/Controllers/DJ/TimetableController.php                        | 40 +++++++++++++++++++++++++++++++++++++++-
 app/Http/Controllers/Event/TimetableController.php                     | 12 +++++++++++-
 app/Http/Controllers/Management/EventTypeController.php                |  2 +-
 8 files changed, 147 insertions(+), 8 deletions(-)

diff --git a/app/Http/routes.php b/app/Http/routes.php
index 82dac25..5a6dcaf 100644
--- a/app/Http/routes.php
+++ a/app/Http/routes.php
@@ -95,7 +95,7 @@
        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::delete('event-type/{id}', ['as' => 'event-type.delete', 'uses' => 'EventTypeController@delete']);
    });

    Route::group([
diff --git a/app/Models/Timezone.php b/app/Models/Timezone.php
new file mode 100644
index 0000000..1e11f38 100644
--- /dev/null
+++ a/app/Models/Timezone.php
@@ -1,0 +1,40 @@
<?php
namespace App\Models;

use Carbon\Carbon;
use Eloquent;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Builder;

/**
 * Table to hold all "remember me" tokens for users.
 *
 * @author Jordan Doyle <jordan@doyle.wf>
 * @property integer $user_id id of the user this token belongs to
 * @property string $timezone timezone this user wants to show times as
 * @property Carbon $created_at when this timezone setting was created
 * @property Carbon $updated_at when this timezone setting was last updated
 * @property-read User $user user this token belongs to
 * @method static Builder|Token whereUserId($value)
 * @method static Builder|Token whereTimezone($value)
 * @method static Builder|Token whereCreatedAt($value)
 * @method static Builder|Token whereUpdatedAt($value)
 * @mixin Eloquent
 */
class Timezone extends Model
{
    public $table = 'users_timezones';
    protected $primaryKey = 'user_id';
    protected $fillable = ['remember_token', 'user_id'];

    /**
     * Get the user this timezone token belongs to.
     *
     * @return BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
diff --git a/app/Models/User.php b/app/Models/User.php
index 2a9d0d4..aaf6885 100644
--- a/app/Models/User.php
+++ a/app/Models/User.php
@@ -50,6 +50,26 @@
    }

    /**
     * Get this user's timezone.
     *
     * @return HasOne
     */
    public function timezone()
    {
        return $this->hasOne(Timezone::class);
    }

    /**
     * Get the user's timezone or the app's timezone if that is not set.
     *
     * @return string
     */
    public function getTimezone()
    {
        return $this->timezone ? $this->timezone->timezone : config('app.timezone');
    }

    /**
     * Get this user's custom fields.
     *
     * @return HasOne
diff --git a/database/migrations/2016_06_25_173046_create_users_timezones_table.php b/database/migrations/2016_06_25_173046_create_users_timezones_table.php
new file mode 100644
index 0000000..fceb6c8 100644
--- /dev/null
+++ a/database/migrations/2016_06_25_173046_create_users_timezones_table.php
@@ -1,0 +1,33 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTimezonesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users_timezones', function (Blueprint $table) {
            $table->integer('user_id')->unsigned();
            $table->string('timezone');
            $table->timestamps();

            $table->primary('user_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users_timezones');
    }
}
diff --git a/resources/assets/sass/_misc.sass b/resources/assets/sass/_misc.sass
index ad6c961..2c09faa 100644
--- a/resources/assets/sass/_misc.sass
+++ a/resources/assets/sass/_misc.sass
@@ -75,3 +75,9 @@
  position: fixed
  bottom: 2rem
  right: 2rem

.rainbow
  color: #9c9c9c
  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
diff --git a/app/Http/Controllers/DJ/TimetableController.php b/app/Http/Controllers/DJ/TimetableController.php
index 397c079..b4a10a8 100644
--- a/app/Http/Controllers/DJ/TimetableController.php
+++ a/app/Http/Controllers/DJ/TimetableController.php
@@ -37,10 +37,30 @@
            'hour' => 'required|integer|min:0|max:23'
        ]);

        $carbon = Carbon::now(auth()->user()->getTimezone())->setISODate(
            Carbon::now()->year,
            Carbon::now()->weekOfYear,
            $request->get('day') + 1
        )->setTime($request->get('hour'), 0);

        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 = Timetable::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)
            ->take(1)
            ->count();

@@ -62,8 +82,8 @@
        $slot = new Timetable;
        $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->dj = auth()->user()->userid;
        $slot->save();

@@ -155,7 +175,17 @@
        }

        foreach ($week as $slot) {
            $timetable[$slot->day][$slot->hour] = [
            $carbon = Carbon::now()->setISODate(
                Carbon::now()->year,
                Carbon::now()->weekOfYear,
                $slot->day + 1
            )->setTime($slot->hour, 0)->tz(auth()->check() ? auth()->user()->getTimezone() : 'Europe/London');

            if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
                continue;
            }

            $timetable[$carbon->dayOfWeek - 1][$carbon->hour] = [
                'id' => $slot->user->userid,
                'name' => $raw ? $slot->user->getDisplayName()->toHtml() : $slot->user->getDisplayName()
            ];
diff --git a/app/Http/Controllers/Event/TimetableController.php b/app/Http/Controllers/Event/TimetableController.php
index 8728fd9..bbd4281 100644
--- a/app/Http/Controllers/Event/TimetableController.php
+++ a/app/Http/Controllers/Event/TimetableController.php
@@ -239,7 +239,17 @@
        foreach ($week as $slot) {
            $type = $slot->type->name;

            $timetable[$slot->day][$slot->hour] = [
            $carbon = Carbon::now()->setISODate(
                Carbon::now()->year,
                Carbon::now()->weekOfYear,
                $slot->day + 1
            )->setTime($slot->hour, 0)->tz(auth()->check() ? auth()->user()->getTimezone() : 'Europe/London');

            if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
                continue;
            }

            $timetable[$carbon->dayOfWeek][$carbon->hour] = [
                'id' => $slot->user()->first()->userid,
                'name' => $raw ? $slot->user()->first()->getDisplayName()->toHtml() :
                    $slot->user()->first()->getDisplayName(),
diff --git a/app/Http/Controllers/Management/EventTypeController.php b/app/Http/Controllers/Management/EventTypeController.php
index a6a9f80..9775b94 100644
--- a/app/Http/Controllers/Management/EventTypeController.php
+++ a/app/Http/Controllers/Management/EventTypeController.php
@@ -20,7 +20,7 @@
    public function index()
    {
        return view('management.event-types', [
            'types' => EventType::orderBy('id', 'desc')->paginate(15)
            'types' => EventType::orderBy('name', 'desc')->paginate(15)
        ]);
    }