Skip to content

Commit

Permalink
chore[XXXX]: fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanmugavel committed Aug 2, 2024
1 parent 2b6b42a commit 8e7a221
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
</mat-card-header>
<mat-card-content class="part-detail--relation__container">
<ng-container>
<app-part-relation [isStandalone]="false" [showMiniMap]="false"></app-part-relation>
<app-part-relation [isStandalone]="false" [showMiniMap]="false" [isAsBuilt]="isAsBuiltPart"></app-part-relation>
<mat-icon onkeydown="openRelationPage(partDetails.data)" (click)="openRelationPage(partDetails.data)" class="part-detail--relation__icon"
>open_in_new
</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class PartsDetailComponent {

public currentPartId: string;
public pageIndexHistory: {AS_BUILT_PAGE: string, AS_PLANNED_PAGE: string}
private isAsBuiltPart: boolean;
public isAsBuiltPart: boolean;

constructor(public readonly partDetailsFacade: PartDetailsFacade, private readonly router: Router, private readonly route: ActivatedRoute, public roleService: RoleService, private location: Location, private sharedPartService: SharedPartService) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ export class PartDetailsFacade {
);
}

public getRootPart(id: string): Observable<View<Part>> {
return this.partsService.getPart(id).pipe(
map((part: Part) => ({ data: part })),
catchError((error: Error) => of({ error })),
);
public getRootPart(id: string, isAsBuilt: boolean): Observable<View<Part>> {
if (isAsBuilt){
return this.partsService.getPartByIdAsBuilt(id).pipe(
map((part: Part) => ({ data: part })),
catchError((error: Error) => of({ error })),
);
}else {
return this.partsService.getPartByIdAsPlanned(id).pipe(
map((part: Part) => ({ data: part })),
catchError((error: Error) => of({ error })),
);
}
}

public getChildPartDetails(part): Observable<Part[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { delay, switchMap, takeWhile, tap } from 'rxjs/operators';
export class PartRelationComponent implements OnInit, OnDestroy {
@Input() isStandalone = true;
@Input() showMiniMap = true;
@Input() isAsBuilt = true;

public readonly htmlIdBase = 'app-part-relation-';
public readonly subscriptions = new Subscription();
Expand Down Expand Up @@ -78,7 +79,7 @@ export class PartRelationComponent implements OnInit, OnDestroy {
if (this.partDetailsFacade.selectedPart) return this.partDetailsFacade.selectedPart$;

const partId = params.get('partId');
return partId ? this.partDetailsFacade.getRootPart(partId) : this.partDetailsFacade.selectedPart$;
return partId ? this.partDetailsFacade.getRootPart(partId, this.isAsBuilt) : this.partDetailsFacade.selectedPart$;
}),
tap(viewData => this._rootPart$.update(viewData)),
takeWhile(({ data }) => !data, true),
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/app/modules/shared/service/parts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,34 @@ export class PartsService {
);
}

public getPartByIdAsBuilt(id: string): Observable<Part> {
if (!id || typeof id !== 'string') {
throw new Error('invalid ID');
}

const encodedId = encodeURIComponent(id);

return this.apiService.get<PartResponse>(`${ this.url }/assets/as-built/${ encodedId }`).pipe(
map(part => PartsAssembler.assemblePart(part, MainAspectType.AS_BUILT)),
catchError(() => of(null)),
);


}

public getPartByIdAsPlanned(id: string): Observable<Part> {
if (!id || typeof id !== 'string') {
throw new Error('invalid ID');
}

const encodedId = encodeURIComponent(id);

return this.apiService.get<PartResponse>(`${ this.url }/assets/as-planned/${ encodedId }`).pipe(
map(part => PartsAssembler.assemblePart(part, MainAspectType.AS_PLANNED)),
catchError(() => of(null)),
);

}
public getPartDetailOfIds(assetIds: string[], isAsBuilt?: boolean): Observable<Part[]> {

if (isAsBuilt !== undefined) {
Expand Down

0 comments on commit 8e7a221

Please sign in to comment.