forked from vergnet/application-amicale
Added proxiwash AF
This commit is contained in:
parent
67357227c0
commit
578e912927
2 changed files with 60 additions and 4 deletions
|
@ -12,6 +12,7 @@ import HeaderButton from "../../components/HeaderButton";
|
||||||
import ProxiwashListItem from "../../components/ProxiwashListItem";
|
import ProxiwashListItem from "../../components/ProxiwashListItem";
|
||||||
import ProxiwashConstants from "../../constants/ProxiwashConstants";
|
import ProxiwashConstants from "../../constants/ProxiwashConstants";
|
||||||
import CustomModal from "../../components/CustomModal";
|
import CustomModal from "../../components/CustomModal";
|
||||||
|
import AprilFoolsManager from "../../utils/AprilFoolsManager";
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
|
@ -229,19 +230,26 @@ class ProxiwashScreen extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
createDataset(fetchedData: Object) {
|
createDataset(fetchedData: Object) {
|
||||||
|
let data = fetchedData;
|
||||||
|
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) {
|
||||||
|
data = JSON.parse(JSON.stringify(fetchedData)); // Deep copy
|
||||||
|
AprilFoolsManager.getNewProxiwashDryerOrderedList(data.dryers);
|
||||||
|
AprilFoolsManager.getNewProxiwashWasherOrderedList(data.washers);
|
||||||
|
}
|
||||||
this.fetchedData = fetchedData;
|
this.fetchedData = fetchedData;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
title: i18n.t('proxiwashScreen.dryers'),
|
title: i18n.t('proxiwashScreen.dryers'),
|
||||||
icon: 'tumble-dryer',
|
icon: 'tumble-dryer',
|
||||||
data: fetchedData.dryers === undefined ? [] : fetchedData.dryers,
|
data: data.dryers === undefined ? [] : data.dryers,
|
||||||
extraData: this.state,
|
extraData: this.state,
|
||||||
keyExtractor: this.getDryersKeyExtractor
|
keyExtractor: this.getDryersKeyExtractor
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: i18n.t('proxiwashScreen.washers'),
|
title: i18n.t('proxiwashScreen.washers'),
|
||||||
icon: 'washing-machine',
|
icon: 'washing-machine',
|
||||||
data: fetchedData.washers === undefined ? [] : fetchedData.washers,
|
data: data.washers === undefined ? [] : data.washers,
|
||||||
extraData: this.state,
|
extraData: this.state,
|
||||||
keyExtractor: this.getWashersKeyExtractor
|
keyExtractor: this.getWashersKeyExtractor
|
||||||
},
|
},
|
||||||
|
@ -387,7 +395,12 @@ class ProxiwashScreen extends React.Component<Props, State> {
|
||||||
*/
|
*/
|
||||||
getRenderItem({item, section}: Object) {
|
getRenderItem({item, section}: Object) {
|
||||||
const isMachineRunning = ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"];
|
const isMachineRunning = ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"];
|
||||||
const machineName = (section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')) + ' n°' + item.number;
|
let displayNumber = item.number;
|
||||||
|
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
|
||||||
|
displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber(parseInt(item.number));
|
||||||
|
const machineName = (section.title === i18n.t('proxiwashScreen.dryers') ?
|
||||||
|
i18n.t('proxiwashScreen.dryer') :
|
||||||
|
i18n.t('proxiwashScreen.washer')) + ' n°' + displayNumber;
|
||||||
const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
||||||
const onPress = this.showModal.bind(this, machineName, item, isDryer);
|
const onPress = this.showModal.bind(this, machineName, item, isDryer);
|
||||||
let width = item.donePercent !== '' ? (parseInt(item.donePercent)).toString() + '%' : 0;
|
let width = item.donePercent !== '' ? (parseInt(item.donePercent)).toString() + '%' : 0;
|
||||||
|
|
|
@ -9,6 +9,22 @@ export default class AprilFoolsManager {
|
||||||
|
|
||||||
aprilFoolsEnabled: boolean;
|
aprilFoolsEnabled: boolean;
|
||||||
|
|
||||||
|
static fakeMachineNumber = [
|
||||||
|
"",
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c",
|
||||||
|
"d",
|
||||||
|
"e",
|
||||||
|
"f",
|
||||||
|
"g",
|
||||||
|
"h",
|
||||||
|
"i",
|
||||||
|
"j",
|
||||||
|
"k",
|
||||||
|
"l",
|
||||||
|
];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
this.aprilFoolsEnabled = (today.getDate() === 1 && today.getMonth() === 3);
|
this.aprilFoolsEnabled = (today.getDate() === 1 && today.getMonth() === 3);
|
||||||
|
@ -25,13 +41,40 @@ export default class AprilFoolsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getFakeMenuItem(menu: Object) {
|
static getFakeMenuItem(menu: Object) {
|
||||||
menu[1]["dishes"].splice(2, 0, {name: "Coq au vin"});
|
menu[1]["dishes"].splice(4, 0, {name: "Coq au vin"});
|
||||||
|
menu[1]["dishes"].splice(2, 0, {name: "Bat'Soupe"});
|
||||||
menu[1]["dishes"].splice(1, 0, {name: "Pave de loup"});
|
menu[1]["dishes"].splice(1, 0, {name: "Pave de loup"});
|
||||||
menu[1]["dishes"].splice(0, 0, {name: "Béranger à point"});
|
menu[1]["dishes"].splice(0, 0, {name: "Béranger à point"});
|
||||||
menu[1]["dishes"].splice(0, 0, {name: "Pieds d'Arnaud"});
|
menu[1]["dishes"].splice(0, 0, {name: "Pieds d'Arnaud"});
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getNewProxiwashDryerOrderedList(dryers: Array<Object>) {
|
||||||
|
if (dryers !== undefined) {
|
||||||
|
let second = dryers[1];
|
||||||
|
dryers.splice(1, 1);
|
||||||
|
dryers.push(second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static getNewProxiwashWasherOrderedList(washers: Array<Object>) {
|
||||||
|
if (washers !== undefined) {
|
||||||
|
let first = washers[0];
|
||||||
|
let second = washers[1];
|
||||||
|
let fifth = washers[4];
|
||||||
|
let ninth = washers[8];
|
||||||
|
washers.splice(8, 1, second);
|
||||||
|
washers.splice(4, 1, ninth);
|
||||||
|
washers.splice(1, 1, first);
|
||||||
|
washers.splice(0, 1, fifth);
|
||||||
|
// washers.push(fifth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static getProxiwashMachineDisplayNumber(number: number) {
|
||||||
|
return AprilFoolsManager.fakeMachineNumber[number];
|
||||||
|
}
|
||||||
|
|
||||||
static getAprilFoolsTheme(currentTheme: Object) {
|
static getAprilFoolsTheme(currentTheme: Object) {
|
||||||
return {
|
return {
|
||||||
...currentTheme,
|
...currentTheme,
|
||||||
|
|
Loading…
Reference in a new issue