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
519c4f0a
Commit
519c4f0a
authored
Sep 20, 2019
by
Tonk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update add new connected device
parent
8ff86ee3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
reduxStore/actions/currentSelectedAction.js
+16
-8
screens/Private/SmartMeterScreen/McbLinkScreen.js
+11
-8
No files found.
reduxStore/actions/currentSelectedAction.js
View file @
519c4f0a
...
...
@@ -252,20 +252,28 @@ export const addConnectedDevice = (mcbLinkId, subBreakerId, deviceData) => async
.
collection
(
'device'
)
.
doc
(
selectedDeviceId
)
.
collection
(
'mcbLinks'
)
.
doc
(
mcbLinkId
)
.
doc
(
String
(
mcbLinkId
)
)
.
collection
(
'subBreakers'
)
.
doc
(
subBreakerId
);
.
doc
(
String
(
subBreakerId
))
.
collection
(
'electronicDevices'
);
return
docRef
;
};
const
newConnectedDevice
=
existedConnectedDevice
.
map
(
x
=>
x
.
index
+
1
===
subBreakerId
&&
[...
x
[
index
],
deviceData
]
);
try
{
const
docRef
=
getDocRef
();
await
docRef
.
add
(
deviceData
);
dispatch
(
getExistedConnectedDeviceAction
(
newConnectedDevice
));
}
catch
(
error
)
{}
const
res
=
await
docRef
.
add
(
deviceData
);
const
newDeviceData
=
Object
.
assign
(
deviceData
,
{
mcbLinkId
:
mcbLinkId
,
subBreakerId
:
subBreakerId
,
connectedDeviceId
:
res
.
id
,
});
let
newAllConnected
=
existedConnectedDevice
.
map
((
x
,
index
)
=>
index
===
(
mcbLinkId
-
1
)
*
8
+
(
subBreakerId
-
1
)
?
[...
x
,
newDeviceData
]
:
[...
x
]
);
dispatch
(
getExistedConnectedDeviceAction
(
newAllConnected
));
}
catch
(
error
)
{
console
.
log
(
error
);
}
};
export
const
deleteConnectedDevice
=
data
=>
async
(
dispatch
,
getState
)
=>
{
const
{
currentSelectedDeviceReducer
,
timersReducer
}
=
getState
();
...
...
screens/Private/SmartMeterScreen/McbLinkScreen.js
View file @
519c4f0a
...
...
@@ -84,10 +84,10 @@ class McbLinkScreen extends React.Component {
this
.
setState
({
subBreakersInfo
:
existedSubBreakersData
[
mcbIndex
],
subBreakerStatus
:
status
});
};
addDevice
=
async
()
=>
{
const
{
deviceName
,
mcbIndex
,
subIndex
}
=
this
.
state
;
const
{
deviceName
,
mcbIndex
,
sub
Breaker
Index
}
=
this
.
state
;
let
deviceData
=
{
name
:
deviceName
};
const
mcbId
=
mcbIndex
+
1
;
const
subId
=
subIndex
+
1
;
const
subId
=
sub
Breaker
Index
+
1
;
await
this
.
props
.
addConnectedDevice
(
mcbId
,
subId
,
deviceData
);
this
.
setState
({
deviceName
:
''
,
isAddElectronicVisible
:
false
});
...
...
@@ -95,8 +95,7 @@ class McbLinkScreen extends React.Component {
formatData
(
item
,
start
,
end
)
{
let
data
=
[];
data
.
push
(...
item
);
//Electronic devices data
data
.
push
({
name
:
'add'
});
data
.
push
(...
item
,
{
name
:
'add'
});
//Electronic devices data
const
numberOfFullRows
=
Math
.
floor
(
data
.
length
/
4
);
let
numberOfElementsLastRow
=
data
.
length
-
numberOfFullRows
*
4
;
while
(
numberOfElementsLastRow
!==
4
&&
numberOfElementsLastRow
!==
0
)
{
...
...
@@ -160,7 +159,11 @@ class McbLinkScreen extends React.Component {
const
{
toggleDel
}
=
this
.
state
;
const
data
=
item
.
connectedDevice
;
const
renderScroll
=
()
=>
{
const
maxPage
=
data
.
length
?
Math
.
ceil
(
data
.
length
/
8
)
:
1
;
const
maxPage
=
data
.
length
?
data
.
length
%
8
===
0
?
Math
.
ceil
(
data
.
length
/
8
)
+
1
:
Math
.
ceil
(
data
.
length
/
8
)
:
1
;
const
scrollPage
=
[];
for
(
let
index
=
0
;
index
<
maxPage
;
index
++
)
{
let
start
=
index
*
8
;
...
...
@@ -285,7 +288,7 @@ class McbLinkScreen extends React.Component {
};
render
()
{
const
subIndex
=
this
.
props
.
navigation
.
getParam
(
'subIndex'
);
const
initialPage
=
this
.
props
.
navigation
.
getParam
(
'subIndex'
);
const
{
subBreakersInfo
}
=
this
.
state
;
const
TabStyle
=
{
textStyle
:
[
theme
.
description
,
theme
.
textWhite
],
...
...
@@ -309,10 +312,10 @@ class McbLinkScreen extends React.Component {
<
Tabs
tabBarUnderlineStyle
=
{{
backgroundColor
:
'transparent'
}}
renderTabBar
=
{()
=>
<
ScrollableTab
style
=
{
styles
.
scrollTab
}
/>
}
initialPage
=
{
subIndex
}
initialPage
=
{
initialPage
}
locked
onChangeTab
=
{
tab
=>
{
this
.
setState
({
subIndex
:
tab
.
i
});
this
.
setState
({
sub
Breaker
Index
:
tab
.
i
});
console
.
log
(
tab
.
i
);
}}
>
...
...
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