diff --git a/src/app/components/rack-parts/rack-detail-data.service.ts b/src/app/components/rack-parts/rack-detail-data.service.ts index d9bd2466..8230e28e 100644 --- a/src/app/components/rack-parts/rack-detail-data.service.ts +++ b/src/app/components/rack-parts/rack-detail-data.service.ts @@ -3,7 +3,7 @@ import { ElementRef, Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { Router } from '@angular/router'; -import _ from 'lodash'; +import { cloneDeep } from 'lodash'; import { BehaviorSubject, combineLatest, of, ReplaySubject, Subject } from 'rxjs'; import { filter, map, switchMap, takeUntil, tap, withLatestFrom } from 'rxjs/operators'; import { UserManagementService } from '../../features/backbone/login/user-management.service'; @@ -47,6 +47,14 @@ export class RackDetailDataService extends SubManager { ) { super(); + // when user toggles locked status of rack, update backend + this.manageSub( + this.requestRackEditableStatusChange$ + .pipe( + requestRackDuplication$ = new Subject(); + } + super(); + // when user toggles locked status of rack, update backend this.manageSub( this.requestRackEditableStatusChange$ @@ -84,6 +92,14 @@ export class RackDetailDataService extends SubManager { this.singleRackData$.pipe( tap(x => this.rowedRackedModules$.next(null)), filter(x => !!x), + this.manageSub( + this.requestRackDuplication$ + .pipe(switchMap(rack => this.duplicateRack(rack))) + .subscribe(newRack => { + this.snackBar.open('Rack duplicated', undefined, {duration: 4000}); + this.updateSingleRackData$.next(newRack.id); + }) + ); switchMap(x => x ? this.backend.get.rackedModules(x.id) : of([])), withLatestFrom(this.singleRackData$) )