main-menu.component.ts 8.1 KB

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