Browse Source

Improved doc

Arnaud Vergnet 4 years ago
parent
commit
fac9d8208e

+ 59
- 8
screens/HomeScreen.js View File

56
 
56
 
57
     /**
57
     /**
58
      * Converts a dateString using Unix Timestamp to a formatted date
58
      * Converts a dateString using Unix Timestamp to a formatted date
59
+     *
59
      * @param dateString {string} The Unix Timestamp representation of a date
60
      * @param dateString {string} The Unix Timestamp representation of a date
60
      * @return {string} The formatted output date
61
      * @return {string} The formatted output date
61
      */
62
      */
80
         this.props.navigation.navigate('SelfMenuScreen');
81
         this.props.navigation.navigate('SelfMenuScreen');
81
     }
82
     }
82
 
83
 
84
+    /**
85
+     * Extract a key for the given item
86
+     *
87
+     * @param item The item to extract the key from
88
+     * @return {*} The extracted key
89
+     */
83
     getKeyExtractor(item: Object) {
90
     getKeyExtractor(item: Object) {
84
         return item !== undefined ? item.id : undefined;
91
         return item !== undefined ? item.id : undefined;
85
     }
92
     }
86
 
93
 
94
+    /**
95
+     * Creates the dataset to be used in the FlatList
96
+     *
97
+     * @param fetchedData
98
+     * @return {*}
99
+     */
87
     createDataset(fetchedData: Object) {
100
     createDataset(fetchedData: Object) {
88
         // fetchedData = DATA;
101
         // fetchedData = DATA;
89
         let newsData = [];
102
         let newsData = [];
110
         ];
123
         ];
111
     }
124
     }
112
 
125
 
126
+    /**
127
+     * Generates the dataset associated to the dashboard to be displayed in the FlatList as a section
128
+     *
129
+     * @param dashboardData
130
+     * @return {*}
131
+     */
113
     generateDashboardDataset(dashboardData: Object) {
132
     generateDashboardDataset(dashboardData: Object) {
114
         let dataset = [
133
         let dataset = [
115
 
134
 
145
         return dataset
164
         return dataset
146
     }
165
     }
147
 
166
 
167
+    /**
168
+     * Gets a dashboard item
169
+     *
170
+     * @param item The item to display
171
+     * @return {*}
172
+     */
148
     getDashboardItem(item: Object) {
173
     getDashboardItem(item: Object) {
149
         let content = item['content'];
174
         let content = item['content'];
150
         if (item['id'] === 'event')
175
         if (item['id'] === 'event')
154
     }
179
     }
155
 
180
 
156
     /**
181
     /**
157
-     * Get the time limit depending on the current day:
182
+     * Gets the time limit depending on the current day:
158
      * 17:30 for every day of the week except for thursday 11:30
183
      * 17:30 for every day of the week except for thursday 11:30
159
      * 00:00 on weekends
184
      * 00:00 on weekends
160
      */
185
      */
170
     }
195
     }
171
 
196
 
172
     /**
197
     /**
173
-     * Get the duration (in milliseconds) of an event
198
+     * Gets the duration (in milliseconds) of an event
199
+     *
174
      * @param event {Object}
200
      * @param event {Object}
175
      * @return {number} The number of milliseconds
201
      * @return {number} The number of milliseconds
176
      */
202
      */
184
     }
210
     }
185
 
211
 
186
     /**
212
     /**
187
-     * Get events starting after the limit
213
+     * Gets events starting after the limit
188
      *
214
      *
189
      * @param events
215
      * @param events
190
      * @param limit
216
      * @param limit
202
     }
228
     }
203
 
229
 
204
     /**
230
     /**
205
-     * Get the event with the longest duration in the given array.
231
+     * Gets the event with the longest duration in the given array.
206
      * If all events have the same duration, return the first in the array.
232
      * If all events have the same duration, return the first in the array.
233
+     *
207
      * @param events
234
      * @param events
208
      */
235
      */
209
     getLongestEvent(events: Array<Object>): Object {
236
     getLongestEvent(events: Array<Object>): Object {
220
     }
247
     }
221
 
248
 
222
     /**
249
     /**
223
-     * Get events that have not yet ended/started
250
+     * Gets events that have not yet ended/started
224
      *
251
      *
225
      * @param events
252
      * @param events
226
      */
253
      */
243
     }
270
     }
244
 
271
 
245
     /**
272
     /**
246
-     *
273
+     * Gets the event to display in the preview
247
      *
274
      *
248
      * @param events
275
      * @param events
249
      * @return {Object}
276
      * @return {Object}
266
         return displayEvent;
293
         return displayEvent;
267
     }
294
     }
268
 
295
 
269
-
296
+    /**
297
+     * Gets the event render item.
298
+     * If a preview is available, it will be rendered inside
299
+     *
300
+     * @param content
301
+     * @return {*}
302
+     */
270
     getDashboardEventItem(content: Array<Object>) {
303
     getDashboardEventItem(content: Array<Object>) {
271
         let icon = 'calendar-range';
304
         let icon = 'calendar-range';
272
         let title = i18n.t('homeScreen.dashboard.todayEventsTitle');
305
         let title = i18n.t('homeScreen.dashboard.todayEventsTitle');
310
         );
343
         );
311
     }
344
     }
312
 
345
 
313
-
346
+    /**
347
+     * Gets a classic dashboard item.
348
+     *
349
+     * @param content
350
+     * @return {*}
351
+     */
314
     getDashboardMiddleItem(content: Array<Object>) {
352
     getDashboardMiddleItem(content: Array<Object>) {
315
         let proxiwashData = content[0]['data'];
353
         let proxiwashData = content[0]['data'];
316
         let tutorinsaData = content[1]['data'];
354
         let tutorinsaData = content[1]['data'];
367
         WebBrowser.openBrowserAsync(link);
405
         WebBrowser.openBrowserAsync(link);
368
     }
406
     }
369
 
407
 
408
+    /**
409
+     * Gets a render item for the given feed object
410
+     *
411
+     * @param item The feed item to display
412
+     * @return {*}
413
+     */
370
     getFeedItem(item: Object) {
414
     getFeedItem(item: Object) {
371
         const onImagePress = this.openLink.bind(this, item.full_picture);
415
         const onImagePress = this.openLink.bind(this, item.full_picture);
372
         const onOutLinkPress = this.openLink.bind(this, item.permalink_url);
416
         const onOutLinkPress = this.openLink.bind(this, item.permalink_url);
382
         );
426
         );
383
     }
427
     }
384
 
428
 
429
+    /**
430
+     * Gets a FlatList render item
431
+     *
432
+     * @param item The item to display
433
+     * @param section The current section
434
+     * @return {*}
435
+     */
385
     getRenderItem({item, section}: Object) {
436
     getRenderItem({item, section}: Object) {
386
         return (section['id'] === SECTIONS_ID[0] ?
437
         return (section['id'] === SECTIONS_ID[0] ?
387
             this.getDashboardItem(item) : this.getFeedItem(item));
438
             this.getDashboardItem(item) : this.getFeedItem(item));

+ 1
- 1
screens/Planning/PlanningDisplayScreen.js View File

18
 }
18
 }
19
 
19
 
20
 /**
20
 /**
21
- * Class defining an about screen. This screen shows the user information about the app and it's author.
21
+ * Class defining a planning event information page.
22
  */
22
  */
23
 class PlanningDisplayScreen extends React.Component<Props> {
23
 class PlanningDisplayScreen extends React.Component<Props> {
24
 
24
 

+ 37
- 2
screens/Planning/PlanningScreen.js View File

78
         this.onBackButtonPressAndroid = this.onBackButtonPressAndroid.bind(this);
78
         this.onBackButtonPressAndroid = this.onBackButtonPressAndroid.bind(this);
79
     }
79
     }
80
 
80
 
81
+    /**
82
+     * Captures focus and blur events to hook on android back button
83
+     */
81
     componentDidMount() {
84
     componentDidMount() {
82
         this.onRefresh();
85
         this.onRefresh();
83
         this.didFocusSubscription = this.props.navigation.addListener(
86
         this.didFocusSubscription = this.props.navigation.addListener(
98
         );
101
         );
99
     }
102
     }
100
 
103
 
104
+    /**
105
+     * Overrides default android back button behaviour to close the calendar if it was open.
106
+     *
107
+     * @return {boolean}
108
+     */
101
     onBackButtonPressAndroid() {
109
     onBackButtonPressAndroid() {
102
         if (this.state.calendarShowing) {
110
         if (this.state.calendarShowing) {
103
             this.agendaRef.chooseDay(this.agendaRef.state.selectedDay);
111
             this.agendaRef.chooseDay(this.agendaRef.state.selectedDay);
107
         }
115
         }
108
     };
116
     };
109
 
117
 
118
+    /**
119
+     * Function used to check if a row has changed
120
+     *
121
+     * @param r1
122
+     * @param r2
123
+     * @return {boolean}
124
+     */
110
     rowHasChanged(r1: Object, r2: Object) {
125
     rowHasChanged(r1: Object, r2: Object) {
111
         return false;
126
         return false;
112
         // if (r1 !== undefined && r2 !== undefined)
127
         // if (r1 !== undefined && r2 !== undefined)
115
     }
130
     }
116
 
131
 
117
     /**
132
     /**
118
-     * Refresh data and show a toast if any error occurred
119
-     * @private
133
+     * Refreshes data and shows an animation while doing it
120
      */
134
      */
121
     onRefresh = () => {
135
     onRefresh = () => {
122
         let canRefresh;
136
         let canRefresh;
143
         }
157
         }
144
     };
158
     };
145
 
159
 
160
+    /**
161
+     * Callback used when receiving the agenda ref
162
+     *
163
+     * @param ref
164
+     */
146
     onAgendaRef(ref: Object) {
165
     onAgendaRef(ref: Object) {
147
         this.agendaRef = ref;
166
         this.agendaRef = ref;
148
     }
167
     }
149
 
168
 
169
+    /**
170
+     * Callback used when a button is pressed to toggle the calendar
171
+     *
172
+     * @param isCalendarOpened True is the calendar is already open, false otherwise
173
+     */
150
     onCalendarToggled(isCalendarOpened: boolean) {
174
     onCalendarToggled(isCalendarOpened: boolean) {
151
         this.setState({calendarShowing: isCalendarOpened});
175
         this.setState({calendarShowing: isCalendarOpened});
152
     }
176
     }
153
 
177
 
178
+    /**
179
+     * Gets an event render item
180
+     *
181
+     * @param item The current event to render
182
+     * @return {*}
183
+     */
154
     getRenderItem(item: eventObject) {
184
     getRenderItem(item: eventObject) {
155
         const onPress = this.props.navigation.navigate.bind(this, 'PlanningDisplayScreen', {data: item});
185
         const onPress = this.props.navigation.navigate.bind(this, 'PlanningDisplayScreen', {data: item});
156
         if (item.logo !== null) {
186
         if (item.logo !== null) {
182
         }
212
         }
183
     }
213
     }
184
 
214
 
215
+    /**
216
+     * Gets an empty render item for an empty date
217
+     *
218
+     * @return {*}
219
+     */
185
     getRenderEmptyDate() {
220
     getRenderEmptyDate() {
186
         return (
221
         return (
187
             <Divider/>
222
             <Divider/>

+ 1
- 1
screens/Proximo/ProximoAboutScreen.js View File

10
 };
10
 };
11
 
11
 
12
 /**
12
 /**
13
- * Class defining an about screen. This screen shows the user information about the app and it's author.
13
+ * Class defining the proximo about screen.
14
  */
14
  */
15
 export default class ProximoAboutScreen extends React.Component<Props> {
15
 export default class ProximoAboutScreen extends React.Component<Props> {
16
 
16
 

+ 99
- 38
screens/Proximo/ProximoListScreen.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import * as React from 'react';
3
 import * as React from 'react';
4
-import {Platform, Image, ScrollView, View} from "react-native";
4
+import {Image, Platform, ScrollView, View} from "react-native";
5
 import i18n from "i18n-js";
5
 import i18n from "i18n-js";
6
 import CustomModal from "../../components/CustomModal";
6
 import CustomModal from "../../components/CustomModal";
7
 import {Avatar, IconButton, List, RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
7
 import {Avatar, IconButton, List, RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
77
 
77
 
78
 
78
 
79
     /**
79
     /**
80
-     * Set the sort mode from state when components are ready
80
+     * Creates the header content
81
      */
81
      */
82
     componentDidMount() {
82
     componentDidMount() {
83
-        const button = this.getSortMenu.bind(this);
83
+        const button = this.getSortMenuButton.bind(this);
84
         const title = this.getSearchBar.bind(this);
84
         const title = this.getSearchBar.bind(this);
85
         this.props.navigation.setOptions({
85
         this.props.navigation.setOptions({
86
             headerRight: button,
86
             headerRight: button,
93
     }
93
     }
94
 
94
 
95
     /**
95
     /**
96
-     * Set the current sort mode.
96
+     * Gets the header search bar
97
+     *
98
+     * @return {*}
99
+     */
100
+    getSearchBar() {
101
+        return (
102
+            <Searchbar
103
+                placeholder={i18n.t('proximoScreen.search')}
104
+                onChangeText={this.onSearchStringChange}
105
+            />
106
+        );
107
+    }
108
+
109
+    /**
110
+     * Gets the sort menu header button
111
+     *
112
+     * @return {*}
113
+     */
114
+    getSortMenuButton() {
115
+        return (
116
+            <IconButton
117
+                icon="sort"
118
+                color={this.colors.text}
119
+                size={26}
120
+                onPress={this.onSortMenuPress}
121
+            />
122
+        );
123
+    }
124
+
125
+    /**
126
+     * Callback used when clicking on the sort menu button.
127
+     * It will open the modal to show a sort selection
128
+     */
129
+    onSortMenuPress() {
130
+        this.setState({
131
+            modalCurrentDisplayItem: this.getModalSortMenu()
132
+        });
133
+        if (this.modalRef) {
134
+            this.modalRef.open();
135
+        }
136
+    }
137
+
138
+    /**
139
+     * Sets the current sort mode.
97
      *
140
      *
98
      * @param mode The number representing the mode
141
      * @param mode The number representing the mode
99
      */
142
      */
121
         }
164
         }
122
     }
165
     }
123
 
166
 
124
-    getSearchBar() {
125
-        return (
126
-            <Searchbar
127
-                placeholder={i18n.t('proximoScreen.search')}
128
-                onChangeText={this.onSearchStringChange}
129
-            />
130
-        );
131
-    }
132
-
133
     /**
167
     /**
134
-     * get color depending on quantity available
168
+     * Gets a color depending on the quantity available
135
      *
169
      *
136
-     * @param availableStock
170
+     * @param availableStock The quantity available
137
      * @return
171
      * @return
138
      */
172
      */
139
     getStockColor(availableStock: number) {
173
     getStockColor(availableStock: number) {
147
         return color;
181
         return color;
148
     }
182
     }
149
 
183
 
150
-    sanitizeString(str: string) {
184
+    /**
185
+     * Sanitizes the given string to improve search performance
186
+     *
187
+     * @param str The string to sanitize
188
+     * @return {string} The sanitized string
189
+     */
190
+    sanitizeString(str: string): string {
151
         return str.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
191
         return str.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
152
     }
192
     }
153
 
193
 
154
     /**
194
     /**
155
-     * Returns only the articles whose name contains str. Case and accents insensitive.
156
-     * @param str
195
+     * Returns only articles whose name contains the given string.
196
+     * Case and accents insensitive.
197
+     *
198
+     * @param str The string used to filter article names
157
      * @returns {[]}
199
      * @returns {[]}
158
      */
200
      */
159
     filterData(str: string) {
201
     filterData(str: string) {
169
         return filteredData;
211
         return filteredData;
170
     }
212
     }
171
 
213
 
214
+    /**
215
+     * Callback used when the search changes
216
+     *
217
+     * @param str The new search string
218
+     */
172
     onSearchStringChange(str: string) {
219
     onSearchStringChange(str: string) {
173
         this.setState({
220
         this.setState({
174
             currentlyDisplayedData: this.filterData(str)
221
             currentlyDisplayedData: this.filterData(str)
175
         })
222
         })
176
     }
223
     }
177
 
224
 
225
+    /**
226
+     * Gets the modal content depending on the given article
227
+     *
228
+     * @param item The article to display
229
+     * @return {*}
230
+     */
178
     getModalItemContent(item: Object) {
231
     getModalItemContent(item: Object) {
179
         return (
232
         return (
180
             <View style={{
233
             <View style={{
206
         );
259
         );
207
     }
260
     }
208
 
261
 
262
+    /**
263
+     * Gets the modal content to display a sort menu
264
+     *
265
+     * @return {*}
266
+     */
209
     getModalSortMenu() {
267
     getModalSortMenu() {
210
         return (
268
         return (
211
             <View style={{
269
             <View style={{
254
         );
312
         );
255
     }
313
     }
256
 
314
 
315
+    /**
316
+     * Callback used when clicking an article in the list.
317
+     * It opens the modal to show detailed information about the article
318
+     *
319
+     * @param item The article pressed
320
+     */
257
     onListItemPress(item: Object) {
321
     onListItemPress(item: Object) {
258
         this.setState({
322
         this.setState({
259
             modalCurrentDisplayItem: this.getModalItemContent(item)
323
             modalCurrentDisplayItem: this.getModalItemContent(item)
263
         }
327
         }
264
     }
328
     }
265
 
329
 
266
-    onSortMenuPress() {
267
-        this.setState({
268
-            modalCurrentDisplayItem: this.getModalSortMenu()
269
-        });
270
-        if (this.modalRef) {
271
-            this.modalRef.open();
272
-        }
273
-    }
274
-
275
-    getSortMenu() {
276
-        return (
277
-            <IconButton
278
-                icon="sort"
279
-                color={this.colors.text}
280
-                size={26}
281
-                onPress={this.onSortMenuPress}
282
-            />
283
-        );
284
-    }
285
-
330
+    /**
331
+     * Gets a render item for the given article
332
+     *
333
+     * @param item The article to render
334
+     * @return {*}
335
+     */
286
     renderItem({item}: Object) {
336
     renderItem({item}: Object) {
287
         const onPress = this.onListItemPress.bind(this, item);
337
         const onPress = this.onListItemPress.bind(this, item);
288
         return (
338
         return (
301
         );
351
         );
302
     }
352
     }
303
 
353
 
354
+    /**
355
+     * Extracts a key for the given article
356
+     *
357
+     * @param item The article to extract the key from
358
+     * @return {*} The extracted key
359
+     */
304
     keyExtractor(item: Object) {
360
     keyExtractor(item: Object) {
305
         return item.name + item.code;
361
         return item.name + item.code;
306
     }
362
     }
307
 
363
 
364
+    /**
365
+     * Callback used when receiving the modal ref
366
+     *
367
+     * @param ref
368
+     */
308
     onModalRef(ref: Object) {
369
     onModalRef(ref: Object) {
309
         this.modalRef = ref;
370
         this.modalRef = ref;
310
     }
371
     }

+ 76
- 36
screens/Proximo/ProximoMainScreen.js View File

18
 }
18
 }
19
 
19
 
20
 /**
20
 /**
21
- * Class defining the main proximo screen. This screen shows the different categories of articles
22
- * offered by proximo.
21
+ * Class defining the main proximo screen.
22
+ * This screen shows the different categories of articles offered by proximo.
23
  */
23
  */
24
 class ProximoMainScreen extends React.Component<Props, State> {
24
 class ProximoMainScreen extends React.Component<Props, State> {
25
 
25
 
41
         this.colors = props.theme.colors;
41
         this.colors = props.theme.colors;
42
     }
42
     }
43
 
43
 
44
+    /**
45
+     * Function used to sort items in the list.
46
+     * Makes the All category stick to the top and sorts the others by name ascending
47
+     *
48
+     * @param a
49
+     * @param b
50
+     * @return {number}
51
+     */
44
     static sortFinalData(a: Object, b: Object) {
52
     static sortFinalData(a: Object, b: Object) {
45
         let str1 = a.type.name.toLowerCase();
53
         let str1 = a.type.name.toLowerCase();
46
         let str2 = b.type.name.toLowerCase();
54
         let str2 = b.type.name.toLowerCase();
59
         return 0;
67
         return 0;
60
     }
68
     }
61
 
69
 
70
+    /**
71
+     * Creates header button
72
+     */
62
     componentDidMount() {
73
     componentDidMount() {
63
-        const rightButton = this.getRightButton.bind(this);
74
+        const rightButton = this.getHeaderButtons.bind(this);
64
         this.props.navigation.setOptions({
75
         this.props.navigation.setOptions({
65
             headerRight: rightButton,
76
             headerRight: rightButton,
66
         });
77
         });
67
     }
78
     }
68
 
79
 
80
+    /**
81
+     * Callback used when the search button is pressed.
82
+     * This will open a new ProximoListScreen with all items displayed
83
+     */
84
+    onPressSearchBtn() {
85
+        let searchScreenData = {
86
+            shouldFocusSearchBar: true,
87
+            data: {
88
+                type: {
89
+                    id: "0",
90
+                    name: i18n.t('proximoScreen.all'),
91
+                    icon: 'star'
92
+                },
93
+                data: this.articles !== undefined ?
94
+                    this.getAvailableArticles(this.articles, undefined) : []
95
+            },
96
+        };
97
+        this.props.navigation.navigate('ProximoListScreen', searchScreenData);
98
+    }
99
+
100
+    /**
101
+     * Callback used when the about button is pressed.
102
+     * This will open the ProximoAboutScreen
103
+     */
104
+    onPressAboutBtn() {
105
+        this.props.navigation.navigate('ProximoAboutScreen');
106
+    }
107
+
108
+    /**
109
+     * Gets the header buttons
110
+     * @return {*}
111
+     */
112
+    getHeaderButtons() {
113
+        return (
114
+            <View
115
+                style={{
116
+                    flexDirection: 'row',
117
+                }}>
118
+                <HeaderButton icon={'magnify'} onPress={this.onPressSearchBtn}/>
119
+                <HeaderButton icon={'information'} onPress={this.onPressAboutBtn}/>
120
+            </View>
121
+        );
122
+    }
123
+
124
+    /**
125
+     * Extracts a key for the given category
126
+     *
127
+     * @param item The category to extract the key from
128
+     * @return {*} The extracted key
129
+     */
69
     getKeyExtractor(item: Object) {
130
     getKeyExtractor(item: Object) {
70
         return item !== undefined ? item.type['id'] : undefined;
131
         return item !== undefined ? item.type['id'] : undefined;
71
     }
132
     }
72
 
133
 
134
+    /**
135
+     * Creates the dataset to be used in the FlatList
136
+     *
137
+     * @param fetchedData
138
+     * @return {*}
139
+     * */
73
     createDataset(fetchedData: Object) {
140
     createDataset(fetchedData: Object) {
74
         return [
141
         return [
75
             {
142
             {
133
         return availableArticles;
200
         return availableArticles;
134
     }
201
     }
135
 
202
 
136
-    onPressSearchBtn() {
137
-        let searchScreenData = {
138
-            shouldFocusSearchBar: true,
139
-            data: {
140
-                type: {
141
-                    id: "0",
142
-                    name: i18n.t('proximoScreen.all'),
143
-                    icon: 'star'
144
-                },
145
-                data: this.articles !== undefined ?
146
-                    this.getAvailableArticles(this.articles, undefined) : []
147
-            },
148
-        };
149
-        this.props.navigation.navigate('ProximoListScreen', searchScreenData);
150
-    }
151
-
152
-    onPressAboutBtn() {
153
-        this.props.navigation.navigate('ProximoAboutScreen');
154
-    }
155
-
156
-    getRightButton() {
157
-        return (
158
-            <View
159
-                style={{
160
-                    flexDirection: 'row',
161
-                }}>
162
-                <HeaderButton icon={'magnify'} onPress={this.onPressSearchBtn}/>
163
-                <HeaderButton icon={'information'} onPress={this.onPressAboutBtn}/>
164
-            </View>
165
-        );
166
-    }
167
-
168
-
203
+    /**
204
+     * Gets the given category render item
205
+     *
206
+     * @param item The category to render
207
+     * @return {*}
208
+     */
169
     getRenderItem({item}: Object) {
209
     getRenderItem({item}: Object) {
170
         let dataToSend = {
210
         let dataToSend = {
171
             shouldFocusSearchBar: false,
211
             shouldFocusSearchBar: false,

+ 1
- 1
screens/Proxiwash/ProxiwashAboutScreen.js View File

10
 };
10
 };
11
 
11
 
12
 /**
12
 /**
13
- * Class defining an about screen. This screen shows the user information about the app and it's author.
13
+ * Class defining the proxiwash about screen.
14
  */
14
  */
15
 export default class ProxiwashAboutScreen extends React.Component<Props> {
15
 export default class ProxiwashAboutScreen extends React.Component<Props> {
16
 
16
 

+ 83
- 27
screens/Proxiwash/ProxiwashScreen.js View File

58
         refreshing: false,
58
         refreshing: false,
59
         firstLoading: true,
59
         firstLoading: true,
60
         fetchedData: {},
60
         fetchedData: {},
61
-        // machinesWatched: JSON.parse(dataString),
62
         machinesWatched: [],
61
         machinesWatched: [],
63
         modalCurrentDisplayItem: null,
62
         modalCurrentDisplayItem: null,
64
         bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
63
         bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
97
         this.colors = props.theme.colors;
96
         this.colors = props.theme.colors;
98
     }
97
     }
99
 
98
 
99
+    /**
100
+     * Callback used when closing the banner.
101
+     * This hides the banner and saves to preferences to prevent it from reopening
102
+     */
100
     onHideBanner() {
103
     onHideBanner() {
101
         this.setState({bannerVisible: false});
104
         this.setState({bannerVisible: false});
102
         AsyncStorageManager.getInstance().savePref(
105
         AsyncStorageManager.getInstance().savePref(
109
      * Setup notification channel for android and add listeners to detect notifications fired
112
      * Setup notification channel for android and add listeners to detect notifications fired
110
      */
113
      */
111
     componentDidMount() {
114
     componentDidMount() {
112
-        const rightButton = this.getRightButton.bind(this);
115
+        const rightButton = this.getAboutButton.bind(this);
113
         this.props.navigation.setOptions({
116
         this.props.navigation.setOptions({
114
             headerRight: rightButton,
117
             headerRight: rightButton,
115
         });
118
         });
134
         }
137
         }
135
     }
138
     }
136
 
139
 
137
-    getDryersKeyExtractor(item: Object) {
138
-        return item !== undefined ? "dryer" + item.number : undefined;
140
+    /**
141
+     * Callback used when pressing the about button.
142
+     * This will open the ProxiwashAboutScreen.
143
+     */
144
+    onAboutPress() {
145
+        this.props.navigation.navigate('ProxiwashAboutScreen');
139
     }
146
     }
140
 
147
 
141
-    getWashersKeyExtractor(item: Object) {
142
-        return item !== undefined ? "washer" + item.number : undefined;
148
+    /**
149
+     * Gets the about header button
150
+     *
151
+     * @return {*}
152
+     */
153
+    getAboutButton() {
154
+        return <HeaderButton icon={'information'} onPress={this.onAboutPress}/>;
143
     }
155
     }
144
 
156
 
145
     /**
157
     /**
146
-     * Setup notifications for the machine with the given ID.
158
+     * Extracts the key for the given item
159
+     *
160
+     * @param item The item to extract the key from
161
+     * @return {*} The extracted key
162
+     */
163
+    getKeyExtractor(item: Object) {
164
+        return item !== undefined ? item.number : undefined;
165
+    }
166
+
167
+    /**
168
+     * Setups notifications for the machine with the given ID.
147
      * One notification will be sent at the end of the program.
169
      * One notification will be sent at the end of the program.
148
      * Another will be send a few minutes before the end, based on the value of reminderNotifTime
170
      * Another will be send a few minutes before the end, based on the value of reminderNotifTime
149
      *
171
      *
162
         }
184
         }
163
     }
185
     }
164
 
186
 
187
+    /**
188
+     * Shows a warning telling the user notifications are disabled for the app
189
+     */
165
     showNotificationsDisabledWarning() {
190
     showNotificationsDisabledWarning() {
166
         Alert.alert(
191
         Alert.alert(
167
             i18n.t("proxiwashScreen.modal.notificationErrorTitle"),
192
             i18n.t("proxiwashScreen.modal.notificationErrorTitle"),
170
     }
195
     }
171
 
196
 
172
     /**
197
     /**
173
-     * Stop scheduled notifications for the machine of the given ID.
198
+     * Stops scheduled notifications for the machine of the given ID.
174
      * This will also remove the notification if it was already shown.
199
      * This will also remove the notification if it was already shown.
175
      *
200
      *
176
      * @param machineId The machine's ID
201
      * @param machineId The machine's ID
187
     }
212
     }
188
 
213
 
189
     /**
214
     /**
190
-     * Add the given notifications associated to a machine ID to the watchlist, and save the array to the preferences
215
+     * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
191
      *
216
      *
192
      * @param machineId
217
      * @param machineId
193
      */
218
      */
198
     }
223
     }
199
 
224
 
200
     /**
225
     /**
201
-     * remove the given index from the watchlist array and save it to preferences
226
+     * Removes the given index from the watchlist array and saves it to preferences
202
      *
227
      *
203
      * @param index
228
      * @param index
204
      */
229
      */
209
     }
234
     }
210
 
235
 
211
     /**
236
     /**
212
-     * Set the given data as the watchlist and save it to preferences
237
+     * Sets the given data as the watchlist
213
      *
238
      *
214
      * @param data
239
      * @param data
215
      */
240
      */
216
     updateNotificationState(data: Array<Object>) {
241
     updateNotificationState(data: Array<Object>) {
217
         this.setState({machinesWatched: data});
242
         this.setState({machinesWatched: data});
218
-        // let prefKey = AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.key;
219
-        // AsyncStorageManager.getInstance().savePref(prefKey, JSON.stringify(data));
220
     }
243
     }
221
 
244
 
222
     /**
245
     /**
229
         return this.state.machinesWatched.indexOf(machineID) !== -1;
252
         return this.state.machinesWatched.indexOf(machineID) !== -1;
230
     }
253
     }
231
 
254
 
255
+    /**
256
+     * Creates the dataset to be used by the flatlist
257
+     *
258
+     * @param fetchedData
259
+     * @return {*}
260
+     */
232
     createDataset(fetchedData: Object) {
261
     createDataset(fetchedData: Object) {
233
         let data = fetchedData;
262
         let data = fetchedData;
234
         if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) {
263
         if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) {
244
                 icon: 'tumble-dryer',
273
                 icon: 'tumble-dryer',
245
                 data: data.dryers === undefined ? [] : data.dryers,
274
                 data: data.dryers === undefined ? [] : data.dryers,
246
                 extraData: this.state,
275
                 extraData: this.state,
247
-                keyExtractor: this.getDryersKeyExtractor
276
+                keyExtractor: this.getKeyExtractor
248
             },
277
             },
249
             {
278
             {
250
                 title: i18n.t('proxiwashScreen.washers'),
279
                 title: i18n.t('proxiwashScreen.washers'),
251
                 icon: 'washing-machine',
280
                 icon: 'washing-machine',
252
                 data: data.washers === undefined ? [] : data.washers,
281
                 data: data.washers === undefined ? [] : data.washers,
253
                 extraData: this.state,
282
                 extraData: this.state,
254
-                keyExtractor: this.getWashersKeyExtractor
283
+                keyExtractor: this.getKeyExtractor
255
             },
284
             },
256
         ];
285
         ];
257
     }
286
     }
258
 
287
 
288
+    /**
289
+     * Shows a modal for the given item
290
+     *
291
+     * @param title The title to use
292
+     * @param item The item to display information for in the modal
293
+     * @param isDryer True if the given item is a dryer
294
+     */
259
     showModal(title: string, item: Object, isDryer: boolean) {
295
     showModal(title: string, item: Object, isDryer: boolean) {
260
         this.setState({
296
         this.setState({
261
             modalCurrentDisplayItem: this.getModalContent(title, item, isDryer)
297
             modalCurrentDisplayItem: this.getModalContent(title, item, isDryer)
265
         }
301
         }
266
     }
302
     }
267
 
303
 
304
+    /**
305
+     * Callback used when the user clicks on enable notifications for a machine
306
+     *
307
+     * @param machineId The machine's id to set notifications for
308
+     */
268
     onSetupNotificationsPress(machineId: string) {
309
     onSetupNotificationsPress(machineId: string) {
269
         if (this.modalRef) {
310
         if (this.modalRef) {
270
             this.modalRef.close();
311
             this.modalRef.close();
272
         this.setupNotifications(machineId)
313
         this.setupNotifications(machineId)
273
     }
314
     }
274
 
315
 
316
+    /**
317
+     * Generates the modal content.
318
+     * This shows information for the given machine.
319
+     *
320
+     * @param title The title to use
321
+     * @param item The item to display information for in the modal
322
+     * @param isDryer True if the given item is a dryer
323
+     * @return {*}
324
+     */
275
     getModalContent(title: string, item: Object, isDryer: boolean) {
325
     getModalContent(title: string, item: Object, isDryer: boolean) {
276
         let button = {
326
         let button = {
277
             text: i18n.t("proxiwashScreen.modal.ok"),
327
             text: i18n.t("proxiwashScreen.modal.ok"),
334
         );
384
         );
335
     }
385
     }
336
 
386
 
337
-    onAboutPress() {
338
-        this.props.navigation.navigate('ProxiwashAboutScreen');
339
-    }
340
-
341
-    getRightButton() {
342
-        return (
343
-            <HeaderButton icon={'information'} onPress={this.onAboutPress}/>
344
-        );
345
-    }
346
-
387
+    /**
388
+     * Callback used when receiving modal ref
389
+     *
390
+     * @param ref
391
+     */
347
     onModalRef(ref: Object) {
392
     onModalRef(ref: Object) {
348
         this.modalRef = ref;
393
         this.modalRef = ref;
349
     }
394
     }
350
 
395
 
396
+    /**
397
+     * Gets the number of machines available
398
+     *
399
+     * @param isDryer True if we are only checking for dryer, false for washers
400
+     * @return {number} The number of machines available
401
+     */
351
     getMachineAvailableNumber(isDryer: boolean) {
402
     getMachineAvailableNumber(isDryer: boolean) {
352
         let data;
403
         let data;
353
         if (isDryer)
404
         if (isDryer)
362
         return count;
413
         return count;
363
     }
414
     }
364
 
415
 
416
+    /**
417
+     * Gets the section render item
418
+     *
419
+     * @param section The section to render
420
+     * @return {*}
421
+     */
365
     getRenderSectionHeader({section}: Object) {
422
     getRenderSectionHeader({section}: Object) {
366
         const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
423
         const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
367
         const nbAvailable = this.getMachineAvailableNumber(isDryer);
424
         const nbAvailable = this.getMachineAvailableNumber(isDryer);
401
     }
458
     }
402
 
459
 
403
     /**
460
     /**
404
-     * Get list item to be rendered
461
+     * Gets the list item to be rendered
405
      *
462
      *
406
      * @param item The object containing the item's FetchedData
463
      * @param item The object containing the item's FetchedData
407
      * @param section The object describing the current SectionList section
464
      * @param section The object describing the current SectionList section
467
                     refreshOnFocus={true}
524
                     refreshOnFocus={true}
468
                     updateData={this.state.machinesWatched.length}/>
525
                     updateData={this.state.machinesWatched.length}/>
469
             </View>
526
             </View>
470
-
471
         );
527
         );
472
     }
528
     }
473
 }
529
 }

+ 30
- 1
screens/SelfMenuScreen.js View File

15
 
15
 
16
 /**
16
 /**
17
  * Class defining the app's menu screen.
17
  * Class defining the app's menu screen.
18
- * This screen fetches data from etud to render the RU menu
19
  */
18
  */
20
 class SelfMenuScreen extends React.Component<Props> {
19
 class SelfMenuScreen extends React.Component<Props> {
21
 
20
 
33
         this.colors = props.theme.colors;
32
         this.colors = props.theme.colors;
34
     }
33
     }
35
 
34
 
35
+    /**
36
+     * Extract a key for the given item
37
+     *
38
+     * @param item The item to extract the key from
39
+     * @return {*} The extracted key
40
+     */
36
     getKeyExtractor(item: Object) {
41
     getKeyExtractor(item: Object) {
37
         return item !== undefined ? item['name'] : undefined;
42
         return item !== undefined ? item['name'] : undefined;
38
     }
43
     }
39
 
44
 
45
+    /**
46
+     * Creates the dataset to be used in the FlatList
47
+     *
48
+     * @param fetchedData
49
+     * @return {[]}
50
+     */
40
     createDataset(fetchedData: Object) {
51
     createDataset(fetchedData: Object) {
41
         let result = [];
52
         let result = [];
42
         // Prevent crash by giving a default value when fetchedData is empty (not yet available)
53
         // Prevent crash by giving a default value when fetchedData is empty (not yet available)
66
         return result
77
         return result
67
     }
78
     }
68
 
79
 
80
+    /**
81
+     * Gets the render section header
82
+     *
83
+     * @param section The section to render the header from
84
+     * @return {*}
85
+     */
69
     getRenderSectionHeader({section}: Object) {
86
     getRenderSectionHeader({section}: Object) {
70
         return (
87
         return (
71
             <Card style={{
88
             <Card style={{
92
         );
109
         );
93
     }
110
     }
94
 
111
 
112
+    /**
113
+     * Gets a FlatList render item
114
+     *
115
+     * @param item The item to render
116
+     * @return {*}
117
+     */
95
     getRenderItem({item}: Object) {
118
     getRenderItem({item}: Object) {
96
         return (
119
         return (
97
             <Card style={{
120
             <Card style={{
128
         );
151
         );
129
     }
152
     }
130
 
153
 
154
+    /**
155
+     * Formats the given string to make sure it starts with a capital letter
156
+     *
157
+     * @param name The string to format
158
+     * @return {string} The formatted string
159
+     */
131
     formatName(name: String) {
160
     formatName(name: String) {
132
         return name.charAt(0) + name.substr(1).toLowerCase();
161
         return name.charAt(0) + name.substr(1).toLowerCase();
133
     }
162
     }

+ 14
- 15
screens/SettingsScreen.js View File

27
     state = {
27
     state = {
28
         nightMode: ThemeManager.getNightMode(),
28
         nightMode: ThemeManager.getNightMode(),
29
         nightModeFollowSystem: AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' &&
29
         nightModeFollowSystem: AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' &&
30
-        Appearance.getColorScheme() !== 'no-preference',
30
+            Appearance.getColorScheme() !== 'no-preference',
31
         proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
31
         proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
32
         startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
32
         startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
33
     };
33
     };
46
     }
46
     }
47
 
47
 
48
     /**
48
     /**
49
-     * Save the value for the proxiwash reminder notification time
49
+     * Saves the value for the proxiwash reminder notification time
50
      *
50
      *
51
      * @param value The value to store
51
      * @param value The value to store
52
      */
52
      */
65
     }
65
     }
66
 
66
 
67
     /**
67
     /**
68
-     * Save the value for the proxiwash reminder notification time
68
+     * Saves the value for the proxiwash reminder notification time
69
      *
69
      *
70
      * @param value The value to store
70
      * @param value The value to store
71
      */
71
      */
118
     }
118
     }
119
 
119
 
120
     /**
120
     /**
121
-     * Toggle night mode and save it to preferences
121
+     * Toggles night mode and saves it to preferences
122
      */
122
      */
123
     onToggleNightMode() {
123
     onToggleNightMode() {
124
         ThemeManager.getInstance().setNightMode(!this.state.nightMode);
124
         ThemeManager.getInstance().setNightMode(!this.state.nightMode);
138
     }
138
     }
139
 
139
 
140
     /**
140
     /**
141
-     * Get a list item using a checkbox control
141
+     * Gets a list item using a checkbox control
142
      *
142
      *
143
      * @param onPressCallback The callback when the checkbox state changes
143
      * @param onPressCallback The callback when the checkbox state changes
144
      * @param icon The icon name to display on the list item
144
      * @param icon The icon name to display on the list item
178
                         ) : null}
178
                         ) : null}
179
                         {
179
                         {
180
                             Appearance.getColorScheme() === 'no-preference' || !this.state.nightModeFollowSystem ?
180
                             Appearance.getColorScheme() === 'no-preference' || !this.state.nightModeFollowSystem ?
181
-                            this.getToggleItem(
182
-                                this.onToggleNightMode,
183
-                                'theme-light-dark',
184
-                                i18n.t('settingsScreen.nightMode'),
185
-                                this.state.nightMode ?
186
-                                    i18n.t('settingsScreen.nightModeSubOn') :
187
-                                    i18n.t('settingsScreen.nightModeSubOff'),
188
-                                this.state.nightMode
189
-                            ) : null
181
+                                this.getToggleItem(
182
+                                    this.onToggleNightMode,
183
+                                    'theme-light-dark',
184
+                                    i18n.t('settingsScreen.nightMode'),
185
+                                    this.state.nightMode ?
186
+                                        i18n.t('settingsScreen.nightModeSubOn') :
187
+                                        i18n.t('settingsScreen.nightModeSubOff'),
188
+                                    this.state.nightMode
189
+                                ) : null
190
                         }
190
                         }
191
                         <List.Accordion
191
                         <List.Accordion
192
                             title={i18n.t('settingsScreen.startScreen')}
192
                             title={i18n.t('settingsScreen.startScreen')}
209
                         </List.Accordion>
209
                         </List.Accordion>
210
                     </List.Section>
210
                     </List.Section>
211
                 </Card>
211
                 </Card>
212
-
213
             </ScrollView>
212
             </ScrollView>
214
         );
213
         );
215
     }
214
     }

+ 5
- 3
screens/Websites/AvailableRoomScreen.js View File

14
 const CUSTOM_CSS_GENERAL = 'https://etud.insa-toulouse.fr/~amicale_app/custom_css/rooms/customMobile.css';
14
 const CUSTOM_CSS_GENERAL = 'https://etud.insa-toulouse.fr/~amicale_app/custom_css/rooms/customMobile.css';
15
 
15
 
16
 /**
16
 /**
17
- * Class defining the app's planex screen.
18
- * This screen uses a webview to render the planex page
17
+ * Class defining the app's available rooms screen.
18
+ * This screen uses a webview to render the page
19
  */
19
  */
20
 export default class AvailableRoomScreen extends React.Component<Props> {
20
 export default class AvailableRoomScreen extends React.Component<Props> {
21
 
21
 
22
     customInjectedJS: string;
22
     customInjectedJS: string;
23
-    customBibInjectedJS: string;
24
 
23
 
24
+    /**
25
+     * Defines custom injected JavaScript to improve the page display on mobile
26
+     */
25
     constructor() {
27
     constructor() {
26
         super();
28
         super();
27
         this.customInjectedJS =
29
         this.customInjectedJS =

+ 5
- 2
screens/Websites/BibScreen.js View File

13
 const CUSTOM_CSS_Bib = 'https://etud.insa-toulouse.fr/~amicale_app/custom_css/rooms/customBibMobile.css';
13
 const CUSTOM_CSS_Bib = 'https://etud.insa-toulouse.fr/~amicale_app/custom_css/rooms/customBibMobile.css';
14
 
14
 
15
 /**
15
 /**
16
- * Class defining the app's planex screen.
17
- * This screen uses a webview to render the planex page
16
+ * Class defining the app's Bib screen.
17
+ * This screen uses a webview to render the page
18
  */
18
  */
19
 export default class AvailableRoomScreen extends React.Component<Props> {
19
 export default class AvailableRoomScreen extends React.Component<Props> {
20
 
20
 
21
     customInjectedJS: string;
21
     customInjectedJS: string;
22
     customBibInjectedJS: string;
22
     customBibInjectedJS: string;
23
 
23
 
24
+    /**
25
+     * Defines custom injected JavaScript to improve the page display on mobile
26
+     */
24
     constructor() {
27
     constructor() {
25
         super();
28
         super();
26
         this.customInjectedJS =
29
         this.customInjectedJS =

+ 20
- 9
screens/Websites/PlanexScreen.js View File

80
     '    removeAlpha($(this));\n' +
80
     '    removeAlpha($(this));\n' +
81
     '});';
81
     '});';
82
 /**
82
 /**
83
- * Class defining the app's planex screen.
84
- * This screen uses a webview to render the planex page
83
+ * Class defining the app's Planex screen.
84
+ * This screen uses a webview to render the page
85
  */
85
  */
86
 export default class PlanexScreen extends React.Component<Props, State> {
86
 export default class PlanexScreen extends React.Component<Props, State> {
87
 
87
 
88
     customInjectedJS: string;
88
     customInjectedJS: string;
89
     onHideBanner: Function;
89
     onHideBanner: Function;
90
     onGoToSettings: Function;
90
     onGoToSettings: Function;
91
+    state = {
92
+        bannerVisible:
93
+            AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' &&
94
+            AsyncStorageManager.getInstance().preferences.defaultStartScreen.current !== 'Planex',
95
+    };
91
 
96
 
97
+    /**
98
+     * Defines custom injected JavaScript to improve the page display on mobile
99
+     */
92
     constructor() {
100
     constructor() {
93
         super();
101
         super();
94
         this.customInjectedJS =
102
         this.customInjectedJS =
102
 
110
 
103
         this.customInjectedJS +=
111
         this.customInjectedJS +=
104
             'removeAlpha();' +
112
             'removeAlpha();' +
105
-            '});true;'; // Prevent crash on ios
113
+            '});true;'; // Prevents crash on ios
106
         this.onHideBanner = this.onHideBanner.bind(this);
114
         this.onHideBanner = this.onHideBanner.bind(this);
107
         this.onGoToSettings = this.onGoToSettings.bind(this);
115
         this.onGoToSettings = this.onGoToSettings.bind(this);
108
     }
116
     }
109
 
117
 
110
-    state = {
111
-        bannerVisible:
112
-            AsyncStorageManager.getInstance().preferences.planexShowBanner.current === '1' &&
113
-            AsyncStorageManager.getInstance().preferences.defaultStartScreen.current !== 'Planex',
114
-    };
115
-
118
+    /**
119
+     * Callback used when closing the banner.
120
+     * This hides the banner and saves to preferences to prevent it from reopening
121
+     */
116
     onHideBanner() {
122
     onHideBanner() {
117
         this.setState({bannerVisible: false});
123
         this.setState({bannerVisible: false});
118
         AsyncStorageManager.getInstance().savePref(
124
         AsyncStorageManager.getInstance().savePref(
121
         );
127
         );
122
     }
128
     }
123
 
129
 
130
+    /**
131
+     * Callback used when the used click on the navigate to settings button.
132
+     * This will hide the banner and open the SettingsScreen
133
+     *
134
+     */
124
     onGoToSettings() {
135
     onGoToSettings() {
125
         this.onHideBanner();
136
         this.onHideBanner();
126
         this.props.navigation.navigate('SettingsScreen');
137
         this.props.navigation.navigate('SettingsScreen');

+ 0
- 5
utils/AsyncStorageManager.js View File

39
             default: '5',
39
             default: '5',
40
             current: '',
40
             current: '',
41
         },
41
         },
42
-        proxiwashWatchedMachines: {
43
-            key: 'proxiwashWatchedMachines',
44
-            default: '[]',
45
-            current: '',
46
-        },
47
         nightModeFollowSystem: {
42
         nightModeFollowSystem: {
48
             key: 'nightModeFollowSystem',
43
             key: 'nightModeFollowSystem',
49
             default: '1',
44
             default: '1',

Loading…
Cancel
Save