Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Subscription list filtering | Subscription on Student List View | Auto Subscribe arch on case #54

Merged
merged 17 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app-modules/assist-data-model/src/AssistDataModelPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ public function register(Panel $panel): void
);
}

public function boot(Panel $panel): void
{
}
public function boot(Panel $panel): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Assist\AssistDataModel\Filament\Resources;

use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Filament\Resources\Resource;
use Assist\AssistDataModel\Models\Student;
use Assist\AssistDataModel\Filament\Resources\StudentResource\Pages;
Expand All @@ -25,31 +23,6 @@ public static function form(Form $form): Form
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('full')
->label('Name')
->searchable()
->sortable(),
])
->filters([
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}

public static function getRelations(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,66 @@

namespace Assist\AssistDataModel\Filament\Resources\StudentResource\Pages;

use Filament\Actions;
use Filament\Tables\Table;
use Filament\Actions\CreateAction;
use Filament\Tables\Actions\Action;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Actions\BulkAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;
use Assist\AssistDataModel\Models\Student;
use Filament\Tables\Actions\BulkActionGroup;
use Illuminate\Database\Eloquent\Collection;
use Filament\Tables\Actions\DeleteBulkAction;
use Assist\Notifications\Actions\SubscriptionToggle;
use Assist\AssistDataModel\Filament\Resources\StudentResource;
use Filament\Tables\Actions\CreateAction as TableCreateAction;

class ListStudents extends ListRecords
{
protected static string $resource = StudentResource::class;

public function table(Table $table): Table
{
return parent::table($table)
->columns([
TextColumn::make('full')
->label('Name')
->searchable()
->sortable(),
])
->filters([
Filter::make('subscribed')
->query(fn (Builder $query): Builder => $query->whereRelation('subscriptions.user', 'id', auth()->id())),
])
->actions([
ViewAction::make(),
Action::make('subscribe')
->label(fn (Student $record) => $record->subscriptions()->whereHas('user', fn (Builder $query) => $query->where('user_id', auth()->id()))->exists() ? 'Unsubscribe' : 'Subscribe')
->icon(fn (Student $record) => $record->subscriptions()->whereHas('user', fn (Builder $query) => $query->where('user_id', auth()->id()))->exists() ? 'heroicon-s-bell-slash' : 'heroicon-s-bell')
->action(fn (Student $record) => resolve(SubscriptionToggle::class)->handle(auth()->user(), $record)),
EditAction::make(),
])
->bulkActions([
BulkActionGroup::make([
BulkAction::make('toggle_subscription')
->icon('heroicon-s-bell')
->action(fn (Collection $records) => $records->each(fn (Student $record) => resolve(SubscriptionToggle::class)->handle(auth()->user(), $record))),
DeleteBulkAction::make(),
]),
])
->emptyStateActions([
TableCreateAction::make(),
]);
}

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
CreateAction::make(),
];
}
}
5 changes: 4 additions & 1 deletion app-modules/assist-data-model/src/Models/Student.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Database\Eloquent\Collection;
use Assist\Notifications\Models\Subscription;
use Illuminate\Notifications\DatabaseNotification;
use Assist\Engagement\Models\EngagementFileEntities;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Assist\Notifications\Models\Contracts\Subscribable;
Expand Down Expand Up @@ -90,7 +91,9 @@ public function engagementFiles(): MorphToMany
foreignPivotKey: 'entity_id',
relatedPivotKey: 'engagement_file_id',
relation: 'engagementFiles',
);
)
->using(EngagementFileEntities::class)
->withTimestamps();
}

public function subscriptions(): MorphMany
Expand Down
4 changes: 1 addition & 3 deletions app-modules/audit/src/AuditPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ public function register(Panel $panel): void
);
}

public function boot(Panel $panel): void
{
}
public function boot(Panel $panel): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ class RoleAttachedToRoleGroup
*/
public function __construct(
public RoleGroupRolePivot $pivot
) {
}
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ class RoleRemovedFromRoleGroup
*/
public function __construct(
public RoleGroupRolePivot $pivot
) {
}
) {}
}
3 changes: 1 addition & 2 deletions app-modules/authorization/src/Events/RoleRemovedFromUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ class RoleRemovedFromUser
public function __construct(
public Role $role,
public User $user
) {
}
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ class UserAttachedToRoleGroup
*/
public function __construct(
public RoleGroupUserPivot $pivot
) {
}
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ class UserRemovedFromRoleGroup
*/
public function __construct(
public RoleGroupUserPivot $pivot
) {
}
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class SocialiteLogoutResponse extends LogoutResponse
{
public function __construct(
public SocialiteProvider $provider
) {
}
) {}

public function toResponse($request): RedirectResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

// TODO I am leaving this trait here as a placeholder for something that will be responsible for creating new permissions
// For specific instances of a model. For instance, when a user record is created, we'll need to create the permissions for that record (user.1.view, user.1.edit, etc.)
trait ImplementsPermissionHandling
{
}
trait ImplementsPermissionHandling {}
4 changes: 1 addition & 3 deletions app-modules/case/src/CasePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ public function register(Panel $panel): void
);
}

public function boot(Panel $panel): void
{
}
public function boot(Panel $panel): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Assist\Case\Filament\Resources\CaseItemResource\RelationManagers;

use Filament\Forms;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use Assist\Case\Models\CaseUpdate;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\Textarea;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Assist\Case\Enums\CaseUpdateDirection;
Expand All @@ -24,9 +26,20 @@ public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('id')
Textarea::make('update')
->label('Update')
->rows(3)
->columnSpan('full')
->required()
->string(),
Select::make('direction')
->options(collect(CaseUpdateDirection::cases())->mapWithKeys(fn (CaseUpdateDirection $direction) => [$direction->value => $direction->name]))
->label('Direction')
->required()
->maxLength(255),
->enum(CaseUpdateDirection::class),
Toggle::make('internal')
->label('Internal')
->rule(['boolean']),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static function form(Form $form): Form
return $form
->schema([
Select::make('case_id')
->relationship('case', 'casenumber')
->searchable()
->relationship('case', 'id')
->preload()
->label('Case')
->translateLabel()
->required()
Expand Down
25 changes: 17 additions & 8 deletions app-modules/case/src/Models/CaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
use DateTimeInterface;
use App\Models\BaseModel;
use App\Models\Institution;
use Assist\Audit\Models\Audit;
use Illuminate\Support\Carbon;
use Kirschbaum\PowerJoins\PowerJoins;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Assist\Case\Database\Factories\CaseItemFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Assist\Notifications\Models\Contracts\Subscribable;
use Assist\Audit\Models\Concerns\Auditable as AuditableTrait;
use Assist\Notifications\Models\Contracts\CanTriggerAutoSubscription;

/**
* Assist\Case\Models\CaseItem
Expand All @@ -39,18 +43,18 @@
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property-read User|null $assignedTo
* @property-read Collection<int, \Assist\Audit\Models\Audit> $audits
* @property-read Collection<int, Audit> $audits
* @property-read int|null $audits_count
* @property-read Collection<int, \Assist\Case\Models\CaseUpdate> $caseUpdates
* @property-read Collection<int, CaseUpdate> $caseUpdates
* @property-read int|null $case_updates_count
* @property-read User|null $createdBy
* @property-read Institution|null $institution
* @property-read \Assist\Case\Models\CaseItemPriority|null $priority
* @property-read Model|\Eloquent $respondent
* @property-read \Assist\Case\Models\CaseItemStatus|null $status
* @property-read \Assist\Case\Models\CaseItemType|null $type
* @property-read CaseItemPriority|null $priority
* @property-read Model|Eloquent $respondent
* @property-read CaseItemStatus|null $status
* @property-read CaseItemType|null $type
*
* @method static \Assist\Case\Database\Factories\CaseItemFactory factory($count = null, $state = [])
* @method static CaseItemFactory factory($count = null, $state = [])
* @method static Builder|CaseItem newModelQuery()
* @method static Builder|CaseItem newQuery()
* @method static Builder|CaseItem onlyTrashed()
Expand All @@ -75,7 +79,7 @@
*
* @mixin Eloquent
*/
class CaseItem extends BaseModel implements Auditable
class CaseItem extends BaseModel implements Auditable, CanTriggerAutoSubscription
{
use SoftDeletes;
use PowerJoins;
Expand All @@ -96,6 +100,11 @@ class CaseItem extends BaseModel implements Auditable
'created_by_id',
];

public function getSubscribable(): ?Subscribable
{
return $this->respondent instanceof Subscribable ? $this->respondent : null;
}

public function respondent(): MorphTo
{
return $this->morphTo(
Expand Down
20 changes: 17 additions & 3 deletions app-modules/case/src/Models/CaseUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
use App\Models\BaseModel;
use Assist\Audit\Models\Audit;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Database\Eloquent\Builder;
use Assist\Case\Enums\CaseUpdateDirection;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Assist\Case\Database\Factories\CaseUpdateFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Assist\Notifications\Models\Contracts\Subscribable;
use Assist\Audit\Models\Concerns\Auditable as AuditableTrait;
use Assist\Notifications\Models\Contracts\CanTriggerAutoSubscription;

/**
* Assist\Case\Models\CaseUpdate
Expand All @@ -29,9 +33,9 @@
* @property Carbon|null $deleted_at
* @property-read Collection<int, Audit> $audits
* @property-read int|null $audits_count
* @property-read \Assist\Case\Models\CaseItem|null $case
* @property-read CaseItem|null $case
*
* @method static \Assist\Case\Database\Factories\CaseUpdateFactory factory($count = null, $state = [])
* @method static CaseUpdateFactory factory($count = null, $state = [])
* @method static Builder|CaseUpdate newModelQuery()
* @method static Builder|CaseUpdate newQuery()
* @method static Builder|CaseUpdate onlyTrashed()
Expand All @@ -49,7 +53,7 @@
*
* @mixin Eloquent
*/
class CaseUpdate extends BaseModel implements Auditable
class CaseUpdate extends BaseModel implements Auditable, CanTriggerAutoSubscription
{
use SoftDeletes;
use HasUuids;
Expand All @@ -72,6 +76,16 @@ public function case(): BelongsTo
return $this->belongsTo(CaseItem::class);
}

public function getSubscribable(): ?Subscribable
{
/** @var Subscribable|Model $respondent */
$respondent = $this->case->respondent;

return $respondent instanceof Subscribable
? $respondent
: null;
}

protected function serializeDate(DateTimeInterface $date): string
{
return $date->format(config('project.datetime_format') ?? 'Y-m-d H:i:s');
Expand Down
Loading