Commit 119cd91fa3c8c98e35868771e1128bd8d946c2ff

Authored by Igor Kulikov
1 parent c428b587

Add baseUrl method

@@ -21,6 +21,7 @@ import { Inject, Injectable, NgZone } from '@angular/core'; @@ -21,6 +21,7 @@ import { Inject, Injectable, NgZone } from '@angular/core';
21 import { WINDOW } from '@core/services/window.service'; 21 import { WINDOW } from '@core/services/window.service';
22 import { ExceptionData } from '@app/shared/models/error.models'; 22 import { ExceptionData } from '@app/shared/models/error.models';
23 import { 23 import {
  24 + baseUrl,
24 createLabelFromDatasource, 25 createLabelFromDatasource,
25 deepClone, 26 deepClone,
26 deleteNullProperties, 27 deleteNullProperties,
@@ -409,7 +410,7 @@ export class UtilsService { @@ -409,7 +410,7 @@ export class UtilsService {
409 } 410 }
410 411
411 public updateQueryParam(name: string, value: string | null) { 412 public updateQueryParam(name: string, value: string | null) {
412 - const baseUrl = [this.window.location.protocol, '//', this.window.location.host, this.window.location.pathname].join(''); 413 + const baseUrlPart = [baseUrl(), this.window.location.pathname].join('');
413 const urlQueryString = this.window.location.search; 414 const urlQueryString = this.window.location.search;
414 let newParam = ''; 415 let newParam = '';
415 let params = ''; 416 let params = '';
@@ -429,7 +430,11 @@ export class UtilsService { @@ -429,7 +430,11 @@ export class UtilsService {
429 } else if (newParam) { 430 } else if (newParam) {
430 params = '?' + newParam; 431 params = '?' + newParam;
431 } 432 }
432 - this.window.history.replaceState({}, '', baseUrl + params); 433 + this.window.history.replaceState({}, '', baseUrlPart + params);
  434 + }
  435 +
  436 + public baseUrl(): string {
  437 + return baseUrl();
433 } 438 }
434 439
435 public deepClone<T>(target: T, ignoreFields?: string[]): T { 440 public deepClone<T>(target: T, ignoreFields?: string[]): T {
@@ -385,6 +385,15 @@ export function padValue(val: any, dec: number): string { @@ -385,6 +385,15 @@ export function padValue(val: any, dec: number): string {
385 return strVal; 385 return strVal;
386 } 386 }
387 387
  388 +export function baseUrl(): string {
  389 + let url = window.location.protocol + '//' + window.location.hostname;
  390 + const port = window.location.port;
  391 + if (port && port.length > 0 && port !== '80' && port !== '443') {
  392 + url += ':' + port;
  393 + }
  394 + return url;
  395 +}
  396 +
388 export function sortObjectKeys<T>(obj: T): T { 397 export function sortObjectKeys<T>(obj: T): T {
389 return Object.keys(obj).sort().reduce((acc, key) => { 398 return Object.keys(obj).sort().reduce((acc, key) => {
390 acc[key] = obj[key]; 399 acc[key] = obj[key];