Improved history table.

This commit is contained in:
Emanuel Schütze 2019-01-19 18:50:05 +01:00
parent 034a4d2a67
commit 2c5d8ea29e
5 changed files with 44 additions and 16 deletions

View File

@ -333,3 +333,15 @@ _('Admin');
_('Delegates');
_('Staff');
_('Committees');
// history strings
_('Motion deleted');
_('Motion updated');
_('Submitters changed');
_('Supporters changed');
_('State set to {arg1}');
_('Recommendation set to {arg1}');
_('Vote created');
_('Vote updated');
_('Vote deleted');
_('Number set');

View File

@ -8,24 +8,16 @@
</div>
</os-head-bar>
<mat-table class="os-listview-table on-transition-fade" [dataSource]="dataSource" matSort>
<mat-table class="os-header-listview-table on-transition-fade" [dataSource]="dataSource" matSort>
<!-- Timestamp -->
<ng-container matColumnDef="time">
<mat-header-cell *matHeaderCellDef mat-sort-header>Time</mat-header-cell>
<mat-cell *matCellDef="let history"> {{ history.getLocaleString('DE-de') }} </mat-cell>
</ng-container>
<!-- Info -->
<ng-container matColumnDef="info">
<mat-header-cell *matHeaderCellDef mat-sort-header>Info</mat-header-cell>
<mat-cell *matCellDef="let history"> {{ history.information }} </mat-cell>
<mat-header-cell *matHeaderCellDef translate>Timestamp</mat-header-cell>
<mat-cell *matCellDef="let history">{{ history.getLocaleString('DE-de') }}</mat-cell>
</ng-container>
<!-- Element -->
<ng-container matColumnDef="element">
<mat-header-cell *matHeaderCellDef mat-sort-header>Element</mat-header-cell>
<!-- <mat-cell *matCellDef="let history"> {{ history.element_id }} </mat-cell> -->
<mat-header-cell *matHeaderCellDef translate>Element</mat-header-cell>
<mat-cell *matCellDef="let history">
<div *ngIf="getElementInfo(history)">{{ getElementInfo(history) | translate }}</div>
<div
@ -38,10 +30,16 @@
</mat-cell>
</ng-container>
<!-- Info -->
<ng-container matColumnDef="info">
<mat-header-cell *matHeaderCellDef translate>Comment</mat-header-cell>
<mat-cell *matCellDef="let history">{{ parseInformation(history.information) }}</mat-cell>
</ng-container>
<!-- User -->
<ng-container matColumnDef="user">
<mat-header-cell *matHeaderCellDef mat-sort-header>User</mat-header-cell>
<mat-cell *matCellDef="let history"> {{ history.user }} </mat-cell>
<mat-header-cell *matHeaderCellDef translate>Changed by</mat-header-cell>
<mat-cell *matCellDef="let history">{{ history.user }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="getRowDef()"></mat-header-row>

View File

@ -60,7 +60,7 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory> imp
* @param unsortedHistoryList
*/
private sortAndPublish(unsortedHistoryList: ViewHistory[]): void {
const sortedList = unsortedHistoryList.map(history => history);
const sortedList = unsortedHistoryList.map(history => history).filter(item => item.information.length > 0);
sortedList.sort((a, b) => b.history.unixtime - a.history.unixtime);
this.dataSource.data = sortedList;
}
@ -109,4 +109,20 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory> imp
public onDeleteAllButton(): void {
this.repo.delete();
}
/**
* Returns a translated history information string which contains optional (translated) arguments.
*
* @param information history information string
*/
public parseInformation(information: string): void {
if (information.length) {
const base_string = this.translate.instant(information[0]);
let argument_string;
if (information.length > 1) {
argument_string = this.translate.instant(information[1]);
}
return base_string.replace(/{arg1}/g, argument_string);
}
}
}

View File

@ -43,7 +43,7 @@ export class ViewHistory extends BaseViewModel {
}
/**
* Get the elementIs of the history object
* Get the elementIDs of the history object
*
* @returns the element ID as String
*/

View File

@ -167,6 +167,8 @@ class HistorySerializer(ModelSerializer):
Does not contain full data of history object.
"""
information = JSONSerializerField()
class Meta:
model = History
fields = ("id", "element_id", "now", "information", "restricted", "user")