forked from vergnet/application-amicale
Use machine remaining time from server instead of calculating it again
This commit is contained in:
parent
a99e8da6e4
commit
3ba3d332f8
2 changed files with 4 additions and 26 deletions
2
app.json
2
app.json
|
@ -10,7 +10,7 @@
|
||||||
"android",
|
"android",
|
||||||
"web"
|
"web"
|
||||||
],
|
],
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"primaryColor": "#be1522",
|
"primaryColor": "#be1522",
|
||||||
"icon": "./assets/android.icon.png",
|
"icon": "./assets/android.icon.png",
|
||||||
|
|
|
@ -120,24 +120,6 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
||||||
return item !== undefined ? "washer" + item.number : undefined;
|
return item !== undefined ? "washer" + item.number : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the time remaining based on start/end time and done percent
|
|
||||||
*
|
|
||||||
* @param startString The string representing the start time. Format: hh:mm
|
|
||||||
* @param endString The string representing the end time. Format: hh:mm
|
|
||||||
* @param percentDone The percentage done
|
|
||||||
* @returns {number} How many minutes are remaining for this machine
|
|
||||||
*/
|
|
||||||
static getRemainingTime(startString: string, endString: string, percentDone: string): number {
|
|
||||||
let startArray = startString.split(':');
|
|
||||||
let endArray = endString.split(':');
|
|
||||||
let startDate = new Date().setHours(parseInt(startArray[0]), parseInt(startArray[1]), 0, 0);
|
|
||||||
let endDate = new Date().setHours(parseInt(endArray[0]), parseInt(endArray[1]), 0, 0);
|
|
||||||
// Convert milliseconds into minutes
|
|
||||||
let time: string = (((100 - parseFloat(percentDone)) / 100) * (endDate - startDate) / (60 * 1000)).toFixed(0);
|
|
||||||
return parseInt(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup notifications for the machine with the given ID.
|
* Setup 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.
|
||||||
|
@ -243,10 +225,9 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title
|
||||||
* @param item
|
* @param item
|
||||||
* @param remainingTime
|
|
||||||
* @param isDryer
|
* @param isDryer
|
||||||
*/
|
*/
|
||||||
showAlert(title: string, item: Object, remainingTime: number, isDryer: boolean) {
|
showAlert(title: string, item: Object, isDryer: boolean) {
|
||||||
let buttons = [{text: i18n.t("proxiwashScreen.modal.ok")}];
|
let buttons = [{text: i18n.t("proxiwashScreen.modal.ok")}];
|
||||||
let message = modalStateStrings[MACHINE_STATES[item.state]];
|
let message = modalStateStrings[MACHINE_STATES[item.state]];
|
||||||
if (MACHINE_STATES[item.state] === MACHINE_STATES["EN COURS"]) {
|
if (MACHINE_STATES[item.state] === MACHINE_STATES["EN COURS"]) {
|
||||||
|
@ -265,7 +246,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
||||||
{
|
{
|
||||||
start: item.startTime,
|
start: item.startTime,
|
||||||
end: item.endTime,
|
end: item.endTime,
|
||||||
remaining: remainingTime
|
remaining: item.remainingTime
|
||||||
});
|
});
|
||||||
} else if (MACHINE_STATES[item.state] === MACHINE_STATES.DISPONIBLE) {
|
} else if (MACHINE_STATES[item.state] === MACHINE_STATES.DISPONIBLE) {
|
||||||
if (isDryer)
|
if (isDryer)
|
||||||
|
@ -304,9 +285,6 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
||||||
let isMachineRunning = MACHINE_STATES[item.state] === MACHINE_STATES["EN COURS"];
|
let isMachineRunning = MACHINE_STATES[item.state] === MACHINE_STATES["EN COURS"];
|
||||||
let machineName = (section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')) + ' n°' + item.number;
|
let machineName = (section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')) + ' n°' + item.number;
|
||||||
let isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
let isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
||||||
let remainingTime = 0;
|
|
||||||
if (isMachineRunning)
|
|
||||||
remainingTime = ProxiwashScreen.getRemainingTime(item.startTime, item.endTime, item.donePercent);
|
|
||||||
return (
|
return (
|
||||||
<Card style={{
|
<Card style={{
|
||||||
flex: 0,
|
flex: 0,
|
||||||
|
@ -331,7 +309,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
||||||
backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor
|
backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor
|
||||||
}}/>
|
}}/>
|
||||||
<PlatformTouchable
|
<PlatformTouchable
|
||||||
onPress={() => this.showAlert(machineName, item, remainingTime, isDryer)}
|
onPress={() => this.showAlert(machineName, item, isDryer)}
|
||||||
style={{
|
style={{
|
||||||
height: 64,
|
height: 64,
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|
Loading…
Reference in a new issue