|
@@ -1,13 +1,19 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import type {Machine} from "../screens/Proxiwash/ProxiwashScreen";
|
4
|
|
-import ProxiwashConstants from "../constants/ProxiwashConstants";
|
5
|
4
|
|
|
5
|
+/**
|
|
6
|
+ * Gets the machine end Date object.
|
|
7
|
+ * If the time is before the current time, it will be considered as tomorrow
|
|
8
|
+ *
|
|
9
|
+ * @param machine The machine to get the date from
|
|
10
|
+ * @returns {Date} The date object representing the end time.
|
|
11
|
+ */
|
6
|
12
|
export function getMachineEndDate(machine: Machine) {
|
7
|
13
|
const array = machine.endTime.split(":");
|
8
|
|
- let date = new Date();
|
|
14
|
+ let date = new Date(Date.now());
|
9
|
15
|
date.setHours(parseInt(array[0]), parseInt(array[1]));
|
10
|
|
- if (date < new Date())
|
|
16
|
+ if (date < new Date(Date.now()))
|
11
|
17
|
date.setDate(date.getDate() + 1);
|
12
|
18
|
return date;
|
13
|
19
|
}
|
|
@@ -15,8 +21,8 @@ export function getMachineEndDate(machine: Machine) {
|
15
|
21
|
/**
|
16
|
22
|
* Checks whether the machine of the given ID has scheduled notifications
|
17
|
23
|
*
|
18
|
|
- * @param machine
|
19
|
|
- * @param machineList
|
|
24
|
+ * @param machine The machine to check
|
|
25
|
+ * @param machineList The machine list
|
20
|
26
|
* @returns {boolean}
|
21
|
27
|
*/
|
22
|
28
|
export function isMachineWatched(machine: Machine, machineList: Array<Machine>) {
|
|
@@ -30,7 +36,14 @@ export function isMachineWatched(machine: Machine, machineList: Array<Machine>)
|
30
|
36
|
return watched;
|
31
|
37
|
}
|
32
|
38
|
|
33
|
|
-function getMachineOfId(id: string, allMachines: Array<Machine>) {
|
|
39
|
+/**
|
|
40
|
+ * Gets the machine of the given id
|
|
41
|
+ *
|
|
42
|
+ * @param id The machine's ID
|
|
43
|
+ * @param allMachines The machine list
|
|
44
|
+ * @returns {null|Machine} The machine or null if not found
|
|
45
|
+ */
|
|
46
|
+export function getMachineOfId(id: string, allMachines: Array<Machine>) {
|
34
|
47
|
for (let i = 0; i < allMachines.length; i++) {
|
35
|
48
|
if (allMachines[i].number === id)
|
36
|
49
|
return allMachines[i];
|
|
@@ -38,13 +51,22 @@ function getMachineOfId(id: string, allMachines: Array<Machine>) {
|
38
|
51
|
return null;
|
39
|
52
|
}
|
40
|
53
|
|
41
|
|
-export function getCleanedMachineWatched(machineList: Array<Machine>, allMachines: Array<Machine>) {
|
|
54
|
+/**
|
|
55
|
+ * Gets a cleaned machine watched list by removing invalid entries.
|
|
56
|
+ * An entry is considered invalid if the end time in the watched list
|
|
57
|
+ * and in the full list does not match (a new machine cycle started)
|
|
58
|
+ *
|
|
59
|
+ * @param machineWatchedList The current machine watch list
|
|
60
|
+ * @param allMachines The current full machine list
|
|
61
|
+ * @returns {Array<Machine>}
|
|
62
|
+ */
|
|
63
|
+export function getCleanedMachineWatched(machineWatchedList: Array<Machine>, allMachines: Array<Machine>) {
|
42
|
64
|
let newList = [];
|
43
|
|
- for (let i = 0; i < machineList.length; i++) {
|
44
|
|
- let machine = getMachineOfId(machineList[i].number, allMachines);
|
|
65
|
+ for (let i = 0; i < machineWatchedList.length; i++) {
|
|
66
|
+ let machine = getMachineOfId(machineWatchedList[i].number, allMachines);
|
45
|
67
|
if (machine !== null
|
46
|
|
- && machineList[i].number === machine.number && machineList[i].endTime === machine.endTime
|
47
|
|
- && ProxiwashConstants.machineStates[machineList[i].state] === ProxiwashConstants.machineStates["EN COURS"]) {
|
|
68
|
+ && machineWatchedList[i].number === machine.number
|
|
69
|
+ && machineWatchedList[i].endTime === machine.endTime) {
|
48
|
70
|
newList.push(machine);
|
49
|
71
|
}
|
50
|
72
|
}
|