Compare commits

..

No commits in common. "e5299ed9c33c2ee34b3c85534fa8f9a931834645" and "f8ded811f4e0f977e2de65e09de6f293155d30bf" have entirely different histories.

10 changed files with 192 additions and 197 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@ web-build/
web-report/ web-report/
/.expo-shared/ /.expo-shared/
/package-lock.json /package-lock.json
/passwords.json
!/.idea/ !/.idea/
/.idea/* /.idea/*

2
App.js
View file

@ -9,6 +9,7 @@ import type {CustomTheme} from "./src/managers/ThemeManager";
import ThemeManager from './src/managers/ThemeManager'; import ThemeManager from './src/managers/ThemeManager';
import {NavigationContainer} from '@react-navigation/native'; import {NavigationContainer} from '@react-navigation/native';
import MainNavigator from './src/navigation/MainNavigator'; import MainNavigator from './src/navigation/MainNavigator';
import {initExpoToken} from "./src/utils/Notifications";
import {Provider as PaperProvider} from 'react-native-paper'; import {Provider as PaperProvider} from 'react-native-paper';
import AprilFoolsManager from "./src/managers/AprilFoolsManager"; import AprilFoolsManager from "./src/managers/AprilFoolsManager";
import Update from "./src/constants/Update"; import Update from "./src/constants/Update";
@ -144,6 +145,7 @@ export default class App extends React.Component<Props, State> {
*/ */
loadAssetsAsync = async () => { loadAssetsAsync = async () => {
await this.storageManager.loadPreferences(); await this.storageManager.loadPreferences();
await initExpoToken();
try { try {
await ConnectionManager.getInstance().recoverLogin(); await ConnectionManager.getInstance().recoverLogin();
} catch (e) { } catch (e) {

View file

@ -1,9 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="fr.amicaleinsat.application"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="fr.amicaleinsat.application">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
@ -16,33 +14,6 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
> >
<!-- NOTIFICATIONS -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="reminders"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="reminders"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/colorPrimary"/> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- END NOTIFICATIONS-->
<meta-data android:name="com.facebook.sdk.AutoInitEnabled" android:value="false"/> <meta-data android:name="com.facebook.sdk.AutoInitEnabled" android:value="false"/>
<meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="false"/> <meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="false"/>
<meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled" android:value="false"/> <meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled" android:value="false"/>

View file

@ -3,9 +3,7 @@
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission tools:node="remove" android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission tools:node="remove" android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
@ -23,5 +21,5 @@
<uses-permission tools:node="remove" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission tools:node="remove" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission tools:node="remove" android:name="android.permission.WRITE_SETTINGS"/> <uses-permission tools:node="remove" android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission tools:node="remove" android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission tools:node="remove" android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission tools:node="remove" android:name="android.permission.WAKE_LOCK"/>
</manifest> </manifest>

View file

@ -44,7 +44,6 @@
"react-native-modalize": "^1.3.6", "react-native-modalize": "^1.3.6",
"react-native-paper": "^3.8.0", "react-native-paper": "^3.8.0",
"react-native-permissions": "^2.1.3", "react-native-permissions": "^2.1.3",
"react-native-push-notification": "^3.3.0",
"react-native-reanimated": "~1.7.0", "react-native-reanimated": "~1.7.0",
"react-native-render-html": "^4.1.2", "react-native-render-html": "^4.1.2",
"react-native-safe-area-context": "0.7.3", "react-native-safe-area-context": "0.7.3",

View file

@ -69,11 +69,6 @@ export default class AsyncStorageManager {
default: '1', default: '1',
current: '', current: '',
}, },
proxiwashWatchedMachines: {
key: 'proxiwashWatchedMachines',
default: '[]',
current: '',
},
planexShowBanner: { planexShowBanner: {
key: 'planexShowBanner', key: 'planexShowBanner',
default: '1', default: '1',

View file

@ -5,6 +5,7 @@ import {ScrollView} from "react-native";
import ThemeManager from '../../managers/ThemeManager'; import ThemeManager from '../../managers/ThemeManager';
import i18n from "i18n-js"; import i18n from "i18n-js";
import AsyncStorageManager from "../../managers/AsyncStorageManager"; import AsyncStorageManager from "../../managers/AsyncStorageManager";
import {setMachineReminderNotificationTime} from "../../utils/Notifications";
import {Card, List, Switch, ToggleButton} from 'react-native-paper'; import {Card, List, Switch, ToggleButton} from 'react-native-paper';
import {Appearance} from "react-native-appearance"; import {Appearance} from "react-native-appearance";
import AnimatedAccordion from "../../components/Animations/AnimatedAccordion"; import AnimatedAccordion from "../../components/Animations/AnimatedAccordion";
@ -48,6 +49,10 @@ export default class SettingsScreen extends React.Component<Props, State> {
this.setState({ this.setState({
proxiwashNotifPickerSelected: value proxiwashNotifPickerSelected: value
}); });
let intVal = 0;
if (value !== 'never')
intVal = parseInt(value);
setMachineReminderNotificationTime(intVal);
} }
}; };

View file

@ -6,6 +6,7 @@ import i18n from "i18n-js";
import WebSectionList from "../../components/Screens/WebSectionList"; import WebSectionList from "../../components/Screens/WebSectionList";
import * as Notifications from "../../utils/Notifications"; import * as Notifications from "../../utils/Notifications";
import AsyncStorageManager from "../../managers/AsyncStorageManager"; import AsyncStorageManager from "../../managers/AsyncStorageManager";
// import * as Expo from "expo";
import {Avatar, Banner, Button, Card, Text, withTheme} from 'react-native-paper'; import {Avatar, Banner, Button, Card, Text, withTheme} from 'react-native-paper';
import ProxiwashListItem from "../../components/Lists/Proxiwash/ProxiwashListItem"; import ProxiwashListItem from "../../components/Lists/Proxiwash/ProxiwashListItem";
import ProxiwashConstants from "../../constants/ProxiwashConstants"; import ProxiwashConstants from "../../constants/ProxiwashConstants";
@ -14,10 +15,6 @@ import AprilFoolsManager from "../../managers/AprilFoolsManager";
import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton"; import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
import ProxiwashSectionHeader from "../../components/Lists/Proxiwash/ProxiwashSectionHeader"; import ProxiwashSectionHeader from "../../components/Lists/Proxiwash/ProxiwashSectionHeader";
import {withCollapsible} from "../../utils/withCollapsible"; import {withCollapsible} from "../../utils/withCollapsible";
import type {CustomTheme} from "../../managers/ThemeManager";
import {Collapsible} from "react-navigation-collapsible";
import {StackNavigationProp} from "@react-navigation/stack";
import {getCleanedMachineWatched, getMachineEndDate, isMachineWatched} from "../../utils/Proxiwash";
const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json"; const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json";
@ -26,25 +23,17 @@ let modalStateStrings = {};
const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
const LIST_ITEM_HEIGHT = 64; const LIST_ITEM_HEIGHT = 64;
export type Machine = {
number: string,
state: string,
startTime: string,
endTime: string,
donePercent: string,
remainingTime: string,
}
type Props = { type Props = {
navigation: StackNavigationProp, navigation: Object,
theme: CustomTheme, route: Object,
collapsibleStack: Collapsible, theme: Object,
collapsibleStack: Object,
} }
type State = { type State = {
refreshing: boolean, refreshing: boolean,
modalCurrentDisplayItem: React.Node, modalCurrentDisplayItem: React.Node,
machinesWatched: Array<Machine>, machinesWatched: Array<string>,
bannerVisible: boolean, bannerVisible: boolean,
}; };
@ -62,7 +51,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
state = { state = {
refreshing: false, refreshing: false,
modalCurrentDisplayItem: null, modalCurrentDisplayItem: null,
machinesWatched: JSON.parse(AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.current), machinesWatched: [],
bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1', bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
}; };
@ -97,6 +86,25 @@ class ProxiwashScreen extends React.Component<Props, State> {
this.props.navigation.setOptions({ this.props.navigation.setOptions({
headerRight: this.getAboutButton, headerRight: this.getAboutButton,
}); });
if (AsyncStorageManager.getInstance().preferences.expoToken.current !== '') {
// Get latest watchlist from server
Notifications.getMachineNotificationWatchlist((fetchedList) => {
this.setState({machinesWatched: fetchedList})
});
// Get updated watchlist after received notification
// Expo.Notifications.addListener(() => {
// Notifications.getMachineNotificationWatchlist((fetchedList) => {
// this.setState({machinesWatched: fetchedList})
// });
// });
// if (Platform.OS === 'android') {
// Expo.Notifications.createChannelAndroidAsync('reminders', {
// name: 'Reminders',
// priority: 'max',
// vibrate: [0, 250, 250, 250],
// });
// }
}
} }
/** /**
@ -121,30 +129,27 @@ class ProxiwashScreen extends React.Component<Props, State> {
* @param item The item to extract the key from * @param item The item to extract the key from
* @return {*} The extracted key * @return {*} The extracted key
*/ */
getKeyExtractor = (item: Machine) => item.number; getKeyExtractor(item: Object) {
return item !== undefined ? item.number : undefined;
}
/** /**
* Setups notifications for the machine with the given ID. * Setups notifications for the machine with the given ID.
* One notification will be sent at the end of the program. * One notification will be sent at the end of the program.
* Another will be send a few minutes before the end, based on the value of reminderNotifTime * Another will be send a few minutes before the end, based on the value of reminderNotifTime
* *
* @param machine The machine to watch * @param machineId The machine's ID
* @returns {Promise<void>}
*/ */
setupNotifications(machine: Machine) { setupNotifications(machineId: string) {
if (!isMachineWatched(machine, this.state.machinesWatched)) { if (AsyncStorageManager.getInstance().preferences.expoToken.current !== '') {
Notifications.setupMachineNotification(machine.number, true, getMachineEndDate(machine)) if (!this.isMachineWatched(machineId)) {
.then(() => { Notifications.setupMachineNotification(machineId, true);
this.saveNotificationToState(machine); this.saveNotificationToState(machineId);
}) } else
.catch(() => { this.disableNotification(machineId);
this.showNotificationsDisabledWarning();
});
} else { } else {
Notifications.setupMachineNotification(machine.number, false) this.showNotificationsDisabledWarning();
.then(() => {
this.removeNotificationFromState(machine);
});
} }
} }
@ -158,39 +163,62 @@ class ProxiwashScreen extends React.Component<Props, State> {
); );
} }
/**
* Stops scheduled notifications for the machine of the given ID.
* This will also remove the notification if it was already shown.
*
* @param machineId The machine's ID
*/
disableNotification(machineId: string) {
let data = this.state.machinesWatched;
if (data.length > 0) {
let arrayIndex = data.indexOf(machineId);
if (arrayIndex !== -1) {
Notifications.setupMachineNotification(machineId, false);
this.removeNotificationFroState(arrayIndex);
}
}
}
/** /**
* Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
* *
* @param machine * @param machineId
*/ */
saveNotificationToState(machine: Machine) { saveNotificationToState(machineId: string) {
let data = this.state.machinesWatched; let data = this.state.machinesWatched;
data.push(machine); data.push(machineId);
this.saveNewWatchedList(data); this.updateNotificationState(data);
} }
/** /**
* Removes the given index from the watchlist array and saves it to preferences * Removes the given index from the watchlist array and saves it to preferences
* *
* @param machine * @param index
*/ */
removeNotificationFromState(machine: Machine) { removeNotificationFroState(index: number) {
let data = this.state.machinesWatched; let data = this.state.machinesWatched;
for (let i = 0; i < data.length; i++) { data.splice(index, 1);
if (data[i].number === machine.number && data[i].endTime === machine.endTime) { this.updateNotificationState(data);
data.splice(i, 1);
break;
}
}
this.saveNewWatchedList(data);
} }
saveNewWatchedList(list: Array<Machine>) { /**
this.setState({machinesWatched: list}); * Sets the given fetchedData as the watchlist
AsyncStorageManager.getInstance().savePref( *
AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.key, * @param data
JSON.stringify(list), */
); updateNotificationState(data: Array<Object>) {
this.setState({machinesWatched: data});
}
/**
* Checks whether the machine of the given ID has scheduled notifications
*
* @param machineID The machine's ID
* @returns {boolean}
*/
isMachineWatched(machineID: string) {
return this.state.machinesWatched.indexOf(machineID) !== -1;
} }
/** /**
@ -206,9 +234,8 @@ class ProxiwashScreen extends React.Component<Props, State> {
AprilFoolsManager.getNewProxiwashDryerOrderedList(data.dryers); AprilFoolsManager.getNewProxiwashDryerOrderedList(data.dryers);
AprilFoolsManager.getNewProxiwashWasherOrderedList(data.washers); AprilFoolsManager.getNewProxiwashWasherOrderedList(data.washers);
} }
this.fetchedData = data; this.fetchedData = fetchedData;
this.state.machinesWatched =
getCleanedMachineWatched(this.state.machinesWatched, [...data.dryers, ...data.washers]);
return [ return [
{ {
title: i18n.t('proxiwashScreen.dryers'), title: i18n.t('proxiwashScreen.dryers'),
@ -244,13 +271,13 @@ class ProxiwashScreen extends React.Component<Props, State> {
/** /**
* Callback used when the user clicks on enable notifications for a machine * Callback used when the user clicks on enable notifications for a machine
* *
* @param machine The machine to set notifications for * @param machineId The machine's id to set notifications for
*/ */
onSetupNotificationsPress(machine: Machine) { onSetupNotificationsPress(machineId: string) {
if (this.modalRef) { if (this.modalRef) {
this.modalRef.close(); this.modalRef.close();
} }
this.setupNotifications(machine); this.setupNotifications(machineId)
} }
/** /**
@ -269,11 +296,11 @@ class ProxiwashScreen extends React.Component<Props, State> {
onPress: undefined onPress: undefined
}; };
let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]]; let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]];
const onPress = this.onSetupNotificationsPress.bind(this, item); const onPress = this.onSetupNotificationsPress.bind(this, item.number);
if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) { if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) {
button = button =
{ {
text: isMachineWatched(item, this.state.machinesWatched) ? text: this.isMachineWatched(item.number) ?
i18n.t("proxiwashScreen.modal.disableNotifications") : i18n.t("proxiwashScreen.modal.disableNotifications") :
i18n.t("proxiwashScreen.modal.enableNotifications"), i18n.t("proxiwashScreen.modal.enableNotifications"),
icon: '', icon: '',
@ -383,7 +410,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
<ProxiwashListItem <ProxiwashListItem
item={item} item={item}
onPress={this.showModal} onPress={this.showModal}
isWatched={isMachineWatched(item, this.state.machinesWatched)} isWatched={this.isMachineWatched(item.number)}
isDryer={isDryer} isDryer={isDryer}
height={LIST_ITEM_HEIGHT} height={LIST_ITEM_HEIGHT}
/> />

View file

@ -1,11 +1,12 @@
// @flow // @flow
import {checkNotifications, requestNotifications, RESULTS} from 'react-native-permissions'; import {checkNotifications, requestNotifications, RESULTS} from 'react-native-permissions';
// import {Notifications} from 'expo';
import AsyncStorageManager from "../managers/AsyncStorageManager"; import AsyncStorageManager from "../managers/AsyncStorageManager";
import LocaleManager from "../managers/LocaleManager";
import passwords from "../../passwords";
const PushNotification = require("react-native-push-notification"); const EXPO_TOKEN_SERVER = 'https://etud.insa-toulouse.fr/~amicale_app/expo_notifications/save_token.php';
const reminderIdMultiplicator = 100;
/** /**
* Async function asking permission to send notifications to the user * Async function asking permission to send notifications to the user
@ -31,53 +32,101 @@ export async function askPermissions() {
})); }));
} }
function createNotifications(machineID: string, date: Date) { /**
let reminder = parseInt(AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current); * Save expo token to allow sending notifications to this device.
if (!isNaN(reminder)) { * This token is unique for each device and won't change.
let id = reminderIdMultiplicator * parseInt(machineID); * It only needs to be fetched once, then it will be saved in storage.
let reminderDate = new Date(date); *
reminderDate.setMinutes(reminderDate.getMinutes() - reminder); * @return {Promise<void>}
PushNotification.localNotificationSchedule({ */
title: "Title", export async function initExpoToken() {
message: "Message", // let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
id: id.toString(), // if (token === '') {
date: reminderDate, // askPermissions().then(() => {
}); // Notifications.getExpoPushTokenAsync().then((token) => {
console.log("Setting up notifications for ", date, " and reminder for ", reminderDate); // // Save token for instant use later on
} else // AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, token);
console.log("Setting up notifications for ", date); // });
// });
// }
}
PushNotification.localNotificationSchedule({ /**
title: "Title", * Gets the machines watched from the server
message: "Message", *
id: machineID, * @param callback Function to execute with the fetched data
date: date, */
export function getMachineNotificationWatchlist(callback: Function) {
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
if (token !== '') {
let data = {
function: 'get_machine_watchlist',
password: passwords.expoNotifications,
token: token,
};
fetch(EXPO_TOKEN_SERVER, {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json',
}),
body: JSON.stringify(data) // <-- Post parameters
}).then((response) => response.json())
.then((responseJson) => {
callback(responseJson);
}); });
} }
}
/** /**
* Asks the server to enable/disable notifications for the specified machine * Asks the server to enable/disable notifications for the specified machine
* *
* @param machineID The machine ID * @param machineID The machine ID
* @param isEnabled True to enable notifications, false to disable * @param isEnabled True to enable notifications, false to disable
* @param endDate
*/ */
export async function setupMachineNotification(machineID: string, isEnabled: boolean, endDate?: Date) { export function setupMachineNotification(machineID: string, isEnabled: boolean) {
return new Promise((resolve, reject) => { let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
if (isEnabled && endDate != null) { if (token !== '') {
askPermissions() let data = {
.then(() => { function: 'setup_machine_notification',
createNotifications(machineID, endDate); password: passwords.expoNotifications,
resolve(); locale: LocaleManager.getCurrentLocale(),
}) token: token,
.catch(() => { machine_id: machineID,
reject(); enabled: isEnabled
}); };
} else { fetch(EXPO_TOKEN_SERVER, {
PushNotification.cancelLocalNotifications({id: machineID}); method: 'POST',
let reminderId = reminderIdMultiplicator * parseInt(machineID); headers: new Headers({
PushNotification.cancelLocalNotifications({id: reminderId.toString()}); Accept: 'application/json',
resolve(); 'Content-Type': 'application/json',
} }),
body: JSON.stringify(data) // <-- Post parameters
}); });
} }
}
/**
* Sends the selected reminder time for notifications to the server
*
* @param time The reminder time to use
*/
export function setMachineReminderNotificationTime(time: number) {
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
if (token !== '') {
let data = {
function: 'set_machine_reminder',
password: passwords.expoNotifications,
token: token,
time: time,
};
fetch(EXPO_TOKEN_SERVER, {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json',
}),
body: JSON.stringify(data) // <-- Post parameters
});
}
}

View file

@ -1,52 +0,0 @@
// @flow
import type {Machine} from "../screens/Proxiwash/ProxiwashScreen";
import ProxiwashConstants from "../constants/ProxiwashConstants";
export function getMachineEndDate(machine: Machine) {
const array = machine.endTime.split(":");
let date = new Date();
date.setHours(parseInt(array[0]), parseInt(array[1]));
if (date < new Date())
date.setDate(date.getDate() + 1);
return date;
}
/**
* Checks whether the machine of the given ID has scheduled notifications
*
* @param machine
* @param machineList
* @returns {boolean}
*/
export function isMachineWatched(machine: Machine, machineList: Array<Machine>) {
let watched = false;
for (let i = 0; i < machineList.length; i++) {
if (machineList[i].number === machine.number && machineList[i].endTime === machine.endTime) {
watched = true;
break;
}
}
return watched;
}
function getMachineOfId(id: string, allMachines: Array<Machine>) {
for (let i = 0; i < allMachines.length; i++) {
if (allMachines[i].number === id)
return allMachines[i];
}
return null;
}
export function getCleanedMachineWatched(machineList: Array<Machine>, allMachines: Array<Machine>) {
let newList = [];
for (let i = 0; i < machineList.length; i++) {
let machine = getMachineOfId(machineList[i].number, allMachines);
if (machine !== null
&& machineList[i].number === machine.number && machineList[i].endTime === machine.endTime
&& ProxiwashConstants.machineStates[machineList[i].state] === ProxiwashConstants.machineStates["EN COURS"]) {
newList.push(machine);
}
}
return newList;
}