Skip to content

Commit

Permalink
[TASK] add consoleView
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed May 30, 2017
1 parent 6046e7d commit 2e5873a
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 16 deletions.
14 changes: 7 additions & 7 deletions ssh/list.go
Expand Up @@ -7,15 +7,15 @@ import (
)

type List struct {
cmd string
Clients map[string]*ListResult
cmd string `json:"cmd"`
Clients map[string]*ListResult `json:"clients"`
sshManager *Manager
}
type ListResult struct {
ssh *ssh.Client
Runned bool
WithError bool
Result string
Running bool `json:"running"`
WithError bool `json:"with_error"`
Result string `json:"result"`
}

func (m *Manager) CreateList(cmd string) *List {
Expand All @@ -25,7 +25,7 @@ func (m *Manager) CreateList(cmd string) *List {
Clients: make(map[string]*ListResult),
}
for host, client := range m.clients {
list.Clients[host] = &ListResult{Runned: false, ssh: client}
list.Clients[host] = &ListResult{Running: true, ssh: client}
}
return list
}
Expand All @@ -43,7 +43,7 @@ func (l List) Run() {
func (l List) runlistelement(host string, client *ListResult, wg *sync.WaitGroup) {
defer wg.Done()
result, err := l.sshManager.run(host, client.ssh, l.cmd)
client.Runned = true
client.Running = false
if err != nil {
client.WithError = true
return
Expand Down
8 changes: 4 additions & 4 deletions ssh/list_test.go
Expand Up @@ -19,18 +19,18 @@ func TestList(t *testing.T) {
list := mgmt.CreateList("exit 1")
assert.Len(list.Clients, 1)
client := list.Clients[addr.IP.String()]
assert.False(client.Runned)
assert.True(client.Running)
list.Run()
assert.True(client.Runned)
assert.False(client.Running)
assert.True(client.WithError)
assert.Equal("", client.Result)

list = mgmt.CreateList("echo 15")
assert.Len(list.Clients, 1)
client = list.Clients[addr.IP.String()]
assert.False(client.Runned)
assert.True(client.Running)
list.Run()
assert.True(client.Runned)
assert.False(client.Running)
assert.False(client.WithError)
assert.Equal("15", client.Result)
}
36 changes: 36 additions & 0 deletions webroot/css/console.css
@@ -0,0 +1,36 @@
.prompt {
position: fixed;
bottom: 0px;
background-color: #ccc;
width: 100%;
}
.prompt .btn {
width: 10%;
}
.prompt input {
width: 85%;
margin-left: 2%;
}
.console {
font-family: monospace;
white-space: pre;
}
.console .cmd {
min-height: 22px;
clear: both;
}
.console .cmd > .time, .console .cmd .host{
display: inline-block;
color: #009ee0;

width: 15%;
}
.console .cmd > div {
clear: both;
background-color: #ccc;
margin-bottom: 3px;
}
.console .cmd .status {
width: 15%;
height: 20px;
}
6 changes: 4 additions & 2 deletions webroot/css/main.css
Expand Up @@ -9,14 +9,16 @@ body {
.status {
float: right;
background: #009ee0;
color: white;
width: 50px;
height: 50px;
}
.status.connecting {
.status.connecting,.status.running {
background: #ffb400;
}
.status.offline {
.status.offline, .status.failed {
background: #dc0067;
color: white;
}
span.online {
color: #009ee0;
Expand Down
2 changes: 2 additions & 0 deletions webroot/index.html
Expand Up @@ -7,6 +7,7 @@
<link rel="stylesheet" href="/css/leaflet.css">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/css/map.css">
<link rel="stylesheet" href="/css/console.css">
<script src="/js/moment.js"></script>
<script src="/js/navigo.js"></script>
<script src="/js/leaflet.js"></script>
Expand All @@ -17,6 +18,7 @@
<script src="/js/domlib.js"></script>
<script src="/js/store.js"></script>
<script src="/js/notify.js"></script>
<script src="/js/gui_console.js"></script>
<script src="/js/gui_list.js"></script>
<script src="/js/gui_map.js"></script>
<script src="/js/gui_node.js"></script>
Expand Down
6 changes: 5 additions & 1 deletion webroot/js/gui.js
@@ -1,5 +1,5 @@
/* exported gui,router */
/* globals socket,notify,domlib,guiList,guiMap,guiStats,guiNode */
/* globals socket,notify,domlib,guiList,guiMap,guiStats,guiNode,guiConsole */

const gui = {},
router = new Navigo(null, true, '#');
Expand Down Expand Up @@ -58,6 +58,9 @@ const gui = {},
}

router.on({
'/console': function routerConsole () {
setView(guiConsole);
},
'/list': function routerList () {
setView(guiList);
},
Expand All @@ -75,6 +78,7 @@ const gui = {},
'/statistics': function routerStats () {
setView(guiStats);
}

});
router.on(() => {
router.navigate('/list');
Expand Down

0 comments on commit 2e5873a

Please sign in to comment.