Skip to content

Commit

Permalink
Fix dashboard rm prefix (#1592)
Browse files Browse the repository at this point in the history
* Remove prefix from path

* Remove slash
  • Loading branch information
wilmveel committed Nov 15, 2023
1 parent a8b2971 commit 7919f78
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 61 deletions.
20 changes: 0 additions & 20 deletions http/baker-http-dashboard/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,6 @@ const routes: Routes = [
"component": InstancesComponent,
"path": "instances/:recipeInstanceId",
},
{
"component": HomeComponent,
"path": ":prefix"
},
{
"component": RecipesComponent,
"path": ":prefix/recipes"
},
{
"component": InteractionsComponent,
"path": ":prefix/interactions",
},
{
"component": InstancesComponent,
"path": ":prefix/instances",
},
{
"component": InstancesComponent,
"path": ":prefix/instances/:recipeInstanceId",
},
{
"component": NotFoundComponent,
"path": "**",
Expand Down
8 changes: 4 additions & 4 deletions http/baker-http-dashboard/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ <h1 class="example-app-name">{{ title }}</h1>
<mat-sidenav #snav [mode]="mobileQuery.matches ? 'over' : 'side'"
[fixedInViewport]="mobileQuery.matches" fixedTopGap="56" opened="true">
<mat-nav-list>
<a mat-list-item routerLink="{{ prefix }}/">Home</a>
<a mat-list-item routerLink="{{ prefix }}/recipes">Recipes</a>
<a mat-list-item routerLink="{{ prefix }}/interactions">Interactions</a>
<a mat-list-item routerLink="{{ prefix }}/instances">Instances</a>
<a mat-list-item routerLink="/">Home</a>
<a mat-list-item routerLink="/recipes">Recipes</a>
<a mat-list-item routerLink="/interactions">Interactions</a>
<a mat-list-item routerLink="/instances">Instances</a>
</mat-nav-list>
</mat-sidenav>

Expand Down
1 change: 0 additions & 1 deletion http/baker-http-dashboard/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {wasmFolder} from "@hpcc-js/wasm";
})
export class AppComponent implements OnDestroy, OnInit {
title = AppSettingsService.settings.applicationName;
prefix = AppSettingsService.prefix.prefix;
mobileQuery: MediaQueryList;

private readonly mobileQueryListener: () => void;
Expand Down
36 changes: 3 additions & 33 deletions http/baker-http-dashboard/src/app/app.settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import {Value} from "./baker-value.api";

const LOCAL_SETTINGS_LOCATION = "/assets/settings/settings.json";
const SETTINGS_LOCATION = "dashboard_config";

export interface PrefixSettings {
prefix: string;
}

export interface AppSettings {
applicationName: string;
apiPath: string;
Expand All @@ -17,13 +12,12 @@ export interface AppSettings {

@Injectable()
export class AppSettingsService {
static prefix: PrefixSettings;
static settings: AppSettings;

constructor (private http: HttpClient) {
}

public getAppSettings(prefix: String):Promise<void> {
public getAppSettings():Promise<void> {
return new Promise<void>((resolve, reject) => {
// //For testing purposes:
// AppSettingsService.settings = {
Expand All @@ -33,7 +27,7 @@ export class AppSettingsService {
// };
// resolve()

this.http.get(prefix + "/" + SETTINGS_LOCATION).toPromise().then(response => {
this.http.get(SETTINGS_LOCATION).toPromise().then(response => {
AppSettingsService.settings = <AppSettings>response;
resolve();
}).catch((response: any) => {
Expand All @@ -43,32 +37,8 @@ export class AppSettingsService {
}

load () {
const url = new URL(window.location.href);

// if there is an empty path or just a / the prefix is empty
if(url.pathname == "/" || url.pathname.length == 0) {
AppSettingsService.prefix = {"prefix": url.pathname.substring(url.pathname.lastIndexOf('/') + 1)}
}
// If there is a path we need to ensure they are not part of the path
else {
var temp = url.pathname;
if(temp.includes('/recipes')) {
temp = temp.substring(0, temp.lastIndexOf('/recipes'))
}
if(temp.includes('/interactions')) {
temp = temp.substring(0, temp.lastIndexOf('/interactions'))
}
if(temp.includes('/instances')) {
temp = temp.substring(0, temp.lastIndexOf('/instances'))
}
if(temp.lastIndexOf("/") > 0) {
temp = temp.substring(0, temp.lastIndexOf('/'))
}
AppSettingsService.prefix = {"prefix": temp}
}

return new Promise<void>((resolve, reject) => {
this.getAppSettings(AppSettingsService.prefix.prefix)
this.getAppSettings()
.then(_ => resolve())
});
}
Expand Down
2 changes: 1 addition & 1 deletion http/baker-http-dashboard/src/app/bakery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Value} from "./baker-value.api";
@Injectable({"providedIn": "root"})
export class BakeryService {

private baseUrl = AppSettingsService.prefix.prefix + AppSettingsService.settings.apiPath;
private baseUrl = AppSettingsService.settings.apiPath;

httpOptions = {
"headers": new HttpHeaders({"Content-Type": "application/json"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class InstancesComponent implements OnInit {

updateInstance(event: Event): void {
(event.target as HTMLInputElement)?.blur();
this.router.navigateByUrl(AppSettingsService.prefix.prefix + `/instances/${this.instanceId}`).then(() => this.instanceChanged());
this.router.navigateByUrl(`/instances/${this.instanceId}`).then(() => this.instanceChanged());
}

instanceChanged (): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class RecipesComponent implements OnInit {
bakeRecipe(recipeId: string): void {
const instanceId = this.randomId(8)
this.bakeryService.postBake(instanceId, recipeId).subscribe(() => {
window.location.href = AppSettingsService.prefix.prefix + `/instances/${instanceId}`
window.location.href = `/instances/${instanceId}`
});
}

Expand Down

0 comments on commit 7919f78

Please sign in to comment.