Skip to content

Commit

Permalink
Feature/planqk demo direct links (#245)
Browse files Browse the repository at this point in the history
* added sso-check on keycloak load and added wait for sso check to algorithms page

* chaned workflow for api queries

* re-added page guard

* removed root-url setting in navigation (is now set directly in algorithms)

* added logout workaround

* added fixme comment

* Update src/app/components/algorithms/algorithm-view/algorithm-view.component.ts

Co-authored-by: Fabian Bühler <buehler-fabian@posteo.de>

* removed logout workaround and moved algorithm parsing to subscribe

---------

Co-authored-by: Fabian Bühler <buehler-fabian@posteo.de>
  • Loading branch information
mhinkie and buehlefs authored Nov 7, 2023
1 parent 33d175f commit ed55182
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { AlgorithmDto } from 'api-atlas/models/algorithm-dto';
import { AlgorithmService } from 'api-atlas/services/algorithm.service';
import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
import { Observable, of, Subscription } from 'rxjs';
import { ApplicationAreaDto } from 'api-atlas/models/application-area-dto';
import { ApplicationAreasService } from 'api-atlas/services/application-areas.service';
import { ProblemTypeService } from 'api-atlas/services/problem-type.service';
import { ProblemTypeDto } from 'api-atlas/models/problem-type-dto';
import { TagDto } from 'api-atlas/models/tag-dto';
import { RevisionDto } from 'api-atlas/models/revision-dto';
import { ApiConfiguration } from 'api-atlas/api-configuration';
import { catchError, map, mergeMap, take } from 'rxjs/operators';

Check warning on line 13 in src/app/components/algorithms/algorithm-view/algorithm-view.component.ts

View workflow job for this annotation

GitHub Actions / Run linters

'map' is defined but never used
import { BreadcrumbLink } from '../../generics/navigation-breadcrumb/navigation-breadcrumb.component';
import { UtilService } from '../../../util/util.service';
import { UiFeatures } from '../../../directives/qc-atlas-ui-repository-configuration.service';
import { ChangePageGuard } from '../../../services/deactivation-guard';
import { PlanqkPlatformLoginService } from '../../../services/planqk-platform-login.service';
import {
ComparedData,
CompareVersionDialogComponent,
Expand Down Expand Up @@ -42,7 +44,9 @@ export class AlgorithmViewComponent implements OnInit, OnDestroy {

links: BreadcrumbLink[] = [{ heading: '', subHeading: '' }];

private routeSub: Subscription;
private dataSubscription: Subscription | null = null;

private configuredApiUrl: string;

constructor(
private algorithmService: AlgorithmService,
Expand All @@ -51,37 +55,62 @@ export class AlgorithmViewComponent implements OnInit, OnDestroy {
private route: ActivatedRoute,
private utilService: UtilService,
private config: ApiConfiguration,
public guard: ChangePageGuard
public guard: ChangePageGuard,
private planqkPlatformLoginService: PlanqkPlatformLoginService
) {}

ngOnInit(): void {
this.routeSub = this.route.params.subscribe(({ algoId }) => {
this.algorithmService.getAlgorithm({ algorithmId: algoId }).subscribe(
(algo: AlgorithmDto) => {
this.algorithm = algo;
this.frontendAlgorithm = JSON.parse(
JSON.stringify(algo)
) as AlgorithmDto;
let subheading = this.algorithm.computationModel
.toString()
.toLowerCase();
subheading = subheading[0].toUpperCase() + subheading.slice(1);
this.links[0] = {
heading: this.createBreadcrumbHeader(this.algorithm),
subHeading: subheading + ' Algorithm',
};
this.getApplicationAreasForAlgorithm(algoId);
this.getProblemTypesForAlgorithm(algoId);
this.getTagsForAlgorithm(algoId);
this.fetchRevisions();
},
() => {
this.dataSubscription = this.planqkPlatformLoginService
.isLoggedIn()
.pipe(
take(1),
mergeMap((loggedIn) => {
if (loggedIn) {
// Try planqk
this.configuredApiUrl = this.config.rootUrl;
this.config.rootUrl = 'https://platform.planqk.de/qc-catalog';
}
return this.loadAlgorithm();
}),
catchError(() => {
// Not available on PlanQK: Try on qc-atlas api
this.config.rootUrl = this.configuredApiUrl;
return this.loadAlgorithm();
}),
catchError(() => {
this.utilService.callSnackBar(
'Error! Algorithm could not be retrieved.'
);
}
);
});
return of();
})
)
.subscribe((algo: AlgorithmDto) => {
const algoId = algo.id;
this.algorithm = algo;
this.frontendAlgorithm = JSON.parse(
JSON.stringify(algo)
) as AlgorithmDto;
let subheading = this.algorithm.computationModel
.toString()
.toLowerCase();
subheading = subheading[0].toUpperCase() + subheading.slice(1);
this.links[0] = {
heading: this.createBreadcrumbHeader(this.algorithm),
subHeading: subheading + ' Algorithm',
};
this.getApplicationAreasForAlgorithm(algoId);
this.getProblemTypesForAlgorithm(algoId);
this.getTagsForAlgorithm(algoId);
this.fetchRevisions();
});
}

loadAlgorithm(): Observable<AlgorithmDto> {
return this.route.params.pipe(
mergeMap(({ algoId }) =>
this.algorithmService.getAlgorithm({ algorithmId: algoId })
)
);
}

changeTab(tabNumber: number): void {
Expand All @@ -91,8 +120,9 @@ export class AlgorithmViewComponent implements OnInit, OnDestroy {
this.generalTab = false;
}
}

ngOnDestroy(): void {
this.routeSub.unsubscribe();
this.dataSubscription?.unsubscribe();
}

saveAlgorithm(
Expand Down
1 change: 0 additions & 1 deletion src/app/components/navigation/navigation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class NavigationComponent implements OnInit {
if (loggedIn) {
this.bearerTokenSet = true;
this.config.rootUrl = 'https://platform.planqk.de/qc-catalog';
this.reloadStartPage();
this.utilService.callSnackBar(
'Successfully logged into the PlanQK platform.'
);
Expand Down
3 changes: 3 additions & 0 deletions src/app/util/keycloak-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export const initializeKeycloak = (keycloak: KeycloakService) => (): Promise<
clientId: 'planqk-login',
},
initOptions: {
onLoad: 'check-sso',
checkLoginIframe: false,
enableLogging: true,
},
enableBearerInterceptor: false,
loadUserProfileAtStartUp: true,
})
.then((retValue) => retValue);

0 comments on commit ed55182

Please sign in to comment.