mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +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 { AuthServiceMock } from './shared/mocks/mock-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 fixture: ComponentFixture<AppComponent>;
|
||||
@@ -62,7 +66,10 @@ describe('App component', () => {
|
||||
{ provide: MetadataService, useValue: new MockMetadataService() },
|
||||
{ provide: Angulartics2GoogleAnalytics, useValue: new AngularticsMock() },
|
||||
{ provide: AuthService, useValue: new AuthServiceMock() },
|
||||
AppComponent
|
||||
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
|
||||
{ provide: Router, useValue: new MockRouter() },
|
||||
AppComponent,
|
||||
RouteService
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
|
@@ -13,6 +13,7 @@ import { NativeWindowRef, NativeWindowService } from './shared/services/window.s
|
||||
import { isAuthenticated } from './core/auth/selectors';
|
||||
import { AuthService } from './core/auth/auth.service';
|
||||
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
|
||||
import { RouteService } from './shared/services/route.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-app',
|
||||
@@ -30,7 +31,8 @@ export class AppComponent implements OnInit {
|
||||
private store: Store<HostWindowState>,
|
||||
private metadata: MetadataService,
|
||||
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
|
||||
translate.setDefaultLang('en');
|
||||
@@ -39,6 +41,8 @@ export class AppComponent implements OnInit {
|
||||
|
||||
metadata.listenForRouteChange();
|
||||
|
||||
routeService.saveRouting();
|
||||
|
||||
if (config.debug) {
|
||||
console.info(config);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ import { findIndex, isEqual, isObject } from 'lodash';
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
import { ChipsItem, ChipsItemIcon } from './chips-item.model';
|
||||
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 {
|
||||
withAuthority?: {
|
||||
@@ -83,6 +84,14 @@ export class Chips {
|
||||
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 {
|
||||
const index = findIndex(this._items, {id: chipsItem.id});
|
||||
this._items.splice(index, 1);
|
||||
@@ -119,7 +128,7 @@ export class Chips {
|
||||
|
||||
config = (configIndex !== -1) ? this.iconsConfig[configIndex].config : defaultConfig;
|
||||
|
||||
if (hasValue(value) && isNotEmpty(config)) {
|
||||
if (hasValue(value) && isNotEmpty(config) && !this.hasPlaceholder(value)) {
|
||||
|
||||
let icon: ChipsItemIcon;
|
||||
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 {
|
||||
public events = Observable.of({});
|
||||
|
||||
// noinspection TypeScriptUnresolvedFunction
|
||||
navigate = jasmine.createSpy('navigate');
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import { RouteService } from './route.service';
|
||||
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 'rxjs/add/observable/of'
|
||||
import { MockRouter } from '../mocks/mock-router';
|
||||
|
||||
describe('RouteService', () => {
|
||||
let service: RouteService;
|
||||
@@ -28,12 +30,13 @@ describe('RouteService', () => {
|
||||
queryParamMap: Observable.of(convertToParamMap(paramObject))
|
||||
},
|
||||
},
|
||||
{ provide: Router, useValue: new MockRouter() },
|
||||
]
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = new RouteService(TestBed.get(ActivatedRoute));
|
||||
service = new RouteService(TestBed.get(ActivatedRoute), TestBed.get(Router));
|
||||
});
|
||||
|
||||
describe('hasQueryParam', () => {
|
||||
|
@@ -1,15 +1,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import {
|
||||
ActivatedRoute, convertToParamMap, NavigationExtras, Params,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
import { isNotEmpty } from '../empty.util';
|
||||
import { ActivatedRoute, NavigationEnd, Params, Router } from '@angular/router';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class RouteService {
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
private history = [];
|
||||
|
||||
constructor(private route: ActivatedRoute, private router: Router) {
|
||||
}
|
||||
|
||||
getQueryParameterValues(paramName: string): Observable<string[]> {
|
||||
@@ -40,4 +39,22 @@ export class RouteService {
|
||||
return params;
|
||||
}).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 { Router } from '@angular/router';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
import { Store } from '@ngrx/store';
|
||||
@@ -17,10 +19,10 @@ import { GLOBAL_CONFIG } from '../../config';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { HttpOptions } from '../core/dspace-rest-v2/dspace-rest-v2.service';
|
||||
import { SubmissionRestService } from './submission-rest.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { SectionDataObject } from './sections/models/section-data.model';
|
||||
import { SubmissionScopeType } from '../core/submission/submission-scope-type';
|
||||
import { SubmissionObject } from '../core/submission/models/submission-object.model';
|
||||
import { RouteService } from '../shared/services/route.service';
|
||||
|
||||
@Injectable()
|
||||
export class SubmissionService {
|
||||
@@ -31,6 +33,7 @@ export class SubmissionService {
|
||||
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
||||
protected restService: SubmissionRestService,
|
||||
protected router: Router,
|
||||
protected routeService: RouteService,
|
||||
protected store: Store<SubmissionState>) {
|
||||
}
|
||||
|
||||
@@ -191,7 +194,12 @@ export class SubmissionService {
|
||||
}
|
||||
|
||||
redirectToMyDSpace() {
|
||||
const previousUrl = this.routeService.getPreviousUrl();
|
||||
if (isEmpty(previousUrl)) {
|
||||
this.router.navigate(['/mydspace']);
|
||||
} else {
|
||||
this.router.navigateByUrl(previousUrl);
|
||||
}
|
||||
}
|
||||
|
||||
retrieveSubmission(submissionId): Observable<SubmissionObject> {
|
||||
|
Reference in New Issue
Block a user