Skip to content

Commit

Permalink
Merge pull request #1636 from SciCatProject/SWAP-4278-new-sdk-frotnen…
Browse files Browse the repository at this point in the history
…d-code-refactor-part-2

fix: adjust types after using the new sdk
  • Loading branch information
nitrosx authored Nov 5, 2024
2 parents 7947926 + 5863345 commit 04f5ac1
Show file tree
Hide file tree
Showing 205 changed files with 1,035 additions and 24,147 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@ngrx/effects": "^16",
"@ngrx/router-store": "^16",
"@ngrx/store": "^16",
"@scicatproject/scicat-sdk-ts": "^4.6.4",
"autolinker": "^4.0.0",
"deep-equal": "^2.0.5",
"exceljs": "^4.3.0",
Expand Down
6 changes: 4 additions & 2 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ export class AppConfigService {

async loadAppConfig(): Promise<void> {
try {
this.appConfig = await this.http
const config = await this.http
.get("/api/v3/admin/config")
.pipe(timeout(2000))
.toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {
console.log("No config available in backend, trying with local config.");
try {
this.appConfig = await this.http.get("/assets/config.json").toPromise();
const config = await this.http.get("/assets/config.json").toPromise();
this.appConfig = Object.assign({}, this.appConfig, config);
} catch (err) {
console.error("No config provided.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/app-routing/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ActivatedRouteSnapshot,
RouterStateSnapshot,
} from "@angular/router";
import { UserApi } from "shared/sdk/services";
import { UsersService } from "@scicatproject/scicat-sdk-ts";

/**
* Ensure that the current user is logged in
Expand All @@ -19,7 +19,7 @@ import { UserApi } from "shared/sdk/services";
})
export class AuthGuard implements CanActivate {
constructor(
private us: UserApi,
private us: UsersService,
private router: Router,
) {}

Expand All @@ -31,7 +31,7 @@ export class AuthGuard implements CanActivate {
state: RouterStateSnapshot,
): Promise<boolean> {
return this.us
.getCurrent()
.usersControllerGetMyUser()
.toPromise()
.catch(() => {
this.router.navigate(["/login"], {
Expand Down
7 changes: 4 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ChangeDetectorRef,
} from "@angular/core";
import { Store } from "@ngrx/store";
import { LoopBackConfig } from "shared/sdk";
import {
clearMessageAction,
fetchCurrentUserAction,
Expand All @@ -25,6 +24,7 @@ import {
} from "state-management/selectors/user.selectors";
import { MessageType } from "state-management/models";
import { AppConfigService, AppConfig as Config } from "app-config.service";
import { Configuration } from "@scicatproject/scicat-sdk-ts";

@Component({
selector: "app-root",
Expand All @@ -45,6 +45,7 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewChecked {
constructor(
@Inject(APP_CONFIG) public appConfig: AppConfig,
private appConfigService: AppConfigService,
private apiConfigService: Configuration,
private cdRef: ChangeDetectorRef,
private metaService: Meta,
public snackBar: MatSnackBar,
Expand All @@ -68,8 +69,8 @@ export class AppComponent implements OnDestroy, OnInit, AfterViewChecked {
* @memberof AppComponent
*/
ngOnInit() {
LoopBackConfig.setBaseURL(this.config.lbBaseURL);
console.log(LoopBackConfig.getPath());
this.apiConfigService.basePath = this.config.lbBaseURL;
console.log(this.apiConfigService.basePath);

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

Expand Down
22 changes: 17 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { EffectsModule } from "@ngrx/effects";
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { APP_INITIALIZER, NgModule } from "@angular/core";
import { ExtraOptions, RouterModule } from "@angular/router";
import { SampleApi, SDKBrowserModule } from "shared/sdk/index";
import { StoreModule } from "@ngrx/store";
import { UserApi } from "shared/sdk/services";
import { ApiModule, Configuration } from "@scicatproject/scicat-sdk-ts";
import { routerReducer } from "@ngrx/router-store";
import { extModules } from "./build-specifics";
import { MatNativeDateModule } from "@angular/material/core";
Expand Down Expand Up @@ -38,6 +37,15 @@ const appThemeInitializerFn = (appTheme: AppThemeService) => {
return () => appTheme.loadTheme();
};

const apiConfigurationFn = (
authService: AuthService,
configurationService: AppConfigService,
) =>
new Configuration({
basePath: configurationService.getConfig().lbBaseURL,
accessToken: authService.getToken().id,
});

@NgModule({
declarations: [AppComponent],
imports: [
Expand All @@ -52,7 +60,7 @@ const appThemeInitializerFn = (appTheme: AppThemeService) => {
MatTabsModule,
MatChipsModule,
MatSnackBarModule,
SDKBrowserModule.forRoot(),
ApiModule,
StoreModule.forRoot(
{ router: routerReducer, users: userReducer },
{
Expand Down Expand Up @@ -98,12 +106,16 @@ const appThemeInitializerFn = (appTheme: AppThemeService) => {
},
AuthService,
AppThemeService,
UserApi,
SampleApi,
Title,
MatNativeDateModule,
{ provide: InternalStorage, useClass: CookieService },
{ provide: SDKStorage, useClass: CookieService },
{
provide: Configuration,
useFactory: apiConfigurationFn,
deps: [AuthService, AppConfigService],
multi: false,
},
],
bootstrap: [AppComponent],
})
Expand Down
3 changes: 1 addition & 2 deletions src/app/datasets/admin-tab/admin-tab.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ComponentFixture, inject, TestBed } from "@angular/core/testing";
import { TestBed } from "@angular/core/testing";
import { Store, StoreModule } from "@ngrx/store";
import { Dataset } from "shared/sdk";
import { AdminTabComponent } from "./admin-tab.component";
import { MatCardModule } from "@angular/material/card";
import { of } from "rxjs";
Expand Down
10 changes: 5 additions & 5 deletions src/app/datasets/admin-tab/admin-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store } from "@ngrx/store";
import { FileObject } from "datasets/dataset-details-dashboard/dataset-details-dashboard.component";
import { Subscription } from "rxjs";
import { take } from "rxjs/operators";
import { Dataset, Job } from "shared/sdk";
import { DatasetClass, JobClass } from "@scicatproject/scicat-sdk-ts";
import { submitJobAction } from "state-management/actions/jobs.actions";
import {
selectCurrentDatablocks,
Expand All @@ -22,7 +22,7 @@ import {
})
export class AdminTabComponent implements OnInit, OnDestroy {
private subscriptions: Subscription[] = [];
dataset: Dataset | undefined;
dataset: DatasetClass | undefined;
datablocks$ = this.store.select(selectCurrentDatablocks);
isAdmin$ = this.store.select(selectIsAdmin);
loading$ = this.store.select(selectIsLoading);
Expand All @@ -44,11 +44,11 @@ export class AdminTabComponent implements OnInit, OnDestroy {
.pipe(take(1))
.subscribe((user) => {
if (user && this.dataset) {
const job = new Job();
let job: JobClass;
job.emailJobInitiator = user.email;
job.jobParams = {};
job.jobParams["username"] = user.username;
job.creationTime = new Date();
job.creationTime = new Date().toString();
job.type = "reset";
const fileObj: FileObject = {
pid: "",
Expand All @@ -62,7 +62,7 @@ export class AdminTabComponent implements OnInit, OnDestroy {
});
}
fileObj.files = fileList;
job.datasetList = [fileObj];
job.datasetList = [fileObj.toString()];
console.log(job);
this.store.dispatch(submitJobAction({ job }));
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/archiving.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed, waitForAsync } from "@angular/core/testing";
import { MockStore, provideMockStore } from "@ngrx/store/testing";
import { RetrieveDestinations } from "app-config.service";
import { Dataset, Job, User } from "shared/sdk";
import { Dataset, Job, User } from "@scicatproject/scicat-sdk-ts";
import { submitJobAction } from "state-management/actions/jobs.actions";
import {
selectCurrentUser,
Expand Down
18 changes: 9 additions & 9 deletions src/app/datasets/archiving.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Injectable } from "@angular/core";
import { Store } from "@ngrx/store";
import { combineLatest, Observable } from "rxjs";
import { first, map } from "rxjs/operators";
import { Dataset, Job, User } from "state-management/models";
import { submitJobAction } from "state-management/actions/jobs.actions";
import {
selectCurrentUser,
selectTapeCopies,
selectProfile,
} from "state-management/selectors/user.selectors";
import { RetrieveDestinations } from "app-config.service";
import { DatasetClass, ReturnedUserDto } from "@scicatproject/scicat-sdk-ts";

@Injectable()
export class ArchivingService {
Expand All @@ -19,12 +19,12 @@ export class ArchivingService {
constructor(private store: Store) {}

private createJob(
user: User,
datasets: Dataset[],
user: ReturnedUserDto,
datasets: DatasetClass[],
archive: boolean,
destinationPath?: Record<string, string>,
// Do not specify tape copies here
): Job {
) {
const extra = archive ? {} : destinationPath;
const jobParams = {
username: user.username,
Expand All @@ -46,11 +46,11 @@ export class ArchivingService {
type: archive ? "archive" : "retrieve",
};

return new Job(data);
return data;
}

private archiveOrRetrieve(
datasets: Dataset[],
datasets: DatasetClass[],
archive: boolean,
destPath?: Record<string, string>,
): Observable<void> {
Expand All @@ -71,18 +71,18 @@ export class ArchivingService {

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

this.store.dispatch(submitJobAction({ job }));
this.store.dispatch(submitJobAction({ job: job as any }));
}
}),
);
}

public archive(datasets: Dataset[]): Observable<void> {
public archive(datasets: DatasetClass[]): Observable<void> {
return this.archiveOrRetrieve(datasets, true);
}

public retrieve(
datasets: Dataset[],
datasets: DatasetClass[],
destinationPath: Record<string, string>,
): Observable<void> {
return this.archiveOrRetrieve(datasets, false, destinationPath);
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/batch-view/batch-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatIconModule } from "@angular/material/icon";
import { MatButtonModule } from "@angular/material/button";

import { MatDialogModule } from "@angular/material/dialog";
import { DatasetApi, Dataset } from "shared/sdk";
import { DatasetApi, Dataset } from "@scicatproject/scicat-sdk-ts";
import { SharedScicatFrontendModule } from "shared/shared.module";
import { MatTableModule } from "@angular/material/table";
import { MockStore, provideMockStore } from "@ngrx/store/testing";
Expand Down
11 changes: 6 additions & 5 deletions src/app/datasets/batch-view/batch-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
removeFromBatchAction,
storeBatchAction,
} from "state-management/actions/datasets.actions";
import { Dataset, Message, MessageType } from "state-management/models";
import { Message, MessageType } from "state-management/models";
import { showMessageAction } from "state-management/actions/user.actions";
import { DialogComponent } from "shared/modules/dialog/dialog.component";

Expand All @@ -24,14 +24,15 @@ import {
selectIsAdmin,
selectProfile,
} from "state-management/selectors/user.selectors";
import { DatasetClass } from "@scicatproject/scicat-sdk-ts";

@Component({
selector: "batch-view",
templateUrl: "./batch-view.component.html",
styleUrls: ["./batch-view.component.scss"],
})
export class BatchViewComponent implements OnInit, OnDestroy {
batch$: Observable<Dataset[]> = this.store.select(selectDatasetsInBatch);
batch$: Observable<DatasetClass[]> = this.store.select(selectDatasetsInBatch);
userProfile$ = this.store.select(selectProfile);
isAdmin$ = this.store.select(selectIsAdmin);
isAdmin = false;
Expand All @@ -41,7 +42,7 @@ export class BatchViewComponent implements OnInit, OnDestroy {
appConfig = this.appConfigService.getConfig();
shareEnabled = this.appConfig.shareEnabled;

datasetList: Dataset[] = [];
datasetList: DatasetClass[] = [];
public hasBatch = false;
visibleColumns: string[] = ["remove", "pid", "sourceFolder", "creationTime"];

Expand All @@ -57,7 +58,7 @@ export class BatchViewComponent implements OnInit, OnDestroy {
this.store.dispatch(clearBatchAction());
}

private storeBatch(datasetUpdatedBatch: Dataset[]) {
private storeBatch(datasetUpdatedBatch: DatasetClass[]) {
this.store.dispatch(storeBatchAction({ batch: datasetUpdatedBatch }));
}

Expand All @@ -69,7 +70,7 @@ export class BatchViewComponent implements OnInit, OnDestroy {
}
}

onRemove(dataset: Dataset) {
onRemove(dataset: DatasetClass) {
this.store.dispatch(removeFromBatchAction({ dataset }));
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/dashboard/dashboard.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
addDatasetAction,
changePageAction,
} from "state-management/actions/datasets.actions";
import { User, Dataset, DerivedDataset } from "shared/sdk";
import { User, Dataset, DerivedDataset } from "@scicatproject/scicat-sdk-ts";
import {
selectColumnAction,
deselectColumnAction,
Expand Down
Loading

0 comments on commit 04f5ac1

Please sign in to comment.