Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServicesManager.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. // @flow
  2. import i18n from 'i18n-js';
  3. import {StackNavigationProp} from '@react-navigation/stack';
  4. import AvailableWebsites from '../constants/AvailableWebsites';
  5. import ConnectionManager from './ConnectionManager';
  6. import type {FullDashboardType} from '../screens/Home/HomeScreen';
  7. import getStrippedServicesList from '../utils/Services';
  8. // AMICALE
  9. const CLUBS_IMAGE =
  10. 'https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png';
  11. const PROFILE_IMAGE =
  12. 'https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png';
  13. const EQUIPMENT_IMAGE =
  14. 'https://etud.insa-toulouse.fr/~amicale_app/images/Materiel.png';
  15. const VOTE_IMAGE = 'https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png';
  16. const AMICALE_IMAGE =
  17. 'https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png';
  18. // STUDENTS
  19. const PROXIMO_IMAGE =
  20. 'https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png';
  21. const WIKETUD_IMAGE =
  22. 'https://etud.insa-toulouse.fr/~amicale_app/images/Wiketud.png';
  23. const EE_IMAGE = 'https://etud.insa-toulouse.fr/~amicale_app/images/EEC.png';
  24. const TUTORINSA_IMAGE =
  25. 'https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png';
  26. // INSA
  27. const BIB_IMAGE = 'https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png';
  28. const RU_IMAGE = 'https://etud.insa-toulouse.fr/~amicale_app/images/RU.png';
  29. const ROOM_IMAGE =
  30. 'https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png';
  31. const EMAIL_IMAGE =
  32. 'https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png';
  33. const ENT_IMAGE = 'https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png';
  34. const ACCOUNT_IMAGE =
  35. 'https://etud.insa-toulouse.fr/~amicale_app/images/Account.png';
  36. // SPECIAL
  37. const WASHER_IMAGE =
  38. 'https://etud.insa-toulouse.fr/~amicale_app/images/ProxiwashLaveLinge.png';
  39. const DRYER_IMAGE =
  40. 'https://etud.insa-toulouse.fr/~amicale_app/images/ProxiwashSecheLinge.png';
  41. const AMICALE_LOGO = require('../../assets/amicale.png');
  42. export const SERVICES_KEY = {
  43. CLUBS: 'clubs',
  44. PROFILE: 'profile',
  45. EQUIPMENT: 'equipment',
  46. AMICALE_WEBSITE: 'amicale_website',
  47. VOTE: 'vote',
  48. PROXIMO: 'proximo',
  49. WIKETUD: 'wiketud',
  50. ELUS_ETUDIANTS: 'elus_etudiants',
  51. TUTOR_INSA: 'tutor_insa',
  52. RU: 'ru',
  53. AVAILABLE_ROOMS: 'available_rooms',
  54. BIB: 'bib',
  55. EMAIL: 'email',
  56. ENT: 'ent',
  57. INSA_ACCOUNT: 'insa_account',
  58. WASHERS: 'washers',
  59. DRYERS: 'dryers',
  60. };
  61. export const SERVICES_CATEGORIES_KEY = {
  62. AMICALE: 'amicale',
  63. STUDENTS: 'students',
  64. INSA: 'insa',
  65. SPECIAL: 'special',
  66. };
  67. export type ServiceItemType = {
  68. key: string,
  69. title: string,
  70. subtitle: string,
  71. image: string,
  72. onPress: () => void,
  73. badgeFunction?: (dashboard: FullDashboardType) => number,
  74. };
  75. export type ServiceCategoryType = {
  76. key: string,
  77. title: string,
  78. subtitle: string,
  79. image: string | number,
  80. content: Array<ServiceItemType>,
  81. };
  82. export default class ServicesManager {
  83. navigation: StackNavigationProp;
  84. amicaleDataset: Array<ServiceItemType>;
  85. studentsDataset: Array<ServiceItemType>;
  86. insaDataset: Array<ServiceItemType>;
  87. specialDataset: Array<ServiceItemType>;
  88. categoriesDataset: Array<ServiceCategoryType>;
  89. constructor(nav: StackNavigationProp) {
  90. this.navigation = nav;
  91. this.amicaleDataset = [
  92. {
  93. key: SERVICES_KEY.CLUBS,
  94. title: i18n.t('screens.clubs.title'),
  95. subtitle: i18n.t('screens.services.descriptions.clubs'),
  96. image: CLUBS_IMAGE,
  97. onPress: (): void => this.onAmicaleServicePress('club-list'),
  98. },
  99. {
  100. key: SERVICES_KEY.PROFILE,
  101. title: i18n.t('screens.profile.title'),
  102. subtitle: i18n.t('screens.services.descriptions.profile'),
  103. image: PROFILE_IMAGE,
  104. onPress: (): void => this.onAmicaleServicePress('profile'),
  105. },
  106. {
  107. key: SERVICES_KEY.EQUIPMENT,
  108. title: i18n.t('screens.equipment.title'),
  109. subtitle: i18n.t('screens.services.descriptions.equipment'),
  110. image: EQUIPMENT_IMAGE,
  111. onPress: (): void => this.onAmicaleServicePress('equipment-list'),
  112. },
  113. {
  114. key: SERVICES_KEY.AMICALE_WEBSITE,
  115. title: i18n.t('screens.websites.amicale'),
  116. subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
  117. image: AMICALE_IMAGE,
  118. onPress: (): void =>
  119. nav.navigate('website', {
  120. host: AvailableWebsites.websites.AMICALE,
  121. title: i18n.t('screens.websites.amicale'),
  122. }),
  123. },
  124. {
  125. key: SERVICES_KEY.VOTE,
  126. title: i18n.t('screens.vote.title'),
  127. subtitle: i18n.t('screens.services.descriptions.vote'),
  128. image: VOTE_IMAGE,
  129. onPress: (): void => this.onAmicaleServicePress('vote'),
  130. },
  131. ];
  132. this.studentsDataset = [
  133. {
  134. key: SERVICES_KEY.PROXIMO,
  135. title: i18n.t('screens.proximo.title'),
  136. subtitle: i18n.t('screens.services.descriptions.proximo'),
  137. image: PROXIMO_IMAGE,
  138. onPress: (): void => nav.navigate('proximo'),
  139. badgeFunction: (dashboard: FullDashboardType): number =>
  140. dashboard.proximo_articles,
  141. },
  142. {
  143. key: SERVICES_KEY.WIKETUD,
  144. title: 'Wiketud',
  145. subtitle: i18n.t('screens.services.descriptions.wiketud'),
  146. image: WIKETUD_IMAGE,
  147. onPress: (): void =>
  148. nav.navigate('website', {
  149. host: AvailableWebsites.websites.WIKETUD,
  150. title: 'Wiketud',
  151. }),
  152. },
  153. {
  154. key: SERVICES_KEY.ELUS_ETUDIANTS,
  155. title: 'Élus Étudiants',
  156. subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
  157. image: EE_IMAGE,
  158. onPress: (): void =>
  159. nav.navigate('website', {
  160. host: AvailableWebsites.websites.ELUS_ETUDIANTS,
  161. title: 'Élus Étudiants',
  162. }),
  163. },
  164. {
  165. key: SERVICES_KEY.TUTOR_INSA,
  166. title: "Tutor'INSA",
  167. subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
  168. image: TUTORINSA_IMAGE,
  169. onPress: (): void =>
  170. nav.navigate('website', {
  171. host: AvailableWebsites.websites.TUTOR_INSA,
  172. title: "Tutor'INSA",
  173. }),
  174. badgeFunction: (dashboard: FullDashboardType): number =>
  175. dashboard.available_tutorials,
  176. },
  177. ];
  178. this.insaDataset = [
  179. {
  180. key: SERVICES_KEY.RU,
  181. title: i18n.t('screens.menu.title'),
  182. subtitle: i18n.t('screens.services.descriptions.self'),
  183. image: RU_IMAGE,
  184. onPress: (): void => nav.navigate('self-menu'),
  185. badgeFunction: (dashboard: FullDashboardType): number =>
  186. dashboard.today_menu.length,
  187. },
  188. {
  189. key: SERVICES_KEY.AVAILABLE_ROOMS,
  190. title: i18n.t('screens.websites.rooms'),
  191. subtitle: i18n.t('screens.services.descriptions.availableRooms'),
  192. image: ROOM_IMAGE,
  193. onPress: (): void =>
  194. nav.navigate('website', {
  195. host: AvailableWebsites.websites.AVAILABLE_ROOMS,
  196. title: i18n.t('screens.websites.rooms'),
  197. }),
  198. },
  199. {
  200. key: SERVICES_KEY.BIB,
  201. title: i18n.t('screens.websites.bib'),
  202. subtitle: i18n.t('screens.services.descriptions.bib'),
  203. image: BIB_IMAGE,
  204. onPress: (): void =>
  205. nav.navigate('website', {
  206. host: AvailableWebsites.websites.BIB,
  207. title: i18n.t('screens.websites.bib'),
  208. }),
  209. },
  210. {
  211. key: SERVICES_KEY.EMAIL,
  212. title: i18n.t('screens.websites.mails'),
  213. subtitle: i18n.t('screens.services.descriptions.mails'),
  214. image: EMAIL_IMAGE,
  215. onPress: (): void =>
  216. nav.navigate('website', {
  217. host: AvailableWebsites.websites.BLUEMIND,
  218. title: i18n.t('screens.websites.mails'),
  219. }),
  220. },
  221. {
  222. key: SERVICES_KEY.ENT,
  223. title: i18n.t('screens.websites.ent'),
  224. subtitle: i18n.t('screens.services.descriptions.ent'),
  225. image: ENT_IMAGE,
  226. onPress: (): void =>
  227. nav.navigate('website', {
  228. host: AvailableWebsites.websites.ENT,
  229. title: i18n.t('screens.websites.ent'),
  230. }),
  231. },
  232. {
  233. key: SERVICES_KEY.INSA_ACCOUNT,
  234. title: i18n.t('screens.insaAccount.title'),
  235. subtitle: i18n.t('screens.services.descriptions.insaAccount'),
  236. image: ACCOUNT_IMAGE,
  237. onPress: (): void =>
  238. nav.navigate('website', {
  239. host: AvailableWebsites.websites.INSA_ACCOUNT,
  240. title: i18n.t('screens.insaAccount.title'),
  241. }),
  242. },
  243. ];
  244. this.specialDataset = [
  245. {
  246. key: SERVICES_KEY.WASHERS,
  247. title: i18n.t('screens.proxiwash.washers'),
  248. subtitle: i18n.t('screens.services.descriptions.washers'),
  249. image: WASHER_IMAGE,
  250. onPress: (): void => nav.navigate('proxiwash'),
  251. badgeFunction: (dashboard: FullDashboardType): number =>
  252. dashboard.available_washers,
  253. },
  254. {
  255. key: SERVICES_KEY.DRYERS,
  256. title: i18n.t('screens.proxiwash.dryers'),
  257. subtitle: i18n.t('screens.services.descriptions.washers'),
  258. image: DRYER_IMAGE,
  259. onPress: (): void => nav.navigate('proxiwash'),
  260. badgeFunction: (dashboard: FullDashboardType): number =>
  261. dashboard.available_dryers,
  262. },
  263. ];
  264. this.categoriesDataset = [
  265. {
  266. key: SERVICES_CATEGORIES_KEY.AMICALE,
  267. title: i18n.t('screens.services.categories.amicale'),
  268. subtitle: i18n.t('screens.services.more'),
  269. image: AMICALE_LOGO,
  270. content: this.amicaleDataset,
  271. },
  272. {
  273. key: SERVICES_CATEGORIES_KEY.STUDENTS,
  274. title: i18n.t('screens.services.categories.students'),
  275. subtitle: i18n.t('screens.services.more'),
  276. image: 'account-group',
  277. content: this.studentsDataset,
  278. },
  279. {
  280. key: SERVICES_CATEGORIES_KEY.INSA,
  281. title: i18n.t('screens.services.categories.insa'),
  282. subtitle: i18n.t('screens.services.more'),
  283. image: 'school',
  284. content: this.insaDataset,
  285. },
  286. {
  287. key: SERVICES_CATEGORIES_KEY.SPECIAL,
  288. title: i18n.t('screens.services.categories.special'),
  289. subtitle: i18n.t('screens.services.categories.special'),
  290. image: 'star',
  291. content: this.specialDataset,
  292. },
  293. ];
  294. }
  295. /**
  296. * Redirects the user to the login screen if he is not logged in
  297. *
  298. * @param route
  299. * @returns {null}
  300. */
  301. onAmicaleServicePress(route: string) {
  302. if (ConnectionManager.getInstance().isLoggedIn())
  303. this.navigation.navigate(route);
  304. else this.navigation.navigate('login', {nextScreen: route});
  305. }
  306. /**
  307. * Gets the list of amicale's services
  308. *
  309. * @param excludedItems Ids of items to exclude from the returned list
  310. * @returns {Array<ServiceItemType>}
  311. */
  312. getAmicaleServices(excludedItems?: Array<string>): Array<ServiceItemType> {
  313. if (excludedItems != null)
  314. return getStrippedServicesList(excludedItems, this.amicaleDataset);
  315. return this.amicaleDataset;
  316. }
  317. /**
  318. * Gets the list of students' services
  319. *
  320. * @param excludedItems Ids of items to exclude from the returned list
  321. * @returns {Array<ServiceItemType>}
  322. */
  323. getStudentServices(excludedItems?: Array<string>): Array<ServiceItemType> {
  324. if (excludedItems != null)
  325. return getStrippedServicesList(excludedItems, this.studentsDataset);
  326. return this.studentsDataset;
  327. }
  328. /**
  329. * Gets the list of INSA's services
  330. *
  331. * @param excludedItems Ids of items to exclude from the returned list
  332. * @returns {Array<ServiceItemType>}
  333. */
  334. getINSAServices(excludedItems?: Array<string>): Array<ServiceItemType> {
  335. if (excludedItems != null)
  336. return getStrippedServicesList(excludedItems, this.insaDataset);
  337. return this.insaDataset;
  338. }
  339. /**
  340. * Gets the list of special services
  341. *
  342. * @param excludedItems Ids of items to exclude from the returned list
  343. * @returns {Array<ServiceItemType>}
  344. */
  345. getSpecialServices(excludedItems?: Array<string>): Array<ServiceItemType> {
  346. if (excludedItems != null)
  347. return getStrippedServicesList(excludedItems, this.specialDataset);
  348. return this.specialDataset;
  349. }
  350. /**
  351. * Gets all services sorted by category
  352. *
  353. * @param excludedItems Ids of categories to exclude from the returned list
  354. * @returns {Array<ServiceCategoryType>}
  355. */
  356. getCategories(excludedItems?: Array<string>): Array<ServiceCategoryType> {
  357. if (excludedItems != null)
  358. return getStrippedServicesList(excludedItems, this.categoriesDataset);
  359. return this.categoriesDataset;
  360. }
  361. }