Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(*): refactor to set the configs files not dependent from any ht… #1387

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/core/src/lib/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, Injector } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpBackend, HttpClient } from '@angular/common/http';
import { throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';

Expand All @@ -13,8 +13,11 @@ import { version } from './version';
})
export class ConfigService {
private config: object = {};
private httpClient: HttpClient;

constructor(private injector: Injector) {}
constructor(handler: HttpBackend) {
this.httpClient = new HttpClient(handler);
}

/**
* Use to get the data found in config file
Expand All @@ -33,10 +36,9 @@ export class ConfigService {
return true;
}

const http = this.injector.get(HttpClient);

return new Promise((resolve, _reject) => {
http
this.httpClient
.get(options.path)
.pipe(
catchError((error: any): any => {
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/lib/language/shared/language.loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { HttpBackend, HttpClient } from '@angular/common/http';

import { forkJoin, map } from 'rxjs';

Expand All @@ -9,15 +9,19 @@ import { ObjectUtils } from '@igo2/utils';
import { ConfigService } from '../../config/config.service';

export class LanguageLoader implements TranslateLoader {
private httpClient: HttpClient;

constructor(
private http: HttpClient,
handler: HttpBackend,
private prefix?: string | string[],
private suffix: string = '.json',
private config?: ConfigService
) {}
) {
this.httpClient = new HttpClient(handler);
}

public getTranslation(lang: string): any {
const igoLocale$ = this.http.get(`locale/libs_locale/${lang}.json`);
const igoLocale$ = this.httpClient.get(`locale/libs_locale/${lang}.json`);

if (this.config && !this.prefix) {
const prefix = this.config.getConfig('language.prefix');
Expand All @@ -29,7 +33,7 @@ export class LanguageLoader implements TranslateLoader {
}

const appLocale$ = (this.prefix as string[]).map((prefix) =>
this.http.get(`${prefix}${lang}${this.suffix}`)
this.httpClient.get(`${prefix}${lang}${this.suffix}`)
);

const locale$ = forkJoin([igoLocale$, ...appLocale$]);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/language/shared/language.provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HttpClient } from '@angular/common/http';
import { HttpBackend } from '@angular/common/http';
import { TranslateLoader } from '@ngx-translate/core';

import { ConfigService } from '../../config/config.service';
import { LanguageLoader } from './language.loader';

export function defaultLanguageLoader(
http: HttpClient,
http: HttpBackend,
config?: ConfigService
) {
return new LanguageLoader(http, undefined, undefined, config);
Expand All @@ -15,14 +15,14 @@ export function provideLanguageLoader(loader?) {
return {
provide: TranslateLoader,
useFactory: loader || defaultLanguageLoader,
deps: [HttpClient]
deps: [HttpBackend]
};
}

export function provideDefaultLanguageLoader(loader?) {
return {
provide: TranslateLoader,
useFactory: loader || defaultLanguageLoader,
deps: [HttpClient, ConfigService]
deps: [HttpBackend, ConfigService]
};
}
13 changes: 7 additions & 6 deletions packages/geo/src/lib/style/style-list/style-list.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, Injector } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpBackend, HttpClient } from '@angular/common/http';
import { throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';

Expand All @@ -12,8 +12,11 @@ import { StyleListOptions } from './style-list.interface';
})
export class StyleListService {
private styleList: object = {};
private httpClient: HttpClient;

constructor(private injector: Injector) {}
constructor(handler: HttpBackend) {
this.httpClient = new HttpClient(handler);
}

/**
* Use to get the data found in styleList file
Expand All @@ -32,10 +35,8 @@ export class StyleListService {
return true;
}

const http = this.injector.get(HttpClient);

return new Promise((resolve, _reject) => {
http
this.httpClient
.get(options.path)
.pipe(
catchError((error: any): any => {
Expand Down