Commit a3e7d977 by HaOuiha

fix bug

parent 4ac09b8a
...@@ -19,21 +19,29 @@ console.disableYellowBox = true; ...@@ -19,21 +19,29 @@ console.disableYellowBox = true;
const Application = () => { const Application = () => {
useEffect(() => { useEffect(() => {
fixTimerWarning(); fixTimerWarning();
}, []);
const batch = fireStore.batch(); return (
<Root>
<ApplicationProvider mapping={mapping} theme={myTheme}>
<Provider store={rootStore}>
<AppContainer />
</Provider>
</ApplicationProvider>
</Root>
);
};
const mainRef = fireStore.doc(`device/${deviceId}`); export default Application;
const mcbLinksRef = fireStore.doc(`device/${deviceId}/mcbLinks/${mcbLinkId}`);
const subBreakersRef = fireStore.doc(`device/${deviceId}/mcbLinks/${mcbLinkId}/subBreakers/${subBreakerId}`);
// const mcbLinksTimerRef = fireStore.doc(`device/${deviceId}/mcbLinks/${mcbLinkId}/Timers`); const createMockData = () => {
// const subBreakersTimerRef = fireStore.doc( // const deviceId = 'iYs6Th9Pkg1vTEDIyPa5';
// `device/${deviceId}/mcbLinks/${mcbLinkId}/subBreakers/${subBreakerId}/Timers` const deviceId = '8998c7d5-4476-41d9-81c6-9ef2dbac2505';
// ); const batch = fireStore.batch();
/*------------------------------*/
const mainRef = fireStore.doc(`device/${deviceId}`);
batch.set(mainRef, main); batch.set(mainRef, main);
batch.set(mcbLinksRef, mcbLinks);
batch.set(subBreakersRef, subBreakers);
for (let i = 1; i <= 5; i++) { for (let i = 1; i <= 5; i++) {
let mainTimerRef = fireStore let mainTimerRef = fireStore
...@@ -44,27 +52,72 @@ const Application = () => { ...@@ -44,27 +52,72 @@ const Application = () => {
batch.set(mainTimerRef, timer); batch.set(mainTimerRef, timer);
} }
/*------------------------------*/
for (let i = 1; i <= 4; i++) {
const mcbLinks = {
type: 'mcbLink',
name: `MCB Link ${i}`,
description: `description ${i}`,
};
let mcbLinksRef = fireStore
.collection('device')
.doc(deviceId)
.collection('mcbLinks')
.doc(i.toString());
batch.commit(); for (let z = 1; z <= 5; z++) {
}, []); let mcbLinkTimerRef = fireStore
.collection('device')
.doc(deviceId)
.collection('mcbLinks')
.doc(i.toString())
.collection('Timers')
.doc();
return ( batch.set(mcbLinkTimerRef, timer);
<Root> }
<ApplicationProvider mapping={mapping} theme={myTheme}>
<Provider store={rootStore}>
<AppContainer />
</Provider>
</ApplicationProvider>
</Root>
);
};
export default Application; batch.set(mcbLinksRef, mcbLinks);
}
/*------------------------------*/
for (let i = 1; i <= 4; i++) {
for (let j = 1; j <= 8; j++) {
let subBreakers = {
type: 'subBreaker',
name: `Sub Breaker ${j}`,
description: `description ${j}`,
};
let subBreakersRef = fireStore
.collection('device')
.doc(deviceId)
.collection('mcbLinks')
.doc(i.toString())
.collection('subBreakers')
.doc(j.toString());
for (let z = 1; z <= 5; z++) {
let subBreakerTimerRef = fireStore
.collection('device')
.doc(deviceId)
.collection('mcbLinks')
.doc(i.toString())
.collection('subBreakers')
.doc(j.toString())
.collection('Timers')
.doc();
batch.set(subBreakerTimerRef, timer);
}
batch.set(subBreakersRef, subBreakers);
}
}
batch.commit();
};
// const deviceId = 'iYs6Th9Pkg1vTEDIyPa5'; // const mcbLinkId = 1;
const deviceId = '8998c7d5-4476-41d9-81c6-9ef2dbac2505'; // const subBreakerId = 2;
const mcbLinkId = 1;
const subBreakerId = 2;
const main = { const main = {
type: 'main', type: 'main',
...@@ -74,24 +127,10 @@ const main = { ...@@ -74,24 +127,10 @@ const main = {
rcbo: 10, rcbo: 10,
}; };
const mcbLinks = {
id: mcbLinkId,
type: 'mcbLink',
name: `MCB Link ${mcbLinkId}`,
description: `description ${mcbLinkId}`,
};
const subBreakers = {
id: subBreakerId,
type: 'subBreaker',
name: `Sub Breaker ${subBreakerId}`,
description: `description ${subBreakerId}`,
};
const timer = { const timer = {
isActive: false, isActive: false,
isPowerOn: false, isPowerOn: false,
timer: 1566378008, timer: 0,
repeatOn: [ repeatOn: [
{ id: 0, isRepeat: false, day: 'Sunday' }, { id: 0, isRepeat: false, day: 'Sunday' },
{ id: 1, isRepeat: false, day: 'Monday' }, { id: 1, isRepeat: false, day: 'Monday' },
...@@ -102,3 +141,32 @@ const timer = { ...@@ -102,3 +141,32 @@ const timer = {
{ id: 6, isRepeat: false, day: 'Saturday' }, { id: 6, isRepeat: false, day: 'Saturday' },
], ],
}; };
// const mcbLinks = {
// // id: mcbLinkId,
// type: 'mcbLink',
// name: `MCB Link ${mcbLinkId}`,
// description: `description ${mcbLinkId}`,
// };
// const subBreakers = {
// // id: subBreakerId,
// type: 'subBreaker',
// name: `Sub Breaker ${subBreakerId}`,
// description: `description ${subBreakerId}`,
// };
// const timer = {
// isActive: false,
// isPowerOn: false,
// timer: 1566378008,
// repeatOn: [
// { id: 0, isRepeat: false, day: 'Sunday' },
// { id: 1, isRepeat: false, day: 'Monday' },
// { id: 2, isRepeat: false, day: 'Tuesday' },
// { id: 3, isRepeat: false, day: 'Wednesday' },
// { id: 4, isRepeat: false, day: 'Thursday' },
// { id: 5, isRepeat: false, day: 'Friday' },
// { id: 6, isRepeat: false, day: 'Saturday' },
// ],
// };
...@@ -45,9 +45,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => { ...@@ -45,9 +45,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
.get(); .get();
let ownerDeviceInfoData = await ownerDeviceInfo.data(); let ownerDeviceInfoData = await ownerDeviceInfo.data();
let { timers, ...rest } = ownerDeviceInfoData; // let { timers, ...rest } = ownerDeviceInfoData;
allMainDeviceInfoData.push(Object.assign(rest, { deviceId, isSharing: false })); allMainDeviceInfoData.push(Object.assign(ownerDeviceInfoData, { deviceId, isSharing: false }));
}); });
allSharingDeviceId.map(async (deviceId, index) => { allSharingDeviceId.map(async (deviceId, index) => {
...@@ -57,9 +57,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => { ...@@ -57,9 +57,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
.get(); .get();
let sharingDeviceInfoData = await sharingDeviceInfo.data(); let sharingDeviceInfoData = await sharingDeviceInfo.data();
let { timers, ...rest } = sharingDeviceInfoData; // let { timers, ...rest } = sharingDeviceInfoData;
allMainDeviceInfoData.push(Object.assign(rest, { deviceId, isSharing: true })); allMainDeviceInfoData.push(Object.assign(sharingDeviceInfoData, { deviceId, isSharing: true }));
}); });
// console.log('allMainDeviceInfoData', allMainDeviceInfoData); // console.log('allMainDeviceInfoData', allMainDeviceInfoData);
......
...@@ -58,99 +58,215 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -58,99 +58,215 @@ export const getTimers = () => async (dispatch, getState) => {
//main device section //main device section
/*-------------------------------------*/ /*-------------------------------------*/
const selectedDevice = await fireStore const selectedDeviceDetails = await fireStore
.collection('device') .collection('device')
.doc(selectedDeviceId) .doc(selectedDeviceId)
.get(); .get();
const selectedDeviceData = await selectedDevice.data(); const selectedDeviceTimers = await fireStore
mainDeviceTimers.push(selectedDeviceData.timers);
selectedDeviceData.timers.map(timer =>
allTimersData.push(Object.assign(timer, { type: selectedDeviceData.type, name: selectedDeviceData.name }))
);
//mcblink section
/*-------------------------------------*/
const selectedDeviceMcbLinks = await fireStore
.collection('device') .collection('device')
.doc(selectedDeviceId) .doc(selectedDeviceId)
.collection('mcbLinks') .collection('Timers')
.orderBy('timer', 'asc')
.where('timer', '>', 0)
.get(); .get();
let existedMcbLinks = []; const selectedDeviceDetailsData = selectedDeviceDetails.data();
let selectedDeviceMcbLinksData = []; // const selectedDeviceTimersData = selectedDeviceTimers.data();
selectedDeviceMcbLinks.docs.map(mcbLink => { selectedDeviceTimers.docs.map(timer => {
existedMcbLinks.push(mcbLink.data().id); mainDeviceTimers.push(timer.data());
selectedDeviceMcbLinksData.push(mcbLink.data()); });
let mcbLinkData = mcbLink.data();
mcbLinksTimers.push(mcbLinkData.timers); // //mcblink section
// /*-------------------------------------*/
// const selectedDeviceMcbLinks = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .get();
// let existedMcbLinks = [];
// let selectedDeviceMcbLinksData = [];
// selectedDeviceMcbLinks.docs.map(mcbLink => {
// existedMcbLinks.push(mcbLink.data().id);
// selectedDeviceMcbLinksData.push(mcbLink.data());
// let mcbLinkData = mcbLink.data();
// mcbLinksTimers.push(mcbLinkData.timers);
// mcbLinkData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// id: mcbLink.data().id,
// type: mcbLink.data().type,
// name: mcbLink.data().name,
// })
// );
// });
// });
// //subbreaker section
// /*-------------------------------------*/
// let existedSubBreakers = [];
// let selectedDeviceSubBreakersData = [];
// selectedDeviceMcbLinksData.map(async mcbLink => {
// let selectedDeviceSubBreakers = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .doc(mcbLink.id.toString())
// .collection('subBreakers')
// .get();
// return selectedDeviceSubBreakers.docs.map(subBreaker => {
// existedSubBreakers.push([mcbLink.id, subBreaker.data().id]);
// selectedDeviceSubBreakersData.push(subBreaker.data());
// let subBreakerData = subBreaker.data();
// subBreakersTimers.push(subBreakerData.timers);
// subBreakerData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// mcbLinkId: mcbLink.id,
// id: subBreaker.data().id,
// type: subBreaker.data().type,
// name: subBreaker.data().name,
// })
// );
// });
// });
// });
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// const existedData = { existedMcbLinks, existedSubBreakers };
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// dispatch(getExistedDataAction(existedData));
mcbLinkData.timers.map(timer => { dispatch(getMainDeviceTImersAction(mainDeviceTimers));
allTimersData.push( // dispatch(getMcbLinksTimersAction(mcbLinksTimers));
Object.assign(timer, { // dispatch(getSubBreakersTimersAction(subBreakersTimers));
id: mcbLink.data().id,
type: mcbLink.data().type,
name: mcbLink.data().name,
})
);
});
});
//subbreaker section
/*-------------------------------------*/
let existedSubBreakers = []; // dispatch(getTimersAction(allTimersData));
let selectedDeviceSubBreakersData = []; } catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
}
dispatch(loadingAction(false));
};
selectedDeviceMcbLinksData.map(async mcbLink => { // export const getTimers = () => async (dispatch, getState) => {
let selectedDeviceSubBreakers = await fireStore // const { currentSelectedDeviceReducer } = getState();
.collection('device') // const { selectedDeviceId } = currentSelectedDeviceReducer;
.doc(selectedDeviceId) // try {
.collection('mcbLinks') // dispatch(loadingAction(true));
.doc(mcbLink.id.toString()) // let allTimersData = [];
.collection('subBreakers') // let mainDeviceTimers = [];
.get(); // let mcbLinksTimers = [];
// let subBreakersTimers = [];
return selectedDeviceSubBreakers.docs.map(subBreaker => { // //main device section
existedSubBreakers.push([mcbLink.id, subBreaker.data().id]); // /*-------------------------------------*/
selectedDeviceSubBreakersData.push(subBreaker.data());
let subBreakerData = subBreaker.data(); // const selectedDevice = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .get();
subBreakersTimers.push(subBreakerData.timers); // const selectedDeviceData = await selectedDevice.data();
subBreakerData.timers.map(timer => { // mainDeviceTimers.push(selectedDeviceData.timers);
allTimersData.push(
Object.assign(timer, {
mcbLinkId: mcbLink.id,
id: subBreaker.data().id,
type: subBreaker.data().type,
name: subBreaker.data().name,
})
);
});
});
});
console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData); // selectedDeviceData.timers.map(timer =>
// allTimersData.push(Object.assign(timer, { type: selectedDeviceData.type, name: selectedDeviceData.name }))
// );
const existedData = { existedMcbLinks, existedSubBreakers }; // //mcblink section
// console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers); // /*-------------------------------------*/
// const selectedDeviceMcbLinks = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .get();
dispatch(getExistedDataAction(existedData)); // let existedMcbLinks = [];
// let selectedDeviceMcbLinksData = [];
dispatch(getMainDeviceTImersAction(mainDeviceTimers)); // selectedDeviceMcbLinks.docs.map(mcbLink => {
dispatch(getMcbLinksTimersAction(mcbLinksTimers)); // existedMcbLinks.push(mcbLink.data().id);
dispatch(getSubBreakersTimersAction(subBreakersTimers)); // selectedDeviceMcbLinksData.push(mcbLink.data());
// let mcbLinkData = mcbLink.data();
dispatch(getTimersAction(allTimersData)); // mcbLinksTimers.push(mcbLinkData.timers);
} catch (error) {
dispatch(errorAction(error.message || error || 'Error')); // mcbLinkData.timers.map(timer => {
} // allTimersData.push(
dispatch(loadingAction(false)); // Object.assign(timer, {
}; // id: mcbLink.data().id,
// type: mcbLink.data().type,
// name: mcbLink.data().name,
// })
// );
// });
// });
// //subbreaker section
// /*-------------------------------------*/
// let existedSubBreakers = [];
// let selectedDeviceSubBreakersData = [];
// selectedDeviceMcbLinksData.map(async mcbLink => {
// let selectedDeviceSubBreakers = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .doc(mcbLink.id.toString())
// .collection('subBreakers')
// .get();
// return selectedDeviceSubBreakers.docs.map(subBreaker => {
// existedSubBreakers.push([mcbLink.id, subBreaker.data().id]);
// selectedDeviceSubBreakersData.push(subBreaker.data());
// let subBreakerData = subBreaker.data();
// subBreakersTimers.push(subBreakerData.timers);
// subBreakerData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// mcbLinkId: mcbLink.id,
// id: subBreaker.data().id,
// type: subBreaker.data().type,
// name: subBreaker.data().name,
// })
// );
// });
// });
// });
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// const existedData = { existedMcbLinks, existedSubBreakers };
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// dispatch(getExistedDataAction(existedData));
// dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getMcbLinksTimersAction(mcbLinksTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers));
// dispatch(getTimersAction(allTimersData));
// } catch (error) {
// dispatch(errorAction(error.message || error || 'Error'));
// }
// dispatch(loadingAction(false));
// };
// export const getTimers = () => async (dispatch, getState) => { // export const getTimers = () => async (dispatch, getState) => {
// dispatch(loadingAction(true)); // dispatch(loadingAction(true));
......
...@@ -24,7 +24,7 @@ class SettingScreen extends React.Component { ...@@ -24,7 +24,7 @@ class SettingScreen extends React.Component {
}); });
} }
state = { state = {
data: this.props.allDeviceInfo[0], data: [],
isVisible: false, isVisible: false,
pressQr: false, pressQr: false,
pressMail: false, pressMail: false,
......
...@@ -119,7 +119,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -119,7 +119,7 @@ class SmartMeterDetailScreen extends Component {
state = { state = {
mbOn: false, mbOn: false,
sb: this.expandState(), sb: this.expandState(),
data: this.props.allDeviceInfo[0], data: [],
}; };
renderCurrent(item, index) { renderCurrent(item, index) {
return ( return (
...@@ -293,7 +293,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -293,7 +293,7 @@ class SmartMeterDetailScreen extends Component {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
allDeviceInfo: state.allDataReducer.allDeviceInfo, allDeviceInfo: state.allMainDeviceReducer.allDeviceInfo,
}); });
export default connect(mapStateToProps)(SmartMeterDetailScreen); export default connect(mapStateToProps)(SmartMeterDetailScreen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment