mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
119602: Allow resetting accessibility settings
This commit is contained in:
@@ -2,13 +2,14 @@ import { Injectable } from '@angular/core';
|
|||||||
import { Observable, of, switchMap } from 'rxjs';
|
import { Observable, of, switchMap } from 'rxjs';
|
||||||
import { map, take } from 'rxjs/operators';
|
import { map, take } from 'rxjs/operators';
|
||||||
import { CookieService } from '../core/services/cookie.service';
|
import { CookieService } from '../core/services/cookie.service';
|
||||||
import { hasValue, isNotEmpty, isNotEmptyOperator } from '../shared/empty.util';
|
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
||||||
import { AuthService } from '../core/auth/auth.service';
|
import { AuthService } from '../core/auth/auth.service';
|
||||||
import { EPerson } from '../core/eperson/models/eperson.model';
|
import { EPerson } from '../core/eperson/models/eperson.model';
|
||||||
import { EPersonDataService } from '../core/eperson/eperson-data.service';
|
import { EPersonDataService } from '../core/eperson/eperson-data.service';
|
||||||
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
import { getFirstCompletedRemoteData } from '../core/shared/operators';
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the cookie used to store the settings locally
|
* Name of the cookie used to store the settings locally
|
||||||
@@ -198,8 +199,8 @@ export class AccessibilitySettingsService {
|
|||||||
|
|
||||||
return this.ePersonService.createPatchFromCache(user).pipe(
|
return this.ePersonService.createPatchFromCache(user).pipe(
|
||||||
take(1),
|
take(1),
|
||||||
isNotEmptyOperator(),
|
switchMap(operations =>
|
||||||
switchMap(operations => this.ePersonService.patch(user, operations)),
|
isNotEmpty(operations) ? this.ePersonService.patch(user, operations) : createSuccessfulRemoteDataObject$({})),
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
map(rd => rd.hasSucceeded),
|
map(rd => rd.hasSucceeded),
|
||||||
);
|
);
|
||||||
@@ -216,6 +217,15 @@ export class AccessibilitySettingsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all settings in the cookie and attempts to clear settings in metadata.
|
||||||
|
* Emits true if settings in metadata were cleared and false otherwise.
|
||||||
|
*/
|
||||||
|
clearSettings(): Observable<boolean> {
|
||||||
|
this.setSettingsInCookie({});
|
||||||
|
return this.setSettingsInAuthenticatedUserMetadata({});
|
||||||
|
}
|
||||||
|
|
||||||
getPlaceholder(setting: AccessibilitySetting): string {
|
getPlaceholder(setting: AccessibilitySetting): string {
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case AccessibilitySetting.NotificationTimeOut:
|
case AccessibilitySetting.NotificationTimeOut:
|
||||||
|
@@ -54,9 +54,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" (click)="saveSettings()" class="btn btn-primary">
|
<div role="group">
|
||||||
{{ 'info.accessibility-settings.submit' | translate }}
|
<button type="submit" (click)="saveSettings()" class="btn btn-primary mr-2">
|
||||||
</button>
|
{{ 'info.accessibility-settings.submit' | translate }}
|
||||||
|
</button>
|
||||||
|
<button type="reset" (click)="resetSettings()" class="btn btn-warning">
|
||||||
|
{{ 'info.accessibility-settings.reset' | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@@ -57,4 +57,14 @@ export class AccessibilitySettingsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets accessibility settings
|
||||||
|
*/
|
||||||
|
resetSettings() {
|
||||||
|
this.settingsService.clearSettings().pipe(take(1)).subscribe(() => {
|
||||||
|
this.notificationsService.success(null, this.translateService.instant('info.accessibility-settings.reset-notification'));
|
||||||
|
this.updateFormValues();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1860,6 +1860,10 @@
|
|||||||
|
|
||||||
"info.accessibility-settings.save-notification.metadata": "Successfully saved settings on the user profile.",
|
"info.accessibility-settings.save-notification.metadata": "Successfully saved settings on the user profile.",
|
||||||
|
|
||||||
|
"info.accessibility-settings.reset-notification": "Successfully reset settings.",
|
||||||
|
|
||||||
|
"info.accessibility-settings.reset": "Reset accessibility settings",
|
||||||
|
|
||||||
"info.accessibility-settings.submit": "Save accessibility settings",
|
"info.accessibility-settings.submit": "Save accessibility settings",
|
||||||
|
|
||||||
"info.accessibility-settings.title": "Accessibility settings",
|
"info.accessibility-settings.title": "Accessibility settings",
|
||||||
|
Reference in New Issue
Block a user