-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Käser
committed
Mar 21, 2024
1 parent
9b6ef0a
commit 58bc117
Showing
18 changed files
with
184 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/ch/puzzle/okr/dto/ClientConfigDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ch.puzzle.okr.dto; | ||
|
||
import java.util.HashMap; | ||
|
||
public record ClientConfigDto( | ||
String activeProfile, | ||
String issuer, | ||
String clientId, | ||
String favicon, | ||
String logo, | ||
HashMap<String, String> customStyles | ||
) { | ||
} |
29 changes: 0 additions & 29 deletions
29
backend/src/main/java/ch/puzzle/okr/service/ClientConfigService.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/ch/puzzle/okr/service/clientconfig/ClientConfigProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ch.puzzle.okr.service.clientconfig; | ||
|
||
import ch.puzzle.okr.dto.ClientConfigDto; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
|
||
@ConfigurationProperties("okr.clientconfig") | ||
public class ClientConfigProperties { | ||
private String favicon; | ||
|
||
private String logo; | ||
|
||
private HashMap<String, String> customStyles; | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/ch/puzzle/okr/service/clientconfig/ClientConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.puzzle.okr.service.clientconfig; | ||
|
||
import ch.puzzle.okr.dto.ClientConfigDto; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
|
||
@Service | ||
public class ClientConfigService { | ||
|
||
@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}") | ||
private String issuer; | ||
|
||
@Value("${spring.profiles.active}") | ||
private String activeProfile; | ||
|
||
@Value("${spring.security.oauth2.resourceserver.opaquetoken.client-id}") | ||
private String clientId; | ||
|
||
@Value("${okr.clientconfig.favicon}") | ||
private String favicon; | ||
|
||
@Value("${okr.clientconfig.logo}") | ||
private String logo; | ||
|
||
@Value("${okr.clientconfig.customStyles}") | ||
private HashMap<String, String> customStyles; | ||
|
||
public ClientConfigDto getConfigBasedOnActiveEnv() { | ||
return new ClientConfigDto(activeProfile, issuer, clientId, favicon, logo, customStyles); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
backend/src/test/java/ch/puzzle/okr/controller/ClientConfigControllerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
frontend/src/app/application-top-bar/application-top-bar.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable, shareReplay } from 'rxjs'; | ||
import { ClientConfig } from "./shared/types/model/ClientConfig"; | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ConfigService { | ||
public config$: Observable<any>; | ||
public config$: Observable<ClientConfig>; | ||
|
||
constructor(private httpClient: HttpClient) { | ||
this.config$ = this.httpClient.get('/config').pipe(shareReplay()); | ||
this.config$ = this.httpClient | ||
.get<ClientConfig>('/config') | ||
.pipe(shareReplay()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ConfigService } from "../../config.service"; | ||
import { CustomizationConfig } from "../types/model/ClientConfig"; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class CustomizationService { | ||
private currentConfig?: CustomizationConfig; | ||
|
||
constructor(private configService: ConfigService) { | ||
configService.config$.subscribe(config => { | ||
this.updateCustomizations(config); | ||
}) | ||
} | ||
|
||
|
||
private updateCustomizations(config: CustomizationConfig) { | ||
this.setFavicon(config.favicon); | ||
this.setStyleCustomizations(config.customStyles); | ||
|
||
this.currentConfig = config; | ||
} | ||
|
||
private setFavicon(favicon: string) { | ||
if (!favicon || this.currentConfig?.favicon === favicon) { | ||
return; | ||
} | ||
|
||
document.getElementById("favicon")?.setAttribute("src", favicon); | ||
} | ||
|
||
private setStyleCustomizations(customStylesMap: Map<string, string>) { | ||
if (!customStylesMap || this.areStylesTheSame(customStylesMap)) { | ||
return; | ||
} | ||
|
||
this.removeStyles(this.currentConfig?.customStyles) | ||
this.setStyles(customStylesMap); | ||
} | ||
|
||
private areStylesTheSame(customStylesMap: Map<string, string>) { | ||
return JSON.stringify(this.currentConfig?.customStyles) === JSON.stringify(customStylesMap); | ||
} | ||
|
||
private removeStyles(customStylesMap: Map<string, string> | undefined) { | ||
if (!customStylesMap) { | ||
return; | ||
} | ||
const styles = document?.getElementById("html")!.style; | ||
if (!styles) { | ||
return | ||
} | ||
|
||
Array.from(customStylesMap.entries()).forEach(([varName, varValue]) => { | ||
styles.setProperty(`--${varName}`, varValue); | ||
}); | ||
} | ||
|
||
private setStyles(customStylesMap: Map<string, string>) { | ||
if (!customStylesMap) { | ||
return; | ||
} | ||
const styles = document?.getElementById("html")!.style; | ||
if (!styles) { | ||
return | ||
} | ||
|
||
Array.from(customStylesMap.keys()).forEach((varName) => { | ||
styles.removeProperty(`--${varName}`); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
export interface AuthConfig { | ||
activeProfile: string; | ||
issuer: string; | ||
clientId: string; | ||
} | ||
|
||
export interface CustomizationConfig { | ||
favicon: string; | ||
logo: string; | ||
customStyles: Map<string, string>; | ||
} | ||
export interface ClientConfig extends AuthConfig, CustomizationConfig { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters