Competence.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. interface ICompetence {
  2. id: number;
  3. name: string;
  4. description: string;
  5. isPreference: boolean;
  6. isTeachable: boolean;
  7. }
  8. export default class Competence {
  9. static maxId = 0;
  10. id: number;
  11. name: string;
  12. description: string;
  13. isPreference: boolean;
  14. isTeachable: boolean;
  15. constructor(id: number, name: string, description: string, isPreference: boolean) {
  16. // Change the current max id
  17. if (!isNaN(id)) Competence.maxId = id > Competence.maxId ? id : Competence.maxId;
  18. this.id = id;
  19. this.name = name;
  20. this.description = description;
  21. this.isPreference = isPreference;
  22. this.isTeachable = false;
  23. }
  24. get renderPreference(): string {
  25. const icon = this.isPreference ? "check_box" : "check_box_outline_blank";
  26. return '<i class="material-icons">' + icon + "</i>";
  27. }
  28. get renderTeachable(): string {
  29. const icon = this.isTeachable ? "check_box" : "check_box_outline_blank";
  30. return '<i class="material-icons">' + icon + "</i>";
  31. }
  32. get overflowDescription(): string {
  33. return this.description;
  34. }
  35. get fullname(): string {
  36. return this.name + (this.isPreference ? " (P)" : " (C)");
  37. }
  38. static fromObject(obj: ICompetence): Competence {
  39. let id: number;
  40. if (isNaN(obj.id)) {
  41. this.maxId += 1;
  42. id = this.maxId;
  43. } else {
  44. id = obj.id;
  45. this.maxId = obj.id > this.maxId ? obj.id : this.maxId;
  46. }
  47. return new Competence(
  48. id,
  49. obj.name,
  50. obj.description ? obj.description : "",
  51. obj.isPreference ? obj.isPreference : false
  52. );
  53. }
  54. toPlainObject(): ICompetence {
  55. return {
  56. id: this.id,
  57. name: this.name,
  58. description: this.description,
  59. isPreference: this.isPreference,
  60. isTeachable: this.isTeachable,
  61. };
  62. }
  63. }