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
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2018-09-20 12:25:37 +02:00
|
|
|
export abstract class BaseViewModel implements Displayable, Identifiable {
|
|
|
|
/**
|
|
|
|
* Force children to have an id.
|
|
|
|
*/
|
|
|
|
public abstract id: number;
|
|
|
|
|
2019-02-01 13:56:08 +01:00
|
|
|
/**
|
|
|
|
* Children should also have a verbose name for generic display purposes
|
|
|
|
*/
|
|
|
|
protected _verboseName: string;
|
|
|
|
|
|
|
|
public constructor(verboseName: string) {
|
|
|
|
this._verboseName = verboseName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the verbose name. Makes it plural by adding a 's'.
|
|
|
|
*
|
|
|
|
* @param plural If the name should be plural
|
|
|
|
* @returns the verbose name of the model
|
|
|
|
*/
|
|
|
|
public getVerboseName(plural: boolean = false): string {
|
|
|
|
if (plural) {
|
|
|
|
return this._verboseName + 's'; // I love english. This works for all our models (participantS, electionS,
|
|
|
|
// topicS, motionS, (media)fileS, motion blockS, commentS, personal noteS, projectorS, messageS, countdownS, ...)
|
|
|
|
// Just categorIES need to overwrite this...
|
|
|
|
} else {
|
|
|
|
return this._verboseName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract updateDependencies(update: BaseViewModel): void;
|
2018-09-10 15:53:11 +02:00
|
|
|
|
2018-09-13 09:23:57 +02:00
|
|
|
public abstract getTitle(): string;
|
2018-09-10 15:53:11 +02:00
|
|
|
|
2018-09-13 09:23:57 +02:00
|
|
|
public getListTitle(): string {
|
|
|
|
return this.getTitle();
|
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
|
|
|
}
|
|
|
|
}
|