app.config.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { HttpClient } from '@angular/common/http';
  2. import { Injectable } from '@angular/core';
  3. import { TranslateService } from '@ngx-translate/core';
  4. import { forkJoin } from 'rxjs';
  5. import { map } from 'rxjs/operators';
  6. import { EntitiesSelectItemGroup } from './components/entities-select/entities-select.component';
  7. import { LemsSelectItemGroup } from './components/lems-select/lems-select.component';
  8. import { IperlemsSelectItemGroup } from './components/iperlems-select/iperlems-select.component';
  9. import { ViewMode, ViewModeId } from './models/evt-models';
  10. import { Attributes, EditorialConventionLayout } from './models/evt-models';
  11. @Injectable()
  12. export class AppConfig {
  13. static evtSettings: EVTConfig;
  14. private readonly uiConfigUrl = 'assets/config/ui_config.json';
  15. private readonly fileConfigUrl = 'assets/config/file_config.json';
  16. private readonly editionConfigUrl = 'assets/config/edition_config.json';
  17. private readonly editorialConventionsConfigUrl = 'assets/config/editorial_conventions_config.json';
  18. constructor(
  19. public translate: TranslateService,
  20. private http: HttpClient,
  21. ) { }
  22. load() {
  23. return new Promise<void>((resolve) => {
  24. forkJoin([
  25. this.http.get<UiConfig>(this.uiConfigUrl),
  26. this.http.get<EditionConfig>(this.editionConfigUrl),
  27. this.http.get<FileConfig>(this.fileConfigUrl),
  28. this.http.get<EditorialConventionsConfig>(this.editorialConventionsConfigUrl),
  29. ]).pipe(
  30. map(([ui, edition, files, editorialConventions]) => {
  31. console.log(ui, edition, files);
  32. // Handle default values => TODO: Decide how to handle defaults!!
  33. if (ui.defaultLocalization) {
  34. if (ui.availableLanguages.find((l) => l.code === ui.defaultLocalization && l.enabled)) {
  35. this.translate.use(ui.defaultLocalization);
  36. } else {
  37. const firstAvailableLang = ui.availableLanguages.find((l) => l.enabled);
  38. if (firstAvailableLang) {
  39. this.translate.use(firstAvailableLang.code);
  40. }
  41. }
  42. }
  43. return { ui, edition, files, editorialConventions };
  44. }),
  45. ).subscribe(evtConfig => {
  46. AppConfig.evtSettings = evtConfig;
  47. console.log('evtConfig', evtConfig);
  48. resolve();
  49. });
  50. });
  51. }
  52. }
  53. export interface EVTConfig {
  54. ui: UiConfig;
  55. edition: EditionConfig;
  56. files: FileConfig;
  57. editorialConventions: EditorialConventionsConfig;
  58. }
  59. export interface UiConfig {
  60. localization: boolean;
  61. defaultLocalization: string;
  62. availableLanguages: Array<{
  63. code: string;
  64. label: string;
  65. enabled: boolean;
  66. }>;
  67. enableNavBar: boolean;
  68. initNavBarOpened: boolean;
  69. thumbnailsButton: boolean;
  70. viscollButton: boolean;
  71. }
  72. export interface EditionConfig {
  73. editionTitle: string;
  74. badge: string;
  75. editionHome: string;
  76. showLists: boolean;
  77. availableEditionLevels: EditionLevel[];
  78. namedEntitiesLists: Partial<{
  79. persons: NamedEntitiesListsConfig;
  80. places: NamedEntitiesListsConfig;
  81. organizations: NamedEntitiesListsConfig;
  82. relations: NamedEntitiesListsConfig;
  83. events: NamedEntitiesListsConfig;
  84. }>;
  85. // add by FS
  86. lemmatizedEntitiesLists: Partial<{
  87. lemmas: LemmatizedEntitiesListsConfig;
  88. relations: LemmatizedEntitiesListsConfig;
  89. }>;
  90. lemsSelectItems: LemsSelectItemGroup[];
  91. iperlemsSelectItems: IperlemsSelectItemGroup[];
  92. entitiesSelectItems: EntitiesSelectItemGroup[];
  93. notSignificantVariants: string[];
  94. lemNotSignificantVariants: string[];
  95. defaultEdition: EditionLevelType;
  96. defaultViewMode: ViewModeId;
  97. availableViewModes: ViewMode[];
  98. proseVersesToggler: boolean;
  99. defaultTextFlow: TextFlow;
  100. verseNumberPrinter: number;
  101. }
  102. export type EditionImagesSources = 'manifest' | 'graphics';
  103. export interface FileConfig {
  104. editionUrls: string[];
  105. editionImagesSource: {
  106. [T in EditionImagesSources]: EditionImagesConfig;
  107. };
  108. logoUrl?: string;
  109. imagesFolderUrl?: string;
  110. }
  111. export interface EditionImagesConfig {
  112. value: string;
  113. enabled: boolean;
  114. }
  115. export interface NamedEntitiesListsConfig {
  116. defaultLabel: string;
  117. enabled: boolean;
  118. }
  119. // add by FS
  120. export interface LemmatizedEntitiesListsConfig {
  121. defaultLabel: string;
  122. enabled: boolean;
  123. }
  124. export type EditionLevelType = 'diplomatic' | 'interpretative' | 'critical';
  125. export interface EditionLevel {
  126. id: EditionLevelType;
  127. label: string;
  128. title?: string;
  129. disabled?: boolean;
  130. }
  131. export interface EditorialConventionsConfig {
  132. [key: string]: CustomEditorialConvention;
  133. }
  134. export interface CustomEditorialConvention {
  135. layouts: { // indicate the output style to be assigned for the indicated encoding for each edition level
  136. [key in EditionLevelType]: EditorialConventionLayout;
  137. };
  138. markup: { // Identifies the element depending on its encoding
  139. element: string;
  140. attributes: Attributes;
  141. };
  142. }
  143. export type TextFlow = 'prose' | 'verses';