-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from canyongbs/feature/advapp-137-admissions-…
…state-management [ADVAPP-137]: Implement Table Filters for Status and State Management / Progression Buttons on Detail View for Online Admissions
- Loading branch information
Showing
8 changed files
with
579 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...cation/src/Filament/Resources/ApplicationResource/Actions/ApplicationAdmissionActions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* | ||
<COPYRIGHT> | ||
Copyright © 2022-2023, Canyon GBS LLC. All rights reserved. | ||
Advising App™ is licensed under the Elastic License 2.0. For more details, | ||
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE. | ||
Notice: | ||
- You may not provide the software to third parties as a hosted or managed | ||
service, where the service provides users with access to any substantial set of | ||
the features or functionality of the software. | ||
- You may not move, change, disable, or circumvent the license key functionality | ||
in the software, and you may not remove or obscure any functionality in the | ||
software that is protected by the license key. | ||
- You may not alter, remove, or obscure any licensing, copyright, or other notices | ||
of the licensor in the software. Any use of the licensor’s trademarks is subject | ||
to applicable law. | ||
- Canyon GBS LLC respects the intellectual property rights of others and expects the | ||
same in return. Canyon GBS™ and Advising App™ are registered trademarks of | ||
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks | ||
vigorously. | ||
- The software solution, including services, infrastructure, and code, is offered as a | ||
Software as a Service (SaaS) by Canyon GBS LLC. | ||
- Use of this software implies agreement to the license terms and conditions as stated | ||
in the Elastic License 2.0. | ||
For more information or inquiries please visit our website at | ||
https://www.canyongbs.com or contact us via email at [email protected]. | ||
</COPYRIGHT> | ||
*/ | ||
|
||
namespace AdvisingApp\Application\Filament\Resources\ApplicationResource\Actions; | ||
|
||
use Filament\Tables\Actions\Action; | ||
use AdvisingApp\Application\Models\Scopes\ClassifiedAs; | ||
use AdvisingApp\Application\Models\ApplicationSubmission; | ||
use AdvisingApp\Application\Models\ApplicationSubmissionState; | ||
use AdvisingApp\Application\Enums\ApplicationSubmissionStateClassification; | ||
|
||
// TODO We either need to introduce support for choosing the state that abides by the allowed classification transitions | ||
// Or we need to restrict creation of these states so that our `first()` logic to grab the desired state is always correct | ||
class ApplicationAdmissionActions | ||
{ | ||
public static function get(): array | ||
{ | ||
return [ | ||
Action::make('mark_as_reviewed') | ||
->label('Mark as Reviewed') | ||
->action( | ||
fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification') | ||
->transitionTo(ApplicationSubmissionState::tap(new ClassifiedAs(ApplicationSubmissionStateClassification::Review))->first(), ApplicationSubmissionStateClassification::Review) | ||
) | ||
->cancelParentActions() | ||
->visible(fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification')->getStateTransitions()->contains(ApplicationSubmissionStateClassification::Review->value)), | ||
Action::make('mark_as_complete') | ||
->label('Mark as Complete') | ||
->action( | ||
fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification') | ||
->transitionTo(ApplicationSubmissionState::tap(new ClassifiedAs(ApplicationSubmissionStateClassification::Complete))->first(), ApplicationSubmissionStateClassification::Complete) | ||
) | ||
->cancelParentActions() | ||
->visible(fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification')->getStateTransitions()->contains(ApplicationSubmissionStateClassification::Complete->value)), | ||
Action::make('mark_as_documents_required') | ||
->label('Mark as Documents Required') | ||
->action( | ||
fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification') | ||
->transitionTo(ApplicationSubmissionState::tap(new ClassifiedAs(ApplicationSubmissionStateClassification::DocumentsRequired))->first(), ApplicationSubmissionStateClassification::DocumentsRequired) | ||
) | ||
->cancelParentActions() | ||
->visible(fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification')->getStateTransitions()->contains(ApplicationSubmissionStateClassification::DocumentsRequired->value)), | ||
Action::make('mark_as_deny') | ||
->label('Mark as Deny') | ||
->action( | ||
fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification') | ||
->transitionTo(ApplicationSubmissionState::tap(new ClassifiedAs(ApplicationSubmissionStateClassification::Deny))->first(), ApplicationSubmissionStateClassification::Deny) | ||
) | ||
->cancelParentActions() | ||
->visible(fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification')->getStateTransitions()->contains(ApplicationSubmissionStateClassification::Deny->value)), | ||
Action::make('mark_as_admit') | ||
->label('Mark as Admit') | ||
->action( | ||
fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification') | ||
->transitionTo(ApplicationSubmissionState::tap(new ClassifiedAs(ApplicationSubmissionStateClassification::Admit))->first(), ApplicationSubmissionStateClassification::Admit) | ||
) | ||
->cancelParentActions() | ||
->visible(fn (ApplicationSubmission $record) => $record->getStateMachine(ApplicationSubmissionStateClassification::class, 'state.classification')->getStateTransitions()->contains(ApplicationSubmissionStateClassification::Admit->value)), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
app-modules/application/src/Models/Concerns/HasRelationBasedStateMachine.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
/* | ||
<COPYRIGHT> | ||
Copyright © 2022-2023, Canyon GBS LLC. All rights reserved. | ||
Advising App™ is licensed under the Elastic License 2.0. For more details, | ||
see https://github.com/canyongbs/advisingapp/blob/main/LICENSE. | ||
Notice: | ||
- You may not provide the software to third parties as a hosted or managed | ||
service, where the service provides users with access to any substantial set of | ||
the features or functionality of the software. | ||
- You may not move, change, disable, or circumvent the license key functionality | ||
in the software, and you may not remove or obscure any functionality in the | ||
software that is protected by the license key. | ||
- You may not alter, remove, or obscure any licensing, copyright, or other notices | ||
of the licensor in the software. Any use of the licensor’s trademarks is subject | ||
to applicable law. | ||
- Canyon GBS LLC respects the intellectual property rights of others and expects the | ||
same in return. Canyon GBS™ and Advising App™ are registered trademarks of | ||
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks | ||
vigorously. | ||
- The software solution, including services, infrastructure, and code, is offered as a | ||
Software as a Service (SaaS) by Canyon GBS LLC. | ||
- Use of this software implies agreement to the license terms and conditions as stated | ||
in the Elastic License 2.0. | ||
For more information or inquiries please visit our website at | ||
https://www.canyongbs.com or contact us via email at [email protected]. | ||
</COPYRIGHT> | ||
*/ | ||
|
||
namespace AdvisingApp\Application\Models\Concerns; | ||
|
||
use Bvtterfly\ModelStateMachine\StateMachine; | ||
use Bvtterfly\ModelStateMachine\HasStateMachine; | ||
use Bvtterfly\ModelStateMachine\Exceptions\FieldWithoutCast; | ||
use Bvtterfly\ModelStateMachine\Exceptions\CouldNotFindStateMachineField; | ||
use AdvisingApp\Application\Models\State\StateMachine as RelationBasedStateMachine; | ||
|
||
trait HasRelationBasedStateMachine | ||
{ | ||
use TargetsRelationships; | ||
use HasStateMachine { | ||
getStateMachine as parentGetStateMachine; | ||
} | ||
|
||
public function getStateMachine(string $enumClass, string $state): RelationBasedStateMachine|StateMachine | ||
{ | ||
// We assume that any state utilizing dot notation is targeting a relationship | ||
if ($this->targetingRelationship($state)) { | ||
$this->isStateMachineField($state); | ||
|
||
return new RelationBasedStateMachine($this, $enumClass, $state); | ||
} | ||
|
||
return $this->parentGetStateMachine($state); | ||
} | ||
|
||
private function setInitialState(): void | ||
{ | ||
foreach ($this->getStateMachineFields() as $field) { | ||
// We don't necessarily need to set the initial state if we are targeting a relationship | ||
if ($this->targetingRelationship($field) || $this->{$field} !== null) { | ||
continue; | ||
} | ||
|
||
$stateMachineConfig = $this->getStateMachineConfig($field); | ||
|
||
$initialValue = $stateMachineConfig->initial; | ||
|
||
if ($initialValue === null) { | ||
continue; | ||
} | ||
|
||
$this->{$field} = $initialValue; | ||
} | ||
} | ||
|
||
private function setInitialStates(): void | ||
{ | ||
foreach ($this->getStateMachineFields() as $field) { | ||
if ($this->targetingRelationship($field) || $this->{$field} !== null) { | ||
continue; | ||
} | ||
|
||
$stateMachineConfig = $this->getStateMachineConfig($field); | ||
|
||
$initialValue = $stateMachineConfig->initial; | ||
|
||
if ($initialValue === null) { | ||
continue; | ||
} | ||
|
||
$this->{$field} = $initialValue; | ||
} | ||
} | ||
|
||
private function isStateMachineField(string $field): bool | ||
{ | ||
if (! in_array($field, $this->getStateMachineFields())) { | ||
throw CouldNotFindStateMachineField::make($field); | ||
} | ||
|
||
if ($this->targetingRelationship($field)) { | ||
$relationPath = explode('.', $field); | ||
|
||
$stateField = array_pop($relationPath); | ||
|
||
$relatedModel = $this->accessNestedRelations($this, $relationPath); | ||
|
||
if (! $relatedModel->hasCast($stateField)) { | ||
throw FieldWithoutCast::make($stateField); | ||
} | ||
} else { | ||
if (! $this->hasCast($field)) { | ||
throw FieldWithoutCast::make($field); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.