|
@@ -0,0 +1,261 @@
|
|
1
|
+// @flow
|
|
2
|
+
|
|
3
|
+import type {cardList} from "../components/Lists/CardList/CardList";
|
|
4
|
+import i18n from "i18n-js";
|
|
5
|
+import AvailableWebsites from "../constants/AvailableWebsites";
|
|
6
|
+import {StackNavigationProp} from "@react-navigation/stack";
|
|
7
|
+import ConnectionManager from "./ConnectionManager";
|
|
8
|
+
|
|
9
|
+const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
|
|
10
|
+const PROFILE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProfilAmicaliste.png";
|
|
11
|
+const EQUIPMENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Materiel.png";
|
|
12
|
+const VOTE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Vote.png";
|
|
13
|
+const AMICALE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png";
|
|
14
|
+
|
|
15
|
+const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png"
|
|
16
|
+const WIKETUD_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Wiketud.png";
|
|
17
|
+const EE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/EEC.png";
|
|
18
|
+const TUTORINSA_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png";
|
|
19
|
+
|
|
20
|
+const BIB_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png";
|
|
21
|
+const RU_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/RU.png";
|
|
22
|
+const ROOM_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png";
|
|
23
|
+const EMAIL_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bluemind.png";
|
|
24
|
+const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
|
|
25
|
+const ACCOUNT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Account.png";
|
|
26
|
+
|
|
27
|
+export const SERVICES_KEY = {
|
|
28
|
+ CLUBS: "clubs",
|
|
29
|
+ PROFILE:"profile",
|
|
30
|
+ EQUIPMENT: "equipment",
|
|
31
|
+ AMICALE_WEBSITE: "amicale_website",
|
|
32
|
+ VOTE: "vote",
|
|
33
|
+ PROXIMO: "proximo",
|
|
34
|
+ WIKETUD: "wiketud",
|
|
35
|
+ ELUS_ETUDIANTS: "elus_etudiants",
|
|
36
|
+ TUTOR_INSA: "tutor_insa",
|
|
37
|
+ RU: "ru",
|
|
38
|
+ AVAILABLE_ROOMS: "available_rooms",
|
|
39
|
+ BIB: "bib",
|
|
40
|
+ EMAIL: "email",
|
|
41
|
+ ENT: "ent",
|
|
42
|
+ INSA_ACCOUNT: "insa_account",
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+export default class ServicesManager {
|
|
46
|
+
|
|
47
|
+ navigation: StackNavigationProp;
|
|
48
|
+
|
|
49
|
+ amicaleDataset: cardList;
|
|
50
|
+ studentsDataset: cardList;
|
|
51
|
+ insaDataset: cardList;
|
|
52
|
+
|
|
53
|
+ constructor(nav: StackNavigationProp) {
|
|
54
|
+ this.navigation = nav;
|
|
55
|
+ this.amicaleDataset = [
|
|
56
|
+ {
|
|
57
|
+ key: SERVICES_KEY.CLUBS,
|
|
58
|
+ title: i18n.t('screens.clubs.title'),
|
|
59
|
+ subtitle: i18n.t('screens.services.descriptions.clubs'),
|
|
60
|
+ image: CLUBS_IMAGE,
|
|
61
|
+ onPress: () => this.onAmicaleServicePress("club-list"),
|
|
62
|
+ },
|
|
63
|
+ {
|
|
64
|
+ key: SERVICES_KEY.PROFILE,
|
|
65
|
+ title: i18n.t('screens.profile.title'),
|
|
66
|
+ subtitle: i18n.t('screens.services.descriptions.profile'),
|
|
67
|
+ image: PROFILE_IMAGE,
|
|
68
|
+ onPress: () => this.onAmicaleServicePress("profile"),
|
|
69
|
+ },
|
|
70
|
+ {
|
|
71
|
+ key: SERVICES_KEY.EQUIPMENT,
|
|
72
|
+ title: i18n.t('screens.equipment.title'),
|
|
73
|
+ subtitle: i18n.t('screens.services.descriptions.equipment'),
|
|
74
|
+ image: EQUIPMENT_IMAGE,
|
|
75
|
+ onPress: () => this.onAmicaleServicePress("equipment-list"),
|
|
76
|
+ },
|
|
77
|
+ {
|
|
78
|
+ key: SERVICES_KEY.AMICALE_WEBSITE,
|
|
79
|
+ title: i18n.t('screens.websites.amicale'),
|
|
80
|
+ subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
|
|
81
|
+ image: AMICALE_IMAGE,
|
|
82
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AMICALE, title: i18n.t('screens.websites.amicale')}),
|
|
83
|
+ },
|
|
84
|
+ {
|
|
85
|
+ key: SERVICES_KEY.VOTE,
|
|
86
|
+ title: i18n.t('screens.vote.title'),
|
|
87
|
+ subtitle: i18n.t('screens.services.descriptions.vote'),
|
|
88
|
+ image: VOTE_IMAGE,
|
|
89
|
+ onPress: () => this.onAmicaleServicePress("vote"),
|
|
90
|
+ },
|
|
91
|
+ ];
|
|
92
|
+ this.studentsDataset = [
|
|
93
|
+ {
|
|
94
|
+ key: SERVICES_KEY.PROXIMO,
|
|
95
|
+ title: i18n.t('screens.proximo.title'),
|
|
96
|
+ subtitle: i18n.t('screens.services.descriptions.proximo'),
|
|
97
|
+ image: PROXIMO_IMAGE,
|
|
98
|
+ onPress: () => nav.navigate("proximo"),
|
|
99
|
+ },
|
|
100
|
+ {
|
|
101
|
+ key: SERVICES_KEY.WIKETUD,
|
|
102
|
+ title: "Wiketud",
|
|
103
|
+ subtitle: i18n.t('screens.services.descriptions.wiketud'),
|
|
104
|
+ image: WIKETUD_IMAGE,
|
|
105
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
|
|
106
|
+ },
|
|
107
|
+ {
|
|
108
|
+ key: SERVICES_KEY.ELUS_ETUDIANTS,
|
|
109
|
+ title: "Élus Étudiants",
|
|
110
|
+ subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
|
|
111
|
+ image: EE_IMAGE,
|
|
112
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
|
|
113
|
+ },
|
|
114
|
+ {
|
|
115
|
+ key: SERVICES_KEY.TUTOR_INSA,
|
|
116
|
+ title: "Tutor'INSA",
|
|
117
|
+ subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
|
|
118
|
+ image: TUTORINSA_IMAGE,
|
|
119
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"})
|
|
120
|
+ },
|
|
121
|
+ ];
|
|
122
|
+ this.insaDataset = [
|
|
123
|
+ {
|
|
124
|
+ key: SERVICES_KEY.RU,
|
|
125
|
+ title: i18n.t('screens.menu.title'),
|
|
126
|
+ subtitle: i18n.t('screens.services.descriptions.self'),
|
|
127
|
+ image: RU_IMAGE,
|
|
128
|
+ onPress: () => nav.navigate("self-menu"),
|
|
129
|
+ },
|
|
130
|
+ {
|
|
131
|
+ key: SERVICES_KEY.AVAILABLE_ROOMS,
|
|
132
|
+ title: i18n.t('screens.websites.rooms'),
|
|
133
|
+ subtitle: i18n.t('screens.services.descriptions.availableRooms'),
|
|
134
|
+ image: ROOM_IMAGE,
|
|
135
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AVAILABLE_ROOMS, title: i18n.t('screens.websites.rooms')}),
|
|
136
|
+ },
|
|
137
|
+ {
|
|
138
|
+ key: SERVICES_KEY.BIB,
|
|
139
|
+ title: i18n.t('screens.websites.bib'),
|
|
140
|
+ subtitle: i18n.t('screens.services.descriptions.bib'),
|
|
141
|
+ image: BIB_IMAGE,
|
|
142
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BIB, title: i18n.t('screens.websites.bib')}),
|
|
143
|
+ },
|
|
144
|
+ {
|
|
145
|
+ key: SERVICES_KEY.EMAIL,
|
|
146
|
+ title: i18n.t('screens.websites.mails'),
|
|
147
|
+ subtitle: i18n.t('screens.services.descriptions.mails'),
|
|
148
|
+ image: EMAIL_IMAGE,
|
|
149
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BLUEMIND, title: i18n.t('screens.websites.mails')}),
|
|
150
|
+ },
|
|
151
|
+ {
|
|
152
|
+ key: SERVICES_KEY.ENT,
|
|
153
|
+ title: i18n.t('screens.websites.ent'),
|
|
154
|
+ subtitle: i18n.t('screens.services.descriptions.ent'),
|
|
155
|
+ image: ENT_IMAGE,
|
|
156
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ENT, title: i18n.t('screens.websites.ent')}),
|
|
157
|
+ },
|
|
158
|
+ {
|
|
159
|
+ key: SERVICES_KEY.INSA_ACCOUNT,
|
|
160
|
+ title: i18n.t('screens.insaAccount.title'),
|
|
161
|
+ subtitle: i18n.t('screens.services.descriptions.insaAccount'),
|
|
162
|
+ image: ACCOUNT_IMAGE,
|
|
163
|
+ onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.INSA_ACCOUNT, title: i18n.t('screens.insaAccount.title')}),
|
|
164
|
+ },
|
|
165
|
+ ];
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ /**
|
|
169
|
+ * Redirects the user to the login screen if he is not logged in
|
|
170
|
+ *
|
|
171
|
+ * @param route
|
|
172
|
+ * @returns {null}
|
|
173
|
+ */
|
|
174
|
+ onAmicaleServicePress(route: string) {
|
|
175
|
+ if (ConnectionManager.getInstance().isLoggedIn())
|
|
176
|
+ this.navigation.navigate(route);
|
|
177
|
+ else
|
|
178
|
+ this.navigation.navigate("login", {nextScreen: route});
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ /**
|
|
182
|
+ * Gets the given services list without items of the given ids
|
|
183
|
+ *
|
|
184
|
+ * @param idList The ids of items to remove
|
|
185
|
+ * @param sourceList The item list to use as source
|
|
186
|
+ * @returns {[]}
|
|
187
|
+ */
|
|
188
|
+ getStrippedList(idList: Array<string>, sourceList: cardList) {
|
|
189
|
+ let newArray = [];
|
|
190
|
+ for (let i = 0; i < sourceList.length; i++) {
|
|
191
|
+ const item = sourceList[i];
|
|
192
|
+ if (!(idList.includes(item.key)))
|
|
193
|
+ newArray.push(item);
|
|
194
|
+ }
|
|
195
|
+ return newArray;
|
|
196
|
+ }
|
|
197
|
+
|
|
198
|
+ /**
|
|
199
|
+ * Gets a services list of items with the given ids only
|
|
200
|
+ *
|
|
201
|
+ * @param idList The ids of items to find
|
|
202
|
+ * @returns {[]}
|
|
203
|
+ */
|
|
204
|
+ getServicesOfId(idList: Array<string>) {
|
|
205
|
+ const allServices = [
|
|
206
|
+ ...this.amicaleDataset,
|
|
207
|
+ ...this.studentsDataset,
|
|
208
|
+ ...this.insaDataset,
|
|
209
|
+ ]
|
|
210
|
+ let servicesFound = [];
|
|
211
|
+ for (let i = 0; i < allServices.length; i++) {
|
|
212
|
+ const item = allServices[i];
|
|
213
|
+ if (idList.includes(item.key)) {
|
|
214
|
+ servicesFound.push(item);
|
|
215
|
+ if (servicesFound.length === idList.length)
|
|
216
|
+ break;
|
|
217
|
+ }
|
|
218
|
+ }
|
|
219
|
+ return servicesFound;
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ /**
|
|
223
|
+ * Gets the list of amicale's services
|
|
224
|
+ *
|
|
225
|
+ * @param excludedItems Ids of items to exclude from the returned list
|
|
226
|
+ * @returns {cardList|*[]}
|
|
227
|
+ */
|
|
228
|
+ getAmicaleServices(excludedItems?: Array<string>) {
|
|
229
|
+ if (excludedItems != null)
|
|
230
|
+ return this.getStrippedList(excludedItems, this.amicaleDataset)
|
|
231
|
+ else
|
|
232
|
+ return this.amicaleDataset;
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ /**
|
|
236
|
+ * Gets the list of students' services
|
|
237
|
+ *
|
|
238
|
+ * @param excludedItems Ids of items to exclude from the returned list
|
|
239
|
+ * @returns {cardList|*[]}
|
|
240
|
+ */
|
|
241
|
+ getStudentServices(excludedItems?: Array<string>) {
|
|
242
|
+ if (excludedItems != null)
|
|
243
|
+ return this.getStrippedList(excludedItems, this.studentsDataset)
|
|
244
|
+ else
|
|
245
|
+ return this.studentsDataset;
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ /**
|
|
249
|
+ * Gets the list of INSA's services
|
|
250
|
+ *
|
|
251
|
+ * @param excludedItems Ids of items to exclude from the returned list
|
|
252
|
+ * @returns {cardList|*[]}
|
|
253
|
+ */
|
|
254
|
+ getINSAServices(excludedItems?: Array<string>) {
|
|
255
|
+ if (excludedItems != null)
|
|
256
|
+ return this.getStrippedList(excludedItems, this.insaDataset)
|
|
257
|
+ else
|
|
258
|
+ return this.insaDataset;
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+}
|