mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Improved redirect after 'Save for later' in Submission edit page
This commit is contained in:
@@ -34,6 +34,10 @@ import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
|||||||
import { AngularticsMock } from './shared/mocks/mock-angulartics.service';
|
import { AngularticsMock } from './shared/mocks/mock-angulartics.service';
|
||||||
import { AuthServiceMock } from './shared/mocks/mock-auth.service';
|
import { AuthServiceMock } from './shared/mocks/mock-auth.service';
|
||||||
import { AuthService } from './core/auth/auth.service';
|
import { AuthService } from './core/auth/auth.service';
|
||||||
|
import { RouteService } from './shared/services/route.service';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { MockActivatedRoute } from './shared/mocks/mock-active-router';
|
||||||
|
import { MockRouter } from './shared/mocks/mock-router';
|
||||||
|
|
||||||
let comp: AppComponent;
|
let comp: AppComponent;
|
||||||
let fixture: ComponentFixture<AppComponent>;
|
let fixture: ComponentFixture<AppComponent>;
|
||||||
@@ -62,7 +66,10 @@ describe('App component', () => {
|
|||||||
{ provide: MetadataService, useValue: new MockMetadataService() },
|
{ provide: MetadataService, useValue: new MockMetadataService() },
|
||||||
{ provide: Angulartics2GoogleAnalytics, useValue: new AngularticsMock() },
|
{ provide: Angulartics2GoogleAnalytics, useValue: new AngularticsMock() },
|
||||||
{ provide: AuthService, useValue: new AuthServiceMock() },
|
{ provide: AuthService, useValue: new AuthServiceMock() },
|
||||||
AppComponent
|
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
|
||||||
|
{ provide: Router, useValue: new MockRouter() },
|
||||||
|
AppComponent,
|
||||||
|
RouteService
|
||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
})
|
})
|
||||||
|
@@ -13,6 +13,7 @@ import { NativeWindowRef, NativeWindowService } from './shared/services/window.s
|
|||||||
import { isAuthenticated } from './core/auth/selectors';
|
import { isAuthenticated } from './core/auth/selectors';
|
||||||
import { AuthService } from './core/auth/auth.service';
|
import { AuthService } from './core/auth/auth.service';
|
||||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
||||||
|
import { RouteService } from './shared/services/route.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-app',
|
selector: 'ds-app',
|
||||||
@@ -30,7 +31,8 @@ export class AppComponent implements OnInit {
|
|||||||
private store: Store<HostWindowState>,
|
private store: Store<HostWindowState>,
|
||||||
private metadata: MetadataService,
|
private metadata: MetadataService,
|
||||||
private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics,
|
private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics,
|
||||||
private authService: AuthService
|
private authService: AuthService,
|
||||||
|
private routeService: RouteService
|
||||||
) {
|
) {
|
||||||
// this language will be used as a fallback when a translation isn't found in the current language
|
// this language will be used as a fallback when a translation isn't found in the current language
|
||||||
translate.setDefaultLang('en');
|
translate.setDefaultLang('en');
|
||||||
@@ -39,6 +41,8 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
metadata.listenForRouteChange();
|
metadata.listenForRouteChange();
|
||||||
|
|
||||||
|
routeService.saveRouting();
|
||||||
|
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
console.info(config);
|
console.info(config);
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ import { findIndex, isEqual, isObject } from 'lodash';
|
|||||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||||
import { ChipsItem, ChipsItemIcon } from './chips-item.model';
|
import { ChipsItem, ChipsItemIcon } from './chips-item.model';
|
||||||
import { hasValue, isNotEmpty } from '../../empty.util';
|
import { hasValue, isNotEmpty } from '../../empty.util';
|
||||||
|
import { PLACEHOLDER_PARENT_METADATA } from '../../form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||||
|
|
||||||
export interface IconsConfig {
|
export interface IconsConfig {
|
||||||
withAuthority?: {
|
withAuthority?: {
|
||||||
@@ -83,6 +84,14 @@ export class Chips {
|
|||||||
return this._items.length > 0;
|
return this._items.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private hasPlaceholder(value) {
|
||||||
|
if (isObject(value)) {
|
||||||
|
return value.value === PLACEHOLDER_PARENT_METADATA;
|
||||||
|
} else {
|
||||||
|
return value === PLACEHOLDER_PARENT_METADATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public remove(chipsItem: ChipsItem): void {
|
public remove(chipsItem: ChipsItem): void {
|
||||||
const index = findIndex(this._items, {id: chipsItem.id});
|
const index = findIndex(this._items, {id: chipsItem.id});
|
||||||
this._items.splice(index, 1);
|
this._items.splice(index, 1);
|
||||||
@@ -119,7 +128,7 @@ export class Chips {
|
|||||||
|
|
||||||
config = (configIndex !== -1) ? this.iconsConfig[configIndex].config : defaultConfig;
|
config = (configIndex !== -1) ? this.iconsConfig[configIndex].config : defaultConfig;
|
||||||
|
|
||||||
if (hasValue(value) && isNotEmpty(config)) {
|
if (hasValue(value) && isNotEmpty(config) && !this.hasPlaceholder(value)) {
|
||||||
|
|
||||||
let icon: ChipsItemIcon;
|
let icon: ChipsItemIcon;
|
||||||
const hasAuthority: boolean = !!(isObject(value) && ((value.hasOwnProperty('authority') && value.authority) || (value.hasOwnProperty('id') && value.id)));
|
const hasAuthority: boolean = !!(isObject(value) && ((value.hasOwnProperty('authority') && value.authority) || (value.hasOwnProperty('id') && value.id)));
|
||||||
|
@@ -1,4 +1,8 @@
|
|||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
export class MockRouter {
|
export class MockRouter {
|
||||||
|
public events = Observable.of({});
|
||||||
|
|
||||||
// noinspection TypeScriptUnresolvedFunction
|
// noinspection TypeScriptUnresolvedFunction
|
||||||
navigate = jasmine.createSpy('navigate');
|
navigate = jasmine.createSpy('navigate');
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
import { RouteService } from './route.service';
|
import { RouteService } from './route.service';
|
||||||
import { async, TestBed } from '@angular/core/testing';
|
import { async, TestBed } from '@angular/core/testing';
|
||||||
import { ActivatedRoute, convertToParamMap, Params } from '@angular/router';
|
import { ActivatedRoute, convertToParamMap, Params, Router } from '@angular/router';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/of'
|
||||||
|
import { MockRouter } from '../mocks/mock-router';
|
||||||
|
|
||||||
describe('RouteService', () => {
|
describe('RouteService', () => {
|
||||||
let service: RouteService;
|
let service: RouteService;
|
||||||
@@ -28,12 +30,13 @@ describe('RouteService', () => {
|
|||||||
queryParamMap: Observable.of(convertToParamMap(paramObject))
|
queryParamMap: Observable.of(convertToParamMap(paramObject))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ provide: Router, useValue: new MockRouter() },
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = new RouteService(TestBed.get(ActivatedRoute));
|
service = new RouteService(TestBed.get(ActivatedRoute), TestBed.get(Router));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hasQueryParam', () => {
|
describe('hasQueryParam', () => {
|
||||||
|
@@ -1,15 +1,14 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import {
|
import { ActivatedRoute, NavigationEnd, Params, Router } from '@angular/router';
|
||||||
ActivatedRoute, convertToParamMap, NavigationExtras, Params,
|
import { filter } from 'rxjs/operators';
|
||||||
Router,
|
|
||||||
} from '@angular/router';
|
|
||||||
import { isNotEmpty } from '../empty.util';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RouteService {
|
export class RouteService {
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute) {
|
private history = [];
|
||||||
|
|
||||||
|
constructor(private route: ActivatedRoute, private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getQueryParameterValues(paramName: string): Observable<string[]> {
|
getQueryParameterValues(paramName: string): Observable<string[]> {
|
||||||
@@ -40,4 +39,22 @@ export class RouteService {
|
|||||||
return params;
|
return params;
|
||||||
}).distinctUntilChanged();
|
}).distinctUntilChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public saveRouting(): void {
|
||||||
|
this.router.events
|
||||||
|
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||||
|
.subscribe(({urlAfterRedirects}: NavigationEnd) => {
|
||||||
|
this.history = [...this.history, urlAfterRedirects];
|
||||||
|
console.log(this.history);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public getHistory(): string[] {
|
||||||
|
return this.history;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPreviousUrl(): string {
|
||||||
|
return this.history[this.history.length - 2] || '';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
import { Inject, Injectable } from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { Subscription } from 'rxjs/Subscription';
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@@ -17,10 +19,10 @@ import { GLOBAL_CONFIG } from '../../config';
|
|||||||
import { HttpHeaders } from '@angular/common/http';
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
import { HttpOptions } from '../core/dspace-rest-v2/dspace-rest-v2.service';
|
import { HttpOptions } from '../core/dspace-rest-v2/dspace-rest-v2.service';
|
||||||
import { SubmissionRestService } from './submission-rest.service';
|
import { SubmissionRestService } from './submission-rest.service';
|
||||||
import { Router } from '@angular/router';
|
|
||||||
import { SectionDataObject } from './sections/models/section-data.model';
|
import { SectionDataObject } from './sections/models/section-data.model';
|
||||||
import { SubmissionScopeType } from '../core/submission/submission-scope-type';
|
import { SubmissionScopeType } from '../core/submission/submission-scope-type';
|
||||||
import { SubmissionObject } from '../core/submission/models/submission-object.model';
|
import { SubmissionObject } from '../core/submission/models/submission-object.model';
|
||||||
|
import { RouteService } from '../shared/services/route.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubmissionService {
|
export class SubmissionService {
|
||||||
@@ -31,6 +33,7 @@ export class SubmissionService {
|
|||||||
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
||||||
protected restService: SubmissionRestService,
|
protected restService: SubmissionRestService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
|
protected routeService: RouteService,
|
||||||
protected store: Store<SubmissionState>) {
|
protected store: Store<SubmissionState>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +194,12 @@ export class SubmissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
redirectToMyDSpace() {
|
redirectToMyDSpace() {
|
||||||
|
const previousUrl = this.routeService.getPreviousUrl();
|
||||||
|
if (isEmpty(previousUrl)) {
|
||||||
this.router.navigate(['/mydspace']);
|
this.router.navigate(['/mydspace']);
|
||||||
|
} else {
|
||||||
|
this.router.navigateByUrl(previousUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retrieveSubmission(submissionId): Observable<SubmissionObject> {
|
retrieveSubmission(submissionId): Observable<SubmissionObject> {
|
||||||
|
Reference in New Issue
Block a user