2019-07-26 11:46:59 +02:00
|
|
|
import { BaseModel } from 'app/shared/models/base/base-model';
|
|
|
|
import { Collection } from 'app/shared/models/base/collection';
|
2019-02-01 13:56:08 +01:00
|
|
|
import { Displayable } from './displayable';
|
2018-09-20 12:25:37 +02:00
|
|
|
import { Identifiable } from '../../shared/models/base/identifiable';
|
2019-02-01 13:56:08 +01:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
export type TitleInformation = object;
|
|
|
|
|
2019-02-12 09:25:56 +01:00
|
|
|
export interface ViewModelConstructor<T extends BaseViewModel> {
|
|
|
|
COLLECTIONSTRING: string;
|
|
|
|
new (...args: any[]): T;
|
|
|
|
}
|
2018-09-10 15:53:11 +02:00
|
|
|
|
|
|
|
/**
|
2019-09-26 14:07:33 +02:00
|
|
|
* Base class for view models.
|
2018-09-10 15:53:11 +02:00
|
|
|
*/
|
2019-09-26 14:07:33 +02:00
|
|
|
export abstract class BaseViewModel<M extends BaseModel = any> {
|
2019-06-17 13:45:16 +02:00
|
|
|
/**
|
|
|
|
* @returns the element id of the model
|
|
|
|
*/
|
|
|
|
public get elementId(): string {
|
2019-09-26 14:07:33 +02:00
|
|
|
return this._model.elementId;
|
2019-06-17 13:45:16 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:02:46 +01:00
|
|
|
/**
|
|
|
|
* @param collectionString
|
2019-04-23 16:57:35 +02:00
|
|
|
* @param model
|
2019-02-08 16:02:46 +01:00
|
|
|
*/
|
2019-08-05 15:00:21 +02:00
|
|
|
public constructor(protected _model: M) {}
|
2018-09-10 15:53:11 +02:00
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
/**
|
|
|
|
* @returns the main underlying model of the view model
|
|
|
|
*/
|
|
|
|
public getModel(): M {
|
|
|
|
return this._model;
|
|
|
|
}
|
2018-09-13 09:23:57 +02:00
|
|
|
public toString(): string {
|
|
|
|
return this.getTitle();
|
2018-09-10 15:53:11 +02:00
|
|
|
}
|
2019-09-26 14:07:33 +02:00
|
|
|
public toJSON(): M {
|
|
|
|
return this.getModel();
|
|
|
|
}
|
|
|
|
public getUpdatedModel(update: Partial<M>): M {
|
|
|
|
return this.getModel().getUpdatedVersion(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export interface BaseViewModel<M extends BaseModel = any> extends Displayable, Identifiable, Collection {
|
|
|
|
getTitle: () => string;
|
|
|
|
getListTitle: () => string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the verbose name.
|
|
|
|
*
|
|
|
|
* @param plural If the name should be plural
|
|
|
|
* @returns the verbose name of the model
|
|
|
|
*/
|
|
|
|
getVerboseName: (plural?: boolean) => string;
|
2018-09-10 15:53:11 +02:00
|
|
|
}
|