Skip to content

Commit 04f5ac1

Browse files
authored
Merge pull request #1636 from SciCatProject/SWAP-4278-new-sdk-frotnend-code-refactor-part-2
fix: adjust types after using the new sdk
2 parents 7947926 + 5863345 commit 04f5ac1

File tree

205 files changed

+1035
-24147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+1035
-24147
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@ngrx/effects": "^16",
3434
"@ngrx/router-store": "^16",
3535
"@ngrx/store": "^16",
36+
"@scicatproject/scicat-sdk-ts": "^4.6.4",
3637
"autolinker": "^4.0.0",
3738
"deep-equal": "^2.0.5",
3839
"exceljs": "^4.3.0",

src/app/app-config.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ export class AppConfigService {
108108

109109
async loadAppConfig(): Promise<void> {
110110
try {
111-
this.appConfig = await this.http
111+
const config = await this.http
112112
.get("/api/v3/admin/config")
113113
.pipe(timeout(2000))
114114
.toPromise();
115+
this.appConfig = Object.assign({}, this.appConfig, config);
115116
} catch (err) {
116117
console.log("No config available in backend, trying with local config.");
117118
try {
118-
this.appConfig = await this.http.get("/assets/config.json").toPromise();
119+
const config = await this.http.get("/assets/config.json").toPromise();
120+
this.appConfig = Object.assign({}, this.appConfig, config);
119121
} catch (err) {
120122
console.error("No config provided.");
121123
}

src/app/app-routing/auth.guard.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ActivatedRouteSnapshot,
66
RouterStateSnapshot,
77
} from "@angular/router";
8-
import { UserApi } from "shared/sdk/services";
8+
import { UsersService } from "@scicatproject/scicat-sdk-ts";
99

1010
/**
1111
* Ensure that the current user is logged in
@@ -19,7 +19,7 @@ import { UserApi } from "shared/sdk/services";
1919
})
2020
export class AuthGuard implements CanActivate {
2121
constructor(
22-
private us: UserApi,
22+
private us: UsersService,
2323
private router: Router,
2424
) {}
2525

@@ -31,7 +31,7 @@ export class AuthGuard implements CanActivate {
3131
state: RouterStateSnapshot,
3232
): Promise<boolean> {
3333
return this.us
34-
.getCurrent()
34+
.usersControllerGetMyUser()
3535
.toPromise()
3636
.catch(() => {
3737
this.router.navigate(["/login"], {

src/app/app.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
ChangeDetectorRef,
1010
} from "@angular/core";
1111
import { Store } from "@ngrx/store";
12-
import { LoopBackConfig } from "shared/sdk";
1312
import {
1413
clearMessageAction,
1514
fetchCurrentUserAction,
@@ -25,6 +24,7 @@ import {
2524
} from "state-management/selectors/user.selectors";
2625
import { MessageType } from "state-management/models";
2726
import { AppConfigService, AppConfig as Config } from "app-config.service";
27+
import { Configuration } from "@scicatproject/scicat-sdk-ts";
2828

2929
@Component({
3030
selector: "app-root",
@@ -45,6 +45,7 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewChecked {
4545
constructor(
4646
@Inject(APP_CONFIG) public appConfig: AppConfig,
4747
private appConfigService: AppConfigService,
48+
private apiConfigService: Configuration,
4849
private cdRef: ChangeDetectorRef,
4950
private metaService: Meta,
5051
public snackBar: MatSnackBar,
@@ -68,8 +69,8 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewChecked {
6869
* @memberof AppComponent
6970
*/
7071
ngOnInit() {
71-
LoopBackConfig.setBaseURL(this.config.lbBaseURL);
72-
console.log(LoopBackConfig.getPath());
72+
this.apiConfigService.basePath = this.config.lbBaseURL;
73+
console.log(this.apiConfigService.basePath);
7374

7475
this.store.dispatch(loadDefaultSettings({ config: this.config }));
7576

src/app/app.module.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { EffectsModule } from "@ngrx/effects";
88
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
99
import { APP_INITIALIZER, NgModule } from "@angular/core";
1010
import { ExtraOptions, RouterModule } from "@angular/router";
11-
import { SampleApi, SDKBrowserModule } from "shared/sdk/index";
1211
import { StoreModule } from "@ngrx/store";
13-
import { UserApi } from "shared/sdk/services";
12+
import { ApiModule, Configuration } from "@scicatproject/scicat-sdk-ts";
1413
import { routerReducer } from "@ngrx/router-store";
1514
import { extModules } from "./build-specifics";
1615
import { MatNativeDateModule } from "@angular/material/core";
@@ -38,6 +37,15 @@ const appThemeInitializerFn = (appTheme: AppThemeService) => {
3837
return () => appTheme.loadTheme();
3938
};
4039

40+
const apiConfigurationFn = (
41+
authService: AuthService,
42+
configurationService: AppConfigService,
43+
) =>
44+
new Configuration({
45+
basePath: configurationService.getConfig().lbBaseURL,
46+
accessToken: authService.getToken().id,
47+
});
48+
4149
@NgModule({
4250
declarations: [AppComponent],
4351
imports: [
@@ -52,7 +60,7 @@ const appThemeInitializerFn = (appTheme: AppThemeService) => {
5260
MatTabsModule,
5361
MatChipsModule,
5462
MatSnackBarModule,
55-
SDKBrowserModule.forRoot(),
63+
ApiModule,
5664
StoreModule.forRoot(
5765
{ router: routerReducer, users: userReducer },
5866
{
@@ -98,12 +106,16 @@ const appThemeInitializerFn = (appTheme: AppThemeService) => {
98106
},
99107
AuthService,
100108
AppThemeService,
101-
UserApi,
102-
SampleApi,
103109
Title,
104110
MatNativeDateModule,
105111
{ provide: InternalStorage, useClass: CookieService },
106112
{ provide: SDKStorage, useClass: CookieService },
113+
{
114+
provide: Configuration,
115+
useFactory: apiConfigurationFn,
116+
deps: [AuthService, AppConfigService],
117+
multi: false,
118+
},
107119
],
108120
bootstrap: [AppComponent],
109121
})

src/app/datasets/admin-tab/admin-tab.component.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { ComponentFixture, inject, TestBed } from "@angular/core/testing";
1+
import { TestBed } from "@angular/core/testing";
22
import { Store, StoreModule } from "@ngrx/store";
3-
import { Dataset } from "shared/sdk";
43
import { AdminTabComponent } from "./admin-tab.component";
54
import { MatCardModule } from "@angular/material/card";
65
import { of } from "rxjs";

src/app/datasets/admin-tab/admin-tab.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Store } from "@ngrx/store";
33
import { FileObject } from "datasets/dataset-details-dashboard/dataset-details-dashboard.component";
44
import { Subscription } from "rxjs";
55
import { take } from "rxjs/operators";
6-
import { Dataset, Job } from "shared/sdk";
6+
import { DatasetClass, JobClass } from "@scicatproject/scicat-sdk-ts";
77
import { submitJobAction } from "state-management/actions/jobs.actions";
88
import {
99
selectCurrentDatablocks,
@@ -22,7 +22,7 @@ import {
2222
})
2323
export class AdminTabComponent implements OnInit, OnDestroy {
2424
private subscriptions: Subscription[] = [];
25-
dataset: Dataset | undefined;
25+
dataset: DatasetClass | undefined;
2626
datablocks$ = this.store.select(selectCurrentDatablocks);
2727
isAdmin$ = this.store.select(selectIsAdmin);
2828
loading$ = this.store.select(selectIsLoading);
@@ -44,11 +44,11 @@ export class AdminTabComponent implements OnInit, OnDestroy {
4444
.pipe(take(1))
4545
.subscribe((user) => {
4646
if (user && this.dataset) {
47-
const job = new Job();
47+
let job: JobClass;
4848
job.emailJobInitiator = user.email;
4949
job.jobParams = {};
5050
job.jobParams["username"] = user.username;
51-
job.creationTime = new Date();
51+
job.creationTime = new Date().toString();
5252
job.type = "reset";
5353
const fileObj: FileObject = {
5454
pid: "",
@@ -62,7 +62,7 @@ export class AdminTabComponent implements OnInit, OnDestroy {
6262
});
6363
}
6464
fileObj.files = fileList;
65-
job.datasetList = [fileObj];
65+
job.datasetList = [fileObj.toString()];
6666
console.log(job);
6767
this.store.dispatch(submitJobAction({ job }));
6868
}

src/app/datasets/archiving.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TestBed, waitForAsync } from "@angular/core/testing";
22
import { MockStore, provideMockStore } from "@ngrx/store/testing";
33
import { RetrieveDestinations } from "app-config.service";
4-
import { Dataset, Job, User } from "shared/sdk";
4+
import { Dataset, Job, User } from "@scicatproject/scicat-sdk-ts";
55
import { submitJobAction } from "state-management/actions/jobs.actions";
66
import {
77
selectCurrentUser,

src/app/datasets/archiving.service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { Injectable } from "@angular/core";
22
import { Store } from "@ngrx/store";
33
import { combineLatest, Observable } from "rxjs";
44
import { first, map } from "rxjs/operators";
5-
import { Dataset, Job, User } from "state-management/models";
65
import { submitJobAction } from "state-management/actions/jobs.actions";
76
import {
87
selectCurrentUser,
98
selectTapeCopies,
109
selectProfile,
1110
} from "state-management/selectors/user.selectors";
1211
import { RetrieveDestinations } from "app-config.service";
12+
import { DatasetClass, ReturnedUserDto } from "@scicatproject/scicat-sdk-ts";
1313

1414
@Injectable()
1515
export class ArchivingService {
@@ -19,12 +19,12 @@ export class ArchivingService {
1919
constructor(private store: Store) {}
2020

2121
private createJob(
22-
user: User,
23-
datasets: Dataset[],
22+
user: ReturnedUserDto,
23+
datasets: DatasetClass[],
2424
archive: boolean,
2525
destinationPath?: Record<string, string>,
2626
// Do not specify tape copies here
27-
): Job {
27+
) {
2828
const extra = archive ? {} : destinationPath;
2929
const jobParams = {
3030
username: user.username,
@@ -46,11 +46,11 @@ export class ArchivingService {
4646
type: archive ? "archive" : "retrieve",
4747
};
4848

49-
return new Job(data);
49+
return data;
5050
}
5151

5252
private archiveOrRetrieve(
53-
datasets: Dataset[],
53+
datasets: DatasetClass[],
5454
archive: boolean,
5555
destPath?: Record<string, string>,
5656
): Observable<void> {
@@ -71,18 +71,18 @@ export class ArchivingService {
7171

7272
const job = this.createJob(user, datasets, archive, destPath);
7373

74-
this.store.dispatch(submitJobAction({ job }));
74+
this.store.dispatch(submitJobAction({ job: job as any }));
7575
}
7676
}),
7777
);
7878
}
7979

80-
public archive(datasets: Dataset[]): Observable<void> {
80+
public archive(datasets: DatasetClass[]): Observable<void> {
8181
return this.archiveOrRetrieve(datasets, true);
8282
}
8383

8484
public retrieve(
85-
datasets: Dataset[],
85+
datasets: DatasetClass[],
8686
destinationPath: Record<string, string>,
8787
): Observable<void> {
8888
return this.archiveOrRetrieve(datasets, false, destinationPath);

0 commit comments

Comments
 (0)