Skip to content

Commit

Permalink
Merge pull request #393 from vu-sa/dev
Browse files Browse the repository at this point in the history
Small ViSAK enhancemenets
  • Loading branch information
justinaskav authored Feb 23, 2025
2 parents 11b6026 + fc5a94f commit cee4115
Show file tree
Hide file tree
Showing 30 changed files with 1,850 additions and 610 deletions.
13 changes: 0 additions & 13 deletions app/Actions/Schedulable/MeetingNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,9 @@

use App\Models\Meeting;
use App\Notifications\MeetingNotFinishedNotification;
use App\Notifications\MeetingSoonNotification;

class MeetingNotifier
{
public static function notifyDaysLeft(int $daysLeft)
{
// get all institution meetings that their date and carbon now is equal or less, but not into future to $daysLeft
$meetings = Meeting::with('institutions.users')->whereDate('start_time', '<=', now()->addDays($daysLeft))->whereDate('start_time', '>=', now())->get();

foreach ($meetings as $meeting) {
$meeting->users->each(function ($user) use ($meeting) {
$user->notify(new MeetingSoonNotification($meeting));
});
}
}

// Used for inform, that the meeting is not finished, i.e. the files were not uploaded
public static function notifyOnMeetingUnfinishedStatus()
{
Expand Down
127 changes: 121 additions & 6 deletions app/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use App\Actions\GetTenantsForUpserts;
use App\Http\Controllers\Controller;
use App\Models\Institution;
use App\Models\Meeting;
use App\Models\Page;
use App\Models\Pivots\AgendaItem;
use App\Models\Resource;
use App\Models\Tenant;
use App\Models\User;
Expand All @@ -16,6 +18,11 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Inertia\Inertia;
use Spatie\Activitylog\Models\Activity;

// HACK: there's so much hacking here...
// TODO: 1. Refactor, so the tenant selection and authorization is done in a middleware
// TODO: 2. Non-existing tenants should 404

class DashboardController extends Controller
{
Expand Down Expand Up @@ -230,15 +237,123 @@ public function sendFeedback(Request $request)
return redirect()->back()->with('success', 'Ačiū už atsiliepimą!');
}

protected function getInstitutionForWorkspace(Request $request)
public function atstovavimasSummary(Request $request, $date = null)
{
$institution = null;
$selectedTenant = request()->input('tenant_id');

$date = $date ? $date : now()->toDateString();

// Leave only tenants that are not 'pkp'
$tenants = collect(GetTenantsForUpserts::execute('institutions.update.padalinys', $this->authorizer))->filter(function ($tenant) {
return $tenant['type'] !== 'pkp';
})->values();

// Check if selected tenant is in the list of tenants
if ($selectedTenant) {
$selectedTenant = $tenants->firstWhere('id', $selectedTenant);
} else {
// Check if there's tenant with type 'pagrindinis'
$selectedTenant = $tenants->firstWhere('type', 'pagrindinis');
}

// check if institution has id
if (! is_null($request->input('institution_id'))) {
$institution = Institution::with('meetings.comments', 'meetings.tasks', 'meetings.files', 'users')->find($request->input('institution_id'));
// If not, select first tenant
if (! $selectedTenant) {
$selectedTenant = $tenants->first();
}

return $institution;
if (! $selectedTenant) {
$providedTenant = null;
$meetings = null;
// All tenants and all activities
} elseif ($this->authorizer->isAllScope && request()->input('tenant_id') === '0') {
$meetingsWithActivities = Meeting::query()
// NOTE: some dark magic doesn't allow to filter activities in this way. In certain cases,
// where there are no activity log that day for a meeting, it will exceed compute time of 30s.
// ->withWhereHas('activities', function ($query) use ($date) {
// $query->where('created_at', '>=', $date)->where('created_at', '<=', $date . ' 23:59:59');
// })
->with(['institutions', 'activities.causer'])->get();

$agendaItemsWithActivities = AgendaItem::query()->withWhereHas('activities', function ($query) use ($date) {
$query->with('causer')->where('created_at', '>=', $date)->where('created_at', '<=', $date.' 23:59:59');
})->with('meeting.institutions')->get();

// Organize loaded activities by meeting
$meetings = new Collection;

$meetings = $meetings->merge($meetingsWithActivities);

$agendaItemsWithActivities->each(function ($agendaItem) use (&$meetings) {
if ($meetings->contains($agendaItem->meeting)) {
if (! $meetings->firstWhere('id', $agendaItem->meeting->id)->changedAgendaItems) {
$meetings->firstWhere('id', $agendaItem->meeting->id)->changedAgendaItems = collect();
}
$meetings->firstWhere('id', $agendaItem->meeting->id)->changedAgendaItems->push($agendaItem);
} else {
$agendaItem->meeting->changedAgendaItems = collect([$agendaItem]);
$meetings->push($agendaItem->meeting);
}
});

$providedTenant = Tenant::query()->get();

$providedTenant = [
'id' => 0,
'shortname' => 'Visi padaliniai',
'institutions' => $providedTenant->map(function ($tenant) {
return $tenant->institutions;
})->flatten(1),
];

// Only one tenant meeting and agenda item activities
} else {
$meetingsWithActivities = Meeting::query()
->withWhereHas('institutions', function ($query) use ($selectedTenant) {
$query->where('tenant_id', $selectedTenant['id']);
})
// NOTE: some dark magic doesn't allow to filter activities in this way. In certain cases,
// where there are no activity log that day for a meeting, it will exceed compute time of 30s.
// ->withWhereHas('activities', function ($query) use ($date) {
// $query->where('created_at', '>=', $date)->where('created_at', '<=', $date . ' 23:59:59');
// })
->with('activities.causer')
->get();

$agendaItemsWithActivities = AgendaItem::query()->withWhereHas('meeting.institutions', function ($query) use ($selectedTenant) {
$query->where('tenant_id', $selectedTenant['id']);
})->withWhereHas('activities', function ($query) use ($date) {
$query->with('causer')->where('created_at', '>=', $date)->where('created_at', '<=', $date.' 23:59:59');
})->get();

// Organize loaded activities by meeting
$meetings = new Collection;

$meetings = $meetings->merge($meetingsWithActivities);

$agendaItemsWithActivities->each(function ($agendaItem) use ($meetings) {
if ($meetings->contains($agendaItem->meeting)) {
if (! $meetings->firstWhere('id', $agendaItem->meeting->id)->changedAgendaItems) {
$meetings->firstWhere('id', $agendaItem->meeting->id)->changedAgendaItems = collect();
}
$meetings->firstWhere('id', $agendaItem->meeting->id)->changedAgendaItems->push($agendaItem);
} else {
$agendaItem->meeting->changedAgendaItems = collect([$agendaItem]);
$meetings->push($agendaItem->meeting);
}
});

$providedTenant = Tenant::query()->where('id', $selectedTenant['id'])->first();
}

// $user = User::query()->where('id', Auth::id())->with('current_duties.institution.meetings.institutions:id,name')->first();

return Inertia::render('Admin/Dashboard/ShowAtstovavimasActivity', [
'meetings' => $meetings->toArray(),
'date' => $date,
'tenants' => $tenants->when($this->authorizer->isAllScope, function ($tenants) {
return $tenants->prepend(['id' => 0, 'shortname' => 'Visi padaliniai']);
}),
'providedTenant' => $providedTenant,
]);
}
}
11 changes: 11 additions & 0 deletions app/Http/Controllers/Admin/UserNotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Inertia\Inertia;

class UserNotificationsController extends Controller
{
public function index()
{
// get all notifications
$notifications = auth()->user()->notifications;

return Inertia::render('Admin/ShowNotifications', [
'notifications' => $notifications,
]);
}

public function markAsRead($id)
{
// mark notification as read
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Pivots/AgendaItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function matter()
return $this->belongsTo(Matter::class);
}

public function meeting()
public function meeting(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Meeting::class);
}
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function allModelsFromModelType()
return $this->model_type::select('id', 'name', 'institution_id')->with('tenants')->orderBy('name')->get();
} elseif (Str::contains($this->model_type, 'Doing')) {
return $this->model_type::select('id', 'title')->with('tenants')->orderBy('title')->get();
} elseif (Str::contains($this->model_type, 'Meeting')) {
return $this->model_type::select('id', 'title')->with('tenants')->orderBy('title')->get();
}
}
}
84 changes: 0 additions & 84 deletions app/Notifications/MeetingSoonNotification.php

This file was deleted.

Loading

0 comments on commit cee4115

Please sign in to comment.