浏览代码

Merge branch 'event-changes'

Torkel Ödegaard 9 年之前
父节点
当前提交
f772a5cf38

+ 2 - 12
CHANGELOG.md

@@ -1,13 +1,4 @@
-# 3.0.0-beta3 (unreleased)
-
-### Bug fixes
-* **Postgres**: Fixed page render crash when using postgres, fixes [#4558](https://github.com/grafana/grafana/issues/4558)
-* **Table panel**: Fixed table panel bug when trying to show annotations in table panel, fixes [#4563](https://github.com/grafana/grafana/issues/4563)
-* **App Config**: Fixed app config issue showing content of other app config, fixes [#4575](https://github.com/grafana/grafana/issues/4575)
-* **Graph Panel**: Fixed legend option max not updating, fixes [#4601](https://github.com/grafana/grafana/issues/4601)
-* **Graph Panel**: Fixed issue where newly added graph panels shared same axes config, fixes [#4582](https://github.com/grafana/grafana/issues/4582)
-
-# 3.0.0-beta2 (2016-04-04)
+# 3.0.0-beta2 (unreleased)
 
 ### New Features (introduces since 3.0-beta1)
 * **Preferences**: Set home dashboard on user and org level, closes [#1678](https://github.com/grafana/grafana/issues/1678)
@@ -18,9 +9,8 @@
 * **Dashboard**: Fixed dashboard panel layout for mobile devices, fixes [#4529](https://github.com/grafana/grafana/issues/4529)
 * **Table Panel**: Fixed issue with table panel sort, fixes [#4532](https://github.com/grafana/grafana/issues/4532)
 * **Page Load Crash**: A Datasource with null jsonData would make Grafana fail to load page, fixes [#4536](https://github.com/grafana/grafana/issues/4536)
-* **Metrics tab**: Fix for missing datasource name in datasource selector, fixes [#4540](https://github.com/grafana/grafana/issues/4540)
+* **Metrics tab**: Fix for missing datasource name in datasource selector, fixes [#4541](https://github.com/grafana/grafana/issues/4540)
 * **Graph**: Fix legend in table mode with series on right-y axis, fixes [#4551](https://github.com/grafana/grafana/issues/4551), [#1145](https://github.com/grafana/grafana/issues/1145)
-* **Password**: Password reset link/page did not work, fixes [#4542](https://github.com/grafana/grafana/issues/4542)
 
 # 3.0.0-beta1 (2016-03-31)
 

+ 2 - 2
package.json

@@ -10,7 +10,6 @@
     "url": "http://github.com/grafana/grafana.git"
   },
   "devDependencies": {
-    "angular2": "2.0.0-beta.12",
     "zone.js": "^0.6.6",
     "autoprefixer": "^6.3.3",
     "es6-promise": "^3.0.2",
@@ -54,7 +53,7 @@
     "mocha": "2.3.4",
     "phantomjs-prebuilt": "^2.1.3",
     "reflect-metadata": "0.1.2",
-    "rxjs": "5.0.0-beta.2",
+    "rxjs": "5.0.0-beta.4",
     "sass-lint": "^1.5.0",
     "systemjs": "0.19.24"
   },
@@ -68,6 +67,7 @@
   },
   "license": "Apache-2.0",
   "dependencies": {
+    "eventemitter3": "^1.2.0",
     "grunt-jscs": "~1.5.x",
     "grunt-sass-lint": "^0.1.0",
     "grunt-sync": "^0.4.1",

+ 1 - 1
public/app/core/time_series2.ts

@@ -170,7 +170,7 @@ export default class TimeSeries {
   }
 
   isMsResolutionNeeded() {
-    for (var i = 0; i<this.datapoints.length; i++) {
+    for (var i = 0; i < this.datapoints.length; i++) {
       if (this.datapoints[i][0] !== null) {
         var timestamp = this.datapoints[i][0].toString();
         if (timestamp.length === 13 && (timestamp % 1000) !== 0) {

+ 8 - 29
public/app/core/utils/emitter.ts

@@ -1,6 +1,6 @@
 ///<reference path="../../headers/common.d.ts" />
 
-import {Subject} from 'vendor/npm/rxjs/Subject';
+import EventEmitter from 'eventemitter3';
 
 var hasOwnProp = {}.hasOwnProperty;
 
@@ -9,48 +9,27 @@ function createName(name) {
 }
 
 export class Emitter {
-  subjects: any;
+  emitter: any;
 
   constructor() {
-    this.subjects = {};
+    this.emitter = new EventEmitter();
   }
 
   emit(name, data?) {
-    var fnName = createName(name);
-    this.subjects[fnName] || (this.subjects[fnName] = new Subject());
-    this.subjects[fnName].next(data);
+    this.emitter.emit(name, data);
   }
 
   on(name, handler, scope?) {
-    var fnName = createName(name);
-    this.subjects[fnName] || (this.subjects[fnName] = new Subject());
-    var subscription = this.subjects[fnName].subscribe(handler);
+    this.emitter.on(name, handler);
 
     if (scope) {
       scope.$on('$destroy', function() {
-        subscription.unsubscribe();
+        this.emitter.off(name, handler);
       });
     }
-
-    return subscription;
-  };
-
-  off(name, handler) {
-    var fnName = createName(name);
-    if (this.subjects[fnName]) {
-      this.subjects[fnName].dispose();
-      delete this.subjects[fnName];
-    }
   }
 
-  dispose() {
-    var subjects = this.subjects;
-    for (var prop in subjects) {
-      if (hasOwnProp.call(subjects, prop)) {
-        subjects[prop].dispose();
-      }
-    }
-
-    this.subjects = {};
+  off(name, handler) {
+    this.emitter.off(name, handler);
   }
 }

+ 5 - 4
public/app/features/templating/templateValuesSrv.js

@@ -272,7 +272,9 @@ function (angular, _, kbn) {
       }
 
       for (i = 0; i < metricNames.length; i++) {
-        var value = metricNames[i].text;
+        var item = metricNames[i];
+        var value = item.value || item.text;
+        var text = item.text || item.value;
 
         if (regex) {
           matches = regex.exec(value);
@@ -282,12 +284,11 @@ function (angular, _, kbn) {
           }
         }
 
-        options[value] = value;
+        options[value] = {text: text, value: value};
       }
 
       return _.map(_.keys(options).sort(), function(key) {
-        var option = { text: key, value: key };
-        return option;
+        return options[key];
       });
     };
 

+ 6 - 2
public/app/headers/common.d.ts

@@ -1,5 +1,4 @@
-///<reference path="../../vendor/npm/angular2/typings/es6-promise/es6-promise.d.ts" />
-///<reference path="../../vendor/npm/angular2/typings/es6-collections/es6-collections.d.ts" />
+/// <reference path="./es6-shim/es6-shim.d.ts" />
 
 declare var System: any;
 
@@ -48,3 +47,8 @@ declare module 'tether-drop' {
   var config: any;
   export default config;
 }
+
+declare module 'eventemitter3' {
+  var config: any;
+  export default config;
+}

+ 0 - 73
public/app/headers/es6-promise/es6-promise.d.ts

@@ -1,73 +0,0 @@
-// Type definitions for es6-promise
-// Project: https://github.com/jakearchibald/ES6-Promise
-// Definitions by: François de Campredon <https://github.com/fdecampredon/>, vvakame <https://github.com/vvakame>
-// Definitions: https://github.com/borisyankov/DefinitelyTyped
-
-interface Thenable<R> {
-    then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
-    then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
-}
-
-declare class Promise<R> implements Thenable<R> {
-	/**
-	 * If you call resolve in the body of the callback passed to the constructor,
-	 * your promise is fulfilled with result object passed to resolve.
-	 * If you call reject your promise is rejected with the object passed to resolve.
-	 * For consistency and debugging (eg stack traces), obj should be an instanceof Error.
-	 * Any errors thrown in the constructor callback will be implicitly passed to reject().
-	 */
-	constructor(callback: (resolve : (value?: R | Thenable<R>) => void, reject: (error?: any) => void) => void);
-
-	/**
-	 * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
-	 * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
-	 * Both callbacks have a single parameter , the fulfillment value or rejection reason.
-	 * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve.
-	 * If an error is thrown in the callback, the returned promise rejects with that error.
-	 *
-	 * @param onFulfilled called when/if "promise" resolves
-	 * @param onRejected called when/if "promise" rejects
-	 */
-    then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Promise<U>;
-    then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Promise<U>;
-
-	/**
-	 * Sugar for promise.then(undefined, onRejected)
-	 *
-	 * @param onRejected called when/if "promise" rejects
-	 */
-	catch<U>(onRejected?: (error: any) => U | Thenable<U>): Promise<U>;
-}
-
-declare module Promise {
-	/**
-	 * Make a new promise from the thenable.
-	 * A thenable is promise-like in as far as it has a "then" method.
-	 */
-	function resolve<R>(value?: R | Thenable<R>): Promise<R>;
-
-	/**
-	 * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
-	 */
-	function reject(error: any): Promise<any>;
-
-	/**
-	 * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
-	 * the array passed to all can be a mixture of promise-like objects and other objects.
-	 * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
-	 */
-	function all<R>(promises: (R | Thenable<R>)[]): Promise<R[]>;
-
-	/**
-	 * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
-	 */
-	function race<R>(promises: (R | Thenable<R>)[]): Promise<R>;
-}
-
-declare module 'es6-promise' {
-	var foo: typeof Promise; // Temp variable to reference Promise in local context
-	module rsvp {
-		export var Promise: typeof foo;
-	}
-	export = rsvp;
-}

+ 5 - 3
public/app/headers/es6-shim/es6-shim.d.ts

@@ -1,7 +1,9 @@
+// Generated by typings
+// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/es6-shim/es6-shim.d.ts
 // Type definitions for es6-shim v0.31.2
 // Project: https://github.com/paulmillr/es6-shim
 // Definitions by: Ron Buckton <http://github.com/rbuckton>
-// Definitions: https://github.com/borisyankov/DefinitelyTyped
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
 
 declare type PropertyKey = string | number | symbol;
 
@@ -621,7 +623,7 @@ interface WeakSetConstructor {
 
 declare var WeakSet: WeakSetConstructor;
 
-declare module Reflect {
+declare namespace Reflect {
     function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
     function construct(target: Function, argumentsList: ArrayLike<any>): any;
     function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
@@ -649,7 +651,7 @@ declare module "es6-shim" {
     var WeakMap: WeakMapConstructor;
     var WeakSet: WeakSetConstructor;
     var Promise: PromiseConstructor;
-    module Reflect {
+    namespace Reflect {
         function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;
         function construct(target: Function, argumentsList: ArrayLike<any>): any;
         function defineProperty(target: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;

+ 5 - 0
public/app/plugins/panel/graph/module.ts

@@ -216,6 +216,11 @@ class GraphCtrl extends MetricsPanelCtrl {
     }
 
     series.applySeriesOverrides(this.panel.seriesOverrides);
+
+    if (seriesData.unit) {
+      this.panel.yaxes[series.yaxis-1].format = seriesData.unit;
+    }
+
     return series;
   }
 

+ 5 - 0
public/app/system.conf.js

@@ -4,6 +4,7 @@ System.config({
   paths: {
     'remarkable': 'vendor/npm/remarkable/dist/remarkable.js',
     'tether': 'vendor/npm/tether/dist/js/tether.js',
+    'eventemitter3': 'vendor/npm/eventemitter3/index.js',
     'tether-drop': 'vendor/npm/tether-drop/dist/js/drop.js',
     'moment': 'vendor/moment.js',
     "jquery": "vendor/jquery/dist/jquery.js",
@@ -55,5 +56,9 @@ System.config({
       deps: ['jquery'],
       exports: 'angular',
     },
+    'vendor/npm/eventemitter3/index.js': {
+      format: 'cjs',
+      exports: 'EventEmitter'
+    },
   }
 });

+ 1 - 0
public/sass/utils/_utils.scss

@@ -52,6 +52,7 @@ button.close {
 .pull-right {
   float: right !important;
 }
+
 .pull-left {
   float: left !important;
 }

+ 21 - 1
public/test/core/utils/emitter_specs.ts

@@ -23,8 +23,28 @@ describe("Emitter", () => {
       expect(sub1Called).to.be(true);
       expect(sub2Called).to.be(true);
     });
-  });
 
+    it.only('should handle errors', () => {
+      var events = new Emitter();
+      var sub1Called = 0;
+      var sub2Called = 0;
+
+      events.on('test', () => {
+        sub1Called++;
+        throw "hello";
+      });
+
+      events.on('test', () => {
+        sub2Called++;
+      });
+
+      try { events.emit('test', null); } catch (_) { }
+      try { events.emit('test', null); } catch (_) {}
+
+      expect(sub1Called).to.be(2);
+      expect(sub2Called).to.be(0);
+    });
+  });
 });
 
 

+ 6 - 1
public/test/test-main.js

@@ -10,6 +10,7 @@
     baseURL: '/base/',
     defaultJSExtensions: true,
     paths: {
+      'eventemitter3': 'vendor/npm/eventemitter3/index.js',
       'tether': 'vendor/npm/tether/dist/js/tether.js',
       'tether-drop': 'vendor/npm/tether-drop/dist/js/drop.js',
       'moment': 'vendor/moment.js',
@@ -58,7 +59,11 @@
       'vendor/angular-mocks/angular-mocks.js': {
         format: 'global',
         deps: ['angular'],
-      }
+      },
+      'vendor/npm/eventemitter3/index.js': {
+        format: 'cjs',
+        exports: 'EventEmitter'
+      },
     }
   });
 

+ 1 - 4
tasks/options/copy.js

@@ -19,10 +19,7 @@ module.exports = function(config) {
       cwd: './node_modules',
       expand: true,
       src: [
-        'angular2/bundles/*.js',
-        'angular2/*.d.ts',
-        'angular2/typings/**/*',
-        'angular2/manual_typings/**/*',
+        'eventemitter3/*.js',
         'systemjs/dist/*.js',
         'es6-promise/**/*',
         'es6-shim/*.js',