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 14KB

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