Show current version in web UI

This commit is contained in:
Victor Felder 2016-10-02 20:07:25 +02:00
parent 408ef0f5b7
commit 4a43273ee5
6 changed files with 56 additions and 1 deletions

13
web.go
View file

@ -15,6 +15,7 @@ import (
"github.com/containous/traefik/middlewares" "github.com/containous/traefik/middlewares"
"github.com/containous/traefik/safe" "github.com/containous/traefik/safe"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
"github.com/containous/traefik/version"
"github.com/elazarl/go-bindata-assetfs" "github.com/elazarl/go-bindata-assetfs"
"github.com/thoas/stats" "github.com/thoas/stats"
"github.com/unrolled/render" "github.com/unrolled/render"
@ -60,6 +61,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag
systemRouter.Methods("GET").Path("/ping").HandlerFunc(provider.getPingHandler) systemRouter.Methods("GET").Path("/ping").HandlerFunc(provider.getPingHandler)
// API routes // API routes
systemRouter.Methods("GET").Path("/api").HandlerFunc(provider.getConfigHandler) systemRouter.Methods("GET").Path("/api").HandlerFunc(provider.getConfigHandler)
systemRouter.Methods("GET").Path("/api/version").HandlerFunc(provider.getVersionHandler)
systemRouter.Methods("GET").Path("/api/providers").HandlerFunc(provider.getConfigHandler) systemRouter.Methods("GET").Path("/api/providers").HandlerFunc(provider.getConfigHandler)
systemRouter.Methods("GET").Path("/api/providers/{provider}").HandlerFunc(provider.getProviderHandler) systemRouter.Methods("GET").Path("/api/providers/{provider}").HandlerFunc(provider.getProviderHandler)
systemRouter.Methods("PUT").Path("/api/providers/{provider}").HandlerFunc(func(response http.ResponseWriter, request *http.Request) { systemRouter.Methods("PUT").Path("/api/providers/{provider}").HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
@ -144,6 +146,17 @@ func (provider *WebProvider) getConfigHandler(response http.ResponseWriter, requ
templatesRenderer.JSON(response, http.StatusOK, currentConfigurations) templatesRenderer.JSON(response, http.StatusOK, currentConfigurations)
} }
func (provider *WebProvider) getVersionHandler(response http.ResponseWriter, request *http.Request) {
v := struct {
Version string
Codename string
}{
Version: version.Version,
Codename: version.Codename,
}
templatesRenderer.JSON(response, http.StatusOK, v)
}
func (provider *WebProvider) getProviderHandler(response http.ResponseWriter, request *http.Request) { func (provider *WebProvider) getProviderHandler(response http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request) vars := mux.Vars(request)
providerID := vars["provider"] providerID := vars["provider"]

View file

@ -0,0 +1,14 @@
'use strict';
var angular = require('angular');
var traefikCoreVersion = 'traefik.core.version';
module.exports = traefikCoreVersion;
angular
.module(traefikCoreVersion, ['ngResource'])
.factory('Version', Version);
/** @ngInject */
function Version($resource) {
return $resource('../api/version');
}

View file

@ -0,0 +1,10 @@
'use strict';
/** @ngInject */
function VersionController($scope, $interval, $log, Version) {
Version.get(function (version) {
$scope.version = version;
});
}
module.exports = VersionController;

View file

@ -0,0 +1,11 @@
'use strict';
var angular = require('angular');
var traefikCoreVersion = require('../core/version.resource');
var VersionController = require('./version.controller');
var traefikVersion = 'traefik.version';
module.exports = traefikVersion;
angular
.module(traefikVersion, [traefikCoreVersion])
.controller('VersionController', VersionController);

View file

@ -27,6 +27,11 @@
<li><a ui-sref="health">Health</a></li> <li><a ui-sref="health">Health</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li>
<a ng-controller="VersionController" href="https://github.com/containous/traefik/tree/{{version.Version}}" target="_blank">
<small>{{version.Version}} / {{version.Codename}}</small>
</a>
</li>
<li> <li>
<a href="https://docs.traefik.io" target="_blank">Documentation</a> <a href="https://docs.traefik.io" target="_blank">Documentation</a>
</li> </li>

View file

@ -10,6 +10,7 @@ var uiRouter = require('angular-ui-router');
var uiBootstrap = require('angular-ui-bootstrap'); var uiBootstrap = require('angular-ui-bootstrap');
var moment = require('moment'); var moment = require('moment');
var traefikSection = require('./app/sections/sections'); var traefikSection = require('./app/sections/sections');
var traefikVersion = require('./app/version/version.module');
require('./index.scss'); require('./index.scss');
require('animate.css/animate.css'); require('animate.css/animate.css');
require('nvd3/build/nv.d3.css'); require('nvd3/build/nv.d3.css');
@ -28,7 +29,8 @@ angular
ngResource, ngResource,
uiRouter, uiRouter,
uiBootstrap, uiBootstrap,
traefikSection traefikSection,
traefikVersion
]) ])
.run(runBlock) .run(runBlock)
.constant('moment', moment) .constant('moment', moment)