base-view.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { ReflectiveInjector } from "@angular/core";
  2. import { getMetadataStorage } from "../odoo/utils/metadata-storage";
  3. export class BaseView<T> {
  4. type: T = {} as T;
  5. model: any = {};
  6. injector: any = {};
  7. title: string;
  8. constructor(c: { new (): T; }, ...injectables: any[]) {
  9. this.type = new c();
  10. this.model = getMetadataStorage().models.filterByTarget(this.type.constructor).items.shift();
  11. this.injector = ReflectiveInjector.resolveAndCreate(injectables);
  12. this.title = "Sin título";
  13. }
  14. /**
  15. *
  16. * @param injectable
  17. */
  18. getInjectable(injectable: any): any {
  19. return this.injector.get(injectable);
  20. }
  21. /**
  22. *
  23. */
  24. getTitle(): string {
  25. return this.title;
  26. }
  27. /**
  28. *
  29. * @param title
  30. */
  31. setTitle(title: string): void {
  32. this.title = title;
  33. }
  34. /**
  35. *
  36. */
  37. getType(): T {
  38. return this.type;
  39. }
  40. /**
  41. *
  42. */
  43. getModel(): any {
  44. return this.model;
  45. }
  46. /**
  47. *
  48. */
  49. getModelName(): string {
  50. return this.getModel().name;
  51. }
  52. /**
  53. *
  54. */
  55. getInjector(): any {
  56. return this.injector;
  57. }
  58. }