v0.9.13 - Added notifications in events, when an event you're signed up to gets canceled.

This commit is contained in:
frederikpyt 2020-08-14 07:36:42 +02:00
parent bd0d504ab8
commit 9e0f449bd3
8 changed files with 98 additions and 13 deletions

View File

@ -210,24 +210,24 @@ class EventController extends Controller
public function destroy(Request $request, $id)
{
if ($request->signup != null) { // If input signup is not empty, which has been set when you look at the individuel signup, then delete the user who have signed up for the event
$UserEvent = UserEvent::where('user_id', $request->signup)->where('event_id', $id);
$UserEvent = UserEvent::query()->where('user_id', "=", $request->signup)->where('event_id', "=", $id);
$UserEvent->delete();
return redirect()->route("events.signups", [ "event" => $id ]);
} else { // Else if you are deleting an event. Then delete all the sign ups AND the event
$UserEvents = UserEvent::where('event_id', $id);
$event = Event::find($id);
$userEvents = UserEvent::query()->where('event_id', "=", $id)->get();
$event = Event::query()->find($id);
foreach ($UserEvents as $userEvent) {
foreach ($userEvents as $userEvent) {
$notification = new Notification();
$notification->user_id = $userEvent->user_id;
$notification->message = $event->name . " - ";
$notification->save();
$userEvent->delete();
}
$UserEvents->delete();
$event->delete();
return redirect()->route("events.index");
@ -298,6 +298,17 @@ class EventController extends Controller
}
return $html;
}
public function deleteNotifications(Request $request){
if($request->ajax()){
foreach (Notification::query()->where("user_id", "=", $request->user_id)->get() as $notification) {
$notification->delete();
}
return "Done";
} else {
return "ERROR";
}
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
protected $fillable = [
'user_id', 'message'
];
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNotifications extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notifications', function (Blueprint $table) {
$table->id();
$table->foreignId("user_id")->constrained("users", "id");
$table->string("message");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notifications');
}
}

View File

@ -58,7 +58,8 @@ return[
"af" => "Af",
"programmedby" => "Programmeret af",
"error" => "Fejl",
"404" => "Denne side findes ikke."
"404" => "Denne side findes ikke.",
"canceled" => "Aflyst"

View File

@ -67,5 +67,6 @@ return[
"af" => "By",
"programmedby" => "Programmed by",
"error" => "Error",
"404" => "This page doesn't exist."
"404" => "This page doesn't exist.",
"canceled" => "Canceled"
];

View File

@ -34,6 +34,18 @@
<main>
<h1 class="text-center sde-blue mb-0" style="margin-bottom: 2rem">{{ __('msg.aktiviteter') }}</h1>
@if(count(\App\Notification::query()->where("user_id", "=", auth()->user()->id)->get()) > 0)
<div class="card" id="notifications">
<div class="container" style="margin-top: 8px;">
<button style="margin-left: calc(100% - 1rem - 8px); border-radius: 50%; background-color: #00788a; color: white; border: 1px solid grey;" onclick="deleteNotifications(document.getElementById('notifications'))">X</button>
@foreach(\App\Notification::query()->where("user_id", "=", auth()->user()->id)->get() as $notification)
<p>{{ $notification->message }}{{ __("msg.canceled") }}</p>
@endforeach
</div>
</div>
@endif
@if(!$events->isEmpty())
@foreach($events as $event)
<div class="card">
@ -115,6 +127,21 @@
});
}
}
function deleteNotifications(el) {
el.remove();
}
window.onload = function () {
setMain();
axios({
method: 'delete',
url: '{{route("notifications.delete")}}',
data: {
user_id: {{ auth()->user()->id }}
}
});
};
</script>
@endsection

View File

@ -67,6 +67,6 @@
@endif
@endforeach
</table>
<button onclick="window.history.back();" style="margin-top: auto; margin-bottom: 8px;" class="btn btn-sde-blue text-white">{{ __('msg.tilbage') }}</button>
<button onclick="document.location = document.referrer;" style="margin-top: auto; margin-bottom: 8px;" class="btn btn-sde-blue text-white">{{ __('msg.tilbage') }}</button>
</main>
@endsection

View File

@ -35,7 +35,7 @@ Route::get("/settings", "SettingsController@index")->name("settings.index");
Route::post("/events/signup", "UserEventController@createajax")->name("userevents.createajax");
Route::get("/about", "AboutController@index")->name("about.index");
Route::post("/events/cancelsignup", "UserEventController@createajaxcancel")->name("userevents.createajaxcancel");
Route::delete("/notifications/delete", "EventController@deleteNotifications")->name("notifications.delete");
//Search/Filter
Route::get("/contactsapi", "ContactController@search")->name("contacts.search");