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
8d82acd1
Commit
8d82acd1
authored
Aug 30, 2019
by
HaOuiha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
412dfd19
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
259 additions
and
154 deletions
+259
-154
components/MeterCard.js
+60
-5
firestore.rules
+5
-1
reduxStore/actions/currentSelectedAction.js
+31
-0
reduxStore/actions/timersAction.js
+69
-23
reduxStore/reducers/currentSelectedReducer.js
+4
-1
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+69
-115
screens/Private/SmartMeterScreen/SmartMeterScreen.js
+8
-1
screens/Private/TimerScreen/TimerScreen.andriod.js
+13
-8
No files found.
components/MeterCard.js
View file @
8d82acd1
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
Component
}
from
'react'
;
import
{
View
,
Row
,
Icon
,
Text
}
from
'native-base'
;
import
{
View
,
Row
,
Icon
,
Text
}
from
'native-base'
;
import
{
Image
,
StyleSheet
}
from
'react-native'
;
import
{
Image
,
StyleSheet
,
Platform
}
from
'react-native'
;
import
{
BaseButton
}
from
'react-native-gesture-handler'
;
import
{
BaseButton
,
TouchableOpacity
}
from
'react-native-gesture-handler'
;
import
{
color
,
theme
}
from
'../constants/Styles'
;
import
{
color
,
theme
}
from
'../constants/Styles'
;
class
MeterCard
extends
Component
{
class
MeterCard
extends
Component
{
render
()
{
render
()
{
return
(
return
Platform
.
OS
===
'android'
?
(
<
BaseButton
<
BaseButton
onPress
=
{
this
.
props
.
onPressEachCard
}
onPress
=
{
this
.
props
.
onPressEachCard
}
rippleColor
=
{
'#fcc5c5'
}
rippleColor
=
{
'#fcc5c5'
}
...
@@ -17,6 +17,62 @@ class MeterCard extends Component {
...
@@ -17,6 +17,62 @@ class MeterCard extends Component {
marginBottom
:
10
,
marginBottom
:
10
,
height
:
136
,
height
:
136
,
borderRadius
:
8
,
borderRadius
:
8
,
elevation
:
5
,
backgroundColor
:
'#fff'
,
},
]}
>
<
View
style
=
{[
styles
.
meterOn
,
{
backgroundColor
:
this
.
props
.
isOn
?
'rgba(65, 204, 0, 0.59)'
:
'rgba(223, 0, 0, 0.59)'
},
]}
>
<
Text
style
=
{[
theme
.
smDescription
,
theme
.
textWhite
]}
>
{
this
.
props
.
isOn
?
'ON'
:
'OFF'
}
<
/Text
>
<
/View
>
<
View
style
=
{[
theme
.
centerContainer
]}
>
{
this
.
props
.
img
?
(
<
Image
source
=
{{
uri
:
this
.
props
.
img
}}
style
=
{
styles
.
meterImgStyle
}
/
>
)
:
(
<
View
style
=
{[
styles
.
meterImgStyle
,
{
flex
:
1
,
justifyContent
:
'center'
,
alignContent
:
'center'
},
]}
>
<
Text
style
=
{{
fontSize
:
10
}}
>
No
Img
<
/Text
>
<
/View
>
)}
<
/View
>
<
View
style
=
{[
theme
.
containerWithPadding
,
{
flex
:
2
}]}
>
{
this
.
props
.
isOnline
?
<
View
style
=
{[
styles
.
online
]}
/> : null
}
<
Row
style
=
{{
alignItems
:
'center'
}}
>
<
Text
style
=
{[
theme
.
smallTitle
,
{
marginRight
:
15
}]}
>
{
this
.
props
.
name
}
<
/Text
>
<
/Row
>
<
Text
style
=
{[
theme
.
smDescription
]}
numberOfLines
=
{
2
}
>
{
this
.
props
.
description
}
<
/Text
>
<
Row
style
=
{{
marginTop
:
10
}}
>
<
View
style
=
{[
styles
.
meterIconCover
]}
>
<
Icon
name
=
"ios-notifications-outline"
style
=
{
styles
.
meterIconStyle
}
/
>
<
/View
>
<
View
style
=
{
styles
.
meterIconCover
}
>
<
Icon
name
=
"md-alarm"
style
=
{
styles
.
meterIconStyle
}
/
>
<
/View
>
<
/Row
>
<
/View
>
<
/BaseButton
>
)
:
(
<
TouchableOpacity
onPress
=
{
this
.
props
.
onPressEachCard
}
style
=
{[
theme
.
rowContainer
,
{
borderRadius
:
8
,
marginBottom
:
10
,
height
:
136
,
borderRadius
:
8
,
shadowColor
:
'#000'
,
shadowColor
:
'#000'
,
shadowOffset
:
{
shadowOffset
:
{
width
:
0
,
width
:
0
,
...
@@ -24,7 +80,6 @@ class MeterCard extends Component {
...
@@ -24,7 +80,6 @@ class MeterCard extends Component {
},
},
shadowOpacity
:
0.25
,
shadowOpacity
:
0.25
,
shadowRadius
:
3.84
,
shadowRadius
:
3.84
,
elevation
:
5
,
backgroundColor
:
'#fff'
,
backgroundColor
:
'#fff'
,
},
},
]}
]}
...
@@ -69,7 +124,7 @@ class MeterCard extends Component {
...
@@ -69,7 +124,7 @@ class MeterCard extends Component {
<
/View
>
<
/View
>
<
/Row
>
<
/Row
>
<
/View
>
<
/View
>
<
/
BaseButton
>
<
/
TouchableOpacity
>
);
);
}
}
}
}
...
...
firestore.rules
View file @
8d82acd1
rules_version = '2';
rules_version = '2';
service cloud.firestore {
service cloud.firestore {
match /databases/{database}/documents {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
match /{document=**} {
match /{document=**} {
allow read, write: if
true
;
allow read, write: if
isSignedIn()
;
}
}
}
}
}
}
\ No newline at end of file
reduxStore/actions/currentSelectedAction.js
View file @
8d82acd1
import
{
fireStore
}
from
'../../firebase'
;
export
const
SET_CURRENT_SELECTED
=
'SET_CURRENT_SELECTED'
;
export
const
SET_CURRENT_SELECTED
=
'SET_CURRENT_SELECTED'
;
export
const
GET_CURRENT_SELECTED_DATA
=
'GET_CURRENT_SELECTED_DATA'
;
export
const
setCurrentSelectedAction
=
selectedDeviceId
=>
({
export
const
setCurrentSelectedAction
=
selectedDeviceId
=>
({
type
:
SET_CURRENT_SELECTED
,
type
:
SET_CURRENT_SELECTED
,
...
@@ -8,3 +11,31 @@ export const setCurrentSelectedAction = selectedDeviceId => ({
...
@@ -8,3 +11,31 @@ export const setCurrentSelectedAction = selectedDeviceId => ({
export
const
setCurrentSelected
=
deviceId
=>
dispatch
=>
{
export
const
setCurrentSelected
=
deviceId
=>
dispatch
=>
{
dispatch
(
setCurrentSelectedAction
(
deviceId
));
dispatch
(
setCurrentSelectedAction
(
deviceId
));
};
};
export
const
getCurrentSelectedDataAction
=
currentSelectedData
=>
({
type
:
GET_CURRENT_SELECTED_DATA
,
currentSelectedData
,
});
export
const
getCurrentSelectedData
=
currentSelectedDeviceData
=>
dispatch
=>
{
dispatch
(
getCurrentSelectedDataAction
(
currentSelectedDeviceData
));
};
// export const getCurrentSelectedData = (deviceId, mcbLinkId, subBreakerId) => (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
// const currentSelectedDeviceId = deviceId || selectedDeviceId;
// try {
// const stopListener = fireStore
// .collection('device')
// .doc(currentSelectedDeviceId)
// .onSnapshot(mainDeviceSanpshot => {
// dispatch(getCurrentSelectedDataAction(mainDeviceSanpshot.data()));
// });
// return stopListener;
// } catch (e) {
// alert(e);
// }
// };
reduxStore/actions/timersAction.js
View file @
8d82acd1
...
@@ -7,7 +7,6 @@ export const GET_TIMERS_ERROR = 'GET_TIMERS_ERROR';
...
@@ -7,7 +7,6 @@ export const GET_TIMERS_ERROR = 'GET_TIMERS_ERROR';
export
const
GET_EXISTED_DATA
=
'GET_EXISTED_DATA'
;
export
const
GET_EXISTED_DATA
=
'GET_EXISTED_DATA'
;
export
const
GET_MAIN_DEVICE_TIMERS
=
'GET_MAIN_DEVICE_TIMERS'
;
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
GET_SUBBREAKERS_TIMERS
=
'GET_SUBBREAKERS_TIMERS'
;
export
const
GET_SELECTED_TIMER_DATA
=
'GET_SELECTED_TIMER_DATA'
;
export
const
GET_SELECTED_TIMER_DATA
=
'GET_SELECTED_TIMER_DATA'
;
...
@@ -23,11 +22,6 @@ export const getMainDeviceTImersAction = mainDeviceTimers => ({
...
@@ -23,11 +22,6 @@ export const getMainDeviceTImersAction = mainDeviceTimers => ({
mainDeviceTimers
,
mainDeviceTimers
,
});
});
// export const getMcbLinksTimersAction = mcbLinksTimers => ({
// type: GET_MCBLINKS_TIMERS,
// mcbLinksTimers,
// });
export
const
getSubBreakersTimersAction
=
subBreakersTimers
=>
({
export
const
getSubBreakersTimersAction
=
subBreakersTimers
=>
({
type
:
GET_SUBBREAKERS_TIMERS
,
type
:
GET_SUBBREAKERS_TIMERS
,
subBreakersTimers
,
subBreakersTimers
,
...
@@ -66,9 +60,9 @@ export const getTimers = () => async (dispatch, getState) => {
...
@@ -66,9 +60,9 @@ export const getTimers = () => async (dispatch, getState) => {
let
allTimersData
=
[];
let
allTimersData
=
[];
let
mainDeviceTimers
=
[];
let
mainDeviceTimers
=
[];
let
subBreakersTimers
=
[];
let
subBreakersTimers
=
[];
let
existedSubBreakers
=
[];
let
existed
McbLinks
SubBreakers
=
[];
let
mcbLinksSubBreakersTimers
=
[];
//
let mcbLinksSubBreakersTimers = [];
//main device section
//main device section
/*-------------------------------------*/
/*-------------------------------------*/
...
@@ -121,12 +115,9 @@ export const getTimers = () => async (dispatch, getState) => {
...
@@ -121,12 +115,9 @@ export const getTimers = () => async (dispatch, getState) => {
.
collection
(
'subBreakers'
)
.
collection
(
'subBreakers'
)
.
get
();
.
get
();
existedSubBreakers
.
push
(
existed
McbLinks
SubBreakers
.
push
(
selectedDeviceSubBreakersDetails
.
docs
.
map
(
subBreaker
=>
selectedDeviceSubBreakersDetails
.
docs
.
map
(
subBreaker
=>
Object
.
assign
(
Object
.
assign
(
subBreaker
.
data
(),
{
mcbLinkId
:
mcbLink
.
id
,
subBreakerId
:
subBreaker
.
id
})
// subBreaker.data(),
{
mcbLinkId
:
mcbLink
.
id
,
subBreakerId
:
subBreaker
.
id
}
)
)
)
);
);
...
@@ -164,7 +155,7 @@ export const getTimers = () => async (dispatch, getState) => {
...
@@ -164,7 +155,7 @@ export const getTimers = () => async (dispatch, getState) => {
})
})
);
);
dispatch
(
getExistedDataAction
(
existedSubBreakers
));
dispatch
(
getExistedDataAction
(
existed
McbLinks
SubBreakers
));
// dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers));
...
@@ -186,11 +177,13 @@ export const setEditModalVisible = bool => async dispatch => {
...
@@ -186,11 +177,13 @@ export const setEditModalVisible = bool => async dispatch => {
};
};
export
const
createNewTimer
=
(
mcbLinkId
,
subBreakerId
,
settingTime
)
=>
async
(
dispatch
,
getState
)
=>
{
export
const
createNewTimer
=
(
mcbLinkId
,
subBreakerId
,
settingTime
)
=>
async
(
dispatch
,
getState
)
=>
{
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedDeviceReducer
,
timersReducer
}
=
getState
();
const
{
selectedDeviceId
}
=
currentSelectedDeviceReducer
;
const
{
selectedDeviceId
,
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
{
allTimers
,
existedData
}
=
timersReducer
;
let
docRef
=
null
;
let
docRef
=
null
;
try
{
try
{
// dispatch(loadingAction(true));
dispatch
(
loadingAction
(
true
));
if
(
mcbLinkId
&&
subBreakerId
)
{
if
(
mcbLinkId
&&
subBreakerId
)
{
docRef
=
fireStore
docRef
=
fireStore
.
collection
(
'device'
)
.
collection
(
'device'
)
...
@@ -209,14 +202,65 @@ export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (d
...
@@ -209,14 +202,65 @@ export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (d
let
timers
=
await
docRef
.
get
();
let
timers
=
await
docRef
.
get
();
// console.log('timerLength', timers.size, timers.docs.length);
// console.log('timerLength', timers.size, timers.docs.length);
if
(
timers
.
size
<
5
)
{
if
(
timers
.
size
<
5
)
{
await
docRef
.
add
(
settingTime
);
const
resRef
=
await
docRef
.
add
(
settingTime
);
let
timerData
=
null
;
if
(
mcbLinkId
&&
subBreakerId
)
{
timerData
=
await
Object
.
assign
(
settingTime
,
{
mcbLinkId
:
mcbLinkId
,
subBreakerId
:
subBreakerId
,
key
:
resRef
.
id
,
type
:
currentSelectedData
.
type
,
name
:
currentSelectedData
.
name
,
});
}
else
{
timerData
=
await
Object
.
assign
(
settingTime
,
{
key
:
resRef
.
id
,
type
:
currentSelectedData
.
type
,
name
:
currentSelectedData
.
name
,
});
}
// console.log(timerData);
let
mergedTimers
=
_
.
sortBy
([...
allTimers
,
timerData
],
[
'type'
,
'mcbLinkId'
,
'subBreakerId'
]);
// console.log(mergedTimers);
const
groupTypeData
=
await
_
.
groupBy
(
allTimers
,
'type'
);
console
.
log
(
groupTypeData
);
const
groupMcbLinks
=
await
_
.
groupBy
(
groupTypeData
.
subBreaker
,
groupMcbLinks
=>
groupMcbLinks
.
mcbLinkId
+
'-'
+
groupMcbLinks
.
subBreakerId
);
console
.
log
(
groupMcbLinks
);
const
testGroup
=
_
.
chain
(
allTimers
)
.
groupBy
(
'type'
)
.
mapValues
(
values
=>
{
return
values
.
subBreakerId
?
_
.
chain
(
values
.
subBreakerId
)
.
groupBy
(
groupMcbLinks
=>
groupMcbLinks
.
mcbLinkId
+
'-'
+
groupMcbLinks
.
subBreakerId
)
.
value
()
:
values
.
value
();
})
.
value
();
console
.
log
(
'testGroup'
,
testGroup
);
// existedData.map(async (mcbLink, index) => {
// let groupMcbLink = await _.groupBy(groupMcbLinks[index + 1], 'subBreakerId');
// console.log(groupMcbLink);
// });
dispatch
(
getTimersAction
(
mergedTimers
));
dispatch
(
loadingAction
(
false
));
return
true
;
return
true
;
}
else
{
}
else
{
alert
(
'Breaker cannot have more than 5 timers.'
);
alert
(
'Breaker cannot have more than 5 timers.'
);
dispatch
(
loadingAction
(
false
));
return
false
;
return
false
;
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
alert
(
e
);
alert
(
e
);
dispatch
(
loadingAction
(
false
));
}
}
};
};
...
@@ -229,7 +273,7 @@ export const editTimer = settingTime => async (dispatch, getState) => {
...
@@ -229,7 +273,7 @@ export const editTimer = settingTime => async (dispatch, getState) => {
let
docRef
=
null
;
let
docRef
=
null
;
try
{
try
{
//
dispatch(loadingAction(true));
dispatch
(
loadingAction
(
true
));
if
(
mcbLinkId
&&
subBreakerId
)
{
if
(
mcbLinkId
&&
subBreakerId
)
{
docRef
=
fireStore
docRef
=
fireStore
.
collection
(
'device'
)
.
collection
(
'device'
)
...
@@ -251,6 +295,7 @@ export const editTimer = settingTime => async (dispatch, getState) => {
...
@@ -251,6 +295,7 @@ export const editTimer = settingTime => async (dispatch, getState) => {
}
catch
(
e
)
{
}
catch
(
e
)
{
alert
(
e
);
alert
(
e
);
}
}
dispatch
(
loadingAction
(
false
));
};
};
export
const
deleteTimer
=
selectedData
=>
async
(
dispatch
,
getState
)
=>
{
export
const
deleteTimer
=
selectedData
=>
async
(
dispatch
,
getState
)
=>
{
...
@@ -260,7 +305,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -260,7 +305,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
let
docRef
=
null
;
let
docRef
=
null
;
try
{
try
{
//
dispatch(loadingAction(true));
dispatch
(
loadingAction
(
true
));
if
(
key
)
{
if
(
key
)
{
if
(
mcbLinkId
&&
subBreakerId
)
{
if
(
mcbLinkId
&&
subBreakerId
)
{
docRef
=
fireStore
docRef
=
fireStore
...
@@ -285,6 +330,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -285,6 +330,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
}
catch
(
e
)
{
}
catch
(
e
)
{
alert
(
e
);
alert
(
e
);
}
}
dispatch
(
loadingAction
(
false
));
};
};
// export const getTimers = () => async (dispatch, getState) => {
// export const getTimers = () => async (dispatch, getState) => {
...
@@ -344,7 +390,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -344,7 +390,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// //subbreaker section
// //subbreaker section
// /*-------------------------------------*/
// /*-------------------------------------*/
// let existedSubBreakers = [];
// let existed
McbLinks
SubBreakers = [];
// let selectedDeviceSubBreakersData = [];
// let selectedDeviceSubBreakersData = [];
// selectedDeviceMcbLinksData.map(async mcbLink => {
// selectedDeviceMcbLinksData.map(async mcbLink => {
...
@@ -357,7 +403,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -357,7 +403,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// .get();
// .get();
// return selectedDeviceSubBreakers.docs.map(subBreaker => {
// return selectedDeviceSubBreakers.docs.map(subBreaker => {
// existedSubBreakers.push([mcbLink.id, subBreaker.data().id]);
// existed
McbLinks
SubBreakers.push([mcbLink.id, subBreaker.data().id]);
// selectedDeviceSubBreakersData.push(subBreaker.data());
// selectedDeviceSubBreakersData.push(subBreaker.data());
// let subBreakerData = subBreaker.data();
// let subBreakerData = subBreaker.data();
...
@@ -379,7 +425,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -379,7 +425,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// const existedData = { existedMcbLinks, existedSubBreakers };
// const existedData = { existedMcbLinks, existed
McbLinks
SubBreakers };
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// dispatch(getExistedDataAction(existedData));
// dispatch(getExistedDataAction(existedData));
...
...
reduxStore/reducers/currentSelectedReducer.js
View file @
8d82acd1
import
{
SET_CURRENT_SELECTED
}
from
'../actions/currentSelectedAction'
;
import
{
SET_CURRENT_SELECTED
,
GET_CURRENT_SELECTED_DATA
}
from
'../actions/currentSelectedAction'
;
const
initState
=
{
const
initState
=
{
selectedDeviceId
:
''
,
selectedDeviceId
:
''
,
currentSelectedData
:
{},
};
};
const
currentSelectedDeviceReducer
=
(
state
=
initState
,
action
)
=>
{
const
currentSelectedDeviceReducer
=
(
state
=
initState
,
action
)
=>
{
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
case
SET_CURRENT_SELECTED
:
case
SET_CURRENT_SELECTED
:
return
{
...
state
,
selectedDeviceId
:
action
.
selectedDeviceId
};
return
{
...
state
,
selectedDeviceId
:
action
.
selectedDeviceId
};
case
GET_CURRENT_SELECTED_DATA
:
return
{
...
state
,
currentSelectedData
:
action
.
currentSelectedData
};
default
:
default
:
return
state
;
return
state
;
}
}
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
8d82acd1
...
@@ -4,77 +4,8 @@ import { color, theme } from '../../../constants/Styles';
...
@@ -4,77 +4,8 @@ import { color, theme } from '../../../constants/Styles';
import
{
FlatList
,
StyleSheet
}
from
'react-native'
;
import
{
FlatList
,
StyleSheet
}
from
'react-native'
;
import
{
TouchableOpacity
}
from
'react-native-gesture-handler'
;
import
{
TouchableOpacity
}
from
'react-native-gesture-handler'
;
import
{
connect
}
from
'react-redux'
;
import
{
connect
}
from
'react-redux'
;
import
{
setCurrentSelected
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
import
{
setCurrentSelected
,
getCurrentSelectedData
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
// Main Breaker mock data
const
MainBreaker
=
{
name
:
'Main Breaker'
,
description
:
'Lorem ipsum dolorsit amet,consectetur adipiscing elit. Cras sagitti.'
,
current
:
'10mA'
,
status
:
true
,
on
:
true
,
Ecurrent
:
[
{
name
:
'AC Volt'
,
number
:
250
,
unit
:
'V'
},
{
name
:
'AC Current'
,
number
:
118
,
unit
:
'A'
},
{
name
:
'Watt'
,
number
:
5890
,
unit
:
'V'
},
{
name
:
'Leakage Current'
,
number
:
25
,
unit
:
'mA'
},
{
name
:
'Units/KWh'
,
number
:
999999
,
unit
:
''
},
{
name
:
'Arcing Fault'
,
number
:
453
,
unit
:
''
},
],
MCB
:
[
{
title
:
'MCB Link 1'
,
sub
:
[
{
title
:
'Sub Breaker 1-1'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 1-2'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 1-3'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 1-4'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 1-5'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 1-6'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 1-7'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 1-8'
,
description
:
'Description'
,
status
:
true
},
],
},
{
title
:
'MCB Link 2'
,
sub
:
[
{
title
:
'Sub Breaker 2-1'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 2-2'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 2-3'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 2-4'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 2-5'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 2-6'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 2-7'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 2-8'
,
description
:
'Description'
,
status
:
true
},
],
},
{
title
:
'MCB Link 3'
,
sub
:
[
{
title
:
'Sub Breaker 3-1'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 3-2'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 3-3'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 3-4'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 3-5'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 3-6'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 3-7'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 3-8'
,
description
:
'Description'
,
status
:
true
},
],
},
{
title
:
'MCB Link 4'
,
sub
:
[
{
title
:
'Sub Breaker 4-1'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 4-2'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 4-3'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 4-4'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 4-5'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 4-6'
,
description
:
'Description'
,
status
:
true
},
{
title
:
'Sub Breaker 4-7'
,
description
:
'Description'
,
status
:
false
},
{
title
:
'Sub Breaker 4-8'
,
description
:
'Description'
,
status
:
true
},
],
},
],
};
const
LimitCurrent
=
[
const
LimitCurrent
=
[
{
name
:
'AC Volt'
,
limit
:
1000
},
{
name
:
'AC Volt'
,
limit
:
1000
},
{
name
:
'AC Current'
,
limit
:
1000
},
{
name
:
'AC Current'
,
limit
:
1000
},
...
@@ -86,7 +17,7 @@ const LimitCurrent = [
...
@@ -86,7 +17,7 @@ const LimitCurrent = [
class
SmartMeterDetailScreen
extends
Component
{
class
SmartMeterDetailScreen
extends
Component
{
static
navigationOptions
=
({
navigation
})
=>
{
static
navigationOptions
=
({
navigation
})
=>
{
const
deviceName
=
navigation
.
getParam
(
'name'
,
''
);
//
const deviceName = navigation.getParam('name', '');
return
{
return
{
title
:
'Device'
,
title
:
'Device'
,
...
@@ -101,14 +32,69 @@ class SmartMeterDetailScreen extends Component {
...
@@ -101,14 +32,69 @@ class SmartMeterDetailScreen extends Component {
};
};
state
=
{
state
=
{
sb
:
this
.
expandState
(),
data
:
[],
data
:
this
.
props
.
allMainDeviceInfo
.
find
(
x
=>
x
.
deviceId
===
this
.
props
.
navigation
.
getParam
(
'deviceId'
)),
description
:
''
,
name
:
''
,
rcbo
:
''
,
isOnline
:
false
,
isPowerOn
:
false
,
};
};
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
props
.
setCurrentSelected
(
this
.
props
.
navigation
.
getParam
(
'deviceId'
));
const
currentSelectedDeviceData
=
this
.
props
.
navigation
.
getParam
(
'currentSelectedDeviceData'
);
this
.
props
.
setCurrentSelected
(
currentSelectedDeviceData
.
deviceId
);
this
.
props
.
getCurrentSelectedData
(
currentSelectedDeviceData
);
}
componentDidMount
=
()
=>
{};
componentDidUpdate
=
(
prevProps
,
prevState
)
=>
{
if
(
prevProps
.
currentSelectedData
!==
this
.
props
.
currentSelectedData
)
{
this
.
setMainCardData
();
}
}
};
setMainCardData
=
async
()
=>
{
const
{
currentSelectedData
}
=
this
.
props
;
this
.
setState
({
description
:
currentSelectedData
.
description
,
name
:
currentSelectedData
.
name
,
rcbo
:
currentSelectedData
.
rcbo
,
isOnline
:
currentSelectedData
.
isOnline
||
false
,
isPowerOn
:
currentSelectedData
.
isPowerOn
||
false
,
});
};
renderMainDatailsCard
=
()
=>
{
const
{
name
,
description
,
rcbo
,
isOnline
,
isPowerOn
}
=
this
.
state
;
return
(
<
Card
style
=
{[
theme
.
containerWithPadding
,
{
borderRadius
:
10
}]}
>
<
Row
>
<
Left
>
<
Text
style
=
{[
theme
.
smallTitle
,
{
color
:
color
.
darkGrey
}]}
>
{
name
}
<
/Text
>
<
/Left
>
<
Right
>
<
Switch
value
=
{
isPowerOn
}
/
>
<
/Right
>
<
/Row
>
<
Text
style
=
{[
theme
.
description
,
theme
.
mt1
]}
>
{
description
}
<
/Text
>
<
Row
style
=
{
theme
.
mt1
}
>
<
Text
style
=
{[
theme
.
description
,
theme
.
textDark
,
{
marginRight
:
5
}]}
>
Status
:{
' '
}
<
Text
style
=
{[
theme
.
description
,
{
color
:
isOnline
?
color
.
success
:
color
.
primary
}]}
>
{
isOnline
?
'Online'
:
'Offline'
}
<
/Text
>
<
/Text
>
<
Text
style
=
{[
theme
.
description
,
theme
.
textDark
]}
>
RCBO
:
<
Text
style
=
{[
theme
.
description
,
{
color
:
color
.
primary
}]}
>
{
rcbo
}
mA
<
/Text
>
<
/Text
>
<
/Row
>
<
/Card
>
);
};
renderCurrent
(
item
,
index
)
{
renderCurrent
(
item
,
index
)
{
return
(
return
(
<
Card
<
Card
...
@@ -197,14 +183,7 @@ class SmartMeterDetailScreen extends Component {
...
@@ -197,14 +183,7 @@ class SmartMeterDetailScreen extends Component {
<
/View
>
<
/View
>
);
);
}
}
expandState
()
{
const
length
=
MainBreaker
.
MCB
.
length
;
const
preSb
=
new
Array
(
length
);
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
preSb
[
i
]
=
{
expand
:
false
};
}
return
preSb
;
}
// full incomplete row
// full incomplete row
formatGridData
(
unformatData
)
{
formatGridData
(
unformatData
)
{
let
data
=
unformatData
;
let
data
=
unformatData
;
...
@@ -221,36 +200,8 @@ class SmartMeterDetailScreen extends Component {
...
@@ -221,36 +200,8 @@ class SmartMeterDetailScreen extends Component {
const
{
data
}
=
this
.
state
;
const
{
data
}
=
this
.
state
;
return
(
return
(
<
Content
style
=
{[
theme
.
container
,
theme
.
containerWithPadding
]}
>
<
Content
style
=
{[
theme
.
container
,
theme
.
containerWithPadding
]}
>
{
/* Main Breaker */
}
{
this
.
renderMainDatailsCard
()}
<
Card
style
=
{[
theme
.
containerWithPadding
,
{
borderRadius
:
10
}]}
>
{
/* <FlatList
<
Row
>
<
Left
>
<
Text
style
=
{[
theme
.
smallTitle
,
{
color
:
color
.
darkGrey
}]}
>
{
data
.
name
}
<
/Text
>
<
/Left
>
<
Right
>
<
Switch
value
=
{
data
.
switch
}
/
>
<
/Right
>
<
/Row
>
<
Text
style
=
{[
theme
.
description
,
theme
.
mt1
]}
>
{
data
.
description
}
<
/Text
>
<
Row
style
=
{
theme
.
mt1
}
>
<
Text
style
=
{[
theme
.
description
,
theme
.
textDark
,
{
marginRight
:
5
}]}
>
Status
:{
' '
}
<
Text
style
=
{[
theme
.
description
,
{
color
:
MainBreaker
.
status
?
color
.
success
:
color
.
primary
},
]}
>
{
MainBreaker
.
status
?
'Online'
:
'Offline'
}
<
/Text
>
<
/Text
>
<
Text
style
=
{[
theme
.
description
,
theme
.
textDark
]}
>
RCBO
:
<
Text
style
=
{[
theme
.
description
,
{
color
:
color
.
primary
}]}
>
{
data
.
rcbo
}
mA
<
/Text
>
<
/Text
>
<
/Row
>
<
/Card
>
{
/* Electric Current */
}
<
FlatList
data={this.formatGridData(MainBreaker.Ecurrent)}
data={this.formatGridData(MainBreaker.Ecurrent)}
renderItem={({ item, index }) => {
renderItem={({ item, index }) => {
if (item.name == 'empty') {
if (item.name == 'empty') {
...
@@ -263,7 +214,7 @@ class SmartMeterDetailScreen extends Component {
...
@@ -263,7 +214,7 @@ class SmartMeterDetailScreen extends Component {
keyExtractor={(item, index) => index.toString()}
keyExtractor={(item, index) => index.toString()}
style={{ paddingTop: 20 }}
style={{ paddingTop: 20 }}
/>
/>
{
/* MCB Link */
}
<Card style={{ borderRadius: 8, overflow: 'hidden', marginTop: 20, marginBottom: 40 }}>
<Card style={{ borderRadius: 8, overflow: 'hidden', marginTop: 20, marginBottom: 40 }}>
<FlatList
<FlatList
data={[]}
data={[]}
...
@@ -271,7 +222,7 @@ class SmartMeterDetailScreen extends Component {
...
@@ -271,7 +222,7 @@ class SmartMeterDetailScreen extends Component {
ListEmptyComponent={() => <Text style={[{ padding: 10 }, theme.normalText]}>No MCB Link</Text>}
ListEmptyComponent={() => <Text style={[{ padding: 10 }, theme.normalText]}>No MCB Link</Text>}
/>
/>
</Card>
</Card>
<
Footer
style
=
{{
backgroundColor
:
'transparent'
,
borderColor
:
'transparent'
}}
/
>
<Footer style={{ backgroundColor: 'transparent', borderColor: 'transparent' }} />
*/
}
<
/Content
>
<
/Content
>
);
);
}
}
...
@@ -279,17 +230,20 @@ class SmartMeterDetailScreen extends Component {
...
@@ -279,17 +230,20 @@ class SmartMeterDetailScreen extends Component {
const
mapStateToProps
=
state
=>
({
const
mapStateToProps
=
state
=>
({
allMainDeviceInfo
:
state
.
allMainDeviceReducer
.
allMainDeviceInfo
,
allMainDeviceInfo
:
state
.
allMainDeviceReducer
.
allMainDeviceInfo
,
currentSelectedData
:
state
.
currentSelectedDeviceReducer
.
currentSelectedData
,
selectedDeviceId
:
state
.
currentSelectedDeviceReducer
.
selectedDeviceId
,
selectedDeviceId
:
state
.
currentSelectedDeviceReducer
.
selectedDeviceId
,
});
});
const
mapDispatchToProps
=
{
const
mapDispatchToProps
=
{
setCurrentSelected
,
setCurrentSelected
,
getCurrentSelectedData
,
};
};
export
default
connect
(
export
default
connect
(
mapStateToProps
,
mapStateToProps
,
mapDispatchToProps
mapDispatchToProps
)(
SmartMeterDetailScreen
);
)(
SmartMeterDetailScreen
);
const
styles
=
StyleSheet
.
create
({
const
styles
=
StyleSheet
.
create
({
currentCard
:
{
currentCard
:
{
flex
:
1
,
flex
:
1
,
...
...
screens/Private/SmartMeterScreen/SmartMeterScreen.js
View file @
8d82acd1
...
@@ -47,8 +47,15 @@ class SmartMeterScreen extends PureComponent {
...
@@ -47,8 +47,15 @@ class SmartMeterScreen extends PureComponent {
isOn
=
{
item
.
isOn
||
false
}
isOn
=
{
item
.
isOn
||
false
}
onPressEachCard
=
{()
=>
{
onPressEachCard
=
{()
=>
{
this
.
props
.
navigation
.
navigate
(
'SmartMeterDetail'
,
{
this
.
props
.
navigation
.
navigate
(
'SmartMeterDetail'
,
{
name
:
item
.
name
||
''
,
currentSelectedDeviceData
:
{
deviceId
:
item
.
deviceId
,
deviceId
:
item
.
deviceId
,
name
:
item
.
name
,
description
:
item
.
description
,
isSharing
:
item
.
isSharing
,
notification
:
item
.
notification
,
rcbo
:
item
.
rcbo
,
type
:
item
.
type
,
},
});
});
}}
}}
/
>
/
>
...
...
screens/Private/TimerScreen/TimerScreen.andriod.js
View file @
8d82acd1
...
@@ -144,13 +144,15 @@ class TimerScreen extends PureComponent {
...
@@ -144,13 +144,15 @@ class TimerScreen extends PureComponent {
const
{
isEditVisible
}
=
this
.
props
;
const
{
isEditVisible
}
=
this
.
props
;
// fixed year mouth date secound So we can focus on hour and minute and can sort with timestamp
// fixed year mouth date secound So we can focus on hour and minute and can sort with timestamp
let
saveTimer
=
new
Date
(
this
.
state
.
timer
)
;
let
saveTimer
=
this
.
state
.
timer
;
saveTimer
.
setFullYear
(
2019
);
saveTimer
.
setFullYear
(
2019
);
saveTimer
.
setMonth
(
0
);
saveTimer
.
setMonth
(
0
);
saveTimer
.
setDate
(
0
);
saveTimer
.
setDate
(
0
);
saveTimer
.
setSeconds
(
0
);
saveTimer
.
setSeconds
(
0
);
const
timerData
=
{
console
.
log
(
'saveTimer'
,
saveTimer
);
let
timerData
=
{
isActive
:
this
.
state
.
isActive
,
isActive
:
this
.
state
.
isActive
,
isPowerOn
:
this
.
state
.
isPowerOn
,
isPowerOn
:
this
.
state
.
isPowerOn
,
timer
:
Number
(
saveTimer
),
timer
:
Number
(
saveTimer
),
...
@@ -163,12 +165,12 @@ class TimerScreen extends PureComponent {
...
@@ -163,12 +165,12 @@ class TimerScreen extends PureComponent {
if
(
isCreated
)
{
if
(
isCreated
)
{
this
.
resetStateAndProps
();
this
.
resetStateAndProps
();
this
.
props
.
getTimers
();
//
this.props.getTimers();
}
}
}
else
if
(
selectedBreaker
&&
selectedSubBreaker
)
{
}
else
if
(
selectedBreaker
&&
selectedSubBreaker
)
{
await
this
.
props
.
createNewTimer
(
selectedBreaker
,
selectedSubBreaker
.
id
,
timerData
);
await
this
.
props
.
createNewTimer
(
selectedBreaker
,
selectedSubBreaker
.
id
,
timerData
);
this
.
resetStateAndProps
();
this
.
resetStateAndProps
();
this
.
props
.
getTimers
();
//
this.props.getTimers();
}
else
{
}
else
{
alert
(
'please select (Sub) Breaker'
);
alert
(
'please select (Sub) Breaker'
);
}
}
...
@@ -176,7 +178,7 @@ class TimerScreen extends PureComponent {
...
@@ -176,7 +178,7 @@ class TimerScreen extends PureComponent {
this
.
props
.
editTimer
(
timerData
);
this
.
props
.
editTimer
(
timerData
);
this
.
resetStateAndProps
();
this
.
resetStateAndProps
();
this
.
props
.
setEditModalVisible
(
false
);
this
.
props
.
setEditModalVisible
(
false
);
this
.
props
.
getTimers
();
//
this.props.getTimers();
}
}
};
};
...
@@ -254,7 +256,7 @@ class TimerScreen extends PureComponent {
...
@@ -254,7 +256,7 @@ class TimerScreen extends PureComponent {
this
.
props
.
deleteTimer
(
selectedTimerData
);
this
.
props
.
deleteTimer
(
selectedTimerData
);
await
this
.
resetStateAndProps
();
await
this
.
resetStateAndProps
();
this
.
props
.
setEditModalVisible
(
false
);
this
.
props
.
setEditModalVisible
(
false
);
await
this
.
props
.
getTimers
();
//
await this.props.getTimers();
}}
}}
/
>
/
>
)}
)}
...
@@ -265,7 +267,10 @@ class TimerScreen extends PureComponent {
...
@@ -265,7 +267,10 @@ class TimerScreen extends PureComponent {
<
DatePicker
<
DatePicker
date
=
{
this
.
state
.
timer
}
date
=
{
this
.
state
.
timer
}
onDateChange
=
{
date
=>
this
.
setState
({
timer
:
date
})}
onDateChange
=
{
date
=>
{
this
.
setState
({
timer
:
date
});
console
.
log
(
date
);
}}
mode
=
"time"
mode
=
"time"
locale
=
"fr"
locale
=
"fr"
style
=
{{
height
:
100
,
display
:
'flex'
,
alignSelf
:
'center'
}}
style
=
{{
height
:
100
,
display
:
'flex'
,
alignSelf
:
'center'
}}
...
@@ -425,7 +430,7 @@ class TimerScreen extends PureComponent {
...
@@ -425,7 +430,7 @@ class TimerScreen extends PureComponent {
<
FlatList
<
FlatList
contentContainerStyle
=
{{
paddingBottom
:
isIphoneX
()
?
90
:
55
}}
contentContainerStyle
=
{{
paddingBottom
:
isIphoneX
()
?
90
:
55
}}
data
=
{
this
.
props
.
allTimers
}
data
=
{
this
.
props
.
allTimers
}
// extraData={this.props.allTimer
s}
extraData
=
{
this
.
prop
s
}
refreshing
=
{
this
.
props
.
isLoading
}
refreshing
=
{
this
.
props
.
isLoading
}
onRefresh
=
{
this
.
props
.
getTimers
}
onRefresh
=
{
this
.
props
.
getTimers
}
ListEmptyComponent
=
{()
=>
(
ListEmptyComponent
=
{()
=>
(
...
...
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