-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-activates the history mode (#1078)
- Loading branch information
1 parent
b7866b0
commit 5ceb330
Showing
61 changed files
with
1,437 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
client/src/app/gateways/presenter/history-presenter.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { HistoryPresenterService } from './history-presenter.service'; | ||
|
||
describe('HistoryPresenterService', () => { | ||
let service: HistoryPresenterService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(HistoryPresenterService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
92 changes: 92 additions & 0 deletions
92
client/src/app/gateways/presenter/history-presenter.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Collection, Fqid, Id } from 'src/app/domain/definitions/key-types'; | ||
import { HttpService } from 'src/app/gateways/http.service'; | ||
import { UserRepositoryService } from 'src/app/gateways/repositories/users'; | ||
import { collectionFromFqid } from 'src/app/infrastructure/utils/transform-functions'; | ||
|
||
interface InformationObject { | ||
[fqid: string]: string[]; | ||
} | ||
|
||
export class Position { | ||
public position: number; | ||
public timestamp: number; | ||
public information: InformationObject; | ||
public user_id: Id; | ||
public fqid: Fqid; | ||
|
||
public constructor(input?: Partial<Position>) { | ||
if (input) { | ||
Object.assign(this, input); | ||
} | ||
} | ||
} | ||
|
||
export class HistoryPosition extends Position { | ||
public user: string; | ||
|
||
public get date(): Date { | ||
return new Date(this.timestamp * 1000); | ||
} | ||
|
||
private get _collection(): Collection { | ||
return collectionFromFqid(this.fqid); | ||
} | ||
|
||
public constructor(input?: Partial<HistoryPosition>) { | ||
super(input); | ||
if (input) { | ||
Object.assign(this, input); | ||
} | ||
} | ||
|
||
/** | ||
* Converts the date (this.now) to a time and date string. | ||
* | ||
* @param locale locale indicator, i.e 'de-DE' | ||
* @returns a human readable kind of time and date representation | ||
*/ | ||
public getLocaleString(locale: string): string { | ||
return this.date.toLocaleString(locale); | ||
} | ||
|
||
public getPositionDescriptions(): string[] { | ||
const information = this.information[this.fqid]; | ||
return information.map(entry => entry.replace(`Object`, this._collection)); | ||
} | ||
} | ||
|
||
interface HistoryPresenterResponse { | ||
[fqid: string]: Position[]; | ||
} | ||
|
||
const HISTORY_ENDPOINT = `/system/autoupdate/history_information`; | ||
|
||
const getUniqueItems = (positions: Position[]) => { | ||
const positionMap: { [positionNumber: number]: Position } = {}; | ||
for (const position of positions) { | ||
positionMap[position.position] = position; | ||
} | ||
return Object.values(positionMap); | ||
}; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class HistoryPresenterService { | ||
public constructor(private http: HttpService, private userRepo: UserRepositoryService) {} | ||
|
||
public async call(fqid: Fqid): Promise<HistoryPosition[]> { | ||
const response = await this.http.post<HistoryPresenterResponse>(HISTORY_ENDPOINT, undefined, { fqid }); | ||
return Object.values(response) | ||
.flatMap(positions => getUniqueItems(positions)) | ||
.sort((positionA, positionB) => positionB.timestamp - positionA.timestamp) | ||
.map(position => { | ||
return new HistoryPosition({ | ||
...position, | ||
fqid, | ||
user: this.userRepo.getViewModel(position.user_id)?.getFullName() | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './functions'; | ||
export * from './nullable-partial'; | ||
export * from './functionable'; | ||
export * from './lang-to-locale'; |
Oops, something went wrong.