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-08 16:02:46 +01:00
|
|
|
import { Collection } from 'app/shared/models/base/collection';
|
2019-02-01 13:56:08 +01:00
|
|
|
|
|
|
|
export type ViewModelConstructor<T extends BaseViewModel> = new (...args: any[]) => T;
|
2018-09-10 15:53:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for view models. alls view models should have titles.
|
|
|
|
*/
|
2019-02-08 16:02:46 +01:00
|
|
|
export abstract class BaseViewModel implements Displayable, Identifiable, Collection {
|
2018-09-20 12:25:37 +02:00
|
|
|
/**
|
|
|
|
* Force children to have an id.
|
|
|
|
*/
|
|
|
|
public abstract id: number;
|
|
|
|
|
2019-02-01 13:56:08 +01:00
|
|
|
/**
|
2019-02-08 16:02:46 +01:00
|
|
|
* force children of BaseModel to have a collectionString.
|
|
|
|
*
|
|
|
|
* Has a getter but no setter.
|
2019-02-01 13:56:08 +01:00
|
|
|
*/
|
2019-02-08 16:02:46 +01:00
|
|
|
protected _collectionString: string;
|
2019-02-01 13:56:08 +01:00
|
|
|
|
2019-02-08 16:02:46 +01:00
|
|
|
/**
|
|
|
|
* returns the collectionString.
|
|
|
|
*
|
|
|
|
* The server and the dataStore use it to identify the collection.
|
|
|
|
*/
|
|
|
|
public get collectionString(): string {
|
|
|
|
return this._collectionString;
|
2019-02-01 13:56:08 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:02:46 +01:00
|
|
|
public abstract getTitle: () => string;
|
|
|
|
|
2019-02-01 13:56:08 +01:00
|
|
|
/**
|
2019-02-08 16:02:46 +01:00
|
|
|
* Returns the verbose name.
|
2019-02-01 13:56:08 +01:00
|
|
|
*
|
|
|
|
* @param plural If the name should be plural
|
|
|
|
* @returns the verbose name of the model
|
|
|
|
*/
|
2019-02-08 16:02:46 +01:00
|
|
|
public abstract getVerboseName: (plural?: boolean) => string;
|
2018-09-10 15:53:11 +02:00
|
|
|
|
2019-02-08 16:02:46 +01:00
|
|
|
/**
|
|
|
|
* TODO: Remove verboseName, this must be overwritten by repos..
|
|
|
|
*
|
|
|
|
* @param verboseName
|
|
|
|
* @param collectionString
|
|
|
|
*/
|
|
|
|
public constructor(collectionString: string) {
|
|
|
|
this._collectionString = collectionString;
|
|
|
|
}
|
2018-09-10 15:53:11 +02:00
|
|
|
|
2019-02-08 16:02:46 +01:00
|
|
|
public getListTitle: () => string = () => {
|
2018-09-13 09:23:57 +02:00
|
|
|
return this.getTitle();
|
2019-02-08 16:02:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
public abstract updateDependencies(update: BaseViewModel): void;
|
2018-09-10 15:53:11 +02:00
|
|
|
|
2018-09-13 09:23:57 +02:00
|
|
|
public toString(): string {
|
|
|
|
return this.getTitle();
|
2018-09-10 15:53:11 +02:00
|
|
|
}
|
|
|
|
}
|