100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI updates: Code reformat rest component
Rich Turner84d1f85d3c80
diff --git a/ui/component/rest/src/rest.ts b/ui/component/rest/src/rest.tsindex 00bbaf5e7..933d7a066 100644--- a/ui/component/rest/src/rest.ts+++ b/ui/component/rest/src/rest.ts@@ -1,69 +1,70 @@import openremote, {Auth, OREvent} from "@openremote/core";import axios, {AxiosInstance} from "axios";import {ApiClient} from "../build/restclient";+import {Promise} from "es6-promise";export class RestApi {- get api() {- return this._client;- }-- protected static getBaseUrl(): string {- let baseUrl = openremote.config.managerUrl;- baseUrl += "/api/" + openremote.config.realm + "/";- return baseUrl;- }+ get api() {+ return this._client;+ }- protected _client!: ApiClient;- protected _axiosInstance!: AxiosInstance;+ protected static getBaseUrl(): string {+ let baseUrl = openremote.config.managerUrl;+ baseUrl += "/api/" + openremote.config.realm + "/";+ return baseUrl;+ }- constructor() {- openremote.addListener((evt) => this.onEvent(evt));- this.initClient();- }+ protected _client!: ApiClient;+ protected _axiosInstance!: AxiosInstance;- protected onEvent(event: OREvent) {- switch (event) {- case OREvent.AUTHENTICATED:- break;- case OREvent.ERROR:- break;- case OREvent.INIT:+ constructor() {+ openremote.addListener((evt) => this.onEvent(evt));this.initClient();- break;}- }- protected initClient() {- if (!this._client && openremote.initialised && openremote.isManagerAvailable) {- this._axiosInstance = axios.create();- this._axiosInstance.defaults.timeout = 10000;+ protected onEvent(event: OREvent) {+ switch (event) {+ case OREvent.AUTHENTICATED:+ break;+ case OREvent.ERROR:+ break;+ case OREvent.INIT:+ this.initClient();+ break;+ }+ }- if (openremote.config.auth === Auth.BASIC && openremote.config.credentials) {- this._axiosInstance.defaults.auth = {- password: openremote.config.credentials.password,- username: openremote.config.credentials.username- };- } else if (openremote.config.auth === Auth.KEYCLOAK) {- // Add interceptor to inject authorization header on each request- this._axiosInstance.interceptors.request.use(- (config) => {- if (!config.headers.Authorization) {- const token = openremote.getKeycloakToken();+ protected initClient() {+ if (!this._client && openremote.initialised && openremote.isManagerAvailable) {+ this._axiosInstance = axios.create();+ this._axiosInstance.defaults.timeout = 10000;- if (token) {- config.headers.Authorization = "Bearer " + token;- }- }+ if (openremote.config.auth === Auth.BASIC && openremote.config.credentials) {+ this._axiosInstance.defaults.auth = {+ password: openremote.config.credentials.password,+ username: openremote.config.credentials.username+ };+ } else if (openremote.config.auth === Auth.KEYCLOAK) {+ // Add interceptor to inject authorization header on each request+ this._axiosInstance.interceptors.request.use(+ (config) => {+ if (!config.headers.Authorization) {+ const token = openremote.getKeycloakToken();++ if (token) {+ config.headers.Authorization = "Bearer " + token;+ }+ }- return config;- },- (error) => Promise.reject(error)- );- }- this._client = new ApiClient(RestApi.getBaseUrl(), this._axiosInstance);+ return config;+ },+ (error) => Promise.reject(error)+ );+ }+ this._client = new ApiClient(RestApi.getBaseUrl(), this._axiosInstance);+ }}- }}export default new RestApi();