app.config.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. iperlemmas: LemmatizedEntitiesListsConfig;
  89. relations: LemmatizedEntitiesListsConfig;
  90. }>;
  91. lemsSelectItems: LemsSelectItemGroup[];
  92. iperlemsSelectItems: IperlemsSelectItemGroup[];
  93. entitiesSelectItems: EntitiesSelectItemGroup[];
  94. notSignificantVariants: string[];
  95. lemNotSignificantVariants: string[];
  96. defaultEdition: EditionLevelType;
  97. defaultViewMode: ViewModeId;
  98. availableViewModes: ViewMode[];
  99. proseVersesToggler: boolean;
  100. defaultTextFlow: TextFlow;
  101. verseNumberPrinter: number;
  102. }
  103. export type EditionImagesSources = 'manifest' | 'graphics';
  104. export interface FileConfig {
  105. editionUrls: string[];
  106. editionImagesSource: {
  107. [T in EditionImagesSources]: EditionImagesConfig;
  108. };
  109. logoUrl?: string;
  110. imagesFolderUrl?: string;
  111. }
  112. export interface EditionImagesConfig {
  113. value: string;
  114. enabled: boolean;
  115. }
  116. export interface NamedEntitiesListsConfig {
  117. defaultLabel: string;
  118. enabled: boolean;
  119. }
  120. // add by FS
  121. export interface LemmatizedEntitiesListsConfig {
  122. defaultLabel: string;
  123. enabled: boolean;
  124. }
  125. export type EditionLevelType = 'diplomatic' | 'interpretative' | 'critical';
  126. export interface EditionLevel {
  127. id: EditionLevelType;
  128. label: string;
  129. title?: string;
  130. disabled?: boolean;
  131. }
  132. export interface EditorialConventionsConfig {
  133. [key: string]: CustomEditorialConvention;
  134. }
  135. export interface CustomEditorialConvention {
  136. layouts: { // indicate the output style to be assigned for the indicated encoding for each edition level
  137. [key in EditionLevelType]: EditorialConventionLayout;
  138. };
  139. markup: { // Identifies the element depending on its encoding
  140. element: string;
  141. attributes: Attributes;
  142. };
  143. }
  144. export type TextFlow = 'prose' | 'verses';