Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/vjeantet/bitfan
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeantet committed Jan 12, 2018
2 parents 7c15987 + 27be9d0 commit c50b878
Show file tree
Hide file tree
Showing 55 changed files with 3,115 additions and 855 deletions.
19 changes: 19 additions & 0 deletions api/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package api

import (
"github.com/gin-gonic/gin"
"github.com/vjeantet/bitfan/core"
)

type DocsController struct {
}

func (d *DocsController) FindAllProcessors(c *gin.Context) {
docs := core.ProcessorsDocs("")
c.JSON(200, docs)
}

func (d *DocsController) FindOneProcessorByCode(c *gin.Context) {
docs := core.ProcessorsDocs(c.Param("code"))
c.JSON(200, docs)
}
13 changes: 12 additions & 1 deletion api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func Handler(path string) http.Handler {
gin.Recovery(),
func(c *gin.Context) {
c.Writer.Header().Add("Access-Control-Allow-Origin", "*")
c.Writer.Header().Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
c.Writer.Header().Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")

if c.Request.Method == "OPTIONS" {
c.Writer.Header().Add("Access-Control-Allow-Headers", "*")
c.JSON(http.StatusOK, struct{}{})
return
}
c.Next()
},
)
Expand All @@ -47,6 +55,8 @@ func Handler(path string) http.Handler {
logs.AddChan(logsCtrl.Hub.Broadcast)
go logsCtrl.Hub.run()

docsCtrl := &DocsController{}

v2.GET("/logs", logsCtrl.Stream) // Websocket

// curl -i -X POST http://localhost:5123/api/v2/pipelines
Expand All @@ -73,7 +83,8 @@ func Handler(path string) http.Handler {

v2.POST("/assets/:uuid/syntax-check", assetCtrl.CheckSyntax) // check syntax

// v1.GET("/docs", getDocs)
v2.GET("/docs/processors", docsCtrl.FindAllProcessors)
v2.GET("/docs/processors/:code", docsCtrl.FindOneProcessorByCode)
// v1.GET("/docs/inputs", getDocsInputs)
// v1.GET("/docs/inputs/:name", getDocsInputsByName)
// v1.GET("/docs/filters", getDocsFilters)
Expand Down
43 changes: 39 additions & 4 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"ContentType": {
"type": "string"
},
"CreatedAt": {},
"CreatedAt": {
"type": "string",
"format": "date-time"
},
"Name": {
"type": "string"
},
Expand All @@ -22,7 +25,10 @@
"Type": {
"type": "string"
},
"UpdatedAt": {},
"UpdatedAt": {
"type": "string",
"format": "date-time"
},
"Value": {
"type": "array",
"items": {
Expand Down Expand Up @@ -57,7 +63,10 @@
"Active": {
"type": "boolean"
},
"CreatedAt": {},
"CreatedAt": {
"type": "string",
"format": "date-time"
},
"Description": {
"type": "string"
},
Expand All @@ -67,7 +76,16 @@
"Playground": {
"type": "boolean"
},
"UpdatedAt": {},
"UpdatedAt": {
"type": "string",
"format": "date-time"
},
"Webhooks": {
"type": "array",
"items": {
"$ref": "#/definitions/Webhook"
}
},
"assets": {
"description": "Assets",
"type": "array",
Expand Down Expand Up @@ -96,6 +114,8 @@
"x-go-name": "Label"
},
"started_at": {
"type": "string",
"format": "date-time",
"x-go-name": "StartedAt"
},
"uuid": {
Expand All @@ -105,6 +125,21 @@
},
"x-go-package": "github.com/vjeantet/bitfan/api/models"
},
"Webhook": {
"type": "object",
"properties": {
"Description": {
"type": "string"
},
"Namespace": {
"type": "string"
},
"Url": {
"type": "string"
}
},
"x-go-package": "github.com/vjeantet/bitfan/api/models"
},
"processorDoc": {
"description": "A Doc is ....\n\nA Doc can have.....",
"type": "object",
Expand Down
235 changes: 235 additions & 0 deletions cmd/bitfanUI/assets/public/js/bitbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
// UMD style ?
// UMD (Universal Module Definition) for bitbar
;
(function(root, UMD) {
if (typeof define === 'function' && define.amd) define([], UMD)
else if (typeof module === 'object' && module.exports) module.exports = UMD()
else root.bitbar = UMD()
})(this, function UMD() {

function isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}

function bitbarNew(instanceOptions) {

initWith([])
var bitbar = {
hide: function() {
$('#exampleModal').modal('hide');
},
// Display bitbar with default items
show: function(label, context) {
console.log("bitbar - GO - label=" + label);
if (this.items.length == 0) {
console.log("no bitbar item set");
return
} else {
this.showWith(this.items, label, context)
}
},
// Display bitbar with given items
showWith: function(items, label, context) {
if (label == null) { label = "" }
console.log("bitbar - GO With keys - label=" + label);

if (context.selected == null) {
context.selected = [];
}
this.context = context
this.citems = items

// console.log(this.context)

// set input value with label
$('#bitbar-input').val(label);
this.search(label);

// Display modal and focus on input
$('#exampleModal').on('shown.bs.modal', function() {
$('#bitbar-input').focus();
});
$('#exampleModal').modal({
keyboard: true
});
},
// Do search term
search: function(txt) {
const term = getSearchLower(txt);

console.log('bitbar - search - term = "' + term + '"')

// let objects = [ 'Favorite Color', 'Google Chrome', 'Launch Chrome' }]
if (txt != null && txt != "") {
this.renderResults(fuzzysort.go(term, this.citems, { keys: ['label'] }));
} else {
this.renderAll();
}
},
// render all items
renderAll: function() {
// Display all
var html = ''
for (var i = 0; i < this.citems.length; i++) {
const result = this.citems[i]
if (i == 0) {
html += this.renderItem(result.id, result.label, "active");
} else {
html += this.renderItem(result.id, result.label, "");
}
}
$('#bitbar-results').html(html);
},
// render results
renderResults: function(results) {
console.log("result count = " + results.length);
var html = ''
for (var i = 0; i < results.length; i++) {
const result = results[i]
if (i == 0) {
html += this.renderItem(result.obj.id, fuzzysort.highlight(result[0]), "active");
} else {
html += this.renderItem(result.obj.id, fuzzysort.highlight(result[0]), "");
}
}
$('#bitbar-results').html(html);
},
renderItem: function(id, label, className) {
return '<li bid="' + id + '" class="' + className + '">' + label + '</li>';
},
// Action Entry selection
select: function(id) {
console.log("selected entry id = " + id)
// hide modal
this.hide();
// find the "do" callback
var result = $.grep(this.citems, function(e) { return e.id == id; });
if (result.length == 0) {
console.log("id " + id + " not found")
} else if (result.length == 1) {
if (isFunction(result[0].do)) {
this.context.selected.unshift(id)
result[0].do(this.context)
} else {
console.log("no callback for item " + id)
}
} else {
// multiple items found
console.log("crazy ids found for " + id)
}
},

new: bitbarNew,
items: [],
citems: [],
context: {},
}

return bitbar;
}

function getSearchLower(txt) { return txt.toLowerCase() }

function scrollToVisible(selected) {
if (
selected.position().top + selected.height() < $('#bitbar-results').position().top + $('#bitbar-results').height() &
selected.position().top >= $('#bitbar-results').position().top
) {return}

// hidden on top
if (selected.position().top >= $('#bitbar-results').position().top) {
$('#bitbar-results').scrollTop(
$('#bitbar-results').scrollTop() + selected.position().top + selected.height() - $('#bitbar-results').height() -$('#bitbar-results').position().top
);
}

// hidden bottom
if (selected.position().top + selected.height() < $('#bitbar-results').position().top + $('#bitbar-results').height()){
$('#bitbar-results').scrollTop(
$('#bitbar-results').scrollTop() + (selected.position().top - $('#bitbar-results').position().top)
);
}
}

// Init Bitbar with data
function initWith(keys) {
// Register shortcut CTRL+SHIFT+P (optional)
// Create the modal screen on DOM
// Prevent UP DOWN and ENTER on input
$(document).on("blur", "#bitbar-input", function(event) {
$("#bitbar-input").focus();
});
$(document).on("keydown", "#bitbar-input", function(event) {
if (event.which == 9) {
event.preventDefault();
bitbar.hide();
}
if (event.which == 38) {
console.log("UP");
event.preventDefault();

active = $('#bitbar-results > li.active')
if (active.length > 0) { // if found

if (active.is(':first-child')) {
// if first
} else {
// if not first
active.prev().addClass("active");
active.removeClass("active");
scrollToVisible(active.prev())
}
} else {
console.log("todo : use the last visible element");
}
}
if (event.which == 40) {
console.log("DOWN");
// find active li in #bitbar-results
active = $('#bitbar-results > li.active')

if (active.length > 0) { // if found
console.log("active li found");
// if the active one is the last one
if (active.is(':last-child')) {
console.log("active is the last one");
} else {
console.log("active is not the last one");
// select next sibbling element
active.next().addClass("active");
active.removeClass("active");
scrollToVisible(active.next())
}
} else { // try to select first
console.log("no active li found");
$('#bitbar-results > li:first').addClass("active");
}

}
if (event.which == 13) {
console.log("ENTER");
active = $('#bitbar-results > li.active')
bitbar.select(active.attr("bid"));
}
});
// On input change do Search
$(document).on("input", "#bitbar-input", function(event) {
// $('#bitbar-input').on("input",function(e){
console.log("bitbar - input : " + event.target.value);
bitbar.search(event.target.value);
});

$(document).on("mousedown", "#bitbar-results li", function(event) {
$('#bitbar-results > li.active').removeClass("active")
$(event.target).addClass("active")
});
$(document).on("click", "#bitbar-results li", function(event) {
bitbar.select($(event.target).attr("bid"));
});


}

return bitbarNew()
}) // UMD

0 comments on commit c50b878

Please sign in to comment.