Commit 701dd903 by HaOuiha

update

parent a3e7d977
......@@ -19,6 +19,7 @@ console.disableYellowBox = true;
const Application = () => {
useEffect(() => {
fixTimerWarning();
// createMockData();
}, []);
return (
......@@ -43,15 +44,15 @@ const createMockData = () => {
const mainRef = fireStore.doc(`device/${deviceId}`);
batch.set(mainRef, main);
for (let i = 1; i <= 5; i++) {
let mainTimerRef = fireStore
.collection('device')
.doc(deviceId)
.collection('Timers')
.doc();
// for (let i = 1; i <= 2; i++) {
// let mainTimerRef = fireStore
// .collection('device')
// .doc(deviceId)
// .collection('Timers')
// .doc();
batch.set(mainTimerRef, timer);
}
// batch.set(mainTimerRef, timer);
// }
/*------------------------------*/
for (let i = 1; i <= 4; i++) {
const mcbLinks = {
......@@ -65,7 +66,7 @@ const createMockData = () => {
.collection('mcbLinks')
.doc(i.toString());
for (let z = 1; z <= 5; z++) {
for (let z = 1; z <= 1; z++) {
let mcbLinkTimerRef = fireStore
.collection('device')
.doc(deviceId)
......@@ -96,7 +97,7 @@ const createMockData = () => {
.collection('subBreakers')
.doc(j.toString());
for (let z = 1; z <= 5; z++) {
for (let z = 1; z <= 1; z++) {
let subBreakerTimerRef = fireStore
.collection('device')
.doc(deviceId)
......@@ -127,6 +128,12 @@ const main = {
rcbo: 10,
};
const initTime = new Date();
initTime.setFullYear(2019);
initTime.setMonth(1);
initTime.setDate(0);
initTime.setSeconds(0);
const timer = {
isActive: false,
isPowerOn: false,
......
......@@ -10,9 +10,14 @@ export const GET_MAIN_DEVICE_TIMERS = 'GET_MAIN_DEVICE_TIMERS';
export const GET_MCBLINKS_TIMERS = 'GET_MCBLINKS_TIMERS';
export const GET_SUBBREAKERS_TIMERS = 'GET_SUBBREAKERS_TIMERS';
export const getTimersAction = timers => ({
// export const getTimersAction = (mainDeviceTimers, mcbLinksTimers, subBreakersTimers) => ({
// type: GET_TIMERS,
// allTimers: { mainDeviceTimers, mcbLinksTimers, subBreakersTimers },
// });
export const getTimersAction = allTimers => ({
type: GET_TIMERS,
timers,
allTimers,
});
export const getMainDeviceTImersAction = mainDeviceTimers => ({
......@@ -55,6 +60,9 @@ export const getTimers = () => async (dispatch, getState) => {
let mcbLinksTimers = [];
let subBreakersTimers = [];
// let existedMcbLinks = [];
let existedSubBreakers = [];
//main device section
/*-------------------------------------*/
......@@ -68,92 +76,112 @@ export const getTimers = () => async (dispatch, getState) => {
.doc(selectedDeviceId)
.collection('Timers')
.orderBy('timer', 'asc')
.where('timer', '>', 0)
.get();
const selectedDeviceDetailsData = selectedDeviceDetails.data();
// const selectedDeviceTimersData = selectedDeviceTimers.data();
selectedDeviceTimers.docs.map(timer => {
mainDeviceTimers.push(timer.data());
if (timer.exists) {
mainDeviceTimers.push(
Object.assign(timer.data(), {
id: timer.id,
type: selectedDeviceDetailsData.type,
name: selectedDeviceDetailsData.name,
})
);
}
});
// //mcblink section
// /*-------------------------------------*/
// const selectedDeviceMcbLinks = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .get();
//mcblink section
/*-------------------------------------*/
// 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));
const selectedDeviceMcbLinksDetails = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.get();
selectedDeviceMcbLinksDetails.docs.map(async mcbLink => {
if (mcbLink.exists) {
// existedMcbLinks.push(Object.assign(mcbLink.data(), { id: mcbLink.id }));
let mcbLinkTimers = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id)
.collection('Timers')
.orderBy('timer', 'asc')
.get();
mcbLinkTimers.docs.map(mcbLinkTimer => {
if (mcbLinkTimer.exists) {
mcbLinksTimers.push(
Object.assign(mcbLinkTimer.data(), {
id: mcbLink.id,
key: mcbLinkTimer.id,
type: mcbLink.data().type,
name: mcbLink.data().name,
})
);
}
});
//subbreaker section
/*-------------------------------------*/
const selectedDeviceSubBreakersDetails = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id)
.collection('subBreakers')
.get();
existedSubBreakers.push(
selectedDeviceSubBreakersDetails.docs.map(subBreaker =>
Object.assign(subBreaker.data(), { mcbLinkId: mcbLink.id, id: subBreaker.id })
)
);
selectedDeviceSubBreakersDetails.docs.map(async subBreaker => {
if (subBreaker.exists) {
let subBreakerTimers = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id)
.collection('subBreakers')
.doc(subBreaker.id)
.collection('Timers')
.orderBy('timer', 'asc')
.get();
subBreakerTimers.docs.map(subBreakerTimer => {
if (subBreakerTimer.exists) {
subBreakersTimers.push(
Object.assign(subBreakerTimer.data(), {
mcbLinkId: mcbLink.id,
id: subBreaker.id,
key: subBreakerTimer.id,
type: subBreaker.data().type,
name: subBreaker.data().name,
})
);
}
});
}
});
}
});
dispatch(getExistedDataAction(existedSubBreakers));
dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getMcbLinksTimersAction(mcbLinksTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers));
dispatch(getMcbLinksTimersAction(mcbLinksTimers));
dispatch(getSubBreakersTimersAction(subBreakersTimers));
// dispatch(getTimersAction(allTimersData));
// dispatch(getTimersAction(allTimersData));
} catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
}
......
......@@ -9,7 +9,7 @@ import {
} from '../actions/timersAction';
const initState = {
timers: [],
allTimers: [],
mainDeviceTimers: [],
mcbLinksTimers: [],
subBreakersTimers: [],
......@@ -23,7 +23,7 @@ const timersReducer = (state = initState, action) => {
case GET_EXISTED_DATA:
return { ...state, existedData: action.existedData };
case GET_TIMERS:
return { ...state, timers: action.timers };
return { ...state, allTimers: action.allTimers };
case GET_MAIN_DEVICE_TIMERS:
return { ...state, mainDeviceTimers: action.mainDeviceTimers };
case GET_MCBLINKS_TIMERS:
......
......@@ -171,7 +171,7 @@ class SmartMeterDetailScreen extends Component {
renderMCBLink(item, index) {
const sb = this.state.sb;
return (
<View>
<View key={item + index}>
<Row
style={{ padding: 7 }}
onPress={() =>
......
......@@ -70,7 +70,7 @@ class SmartMeterScreen extends PureComponent {
style={[theme.container, theme.containerWithPadding]}
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }} //iPhoneX BottomSpace = 34
data={allMainDeviceInfo}
extraData={allMainDeviceInfo}
extraData={this.props}
keyExtractor={(item, index) => `Card${item.deviceId}`}
ListEmptyComponent={() => (
<View>
......
......@@ -27,10 +27,16 @@ import { fireStore } from '../../../firebase';
import firebase from 'firebase/app';
import 'firebase/firestore';
const initTime = new Date();
initTime.setFullYear(2019);
initTime.setMonth(1);
initTime.setDate(0);
initTime.setSeconds(0);
const initState = {
isActive: false,
isPowerOn: false,
timer: new Date(),
timer: initTime,
repeatOn: [
{ id: 0, isRepeat: false, day: 'Sunday' },
{ id: 1, isRepeat: false, day: 'Monday' },
......@@ -63,23 +69,10 @@ class TimerScreen extends PureComponent {
headerRight: navigation.state.params ? navigation.state.params.headerRight : null,
});
// constructor(props) {
// super(props);
// this.props.navigation.setParams({
// headerRight: (
// <TouchableOpacity onPress={() => this.setState({ isAddVisible: true })}>
// <View style={{ marginRight: 17 }}>
// <Icon name="ios-add" style={{ color: color.white }} />
// </View>
// </TouchableOpacity>
// ),
// });
// }
state = {
isActive: false,
isPowerOn: false,
timer: new Date(),
timer: initTime,
repeatOn: [
{ id: 0, isRepeat: false, day: 'Sunday' },
{ id: 1, isRepeat: false, day: 'Monday' },
......@@ -101,30 +94,31 @@ class TimerScreen extends PureComponent {
selectedBreaker: null,
selectedSubBreaker: null,
allListTimers: [],
};
setPickerSelectData = async () => {
setPickerSelectData = () => {
let pickerSelectData = [{ label: 'Main Device', value: false }];
await this.props.existedData.existedMcbLinks.map((mcbLinkId, index) => {
pickerSelectData.push({ label: `MCB Link ${mcbLinkId}`, value: index + 1 });
this.props.existedData.map((mcbLink, index) => {
pickerSelectData.push({ label: `MCB Link ${index + 1}`, value: index + 1 });
});
this.setState({ pickerSelectData });
};
setExistedSubBreaker = () => {
let existedSubBreaker = [];
this.props.existedData.existedSubBreakers.map(subBreaker => {
if (this.state.selectedBreaker === subBreaker[0]) {
existedSubBreaker.push(subBreaker);
let subBreakersList = 0;
this.props.existedData.map((mainBreaker, index) => {
if (this.state.selectedBreaker === index + 1) {
subBreakersList = mainBreaker.length;
}
});
console.log('existedSubBreaker', existedSubBreaker);
let subBreakerList = new Array(existedSubBreaker.length).fill().map((el, index) => {
let subBreakerList = new Array(subBreakersList).fill().map((el, index) => {
return { id: index + 1, selected: false };
});
console.log('subBreakerList', subBreakerList);
// console.log('subBreakerList', subBreakerList);
this.setState({ subBreakerList });
};
......@@ -159,23 +153,10 @@ class TimerScreen extends PureComponent {
const deviceId = this.props.selectedDeviceId;
const { selectedSubBreaker, selectedBreaker } = this.state;
// const data = {
// timers: [
// {
// isActive: this.state.isActive,
// isPowerOn: this.state.isPowerOn,
// timer: Number(this.state.timer),
// repeatOn: this.state.repeatOn,
// },
// ],
// };
let docRef = null;
if (selectedSubBreaker) {
docRef = fireStore.doc(
`device/${deviceId}/mcbLinks/${selectedBreaker}/subBreakers/${selectedSubBreaker.id}`
);
docRef = fireStore.doc(`device/${deviceId}/mcbLinks/${selectedBreaker}/subBreakers/${selectedSubBreaker}`);
} else if (selectedBreaker) {
docRef = fireStore.doc(`device/${deviceId}/mcbLinks/${selectedBreaker}`);
} else {
......@@ -203,8 +184,7 @@ class TimerScreen extends PureComponent {
if (prevState.selectedBreaker !== this.state.selectedBreaker) {
this.setExistedSubBreaker();
}
if (prevProps.existedData.existedMcbLinks !== this.props.existedData.existedMcbLinks) {
console.log('this.props.existedData.existedMcbLinks', this.props.existedData.existedMcbLinks);
if (prevProps.existedData !== this.props.existedData) {
this.setPickerSelectData();
}
if (prevState.subBreakerList !== this.state.subBreakerList && this.state.subBreakerList) {
......@@ -214,6 +194,15 @@ class TimerScreen extends PureComponent {
this.setState({ selectedSubBreaker: selectedSubBreaker });
}
if (prevProps.allTimers !== this.props.allTimers) {
this.setState({
allListTimers: [
...this.props.mainDeviceTimers,
...this.props.mcbLinksTimers,
...this.props.subBreakersTimers,
],
});
}
console.log('STATE', this.state);
};
......@@ -229,7 +218,14 @@ class TimerScreen extends PureComponent {
),
});
this.setExistedSubBreaker();
this.props.existedData.existedMcbLinks && this.setPickerSelectData();
this.props.existedData && this.setPickerSelectData();
this.setState({
allListTimers: [
...this.props.mainDeviceTimers,
...this.props.mcbLinksTimers,
...this.props.subBreakersTimers,
],
});
};
render() {
......@@ -267,8 +263,8 @@ class TimerScreen extends PureComponent {
{/* List Timer */}
<FlatList
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }}
data={this.props.timers}
extraData={this.props}
data={this.props.allTimers}
extraData={this.props.allTimers}
ListEmptyComponent={() => (
<View>
<Text style={[theme.normalText, theme.mt2]}>No timers</Text>
......@@ -519,7 +515,10 @@ class TimerScreen extends PureComponent {
const mapStateToProps = state => ({
existedData: state.timersReducer.existedData,
timers: state.timersReducer.timers,
allTimers: state.timersReducer.allTimers,
mainDeviceTimers: state.timersReducer.mainDeviceTimers,
mcbLinksTimers: state.timersReducer.mcbLinksTimers,
subBreakersTimers: state.timersReducer.subBreakersTimers,
isLoading: state.timersReducer.isLoading,
selectedDeviceId: state.currentSelectedDeviceReducer.selectedDeviceId,
});
......
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