main-menu.component.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import { Component, EventEmitter, OnDestroy, OnInit, Output } from '@angular/core';
  2. import { TranslateService } from '@ngx-translate/core';
  3. import { Observable, of } from 'rxjs';
  4. import { map } from 'rxjs/operators';
  5. import { AppConfig } from '../app.config';
  6. import { GlobalListsComponent } from '../components/global-lists/global-lists.component';
  7. import { ProjectInfoComponent } from '../components/project-info/project-info.component';
  8. import { EvtInfoComponent } from '../evt-info/evt-info.component';
  9. import { EVTModelService } from '../services/evt-model.service';
  10. import { ColorTheme, ThemesService } from '../services/themes.service';
  11. import { ShortcutsComponent } from '../shortcuts/shortcuts.component';
  12. import { EvtIconInfo } from '../ui-components/icon/icon.component';
  13. import { ModalComponent } from '../ui-components/modal/modal.component';
  14. import { ModalService } from '../ui-components/modal/modal.service';
  15. @Component({
  16. selector: 'evt-main-menu',
  17. templateUrl: './main-menu.component.html',
  18. styleUrls: ['./main-menu.component.scss'],
  19. })
  20. export class MainMenuComponent implements OnInit, OnDestroy {
  21. @Output() itemClicked = new EventEmitter<string>();
  22. public dynamicItems: MainMenuItem[] = [];
  23. public uiConfig = AppConfig.evtSettings.ui;
  24. public fileConfig = AppConfig.evtSettings.files;
  25. public editionConfig = AppConfig.evtSettings.edition;
  26. private isOpened = false;
  27. private subscriptions = [];
  28. private availableLangs = AppConfig.evtSettings.ui.availableLanguages.filter((l) => l.enabled);
  29. constructor(
  30. public themes: ThemesService,
  31. public translate: TranslateService,
  32. private modalService: ModalService,
  33. private evtModelService: EVTModelService,
  34. ) {
  35. }
  36. ngOnInit() {
  37. this.loadUiConfig();
  38. this.isOpened = true;
  39. }
  40. closeMenu() {
  41. if (this.isOpened) {
  42. this.isOpened = false;
  43. this.itemClicked.emit('close');
  44. }
  45. }
  46. private loadUiConfig(): void {
  47. this.initDynamicItems();
  48. }
  49. private initDynamicItems() {
  50. // TODO Check if available from uiConfig
  51. this.dynamicItems = [
  52. {
  53. id: 'projectInfo',
  54. iconInfo: {
  55. icon: 'info-circle',
  56. additionalClasses: 'icon',
  57. },
  58. label: 'projectInfo',
  59. enabled$: of(true),
  60. callback: () => this.openGlobalDialogInfo(),
  61. },
  62. {
  63. id: 'openLists',
  64. iconInfo: {
  65. icon: 'clipboard-list',
  66. additionalClasses: 'icon',
  67. },
  68. label: 'openLists',
  69. enabled$: this.evtModelService.namedEntities$.pipe(
  70. map(ne => this.editionConfig.showLists && ne.all.entities.length > 0),
  71. ),
  72. callback: () => this.openGlobalDialogLists(),
  73. },
  74. {
  75. id: 'bookmark',
  76. iconInfo: {
  77. icon: 'bookmark',
  78. additionalClasses: 'icon',
  79. },
  80. label: 'bookmark',
  81. enabled$: of(true),
  82. callback: () => this.generateBookmark(),
  83. },
  84. {
  85. id: 'downloadXML',
  86. iconInfo: {
  87. icon: 'download',
  88. additionalClasses: 'icon',
  89. },
  90. label: 'downloadXML',
  91. enabled$: of(true),
  92. callback: () => this.downloadXML(),
  93. },
  94. ];
  95. }
  96. private openGlobalDialogInfo() {
  97. this.itemClicked.emit('globalInfo');
  98. const modalRef = this.modalService.open(ModalComponent, { id: 'project-info', animation: false });
  99. const modalComp = modalRef.componentInstance as ModalComponent;
  100. modalComp.fixedHeight = true;
  101. modalComp.wider = true;
  102. modalComp.modalId = 'project-info';
  103. modalComp.title = 'projectInfo';
  104. modalComp.bodyContentClass = 'p-0 h-100';
  105. modalComp.headerIcon = { icon: 'info', iconSet: 'fas', additionalClasses: 'mr-3' };
  106. modalComp.bodyComponent = ProjectInfoComponent;
  107. }
  108. private openGlobalDialogLists() {
  109. this.itemClicked.emit('lists');
  110. const modalRef = this.modalService.open(ModalComponent, { id: 'global-lists' });
  111. const modalComp = modalRef.componentInstance as ModalComponent;
  112. modalComp.fixedHeight = true;
  113. modalComp.wider = true;
  114. modalComp.modalId = 'global-lists';
  115. modalComp.title = 'lists';
  116. modalComp.bodyContentClass = 'p-0 h-100';
  117. modalComp.headerIcon = { icon: 'clipboard-list', iconSet: 'fas', additionalClasses: 'mr-3' };
  118. modalComp.bodyComponent = GlobalListsComponent;
  119. }
  120. private generateBookmark() {
  121. // TODO generateBookmark
  122. this.itemClicked.emit('bookmark');
  123. }
  124. private downloadXML() {
  125. // TODO downloadXML
  126. this.itemClicked.emit('downloadXML');
  127. if (this.fileConfig && this.fileConfig.editionUrls) {
  128. this.fileConfig.editionUrls.forEach(url => window.open(url, '_blank'));
  129. } else {
  130. alert('Loading data... \nPlease try again later.');
  131. }
  132. }
  133. openShortCuts() {
  134. this.itemClicked.emit('shortcuts');
  135. const modalRef = this.modalService.open(ModalComponent, { id: 'shortcuts' });
  136. const modalComp = modalRef.componentInstance as ModalComponent;
  137. modalComp.fixedHeight = true;
  138. modalComp.modalId = 'shortcuts';
  139. modalComp.title = 'shortcuts';
  140. modalComp.bodyContentClass = 'p-3';
  141. modalComp.headerIcon = { icon: 'keyboard', iconSet: 'fas', additionalClasses: 'mr-3' };
  142. modalComp.bodyComponent = ShortcutsComponent;
  143. }
  144. // LANGUAGE
  145. selectLanguage(event: MouseEvent, languageSelected: Language) {
  146. event.stopPropagation();
  147. this.translate.use(languageSelected.code);
  148. this.itemClicked.emit('language');
  149. }
  150. getAvailableLanguages() {
  151. return this.availableLangs;
  152. }
  153. // THEMES
  154. selectTheme(event: MouseEvent, theme: ColorTheme) {
  155. event.stopPropagation();
  156. this.itemClicked.emit('theme');
  157. this.themes.selectTheme(theme);
  158. }
  159. getAvailableThemes(): ColorTheme[] {
  160. return this.themes.getAvailableThemes();
  161. }
  162. getCurrentTheme() {
  163. return this.themes.getCurrentTheme();
  164. }
  165. openEVTInfo() {
  166. this.itemClicked.emit('evtInfo');
  167. const modalRef = this.modalService.open(ModalComponent, { id: 'evtInfo' });
  168. const modalComp = modalRef.componentInstance as ModalComponent;
  169. modalComp.fixedHeight = true;
  170. modalComp.modalId = 'evtInfo';
  171. modalComp.title = 'aboutEVT';
  172. modalComp.bodyContentClass = 'p-3';
  173. modalComp.headerIcon = { icon: 'copyright', iconSet: 'fas', additionalClasses: 'mr-3' };
  174. modalComp.bodyComponent = EvtInfoComponent;
  175. }
  176. // tslint:disable-next-line: variable-name
  177. trackMenuItem(_index: number, item: MainMenuItem) {
  178. return item.id;
  179. }
  180. // tslint:disable-next-line: variable-name
  181. trackLanguages(_index: number, item: Language) {
  182. return item.code;
  183. }
  184. // tslint:disable-next-line: variable-name
  185. trackTheme(_index: number, item: ColorTheme) {
  186. return item.value;
  187. }
  188. ngOnDestroy() {
  189. this.subscriptions.forEach(subscription => subscription.unsubscribe());
  190. }
  191. }
  192. export interface Language {
  193. code: string;
  194. label: string;
  195. }
  196. export interface MainMenuItem {
  197. id: string;
  198. iconInfo: EvtIconInfo;
  199. label: string;
  200. enabled$: Observable<boolean>;
  201. callback: () => void;
  202. }