From 2eb1a986394162a73b084074a969490b78b3f7e4 Mon Sep 17 00:00:00 2001 From: Pop John Date: Fri, 12 Jul 2024 15:23:23 +0300 Subject: [PATCH] better code organization --- frontend/src/app/app.config.ts | 6 ++++-- ...{core.provide.ts => core-services.provide.ts} | 12 +----------- frontend/src/app/services/be-services.provide.ts | 16 ++++++++++++++++ .../services.tokens.ts} | 2 +- frontend/src/app/state/core/auth/auth.effects.ts | 2 +- .../src/app/state/core/charts/charts.effects.ts | 2 +- frontend/src/app/state/core/file/file.effects.ts | 2 +- .../src/app/state/core/models/models.effects.ts | 2 +- .../state/core/parameters/parameters.effects.ts | 2 +- .../src/app/state/core/script/script.effects.ts | 2 +- .../state/core/statistics/statistics.effects.ts | 2 +- .../app/state/core/terminal/terminal.effects.ts | 2 +- .../state/run-records/records/records.effects.ts | 2 +- 13 files changed, 31 insertions(+), 23 deletions(-) rename frontend/src/app/modules/core/{core.provide.ts => core-services.provide.ts} (83%) create mode 100644 frontend/src/app/services/be-services.provide.ts rename frontend/src/app/{app.tokens.ts => services/services.tokens.ts} (93%) diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index 30c8a358..6b1e20f9 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -4,8 +4,9 @@ import { provideClientHydration } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; -import { provideCore } from './modules/core/core.provide'; +import { provideCoreServices } from './modules/core/core-services.provide'; import { provideCustomMaterialConfigs } from './modules/shared/material.providers'; +import { provideBEServices } from './services/be-services.provide'; import { provideInterceptors } from './services/interceptors.provide'; import { provideGlobalStore } from './state/global-store.providers'; @@ -15,7 +16,8 @@ export const appConfig: ApplicationConfig = { provideRouter(routes), provideCustomMaterialConfigs(), provideGlobalStore(), - provideCore(), + provideBEServices(), + provideCoreServices(), provideInterceptors(), provideClientHydration(), provideHttpClient(withInterceptorsFromDi()) diff --git a/frontend/src/app/modules/core/core.provide.ts b/frontend/src/app/modules/core/core-services.provide.ts similarity index 83% rename from frontend/src/app/modules/core/core.provide.ts rename to frontend/src/app/modules/core/core-services.provide.ts index 92d0739e..044b0d87 100644 --- a/frontend/src/app/modules/core/core.provide.ts +++ b/frontend/src/app/modules/core/core-services.provide.ts @@ -1,8 +1,5 @@ -import { HttpClient } from '@angular/common/http'; import { ENVIRONMENT_INITIALIZER, inject, Provider } from '@angular/core'; import { MatIconRegistry } from '@angular/material/icon'; -import { CLIENT } from '../../app.tokens'; -import { ClientBackend } from '../../services/client/client-backend'; import { ScriptActions } from '../../state/core/script'; import { AuthGuard } from './guards/auth.guard'; import { ModeSelectGuard } from './guards/mode-select.guard'; @@ -23,7 +20,7 @@ import { import { ModelsFacadeService } from './services/models-facade.service'; import { PageRunningScriptSpiningIndicatorService } from './services/page-running-script-spinning-indicator.service'; -export function provideCore(): Provider[] { +export function provideCoreServices(): Provider[] { return [ WebsocketService, AuthGuard, @@ -41,13 +38,6 @@ export function provideCore(): Provider[] { StatisticsFacadeService, PageRunningScriptSpiningIndicatorService, ModelsFacadeService, - { - provide: CLIENT, - useFactory: (httpClient: HttpClient) => { - return new ClientBackend(httpClient); - }, - deps: [HttpClient] - }, { provide: ENVIRONMENT_INITIALIZER, multi: true, diff --git a/frontend/src/app/services/be-services.provide.ts b/frontend/src/app/services/be-services.provide.ts new file mode 100644 index 00000000..9075d9f9 --- /dev/null +++ b/frontend/src/app/services/be-services.provide.ts @@ -0,0 +1,16 @@ +import { HttpClient } from '@angular/common/http'; +import { Provider } from '@angular/core'; +import { ClientBackend } from './client/client-backend'; +import { CLIENT } from './services.tokens'; + +export function provideBEServices(): Provider[] { + return [ + { + provide: CLIENT, + useFactory: (httpClient: HttpClient) => { + return new ClientBackend(httpClient); + }, + deps: [HttpClient] + } + ]; +} diff --git a/frontend/src/app/app.tokens.ts b/frontend/src/app/services/services.tokens.ts similarity index 93% rename from frontend/src/app/app.tokens.ts rename to frontend/src/app/services/services.tokens.ts index 81536c63..7e7375e4 100644 --- a/frontend/src/app/app.tokens.ts +++ b/frontend/src/app/services/services.tokens.ts @@ -15,6 +15,6 @@ // SPDX-License-Identifier: Apache-2.0 import { InjectionToken } from '@angular/core'; -import { Client } from './services/client/client'; +import { Client } from './client/client'; export const CLIENT = new InjectionToken('CLIENT'); diff --git a/frontend/src/app/state/core/auth/auth.effects.ts b/frontend/src/app/state/core/auth/auth.effects.ts index 8161f9ff..8bf58b42 100644 --- a/frontend/src/app/state/core/auth/auth.effects.ts +++ b/frontend/src/app/state/core/auth/auth.effects.ts @@ -19,11 +19,11 @@ import { Router } from '@angular/router'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; import { catchError, filter, map, mergeMap, tap, withLatestFrom } from 'rxjs/operators'; -import { CLIENT } from '../../../app.tokens'; import { RoutesList } from '../../../modules/core/models/enums/routes-list.enum'; import { Client } from '../../../services/client/client'; import { PostLogin } from '../../../services/client/serviceCalls/authenticate/post-login'; import { PostLogout } from '../../../services/client/serviceCalls/user/post-logout'; +import { CLIENT } from '../../../services/services.tokens'; import { AuthActions } from './auth.actions'; import { selectIsAuthenticated } from './auth.selector'; import { AuthState } from './auth.state'; diff --git a/frontend/src/app/state/core/charts/charts.effects.ts b/frontend/src/app/state/core/charts/charts.effects.ts index 80b9c546..244d5c4b 100644 --- a/frontend/src/app/state/core/charts/charts.effects.ts +++ b/frontend/src/app/state/core/charts/charts.effects.ts @@ -17,12 +17,12 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { catchError, map, of, switchMap } from 'rxjs'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetChartConfigurationSettings } from '../../../services/client/serviceCalls/charts/get-chart-configuration-settings'; import { GetCurrentMachineUnlearningChartData } from '../../../services/client/serviceCalls/charts/get-current-machine-unlearning-chart-data copy'; import { GetCurrentPruningChartData } from '../../../services/client/serviceCalls/charts/get-current-pruning-chart-data'; import { GetCurrentQuantizationChartData } from '../../../services/client/serviceCalls/charts/get-current-quantization-chart-data'; +import { CLIENT } from '../../../services/services.tokens'; import { ChartActions } from './charts.actions'; @Injectable() diff --git a/frontend/src/app/state/core/file/file.effects.ts b/frontend/src/app/state/core/file/file.effects.ts index 33d80d5c..7370ddac 100644 --- a/frontend/src/app/state/core/file/file.effects.ts +++ b/frontend/src/app/state/core/file/file.effects.ts @@ -18,10 +18,10 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of } from 'rxjs'; import { catchError, map, switchMap } from 'rxjs/operators'; -import { CLIENT } from '../../../app.tokens'; import { BannerService } from '../../../modules/shared/components/ms-banner/services/banner.service'; import { Client } from '../../../services/client/client'; import { PostUploadModel } from '../../../services/client/serviceCalls/upload-file/post-upload-file'; +import { CLIENT } from '../../../services/services.tokens'; import { ScriptActions } from '../script/script.actions'; import { FileActions } from './file.actions'; diff --git a/frontend/src/app/state/core/models/models.effects.ts b/frontend/src/app/state/core/models/models.effects.ts index 91d2c54a..b379462f 100644 --- a/frontend/src/app/state/core/models/models.effects.ts +++ b/frontend/src/app/state/core/models/models.effects.ts @@ -18,11 +18,11 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { of } from 'rxjs'; import { catchError, map, switchMap } from 'rxjs/operators'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetCurrentOrPreviousSelectedModel } from '../../../services/client/serviceCalls/models/get-current-or-previous-selected-model'; import { GetModelMetadata } from '../../../services/client/serviceCalls/models/get-model-metadata'; import { GetModelsList } from '../../../services/client/serviceCalls/models/get-models-list'; +import { CLIENT } from '../../../services/services.tokens'; import { ModelsActions } from './models.actions'; @Injectable() diff --git a/frontend/src/app/state/core/parameters/parameters.effects.ts b/frontend/src/app/state/core/parameters/parameters.effects.ts index cafb9925..0d58b6d8 100644 --- a/frontend/src/app/state/core/parameters/parameters.effects.ts +++ b/frontend/src/app/state/core/parameters/parameters.effects.ts @@ -18,9 +18,9 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { catchError, map, of, switchMap } from 'rxjs'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetParameters } from '../../../services/client/serviceCalls/parameters/get-parameters'; +import { CLIENT } from '../../../services/services.tokens'; import { ParameterActions } from './parameters.actions'; @Injectable() diff --git a/frontend/src/app/state/core/script/script.effects.ts b/frontend/src/app/state/core/script/script.effects.ts index 0e3cab4e..9d6ace64 100644 --- a/frontend/src/app/state/core/script/script.effects.ts +++ b/frontend/src/app/state/core/script/script.effects.ts @@ -17,12 +17,12 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { catchError, map, of, switchMap } from 'rxjs'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetCurrentOrLastActiveScriptDetails } from '../../../services/client/serviceCalls/script/get-current-or-last-active-script-details'; import { GetScriptStatus } from '../../../services/client/serviceCalls/script/get-script-status'; import { PostRunScript } from '../../../services/client/serviceCalls/script/post-run-script'; import { PostStopScript } from '../../../services/client/serviceCalls/script/post-stop-script'; +import { CLIENT } from '../../../services/services.tokens'; import { ScriptActions } from './script.actions'; @Injectable() diff --git a/frontend/src/app/state/core/statistics/statistics.effects.ts b/frontend/src/app/state/core/statistics/statistics.effects.ts index 29dd7faa..ea997c83 100644 --- a/frontend/src/app/state/core/statistics/statistics.effects.ts +++ b/frontend/src/app/state/core/statistics/statistics.effects.ts @@ -17,9 +17,9 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { catchError, map, of, switchMap } from 'rxjs'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetStatistics } from '../../../services/client/serviceCalls/statistics/get-statistics'; +import { CLIENT } from '../../../services/services.tokens'; import { StatisticsActions } from './statistics.actions'; @Injectable() diff --git a/frontend/src/app/state/core/terminal/terminal.effects.ts b/frontend/src/app/state/core/terminal/terminal.effects.ts index 9b5a7826..a4c1d4f0 100644 --- a/frontend/src/app/state/core/terminal/terminal.effects.ts +++ b/frontend/src/app/state/core/terminal/terminal.effects.ts @@ -17,10 +17,10 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { catchError, map, of, switchMap } from 'rxjs'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetLatestMessages } from '../../../services/client/serviceCalls/terminal/get-latest-messages'; import { PostClearHistory } from '../../../services/client/serviceCalls/terminal/post-clear-history'; +import { CLIENT } from '../../../services/services.tokens'; import { TerminalActions } from './terminal.actions'; @Injectable() diff --git a/frontend/src/app/state/run-records/records/records.effects.ts b/frontend/src/app/state/run-records/records/records.effects.ts index d457fec5..cbbcf56c 100644 --- a/frontend/src/app/state/run-records/records/records.effects.ts +++ b/frontend/src/app/state/run-records/records/records.effects.ts @@ -17,10 +17,10 @@ import { Inject, Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { catchError, map, of, switchMap } from 'rxjs'; -import { CLIENT } from '../../../app.tokens'; import { Client } from '../../../services/client/client'; import { GetRunRecordsFilenames } from '../../../services/client/serviceCalls/run-records/get-run-records-filenames'; import { GetRunRecordsSummarizedData } from '../../../services/client/serviceCalls/run-records/get-run-records-summarized-data'; +import { CLIENT } from '../../../services/services.tokens'; import { RunRecordsActions } from './records.actions'; @Injectable()