Skip to content

Commit

Permalink
feat: add unconnected printers warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Dafnik committed Aug 12, 2024
1 parent 9b0cd9e commit 8ed08be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
32 changes: 27 additions & 5 deletions src/app/home/start/start.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,36 @@ <h5 class="card-title">{{ 'HOME_START_SETUP' | transloco }}</h5>
</div>
</div>

<div class="card p-2">
<div class="card p-2 col-12 col-sm-7 col-md-8">
<div class="card-body">
<h5 class="card-title">{{ 'ABOUT_APP_DISCOVER' | transloco }}</h5>
<app-download-btn-list />
</div>
</div>

@if (myUser()?.isAdmin) {
<div class="card p-2">
@if (unusedPrinters(); as unusedPrinters) {
<div class="card p-2 col-12 col-sm-7 col-md-8">
<div class="card-body">
<h5 class="card-title d-flex justify-content-between align-items-center">
{{ 'Ungekoppelte Drucker' | transloco }}
<bi name="info-circle-fill" />
</h5>

<div class="list-group mb-3">
@for (printer of unusedPrinters; track printer.id) {
<a
class="list-group-item list-group-item-action list-group-item-warning d-flex align-items-center gap-2"
[routerLink]="'o/organisationId/e/eventId/printers/' + printer.id"
>
{{printer.name}}
</a>
}
</div>
<a href="#" class="card-link" routerLink="o/organisationId/e/eventId/printers/mediators/all">Zu den Mediators</a>
</div>
</div>
} @if (myUser()?.isAdmin) {
<div class="card p-2 col-12 col-sm-7 col-md-8">
<div
class="card-body d-inline-flex align-items-center gap-2 clickable"
(mousedown)="showSystemInfoService.set(!showSystemInfoService.show())"
Expand All @@ -56,13 +77,14 @@ <h5 class="card-title">{{ 'ABOUT_APP_DISCOVER' | transloco }}</h5>
</div>

@if (event()) {

<div class="col-12 col-lg-5 d-flex flex-column gap-2">
<div class="card p-2">
<div class="card-body">
<h5 class="card-title">{{ 'Neue Bestellungen' | transloco }}</h5>

<div class="list-group list-group-flush">
@for (order of orders(); track order.id) {
@if (orders(); as orders) { @for (order of orders; track order.id) {
<a
class="list-group-item list-group-item-action d-flex justify-content-between align-items-start"
[routerLink]="'o/organisationId/e/eventId/orders/' + order.id"
Expand Down Expand Up @@ -96,7 +118,7 @@ <h5 class="card-title">{{ 'Neue Bestellungen' | transloco }}</h5>
}
</div>
</a>
} @empty {
} @empty { Keine Bestellungen. } } @else {
<app-progress-bar show />
}
</div>
Expand Down
17 changes: 16 additions & 1 deletion src/app/home/start/start.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import {AppProgressBarComponent} from '@shared/ui/loading/app-progress-bar.compo
import {BiComponent} from 'dfx-bootstrap-icons';
import {StopPropagationDirective} from 'dfx-helper';

import {catchError, filter, map, of, startWith, switchMap, timer} from 'rxjs';
import {catchError, combineLatest, filter, map, of, startWith, switchMap, timer} from 'rxjs';
import {MyUserService} from '../_shared/services/user/my-user.service';
import {SelectedEventService} from '../_admin/events/_services/selected-event.service';
import {AppOrderStateBadgeComponent} from '../orders/_components/app-order-state-badge.component';
import {OrdersService} from '../orders/orders.service';
import {MediatorsService} from '../printers/_services/mediators.service';
import {PrintersService} from '../printers/_services/printers.service';

@Component({
selector: 'app-start',
Expand All @@ -42,6 +44,8 @@ export class StartComponent {
#httpClient = inject(HttpClient);
#authService = inject(AuthService);
#ordersService = inject(OrdersService);
#mediatorsService = inject(MediatorsService);
#printersService = inject(PrintersService);

isProduction = EnvironmentHelper.getProduction();
type = EnvironmentHelper.getType();
Expand Down Expand Up @@ -74,6 +78,17 @@ export class StartComponent {
),
);

unusedPrinters = toSignal(
timer(0, 3 * 60000).pipe(
switchMap(() => combineLatest([this.#mediatorsService.getAll$(), this.#printersService.getAll$()])),
map(([mediators, printers]) => {
const allUsedPrinters = mediators.map((mediator) => mediator.printers.map((printer) => printer.id)).flat();
return printers.filter((printer) => !allUsedPrinters.includes(printer.id));
}),
map((printers) => (printers.length > 0 ? printers : undefined)),
),
);

logout(): void {
this.#authService.logout();
}
Expand Down

0 comments on commit 8ed08be

Please sign in to comment.