Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
0x4A6F
FFS Gluon
Commits
9b46a05d
Commit
9b46a05d
authored
Oct 26, 2015
by
Matthias Schiffer
Browse files
Options
Downloads
Plain Diff
Merge pull request #450 from freifunk-gluon/status-page
gluon-status-page: new status page
parents
557a073d
5e5dc5ab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
package/gluon-status-page/src/js/main.js
+108
-0
108 additions, 0 deletions
package/gluon-status-page/src/js/main.js
with
108 additions
and
0 deletions
package/gluon-status-page/src/js/main.js
0 → 100644
+
108
−
0
View file @
9b46a05d
"
use strict
"
require
([
"
bacon
"
,
"
lib/helper
"
,
"
lib/streams
"
,
"
lib/gui
"
],
function
(
Bacon
,
Helper
,
Streams
,
GUI
)
{
var
mgmtBus
=
new
Bacon
.
Bus
()
mgmtBus
.
pushEvent
=
function
(
key
,
a
)
{
var
v
=
[
key
].
concat
(
a
)
return
this
.
push
(
v
)
}
mgmtBus
.
onEvent
=
function
(
events
)
{
return
this
.
onValue
(
function
(
e
)
{
var
d
=
e
.
slice
()
// shallow copy so calling shift doesn't change it
var
ev
=
d
.
shift
()
if
(
ev
in
events
)
events
[
ev
].
apply
(
this
,
d
)
})
}
var
nodesBusIn
=
new
Bacon
.
Bus
()
var
nodesBus
=
nodesBusIn
.
scan
({
"
nodes
"
:
{}
,
"
macs
"
:
{}
},
scanNodeInfo
)
new
GUI
(
mgmtBus
,
nodesBus
)
mgmtBus
.
onEvent
({
"
goto
"
:
gotoNode
,
"
nodeinfo
"
:
function
(
d
)
{
nodesBusIn
.
push
(
d
)
}
})
function
tryIp
(
ip
)
{
return
Helper
.
request
(
ip
,
"
nodeinfo
"
).
map
(
function
()
{
return
ip
})
}
var
gotoEpoch
=
0
function
onEpoch
(
epoch
,
f
)
{
return
function
(
d
)
{
if
(
epoch
===
gotoEpoch
)
return
f
(
d
)
}
}
function
gotoNode
(
nodeInfo
)
{
gotoEpoch
++
var
addresses
=
nodeInfo
.
network
.
addresses
.
filter
(
function
(
d
)
{
return
!
/^fe80:/
.
test
(
d
)
})
var
race
=
Bacon
.
fromArray
(
addresses
).
flatMap
(
tryIp
).
withStateMachine
([],
function
(
acc
,
ev
)
{
if
(
ev
.
isError
())
return
[
acc
.
concat
(
ev
.
error
),
[]]
else
if
(
ev
.
isEnd
()
&&
acc
.
length
>
0
)
return
[
undefined
,
[
new
Bacon
.
Error
(
acc
),
ev
]]
else
if
(
ev
.
hasValue
())
return
[[],
[
ev
,
new
Bacon
.
End
()]]
})
race
.
onValue
(
onEpoch
(
gotoEpoch
,
function
(
d
)
{
mgmtBus
.
pushEvent
(
"
arrived
"
,
[
nodeInfo
,
d
])
}))
race
.
onError
(
onEpoch
(
gotoEpoch
,
function
()
{
mgmtBus
.
pushEvent
(
"
gotoFailed
"
,
nodeInfo
)
}))
}
function
scanNodeInfo
(
a
,
nodeInfo
)
{
a
.
nodes
[
nodeInfo
.
node_id
]
=
nodeInfo
var
mesh
=
Helper
.
dictGet
(
nodeInfo
,
[
"
network
"
,
"
mesh
"
])
if
(
mesh
)
for
(
var
m
in
mesh
)
for
(
var
ifname
in
mesh
[
m
].
interfaces
)
mesh
[
m
].
interfaces
[
ifname
].
forEach
(
function
(
d
)
{
a
.
macs
[
d
]
=
nodeInfo
})
return
a
}
if
(
localStorage
.
nodes
)
JSON
.
parse
(
localStorage
.
nodes
).
forEach
(
nodesBusIn
.
push
)
nodesBus
.
map
(
"
.nodes
"
).
onValue
(
function
(
nodes
)
{
var
out
=
[]
for
(
var
k
in
nodes
)
out
.
push
(
nodes
[
k
])
localStorage
.
nodes
=
JSON
.
stringify
(
out
)
})
var
bootstrap
=
Helper
.
getJSON
(
bootstrapUrl
)
bootstrap
.
onError
(
function
()
{
console
.
log
(
"
FIXME bootstrapping failed
"
)
})
bootstrap
.
onValue
(
function
(
d
)
{
mgmtBus
.
pushEvent
(
"
nodeinfo
"
,
d
)
mgmtBus
.
pushEvent
(
"
goto
"
,
d
)
})
})
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment