Browse Source

Dashboard can now display any service from ServicesManager.js

Arnaud Vergnet 3 years ago
parent
commit
2022b738f5

+ 51
- 35
src/components/Home/SmallDashboardItem.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import * as React from 'react';
3
 import * as React from 'react';
4
-import {Badge, IconButton, withTheme} from 'react-native-paper';
5
-import {View} from "react-native";
4
+import {Badge, TouchableRipple, withTheme} from 'react-native-paper';
5
+import {Dimensions, Image, View} from "react-native";
6
 import type {CustomTheme} from "../../managers/ThemeManager";
6
 import type {CustomTheme} from "../../managers/ThemeManager";
7
 import * as Animatable from "react-native-animatable";
7
 import * as Animatable from "react-native-animatable";
8
 
8
 
9
 type Props = {
9
 type Props = {
10
-    color: string,
11
-    icon: string,
12
-    clickAction: () => void,
13
-    isAvailable: boolean,
14
-    badgeNumber: number,
10
+    image: string,
11
+    onPress: () => void,
12
+    badgeCount: number | null,
15
     theme: CustomTheme,
13
     theme: CustomTheme,
16
 };
14
 };
17
 
15
 
22
  */
20
  */
23
 class SmallDashboardItem extends React.Component<Props> {
21
 class SmallDashboardItem extends React.Component<Props> {
24
 
22
 
23
+    itemSize: number;
24
+
25
+    constructor(props: Props) {
26
+        super(props);
27
+        this.itemSize = Dimensions.get('window').width / 8;
28
+    }
29
+
25
     shouldComponentUpdate(nextProps: Props) {
30
     shouldComponentUpdate(nextProps: Props) {
26
         return (nextProps.theme.dark !== this.props.theme.dark)
31
         return (nextProps.theme.dark !== this.props.theme.dark)
27
-            || (nextProps.isAvailable !== this.props.isAvailable)
28
-            || (nextProps.badgeNumber !== this.props.badgeNumber);
32
+            || (nextProps.badgeCount !== this.props.badgeCount);
29
     }
33
     }
30
 
34
 
31
     render() {
35
     render() {
32
         const props = this.props;
36
         const props = this.props;
33
-        const colors = props.theme.colors;
34
         return (
37
         return (
35
-            <View>
36
-                <IconButton
37
-                    icon={props.icon}
38
-                    color={
39
-                        props.isAvailable
40
-                            ? props.color
41
-                            : colors.textDisabled
42
-                    }
43
-                    size={35}
44
-                    onPress={props.clickAction}
45
-                />
46
-                {
47
-                    props.badgeNumber > 0 ?
48
-                        <AnimatableBadge
49
-                            animation={"zoomIn"}
50
-                            duration={300}
51
-                            useNativeDriver
38
+                <TouchableRipple
39
+                    onPress={this.props.onPress}
40
+                    borderless={true}
41
+                    style={{
42
+                        marginLeft: 5,
43
+                        marginRight: 5,
44
+                    }}
45
+                >
46
+                    <View style={{
47
+                        width: this.itemSize,
48
+                        height: this.itemSize,
49
+                    }}>
50
+                        <Image
51
+                            source={{uri: props.image}}
52
                             style={{
52
                             style={{
53
-                                position: 'absolute',
54
-                                top: 5,
55
-                                right: 5
56
-                            }}>
57
-                            {props.badgeNumber}
58
-                        </AnimatableBadge> : null
59
-                }
60
-            </View>
53
+                                width: "100%",
54
+                                height: "100%",
55
+                            }}
56
+                        />
57
+                        {
58
+                            props.badgeCount != null && props.badgeCount > 0 ?
59
+                                <AnimatableBadge
60
+                                    animation={"zoomIn"}
61
+                                    duration={300}
62
+                                    useNativeDriver
63
+                                    style={{
64
+                                        position: 'absolute',
65
+                                        top: 0,
66
+                                        right: 0,
67
+                                        backgroundColor: props.theme.colors.primary,
68
+                                        borderColor: "#fff",
69
+                                        borderWidth: 1,
70
+                                    }}>
71
+                                    {props.badgeCount}
72
+                                </AnimatableBadge> : null
73
+                        }
74
+                    </View>
75
+                </TouchableRipple>
76
+
61
         );
77
         );
62
     }
78
     }
63
 
79
 

+ 12
- 0
src/managers/AsyncStorageManager.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import AsyncStorage from '@react-native-community/async-storage';
3
 import AsyncStorage from '@react-native-community/async-storage';
4
+import {SERVICES_KEY} from "./ServicesManager";
4
 
5
 
5
 /**
6
 /**
6
  * Singleton used to manage preferences.
7
  * Singleton used to manage preferences.
119
             default: '[]',
120
             default: '[]',
120
             current: '',
121
             current: '',
121
         },
122
         },
123
+        dashboardItems: {
124
+            key: 'dashboardItems',
125
+            default: JSON.stringify([
126
+                SERVICES_KEY.EMAIL,
127
+                SERVICES_KEY.WASHERS,
128
+                SERVICES_KEY.PROXIMO,
129
+                SERVICES_KEY.TUTOR_INSA,
130
+                SERVICES_KEY.RU,
131
+            ]),
132
+            current: '',
133
+        },
122
     };
134
     };
123
 
135
 
124
     /**
136
     /**

+ 26
- 0
src/managers/DashboardManager.js View File

1
+// @flow
2
+
3
+import type {ServiceItem} from "./ServicesManager";
4
+import ServicesManager from "./ServicesManager";
5
+import {StackNavigationProp} from "@react-navigation/stack";
6
+import {getSublistWithIds} from "../utils/Utils";
7
+import AsyncStorageManager from "./AsyncStorageManager";
8
+
9
+
10
+export default class DashboardManager extends ServicesManager{
11
+
12
+    constructor(nav: StackNavigationProp) {
13
+        super(nav)
14
+    }
15
+
16
+    getCurrentDashboard(): Array<ServiceItem> {
17
+        const dashboardIdList = JSON.parse(AsyncStorageManager.getInstance().preferences.dashboardItems.current);
18
+        const allDatasets = [
19
+            ...this.amicaleDataset,
20
+            ...this.studentsDataset,
21
+            ...this.insaDataset,
22
+            ...this.specialDataset,
23
+        ];
24
+        return getSublistWithIds(dashboardIdList, allDatasets);
25
+    }
26
+}

+ 94
- 41
src/managers/ServicesManager.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import type {cardList} from "../components/Lists/CardList/CardList";
4
 import i18n from "i18n-js";
3
 import i18n from "i18n-js";
5
 import AvailableWebsites from "../constants/AvailableWebsites";
4
 import AvailableWebsites from "../constants/AvailableWebsites";
6
 import {StackNavigationProp} from "@react-navigation/stack";
5
 import {StackNavigationProp} from "@react-navigation/stack";
7
 import ConnectionManager from "./ConnectionManager";
6
 import ConnectionManager from "./ConnectionManager";
7
+import type {fullDashboard} from "../screens/Home/HomeScreen";
8
 
8
 
9
+// AMICALE
9
 const CLUBS_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Clubs.png";
10
 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 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 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 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
 const AMICALE_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/WebsiteAmicale.png";
14
 
15
 
16
+// STUDENTS
15
 const PROXIMO_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Proximo.png"
17
 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";
18
 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";
19
 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";
20
 const TUTORINSA_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/TutorINSA.png";
19
 
21
 
22
+// INSA
20
 const BIB_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Bib.png";
23
 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";
24
 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";
25
 const ROOM_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Salles.png";
24
 const ENT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ENT.png";
27
 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";
28
 const ACCOUNT_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/Account.png";
26
 
29
 
30
+// SPECIAL
31
+const WASHER_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProxiwashLaveLinge.png";
32
+const DRYER_IMAGE = "https://etud.insa-toulouse.fr/~amicale_app/images/ProxiwashSecheLinge.png";
33
+
27
 export const SERVICES_KEY = {
34
 export const SERVICES_KEY = {
28
     CLUBS: "clubs",
35
     CLUBS: "clubs",
29
-    PROFILE:"profile",
36
+    PROFILE: "profile",
30
     EQUIPMENT: "equipment",
37
     EQUIPMENT: "equipment",
31
     AMICALE_WEBSITE: "amicale_website",
38
     AMICALE_WEBSITE: "amicale_website",
32
     VOTE: "vote",
39
     VOTE: "vote",
40
     EMAIL: "email",
47
     EMAIL: "email",
41
     ENT: "ent",
48
     ENT: "ent",
42
     INSA_ACCOUNT: "insa_account",
49
     INSA_ACCOUNT: "insa_account",
50
+    WASHERS: "washers",
51
+    DRYERS: "dryers",
52
+}
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,
43
 }
61
 }
44
 
62
 
45
 export default class ServicesManager {
63
 export default class ServicesManager {
46
 
64
 
47
     navigation: StackNavigationProp;
65
     navigation: StackNavigationProp;
48
 
66
 
49
-    amicaleDataset: cardList;
50
-    studentsDataset: cardList;
51
-    insaDataset: cardList;
67
+    amicaleDataset: Array<ServiceItem>;
68
+    studentsDataset: Array<ServiceItem>;
69
+    insaDataset: Array<ServiceItem>;
70
+    specialDataset: Array<ServiceItem>;
52
 
71
 
53
     constructor(nav: StackNavigationProp) {
72
     constructor(nav: StackNavigationProp) {
54
         this.navigation = nav;
73
         this.navigation = nav;
79
                 title: i18n.t('screens.websites.amicale'),
98
                 title: i18n.t('screens.websites.amicale'),
80
                 subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
99
                 subtitle: i18n.t('screens.services.descriptions.amicaleWebsite'),
81
                 image: AMICALE_IMAGE,
100
                 image: AMICALE_IMAGE,
82
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AMICALE, title: i18n.t('screens.websites.amicale')}),
101
+                onPress: () => nav.navigate("website", {
102
+                    host: AvailableWebsites.websites.AMICALE,
103
+                    title: i18n.t('screens.websites.amicale')
104
+                }),
83
             },
105
             },
84
             {
106
             {
85
                 key: SERVICES_KEY.VOTE,
107
                 key: SERVICES_KEY.VOTE,
96
                 subtitle: i18n.t('screens.services.descriptions.proximo'),
118
                 subtitle: i18n.t('screens.services.descriptions.proximo'),
97
                 image: PROXIMO_IMAGE,
119
                 image: PROXIMO_IMAGE,
98
                 onPress: () => nav.navigate("proximo"),
120
                 onPress: () => nav.navigate("proximo"),
121
+                badgeFunction: (dashboard: fullDashboard) => dashboard.proximo_articles
99
             },
122
             },
100
             {
123
             {
101
                 key: SERVICES_KEY.WIKETUD,
124
                 key: SERVICES_KEY.WIKETUD,
109
                 title: "Élus Étudiants",
132
                 title: "Élus Étudiants",
110
                 subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
133
                 subtitle: i18n.t('screens.services.descriptions.elusEtudiants'),
111
                 image: EE_IMAGE,
134
                 image: EE_IMAGE,
112
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.WIKETUD, title: "Wiketud"}),
135
+                onPress: () => nav.navigate("website", {
136
+                    host: AvailableWebsites.websites.ELUS_ETUDIANTS,
137
+                    title: "Élus Étudiants"
138
+                }),
113
             },
139
             },
114
             {
140
             {
115
                 key: SERVICES_KEY.TUTOR_INSA,
141
                 key: SERVICES_KEY.TUTOR_INSA,
116
                 title: "Tutor'INSA",
142
                 title: "Tutor'INSA",
117
                 subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
143
                 subtitle: i18n.t('screens.services.descriptions.tutorInsa'),
118
                 image: TUTORINSA_IMAGE,
144
                 image: TUTORINSA_IMAGE,
119
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"})
145
+                onPress: () => nav.navigate("website", {
146
+                    host: AvailableWebsites.websites.TUTOR_INSA,
147
+                    title: "Tutor'INSA"
148
+                }),
149
+                badgeFunction: (dashboard: fullDashboard) => dashboard.available_tutorials
120
             },
150
             },
121
         ];
151
         ];
122
         this.insaDataset = [
152
         this.insaDataset = [
126
                 subtitle: i18n.t('screens.services.descriptions.self'),
156
                 subtitle: i18n.t('screens.services.descriptions.self'),
127
                 image: RU_IMAGE,
157
                 image: RU_IMAGE,
128
                 onPress: () => nav.navigate("self-menu"),
158
                 onPress: () => nav.navigate("self-menu"),
159
+                badgeFunction: (dashboard: fullDashboard) => dashboard.today_menu.length
129
             },
160
             },
130
             {
161
             {
131
                 key: SERVICES_KEY.AVAILABLE_ROOMS,
162
                 key: SERVICES_KEY.AVAILABLE_ROOMS,
132
                 title: i18n.t('screens.websites.rooms'),
163
                 title: i18n.t('screens.websites.rooms'),
133
                 subtitle: i18n.t('screens.services.descriptions.availableRooms'),
164
                 subtitle: i18n.t('screens.services.descriptions.availableRooms'),
134
                 image: ROOM_IMAGE,
165
                 image: ROOM_IMAGE,
135
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.AVAILABLE_ROOMS, title: i18n.t('screens.websites.rooms')}),
166
+                onPress: () => nav.navigate("website", {
167
+                    host: AvailableWebsites.websites.AVAILABLE_ROOMS,
168
+                    title: i18n.t('screens.websites.rooms')
169
+                }),
136
             },
170
             },
137
             {
171
             {
138
                 key: SERVICES_KEY.BIB,
172
                 key: SERVICES_KEY.BIB,
139
                 title: i18n.t('screens.websites.bib'),
173
                 title: i18n.t('screens.websites.bib'),
140
                 subtitle: i18n.t('screens.services.descriptions.bib'),
174
                 subtitle: i18n.t('screens.services.descriptions.bib'),
141
                 image: BIB_IMAGE,
175
                 image: BIB_IMAGE,
142
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BIB, title: i18n.t('screens.websites.bib')}),
176
+                onPress: () => nav.navigate("website", {
177
+                    host: AvailableWebsites.websites.BIB,
178
+                    title: i18n.t('screens.websites.bib')
179
+                }),
143
             },
180
             },
144
             {
181
             {
145
                 key: SERVICES_KEY.EMAIL,
182
                 key: SERVICES_KEY.EMAIL,
146
                 title: i18n.t('screens.websites.mails'),
183
                 title: i18n.t('screens.websites.mails'),
147
                 subtitle: i18n.t('screens.services.descriptions.mails'),
184
                 subtitle: i18n.t('screens.services.descriptions.mails'),
148
                 image: EMAIL_IMAGE,
185
                 image: EMAIL_IMAGE,
149
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.BLUEMIND, title: i18n.t('screens.websites.mails')}),
186
+                onPress: () => nav.navigate("website", {
187
+                    host: AvailableWebsites.websites.BLUEMIND,
188
+                    title: i18n.t('screens.websites.mails')
189
+                }),
150
             },
190
             },
151
             {
191
             {
152
                 key: SERVICES_KEY.ENT,
192
                 key: SERVICES_KEY.ENT,
153
                 title: i18n.t('screens.websites.ent'),
193
                 title: i18n.t('screens.websites.ent'),
154
                 subtitle: i18n.t('screens.services.descriptions.ent'),
194
                 subtitle: i18n.t('screens.services.descriptions.ent'),
155
                 image: ENT_IMAGE,
195
                 image: ENT_IMAGE,
156
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.ENT, title: i18n.t('screens.websites.ent')}),
196
+                onPress: () => nav.navigate("website", {
197
+                    host: AvailableWebsites.websites.ENT,
198
+                    title: i18n.t('screens.websites.ent')
199
+                }),
157
             },
200
             },
158
             {
201
             {
159
                 key: SERVICES_KEY.INSA_ACCOUNT,
202
                 key: SERVICES_KEY.INSA_ACCOUNT,
160
                 title: i18n.t('screens.insaAccount.title'),
203
                 title: i18n.t('screens.insaAccount.title'),
161
                 subtitle: i18n.t('screens.services.descriptions.insaAccount'),
204
                 subtitle: i18n.t('screens.services.descriptions.insaAccount'),
162
                 image: ACCOUNT_IMAGE,
205
                 image: ACCOUNT_IMAGE,
163
-                onPress: () => nav.navigate("website", {host: AvailableWebsites.websites.INSA_ACCOUNT, title: i18n.t('screens.insaAccount.title')}),
206
+                onPress: () => nav.navigate("website", {
207
+                    host: AvailableWebsites.websites.INSA_ACCOUNT,
208
+                    title: i18n.t('screens.insaAccount.title')
209
+                }),
164
             },
210
             },
165
         ];
211
         ];
212
+        this.specialDataset = [
213
+            {
214
+                key: SERVICES_KEY.WASHERS,
215
+                title: i18n.t('screens.proxiwash.washers'),
216
+                subtitle: i18n.t('screens.proxiwash.title'), // TODO add description
217
+                image: WASHER_IMAGE,
218
+                onPress: () => nav.navigate("proxiwash"),
219
+                badgeFunction: (dashboard: fullDashboard) => dashboard.available_washers
220
+            },
221
+            {
222
+                key: SERVICES_KEY.DRYERS,
223
+                title: i18n.t('screens.proxiwash.dryers'),
224
+                subtitle: i18n.t('screens.proxiwash.title'), // TODO add description
225
+                image: DRYER_IMAGE,
226
+                onPress: () => nav.navigate("proxiwash"),
227
+                badgeFunction: (dashboard: fullDashboard) => dashboard.available_dryers
228
+            }
229
+        ]
166
     }
230
     }
167
 
231
 
168
     /**
232
     /**
185
      * @param sourceList The item list to use as source
249
      * @param sourceList The item list to use as source
186
      * @returns {[]}
250
      * @returns {[]}
187
      */
251
      */
188
-    getStrippedList(idList: Array<string>, sourceList: cardList) {
252
+    getStrippedList(idList: Array<string>, sourceList: Array<ServiceItem>) {
189
         let newArray = [];
253
         let newArray = [];
190
         for (let i = 0; i < sourceList.length; i++) {
254
         for (let i = 0; i < sourceList.length; i++) {
191
             const item = sourceList[i];
255
             const item = sourceList[i];
196
     }
260
     }
197
 
261
 
198
     /**
262
     /**
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
263
      * Gets the list of amicale's services
224
      *
264
      *
225
      * @param excludedItems Ids of items to exclude from the returned list
265
      * @param excludedItems Ids of items to exclude from the returned list
226
-     * @returns {cardList|*[]}
266
+     * @returns {Array<ServiceItem>}
227
      */
267
      */
228
     getAmicaleServices(excludedItems?: Array<string>) {
268
     getAmicaleServices(excludedItems?: Array<string>) {
229
         if (excludedItems != null)
269
         if (excludedItems != null)
236
      * Gets the list of students' services
276
      * Gets the list of students' services
237
      *
277
      *
238
      * @param excludedItems Ids of items to exclude from the returned list
278
      * @param excludedItems Ids of items to exclude from the returned list
239
-     * @returns {cardList|*[]}
279
+     * @returns {Array<ServiceItem>}
240
      */
280
      */
241
     getStudentServices(excludedItems?: Array<string>) {
281
     getStudentServices(excludedItems?: Array<string>) {
242
         if (excludedItems != null)
282
         if (excludedItems != null)
249
      * Gets the list of INSA's services
289
      * Gets the list of INSA's services
250
      *
290
      *
251
      * @param excludedItems Ids of items to exclude from the returned list
291
      * @param excludedItems Ids of items to exclude from the returned list
252
-     * @returns {cardList|*[]}
292
+     * @returns {Array<ServiceItem>}
253
      */
293
      */
254
     getINSAServices(excludedItems?: Array<string>) {
294
     getINSAServices(excludedItems?: Array<string>) {
255
         if (excludedItems != null)
295
         if (excludedItems != null)
258
             return this.insaDataset;
298
             return this.insaDataset;
259
     }
299
     }
260
 
300
 
301
+    /**
302
+     * Gets the list of special services
303
+     *
304
+     * @param excludedItems Ids of items to exclude from the returned list
305
+     * @returns {Array<ServiceItem>}
306
+     */
307
+    getSpecialServices(excludedItems?: Array<string>) {
308
+        if (excludedItems != null)
309
+            return this.getStrippedList(excludedItems, this.specialDataset)
310
+        else
311
+            return this.specialDataset;
312
+    }
313
+
261
 }
314
 }

+ 19
- 78
src/screens/Home/HomeScreen.js View File

20
 import ConnectionManager from "../../managers/ConnectionManager";
20
 import ConnectionManager from "../../managers/ConnectionManager";
21
 import LogoutDialog from "../../components/Amicale/LogoutDialog";
21
 import LogoutDialog from "../../components/Amicale/LogoutDialog";
22
 import AsyncStorageManager from "../../managers/AsyncStorageManager";
22
 import AsyncStorageManager from "../../managers/AsyncStorageManager";
23
-import AvailableWebsites from "../../constants/AvailableWebsites";
24
 import {MASCOT_STYLE} from "../../components/Mascot/Mascot";
23
 import {MASCOT_STYLE} from "../../components/Mascot/Mascot";
25
 import MascotPopup from "../../components/Mascot/MascotPopup";
24
 import MascotPopup from "../../components/Mascot/MascotPopup";
25
+import DashboardManager from "../../managers/DashboardManager";
26
 // import DATA from "../dashboard_data.json";
26
 // import DATA from "../dashboard_data.json";
27
 
27
 
28
 
28
 
52
     id: string,
52
     id: string,
53
 };
53
 };
54
 
54
 
55
-type fullDashboard = {
55
+export type fullDashboard = {
56
     today_menu: Array<{ [key: string]: any }>,
56
     today_menu: Array<{ [key: string]: any }>,
57
     proximo_articles: number,
57
     proximo_articles: number,
58
     available_dryers: number,
58
     available_dryers: number,
66
     content: Array<{ [key: string]: any }>
66
     content: Array<{ [key: string]: any }>
67
 };
67
 };
68
 
68
 
69
-type dashboardSmallItem = {
70
-    id: string,
71
-    data: number,
72
-    icon: string,
73
-    color: string,
74
-    onPress: () => void,
75
-    isAvailable: boolean
76
-};
77
-
78
 export type event = {
69
 export type event = {
79
     id: number,
70
     id: number,
80
     title: string,
71
     title: string,
113
 
104
 
114
     fabRef: { current: null | AnimatedFAB };
105
     fabRef: { current: null | AnimatedFAB };
115
     currentNewFeed: Array<feedItem>;
106
     currentNewFeed: Array<feedItem>;
107
+    currentDashboard: fullDashboard | null;
108
+
109
+    dashboardManager: DashboardManager;
116
 
110
 
117
     constructor(props) {
111
     constructor(props) {
118
         super(props);
112
         super(props);
119
         this.fabRef = React.createRef();
113
         this.fabRef = React.createRef();
114
+        this.dashboardManager = new DashboardManager(this.props.navigation);
120
         this.currentNewFeed = [];
115
         this.currentNewFeed = [];
116
+        this.currentDashboard = null;
121
         this.isLoggedIn = ConnectionManager.getInstance().isLoggedIn();
117
         this.isLoggedIn = ConnectionManager.getInstance().isLoggedIn();
122
         this.props.navigation.setOptions({
118
         this.props.navigation.setOptions({
123
             headerRight: this.getHeaderButton,
119
             headerRight: this.getHeaderButton,
207
 
203
 
208
     hideDisconnectDialog = () => this.setState({dialogVisible: false});
204
     hideDisconnectDialog = () => this.setState({dialogVisible: false});
209
 
205
 
210
-    onProxiwashClick = () => {
211
-        this.props.navigation.navigate("proxiwash");
212
-    };
213
-
214
-    onProximoClick = () => {
215
-        this.props.navigation.navigate("proximo");
216
-    };
217
-
218
-    onTutorInsaClick = () => {
219
-        this.props.navigation.navigate("website", {host: AvailableWebsites.websites.TUTOR_INSA, title: "Tutor'INSA"});
220
-    };
221
-
222
-    onMenuClick = () => {
223
-        this.props.navigation.navigate('self-menu');
224
-    };
225
-
226
     /**
206
     /**
227
      * Creates the dataset to be used in the FlatList
207
      * Creates the dataset to be used in the FlatList
228
      *
208
      *
232
     createDataset = (fetchedData: rawDashboard) => {
212
     createDataset = (fetchedData: rawDashboard) => {
233
         // fetchedData = DATA;
213
         // fetchedData = DATA;
234
         let dashboardData;
214
         let dashboardData;
235
-        if (fetchedData.news_feed != null) {
215
+        if (fetchedData.news_feed != null)
236
             this.currentNewFeed = fetchedData.news_feed.data;
216
             this.currentNewFeed = fetchedData.news_feed.data;
237
-        }
217
+        if (fetchedData.dashboard != null)
218
+            this.currentDashboard = fetchedData.dashboard;
219
+
238
         if (fetchedData.dashboard != null)
220
         if (fetchedData.dashboard != null)
239
             dashboardData = this.generateDashboardDataset(fetchedData.dashboard);
221
             dashboardData = this.generateDashboardDataset(fetchedData.dashboard);
240
         else
222
         else
264
             {id: 'actions', content: []},
246
             {id: 'actions', content: []},
265
             {
247
             {
266
                 id: 'top',
248
                 id: 'top',
267
-                content: [
268
-                    {
269
-                        id: 'washers',
270
-                        data: dashboardData == null ? 0 : dashboardData.available_washers,
271
-                        icon: 'washing-machine',
272
-                        color: this.props.theme.colors.proxiwashColor,
273
-                        onPress: this.onProxiwashClick,
274
-                        isAvailable: dashboardData == null ? false : dashboardData.available_washers > 0
275
-                    },
276
-                    {
277
-                        id: 'dryers',
278
-                        data: dashboardData == null ? 0 : dashboardData.available_dryers,
279
-                        icon: 'tumble-dryer',
280
-                        color: this.props.theme.colors.proxiwashColor,
281
-                        onPress: this.onProxiwashClick,
282
-                        isAvailable: dashboardData == null ? false : dashboardData.available_dryers > 0
283
-                    },
284
-                    {
285
-                        id: 'available_tutorials',
286
-                        data: dashboardData == null ? 0 : dashboardData.available_tutorials,
287
-                        icon: 'school',
288
-                        color: this.props.theme.colors.tutorinsaColor,
289
-                        onPress: this.onTutorInsaClick,
290
-                        isAvailable: dashboardData == null ? false : dashboardData.available_tutorials > 0
291
-                    },
292
-                    {
293
-                        id: 'proximo_articles',
294
-                        data: dashboardData == null ? 0 : dashboardData.proximo_articles,
295
-                        icon: 'shopping',
296
-                        color: this.props.theme.colors.proximoColor,
297
-                        onPress: this.onProximoClick,
298
-                        isAvailable: dashboardData == null ? false : dashboardData.proximo_articles > 0
299
-                    },
300
-                    {
301
-                        id: 'today_menu',
302
-                        data: dashboardData == null ? [] : dashboardData.today_menu,
303
-                        icon: 'silverware-fork-knife',
304
-                        color: this.props.theme.colors.menuColor,
305
-                        onPress: this.onMenuClick,
306
-                        isAvailable: dashboardData == null ? false : dashboardData.today_menu.length > 0
307
-                    },
308
-                ]
249
+                content: this.dashboardManager.getCurrentDashboard(),
309
             },
250
             },
310
             {
251
             {
311
                 id: 'event',
252
                 id: 'event',
491
      * @param item
432
      * @param item
492
      * @returns {*}
433
      * @returns {*}
493
      */
434
      */
494
-    dashboardRowRenderItem = ({item}: { item: dashboardSmallItem }) => {
435
+    dashboardRowRenderItem = ({item}: { item: DashboardItem }) => {
495
         return (
436
         return (
496
             <SquareDashboardItem
437
             <SquareDashboardItem
497
-                color={item.color}
498
-                icon={item.icon}
499
-                clickAction={item.onPress}
500
-                isAvailable={item.isAvailable}
501
-                badgeNumber={item.data}
438
+                image={item.image}
439
+                onPress={item.onPress}
440
+                badgeCount={this.currentDashboard != null && item.badgeFunction != null
441
+                    ? item.badgeFunction(this.currentDashboard)
442
+                    : null}
502
             />
443
             />
503
         );
444
         );
504
     };
445
     };
509
      * @param content
450
      * @param content
510
      * @return {*}
451
      * @return {*}
511
      */
452
      */
512
-    getDashboardRow(content: Array<dashboardSmallItem>) {
453
+    getDashboardRow(content: Array<DashboardItem>) {
513
         return (
454
         return (
514
             //$FlowFixMe
455
             //$FlowFixMe
515
             <FlatList
456
             <FlatList

+ 37
- 0
src/utils/Utils.js View File

1
+// @flow
2
+
3
+
4
+/**
5
+ * Gets a sublist of the given list with items of the given ids only
6
+ *
7
+ * The given list must have a field id or key
8
+ *
9
+ * @param idList The ids of items to find
10
+ * @param originalList The original list
11
+ * @returns {[]}
12
+ */
13
+export function getSublistWithIds(
14
+    idList: Array<string>,
15
+    originalList: Array<{ key: string, [key: string]: any }>
16
+): Array<{ key: string, [key: string]: any }> {
17
+    let subList = [];
18
+    for (let i = 0; i < subList.length; i++) {
19
+        subList.push(null);
20
+    }
21
+    let itemsAdded = 0;
22
+    for (let i = 0; i < originalList.length; i++) {
23
+        const item = originalList[i];
24
+        if (idList.includes(item.key)) {
25
+            subList[idList.indexOf(item.key)] = item;
26
+            itemsAdded++;
27
+            if (itemsAdded === idList.length)
28
+                break;
29
+        }
30
+    }
31
+    for (let i = 0; i < subList.length; i++) {
32
+        if (subList[i] == null)
33
+            subList.splice(i, 1);
34
+    }
35
+
36
+    return subList;
37
+}

Loading…
Cancel
Save