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
8d120271
Commit
8d120271
authored
Sep 13, 2019
by
HaOuiha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
bf95de6e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
17 deletions
+99
-17
components/MeterCard.js
+6
-4
reduxStore/actions/currentSelectedAction.js
+7
-3
reduxStore/actions/timersAction.js
+75
-6
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+8
-4
screens/Private/TimerScreen/TimerScreen.js
+3
-0
No files found.
components/MeterCard.js
View file @
8d120271
...
@@ -10,15 +10,17 @@ class MeterCard extends Component {
...
@@ -10,15 +10,17 @@ class MeterCard extends Component {
state
=
{
state
=
{
isPowerOn
:
false
,
isPowerOn
:
false
,
};
};
getShadow
=
async
()
=>
{
getShadow
=
()
=>
{
const
deviceId
=
this
.
props
.
item
.
deviceId
;
const
deviceId
=
this
.
props
.
item
.
deviceId
;
await
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
};
};
componentDidMount
=
async
()
=>
{
componentDidMount
=
async
()
=>
{
await
this
.
getShadow
();
console
.
log
(
'meter props'
,
this
.
props
);
console
.
log
(
'meter props'
,
this
.
props
);
};
};
componentDidUpdate
=
async
(
prevProps
,
prevState
)
=>
{
componentDidUpdate
=
async
(
prevProps
,
prevState
)
=>
{
if
(
prevProps
.
item
!==
this
.
props
.
item
)
{
this
.
getShadow
();
}
if
(
prevProps
.
shadow
!==
this
.
props
.
shadow
)
{
if
(
prevProps
.
shadow
!==
this
.
props
.
shadow
)
{
await
this
.
setInitState
();
await
this
.
setInitState
();
}
}
...
@@ -30,7 +32,7 @@ class MeterCard extends Component {
...
@@ -30,7 +32,7 @@ class MeterCard extends Component {
});
});
};
};
render
()
{
render
()
{
const
item
=
this
.
props
.
item
;
const
{
item
}
=
this
.
props
;
const
{
isPowerOn
}
=
this
.
state
;
const
{
isPowerOn
}
=
this
.
state
;
return
Platform
.
OS
===
'android'
?
(
return
Platform
.
OS
===
'android'
?
(
<
BaseButton
onPress
=
{
this
.
props
.
onPressEachCard
}
rippleColor
=
{
'#fcc5c5'
}
style
=
{
styles
.
cardContainer
}
>
<
BaseButton
onPress
=
{
this
.
props
.
onPressEachCard
}
rippleColor
=
{
'#fcc5c5'
}
style
=
{
styles
.
cardContainer
}
>
...
...
reduxStore/actions/currentSelectedAction.js
View file @
8d120271
import
app
,
{
fireStore
}
from
'../../firebase'
;
import
app
,
{
fireStore
}
from
'../../firebase'
;
import
axios
from
'axios'
;
import
axios
from
'axios'
;
import
qs
from
'qs'
;
const
baseURL
=
'https://us-central1-safetcut-20cdf.cloudfunctions.net'
;
const
baseURL
=
'https://us-central1-safetcut-20cdf.cloudfunctions.net'
;
...
@@ -30,8 +29,12 @@ export const getCurrentSelectedShadowAction = shadow => ({
...
@@ -30,8 +29,12 @@ export const getCurrentSelectedShadowAction = shadow => ({
shadow
,
shadow
,
});
});
export
const
getCurrentSelectedShadow
=
deviceId
=>
async
dispatch
=>
{
export
const
getCurrentSelectedShadow
=
()
=>
async
(
dispatch
,
getState
)
=>
{
const
URL
=
`
${
baseURL
}
/shadow/
${
deviceId
}
`
;
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
URL
=
`
${
baseURL
}
/shadow/
${
selectedDeviceId
}
`
;
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
options
=
{
const
options
=
{
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
...
@@ -72,6 +75,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
...
@@ -72,6 +75,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
//cut deviceId
const
{
deviceId
,
...
currentSelectedMainData
}
=
currentSelectedData
;
const
{
deviceId
,
...
currentSelectedMainData
}
=
currentSelectedData
;
const
getNewData
=
()
=>
{
const
getNewData
=
()
=>
{
...
...
reduxStore/actions/timersAction.js
View file @
8d120271
import
{
fireStore
}
from
'../../firebase'
;
import
app
,
{
fireStore
}
from
'../../firebase'
;
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
axios
from
'axios'
;
import
moment
from
'moment'
;
const
baseURL
=
'https://us-central1-safetcut-20cdf.cloudfunctions.net'
;
export
const
GET_TIMERS
=
'GET_TIMERS'
;
export
const
GET_TIMERS
=
'GET_TIMERS'
;
export
const
GET_TIMERS_LOADING
=
'GET_TIMERS_LOADING'
;
export
const
GET_TIMERS_LOADING
=
'GET_TIMERS_LOADING'
;
...
@@ -39,7 +43,7 @@ export const loadingTimersAction = bool => ({
...
@@ -39,7 +43,7 @@ export const loadingTimersAction = bool => ({
isLoading
:
bool
,
isLoading
:
bool
,
});
});
export
const
errorAction
=
error
=>
({
export
const
error
Timers
Action
=
error
=>
({
type
:
GET_TIMERS_ERROR
,
type
:
GET_TIMERS_ERROR
,
error
,
error
,
});
});
...
@@ -161,7 +165,7 @@ export const getTimers = () => async (dispatch, getState) => {
...
@@ -161,7 +165,7 @@ export const getTimers = () => async (dispatch, getState) => {
allTimersData
=
[...
mainDeviceTimers
,
...
subBreakersTimers
];
allTimersData
=
[...
mainDeviceTimers
,
...
subBreakersTimers
];
dispatch
(
getTimersAction
(
allTimersData
));
dispatch
(
getTimersAction
(
allTimersData
));
}
catch
(
error
)
{
}
catch
(
error
)
{
dispatch
(
errorAction
(
error
.
message
||
error
||
'Error'
));
dispatch
(
error
Timers
Action
(
error
.
message
||
error
||
'Error'
));
}
}
dispatch
(
loadingTimersAction
(
false
));
dispatch
(
loadingTimersAction
(
false
));
};
};
...
@@ -223,7 +227,8 @@ export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (d
...
@@ -223,7 +227,8 @@ export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (d
const
docRef
=
getDocRef
();
const
docRef
=
getDocRef
();
const
currentNumTimers
=
countingTimers
();
const
currentNumTimers
=
countingTimers
();
if
(
currentNumTimers
<
5
)
{
// limit timers
if
(
currentNumTimers
<
6
)
{
const
resRef
=
await
docRef
.
add
(
settingTime
);
const
resRef
=
await
docRef
.
add
(
settingTime
);
//assign more timers details
//assign more timers details
...
@@ -373,6 +378,70 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -373,6 +378,70 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
}
}
};
};
export
const
writeTimersToShadow
=
()
=>
async
(
dispatch
,
getState
)
=>
{
const
{
currentSelectedDeviceReducer
,
timersReducer
}
=
getState
();
const
{
allTimers
}
=
timersReducer
;
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
URL
=
`
${
baseURL
}
/shadow/
${
selectedDeviceId
}
`
;
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
groupTypeData
=
_
.
groupBy
(
allTimers
,
'type'
);
const
tempSubBreakerTimersData
=
_
.
groupBy
(
groupTypeData
.
subBreaker
,
tempSubBreakerTimersData
=>
'L'
+
tempSubBreakerTimersData
.
mcbLinkId
+
'B'
+
tempSubBreakerTimersData
.
subBreakerId
+
'T'
);
const
tempMainBreakerTimersData
=
{
MAB1T
:
groupTypeData
.
main
};
console
.
log
(
'mainBreakerTimersData'
,
mainBreakerTimersData
);
console
.
log
(
'tempSubBreakerTimersData'
,
tempSubBreakerTimersData
);
//convert Timer to shadow format
const
mainBreakerTimersData
=
tempMainBreakerTimersData
.
MAB1T
.
map
((
timer
,
index
)
=>
{
const
isActive
=
timer
.
isActive
?
'1'
:
'0'
;
const
isPowerOn
=
timer
.
isPowerOn
?
'1'
:
'0'
;
const
repeatOn
=
()
=>
{
let
binaryFormat
=
timer
.
repeatOn
.
map
(
item
=>
{
return
item
.
isRepeat
?
+
'1'
:
+
'0'
;
})
.
toString
()
.
replace
(
/
\,
/g
,
''
);
const
decimalFormat
=
parseInt
(
Number
(
binaryFormat
),
2
);
return
decimalFormat
;
};
const
hour
=
moment
(
timer
.
timer
).
format
(
'HH'
);
const
minute
=
moment
(
timer
.
timer
).
format
(
'mm'
);
console
.
log
({
[
`T
${
index
+
1
}
`
]:
`
${
isActive
}
,
${
isPowerOn
}
,
${
repeatOn
()}
,
${
hour
}
,
${
minute
}
`
});
const
writingData
=
{
[
`T
${
index
+
1
}
`
]:
`
${
isActive
}
,
${
isPowerOn
}
,
${
repeatOn
()}
,
${
hour
}
,
${
minute
}
`
};
return
writingData
;
});
console
.
log
(
mainBreakerTimersData
[
0
]);
const
data
=
{
data
:
{
L1B1T
:
{
T1
:
'1,1,127,8,0'
}
}
};
const
options
=
{
method
:
'PUT'
,
headers
:
{
Authorization
:
`Token
${
idToken
}
`
,
'content-Type'
:
'text/plain'
},
url
:
URL
,
data
:
JSON
.
stringify
(
data
).
replace
(
/
\"
/g
,
''
),
};
try
{
// const response = await axios(options);
// console.log(response);
}
catch
(
error
)
{
console
.
log
(
error
);
}
};
// export const deleteTimer2 = selectedData => async (dispatch, getState) => {
// export const deleteTimer2 = selectedData => async (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
// const { selectedDeviceId } = currentSelectedDeviceReducer;
...
@@ -511,7 +580,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -511,7 +580,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// dispatch(getTimersAction(allTimersData));
// dispatch(getTimersAction(allTimersData));
// } catch (error) {
// } catch (error) {
// dispatch(errorAction(error.message || error || 'Error'));
// dispatch(error
Timers
Action(error.message || error || 'Error'));
// }
// }
// dispatch(loadingTimersAction(false));
// dispatch(loadingTimersAction(false));
// };
// };
...
@@ -564,7 +633,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
...
@@ -564,7 +633,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// dispatch(getTimersAction(allTimersData));
// dispatch(getTimersAction(allTimersData));
// dispatch(loadingTimersAction(false));
// dispatch(loadingTimersAction(false));
// } catch (error) {
// } catch (error) {
// dispatch(errorAction(error.message || error || 'Error'));
// dispatch(error
Timers
Action(error.message || error || 'Error'));
// dispatch(loadingTimersAction(false));
// dispatch(loadingTimersAction(false));
// }
// }
// };
// };
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
8d120271
...
@@ -10,7 +10,7 @@ import {
...
@@ -10,7 +10,7 @@ import {
loadingAction
,
loadingAction
,
setMainStatus
,
setMainStatus
,
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
import
{
getTimers
,
loadingTimersAction
}
from
'../../../reduxStore/actions/timersAction'
;
import
{
getTimers
,
loadingTimersAction
,
errorTimersAction
}
from
'../../../reduxStore/actions/timersAction'
;
import
{
isIphoneX
}
from
'../../../utils/isPhoneX'
;
import
{
isIphoneX
}
from
'../../../utils/isPhoneX'
;
import
{
withNavigationFocus
}
from
'react-navigation'
;
import
{
withNavigationFocus
}
from
'react-navigation'
;
...
@@ -85,7 +85,7 @@ class SmartMeterDetailScreen extends Component {
...
@@ -85,7 +85,7 @@ class SmartMeterDetailScreen extends Component {
await
this
.
props
.
setMainStatus
(
value
);
await
this
.
props
.
setMainStatus
(
value
);
let
test
=
setInterval
(()
=>
{
let
test
=
setInterval
(()
=>
{
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
this
.
props
.
getCurrentSelectedShadow
();
console
.
log
(
'getShadow'
);
console
.
log
(
'getShadow'
);
},
2000
);
},
2000
);
...
@@ -108,7 +108,7 @@ class SmartMeterDetailScreen extends Component {
...
@@ -108,7 +108,7 @@ class SmartMeterDetailScreen extends Component {
componentWillUnmount
=
()
=>
{
componentWillUnmount
=
()
=>
{
this
.
_mcbLinksListMounted
=
false
;
this
.
_mcbLinksListMounted
=
false
;
//reset new loading to redux fix blink screen
//reset new loading to redux
;
fix blink screen
this
.
props
.
loadingAction
(
true
);
this
.
props
.
loadingAction
(
true
);
this
.
props
.
loadingTimersAction
(
true
);
this
.
props
.
loadingTimersAction
(
true
);
};
};
...
@@ -304,7 +304,10 @@ class SmartMeterDetailScreen extends Component {
...
@@ -304,7 +304,10 @@ class SmartMeterDetailScreen extends Component {
refreshControl
=
{
refreshControl
=
{
<
RefreshControl
<
RefreshControl
refreshing
=
{
this
.
_mcbLinksListMounted
&&
(
isLoadingList
||
isLoadingValues
)}
refreshing
=
{
this
.
_mcbLinksListMounted
&&
(
isLoadingList
||
isLoadingValues
)}
onRefresh
=
{
async
()
=>
await
this
.
getData
()}
onRefresh
=
{
async
()
=>
{
await
this
.
getData
();
this
.
props
.
errorTimersAction
(
null
);
}}
title
=
"Pull to refresh"
title
=
"Pull to refresh"
tintColor
=
{
color
.
primary
}
tintColor
=
{
color
.
primary
}
titleColor
=
{
color
.
darkGrey
}
titleColor
=
{
color
.
darkGrey
}
...
@@ -374,6 +377,7 @@ const mapDispatchToProps = {
...
@@ -374,6 +377,7 @@ const mapDispatchToProps = {
loadingTimersAction
,
loadingTimersAction
,
getTimers
,
getTimers
,
setMainStatus
,
setMainStatus
,
errorTimersAction
,
};
};
const
withNavSmartMeterDetailScreen
=
withNavigationFocus
(
SmartMeterDetailScreen
);
const
withNavSmartMeterDetailScreen
=
withNavigationFocus
(
SmartMeterDetailScreen
);
...
...
screens/Private/TimerScreen/TimerScreen.js
View file @
8d120271
...
@@ -25,6 +25,7 @@ import {
...
@@ -25,6 +25,7 @@ import {
createNewTimer
,
createNewTimer
,
editTimer
,
editTimer
,
deleteTimer
,
deleteTimer
,
writeTimersToShadow
,
}
from
'../../../reduxStore/actions/timersAction'
;
}
from
'../../../reduxStore/actions/timersAction'
;
import
Modal
from
'react-native-modalbox'
;
import
Modal
from
'react-native-modalbox'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
...
@@ -250,6 +251,7 @@ class TimerScreen extends PureComponent {
...
@@ -250,6 +251,7 @@ class TimerScreen extends PureComponent {
selectedSubBreaker
:
null
,
selectedSubBreaker
:
null
,
});
});
}
}
this
.
props
.
writeTimersToShadow
();
}
}
if
(
prevProps
.
existedMcbLinksData
!==
this
.
props
.
existedMcbLinksData
)
{
if
(
prevProps
.
existedMcbLinksData
!==
this
.
props
.
existedMcbLinksData
)
{
this
.
setPickerSelectData
();
this
.
setPickerSelectData
();
...
@@ -712,6 +714,7 @@ const mapDispatchToProps = {
...
@@ -712,6 +714,7 @@ const mapDispatchToProps = {
createNewTimer
,
createNewTimer
,
editTimer
,
editTimer
,
deleteTimer
,
deleteTimer
,
writeTimersToShadow
,
};
};
export
default
connect
(
export
default
connect
(
...
...
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