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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. export const SERVICES_KEY = {
  29. CLUBS: "clubs",
  30. PROFILE: "profile",
  31. EQUIPMENT: "equipment",
  32. AMICALE_WEBSITE: "amicale_website",
  33. VOTE: "vote",
  34. PROXIMO: "proximo",
  35. WIKETUD: "wiketud",
  36. ELUS_ETUDIANTS: "elus_etudiants",
  37. TUTOR_INSA: "tutor_insa",
  38. RU: "ru",
  39. AVAILABLE_ROOMS: "available_rooms",
  40. BIB: "bib",
  41. EMAIL: "email",
  42. ENT: "ent",
  43. INSA_ACCOUNT: "insa_account",
  44. WASHERS: "washers",
  45. DRYERS: "dryers",
  46. }
  47. export type ServiceItem = {
  48. key: string,
  49. title: string,
  50. subtitle: string,
  51. image: string,
  52. onPress: () => void,
  53. badgeFunction?: (dashboard: fullDashboard) => number,
  54. }
  55. export default class ServicesManager {
  56. navigation: StackNavigationProp;
  57. amicaleDataset: Array<ServiceItem>;
  58. studentsDataset: Array<ServiceItem>;
  59. insaDataset: Array<ServiceItem>;
  60. specialDataset: Array<ServiceItem>;
  61. constructor(nav: StackNavigationProp) {
  62. this.navigation = nav;
  63. this.amicaleDataset = [
  64. {
  65. key: SERVICES_KEY.CLUBS,
  66. title: i18n.t('screens.clubs.title'),
  67. subtitle: i18n.t('screens.services.descriptions.clubs'),
  68. image: CLUBS_IMAGE,
  69. onPress: () => this.onAmicaleServicePress("club-list"),
  70. },
  71. {
  72. key: SERVICES_KEY.PROFILE,
  73. title: i18n.t('screens.profile.title'),
  74. subtitle: i18n.t('screens.services.descriptions.profile'),
  75. image: PROFILE_IMAGE,
  76. onPress: () => this.onAmicaleServicePress("profile"),
  77. },
  78. {
  79. key: SERVICES_KEY.EQUIPMENT,
  80. title: i18n.t('screens.equipment.title'),
  81. subtitle: i18n.t('screens.services.descriptions.equipment'),
  82. image: EQUIPMENT_IMAGE,
  83. onPress: () => this.onAmicaleServicePress("equipment-list"),
  84. },
  85. {
  86. key: SERVICES_KEY.AMICALE_WEBSITE,
  87. title: i18n.t('screens.websites.amicale'),
  88. subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
  89. image: AMICALE_IMAGE,
  90. onPress: () => nav.navigate("website", {
  91. host: AvailableWebsites.websites.AMICALE,
  92. title: i18n.t('screens.websites.amicale')
  93. }),
  94. },
  95. {
  96. key: SERVICES_KEY.VOTE,
  97. title: i18n.t('screens.vote.title'),
  98. subtitle: i18n.t('screens.services.descriptions.vote'),
  99. image: VOTE_IMAGE,
  100. onPress: () => this.onAmicaleServicePress("vote"),
  101. },
  102. ];
  103. this.studentsDataset = [
  104. {
  105. key: SERVICES_KEY.PROXIMO,
  106. title: i18n.t('screens.proximo.title'),
  107. subtitle: i18n.t('screens.services.descriptions.proximo'),
  108. image: PROXIMO_IMAGE,
  109. onPress: () => nav.navigate("proximo"),
  110. badgeFunction: (dashboard: fullDashboard) => dashboard.proximo_articles
  111. },
  112. {
  113. key: SERVICES_KEY.WIKETUD,
  114. title: "Wiketud",
  115. subtitle: i18n.t('screens.services.descriptions.wiketud'),
  116. image: WIKETUD_IMAGE,
  117. onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
  118. },
  119. {
  120. key: SERVICES_KEY.ELUS_ETUDIANTS,
  121. title: "Élus Étudiants",
  122. subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
  123. image: EE_IMAGE,
  124. onPress: () => nav.navigate("website", {
  125. host: AvailableWebsites.websites.ELUS_ETUDIANTS,
  126. title: "Élus Étudiants"
  127. }),
  128. },
  129. {
  130. key: SERVICES_KEY.TUTOR_INSA,
  131. title: "Tutor'INSA",
  132. subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
  133. image: TUTORINSA_IMAGE,
  134. onPress: () => nav.navigate("website", {
  135. host: AvailableWebsites.websites.TUTOR_INSA,
  136. title: "Tutor'INSA"
  137. }),
  138. badgeFunction: (dashboard: fullDashboard) => dashboard.available_tutorials
  139. },
  140. ];
  141. this.insaDataset = [
  142. {
  143. key: SERVICES_KEY.RU,
  144. title: i18n.t('screens.menu.title'),
  145. subtitle: i18n.t('screens.services.descriptions.self'),
  146. image: RU_IMAGE,
  147. onPress: () => nav.navigate("self-menu"),
  148. badgeFunction: (dashboard: fullDashboard) => dashboard.today_menu.length
  149. },
  150. {
  151. key: SERVICES_KEY.AVAILABLE_ROOMS,
  152. title: i18n.t('screens.websites.rooms'),
  153. subtitle: i18n.t('screens.services.descriptions.availableRooms'),
  154. image: ROOM_IMAGE,
  155. onPress: () => nav.navigate("website", {
  156. host: AvailableWebsites.websites.AVAILABLE_ROOMS,
  157. title: i18n.t('screens.websites.rooms')
  158. }),
  159. },
  160. {
  161. key: SERVICES_KEY.BIB,
  162. title: i18n.t('screens.websites.bib'),
  163. subtitle: i18n.t('screens.services.descriptions.bib'),
  164. image: BIB_IMAGE,
  165. onPress: () => nav.navigate("website", {
  166. host: AvailableWebsites.websites.BIB,
  167. title: i18n.t('screens.websites.bib')
  168. }),
  169. },
  170. {
  171. key: SERVICES_KEY.EMAIL,
  172. title: i18n.t('screens.websites.mails'),
  173. subtitle: i18n.t('screens.services.descriptions.mails'),
  174. image: EMAIL_IMAGE,
  175. onPress: () => nav.navigate("website", {
  176. host: AvailableWebsites.websites.BLUEMIND,
  177. title: i18n.t('screens.websites.mails')
  178. }),
  179. },
  180. {
  181. key: SERVICES_KEY.ENT,
  182. title: i18n.t('screens.websites.ent'),
  183. subtitle: i18n.t('screens.services.descriptions.ent'),
  184. image: ENT_IMAGE,
  185. onPress: () => nav.navigate("website", {
  186. host: AvailableWebsites.websites.ENT,
  187. title: i18n.t('screens.websites.ent')
  188. }),
  189. },
  190. {
  191. key: SERVICES_KEY.INSA_ACCOUNT,
  192. title: i18n.t('screens.insaAccount.title'),
  193. subtitle: i18n.t('screens.services.descriptions.insaAccount'),
  194. image: ACCOUNT_IMAGE,
  195. onPress: () => nav.navigate("website", {
  196. host: AvailableWebsites.websites.INSA_ACCOUNT,
  197. title: i18n.t('screens.insaAccount.title')
  198. }),
  199. },
  200. ];
  201. this.specialDataset = [
  202. {
  203. key: SERVICES_KEY.WASHERS,
  204. title: i18n.t('screens.proxiwash.washers'),
  205. subtitle: i18n.t('screens.proxiwash.title'), // TODO add description
  206. image: WASHER_IMAGE,
  207. onPress: () => nav.navigate("proxiwash"),
  208. badgeFunction: (dashboard: fullDashboard) => dashboard.available_washers
  209. },
  210. {
  211. key: SERVICES_KEY.DRYERS,
  212. title: i18n.t('screens.proxiwash.dryers'),
  213. subtitle: i18n.t('screens.proxiwash.title'), // TODO add description
  214. image: DRYER_IMAGE,
  215. onPress: () => nav.navigate("proxiwash"),
  216. badgeFunction: (dashboard: fullDashboard) => dashboard.available_dryers
  217. }
  218. ]
  219. }
  220. /**
  221. * Redirects the user to the login screen if he is not logged in
  222. *
  223. * @param route
  224. * @returns {null}
  225. */
  226. onAmicaleServicePress(route: string) {
  227. if (ConnectionManager.getInstance().isLoggedIn())
  228. this.navigation.navigate(route);
  229. else
  230. this.navigation.navigate("login", {nextScreen: route});
  231. }
  232. /**
  233. * Gets the given services list without items of the given ids
  234. *
  235. * @param idList The ids of items to remove
  236. * @param sourceList The item list to use as source
  237. * @returns {[]}
  238. */
  239. getStrippedList(idList: Array<string>, sourceList: Array<ServiceItem>) {
  240. let newArray = [];
  241. for (let i = 0; i < sourceList.length; i++) {
  242. const item = sourceList[i];
  243. if (!(idList.includes(item.key)))
  244. newArray.push(item);
  245. }
  246. return newArray;
  247. }
  248. /**
  249. * Gets the list of amicale's services
  250. *
  251. * @param excludedItems Ids of items to exclude from the returned list
  252. * @returns {Array<ServiceItem>}
  253. */
  254. getAmicaleServices(excludedItems?: Array<string>) {
  255. if (excludedItems != null)
  256. return this.getStrippedList(excludedItems, this.amicaleDataset)
  257. else
  258. return this.amicaleDataset;
  259. }
  260. /**
  261. * Gets the list of students' services
  262. *
  263. * @param excludedItems Ids of items to exclude from the returned list
  264. * @returns {Array<ServiceItem>}
  265. */
  266. getStudentServices(excludedItems?: Array<string>) {
  267. if (excludedItems != null)
  268. return this.getStrippedList(excludedItems, this.studentsDataset)
  269. else
  270. return this.studentsDataset;
  271. }
  272. /**
  273. * Gets the list of INSA's services
  274. *
  275. * @param excludedItems Ids of items to exclude from the returned list
  276. * @returns {Array<ServiceItem>}
  277. */
  278. getINSAServices(excludedItems?: Array<string>) {
  279. if (excludedItems != null)
  280. return this.getStrippedList(excludedItems, this.insaDataset)
  281. else
  282. return this.insaDataset;
  283. }
  284. /**
  285. * Gets the list of special services
  286. *
  287. * @param excludedItems Ids of items to exclude from the returned list
  288. * @returns {Array<ServiceItem>}
  289. */
  290. getSpecialServices(excludedItems?: Array<string>) {
  291. if (excludedItems != null)
  292. return this.getStrippedList(excludedItems, this.specialDataset)
  293. else
  294. return this.specialDataset;
  295. }
  296. }