Merge pull request #4238 from MaximilianKrambach/historyNavigate

navigate to detail view after setting the history mode
This commit is contained in:
Sean 2019-02-01 15:17:16 +01:00 committed by GitHub
commit e281b310a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 4 deletions

View File

@ -7,3 +7,13 @@ export interface DetailNavigable {
*/ */
getDetailStateURL(): string; 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 (<DetailNavigable>obj).getDetailStateURL !== undefined;
}

View File

@ -1,6 +1,7 @@
import { Searchable } from '../base/searchable'; import { Searchable } from '../base/searchable';
import { SearchRepresentation } from '../../../core/ui-services/search.service'; import { SearchRepresentation } from '../../../core/ui-services/search.service';
import { BaseModel } from '../base/base-model'; import { BaseModel } from '../base/base-model';
import { DetailNavigable } from '../base/detail-navigable';
/** /**
* Iterable pre selection of genders (sexes) * 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. * Representation of a user in contrast to the operator.
* @ignore * @ignore
*/ */
export class User extends BaseModel<User> implements Searchable { export class User extends BaseModel<User> implements Searchable, DetailNavigable {
public static COLLECTIONSTRING = 'users/user'; public static COLLECTIONSTRING = 'users/user';
public id: number; public id: number;

View File

@ -14,7 +14,7 @@
<mat-icon matSuffix>search</mat-icon> <mat-icon matSuffix>search</mat-icon>
</mat-form-field> </mat-form-field>
</div> </div>
<mat-table class="os-header-listview-table on-transition-fade" [dataSource]="dataSource" matSort> <mat-table class="os-headed-listview-table on-transition-fade" [dataSource]="dataSource" matSort>
<!-- Timestamp --> <!-- Timestamp -->
<ng-container matColumnDef="time"> <ng-container matColumnDef="time">
<mat-header-cell *matHeaderCellDef translate>Timestamp</mat-header-cell> <mat-header-cell *matHeaderCellDef translate>Timestamp</mat-header-cell>

View File

@ -1,12 +1,16 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { MatSnackBar } from '@angular/material'; import { MatSnackBar } from '@angular/material';
import { Router } from '@angular/router';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ListViewBaseComponent } from 'app/site/base/list-view-base'; import { ListViewBaseComponent } from 'app/site/base/list-view-base';
import { HistoryRepositoryService } from 'app/core/repositories/history/history-repository.service'; 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'; import { ViewHistory } from '../../models/view-history';
/** /**
@ -37,7 +41,9 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory> imp
titleService: Title, titleService: Title,
translate: TranslateService, translate: TranslateService,
matSnackBar: MatSnackBar, matSnackBar: MatSnackBar,
private repo: HistoryRepositoryService private repo: HistoryRepositoryService,
private DS: DataStoreService,
private router: Router
) { ) {
super(titleService, translate, matSnackBar); super(titleService, translate, matSnackBar);
} }
@ -100,7 +106,19 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory> imp
*/ */
public onClickRow(history: ViewHistory): void { public onClickRow(history: ViewHistory): void {
this.repo.browseHistory(history).then(() => { 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);
}
}); });
} }