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

Add a assign command vehicle behavior #980

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project does **not** adhere to [Semantic Versioning](https://semver.org

- Add behaviors button now opens towards the top.
- Simulated regions can now send patients to any hospital. The hospitals tab was removed.
- The assign leader behavior now prioritized vehicles instead of gfs. Custom command vehicles can be set in the frontend.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,64 @@
<h6>Aktuell zugewiesene Führungskraft</h6>
<h5>Aktuell zugewiesene Führungskraft</h5>

<p *ngIf="currentLeader; else noLeader">
{{ (currentLeader | async)?.personnelType | personnelName }}
<p *ngIf="currentLeader$ | async as currentLeader; else noLeader">
{{ currentLeader.personnelType | personnelName }}
<ng-container
*ngIf="vehicleOfCurrentLeader$ | async as vehicleOfCurrentLeader"
>aus Fahrzeug {{ vehicleOfCurrentLeader.name }}</ng-container
>
</p>

<ng-template #noLeader>
<p>Keine Führungskraft zugewiesen.</p>
</ng-template>

<h6>Mögliche Kommandofahrzeuge</h6>

<ul class="list-group" *ngIf="behaviorState$ | async as behaviorState">
<li
*ngFor="
let leadershipVehicleType of behaviorState.leadershipVehicleTypes
| keys
"
class="list-group-item d-flex flex-row justify-content-between align-items-center"
>
<span>{{ leadershipVehicleType }}</span>
<button
class="btn btn-outline-danger"
type="button"
(click)="removeVehicleType(leadershipVehicleType)"
>
<span class="bi-trash"></span>
</button>
</li>
</ul>

<div
ngbDropdown
*ngIf="vehicleTypesToAdd$ | async as vehicleTypesToAdd"
placement="bottom-start"
autoClose="outside"
class="d-inline-block overflow-visible text-center mb-3"
>
<button
ngbDropdownToggle
type="button"
class="btn btn-outline-primary"
[disabled]="vehicleTypesToAdd.length === 0"
>
<span class="bi-plus me-1"></span>
Weiteren Kommandofahrzeugtyp hinzufügen
</button>
<div *ngIf="vehicleTypesToAdd.length > 0" ngbDropdownMenu>
<button
*ngFor="let vehicleType of vehicleTypesToAdd"
ngbDropdownItem
class="dropdown-item"
type="button"
(click)="addVehicleType(vehicleType)"
>
<span class="bi-plus me-1"></span>
{{ vehicleType }}
</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import type { OnChanges } from '@angular/core';
import { Component, Input } from '@angular/core';
import { Store } from '@ngrx/store';
import type { Personnel } from 'digital-fuesim-manv-shared';
import { AssignLeaderBehaviorState } from 'digital-fuesim-manv-shared';
import { UUID } from 'digital-fuesim-manv-shared';
import type {
AssignLeaderBehaviorState,
Personnel,
Vehicle,
} from 'digital-fuesim-manv-shared';
import type { Observable } from 'rxjs';
import { combineLatest, map } from 'rxjs';
import { ExerciseService } from 'src/app/core/exercise.service';
import type { AppState } from 'src/app/state/app.state';
import { createSelectPersonnel } from 'src/app/state/application/selectors/exercise.selectors';
import {
createSelectBehaviorState,
selectPersonnel,
selectVehicleTemplates,
selectVehicles,
} from 'src/app/state/application/selectors/exercise.selectors';

@Component({
selector: 'app-simulated-region-overview-behavior-assign-leader',
Expand All @@ -18,18 +29,86 @@ import { createSelectPersonnel } from 'src/app/state/application/selectors/exerc
export class SimulatedRegionOverviewBehaviorAssignLeaderComponent
implements OnChanges
{
@Input()
assignLeaderBehaviorState!: AssignLeaderBehaviorState;
@Input() assignLeaderBehaviorId!: UUID;
@Input() simulatedRegionId!: UUID;

currentLeader?: Observable<Personnel>;
behaviorState$!: Observable<AssignLeaderBehaviorState>;

constructor(private readonly store: Store<AppState>) {}
currentLeader$!: Observable<Personnel | undefined>;

vehicleOfCurrentLeader$!: Observable<Vehicle | undefined>;

vehicleTypesToAdd$!: Observable<string[]>;

constructor(
private readonly store: Store<AppState>,
private readonly exerciseService: ExerciseService
) {}

ngOnChanges(): void {
if (this.assignLeaderBehaviorState.leaderId) {
this.currentLeader = this.store.select(
createSelectPersonnel(this.assignLeaderBehaviorState.leaderId)
);
}
this.behaviorState$ = this.store.select(
createSelectBehaviorState<AssignLeaderBehaviorState>(
this.simulatedRegionId,
this.assignLeaderBehaviorId
)
);

const personnel$ = this.store.select(selectPersonnel);

this.currentLeader$ = combineLatest([
this.behaviorState$,
personnel$,
]).pipe(
map(([behaviorState, personnel]) =>
behaviorState.leaderId
? personnel[behaviorState.leaderId]
: undefined
)
);

const vehicles$ = this.store.select(selectVehicles);

this.vehicleOfCurrentLeader$ = combineLatest([
this.currentLeader$,
vehicles$,
]).pipe(
map(([currentLeader, vehicles]) =>
currentLeader ? vehicles[currentLeader.vehicleId] : undefined
)
);

const vehicleTemplates$ = this.store.select(selectVehicleTemplates);

this.vehicleTypesToAdd$ = combineLatest([
this.behaviorState$,
vehicleTemplates$,
]).pipe(
map(([behaviorState, vehicleTemplates]) =>
vehicleTemplates
.map((vehicleTemplate) => vehicleTemplate.vehicleType)
.filter(
(vehicleType) =>
!behaviorState.leadershipVehicleTypes[vehicleType]
)
)
);
}

addVehicleType(vehicleType: string) {
this.exerciseService.proposeAction({
type: '[AssignLeaderBehavior] Add Leadership Vehicle Type',
simulatedRegionId: this.simulatedRegionId,
behaviorId: this.assignLeaderBehaviorId,
vehicleType,
});
}

removeVehicleType(vehicleType: string) {
this.exerciseService.proposeAction({
type: '[AssignLeaderBehavior] Remove Leadership Vehicle Type',
simulatedRegionId: this.simulatedRegionId,
behaviorId: this.assignLeaderBehaviorId,
vehicleType,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<div [ngSwitch]="selectedBehavior?.type">
<app-simulated-region-overview-behavior-assign-leader
*ngSwitchCase="'assignLeaderBehavior'"
[assignLeaderBehaviorState]="$any(selectedBehavior)"
[simulatedRegionId]="simulatedRegion.id"
[assignLeaderBehaviorId]="selectedBehavior!.id"
></app-simulated-region-overview-behavior-assign-leader
><app-simulated-region-overview-behavior-treat-patients
*ngSwitchCase="'treatPatientsBehavior'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
reserviert.
</span>
</ng-container>
<ng-container *ngSwitchCase="'isLeaderOccupation'">
<span>Das Fahrzeug führt diese Region</span>
</ng-container>
<ng-container *ngSwitchDefault>
<span class="text-muted">Die Tätigkeit ist unbekannt.</span>
</ng-container>
Expand Down
3 changes: 3 additions & 0 deletions shared/src/models/utils/occupations/exercise-occupation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LoadOccupation } from './load-occupation';
import { WaitForTransferOccupation } from './wait-for-transfer-occupation';
import { UnloadingOccupation } from './unloading-occupation';
import { PatientTransferOccupation } from './patient-transfer-occupation';
import { IsLeaderOccupation } from './is-leader-occupation';

export const occupations = {
IntermediateOccupation,
Expand All @@ -15,6 +16,7 @@ export const occupations = {
WaitForTransferOccupation,
UnloadingOccupation,
PatientTransferOccupation,
IsLeaderOccupation,
};

export type ExerciseOccupation = InstanceType<
Expand All @@ -34,6 +36,7 @@ export const occupationDictionary: ExerciseOccupationDictionary = {
waitForTransferOccupation: WaitForTransferOccupation,
unloadingOccupation: UnloadingOccupation,
patientTransferOccupation: PatientTransferOccupation,
isLeaderOccupation: IsLeaderOccupation,
};

export const occupationTypeOptions: Parameters<typeof Type> = [
Expand Down
1 change: 1 addition & 0 deletions shared/src/models/utils/occupations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './occupation-helpers';
export * from './patient-transfer-occupation';
export * from './unloading-occupation';
export * from './wait-for-transfer-occupation';
export * from './is-leader-occupation';
22 changes: 22 additions & 0 deletions shared/src/models/utils/occupations/is-leader-occupation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IsUUID } from 'class-validator';
import { UUID, uuidValidationOptions } from '../../../utils';
import { IsValue } from '../../../utils/validators';
import { getCreate } from '../get-create';
import type { Occupation } from './occupation';

export class IsLeaderOccupation implements Occupation {
@IsValue('isLeaderOccupation')
readonly type = 'isLeaderOccupation';

@IsUUID(4, uuidValidationOptions)
readonly simulatedRegionId: UUID;

/**
* @deprecated Use static `create` method instead.
*/
constructor(simulatedRegionId: UUID) {
this.simulatedRegionId = simulatedRegionId;
}

static readonly create = getCreate(this);
}
Loading