Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
safetcut-app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
atichat
safetcut-app
Commits
a3e7d977
Commit
a3e7d977
authored
Aug 26, 2019
by
HaOuiha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
4ac09b8a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
311 additions
and
127 deletions
+311
-127
App.js
+114
-46
reduxStore/actions/allMainDeviceAction.js
+4
-4
reduxStore/actions/timersAction.js
+190
-74
screens/Private/SettingScreen/SettingScreen.js
+1
-1
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+2
-2
No files found.
App.js
View file @
a3e7d977
...
...
@@ -19,33 +19,6 @@ console.disableYellowBox = true;
const
Application
=
()
=>
{
useEffect
(()
=>
{
fixTimerWarning
();
const
batch
=
fireStore
.
batch
();
const
mainRef
=
fireStore
.
doc
(
`device/
${
deviceId
}
`
);
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 subBreakersTimerRef = fireStore.doc(
// `device/${deviceId}/mcbLinks/${mcbLinkId}/subBreakers/${subBreakerId}/Timers`
// );
batch
.
set
(
mainRef
,
main
);
batch
.
set
(
mcbLinksRef
,
mcbLinks
);
batch
.
set
(
subBreakersRef
,
subBreakers
);
for
(
let
i
=
1
;
i
<=
5
;
i
++
)
{
let
mainTimerRef
=
fireStore
.
collection
(
'device'
)
.
doc
(
deviceId
)
.
collection
(
'Timers'
)
.
doc
();
batch
.
set
(
mainTimerRef
,
timer
);
}
batch
.
commit
();
},
[]);
return
(
...
...
@@ -61,10 +34,90 @@ const Application = () => {
export
default
Application
;
// const deviceId = 'iYs6Th9Pkg1vTEDIyPa5';
const
deviceId
=
'8998c7d5-4476-41d9-81c6-9ef2dbac2505'
;
const
mcbLinkId
=
1
;
const
subBreakerId
=
2
;
const
createMockData
=
()
=>
{
// const deviceId = 'iYs6Th9Pkg1vTEDIyPa5';
const
deviceId
=
'8998c7d5-4476-41d9-81c6-9ef2dbac2505'
;
const
batch
=
fireStore
.
batch
();
/*------------------------------*/
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
();
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
());
for
(
let
z
=
1
;
z
<=
5
;
z
++
)
{
let
mcbLinkTimerRef
=
fireStore
.
collection
(
'device'
)
.
doc
(
deviceId
)
.
collection
(
'mcbLinks'
)
.
doc
(
i
.
toString
())
.
collection
(
'Timers'
)
.
doc
();
batch
.
set
(
mcbLinkTimerRef
,
timer
);
}
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 mcbLinkId = 1;
// const subBreakerId = 2;
const
main
=
{
type
:
'main'
,
...
...
@@ -74,24 +127,10 @@ const main = {
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
=
{
isActive
:
false
,
isPowerOn
:
false
,
timer
:
1566378008
,
timer
:
0
,
repeatOn
:
[
{
id
:
0
,
isRepeat
:
false
,
day
:
'Sunday'
},
{
id
:
1
,
isRepeat
:
false
,
day
:
'Monday'
},
...
...
@@ -102,3 +141,32 @@ const timer = {
{
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' },
// ],
// };
reduxStore/actions/allMainDeviceAction.js
View file @
a3e7d977
...
...
@@ -45,9 +45,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
.
get
();
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
)
=>
{
...
...
@@ -57,9 +57,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
.
get
();
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);
...
...
reduxStore/actions/timersAction.js
View file @
a3e7d977
...
...
@@ -58,94 +58,102 @@ export const getTimers = () => async (dispatch, getState) => {
//main device section
/*-------------------------------------*/
const
selectedDevice
=
await
fireStore
const
selectedDevice
Details
=
await
fireStore
.
collection
(
'device'
)
.
doc
(
selectedDeviceId
)
.
get
();
const
selectedDeviceData
=
await
selectedDevice
.
data
();
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
const
selectedDeviceTimers
=
await
fireStore
.
collection
(
'device'
)
.
doc
(
selectedDeviceId
)
.
collection
(
'mcbLinks'
)
.
collection
(
'Timers'
)
.
orderBy
(
'timer'
,
'asc'
)
.
where
(
'timer'
,
'>'
,
0
)
.
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
/*-------------------------------------*/
const
selectedDeviceDetailsData
=
selectedDeviceDetails
.
data
();
// const selectedDeviceTimersData = selectedDeviceTimers.data();
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
,
})
);
});
});
selectedDeviceTimers
.
docs
.
map
(
timer
=>
{
mainDeviceTimers
.
push
(
timer
.
data
());
});
console
.
log
(
'selectedDeviceMcbLinksData'
,
selectedDeviceMcbLinksData
);
const
existedData
=
{
existedMcbLinks
,
existedSubBreakers
};
// console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
dispatch
(
getExistedDataAction
(
existedData
));
// //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));
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'
));
}
...
...
@@ -153,6 +161,114 @@ export const getTimers = () => async (dispatch, getState) => {
};
// export const getTimers = () => async (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
// try {
// dispatch(loadingAction(true));
// let allTimersData = [];
// let mainDeviceTimers = [];
// let mcbLinksTimers = [];
// let subBreakersTimers = [];
// //main device section
// /*-------------------------------------*/
// const selectedDevice = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .get();
// const selectedDeviceData = await selectedDevice.data();
// 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')
// .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));
// 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) => {
// dispatch(loadingAction(true));
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
...
...
screens/Private/SettingScreen/SettingScreen.js
View file @
a3e7d977
...
...
@@ -24,7 +24,7 @@ class SettingScreen extends React.Component {
});
}
state
=
{
data
:
this
.
props
.
allDeviceInfo
[
0
],
data
:
[
],
isVisible
:
false
,
pressQr
:
false
,
pressMail
:
false
,
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
a3e7d977
...
...
@@ -119,7 +119,7 @@ class SmartMeterDetailScreen extends Component {
state
=
{
mbOn
:
false
,
sb
:
this
.
expandState
(),
data
:
this
.
props
.
allDeviceInfo
[
0
],
data
:
[
],
};
renderCurrent
(
item
,
index
)
{
return
(
...
...
@@ -293,7 +293,7 @@ class SmartMeterDetailScreen extends Component {
}
const
mapStateToProps
=
state
=>
({
allDeviceInfo
:
state
.
all
Data
Reducer
.
allDeviceInfo
,
allDeviceInfo
:
state
.
all
MainDevice
Reducer
.
allDeviceInfo
,
});
export
default
connect
(
mapStateToProps
)(
SmartMeterDetailScreen
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment