cotisationsMenu.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { NuxtConfig } from '@nuxt/types/config'
  2. import { Ability } from '@casl/ability'
  3. import { ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  4. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  5. /**
  6. * @category composables/layout/Menus
  7. * @class CotisationsMenu
  8. * Classe pour la construction du Menu Cotisation (CMF)
  9. */
  10. class CotisationsMenu extends BaseMenu implements Menu {
  11. private $ability: Ability;
  12. /**
  13. * @constructor
  14. * Initialisation des services issues du context
  15. */
  16. constructor ($config: NuxtConfig, $ability: Ability) {
  17. super($config)
  18. this.$ability = $ability
  19. }
  20. /**
  21. * Construit le menu Cotisations ou null si aucune page accessible
  22. * @return {ItemMenu | null}
  23. */
  24. getMenu (): ItemMenu | null {
  25. const children: ItemsMenu = []
  26. if (this.$ability.can('display', 'rate_cotisation_page')) {
  27. children.push(this.constructMenu('rate_cotisation', 'fa-euro-sign', '/cotisation/rate', true))
  28. }
  29. if (this.$ability.can('display', 'parameters_cotisation_page')) {
  30. children.push(this.constructMenu('parameters_cotisation', 'fa-euro-sign', '/cotisation/parameter', true))
  31. }
  32. if (this.$ability.can('display', 'send_cotisation_page')) {
  33. children.push(this.constructMenu('send_cotisation', 'fa-euro-sign', '/cotisation/send', true))
  34. }
  35. if (this.$ability.can('display', 'state_cotisation_page')) {
  36. children.push(this.constructMenu('state_cotisation', 'fa-euro-sign', '/cotisation/state', true))
  37. }
  38. if (this.$ability.can('display', 'pay_cotisation_page')) {
  39. children.push(this.constructMenu('pay_cotisation', 'fa-euro-sign', '/cotisation/pay', true))
  40. }
  41. if (this.$ability.can('display', 'check_cotisation_page')) {
  42. children.push(this.constructMenu('check_cotisation', 'fa-euro-sign', '/cotisation/check', true))
  43. }
  44. if (this.$ability.can('display', 'ledger_cotisation_page')) {
  45. children.push(this.constructMenu('ledger_cotisation', 'fa-euro-sign', '/cotisation/ledger', true))
  46. }
  47. if (this.$ability.can('display', 'magazine_cotisation_page')) {
  48. children.push(this.constructMenu('magazine_cotisation', 'fa-euro-sign', '/cotisation/magazine', true))
  49. }
  50. if (this.$ability.can('display', 'ventilated_cotisation_page')) {
  51. children.push(this.constructMenu('ventilated_cotisation', 'fa-euro-sign', '/cotisation/ventilated', true))
  52. }
  53. if (this.$ability.can('display', 'pay_erase_cotisation_page')) {
  54. children.push(this.constructMenu('pay_erase_cotisation', 'fa-euro-sign', '/cotisation/payerase', true))
  55. }
  56. if (this.$ability.can('display', 'resume_cotisation_page')) {
  57. children.push(this.constructMenu('resume_cotisation', 'fa-euro-sign', '/cotisation/resume', true))
  58. }
  59. if (this.$ability.can('display', 'history_cotisation_page')) {
  60. children.push(this.constructMenu('history_cotisation', 'fa-euro-sign', '/cotisation/history', true))
  61. }
  62. if (this.$ability.can('display', 'call_cotisation_page')) {
  63. children.push(this.constructMenu('call_cotisation', 'fa-euro-sign', '/cotisation/call', true))
  64. }
  65. if (this.$ability.can('display', 'history_struture_cotisation_page')) {
  66. children.push(this.constructMenu('history_struture_cotisation', 'fa-euro-sign', '/cotisation/historystructure', true))
  67. }
  68. if (this.$ability.can('display', 'insurance_cotisation_page')) {
  69. children.push(this.constructMenu('insurance_cotisation', 'fa-euro-sign', '/cotisation/insurance', true))
  70. }
  71. if (this.$ability.can('display', 'resume_all_cotisation_page')) {
  72. children.push(this.constructMenu('resume_all_cotisation', 'fa-euro-sign', '/cotisation/resumeall', true))
  73. }
  74. if (this.$ability.can('display', 'resume_pay_cotisation_page')) {
  75. children.push(this.constructMenu('resume_pay_cotisation', 'fa-euro-sign', '/cotisation/resumepay', true))
  76. }
  77. if (children.length === 1) {
  78. return children[0]
  79. } else if (children.length > 0) {
  80. return this.constructMenu('cotisations', 'fa-money-bill', undefined, undefined, children)
  81. } else {
  82. return null
  83. }
  84. }
  85. }
  86. export const getCotisationsMenu = ($config: NuxtConfig, $ability: Ability) => new CotisationsMenu($config, $ability).getMenu()