| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import { Skill } from "./SolverInput";
- export interface ICompetence {
- id?: number;
- name: string;
- description: string;
- isPreference?: boolean;
- isTeachable?: boolean;
- }
- export default class Competence {
- static maxId = 0;
- id: number;
- name: string;
- description: string;
- private _isPreference!: boolean;
- renderPreference!: string;
- renderTeachable!: string;
- public get isPreference(): boolean {
- return this._isPreference;
- }
- public set isPreference(value: boolean) {
- this._isPreference = value;
- this.renderPreference = Competence.getBox(value);
- }
- private _isTeachable!: boolean;
- public get isTeachable(): boolean {
- return this._isTeachable;
- }
- public set isTeachable(value: boolean) {
- this._isTeachable = value;
- this.renderTeachable = Competence.getBox(value);
- }
- constructor(
- id: number,
- name: string,
- description: string,
- isPreference = true,
- isTeachable = false
- ) {
- // Change the current max id
- if (!isNaN(id)) Competence.maxId = id > Competence.maxId ? id : Competence.maxId;
- this.id = id;
- this.name = name;
- this.description = description;
- this.isPreference = isPreference;
- this.isTeachable = isTeachable;
- }
- static getBox(v: boolean): string {
- return `<i class="material-icons">${v ? "check_box" : "check_box_outline_blank"}</i>`;
- }
- get overflowDescription(): string {
- // TODO implement tooltiped description
- return this.description;
- }
- get fullname(): string {
- return this.name + (this.isPreference ? " (P)" : " (C)");
- }
- static fromObject(obj: ICompetence): Competence {
- let id: number;
- if (obj.id && !isNaN(obj.id)) {
- id = obj.id;
- this.maxId = obj.id > this.maxId ? obj.id : this.maxId;
- } else {
- this.maxId += 1;
- id = this.maxId;
- }
- return new Competence(
- id,
- obj.name,
- obj.description ? obj.description : "",
- obj.isPreference !== undefined ? obj.isPreference : true,
- obj.isTeachable !== undefined ? obj.isTeachable : false
- );
- }
- toPlainObject(): ICompetence {
- return {
- id: this.id,
- name: this.name,
- description: this.description,
- isPreference: this.isPreference,
- isTeachable: this.isTeachable,
- };
- }
- toSkill(): Skill {
- return {
- id: this.id,
- name: this.name,
- isPreference: this.isPreference,
- isTeachable: this.isTeachable,
- };
- }
- toJSON(): ICompetence {
- return this.toPlainObject();
- }
- static fromJSON(input: string | ICompetence): Competence {
- let obj: ICompetence;
- if (typeof input == "string") {
- obj = JSON.parse(input);
- } else {
- obj = input as ICompetence;
- }
- return Competence.fromObject(obj);
- }
- }
|