Browse Source

start docker backend funcs

luis 7 years ago
parent
commit
657c75e17e

+ 4 - 0
browser/vue-flow/src/assets/default-theme.css

@@ -69,6 +69,10 @@ button.active {
   color: var(--primary-inverse);
 }
 
+.hover {
+  position: relative;
+}
+
 button::after,
 .hover::after {
   background: var(--primary);

+ 6 - 2
browser/vue-flow/src/components/defregistry.js

@@ -21,9 +21,13 @@ export default{
     categories: ['flow-web'],
     inputs: [{type: 'interface {}'}, {type: 'string', name: 'msg'}],
     output: {type: 'interface {}'},
-    style: { color: '#665'}
+    style: {color: '#665'}
+  },
+  'Log': {
+    categories: ['flow-web'],
+    output: {type: 'io.Writer'},
+    style: {color: '#665'}
   }
-
 }
 
 /* {

+ 11 - 6
browser/vue-flow/src/components/flow/manager.vue

@@ -72,10 +72,10 @@
     <hx-context-menu ref="menu">
       <template slot-scope="d" >
         <div class="flow-node__context-menu">
-          <button @click="nodeProcess(d.userData)">Run</button>
-          <button @click="nodeRemove(d.userData)">Delete</button>
+          <div class="hover" @click="nodeProcess(d.userData)">Run</div>
+          <div class="hover" tabindex="0" @click="nodeRemove(d.userData)">Delete</div>
           <hr>
-          <button @click="nodeInspect(d.userData)">Inspect</button>
+          <div class="hover" @click="nodeInspect(d.userData,true)">Inspect</div>
         </div>
       </template>
     </hx-context-menu>
@@ -237,7 +237,7 @@ export default {
       switch (ev.key) {
         case 'Enter':
           if (!single) { return }
-          this.$emit('nodeInspect', single)
+          this.nodeInspect(single)
           break
         case 'Delete':
           if (!this.nodeSelection) { return }
@@ -362,8 +362,8 @@ export default {
         }})
     },
 
-    nodeInspect (tnode) {
-      this.$emit('nodeInspect', tnode)
+    nodeInspect (tnode, force) {
+      this.$emit('nodeInspect', tnode, force)
     },
 
     nodePointerDown (ev, i) {
@@ -591,6 +591,11 @@ export default {
   width:180px;
 }
 
+.flow-node__context-menu > div {
+  padding:10px 20px;
+  cursor: pointer;
+}
+
 .flow-node__context-menu > * {
   width:100%;
 }

+ 14 - 12
browser/vue-flow/src/components/flow/node.vue

@@ -11,16 +11,6 @@
     @dblclick="$emit('nodeDoubleClick',$event)"
   >
 
-    <!-- selection square -->
-    <rect
-      class="flow-node__selection"
-      stroke-dasharray="7,3"
-      :x="bodyProps.x-4"
-      :y="bodyProps.y-4"
-      :width="bodyProps.width+8"
-      :height="bodyProps.height+8"
-    />
-
     <!-- shape -->
     <template>
       <svg
@@ -50,6 +40,16 @@
       />
     </template>
 
+    <!-- selection square -->
+    <rect
+      class="flow-node__selection"
+      stroke-dasharray="7,3"
+      :x="bodyProps.x-4"
+      :y="bodyProps.y-4"
+      :width="bodyProps.width+8"
+      :height="bodyProps.height+8"
+    />
+
     <!-- label -->
     <text
       ref="label"
@@ -285,6 +285,7 @@ export default {
 }
 
 .flow-node__body {
+  opacity:0.9;
   transition: all var(--transition-speed);
 }
 
@@ -341,13 +342,14 @@ for hidden
 
 .flow-node .flow-node__selection {
   opacity:0;
-  stroke-width:1;
+  stroke-width:2;
+  stroke: var(--primary-lighter);
   pointer-events:none;
   transition: all var(--transition-speed);
 }
 
 .flow-node--selected .flow-node__selection {
-  opacity:1;
+  opacity:0.9;
 }
 
 </style>

+ 3 - 0
browser/vue-flow/src/components/main.vue

@@ -255,6 +255,9 @@ export default {
       // Make this elsewhere
       // console.log(v.data)
     })
+    this.$flowService.on('sessionLog', (v) => {
+      console.log(v.data) // Temporary
+    })
 
     // Connected
     this.$flowService.connected(() => {

+ 11 - 6
browser/vue-flow/src/components/shared/hx-contextmenu.vue

@@ -2,7 +2,7 @@
   <div
     :class="{visible:isVisible}"
     class="hx-context-menu"
-    :style="style" tabindex="-1" @blur="close" @click="close" @contextmenu.capture.prevent>
+    :style="style" tabindex="-1" @click="close" @blur="close" @contextmenu.capture.prevent>
     <slot :user-data="userData"/>
   </div>
 </template>
@@ -61,19 +61,24 @@ module.exports = {
 </script>
 
 <style scoped>
+
 .hx-context-menu {
-  pointer-events: none;
-  opacity:0;
   position: fixed;
-  z-index: 2000;
+  z-index: -2000;
+  opacity:0;
   background: var(--background-secondary);
   color: var(--normal);
   transition: opacity var(--transition-speed);
+  border: solid 1px rgba(150,150,150,0.1)
+}
+
+.hx-context-menu.visible{
+  opacity:1;
+  z-index: 2000;
 }
 
 .hx-context-menu:focus {
-  pointer-events: initial;
-  opacity:0.9;
+  opacity:1;
   outline: none;
 }
 </style>

+ 107 - 1
go/src/flow/cmd/demo1/main.go

@@ -1,11 +1,13 @@
 package main
 
 import (
+	"bufio"
 	"errors"
 	"flow"
 	"flow/flowserver"
 	"flow/registry"
 	"fmt"
+	"io"
 	"log"
 	"math"
 	"math/rand"
@@ -33,7 +35,7 @@ func main() {
 		math.Abs, math.Cos, math.Sin, math.Exp, math.Exp2, math.Tanh, math.Max, math.Min,
 	).Tags("math").Extra("style", registry.M{"color": "#386"})
 
-	// Rand functions
+	registry.Add(registry.Add(DockerPull)).Tags("devops") // Rand functions
 	registry.Batch(
 		registry.Add(rand.Int, rand.Intn, rand.Float64),
 		registry.Register("Perm", func(n int) []int {
@@ -94,3 +96,107 @@ func testRandomError(d flow.Data) (flow.Data, error) {
 	}
 	return d, nil
 }
+
+//////////////////////
+// DevOps SIM
+////////
+//
+type DockerImage struct{}
+
+//
+func DockerPull(w io.Writer, imageName string) DockerImage {
+	sampleData := `
+	make: Entering directory '/home/stdio/coding/Projects/Flow'
+make -C go test
+make[1]: Entering directory '/home/stdio/coding/Projects/Flow/go'
+gocov test -race ./src/... | gocov report
+ok  	flow	1.020s	coverage: 84.1% of statements
+?   	flow/cmd/buildops	[no test files]
+?   	flow/cmd/demo1	[no test files]
+?   	flow/flowserver	[no test files]
+?   	flow/flowserver/flowmsg	[no test files]
+?   	flow/internal/assert	[no test files]
+ok  	flow/registry	1.011s	coverage: 100.0% of statements
+
+flow/flow.go		 Flow.String			 100.00% (11/11)
+flow/utils.go		 RandString			 100.00% (10/10)
+flow/flow.go		 @290:21			 100.00% (8/8)
+flow/flow.go		 Flow.MarshalJSON		 100.00% (8/8)
+flow/flow.go		 Flow.Const			 100.00% (7/7)
+flow/flow.go		 Flow.Var			 100.00% (6/6)
+flow/flow.go		 @315:21			 100.00% (6/6)
+flow/hook.go		 Hooks.Attach			 100.00% (3/3)
+flow/flow.go		 Flow.Run			 100.00% (2/2)
+flow/flow.go		 Flow.SetRegistry		 100.00% (2/2)
+flow/operation.go	 @107:12			 100.00% (2/2)
+flow/operation.go	 operation.ID			 100.00% (1/1)
+flow/operation.go	 opFunc				 100.00% (1/1)
+flow/operation.go	 opVar				 100.00% (1/1)
+flow/operation.go	 opConst			 100.00% (1/1)
+flow/flow.go		 Flow.In			 100.00% (1/1)
+flow/operation.go	 @220:12			 100.00% (1/1)
+flow/flow.go		 Flow.Res			 100.00% (1/1)
+flow/operation.go	 @221:12			 100.00% (1/1)
+flow/operation.go	 opIn				 100.00% (1/1)
+flow/flow.go		 Flow.Hook			 100.00% (1/1)
+flow/operation.go	 operation.Set			 100.00% (1/1)
+flow/hook.go		 Hooks.wait			 100.00% (1/1)
+flow/flow.go		 Flow.SetIDGen			 100.00% (1/1)
+flow/hook.go		 Hooks.finish			 100.00% (1/1)
+flow/operation.go	 operation.processWithCtx	 100.00% (1/1)
+flow/flow.go		 @49:13				 100.00% (1/1)
+flow/operation.go	 newOpCtx			 100.00% (1/1)
+flow/operation.go	 operation.Process		 100.00% (1/1)
+flow/hook.go		 Hooks.start			 100.00% (1/1)
+flow/flow.go		 New				 100.00% (1/1)
+flow/flow.go		 Flow.DefOp			 92.31% (12/13)
+flow/flow.go		 Flow.Op			 88.89% (16/18)
+flow/flow.go		 @240:21			 84.21% (16/19)
+flow/flow.go		 Flow.run			 84.21% (16/19)
+flow/operation.go	 @166:8				 80.00% (4/5)
+flow/hook.go		 Hooks.Trigger			 78.57% (11/14)
+flow/flow.go		 Flow.Analyse			 75.00% (3/4)
+flow/flow.go		 Flow.getOp			 75.00% (3/4)
+flow/flow.go		 Flow.Must			 66.67% (2/3)
+flow/operation.go	 @93:12				 66.67% (2/3)
+flow/operation.go	 @121:12			 65.22% (30/46)
+flow/operation.go	 @123:10			 33.33% (1/3)
+flow/hook.go		 Hooks.error			 0.00% (0/1)
+flow/operation.go	 opNil				 0.00% (0/1)
+flow/operation.go	 @229:12			 0.00% (0/1)
+flow/operation.go	 dumbSet			 0.00% (0/0)
+flow			 ------------------------	 84.10% (201/239)
+
+flow/registry/entry.go		 NewEntry		 100.00% (18/18)
+flow/registry/registry.go	 R.Get			 100.00% (12/12)
+flow/registry/registry.go	 R.Add			 100.00% (8/8)
+flow/registry/entry.go		 Entry.DescInputs	 100.00% (8/8)
+flow/registry/batch.go		 Batch			 100.00% (6/6)
+flow/registry/registry.go	 R.Register		 100.00% (5/5)
+flow/registry/entry.go		 Entry.Extra		 100.00% (4/4)
+flow/registry/registry.go	 R.Entry		 100.00% (4/4)
+flow/registry/registry.go	 R.Clone		 100.00% (4/4)
+flow/registry/entry.go		 Entry.Tags		 100.00% (4/4)
+flow/registry/entry.go		 Entry.DescOutput	 100.00% (4/4)
+flow/registry/registry.go	 R.Descriptions		 100.00% (4/4)
+flow/registry/batch.go		 EntryBatch.Extra	 100.00% (3/3)
+flow/registry/batch.go		 EntryBatch.DescOutput	 100.00% (3/3)
+flow/registry/batch.go		 EntryBatch.DescInputs	 100.00% (3/3)
+flow/registry/batch.go		 EntryBatch.Tags	 100.00% (3/3)
+flow/registry/entry.go		 Entry.Err		 100.00% (1/1)
+flow/registry/registry.go	 New			 100.00% (1/1)
+flow/registry			 ---------------------	 100.00% (95/95)
+
+Total Coverage: 88.62% (296/334)
+make[1]: Leaving directory '/home/stdio/coding/Projects/Flow/go'
+make: Leaving directory '/home/stdio/coding/Projects/Flow'`
+
+	scanner := bufio.NewScanner(strings.NewReader(sampleData))
+
+	for scanner.Scan() {
+		time.Sleep(time.Duration(rand.Intn(4)) * time.Second)
+		w.Write([]byte(scanner.Text()))
+	}
+
+	return DockerImage{}
+}

+ 13 - 10
go/src/flow/flowserver/session.go

@@ -7,6 +7,7 @@ import (
 	"flow/flowserver/flowmsg"
 	"flow/registry"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"log"
 	"os"
@@ -193,6 +194,9 @@ func (s *FlowSession) NodeRun(c *websocket.Conn, data []byte) error {
 			s.Notify(msg)
 			return v
 		})
+		localr.Register("Log", func() io.Writer {
+			return s
+		})
 
 		s.flow, err = FlowBuild(s.RawDoc, localr)
 
@@ -234,7 +238,6 @@ func (s *FlowSession) NodeRun(c *websocket.Conn, data []byte) error {
 				}
 				act.Status = status
 				s.broadcast(nil, flowmsg.SendMessage{OP: "nodeActivity", Data: s.nodeActivity})
-
 			},
 		})
 
@@ -244,15 +247,6 @@ func (s *FlowSession) NodeRun(c *websocket.Conn, data []byte) error {
 			log.Println("error processing node", err)
 		}
 		s.flow = nil
-		/*func() {
-			s.Lock()
-			defer s.Unlock()
-			if len(s.clients) == 0 {
-				log.Println("No more clients, remove session")
-				delete(s.mgr.sessions, s.ID) // Clear memory session
-			}
-		}()*/
-
 	}()
 	return nil
 }
@@ -262,6 +256,15 @@ func (s *FlowSession) Notify(v interface{}) error {
 	return s.Broadcast(nil, flowmsg.SendMessage{OP: "sessionNotify", Data: v})
 }
 
+// Write io.Writer implementation to send event logging
+func (s *FlowSession) Write(data []byte) (int, error) {
+	err := s.Broadcast(nil, flowmsg.SendMessage{OP: "sessionLog", Data: string(data)})
+	if err != nil {
+		return -1, err
+	}
+	return len(data), nil
+}
+
 // Broadcast broadcast a message in session besides C
 func (s *FlowSession) Broadcast(c *websocket.Conn, v interface{}) error {
 	s.Lock()