Refactured client
This commit is contained in:
parent
5a5bc77e62
commit
ff98ee1b96
@ -358,6 +358,10 @@ export class OperatorService implements OnAfterAppsLoaded {
|
||||
return groupIds.some(id => this.user.groups_id.includes(id));
|
||||
}
|
||||
|
||||
public isSuperAdmin(): boolean {
|
||||
return this.isInGroupIdsNonAdminCheck(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the operators permissions and publish the operator afterwards.
|
||||
* Saves the current WhoAmI to storage with the updated permissions
|
||||
|
@ -9,6 +9,7 @@ import { BaseModel } from 'app/shared/models/base/base-model';
|
||||
import { OpenSlidesStatusService } from './openslides-status.service';
|
||||
import { OpenSlidesService } from './openslides.service';
|
||||
import { HttpService } from './http.service';
|
||||
import { DataStoreUpdateManagerService } from './data-store-update-manager.service';
|
||||
|
||||
/**
|
||||
* Interface for full history data objects.
|
||||
@ -51,7 +52,8 @@ export class TimeTravelService {
|
||||
private modelMapperService: CollectionStringMapperService,
|
||||
private DS: DataStoreService,
|
||||
private OSStatus: OpenSlidesStatusService,
|
||||
private OpenSlides: OpenSlidesService
|
||||
private OpenSlides: OpenSlidesService,
|
||||
private DSUpdateManager: DataStoreUpdateManagerService
|
||||
) {}
|
||||
|
||||
/**
|
||||
@ -60,6 +62,8 @@ export class TimeTravelService {
|
||||
* @param history the desired point in the history of OpenSlides
|
||||
*/
|
||||
public async loadHistoryPoint(history: History): Promise<void> {
|
||||
const updateSlot = await this.DSUpdateManager.getNewUpdateSlot(this.DS);
|
||||
|
||||
await this.stopTime(history);
|
||||
const fullDataHistory: HistoryData[] = await this.getHistoryData(history);
|
||||
for (const historyObject of fullDataHistory) {
|
||||
@ -74,6 +78,8 @@ export class TimeTravelService {
|
||||
await this.DS.remove(collectionString, [+id]);
|
||||
}
|
||||
}
|
||||
|
||||
this.DSUpdateManager.commit(updateSlot);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,25 +100,16 @@ export class TimeTravelService {
|
||||
* @returns the full history on the given date
|
||||
*/
|
||||
private async getHistoryData(history: History): Promise<HistoryData[]> {
|
||||
const queryParams = { timestamp: Math.ceil(+history.unixtime) };
|
||||
return this.httpService.get<HistoryData[]>(`${environment.urlPrefix}/core/history/`, null, queryParams);
|
||||
const queryParams = { timestamp: Math.ceil(history.timestamp) };
|
||||
return this.httpService.get<HistoryData[]>(`${environment.urlPrefix}/core/history/data/`, null, queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the DataStore and stops the WebSocket connection
|
||||
*/
|
||||
private async stopTime(history: History): Promise<void> {
|
||||
this.webSocketService.close();
|
||||
await this.cleanDataStore();
|
||||
await this.webSocketService.close();
|
||||
await this.DS.set(); // Same as clear, but not persistent.
|
||||
this.OSStatus.enterHistoryMode(history);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean the DataStore to inject old Data.
|
||||
* Remove everything "but" the history.
|
||||
*/
|
||||
private async cleanDataStore(): Promise<void> {
|
||||
const historyArchive = this.DS.getAll(History);
|
||||
await this.DS.set(historyArchive);
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ export class WebsocketService {
|
||||
if (data instanceof ArrayBuffer) {
|
||||
const compressedSize = data.byteLength;
|
||||
const decompressedBuffer: Uint8Array = decompress(new Uint8Array(data));
|
||||
console.log(
|
||||
console.debug(
|
||||
`Recieved ${compressedSize / 1024} KB (${decompressedBuffer.byteLength /
|
||||
1024} KB uncompressed), ratio ${decompressedBuffer.byteLength / compressedSize}`
|
||||
);
|
||||
@ -285,7 +285,7 @@ export class WebsocketService {
|
||||
}
|
||||
|
||||
const message: IncommingWebsocketMessage = JSON.parse(data);
|
||||
console.log('Received', message);
|
||||
console.debug('Received', message);
|
||||
const type = message.type;
|
||||
const inResponse = message.in_response;
|
||||
const callbacks = this.responseCallbacks[inResponse];
|
||||
|
@ -1,18 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HistoryRepositoryService } from './history-repository.service';
|
||||
import { E2EImportsModule } from 'e2e-imports.module';
|
||||
|
||||
describe('HistoryRepositoryService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [E2EImportsModule],
|
||||
providers: [HistoryRepositoryService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
const service = TestBed.get(HistoryRepositoryService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,145 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
import { CollectionStringMapperService } from 'app/core/core-services/collection-string-mapper.service';
|
||||
import { DataStoreService } from 'app/core/core-services/data-store.service';
|
||||
import { BaseRepository } from 'app/core/repositories/base-repository';
|
||||
import { History } from 'app/shared/models/core/history';
|
||||
import { Identifiable } from 'app/shared/models/base/identifiable';
|
||||
import { HttpService } from 'app/core/core-services/http.service';
|
||||
import { ViewHistory, ProxyHistory, HistoryTitleInformation } from 'app/site/history/models/view-history';
|
||||
import { TimeTravelService } from 'app/core/core-services/time-travel.service';
|
||||
import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service';
|
||||
import { ViewUser } from 'app/site/users/models/view-user';
|
||||
import { DataSendService } from 'app/core/core-services/data-send.service';
|
||||
|
||||
/**
|
||||
* Repository for the history.
|
||||
*
|
||||
* Gets new history objects/entries and provides them for the view.
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HistoryRepositoryService extends BaseRepository<ViewHistory, History, HistoryTitleInformation> {
|
||||
/**
|
||||
* Constructs the history repository
|
||||
*
|
||||
* @param DS The DataStore
|
||||
* @param mapperService mapps the models to the collection string
|
||||
* @param httpService OpenSlides own HTTP service
|
||||
* @param timeTravel To change the time
|
||||
*/
|
||||
public constructor(
|
||||
DS: DataStoreService,
|
||||
dataSend: DataSendService,
|
||||
mapperService: CollectionStringMapperService,
|
||||
viewModelStoreService: ViewModelStoreService,
|
||||
translate: TranslateService,
|
||||
private httpService: HttpService,
|
||||
private timeTravel: TimeTravelService
|
||||
) {
|
||||
super(DS, dataSend, mapperService, viewModelStoreService, translate, History);
|
||||
}
|
||||
|
||||
public getVerboseName = (plural: boolean = false) => {
|
||||
return this.translate.instant(plural ? 'Histories' : 'History');
|
||||
};
|
||||
|
||||
public getTitle = (titleInformation: HistoryTitleInformation) => {
|
||||
return titleInformation.element_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new ViewHistory objects out of a historyObject
|
||||
*
|
||||
* @param history the source history object
|
||||
* @return a new ViewHistory object
|
||||
*/
|
||||
public createViewModel(history: History): ViewHistory {
|
||||
return new ViewHistory(this.createProxyHistory(history));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ProxyHistory from a History by wrapping it and give access to the user.
|
||||
*
|
||||
* @param history The History object
|
||||
* @returns the ProxyHistory
|
||||
*/
|
||||
private createProxyHistory(history: History): ProxyHistory {
|
||||
return new Proxy(history, {
|
||||
get: (instance, property) => {
|
||||
if (property === 'user') {
|
||||
return this.viewModelStoreService.get(ViewUser, instance.user_id);
|
||||
} else {
|
||||
return instance[property];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the default procedure
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
public async create(): Promise<Identifiable> {
|
||||
throw new Error('You cannot create a history object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the default procedure
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
public async update(): Promise<void> {
|
||||
throw new Error('You cannot update a history object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the default procedure
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
public async patch(): Promise<void> {
|
||||
throw new Error('You cannot patch a history object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the default procedure
|
||||
*
|
||||
* Sends a post-request to delete history objects
|
||||
*/
|
||||
public async delete(): Promise<void> {
|
||||
const restPath = '/rest/core/history/clear_history/';
|
||||
await this.httpService.post(restPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ListTitle of a history Element from the dataStore
|
||||
* using the collection string and the ID.
|
||||
*
|
||||
* @param collectionString the models collection string
|
||||
* @param id the models id
|
||||
* @returns the ListTitle or null if the model was deleted already
|
||||
*/
|
||||
public getOldModelInfo(collectionString: string, id: number): string {
|
||||
const model = this.viewModelStoreService.get(collectionString, id);
|
||||
if (model) {
|
||||
return model.getListTitle();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full data on the given date and use the
|
||||
* TimeTravelService to browse the history on the
|
||||
* given date
|
||||
*
|
||||
* @param viewHistory determines to point to travel back to
|
||||
*/
|
||||
public async browseHistory(viewHistory: ViewHistory): Promise<void> {
|
||||
return this.timeTravel.loadHistoryPoint(viewHistory.history);
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ export class PromptService {
|
||||
* @param title The title to display in the dialog
|
||||
* @param content The content in the dialog
|
||||
*/
|
||||
public async open(title: string, content: string): Promise<any> {
|
||||
public async open(title: string, content: string = ''): Promise<any> {
|
||||
const dialogRef = this.dialog.open(PromptDialogComponent, {
|
||||
width: '250px',
|
||||
data: { title: title, content: content }
|
||||
|
@ -1,16 +1,15 @@
|
||||
import { BaseModel } from '../base/base-model';
|
||||
import { Deserializable } from '../base/deserializable';
|
||||
|
||||
/**
|
||||
* Representation of a history object.
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
export class History extends BaseModel {
|
||||
public static COLLECTIONSTRING = 'core/history';
|
||||
public id: number;
|
||||
export class History implements Deserializable {
|
||||
public element_id: string;
|
||||
public now: string;
|
||||
public timestamp: number;
|
||||
public information: string;
|
||||
public restricted: boolean;
|
||||
public user_id: number;
|
||||
|
||||
/**
|
||||
@ -19,18 +18,21 @@ export class History extends BaseModel {
|
||||
* @returns a Data object
|
||||
*/
|
||||
public get date(): Date {
|
||||
return new Date(this.now);
|
||||
return new Date(this.timestamp * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the timestamp to unix time
|
||||
*/
|
||||
public get unixtime(): number {
|
||||
return Date.parse(this.now) / 1000;
|
||||
public get collectionString(): string {
|
||||
return this.element_id.split(':')[0];
|
||||
}
|
||||
|
||||
public constructor(input?: any) {
|
||||
super(History.COLLECTIONSTRING, input);
|
||||
public get modelId(): number {
|
||||
return +this.element_id.split(':')[1];
|
||||
}
|
||||
|
||||
public constructor(input: History) {
|
||||
if (input) {
|
||||
this.deserialize(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,4 +44,8 @@ export class History extends BaseModel {
|
||||
public getLocaleString(locale: string): string {
|
||||
return this.date.toLocaleString(locale);
|
||||
}
|
||||
|
||||
public deserialize(input: any): void {
|
||||
Object.assign(this, input);
|
||||
}
|
||||
}
|
||||
|
@ -5,20 +5,41 @@
|
||||
<!-- Menu -->
|
||||
<div class="menu-slot">
|
||||
<!-- Hidden for everyone but the superadmin -->
|
||||
<button *osPerms="'superadmin'" type="button" mat-icon-button [matMenuTriggerFor]="historyMenu">
|
||||
<button *ngIf="isSuperAdmin" type="button" mat-icon-button [matMenuTriggerFor]="historyMenu">
|
||||
<mat-icon>more_vert</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</os-head-bar>
|
||||
|
||||
<div class="custom-table-header">
|
||||
<div>
|
||||
<span>
|
||||
<os-search-value-selector
|
||||
ngDefaultControl
|
||||
[form]="modelSelectForm"
|
||||
[formControl]="modelSelectForm.get('model')"
|
||||
[multiple]="false"
|
||||
[includeNone]="false"
|
||||
listname="{{ 'Motion' | translate }}"
|
||||
[InputListValues]="collectionObserver"
|
||||
></os-search-value-selector>
|
||||
</span>
|
||||
<span class="spacer-left-20">
|
||||
<button mat-button (click)="refresh()" *ngIf="currentModelId">
|
||||
<mat-icon>refresh</mat-icon>
|
||||
<span translate>Refresh</span>
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<mat-form-field>
|
||||
<input matInput (keyup)="applySearch($event.target.value)" placeholder="{{ 'Search' | translate }}" />
|
||||
<mat-icon matSuffix>search</mat-icon>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<mat-table class="os-headed-listview-table on-transition-fade" [dataSource]="dataSource" matSort>
|
||||
<mat-table class="on-transition-fade" [dataSource]="dataSource" matSort>
|
||||
<!-- Timestamp -->
|
||||
<ng-container matColumnDef="time">
|
||||
<mat-header-cell *matHeaderCellDef translate>Timestamp</mat-header-cell>
|
||||
@ -43,23 +64,23 @@
|
||||
<!-- Info -->
|
||||
<ng-container matColumnDef="info">
|
||||
<mat-header-cell *matHeaderCellDef translate>Comment</mat-header-cell>
|
||||
<mat-cell *matCellDef="let history">{{ parseInformation(history.information) }}</mat-cell>
|
||||
<mat-cell *matCellDef="let history">{{ parseInformation(history) }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- User -->
|
||||
<ng-container matColumnDef="user">
|
||||
<mat-header-cell *matHeaderCellDef translate>Changed by</mat-header-cell>
|
||||
<mat-cell *matCellDef="let history">{{ history.user_full_name }}</mat-cell>
|
||||
<mat-cell *matCellDef="let history">{{ getUserName(history) }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="getRowDef()"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: getRowDef()" (click)="onClickRow(row)"></mat-row>
|
||||
</mat-table>
|
||||
|
||||
<mat-paginator class="on-transition-fade" [pageSizeOptions]="pageSize"></mat-paginator>
|
||||
<mat-paginator class="on-transition-fade" [pageSizeOptions]="pageSizes"></mat-paginator>
|
||||
|
||||
<mat-menu #historyMenu="matMenu">
|
||||
<button mat-menu-item class="red-warning-text" (click)="onDeleteAllButton()">
|
||||
<button mat-menu-item class="red-warning-text" (click)="clearHistory()">
|
||||
<mat-icon>delete</mat-icon>
|
||||
<span translate>Delete whole history</span>
|
||||
</button>
|
||||
|
@ -1,4 +1,4 @@
|
||||
.os-listview-table {
|
||||
.mat-table {
|
||||
/** Time */
|
||||
.mat-column-time {
|
||||
flex: 1 0 50px;
|
||||
@ -24,3 +24,12 @@
|
||||
font-style: italic;
|
||||
color: slategray; // TODO: Colors per theme
|
||||
}
|
||||
|
||||
.custom-table-header {
|
||||
justify-content: space-between;
|
||||
text-align: left;
|
||||
|
||||
& > div {
|
||||
padding: 0 20px;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,26 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material';
|
||||
import { MatSnackBar, MatTableDataSource } from '@angular/material';
|
||||
import { Router } from '@angular/router';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { Subject, BehaviorSubject } from 'rxjs';
|
||||
|
||||
import { History } from 'app/shared/models/core/history';
|
||||
import { HistoryRepositoryService } from 'app/core/repositories/history/history-repository.service';
|
||||
import { environment } from 'environments/environment';
|
||||
import { isDetailNavigable } from 'app/shared/models/base/detail-navigable';
|
||||
import { ListViewBaseComponent } from 'app/site/base/list-view-base';
|
||||
import { OperatorService } from 'app/core/core-services/operator.service';
|
||||
import { ViewHistory } from '../../models/view-history';
|
||||
import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service';
|
||||
import { langToLocale } from 'app/shared/utils/lang-to-locale';
|
||||
import { TimeTravelService } from 'app/core/core-services/time-travel.service';
|
||||
import { HttpService } from 'app/core/core-services/http.service';
|
||||
import { BaseViewComponent } from 'app/site/base/base-view';
|
||||
import { History } from 'app/shared/models/core/history';
|
||||
import { ViewUser } from 'app/site/users/models/view-user';
|
||||
import { FormGroup, FormBuilder } from '@angular/forms';
|
||||
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
|
||||
import { BaseViewModel } from 'app/site/base/base-view-model';
|
||||
import { Motion } from 'app/shared/models/motions/motion';
|
||||
import { PromptService } from 'app/core/ui-services/prompt.service';
|
||||
|
||||
/**
|
||||
* A list view for the history.
|
||||
@ -25,13 +32,41 @@ import { langToLocale } from 'app/shared/utils/lang-to-locale';
|
||||
templateUrl: './history-list.component.html',
|
||||
styleUrls: ['./history-list.component.scss']
|
||||
})
|
||||
export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, History, HistoryRepositoryService>
|
||||
implements OnInit {
|
||||
export class HistoryListComponent extends BaseViewComponent implements OnInit {
|
||||
/**
|
||||
* Subject determine when the custom timestamp subject changes
|
||||
*/
|
||||
public customTimestampChanged: Subject<number> = new Subject<number>();
|
||||
|
||||
public dataSource: MatTableDataSource<History> = new MatTableDataSource<History>();
|
||||
|
||||
public get isSuperAdmin(): boolean {
|
||||
return this.operator.isSuperAdmin();
|
||||
}
|
||||
|
||||
public pageSizes = [50, 100, 150, 200, 250];
|
||||
|
||||
/**
|
||||
* The form for the selection of the model
|
||||
* When more models are supproted, add a "collection"-dropdown
|
||||
*/
|
||||
public modelSelectForm: FormGroup;
|
||||
|
||||
/**
|
||||
* The observer for the selected collection, which is currently hardcoded
|
||||
* to motions.
|
||||
*/
|
||||
public collectionObserver: BehaviorSubject<BaseViewModel[]>;
|
||||
|
||||
/**
|
||||
* The current selected collection. THis may move to `modelSelectForm`, if this can be choosen.
|
||||
*/
|
||||
private currentCollection = Motion.COLLECTIONSTRING;
|
||||
|
||||
public get currentModelId(): number | null {
|
||||
return this.modelSelectForm.controls.model.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the history list component
|
||||
*
|
||||
@ -47,12 +82,25 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
|
||||
titleService: Title,
|
||||
translate: TranslateService,
|
||||
matSnackBar: MatSnackBar,
|
||||
private repo: HistoryRepositoryService,
|
||||
private viewModelStore: ViewModelStoreService,
|
||||
private router: Router,
|
||||
private operator: OperatorService
|
||||
private operator: OperatorService,
|
||||
private timeTravelService: TimeTravelService,
|
||||
private http: HttpService,
|
||||
private formBuilder: FormBuilder,
|
||||
private motionRepo: MotionRepositoryService,
|
||||
private promptService: PromptService
|
||||
) {
|
||||
super(titleService, translate, matSnackBar, repo);
|
||||
super(titleService, translate, matSnackBar);
|
||||
|
||||
this.modelSelectForm = this.formBuilder.group({
|
||||
model: []
|
||||
});
|
||||
this.collectionObserver = this.motionRepo.getViewModelListBehaviorSubject();
|
||||
|
||||
this.modelSelectForm.controls.model.valueChanges.subscribe((id: number) => {
|
||||
this.queryElementId(this.currentCollection, id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,23 +108,34 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
|
||||
*/
|
||||
public ngOnInit(): void {
|
||||
super.setTitle('History');
|
||||
this.initTable();
|
||||
this.setFilters();
|
||||
|
||||
this.repo.getViewModelListObservable().subscribe(history => {
|
||||
this.sortAndPublish(history);
|
||||
});
|
||||
this.dataSource.filterPredicate = (history: History, filter: string) => {
|
||||
filter = filter ? filter.toLowerCase() : '';
|
||||
|
||||
if (!history) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the given ViewHistory array and sets it in the table data source
|
||||
*
|
||||
* @param unsortedHistoryList
|
||||
*/
|
||||
private sortAndPublish(unsortedHistoryList: ViewHistory[]): void {
|
||||
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;
|
||||
const userfullname = this.getUserName(history);
|
||||
if (userfullname.toLowerCase().indexOf(filter) >= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
this.getElementInfo(history) &&
|
||||
this.getElementInfo(history)
|
||||
.toLowerCase()
|
||||
.indexOf(filter) >= 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
this.parseInformation(history)
|
||||
.toLowerCase()
|
||||
.indexOf(filter) >= 0
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,17 +151,12 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
|
||||
* Tries get the title of the BaseModel element corresponding to
|
||||
* a history object.
|
||||
*
|
||||
* @param history the history
|
||||
* @returns the title of an old element or null if it could not be found
|
||||
* @param history a history object
|
||||
* @returns the title of the history element or null if it could not be found
|
||||
*/
|
||||
public getElementInfo(history: ViewHistory): string {
|
||||
const oldElementTitle = this.repo.getOldModelInfo(history.getCollectionString(), history.getModelId());
|
||||
|
||||
if (oldElementTitle) {
|
||||
return oldElementTitle;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
public getElementInfo(history: History): string {
|
||||
const model = this.viewModelStore.get(history.collectionString, history.modelId);
|
||||
return model ? model.getListTitle() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,10 +165,13 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
|
||||
*
|
||||
* @param history Represents the selected element
|
||||
*/
|
||||
public async onClickRow(history: ViewHistory): Promise<void> {
|
||||
if (this.operator.isInGroupIds(2)) {
|
||||
await this.repo.browseHistory(history);
|
||||
const element = this.viewModelStore.get(history.getCollectionString(), history.getModelId());
|
||||
public async onClickRow(history: History): Promise<void> {
|
||||
if (!this.isSuperAdmin) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.timeTravelService.loadHistoryPoint(history);
|
||||
const element = this.viewModelStore.get(history.collectionString, history.modelId);
|
||||
if (element && isDetailNavigable(element)) {
|
||||
this.router.navigate([element.getDetailStateURL()]);
|
||||
} else {
|
||||
@ -122,35 +179,53 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
|
||||
this.raiseError(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getTimestamp(viewHistory: ViewHistory): string {
|
||||
return viewHistory.history.getLocaleString(langToLocale(this.translate.currentLang));
|
||||
public getTimestamp(history: History): string {
|
||||
return history.getLocaleString(langToLocale(this.translate.currentLang));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the delete all button
|
||||
* clears the whole history.
|
||||
*/
|
||||
public onDeleteAllButton(): void {
|
||||
if (this.operator.isInGroupIds(2)) {
|
||||
this.repo.delete();
|
||||
public async clearHistory(): Promise<void> {
|
||||
const title = this.translate.instant('Are you sure you want delete the whole history?');
|
||||
if (await this.promptService.open(title)) {
|
||||
try {
|
||||
await this.http.delete(`${environment.urlPrefix}/core/history/information/`);
|
||||
this.refresh();
|
||||
} catch (e) {
|
||||
this.raiseError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public refresh(): void {
|
||||
if (this.currentCollection && this.currentModelId) {
|
||||
this.queryElementId(this.currentCollection, this.currentModelId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a translated history information string which contains optional (translated) arguments.
|
||||
*
|
||||
* @param information history information string
|
||||
* @param history the history
|
||||
*/
|
||||
public parseInformation(information: string): string {
|
||||
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]);
|
||||
public parseInformation(history: History): string {
|
||||
if (!history.information || !history.information.length) {
|
||||
return '';
|
||||
}
|
||||
return base_string.replace(/{arg1}/g, argument_string);
|
||||
|
||||
const baseString = this.translate.instant(history.information[0]);
|
||||
let argumentString;
|
||||
if (history.information.length > 1) {
|
||||
argumentString = this.translate.instant(history.information[1]);
|
||||
}
|
||||
return baseString.replace(/{arg1}/g, argumentString);
|
||||
}
|
||||
|
||||
public getUserName(history: History): string {
|
||||
const user = this.viewModelStore.get(ViewUser, history.user_id);
|
||||
return user ? user.full_name : '';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,31 +238,13 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the dataSource's string filter with a more advanced option
|
||||
* using the display methods of this class.
|
||||
* Sets the data source to the request element id given by the collection string and the id.
|
||||
*/
|
||||
private setFilters(): void {
|
||||
this.dataSource.filterPredicate = (data, filter) => {
|
||||
if (!data || !data.information) {
|
||||
return false;
|
||||
}
|
||||
filter = filter ? filter.toLowerCase() : '';
|
||||
if (
|
||||
this.getElementInfo(data) &&
|
||||
this.getElementInfo(data)
|
||||
.toLowerCase()
|
||||
.indexOf(filter) >= 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (data.user && data.user.full_name.toLowerCase().indexOf(filter) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
this.parseInformation(data.information)
|
||||
.toLowerCase()
|
||||
.indexOf(filter) >= 0
|
||||
);
|
||||
};
|
||||
private async queryElementId(collectionString: string, id: number): Promise<void> {
|
||||
const historyData = await this.http.get<History[]>(`${environment.urlPrefix}/core/history/information/`, null, {
|
||||
type: 'element',
|
||||
value: `${collectionString}:${id}`
|
||||
});
|
||||
this.dataSource.data = historyData.map(data => new History(data));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
import { AppConfig } from '../../core/app-config';
|
||||
import { History } from 'app/shared/models/core/history';
|
||||
import { HistoryRepositoryService } from 'app/core/repositories/history/history-repository.service';
|
||||
import { ViewHistory } from './models/view-history';
|
||||
|
||||
/**
|
||||
* Config object for history.
|
||||
@ -9,14 +6,6 @@ import { ViewHistory } from './models/view-history';
|
||||
*/
|
||||
export const HistoryAppConfig: AppConfig = {
|
||||
name: 'history',
|
||||
models: [
|
||||
{
|
||||
collectionString: 'core/history',
|
||||
model: History,
|
||||
viewModel: ViewHistory,
|
||||
repository: HistoryRepositoryService
|
||||
}
|
||||
],
|
||||
mainMenuEntries: [
|
||||
{
|
||||
route: '/history',
|
||||
|
@ -1,102 +0,0 @@
|
||||
import { BaseViewModel } from 'app/site/base/base-view-model';
|
||||
import { History } from 'app/shared/models/core/history';
|
||||
import { ViewUser } from 'app/site/users/models/view-user';
|
||||
|
||||
export type ProxyHistory = History & { user?: ViewUser };
|
||||
|
||||
export interface HistoryTitleInformation {
|
||||
element_id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* View model for history objects
|
||||
*/
|
||||
export class ViewHistory extends BaseViewModel<ProxyHistory> implements HistoryTitleInformation {
|
||||
public static COLLECTIONSTRING = History.COLLECTIONSTRING;
|
||||
|
||||
/**
|
||||
* Read the history property
|
||||
*/
|
||||
public get history(): ProxyHistory {
|
||||
return this._model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the users ViewUser.
|
||||
*/
|
||||
public get user(): ViewUser | null {
|
||||
return this.history.user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the history object
|
||||
* Required by BaseViewModel
|
||||
*
|
||||
* @returns the id as number
|
||||
*/
|
||||
public get id(): number {
|
||||
return this.history.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the users full name
|
||||
*/
|
||||
public get user_full_name(): string {
|
||||
return this.history.user ? this.history.user.full_name : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the elementIDs of the history object
|
||||
*
|
||||
* @returns the element ID as String
|
||||
*/
|
||||
public get element_id(): string {
|
||||
return this.history.element_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the information about the history
|
||||
*
|
||||
* @returns a string with the information to the history object
|
||||
*/
|
||||
public get information(): string {
|
||||
return this.history.information;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time of the history as number
|
||||
*
|
||||
* @returns the unix timestamp as number
|
||||
*/
|
||||
public get now(): string {
|
||||
return this.history.now;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construction of a ViewHistory
|
||||
*
|
||||
* @param history the real history BaseModel
|
||||
* @param user the real user BaseModel
|
||||
*/
|
||||
public constructor(history: ProxyHistory) {
|
||||
super(History.COLLECTIONSTRING, history);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts elementID into collection string
|
||||
* @returns the CollectionString to the model
|
||||
*/
|
||||
public getCollectionString(): string {
|
||||
return this.element_id.split(':')[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the models ID from the elementID
|
||||
* @returns a model id
|
||||
*/
|
||||
public getModelId(): number {
|
||||
return +this.element_id.split(':')[1];
|
||||
}
|
||||
|
||||
public updateDependencies(update: BaseViewModel): void {}
|
||||
}
|
@ -530,6 +530,9 @@ button.mat-menu-item.selected {
|
||||
.spacer-left-10 {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.spacer-left-20 {
|
||||
margin-left: 20px;
|
||||
}
|
||||
.spacer-left-50 {
|
||||
margin-left: 50px !important;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
],
|
||||
"no-arg": true,
|
||||
"no-bitwise": true,
|
||||
"no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
|
||||
"no-console": [true, "table", "clear", "count", "countReset", "info", "time", "timeEnd", "timeline", "timelineEnd", "trace"],
|
||||
"no-construct": true,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-super": true,
|
||||
|
@ -494,7 +494,6 @@ class HistoryInformationView(utils_views.APIView):
|
||||
Examples:
|
||||
|
||||
/?type=element&value=motions%2Fmotion%3A42 if your search for motion 42
|
||||
/?type=text&value=my%20question
|
||||
|
||||
Use DELETE to clear the history.
|
||||
"""
|
||||
@ -509,15 +508,12 @@ class HistoryInformationView(utils_views.APIView):
|
||||
self.permission_denied(self.request)
|
||||
type = self.request.query_params.get("type")
|
||||
value = self.request.query_params.get("value")
|
||||
if type not in ("element", "text"):
|
||||
if type not in ("element"):
|
||||
raise ValidationError(
|
||||
{"detail": "Invalid input. Type should be 'element' or 'text'."}
|
||||
)
|
||||
if type == "element":
|
||||
# We currently just support searching by element id.
|
||||
data = self.get_data_element_search(value)
|
||||
else:
|
||||
# type == "text"
|
||||
data = self.get_data_text_search(value)
|
||||
return data
|
||||
|
||||
def get_data_element_search(self, value):
|
||||
@ -525,7 +521,7 @@ class HistoryInformationView(utils_views.APIView):
|
||||
Retrieves history information for element search.
|
||||
"""
|
||||
data = []
|
||||
for instance in History.objects.filter(element_id=value):
|
||||
for instance in History.objects.filter(element_id=value).order_by("-now"):
|
||||
data.append(
|
||||
{
|
||||
"element_id": instance.element_id,
|
||||
@ -537,13 +533,6 @@ class HistoryInformationView(utils_views.APIView):
|
||||
)
|
||||
return data
|
||||
|
||||
def get_data_text_search(self, value):
|
||||
"""
|
||||
Retrieves history information for text search.
|
||||
"""
|
||||
# TODO: Add results here.
|
||||
return []
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
"""
|
||||
Deletes and rebuilds the history.
|
||||
|
@ -111,7 +111,7 @@ class WebsocketThroughputLogger:
|
||||
async def check_and_flush(self) -> None:
|
||||
# If we waited longer then 60 seconds, flush the data.
|
||||
current_time = time.time()
|
||||
if current_time > (self.time + 20):
|
||||
if current_time > (self.time + 60):
|
||||
|
||||
send_ratio = receive_ratio = 1.0
|
||||
if self.send_compressed > 0:
|
||||
|
Loading…
Reference in New Issue
Block a user