From ba6d3da8f0f08e1fa681b139d72a27ecc4b2bb07 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Fri, 1 Feb 2019 10:59:58 +0100 Subject: [PATCH] navigate to detail view after setting the history mode (if a detailView is existant) --- .../shared/models/base/detail-navigable.ts | 10 +++++++++ client/src/app/shared/models/users/user.ts | 3 ++- .../history-list/history-list.component.html | 2 +- .../history-list/history-list.component.ts | 22 +++++++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/client/src/app/shared/models/base/detail-navigable.ts b/client/src/app/shared/models/base/detail-navigable.ts index 4a7949396..c02372daf 100644 --- a/client/src/app/shared/models/base/detail-navigable.ts +++ b/client/src/app/shared/models/base/detail-navigable.ts @@ -7,3 +7,13 @@ export interface DetailNavigable { */ getDetailStateURL(): string; } + +/** + * check if a given object implements implements this interface + * + * @param obj + * @returns true if the interface is implemented + */ +export function isDetailNavigable(obj: object): obj is DetailNavigable { + return (obj).getDetailStateURL !== undefined; +} diff --git a/client/src/app/shared/models/users/user.ts b/client/src/app/shared/models/users/user.ts index b23c20ffc..2a8b7161b 100644 --- a/client/src/app/shared/models/users/user.ts +++ b/client/src/app/shared/models/users/user.ts @@ -1,6 +1,7 @@ import { Searchable } from '../base/searchable'; import { SearchRepresentation } from '../../../core/ui-services/search.service'; import { BaseModel } from '../base/base-model'; +import { DetailNavigable } from '../base/detail-navigable'; /** * Iterable pre selection of genders (sexes) @@ -11,7 +12,7 @@ export const genders = ['Female', 'Male', 'Diverse']; * Representation of a user in contrast to the operator. * @ignore */ -export class User extends BaseModel implements Searchable { +export class User extends BaseModel implements Searchable, DetailNavigable { public static COLLECTIONSTRING = 'users/user'; public id: number; diff --git a/client/src/app/site/history/components/history-list/history-list.component.html b/client/src/app/site/history/components/history-list/history-list.component.html index 874da32ca..f851221eb 100644 --- a/client/src/app/site/history/components/history-list/history-list.component.html +++ b/client/src/app/site/history/components/history-list/history-list.component.html @@ -14,7 +14,7 @@ search - + Timestamp diff --git a/client/src/app/site/history/components/history-list/history-list.component.ts b/client/src/app/site/history/components/history-list/history-list.component.ts index a19bc2700..8e7b93685 100644 --- a/client/src/app/site/history/components/history-list/history-list.component.ts +++ b/client/src/app/site/history/components/history-list/history-list.component.ts @@ -1,12 +1,16 @@ import { Component, OnInit } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { MatSnackBar } from '@angular/material'; +import { Router } from '@angular/router'; import { Subject } from 'rxjs'; import { TranslateService } from '@ngx-translate/core'; import { ListViewBaseComponent } from 'app/site/base/list-view-base'; import { HistoryRepositoryService } from 'app/core/repositories/history/history-repository.service'; +import { DataStoreService } from 'app/core/core-services/data-store.service'; +import { isDetailNavigable } from 'app/shared/models/base/detail-navigable'; + import { ViewHistory } from '../../models/view-history'; /** @@ -37,7 +41,9 @@ export class HistoryListComponent extends ListViewBaseComponent imp titleService: Title, translate: TranslateService, matSnackBar: MatSnackBar, - private repo: HistoryRepositoryService + private repo: HistoryRepositoryService, + private DS: DataStoreService, + private router: Router ) { super(titleService, translate, matSnackBar); } @@ -100,7 +106,19 @@ export class HistoryListComponent extends ListViewBaseComponent imp */ public onClickRow(history: ViewHistory): void { this.repo.browseHistory(history).then(() => { - this.raiseError(`Temporarily reset OpenSlides to the state from ${history.getLocaleString('DE-de')}`); + const element = this.DS.get(history.getCollectionString(), history.getModelID()); + let message = this.translate.instant('Temporarily reset OpenSlides to the state from '); + message += history.getLocaleString('DE-de') + '. '; + + if (isDetailNavigable(element)) { + message += this.translate.instant( + 'You will be redirected to the detail state of the last changed item.' + ); + this.raiseError(message); + this.router.navigate([element.getDetailStateURL()]); + } else { + this.raiseError(message); + } }); }