Skip to content

Commit 8742b98

Browse files
retriving single model when accesing model info (#974)
* retriving single model when accesing model info * Fixed spelling mistake
1 parent bc9698b commit 8742b98

File tree

9 files changed

+55
-41
lines changed

9 files changed

+55
-41
lines changed

ui/src/app/core/model/model.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export class ModelService {
4444
);
4545
}
4646

47+
getModel(applicationId: string, currentModelId: string): Observable<Model> {
48+
return this.http.get<Model>(`${environment.adminApiUrl}app/${applicationId}/model/${currentModelId}`);
49+
}
50+
4751
getAll(applicationId: string): Observable<Model[]> {
4852
return this.http
4953
.get<Model[]>(`${environment.adminApiUrl}app/${applicationId}/models`)

ui/src/app/features/model-info/model-info.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { Component, OnDestroy, OnInit } from '@angular/core';
18-
import { ActivatedRoute } from '@angular/router';
1918
import { Observable, Subscription } from 'rxjs';
2019
import { shareReplay } from 'rxjs/operators';
2120
import { ServiceTypes } from 'src/app/data/enums/service-types.enum';
@@ -34,17 +33,13 @@ export class ModelInfoComponent implements OnInit, OnDestroy {
3433
recognition = ServiceTypes.Recognition;
3534
statistics$: Observable<Statistics[]>;
3635

37-
constructor(private modelInfoFacade: ModelInfoFacade, private route: ActivatedRoute) {
36+
constructor(private modelInfoFacade: ModelInfoFacade) {
3837
this.statistics$ = this.modelInfoFacade.statistics$.pipe(shareReplay());
3938
}
4039

4140
ngOnInit(): void {
42-
const modelId = this.route.snapshot.queryParams.model;
43-
const app = this.route.snapshot.queryParams.app;
44-
4541
this.modelInfoFacade.statistics$.subscribe();
4642

47-
this.modelInfoFacade.loadModels(app, modelId);
4843
this.subs = this.modelInfoFacade.currentModel$.subscribe(model => (this.currentModel = model));
4944
}
5045

ui/src/app/features/model-info/model-info.facade.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import { filter } from 'rxjs/operators';
2121
import { Application } from 'src/app/data/interfaces/application';
2222
import { Model } from 'src/app/data/interfaces/model';
2323
import { Statistics } from 'src/app/data/interfaces/statistics';
24-
import { selectCurrentApp } from 'src/app/store/application/selectors';
25-
import { loadModels, setSelectedModelIdEntityAction } from 'src/app/store/model/action';
24+
import { loadModel, setSelectedModelIdEntityAction } from 'src/app/store/model/action';
2625
import { selectCurrentModel } from 'src/app/store/model/selectors';
2726
import { loadModelStatistics } from 'src/app/store/statistics/actions';
2827
import { selectModelStatistics } from 'src/app/store/statistics/selectors';
@@ -37,10 +36,4 @@ export class ModelInfoFacade {
3736
this.currentModel$ = this.store.select(selectCurrentModel).pipe(filter(model => !!model));
3837
this.statistics$ = this.store.select(selectModelStatistics).pipe(filter(data => !!data[0]));
3938
}
40-
41-
loadModels(applicationId: string, selectedModelId: string): void {
42-
this.store.dispatch(loadModels({ applicationId }));
43-
this.store.dispatch(setSelectedModelIdEntityAction({ selectedModelId }));
44-
this.store.dispatch(loadModelStatistics({ appId: applicationId, modelId: selectedModelId }));
45-
}
4639
}

ui/src/app/features/password-recovery-dialog/password-recovery.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h1 mat-dialog-title class="dialog__header--title">{{ 'recovery.password_recover
3636
{{ 'common.capital.cancel' | translate | titlecase }}
3737
</button>
3838
<button type="submit" [mat-dialog-close]="email" class="save-btn" [disabled]="!form.valid">
39-
{{ 'common.capital.create' | translate | titlecase }}
39+
{{ 'common.capital.submit' | translate | titlecase }}
4040
</button>
4141
</div>
4242
</form>

ui/src/app/pages/manage-collection/manage-collection.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Store } from '@ngrx/store';
1919

2020
import { loadApplications, setSelectedAppIdEntityAction } from '../../store/application/action';
2121
import { getUserInfo } from '../../store/userInfo/action';
22-
import { loadModels, setSelectedModelIdEntityAction } from '../../store/model/action';
22+
import { loadModel, setSelectedModelIdEntityAction } from '../../store/model/action';
2323
import { Routes } from '../../data/enums/routers-url.enum';
2424
import { resetSubjects } from '../../store/manage-collectiom/action';
2525

@@ -35,7 +35,7 @@ export class ManageCollectionPageService {
3535
this.modelId = this.route.snapshot.queryParams.model;
3636

3737
if (this.appId && this.modelId) {
38-
this.store.dispatch(loadModels({ applicationId: this.appId }));
38+
this.store.dispatch(loadModel({ applicationId: this.appId, selectedModelId: this.modelId }));
3939
this.store.dispatch(setSelectedAppIdEntityAction({ selectedAppId: this.appId }));
4040
this.store.dispatch(setSelectedModelIdEntityAction({ selectedModelId: this.modelId }));
4141
this.store.dispatch(loadApplications());

ui/src/app/store/auth/effects.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class AuthEffects {
6767
ofType(logIn),
6868
switchMap(action =>
6969
this.authService.logIn(action.email, action.password, GranTypes.Password).pipe(
70-
tap(() => 'from login'),
7170
map(() => logInSuccess()),
7271
catchError(error => observableOf(logInFail(error)))
7372
)
@@ -136,9 +135,7 @@ export class AuthEffects {
136135
ofType(signUpSuccess),
137136
withLatestFrom(this.store.select(selectMailStatus)),
138137
map(([action, mailStatus]) =>
139-
mailStatus.mailServiceEnabled
140-
? this.store.dispatch(confirmEmailMessage())
141-
: this.store.dispatch(logIn({ email: action.email, password: action.password }))
138+
mailStatus.mailServiceEnabled ? confirmEmailMessage() : logIn({ email: action.email, password: action.password })
142139
)
143140
);
144141

ui/src/app/store/model/action.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import { createAction, props } from '@ngrx/store';
1818
import { Model, ModelUpdate } from 'src/app/data/interfaces/model';
1919

20+
export const loadModel = createAction('[Model] Load Model', props<{ applicationId: string; selectedModelId: string }>());
21+
export const loadModelSuccess = createAction('[Model] Load Model Success', props<{ model: Model }>());
22+
export const loadModelFail = createAction('[Model] Load Model Fail', props<{ error: any }>());
23+
2024
export const loadModels = createAction('[Model] Load Models', props<{ applicationId: string }>());
2125
export const loadModelsSuccess = createAction('[Model] Load Models Success', props<{ models: Model[] }>());
2226
export const loadModelsFail = createAction('[Model] Load Models Fail', props<{ error: any }>());

ui/src/app/store/model/effects.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import {
3838
updateModel,
3939
updateModelFail,
4040
updateModelSuccess,
41+
loadModel,
42+
loadModelFail,
43+
loadModelSuccess,
4144
} from './action';
4245
import { ServiceTypes } from 'src/app/data/enums/service-types.enum';
4346
import { Store } from '@ngrx/store';
@@ -51,7 +54,18 @@ export class ModelEffects {
5154
private snackBarService: SnackBarService,
5255
private router: Router,
5356
private store: Store<any>
54-
) { }
57+
) {}
58+
59+
@Effect()
60+
loadModel$ = this.actions.pipe(
61+
ofType(loadModel),
62+
switchMap(action =>
63+
this.modelService.getModel(action.applicationId, action.selectedModelId).pipe(
64+
map(model => loadModelSuccess({ model })),
65+
catchError(error => of(loadModelFail({ error })))
66+
)
67+
)
68+
);
5569

5670
@Effect()
5771
loadModels$ = this.actions.pipe(
@@ -69,8 +83,8 @@ export class ModelEffects {
6983
@Effect()
7084
createModel$ = this.actions.pipe(
7185
ofType(createModel),
72-
tap(({ model }) => this.isFirtsService = model.isFirstService),
73-
switchMap((action) =>
86+
tap(({ model }) => (this.isFirtsService = model.isFirstService)),
87+
switchMap(action =>
7488
this.modelService.create(action.model.applicationId, action.model.name, action.model.type).pipe(
7589
map(model => createModelSuccess({ model })),
7690
catchError(error => of(createModelFail({ error })))
@@ -83,24 +97,25 @@ export class ModelEffects {
8397
ofType(createModelSuccess),
8498
withLatestFrom(this.store.select(selectCurrentApp)),
8599
tap(([{ model }, app]) => {
86-
if(this.isFirtsService){
87-
model.type === ServiceTypes.Recognition ?
88-
this.router.navigate([Routes.ManageCollection], {
89-
queryParams: {
90-
app: app.id,
91-
model: model.id,
92-
type: model.type,
93-
},
94-
}) : this.router.navigate([Routes.TestModel], {
95-
queryParams: {
96-
app: app.id,
97-
model: model.id,
98-
type: model.type,
99-
},
100-
});
100+
if (this.isFirtsService) {
101+
model.type === ServiceTypes.Recognition
102+
? this.router.navigate([Routes.ManageCollection], {
103+
queryParams: {
104+
app: app.id,
105+
model: model.id,
106+
type: model.type,
107+
},
108+
})
109+
: this.router.navigate([Routes.TestModel], {
110+
queryParams: {
111+
app: app.id,
112+
model: model.id,
113+
type: model.type,
114+
},
115+
});
101116
}
102117
})
103-
)
118+
);
104119

105120
@Effect()
106121
updateModel$ = this.actions.pipe(

ui/src/app/store/model/reducers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
updateModel,
3535
updateModelFail,
3636
updateModelSuccess,
37+
loadModelFail,
38+
loadModelSuccess,
3739
} from './action';
3840

3941
export interface ModelEntityState extends EntityState<Model> {
@@ -51,8 +53,12 @@ const initialState: ModelEntityState = modelAdapter.getInitialState({
5153
const reducer: ActionReducer<ModelEntityState> = createReducer(
5254
initialState,
5355
on(loadModels, createModel, cloneModel, updateModel, deleteModel, state => ({ ...state, isPending: true })),
54-
on(loadModelsFail, createModelFail, cloneModelFail, updateModelFail, deleteModelFail, state => ({ ...state, isPending: false })),
56+
on(loadModelFail, loadModelsFail, createModelFail, cloneModelFail, updateModelFail, deleteModelFail, state => ({
57+
...state,
58+
isPending: false,
59+
})),
5560
on(loadModelsSuccess, (state, { models }) => modelAdapter.setAll(models, { ...state, isPending: false })),
61+
on(loadModelSuccess, (state, { model }) => modelAdapter.upsertOne(model, state)),
5662
on(createModelSuccess, cloneModelSuccess, (state, { model }) => modelAdapter.addOne(model, { ...state, isPending: false })),
5763
on(updateModelSuccess, (state, { model }) => modelAdapter.updateOne({ id: model.id, changes: model }, { ...state, isPending: false })),
5864
on(deleteModelSuccess, (state, { modelId }) => modelAdapter.removeOne(modelId, { ...state, isPending: false })),

0 commit comments

Comments
 (0)