From a4e415943a3a66e5c6179f3bce55aa2c9fee7636 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Fri, 8 May 2020 00:24:56 +0100 Subject: [PATCH] Add save & update functionality to positions Tooltips also added, as well as a general configuration file for Mojang Status URL. Relationships were also added between forms and Vacancies. Status verification for the dashboard was moved to a Service Provider, where it adds log entries when cache expires. Authentication controllers were also updated to reflect the new dashboard URL. --- app/Form.php | 5 + .../Auth/ConfirmPasswordController.php | 2 +- .../Auth/ResetPasswordController.php | 2 +- .../Auth/VerificationController.php | 2 +- app/Http/Controllers/DashboardController.php | 13 +- app/Http/Controllers/VacancyController.php | 76 ++++++- app/Http/Requests/VacancyRequest.php | 35 ++++ app/Providers/GuzzleServiceProvider.php | 28 --- app/Providers/MojangStatusProvider.php | 41 ++++ app/Vacancy.php | 39 +++- config/adminlte.php | 11 ++ config/app.php | 1 + config/general.php | 15 ++ ...20_04_29_022642_create_vacancies_table.php | 2 + ...0_05_07_021604_add_status_to_vacancies.php | 35 ++++ public/js/globaltooltip.js | 3 + .../administration/positions.blade.php | 187 ++++++++++++++++-- routes/web.php | 11 +- 18 files changed, 441 insertions(+), 67 deletions(-) create mode 100644 app/Http/Requests/VacancyRequest.php delete mode 100644 app/Providers/GuzzleServiceProvider.php create mode 100644 app/Providers/MojangStatusProvider.php create mode 100644 config/general.php create mode 100644 database/migrations/2020_05_07_021604_add_status_to_vacancies.php create mode 100644 public/js/globaltooltip.js diff --git a/app/Form.php b/app/Form.php index 02c1dd2..e234d94 100644 --- a/app/Form.php +++ b/app/Form.php @@ -13,4 +13,9 @@ class Form extends Model 'formStatus' ]; + + public function vacancy() + { + return $this->hasMany('App\Vacancy', 'vacancyFormID'); + } } diff --git a/app/Http/Controllers/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Auth/ConfirmPasswordController.php index 138c1f0..71a9592 100644 --- a/app/Http/Controllers/Auth/ConfirmPasswordController.php +++ b/app/Http/Controllers/Auth/ConfirmPasswordController.php @@ -26,7 +26,7 @@ class ConfirmPasswordController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/dashboard'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index b1726a3..6c0c13a 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -26,5 +26,5 @@ class ResetPasswordController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/dashboard'; } diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php index 5e749af..482a167 100644 --- a/app/Http/Controllers/Auth/VerificationController.php +++ b/app/Http/Controllers/Auth/VerificationController.php @@ -26,7 +26,7 @@ class VerificationController extends Controller * * @var string */ - protected $redirectTo = RouteServiceProvider::HOME; + protected $redirectTo = '/dashboard'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index e1df50e..3b32ec6 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -5,23 +5,14 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; class DashboardController extends Controller { public function index() { - // TODO: Switch status checking to provider, share with all views - - // Mojang status for informational purposes - if (!Cache::has('mojang_status')) - { - $mcstatus = Http::get('https://status.mojang.com/check'); - Cache::put('mojang_status', base64_encode($mcstatus->body()), now()->addMinutes(60)); - } - - return view('dashboard.dashboard') - ->with('mcstatus', json_decode(base64_decode(Cache::get('mojang_status')), true)); + return view('dashboard.dashboard'); } } diff --git a/app/Http/Controllers/VacancyController.php b/app/Http/Controllers/VacancyController.php index 81fc864..919af13 100644 --- a/app/Http/Controllers/VacancyController.php +++ b/app/Http/Controllers/VacancyController.php @@ -2,14 +2,86 @@ namespace App\Http\Controllers; +use App\Form; +use App\Http\Requests\VacancyRequest; +use App\Vacancy; use Illuminate\Http\Request; class VacancyController extends Controller { - public function index() { - return view('dashboard.administration.positions'); + return view('dashboard.administration.positions') + ->with([ + 'forms' => Form::all(), + 'vacancies' => Vacancy::all() + ]); + } + + public function store(VacancyRequest $request) + { + $form = Form::find($request->vacancyFormID); + + if (!is_null($form)) + { + Vacancy::create([ + + 'vacancyName' => $request->vacancyName, + 'vacancyDescription' => $request->vacancyDescription, + 'permissionGroupName' => $request->permissionGroup, + 'discordRoleID' => $request->discordRole, + 'vacancyFormID' => $request->vacancyFormID, + 'vacancyCount' => $request->vacancyCount + + ]); + + $request->session()->flash('success', 'Vacancy successfully opened. It will now show in the home page.'); + } + else + { + $request->session()->flash('error', 'You cannot create a vacancy without a valid form.'); + } + + return redirect()->back(); + + } + + public function updatePositionAvailability(Request $request, $status, $id) + { + $vacancy = Vacancy::find($id); + + if (!is_null($vacancy)) + { + $type = 'success'; + + switch ($status) + { + case 'open': + $vacancy->open(); + $message = "Position successfully opened!"; + + break; + + case 'close': + $vacancy->close(); + $message = "Position successfully closed!"; + + break; + + default: + $message = "Please do not tamper with the button's URLs. To report a bug, please contact an administrator."; + $type = 'error'; + + } + } + else + { + $message = "The position you're trying to update doesn't exist!"; + $type = "error"; + } + + $request->session()->flash($type, $message); + return redirect()->back(); } } diff --git a/app/Http/Requests/VacancyRequest.php b/app/Http/Requests/VacancyRequest.php new file mode 100644 index 0000000..02e22b3 --- /dev/null +++ b/app/Http/Requests/VacancyRequest.php @@ -0,0 +1,35 @@ + 'required|string', + 'vacancyDescription' => 'required|string', + 'permissionGroup' => 'required|string', + 'discordRole' => 'required|string', + 'vacancyCount' => 'required|integer', + 'vacancyFormID' => 'required|integer' + ]; + } +} diff --git a/app/Providers/GuzzleServiceProvider.php b/app/Providers/GuzzleServiceProvider.php deleted file mode 100644 index 6bc9b6d..0000000 --- a/app/Providers/GuzzleServiceProvider.php +++ /dev/null @@ -1,28 +0,0 @@ -body()), now()->addMinutes(60)); + } + + View::share('mcstatus', json_decode(base64_decode(Cache::get('mojang_status')), true)); + } +} diff --git a/app/Vacancy.php b/app/Vacancy.php index f89da83..464bcf9 100644 --- a/app/Vacancy.php +++ b/app/Vacancy.php @@ -3,8 +3,45 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; class Vacancy extends Model { - // + public $fillable = [ + + 'permissionGroupName', + 'vacancyName', + 'vacancyDescription', + 'discordRoleID', + 'vacancyFormID', + 'vacancyCount', + 'vacancyStatus' + + ]; + + public function forms() + { + return $this->belongsTo('App\Form'); + } + + public function open() + { + $this->update([ + 'vacancyStatus' => 'OPEN' + ]); + + Log::info("Vacancies: Vacancy " . $this->id . " (" . $this->vacancyName . ") opened by " . Auth::user()->name); + } + + public function close() + { + $this->update([ + 'vacancyStatus' => 'CLOSED' + ]); + + Log::warning("Vacancies: Vacancy " . $this->id . " (" . $this->vacancyName . ") closed by " . Auth::user()->name); + + } + } diff --git a/config/adminlte.php b/config/adminlte.php index 320b6ce..8c54c3f 100644 --- a/config/adminlte.php +++ b/config/adminlte.php @@ -446,6 +446,17 @@ return [ 'location' => 'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css' ] ] + ], + [ + 'name' => 'GlobalTooltip', + 'active' => 'true', + 'files' => [ + [ + 'type' => 'js', + 'asset' => false, + 'location' => '/js/globaltooltip.js' + ] + ] ] ], ]; diff --git a/config/app.php b/config/app.php index 8409e00..f096c29 100644 --- a/config/app.php +++ b/config/app.php @@ -174,6 +174,7 @@ return [ // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, + \App\Providers\MojangStatusProvider::class, ], diff --git a/config/general.php b/config/general.php new file mode 100644 index 0000000..3b6f109 --- /dev/null +++ b/config/general.php @@ -0,0 +1,15 @@ + + [ + + 'mojang' => [ + + 'statuscheck' => env('MOJANG_STATUS_URL') ?? 'https://status.mojang.com/check' + + ] + ] + +]; diff --git a/database/migrations/2020_04_29_022642_create_vacancies_table.php b/database/migrations/2020_04_29_022642_create_vacancies_table.php index 50480bc..788206a 100644 --- a/database/migrations/2020_04_29_022642_create_vacancies_table.php +++ b/database/migrations/2020_04_29_022642_create_vacancies_table.php @@ -22,6 +22,8 @@ class CreateVacanciesTable extends Migration $table->bigInteger('vacancyFormID')->unsigned(); $table->integer('vacancyCount')->default(3); $table->timestamps(); + + $table->foreign('vacancyFormID')->references('id')->on('forms'); }); } diff --git a/database/migrations/2020_05_07_021604_add_status_to_vacancies.php b/database/migrations/2020_05_07_021604_add_status_to_vacancies.php new file mode 100644 index 0000000..1d40c92 --- /dev/null +++ b/database/migrations/2020_05_07_021604_add_status_to_vacancies.php @@ -0,0 +1,35 @@ +enum('vacancyStatus', [ + 'OPEN', + 'CLOSED' + ])->after('vacancyCount'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('vacancies', function (Blueprint $table) { + $table->dropColumn('vacancyStatus'); + }); + } +} diff --git a/public/js/globaltooltip.js b/public/js/globaltooltip.js new file mode 100644 index 0000000..fc1f993 --- /dev/null +++ b/public/js/globaltooltip.js @@ -0,0 +1,3 @@ +$(document).ready(function() { + $('input[rel="txtTooltip"]').tooltip(); +}); diff --git a/resources/views/dashboard/administration/positions.blade.php b/resources/views/dashboard/administration/positions.blade.php index 87f0eb6..4284637 100644 --- a/resources/views/dashboard/administration/positions.blade.php +++ b/resources/views/dashboard/administration/positions.blade.php @@ -8,8 +8,114 @@ @stop +@section('js') + + @if (session()->has('success')) + + + + @elseif(session()->has('error')) + + @endif + + @if($errors->any()) + + @foreach ($errors->all() as $error) + + @endforeach + + @endif + +@stop + @section('content') + +
@@ -18,7 +124,7 @@
- +
@@ -40,40 +146,79 @@
- + @if(!$vacancies->isEmpty()) - +
+ + - - - + + + + + - + - + - - - - - - - - - + @foreach($vacancies as $vacancy) - + -
# Vacancy Name Vacancy DescriptionDate CreatedDate UpdatedTotal ApplicantsDiscord Role IDPerm. Group NameOpen SlotsStatusCreated On Actions
1HelperHelp manage the server2020-04-032020-05-0110 - -
+ {{$vacancy->id}} + {{$vacancy->vacancyName}} + {{$vacancy->vacancyDescription}} + {{$vacancy->discordRoleID}} + {{$vacancy->permissionGroupName}} + {{$vacancy->vacancyCount}} + @if($vacancy->vacancyStatus == 'OPEN') + OPEN + @else + CLOSED + @endif + {{$vacancy->created_at}} + + @if ($vacancy->vacancyStatus == 'OPEN') +
+ @csrf + @method('PATCH') + +
+ + @else + +
+ @csrf + @method('PATCH') + +
+ + @endif + + + + + @endforeach + + + + + + @else + +
+

Nothing to see here! Open some vacancies first. This will get applicants pouring in! (hopefully)

+
+ + @endif