Selaa lähdekoodia

Merge branch 'v3.0.x'

Torkel Ödegaard 9 vuotta sitten
vanhempi
commit
2cd6c2e7e0

+ 1 - 1
pkg/api/api.go

@@ -209,7 +209,7 @@ func Register(r *macaron.Macaron) {
 			r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard)
 			r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
 			r.Get("/file/:file", GetDashboardFromJsonFile)
-			r.Get("/home", GetHomeDashboard)
+			r.Get("/home", wrap(GetHomeDashboard))
 			r.Get("/tags", GetDashboardTags)
 			r.Post("/import", bind(dtos.ImportDashboardCommand{}), wrap(ImportDashboard))
 		})

+ 6 - 8
pkg/api/dashboard.go

@@ -159,10 +159,10 @@ func canEditDashboard(role m.RoleType) bool {
 	return role == m.ROLE_ADMIN || role == m.ROLE_EDITOR || role == m.ROLE_READ_ONLY_EDITOR
 }
 
-func GetHomeDashboard(c *middleware.Context) {
+func GetHomeDashboard(c *middleware.Context) Response {
 	prefsQuery := m.GetPreferencesWithDefaultsQuery{OrgId: c.OrgId, UserId: c.UserId}
 	if err := bus.Dispatch(&prefsQuery); err != nil {
-		c.JsonApiErr(500, "Failed to get preferences", err)
+		return ApiError(500, "Failed to get preferences", err)
 	}
 
 	if prefsQuery.Result.HomeDashboardId != 0 {
@@ -170,7 +170,7 @@ func GetHomeDashboard(c *middleware.Context) {
 		err := bus.Dispatch(&slugQuery)
 		if err == nil {
 			dashRedirect := dtos.DashboardRedirect{RedirectUri: "db/" + slugQuery.Result}
-			c.JSON(200, &dashRedirect)
+			return Json(200, &dashRedirect)
 		} else {
 			log.Warn("Failed to get slug from database, %s", err.Error())
 		}
@@ -179,8 +179,7 @@ func GetHomeDashboard(c *middleware.Context) {
 	filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
 	file, err := os.Open(filePath)
 	if err != nil {
-		c.JsonApiErr(500, "Failed to load home dashboard", err)
-		return
+		return ApiError(500, "Failed to load home dashboard", err)
 	}
 
 	dash := dtos.DashboardFullWithMeta{}
@@ -188,11 +187,10 @@ func GetHomeDashboard(c *middleware.Context) {
 	dash.Meta.CanEdit = canEditDashboard(c.OrgRole)
 	jsonParser := json.NewDecoder(file)
 	if err := jsonParser.Decode(&dash.Dashboard); err != nil {
-		c.JsonApiErr(500, "Failed to load home dashboard", err)
-		return
+		return ApiError(500, "Failed to load home dashboard", err)
 	}
 
-	c.JSON(200, &dash)
+	return Json(200, &dash)
 }
 
 func GetDashboardFromJsonFile(c *middleware.Context) {

+ 2 - 1
public/app/features/dashboard/rowCtrl.js

@@ -142,9 +142,10 @@ function (angular, _, config) {
   });
 
   module.directive('panelWidth', function() {
-    var fullscreen = false;
 
     return function(scope, element) {
+      var fullscreen = false;
+
       function updateWidth() {
         if (!fullscreen) {
           element[0].style.width = ((scope.panel.span / 1.2) * 10) + '%';

+ 1 - 1
public/app/features/templating/templateSrv.js

@@ -103,7 +103,7 @@ function (angular, _) {
       }
 
       variableName = regexEscape(variableName);
-      var findVarRegex = new RegExp('\\$(' + variableName + ')[\\W|$]|\\[\\[(' + variableName + ')\\]\\]', 'g');
+      var findVarRegex = new RegExp('\\$(' + variableName + ')(?:\\W|$)|\\[\\[(' + variableName + ')\\]\\]', 'g');
       var match = findVarRegex.exec(str);
       return match !== null;
     };

+ 4 - 0
public/test/specs/templateSrv-specs.js

@@ -205,6 +205,10 @@ define([
         expect(contains).to.be(true);
       });
 
+      it('should find it its the only thing', function() {
+        var contains = _templateSrv.containsVariable('$env', 'env');
+        expect(contains).to.be(true);
+      });
     });
 
     describe('updateTemplateData with simple value', function() {