Commit 30b581e2 authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

refactor: apply abstract base service and new subscribe when needed

parent 43e768b7
......@@ -202,7 +202,7 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
).pipe(
tap(deleteSubResourceWithSuccess => {
if (deleteSubResourceWithSuccess) {
super.delete(ctx, action).subscribe();
this.subscribe(super.delete(ctx, action));
} else {
super.deleteFail(ctx, action as any);
}
......
......@@ -12,7 +12,6 @@ import {
AlternativeDepositPersonWrapper,
DepositPersonAlternativeDialog,
} from "@deposit/components/dialogs/deposit-person-alternative/deposit-person-alternative.dialog";
import {DepositDataFileAction} from "@deposit/stores/data-file/deposit-data-file.action";
import {Person} from "@models";
import {
Actions,
......@@ -28,11 +27,9 @@ import {tap} from "rxjs/operators";
import {
isEmptyArray,
isNullOrUndefined,
isTrue,
MemoizedUtil,
ModelFormControlEvent,
NotificationService,
ofSolidifyActionCompleted,
StoreUtil,
} from "solidify-frontend";
......
......@@ -556,7 +556,7 @@ export class DepositDetailEditRoutable extends AbstractDetailEditRoutable<Deposi
this.subscribe(this.currentObs.pipe(
take(1),
tap(deposit => {
this._dialog.open(DepositRejectDialog, {
this.subscribe(this._dialog.open(DepositRejectDialog, {
minWidth: "500px",
}).afterClosed().pipe(
take(1),
......@@ -566,7 +566,7 @@ export class DepositDetailEditRoutable extends AbstractDetailEditRoutable<Deposi
}
this._store.dispatch(new DepositAction.Reject(deposit, message));
}),
).subscribe();
));
}),
));
}
......
......@@ -115,7 +115,6 @@ import {
MARK_AS_TRANSLATABLE,
MemoizedUtil,
NotificationService,
ObjectUtil,
ofSolidifyActionCompleted,
OverrideDefaultAction,
PollingHelper,
......@@ -863,23 +862,23 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
file: action.file,
} as DlcmFileUploadWrapper);
StoreUtil.waitForSubActionCompletion(this.actions$,
this.subscribe(StoreUtil.waitForSubActionCompletion(this.actions$,
actionUploadDataFile,
DepositAction.UploadDataFileSuccess,
DepositUploadAction.UploadFileSuccess,
resultAction => {
const actionUploadDatafileSuccess = resultAction.depositDataFile[0];
const actionUploadDatafileSuccess = resultAction.solidifyFile;
ctx.patchState({
dataFileLogo: actionUploadDatafileSuccess,
});
ctx.dispatch(new DepositAction.UploadPhotoSuccess(resultAction as any));
}).subscribe();
}));
StoreUtil.waitForSubActionCompletion(this.actions$,
this.subscribe(StoreUtil.waitForSubActionCompletion(this.actions$,
actionUploadDataFile,
DepositAction.UploadDataFileFail,
DepositUploadAction.UploadFileFail,
resultAction => {
ctx.dispatch(new DepositAction.UploadPhotoFail(resultAction as any));
}).subscribe();
}));
return ctx.dispatch(actionUploadDataFile);
}
......@@ -927,7 +926,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
continueUntil: () => !isReady,
actionToDo: () => {
const url = `${this._urlResource}/${depositId}/${ApiResourceNameEnum.DATAFILE}/${datafileId}`;
this.apiService.getByIdInPath(url)
this.subscribe(this.apiService.getByIdInPath(url)
.pipe(
tap((result: DataFile) => {
if (result.status === Enums.DataFile.StatusEnum.READY) {
......@@ -948,7 +947,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
ctx.dispatch(new DepositAction.GetPhotoFail(action));
throw new SolidifyStateError(this, e);
}),
).subscribe();
));
},
});
}
......@@ -958,7 +957,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
let headers = new HttpHeaders();
headers = headers.set("Content-Disposition", "attachment; filename=logo");
this._httpClient.get(url, {
this.subscribe(this._httpClient.get(url, {
headers,
responseType: "blob",
}).pipe(
......@@ -969,7 +968,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
ctx.dispatch(new DepositAction.GetPhotoFail(action));
throw new SolidifyStateError(this, e);
}),
).subscribe();
));
}
@OverrideDefaultAction()
......
......@@ -18,6 +18,7 @@ import {
tap,
} from "rxjs/operators";
import {
AbstractBaseService,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
MemoizedUtil,
......@@ -27,11 +28,12 @@ import {
@Injectable({
providedIn: "root",
})
export class ArchiveAccessRightService {
export class ArchiveAccessRightService extends AbstractBaseService {
constructor(private readonly _dialog: MatDialog,
private readonly _store: Store,
private readonly _securityService: SecurityService,
private readonly _oauthService: OAuth2Service) {
super();
}
isAccessControlled(archive: Archive): boolean {
......@@ -94,7 +96,7 @@ export class ArchiveAccessRightService {
}
openRequestArchiveDialog(archiveId: string, archiveOrgUnitId: string): void {
this._dialog.open(HomeArchiveRestrictedRequestAccessDialog, {
this.subscribe(this._dialog.open(HomeArchiveRestrictedRequestAccessDialog, {
minWidth: "500px",
}).afterClosed().pipe(
take(1),
......@@ -104,7 +106,7 @@ export class ArchiveAccessRightService {
}
this.sendRequestAccessDataset(archiveId, archiveOrgUnitId, message);
}),
).subscribe();
));
}
isPublicMetadata(archive: Archive): boolean {
......
......@@ -7,11 +7,12 @@ import {
import {WINDOW} from "@app/app.module";
import {TwitterMetadata} from "@app/features/home/models/twitter-metadata.model";
import {Observable} from "rxjs";
import {AbstractBaseService} from "solidify-frontend";
@Injectable({
providedIn: "root",
})
export class TwitterService {
export class TwitterService extends AbstractBaseService {
private readonly _TWITTER_SCRIPT_ID: string = "twitter-wjs";
private readonly _TWITTER_WIDGET_URL: string = "https://platform.twitter.com/widgets.js";
private readonly _SCRIPT: string = "script";
......@@ -19,8 +20,9 @@ export class TwitterService {
private readonly _ATTRIBUTE_SRC: string = "src";
readonly TWITTER_WINDOW_ID: string = "twttr";
constructor(@Inject(DOCUMENT) private _document: Document,
@Inject(WINDOW) private _window: Window) {
constructor(@Inject(DOCUMENT) private readonly _document: Document,
@Inject(WINDOW) private readonly _window: Window) {
super();
}
loadScript(renderer: Renderer2): Observable<TwitterMetadata> {
......
......@@ -19,6 +19,7 @@ import {
tap,
} from "rxjs/operators";
import {
AbstractBaseService,
ApiService,
HttpStatus,
isNotNullNorUndefined,
......@@ -34,11 +35,13 @@ import {WritableStream} from "web-streams-polyfill/ponyfill";
@Injectable({
providedIn: "root",
})
export class DownloadService {
constructor(private oauth2Service: OAuth2Service,
private httpClient: HttpClient,
export class DownloadService extends AbstractBaseService {
constructor(private readonly _oauth2Service: OAuth2Service,
private readonly _httpClient: HttpClient,
private readonly _apiService: ApiService,
private readonly _notificationService: NotificationService) {}
private readonly _notificationService: NotificationService) {
super();
}
download(isPublic: boolean, url: string, fileName: string, size?: number, archiveId?: string): void {
this._notificationService.showInformation(LabelTranslateEnum.fileDownloadStart);
......@@ -58,7 +61,7 @@ export class DownloadService {
}
private _downloadPrivateWithoutDownloadToken(url: string, fileName: string, size?: number): void {
this.downloadWithMitm(url, fileName, size).pipe(
this.subscribe(this.downloadWithMitm(url, fileName, size).pipe(
tap(result => {
if (result === HttpStatus.OK) {
this._notificationService.showSuccess(LabelTranslateEnum.fileDownloadedSuccessfully);
......@@ -68,11 +71,11 @@ export class DownloadService {
this._notificationService.showSuccess(LabelTranslateEnum.fileDownloadFail);
}
}),
).subscribe();
));
}
private _getAndStoreDownloadTokenThenDownload(url: string, archiveId: string): void {
this.httpClient.get<DownloadToken>(ApiEnum.accessDownloadToken + urlSeparator + archiveId, {
this.subscribe(this._httpClient.get<DownloadToken>(ApiEnum.accessDownloadToken + urlSeparator + archiveId, {
withCredentials: true,
}).pipe(
take(1),
......@@ -83,7 +86,7 @@ export class DownloadService {
this._notificationService.showError(LabelTranslateEnum.fileDownloadForbidden);
throw error;
}),
).subscribe();
));
}
downloadWithMitm(url: string, fileName: string, size?: number): Observable<number> {
......@@ -103,7 +106,7 @@ export class DownloadService {
const requestHeaders: HeadersInit = new Headers();
requestHeaders.set("Content-Type", "application/json");
const token = this.oauth2Service.getAccessToken();
const token = this._oauth2Service.getAccessToken();
if (!isNullOrUndefined(token)) {
requestHeaders.set("Authorization", "Bearer " + token);
}
......@@ -147,7 +150,7 @@ export class DownloadService {
let headers = new HttpHeaders();
headers = headers.set("Content-Disposition", "attachment; filename=" + fileName);
return this.httpClient.get(url, {
return this._httpClient.get(url, {
headers,
responseType: "blob",
}).pipe(tap((blobContent: Blob) => {
......
import {Injectable} from "@angular/core";
import {isNullOrUndefined} from "solidify-frontend";
import {
AbstractBaseService,
isNullOrUndefined,
} from "solidify-frontend";
@Injectable({
providedIn: "root",
})
export class ErrorsSkipperService {
export class ErrorsSkipperService extends AbstractBaseService {
private _errorHttpCodeToSkipTemporary: number[];
constructor() {
super();
this.init();
}
......
......@@ -15,6 +15,7 @@ import {LocalStorageEnum} from "@shared/enums/local-storage.enum";
import {CookieService} from "ngx-cookie";
import {tap} from "rxjs/operators";
import {
AbstractBaseService,
isNullOrUndefined,
LocalStorageHelper,
} from "solidify-frontend";
......@@ -24,7 +25,7 @@ declare let gtag: Function;
@Injectable({
providedIn: "root",
})
export class GoogleAnalyticsService {
export class GoogleAnalyticsService extends AbstractBaseService {
private static readonly _KEY_CONFIG: string = "config";
private readonly _ATTRIBUTE_SRC: string = "src";
private readonly _ATTRIBUTE_SRC_GA_DIFFER_KEY: string = "src-ga-differ";
......@@ -32,7 +33,8 @@ export class GoogleAnalyticsService {
constructor(private readonly _store: Store,
private readonly _cookieService: CookieService,
@Inject(DOCUMENT) private readonly _document: Document,
private router: Router) {
private readonly _router: Router) {
super();
}
init(renderer: Renderer2): void {
......@@ -56,7 +58,7 @@ export class GoogleAnalyticsService {
renderer.setAttribute(script, this._ATTRIBUTE_SRC, src + idGoogleAnalytics);
renderer.removeAttribute(script, this._ATTRIBUTE_SRC_GA_DIFFER_KEY);
this.router.events.pipe(
this.subscribe(this._router.events.pipe(
tap(event => {
if (event instanceof NavigationEnd) {
gtag(GoogleAnalyticsService._KEY_CONFIG, idGoogleAnalytics,
......@@ -67,7 +69,7 @@ export class GoogleAnalyticsService {
);
}
}),
).subscribe();
));
}
disableCookie(): void {
......
......@@ -4,6 +4,7 @@ import {environment} from "@environments/environment";
import {Store} from "@ngxs/store";
import {ApiEnum} from "@shared/enums/api.enum";
import {
AbstractBaseService,
ApiService,
MemoizedUtil,
} from "solidify-frontend";
......@@ -11,9 +12,10 @@ import {
@Injectable({
providedIn: "root",
})
export class OrcidService {
export class OrcidService extends AbstractBaseService {
constructor(private readonly _apiService: ApiService,
private readonly _store: Store) {
super();
}
public startOrcidAuth(): void {
......
......@@ -14,7 +14,6 @@ import {adminPreservationPolicyActionNameSpace} from "@admin/preservation-policy
import {adminResearchDomainActionNameSpace} from "@admin/research-domain/stores/admin-research-domain.action";
import {adminSubmissionPolicyActionNameSpace} from "@admin/submission-policy/stores/admin-submission-policy.action";
import {adminUserActionNameSpace} from "@admin/user/stores/admin-user.action";
import {adminRoleActionNameSpace} from "@admin/role/stores/admin-role.action";
import {Injectable} from "@angular/core";
import {depositActionNameSpace} from "@app/features/deposit/stores/deposit.action";
import {environment} from "@environments/environment";
......
......@@ -312,7 +312,7 @@ export class SharedArchiveState extends ResourceState<SharedArchiveStateModel, A
tap((res: string) => {
if (res === StringUtil.stringEmpty) {
this._setIsPendingRequest(ctx, action, true);
this._prepareDownload(ctx, action.archive.resId).pipe(
this.subscribe(this._prepareDownload(ctx, action.archive.resId).pipe(
tap(() => {
this._setIsPendingRequest(ctx, action, false);
}),
......@@ -325,7 +325,7 @@ export class SharedArchiveState extends ResourceState<SharedArchiveStateModel, A
}
return of(StringUtil.stringEmpty);
}),
).subscribe();
));
return;
}
if (res === Enums.Order.StatusEnum.READY) {
......
......@@ -302,7 +302,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
@Action(AppExtendAction.StartPollingOrder)
startPollingOrder(ctx: StateContext<AppStateModel>, action: AppExtendAction.StartPollingOrder): void {
PollingHelper.startPollingObs({
this.subscribe(PollingHelper.startPollingObs({
initialIntervalRefreshInSecond: environment.refreshOrderAvailableIntervalInSecond,
incrementInterval: true,
resetIntervalWhenUserMouseEvent: true,
......@@ -333,7 +333,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
}
});
},
}).subscribe();
}));
}
@Action(AppExtendAction.StartPollingNotification)
......@@ -342,7 +342,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
this._store.dispatch(new AppExtendAction.UpdateNotificationInbox);
}
PollingHelper.startPollingObs({
this.subscribe(PollingHelper.startPollingObs({
initialIntervalRefreshInSecond: environment.refreshNotificationInboxAvailableIntervalInSecond,
incrementInterval: true,
resetIntervalWhenUserMouseEvent: true,
......@@ -351,7 +351,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
actionToDo: () => {
this._store.dispatch(new AppExtendAction.UpdateNotificationInbox);
},
}).subscribe();
}));
}
@Action(AppExtendAction.UpdateNotificationInbox)
......@@ -393,7 +393,8 @@ export class AppState extends SolidifyAppState<AppStateModel> {
userRoles: tokenDecoded.authorities,
token: tokenDecoded,
});
StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
this.subscribe(StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, [
{
action: new AppUserAction.GetCurrentUser(),
subActionCompletions: [
......@@ -418,7 +419,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
]).pipe(
tap(success => {
}),
).subscribe();
));
return tokenDecoded;
}
......@@ -427,7 +428,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
initiateNewLogin(ctx: StateContext<AppStateModel>, action: AppExtendAction.InitiateNewLogin): void {
const privacyPolicyAndTermsOfUseAccepted = LocalStorageHelper.getItem(LocalStorageEnum.privacyPolicyAndTermsOfUseAccepted);
if (isTrue(environment.displayPrivacyPolicyAndTermsOfUseApprovalDialog) && privacyPolicyAndTermsOfUseAccepted !== "true") {
this._dialog.open(PrivacyPolicyTermsOfUseApprovalDialog).afterClosed().pipe(
this.subscribe(this._dialog.open(PrivacyPolicyTermsOfUseApprovalDialog).afterClosed().pipe(
take(1),
tap(result => {
if (isTrue(result)) {
......@@ -435,7 +436,7 @@ export class AppState extends SolidifyAppState<AppStateModel> {
this._oauthService.initAuthorizationCodeFlow();
}
}),
).subscribe();
));
} else {
this._oauthService.initAuthorizationCodeFlow();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment