Skip to content

Commit

Permalink
Move static assets to it's own directory inside static folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Jan 10, 2019
1 parent 785c560 commit 2475b37
Show file tree
Hide file tree
Showing 97 changed files with 64,707 additions and 20,224 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ doc:
ghp-import -p public

gen:
go generate ./dkron
gofmt -s -w ./dkron/bindata.go
go generate ./templates
go generate ./static

test:
@bash --norc -i ./scripts/test
21,186 changes: 983 additions & 20,203 deletions dkron/bindata.go

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions dkron/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package dkron
import (
"fmt"
"html/template"
"io/ioutil"
"net/http"
"strings"

"github.com/gin-contrib/multitemplate"
"github.com/gin-gonic/gin"
"github.com/victorcoder/dkron/static"
"github.com/victorcoder/dkron/templates"
)

const (
Expand Down Expand Up @@ -61,7 +64,8 @@ func (a *Agent) DashboardRoutes(r *gin.RouterGroup) {
}
})

r.GET("/static/*asset", servePublic)
r.StaticFS("static", static.Assets)
//r.GET("/static/*asset", servePublic)

dashboard := r.Group("/" + dashboardPathPrefix)
dashboard.GET("/", a.dashboardIndexHandler)
Expand Down Expand Up @@ -112,7 +116,13 @@ func (a *Agent) dashboardExecutionsHandler(c *gin.Context) {
}

func mustLoadTemplate(path string) []byte {
tmpl, err := Asset(path)
f, err := templates.Templates.Open(path)
if err != nil {
log.Error(err)
return nil
}

tmpl, err := ioutil.ReadAll(f)
if err != nil {
log.Error(err)
return nil
Expand Down Expand Up @@ -145,7 +155,11 @@ func CreateMyRender() multitemplate.Render {
return r
}

//go:generate go-bindata -prefix "../" -pkg dkron -ignore=scss -ignore=.*\.md -ignore=\.?package\.json -ignore=\.?package-lock\.json -ignore=\.gitignore -ignore=Makefile -ignore=examples -ignore=tutorial -ignore=tests -ignore=rickshaw\/src -o bindata.go ../static/... ../templates
//var Assets http.FileSystem = http.Dir("../static")
//var Templates http.FileSystem = http.Dir("../templates")

//go:generate vfsgendev -source="github.com/victorcoder/dkron/static".Assets
//go:generate vfsgendev -source="github.com/victorcoder/dkron/templates".Templates
func servePublic(c *gin.Context) {
path := c.Request.URL.Path

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ require (
github.com/russross/blackfriday v0.0.0-20180804101149-46c73eb196ba // indirect
github.com/samuel/go-zookeeper v0.0.0-20170815201139-e6b59f6144be // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect
github.com/sirupsen/logrus v1.2.0
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/spf13/afero v0.0.0-20171008182726-e67d870304c4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ github.com/samuel/go-zookeeper v0.0.0-20170815201139-e6b59f6144be h1:9prAjluC9cN
github.com/samuel/go-zookeeper v0.0.0-20170815201139-e6b59f6144be/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 h1:IYVb70m/qpJGjyZV2S4qbdSDnsMl+w9nsQ2iQedf1HI=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
Expand Down
281 changes: 281 additions & 0 deletions static/angular-rickshaw/rickshaw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
/**
@toc
@param {Object} scope (attrs that must be defined on the scope (i.e. in the controller) - they can't just be defined in the partial html). REMEMBER: use snake-case when setting these on the partial!
TODO
@param {Object} attrs REMEMBER: use snake-case when setting these on the partial! i.e. my-attr='1' NOT myAttr='1'
TODO
@dependencies
TODO
@usage
partial / html:
TODO
controller / js:
TODO
//end: usage
*/

'use strict';

/* global Rickshaw */

angular.module('angular-rickshaw', [])
.directive('rickshaw', ['$compile', '$window', function($compile, $window) {
return {
restrict: 'EA',
scope: {
options: '=rickshawOptions',
series: '=rickshawSeries',
features: '=rickshawFeatures'
},
// replace: true,
link: function(scope, element, attrs) {
var mainEl;
var graphEl;
var legendEl;
var previewEl;
var xAxis;
var yAxis;
var graph;
var settings;

function redraw() {
graph.setSize();
graph.render();
}

function _splice(args) {
var data = args.data;
var series = args.series;

if (!args.series) {
return data;
}

series.forEach(function(s) {
var seriesKey = s.key || s.name;
if (!seriesKey) {
throw "series needs a key or a name";
}

data.forEach(function(d) {
var dataKey = d.key || d.name;
if (!dataKey) {
throw "data needs a key or a name";
}
if (seriesKey == dataKey) {
var properties = ['color', 'name', 'data'];
properties.forEach(function(p) {
if (d[p]) {
s[p] = d[p];
}
});
}
} );
});
}

function updateData() {
if (graph && settings) {
_splice({ data: scope.series, series: settings.series });
redraw();
}
}

function updateConfiguration() {
if (!graph) {
mainEl = angular.element(element);
mainEl.append(graphEl);
mainEl.empty();
graphEl = $compile('<div></div>')(scope);
mainEl.append(graphEl);

settings = angular.copy(scope.options);
settings.element = graphEl[0];
settings.series = scope.series;

graph = new Rickshaw.Graph(settings);
}
else {
if (scope.options) {
for (var key in scope.options) {
settings[key] = scope.options[key];
console.log(key + '=' + scope.options[key]);
}
settings.element = graphEl[0];
}

graph.configure(settings);
}

if (scope.features) {
if (scope.features.hover) {
var hoverConfig = {
graph: graph
};
hoverConfig.xFormatter = scope.features.hover.xFormatter;
hoverConfig.yFormatter = scope.features.hover.yFormatter;
hoverConfig.formatter = scope.features.hover.formatter;
var hoverDetail = new Rickshaw.Graph.HoverDetail(hoverConfig);
}

if (scope.features.palette) {
var palette = new Rickshaw.Color.Palette({scheme: scope.features.palette});
for (var i = 0; i < settings.series.length; i++) {
settings.series[i].color = palette.color();
}
}
}

redraw();

if (scope.features) {
if (scope.features.xAxis) {
if (!xAxis) {
var xAxisConfig = {
graph: graph
};
if (scope.features.xAxis.timeUnit) {
var time = new Rickshaw.Fixtures.Time();
xAxisConfig.timeUnit = time.unit(scope.features.xAxis.timeUnit);
}
if (scope.features.xAxis.tickFormat) {
xAxisConfig.tickFormat = scope.features.xAxis.tickFormat;
}
if (scope.features.xAxis.ticksTreatment) {
xAxisConfig.ticksTreatment = scope.features.xAxis.ticksTreatment;
}
if (scope.features.xAxis.time) {
if (scope.features.xAxis.time.local) {
xAxisConfig.timeFixture = new Rickshaw.Fixtures.Time.Local();
}
xAxis = new Rickshaw.Graph.Axis.Time(xAxisConfig);
}
else {
xAxis = new Rickshaw.Graph.Axis.X(xAxisConfig);
}
xAxis.render();
}
else {
// Update xAxis if Rickshaw allows it in future.
}
}
else {
// Remove xAxis if Rickshaw allows it in future.
}

if (scope.features.yAxis) {
var yAxisConfig = {
graph: graph
};
if (scope.features.yAxis.tickFormat) {
var tickFormat = scope.features.yAxis.tickFormat;
if (typeof tickFormat === 'string'){
yAxisConfig.tickFormat = Rickshaw.Fixtures.Number[tickFormat];
} else {
yAxisConfig.tickFormat = tickFormat;
}
}
if (!yAxis) {
yAxis = new Rickshaw.Graph.Axis.Y(yAxisConfig);
yAxis.render();
}
else {
// Update yAxis if Rickshaw allows it in future.
}
}
else {
// Remove yAxis if Rickshaw allows it in future.
}

if (scope.features.legend) {
if (!legendEl) {
legendEl = $compile('<div></div>')(scope);
mainEl.append(legendEl);

var legend = new Rickshaw.Graph.Legend({
graph: graph,
element: legendEl[0]
});
if (scope.features.legend.toggle) {
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
graph: graph,
legend: legend
});
}
if (scope.features.legend.highlight) {
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
graph: graph,
legend: legend
});
}
}
}
else {
if (legendEl) {
legendEl.remove();
legendEl = null;
}
}

if (scope.features.preview) {
if (!previewEl) {
previewEl = $compile('<div></div>')(scope);
mainEl.append(previewEl);

new Rickshaw.Graph.RangeSlider.Preview({
graph: graph,
element: previewEl[0]
});
}
}
else {
if (previewEl) {
previewEl.remove();
previewEl = null;
}
}
}
}

var optionsWatch = scope.$watch('options', function(newValue, oldValue) {
if (!angular.equals(newValue, oldValue)) {
updateConfiguration();
}
}, true);
var seriesWatch = scope.$watchCollection('series', function(newValue, oldValue) {
if (!angular.equals(newValue, oldValue)) {
updateData();
}
}, true);
var featuresWatch = scope.$watch('features', function(newValue, oldValue) {
if (!angular.equals(newValue, oldValue)) {
updateConfiguration();
}
}, true);

scope.$on('$destroy', function() {
optionsWatch();
seriesWatch();
featuresWatch();
});

angular.element($window).on('resize', function() {
scope.$broadcast('rickshaw::resize');
});

scope.$on('rickshaw::resize', function() {
redraw();
});

updateConfiguration();
},
controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
}]
};
}]);
9 changes: 9 additions & 0 deletions static/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build dev

package static

import "net/http"

//go:generate vfsgendev -source="github.com/victorcoder/dkron/static".Assets
// Templates contains project templates.
var Assets http.FileSystem = http.Dir(".")
Loading

0 comments on commit 2475b37

Please sign in to comment.