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 {
state
=
{
isPowerOn
:
false
,
};
getShadow
=
async
()
=>
{
getShadow
=
()
=>
{
const
deviceId
=
this
.
props
.
item
.
deviceId
;
await
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
};
componentDidMount
=
async
()
=>
{
await
this
.
getShadow
();
console
.
log
(
'meter props'
,
this
.
props
);
};
componentDidUpdate
=
async
(
prevProps
,
prevState
)
=>
{
if
(
prevProps
.
item
!==
this
.
props
.
item
)
{
this
.
getShadow
();
}
if
(
prevProps
.
shadow
!==
this
.
props
.
shadow
)
{
await
this
.
setInitState
();
}
...
...
@@ -30,7 +32,7 @@ class MeterCard extends Component {
});
};
render
()
{
const
item
=
this
.
props
.
item
;
const
{
item
}
=
this
.
props
;
const
{
isPowerOn
}
=
this
.
state
;
return
Platform
.
OS
===
'android'
?
(
<
BaseButton
onPress
=
{
this
.
props
.
onPressEachCard
}
rippleColor
=
{
'#fcc5c5'
}
style
=
{
styles
.
cardContainer
}
>
...
...
reduxStore/actions/currentSelectedAction.js
View file @
8d120271
import
app
,
{
fireStore
}
from
'../../firebase'
;
import
axios
from
'axios'
;
import
qs
from
'qs'
;
const
baseURL
=
'https://us-central1-safetcut-20cdf.cloudfunctions.net'
;
...
...
@@ -30,8 +29,12 @@ export const getCurrentSelectedShadowAction = shadow => ({
shadow
,
});
export
const
getCurrentSelectedShadow
=
deviceId
=>
async
dispatch
=>
{
const
URL
=
`
${
baseURL
}
/shadow/
${
deviceId
}
`
;
export
const
getCurrentSelectedShadow
=
()
=>
async
(
dispatch
,
getState
)
=>
{
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
URL
=
`
${
baseURL
}
/shadow/
${
selectedDeviceId
}
`
;
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
options
=
{
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
...
...
@@ -72,6 +75,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
//cut deviceId
const
{
deviceId
,
...
currentSelectedMainData
}
=
currentSelectedData
;
const
getNewData
=
()
=>
{
...
...
reduxStore/actions/timersAction.js
View file @
8d120271
import
{
fireStore
}
from
'../../firebase'
;
import
app
,
{
fireStore
}
from
'../../firebase'
;
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_LOADING
=
'GET_TIMERS_LOADING'
;
...
...
@@ -39,7 +43,7 @@ export const loadingTimersAction = bool => ({
isLoading
:
bool
,
});
export
const
errorAction
=
error
=>
({
export
const
error
Timers
Action
=
error
=>
({
type
:
GET_TIMERS_ERROR
,
error
,
});
...
...
@@ -161,7 +165,7 @@ export const getTimers = () => async (dispatch, getState) => {
allTimersData
=
[...
mainDeviceTimers
,
...
subBreakersTimers
];
dispatch
(
getTimersAction
(
allTimersData
));
}
catch
(
error
)
{
dispatch
(
errorAction
(
error
.
message
||
error
||
'Error'
));
dispatch
(
error
Timers
Action
(
error
.
message
||
error
||
'Error'
));
}
dispatch
(
loadingTimersAction
(
false
));
};
...
...
@@ -223,7 +227,8 @@ export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (d
const
docRef
=
getDocRef
();
const
currentNumTimers
=
countingTimers
();
if
(
currentNumTimers
<
5
)
{
// limit timers
if
(
currentNumTimers
<
6
)
{
const
resRef
=
await
docRef
.
add
(
settingTime
);
//assign more timers details
...
...
@@ -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) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
...
...
@@ -511,7 +580,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// dispatch(getTimersAction(allTimersData));
// } catch (error) {
// dispatch(errorAction(error.message || error || 'Error'));
// dispatch(error
Timers
Action(error.message || error || 'Error'));
// }
// dispatch(loadingTimersAction(false));
// };
...
...
@@ -564,7 +633,7 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
// dispatch(getTimersAction(allTimersData));
// dispatch(loadingTimersAction(false));
// } catch (error) {
// dispatch(errorAction(error.message || error || 'Error'));
// dispatch(error
Timers
Action(error.message || error || 'Error'));
// dispatch(loadingTimersAction(false));
// }
// };
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
8d120271
...
...
@@ -10,7 +10,7 @@ import {
loadingAction
,
setMainStatus
,
}
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
{
withNavigationFocus
}
from
'react-navigation'
;
...
...
@@ -85,7 +85,7 @@ class SmartMeterDetailScreen extends Component {
await
this
.
props
.
setMainStatus
(
value
);
let
test
=
setInterval
(()
=>
{
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
this
.
props
.
getCurrentSelectedShadow
();
console
.
log
(
'getShadow'
);
},
2000
);
...
...
@@ -108,7 +108,7 @@ class SmartMeterDetailScreen extends Component {
componentWillUnmount
=
()
=>
{
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
.
loadingTimersAction
(
true
);
};
...
...
@@ -304,7 +304,10 @@ class SmartMeterDetailScreen extends Component {
refreshControl
=
{
<
RefreshControl
refreshing
=
{
this
.
_mcbLinksListMounted
&&
(
isLoadingList
||
isLoadingValues
)}
onRefresh
=
{
async
()
=>
await
this
.
getData
()}
onRefresh
=
{
async
()
=>
{
await
this
.
getData
();
this
.
props
.
errorTimersAction
(
null
);
}}
title
=
"Pull to refresh"
tintColor
=
{
color
.
primary
}
titleColor
=
{
color
.
darkGrey
}
...
...
@@ -374,6 +377,7 @@ const mapDispatchToProps = {
loadingTimersAction
,
getTimers
,
setMainStatus
,
errorTimersAction
,
};
const
withNavSmartMeterDetailScreen
=
withNavigationFocus
(
SmartMeterDetailScreen
);
...
...
screens/Private/TimerScreen/TimerScreen.js
View file @
8d120271
...
...
@@ -25,6 +25,7 @@ import {
createNewTimer
,
editTimer
,
deleteTimer
,
writeTimersToShadow
,
}
from
'../../../reduxStore/actions/timersAction'
;
import
Modal
from
'react-native-modalbox'
;
import
moment
from
'moment'
;
...
...
@@ -250,6 +251,7 @@ class TimerScreen extends PureComponent {
selectedSubBreaker
:
null
,
});
}
this
.
props
.
writeTimersToShadow
();
}
if
(
prevProps
.
existedMcbLinksData
!==
this
.
props
.
existedMcbLinksData
)
{
this
.
setPickerSelectData
();
...
...
@@ -712,6 +714,7 @@ const mapDispatchToProps = {
createNewTimer
,
editTimer
,
deleteTimer
,
writeTimersToShadow
,
};
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