diff --git a/.gitignore b/.gitignore
index 3fdbcac5734..2cd3623cf83 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ awsconfig
/dist
/emails/dist
/public_gen
+/public/vendor/npm
/tmp
vendor/phantomjs/phantomjs
diff --git a/package.json b/package.json
index ef79f3367d8..03c5ab52bb4 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,8 @@
},
"scripts": {
"test": "grunt test",
- "coveralls": "grunt karma:coveralls && rm -rf ./coverage"
+ "coveralls": "grunt karma:coveralls && rm -rf ./coverage",
+ "postinstall": "grunt copy:node_modules"
},
"license": "Apache-2.0",
"dependencies": {
diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go
index 7bea0b6338c..0759f1e83b8 100644
--- a/pkg/api/frontendsettings.go
+++ b/pkg/api/frontendsettings.go
@@ -123,6 +123,8 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
panels[panel.Id] = map[string]interface{}{
"module": panel.Module,
"name": panel.Name,
+ "id": panel.Id,
+ "info": panel.Info,
}
}
diff --git a/public/app/core/components/grafana_app.ts b/public/app/core/components/grafana_app.ts
index efcd1f2ec25..9b627e930a0 100644
--- a/public/app/core/components/grafana_app.ts
+++ b/public/app/core/components/grafana_app.ts
@@ -5,7 +5,7 @@ import store from 'app/core/store';
import _ from 'lodash';
import angular from 'angular';
import $ from 'jquery';
-import coreModule from '../core_module';
+import coreModule from 'app/core/core_module';
export class GrafanaCtrl {
diff --git a/public/app/core/filters/filters.ts b/public/app/core/filters/filters.ts
index 57b2b1bd9ba..6122a010182 100644
--- a/public/app/core/filters/filters.ts
+++ b/public/app/core/filters/filters.ts
@@ -59,11 +59,14 @@ coreModule.filter('noXml', function() {
coreModule.filter('interpolateTemplateVars', function (templateSrv) {
var filterFunc: any = function(text, scope) {
- if (scope.panel) {
- return templateSrv.replaceWithText(text, scope.panel.scopedVars);
+ var scopedVars;
+ if (scope.ctrl && scope.ctrl.panel) {
+ scopedVars = scope.ctrl.panel.scopedVars;
} else {
- return templateSrv.replaceWithText(text, scope.row.scopedVars);
+ scopedVars = scope.row.scopedVars;
}
+
+ return templateSrv.replaceWithText(text, scopedVars);
};
filterFunc.$stateful = true;
diff --git a/public/app/features/dashboard/rowCtrl.js b/public/app/features/dashboard/rowCtrl.js
index 3b178c4de26..e8abb5bbb05 100644
--- a/public/app/features/dashboard/rowCtrl.js
+++ b/public/app/features/dashboard/rowCtrl.js
@@ -116,36 +116,7 @@ function (angular, _, config) {
$scope.$broadcast('render');
};
- $scope.removePanel = function(panel) {
- $scope.appEvent('confirm-modal', {
- title: 'Are you sure you want to remove this panel?',
- icon: 'fa-trash',
- yesText: 'Delete',
- onConfirm: function() {
- $scope.row.panels = _.without($scope.row.panels, panel);
- }
- });
- };
-
- $scope.updatePanelSpan = function(panel, span) {
- panel.span = Math.min(Math.max(Math.floor(panel.span + span), 1), 12);
- };
-
- $scope.replacePanel = function(newPanel, oldPanel) {
- var row = $scope.row;
- var index = _.indexOf(row.panels, oldPanel);
- row.panels.splice(index, 1);
-
- // adding it back needs to be done in next digest
- $timeout(function() {
- newPanel.id = oldPanel.id;
- newPanel.span = oldPanel.span;
- row.panels.splice(index, 0, newPanel);
- });
- };
-
$scope.init();
-
});
module.directive('rowHeight', function() {
diff --git a/public/app/features/dashboard/shareModalCtrl.js b/public/app/features/dashboard/shareModalCtrl.js
index 336600975dc..0ba27ec6f5d 100644
--- a/public/app/features/dashboard/shareModalCtrl.js
+++ b/public/app/features/dashboard/shareModalCtrl.js
@@ -26,7 +26,7 @@ function (angular, _, require, config) {
$scope.modalTitle = 'Share Dashboard';
}
- if (!$scope.dashboardMeta.isSnapshot) {
+ if (!$scope.dashboard.meta.isSnapshot) {
$scope.tabs.push({title: 'Snapshot sharing', src: 'shareSnapshot.html'});
}
diff --git a/public/app/features/dashboard/viewStateSrv.js b/public/app/features/dashboard/viewStateSrv.js
index 58403766a31..abe1ec3279e 100644
--- a/public/app/features/dashboard/viewStateSrv.js
+++ b/public/app/features/dashboard/viewStateSrv.js
@@ -17,6 +17,7 @@ function (angular, _, $) {
self.state = {};
self.panelScopes = [];
self.$scope = $scope;
+ self.dashboard = $scope.dashboard;
$scope.exitFullscreen = function() {
if (self.state.fullscreen) {
@@ -31,6 +32,14 @@ function (angular, _, $) {
}
});
+ $scope.onAppEvent('panel-change-view', function(evt, payload) {
+ self.update(payload);
+ });
+
+ $scope.onAppEvent('panel-instantiated', function(evt, payload) {
+ self.registerPanel(payload.scope);
+ });
+
this.update(this.getQueryStringState(), true);
this.expandRowForPanel();
}
@@ -66,7 +75,7 @@ function (angular, _, $) {
DashboardViewState.prototype.update = function(state, skipUrlSync) {
_.extend(this.state, state);
- this.fullscreen = this.state.fullscreen;
+ this.dashboard.meta.fullscreen = this.state.fullscreen;
if (!this.state.fullscreen) {
this.state.panelId = null;
@@ -84,7 +93,7 @@ function (angular, _, $) {
DashboardViewState.prototype.syncState = function() {
if (this.panelScopes.length === 0) { return; }
- if (this.fullscreen) {
+ if (this.dashboard.meta.fullscreen) {
if (this.fullscreenPanel) {
this.leaveFullscreen(false);
}
@@ -105,23 +114,24 @@ function (angular, _, $) {
DashboardViewState.prototype.getPanelScope = function(id) {
return _.find(this.panelScopes, function(panelScope) {
- return panelScope.panel.id === id;
+ return panelScope.ctrl.panel.id === id;
});
};
DashboardViewState.prototype.leaveFullscreen = function(render) {
var self = this;
+ var ctrl = self.fullscreenPanel.ctrl;
- self.fullscreenPanel.editMode = false;
- self.fullscreenPanel.fullscreen = false;
- delete self.fullscreenPanel.height;
+ ctrl.editMode = false;
+ ctrl.fullscreen = false;
+ delete ctrl.height;
- this.$scope.appEvent('panel-fullscreen-exit', {panelId: this.fullscreenPanel.panel.id});
+ this.$scope.appEvent('panel-fullscreen-exit', {panelId: ctrl.panel.id});
if (!render) { return false;}
$timeout(function() {
- if (self.oldTimeRange !== self.fullscreenPanel.range) {
+ if (self.oldTimeRange !== ctrl.range) {
self.$scope.broadcastRefresh();
}
else {
@@ -135,17 +145,18 @@ function (angular, _, $) {
var docHeight = $(window).height();
var editHeight = Math.floor(docHeight * 0.3);
var fullscreenHeight = Math.floor(docHeight * 0.7);
+ var ctrl = panelScope.ctrl;
- panelScope.editMode = this.state.edit && this.$scope.dashboardMeta.canEdit;
- panelScope.height = panelScope.editMode ? editHeight : fullscreenHeight;
+ ctrl.editMode = this.state.edit && this.$scope.dashboardMeta.canEdit;
+ ctrl.height = ctrl.editMode ? editHeight : fullscreenHeight;
+ ctrl.fullscreen = true;
- this.oldTimeRange = panelScope.range;
+ this.oldTimeRange = ctrl.range;
this.fullscreenPanel = panelScope;
$(window).scrollTop(0);
- panelScope.fullscreen = true;
- this.$scope.appEvent('panel-fullscreen-enter', {panelId: panelScope.panel.id});
+ this.$scope.appEvent('panel-fullscreen-enter', {panelId: ctrl.panel.id});
$timeout(function() {
panelScope.$broadcast('render');
@@ -156,8 +167,12 @@ function (angular, _, $) {
var self = this;
self.panelScopes.push(panelScope);
- if (self.state.panelId === panelScope.panel.id) {
- self.enterFullscreen(panelScope);
+ if (self.state.panelId === panelScope.ctrl.panel.id) {
+ if (self.state.edit) {
+ panelScope.ctrl.editPanel();
+ } else {
+ panelScope.ctrl.viewPanel();
+ }
}
panelScope.$on('$destroy', function() {
diff --git a/public/app/features/panel/all.js b/public/app/features/panel/all.js
index ef3ea9b9b0f..ad635d83f07 100644
--- a/public/app/features/panel/all.js
+++ b/public/app/features/panel/all.js
@@ -6,4 +6,5 @@ define([
'./solo_panel_ctrl',
'./panel_loader',
'./query_editor',
+ './panel_editor_tab',
], function () {});
diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts
new file mode 100644
index 00000000000..896babade6d
--- /dev/null
+++ b/public/app/features/panel/metrics_panel_ctrl.ts
@@ -0,0 +1,234 @@
+///
|
-
- {{col.text}}
-
-
-
-
-
- |
-
|---|
|
+
+ {{col.text}}
+
+
+
+
+
+ |
+
|---|
Progress: {{progress}}%
- *= 100">Done processing {{label}} of Angular zone!
- * - *- * Use this API as the last resort when direct access to DOM is needed. Use templating and - * data-binding provided by Angular instead. Alternatively you take a look at {@link Renderer} - * which provides API that can safely be used even when direct access to native elements is not - * supported. - *
- *- * Relying on direct DOM access creates tight coupling between your application and rendering - * layers which will make it impossible to separate the two and deploy your application into a - * web worker. - *
- *Value = {{value}}
- *increment to start
- *0, increment again
- *1, increment again
- *2, stop incrementing
- *> 2, STOP!
- *- * increment to start - * 0, increment again - * 1, increment again - * 2, stop incrementing - * > 2, STOP! - *
- * `, - * directives: [NgSwitch, NgSwitchWhen, NgSwitchDefault] - * }) - * export class App { - * value = 'init'; - * - * inc() { - * this.value = this.value === 'init' ? 0 : this.value + 1; - * } - * } - * - * bootstrap(App).catch(err => console.error(err)); - * ``` - */ - var NgSwitch = (function () { - function NgSwitch() { - this._useDefault = false; - this._valueViews = new collection_1.Map(); - this._activeViews = []; - } - Object.defineProperty(NgSwitch.prototype, "ngSwitch", { - set: function (value) { - // Empty the currently active ViewContainers - this._emptyAllActiveViews(); - // Add the ViewContainers matching the value (with a fallback to default) - this._useDefault = false; - var views = this._valueViews.get(value); - if (lang_1.isBlank(views)) { - this._useDefault = true; - views = lang_1.normalizeBlank(this._valueViews.get(_WHEN_DEFAULT)); - } - this._activateViews(views); - this._switchValue = value; - }, - enumerable: true, - configurable: true - }); - /** @internal */ - NgSwitch.prototype._onWhenValueChanged = function (oldWhen, newWhen, view) { - this._deregisterView(oldWhen, view); - this._registerView(newWhen, view); - if (oldWhen === this._switchValue) { - view.destroy(); - collection_1.ListWrapper.remove(this._activeViews, view); - } - else if (newWhen === this._switchValue) { - if (this._useDefault) { - this._useDefault = false; - this._emptyAllActiveViews(); - } - view.create(); - this._activeViews.push(view); - } - // Switch to default when there is no more active ViewContainers - if (this._activeViews.length === 0 && !this._useDefault) { - this._useDefault = true; - this._activateViews(this._valueViews.get(_WHEN_DEFAULT)); - } - }; - /** @internal */ - NgSwitch.prototype._emptyAllActiveViews = function () { - var activeContainers = this._activeViews; - for (var i = 0; i < activeContainers.length; i++) { - activeContainers[i].destroy(); - } - this._activeViews = []; - }; - /** @internal */ - NgSwitch.prototype._activateViews = function (views) { - // TODO(vicb): assert(this._activeViews.length === 0); - if (lang_1.isPresent(views)) { - for (var i = 0; i < views.length; i++) { - views[i].create(); - } - this._activeViews = views; - } - }; - /** @internal */ - NgSwitch.prototype._registerView = function (value, view) { - var views = this._valueViews.get(value); - if (lang_1.isBlank(views)) { - views = []; - this._valueViews.set(value, views); - } - views.push(view); - }; - /** @internal */ - NgSwitch.prototype._deregisterView = function (value, view) { - // `_WHEN_DEFAULT` is used a marker for non-registered whens - if (value === _WHEN_DEFAULT) - return; - var views = this._valueViews.get(value); - if (views.length == 1) { - this._valueViews.delete(value); - } - else { - collection_1.ListWrapper.remove(views, view); - } - }; - NgSwitch = __decorate([ - core_1.Directive({ selector: '[ngSwitch]', inputs: ['ngSwitch'] }), - __metadata('design:paramtypes', []) - ], NgSwitch); - return NgSwitch; - })(); - exports.NgSwitch = NgSwitch; - /** - * Insert the sub-tree when the `ngSwitchWhen` expression evaluates to the same value as the - * enclosing switch expression. - * - * If multiple match expression match the switch expression value, all of them are displayed. - * - * See {@link NgSwitch} for more details and example. - */ - var NgSwitchWhen = (function () { - function NgSwitchWhen(viewContainer, templateRef, ngSwitch) { - // `_WHEN_DEFAULT` is used as a marker for a not yet initialized value - /** @internal */ - this._value = _WHEN_DEFAULT; - this._switch = ngSwitch; - this._view = new SwitchView(viewContainer, templateRef); - } - Object.defineProperty(NgSwitchWhen.prototype, "ngSwitchWhen", { - set: function (value) { - this._switch._onWhenValueChanged(this._value, value, this._view); - this._value = value; - }, - enumerable: true, - configurable: true - }); - NgSwitchWhen = __decorate([ - core_1.Directive({ selector: '[ngSwitchWhen]', inputs: ['ngSwitchWhen'] }), - __param(2, core_1.Host()), - __metadata('design:paramtypes', [core_1.ViewContainerRef, core_1.TemplateRef, NgSwitch]) - ], NgSwitchWhen); - return NgSwitchWhen; - })(); - exports.NgSwitchWhen = NgSwitchWhen; - /** - * Default case statements are displayed when no match expression matches the switch expression - * value. - * - * See {@link NgSwitch} for more details and example. - */ - var NgSwitchDefault = (function () { - function NgSwitchDefault(viewContainer, templateRef, sswitch) { - sswitch._registerView(_WHEN_DEFAULT, new SwitchView(viewContainer, templateRef)); - } - NgSwitchDefault = __decorate([ - core_1.Directive({ selector: '[ngSwitchDefault]' }), - __param(2, core_1.Host()), - __metadata('design:paramtypes', [core_1.ViewContainerRef, core_1.TemplateRef, NgSwitch]) - ], NgSwitchDefault); - return NgSwitchDefault; - })(); - exports.NgSwitchDefault = NgSwitchDefault; - - -/***/ }, -/* 121 */ -/***/ function(module, exports) { - - // TS does not have Observables - - -/***/ }, -/* 122 */ -/***/ function(module, exports, __webpack_require__) { - - var lang_1 = __webpack_require__(5); - var ng_class_1 = __webpack_require__(116); - var ng_for_1 = __webpack_require__(117); - var ng_if_1 = __webpack_require__(118); - var ng_style_1 = __webpack_require__(119); - var ng_switch_1 = __webpack_require__(120); - /** - * A collection of Angular core directives that are likely to be used in each and every Angular - * application. - * - * This collection can be used to quickly enumerate all the built-in directives in the `directives` - * property of the `@View` annotation. - * - * ### Example ([live demo](http://plnkr.co/edit/yakGwpCdUkg0qfzX5m8g?p=preview)) - * - * Instead of writing: - * - * ```typescript - * import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from 'angular2/common'; - * import {OtherDirective} from './myDirectives'; - * - * @Component({ - * selector: 'my-component', - * templateUrl: 'myComponent.html', - * directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, OtherDirective] - * }) - * export class MyComponent { - * ... - * } - * ``` - * one could import all the core directives at once: - * - * ```typescript - * import {CORE_DIRECTIVES} from 'angular2/common'; - * import {OtherDirective} from './myDirectives'; - * - * @Component({ - * selector: 'my-component', - * templateUrl: 'myComponent.html', - * directives: [CORE_DIRECTIVES, OtherDirective] - * }) - * export class MyComponent { - * ... - * } - * ``` - */ - exports.CORE_DIRECTIVES = lang_1.CONST_EXPR([ng_class_1.NgClass, ng_for_1.NgFor, ng_if_1.NgIf, ng_style_1.NgStyle, ng_switch_1.NgSwitch, ng_switch_1.NgSwitchWhen, ng_switch_1.NgSwitchDefault]); - - -/***/ }, -/* 123 */ -/***/ function(module, exports, __webpack_require__) { - - /** - * @module - * @description - * This module is used for handling user input, by defining and building a {@link ControlGroup} that - * consists of - * {@link Control} objects, and mapping them onto the DOM. {@link Control} objects can then be used - * to read information - * from the form DOM elements. - * - * This module is not included in the `angular2` module; you must import the forms module - * explicitly. - * - */ - var model_1 = __webpack_require__(124); - exports.AbstractControl = model_1.AbstractControl; - exports.Control = model_1.Control; - exports.ControlGroup = model_1.ControlGroup; - exports.ControlArray = model_1.ControlArray; - var abstract_control_directive_1 = __webpack_require__(125); - exports.AbstractControlDirective = abstract_control_directive_1.AbstractControlDirective; - var control_container_1 = __webpack_require__(126); - exports.ControlContainer = control_container_1.ControlContainer; - var ng_control_name_1 = __webpack_require__(127); - exports.NgControlName = ng_control_name_1.NgControlName; - var ng_form_control_1 = __webpack_require__(137); - exports.NgFormControl = ng_form_control_1.NgFormControl; - var ng_model_1 = __webpack_require__(138); - exports.NgModel = ng_model_1.NgModel; - var ng_control_1 = __webpack_require__(128); - exports.NgControl = ng_control_1.NgControl; - var ng_control_group_1 = __webpack_require__(139); - exports.NgControlGroup = ng_control_group_1.NgControlGroup; - var ng_form_model_1 = __webpack_require__(140); - exports.NgFormModel = ng_form_model_1.NgFormModel; - var ng_form_1 = __webpack_require__(141); - exports.NgForm = ng_form_1.NgForm; - var control_value_accessor_1 = __webpack_require__(129); - exports.NG_VALUE_ACCESSOR = control_value_accessor_1.NG_VALUE_ACCESSOR; - var default_value_accessor_1 = __webpack_require__(132); - exports.DefaultValueAccessor = default_value_accessor_1.DefaultValueAccessor; - var ng_control_status_1 = __webpack_require__(142); - exports.NgControlStatus = ng_control_status_1.NgControlStatus; - var checkbox_value_accessor_1 = __webpack_require__(134); - exports.CheckboxControlValueAccessor = checkbox_value_accessor_1.CheckboxControlValueAccessor; - var select_control_value_accessor_1 = __webpack_require__(135); - exports.NgSelectOption = select_control_value_accessor_1.NgSelectOption; - exports.SelectControlValueAccessor = select_control_value_accessor_1.SelectControlValueAccessor; - var directives_1 = __webpack_require__(143); - exports.FORM_DIRECTIVES = directives_1.FORM_DIRECTIVES; - var validators_1 = __webpack_require__(131); - exports.NG_VALIDATORS = validators_1.NG_VALIDATORS; - exports.NG_ASYNC_VALIDATORS = validators_1.NG_ASYNC_VALIDATORS; - exports.Validators = validators_1.Validators; - var validators_2 = __webpack_require__(144); - exports.RequiredValidator = validators_2.RequiredValidator; - exports.MinLengthValidator = validators_2.MinLengthValidator; - exports.MaxLengthValidator = validators_2.MaxLengthValidator; - var form_builder_1 = __webpack_require__(145); - exports.FormBuilder = form_builder_1.FormBuilder; - exports.FORM_PROVIDERS = form_builder_1.FORM_PROVIDERS; - exports.FORM_BINDINGS = form_builder_1.FORM_BINDINGS; - - -/***/ }, -/* 124 */ -/***/ function(module, exports, __webpack_require__) { - - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var lang_1 = __webpack_require__(5); - var async_1 = __webpack_require__(60); - var promise_1 = __webpack_require__(61); - var collection_1 = __webpack_require__(12); - /** - * Indicates that a Control is valid, i.e. that no errors exist in the input value. - */ - exports.VALID = "VALID"; - /** - * Indicates that a Control is invalid, i.e. that an error exists in the input value. - */ - exports.INVALID = "INVALID"; - /** - * Indicates that a Control is pending, i.e. that async validation is occuring and - * errors are not yet available for the input value. - */ - exports.PENDING = "PENDING"; - function isControl(control) { - return control instanceof AbstractControl; - } - exports.isControl = isControl; - function _find(control, path) { - if (lang_1.isBlank(path)) - return null; - if (!(path instanceof Array)) { - path = path.split("/"); - } - if (path instanceof Array && collection_1.ListWrapper.isEmpty(path)) - return null; - return path - .reduce(function (v, name) { - if (v instanceof ControlGroup) { - return lang_1.isPresent(v.controls[name]) ? v.controls[name] : null; - } - else if (v instanceof ControlArray) { - var index = name; - return lang_1.isPresent(v.at(index)) ? v.at(index) : null; - } - else { - return null; - } - }, control); - } - function toObservable(r) { - return promise_1.PromiseWrapper.isPromise(r) ? async_1.ObservableWrapper.fromPromise(r) : r; - } - /** - * - */ - var AbstractControl = (function () { - function AbstractControl(validator, asyncValidator) { - this.validator = validator; - this.asyncValidator = asyncValidator; - this._pristine = true; - this._touched = false; - } - Object.defineProperty(AbstractControl.prototype, "value", { - get: function () { return this._value; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "status", { - get: function () { return this._status; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "valid", { - get: function () { return this._status === exports.VALID; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "errors", { - /** - * Returns the errors of this control. - */ - get: function () { return this._errors; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "pristine", { - get: function () { return this._pristine; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "dirty", { - get: function () { return !this.pristine; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "touched", { - get: function () { return this._touched; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "untouched", { - get: function () { return !this._touched; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "valueChanges", { - get: function () { return this._valueChanges; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "statusChanges", { - get: function () { return this._statusChanges; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "pending", { - get: function () { return this._status == exports.PENDING; }, - enumerable: true, - configurable: true - }); - AbstractControl.prototype.markAsTouched = function () { this._touched = true; }; - AbstractControl.prototype.markAsDirty = function (_a) { - var onlySelf = (_a === void 0 ? {} : _a).onlySelf; - onlySelf = lang_1.normalizeBool(onlySelf); - this._pristine = false; - if (lang_1.isPresent(this._parent) && !onlySelf) { - this._parent.markAsDirty({ onlySelf: onlySelf }); - } - }; - AbstractControl.prototype.markAsPending = function (_a) { - var onlySelf = (_a === void 0 ? {} : _a).onlySelf; - onlySelf = lang_1.normalizeBool(onlySelf); - this._status = exports.PENDING; - if (lang_1.isPresent(this._parent) && !onlySelf) { - this._parent.markAsPending({ onlySelf: onlySelf }); - } - }; - AbstractControl.prototype.setParent = function (parent) { this._parent = parent; }; - AbstractControl.prototype.updateValueAndValidity = function (_a) { - var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent; - onlySelf = lang_1.normalizeBool(onlySelf); - emitEvent = lang_1.isPresent(emitEvent) ? emitEvent : true; - this._updateValue(); - this._errors = this._runValidator(); - this._status = this._calculateStatus(); - if (this._status == exports.VALID || this._status == exports.PENDING) { - this._runAsyncValidator(emitEvent); - } - if (emitEvent) { - async_1.ObservableWrapper.callEmit(this._valueChanges, this._value); - async_1.ObservableWrapper.callEmit(this._statusChanges, this._status); - } - if (lang_1.isPresent(this._parent) && !onlySelf) { - this._parent.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent }); - } - }; - AbstractControl.prototype._runValidator = function () { return lang_1.isPresent(this.validator) ? this.validator(this) : null; }; - AbstractControl.prototype._runAsyncValidator = function (emitEvent) { - var _this = this; - if (lang_1.isPresent(this.asyncValidator)) { - this._status = exports.PENDING; - this._cancelExistingSubscription(); - var obs = toObservable(this.asyncValidator(this)); - this._asyncValidationSubscription = - async_1.ObservableWrapper.subscribe(obs, function (res) { return _this.setErrors(res, { emitEvent: emitEvent }); }); - } - }; - AbstractControl.prototype._cancelExistingSubscription = function () { - if (lang_1.isPresent(this._asyncValidationSubscription)) { - async_1.ObservableWrapper.dispose(this._asyncValidationSubscription); - } - }; - /** - * Sets errors on a control. - * - * This is used when validations are run not automatically, but manually by the user. - * - * Calling `setErrors` will also update the validity of the parent control. - * - * ## Usage - * - * ``` - * var login = new Control("someLogin"); - * login.setErrors({ - * "notUnique": true - * }); - * - * expect(login.valid).toEqual(false); - * expect(login.errors).toEqual({"notUnique": true}); - * - * login.updateValue("someOtherLogin"); - * - * expect(login.valid).toEqual(true); - * ``` - */ - AbstractControl.prototype.setErrors = function (errors, _a) { - var emitEvent = (_a === void 0 ? {} : _a).emitEvent; - emitEvent = lang_1.isPresent(emitEvent) ? emitEvent : true; - this._errors = errors; - this._status = this._calculateStatus(); - if (emitEvent) { - async_1.ObservableWrapper.callEmit(this._statusChanges, this._status); - } - if (lang_1.isPresent(this._parent)) { - this._parent._updateControlsErrors(); - } - }; - AbstractControl.prototype.find = function (path) { return _find(this, path); }; - AbstractControl.prototype.getError = function (errorCode, path) { - if (path === void 0) { path = null; } - var control = lang_1.isPresent(path) && !collection_1.ListWrapper.isEmpty(path) ? this.find(path) : this; - if (lang_1.isPresent(control) && lang_1.isPresent(control._errors)) { - return collection_1.StringMapWrapper.get(control._errors, errorCode); - } - else { - return null; - } - }; - AbstractControl.prototype.hasError = function (errorCode, path) { - if (path === void 0) { path = null; } - return lang_1.isPresent(this.getError(errorCode, path)); - }; - /** @internal */ - AbstractControl.prototype._updateControlsErrors = function () { - this._status = this._calculateStatus(); - if (lang_1.isPresent(this._parent)) { - this._parent._updateControlsErrors(); - } - }; - /** @internal */ - AbstractControl.prototype._initObservables = function () { - this._valueChanges = new async_1.EventEmitter(); - this._statusChanges = new async_1.EventEmitter(); - }; - AbstractControl.prototype._calculateStatus = function () { - if (lang_1.isPresent(this._errors)) - return exports.INVALID; - if (this._anyControlsHaveStatus(exports.PENDING)) - return exports.PENDING; - if (this._anyControlsHaveStatus(exports.INVALID)) - return exports.INVALID; - return exports.VALID; - }; - return AbstractControl; - })(); - exports.AbstractControl = AbstractControl; - /** - * Defines a part of a form that cannot be divided into other controls. `Control`s have values and - * validation state, which is determined by an optional validation function. - * - * `Control` is one of the three fundamental building blocks used to define forms in Angular, along - * with {@link ControlGroup} and {@link ControlArray}. - * - * ## Usage - * - * By default, a `Control` is created for every `` or other form component. - * With {@link NgFormControl} or {@link NgFormModel} an existing {@link Control} can be - * bound to a DOM element instead. This `Control` can be configured with a custom - * validation function. - * - * ### Example ([live demo](http://plnkr.co/edit/23DESOpbNnBpBHZt1BR4?p=preview)) - */ - var Control = (function (_super) { - __extends(Control, _super); - function Control(value, validator, asyncValidator) { - if (value === void 0) { value = null; } - if (validator === void 0) { validator = null; } - if (asyncValidator === void 0) { asyncValidator = null; } - _super.call(this, validator, asyncValidator); - this._value = value; - this.updateValueAndValidity({ onlySelf: true, emitEvent: false }); - this._initObservables(); - } - /** - * Set the value of the control to `value`. - * - * If `onlySelf` is `true`, this change will only affect the validation of this `Control` - * and not its parent component. If `emitEvent` is `true`, this change will cause a - * `valueChanges` event on the `Control` to be emitted. Both of these options default to - * `false`. - * - * If `emitModelToViewChange` is `true`, the view will be notified about the new value - * via an `onChange` event. This is the default behavior if `emitModelToViewChange` is not - * specified. - */ - Control.prototype.updateValue = function (value, _a) { - var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent, emitModelToViewChange = _b.emitModelToViewChange; - emitModelToViewChange = lang_1.isPresent(emitModelToViewChange) ? emitModelToViewChange : true; - this._value = value; - if (lang_1.isPresent(this._onChange) && emitModelToViewChange) - this._onChange(this._value); - this.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent }); - }; - /** - * @internal - */ - Control.prototype._updateValue = function () { }; - /** - * @internal - */ - Control.prototype._anyControlsHaveStatus = function (status) { return false; }; - /** - * Register a listener for change events. - */ - Control.prototype.registerOnChange = function (fn) { this._onChange = fn; }; - return Control; - })(AbstractControl); - exports.Control = Control; - /** - * Defines a part of a form, of fixed length, that can contain other controls. - * - * A `ControlGroup` aggregates the values and errors of each {@link Control} in the group. Thus, if - * one of the controls in a group is invalid, the entire group is invalid. Similarly, if a control - * changes its value, the entire group changes as well. - * - * `ControlGroup` is one of the three fundamental building blocks used to define forms in Angular, - * along with {@link Control} and {@link ControlArray}. {@link ControlArray} can also contain other - * controls, but is of variable length. - * - * ### Example ([live demo](http://plnkr.co/edit/23DESOpbNnBpBHZt1BR4?p=preview)) - */ - var ControlGroup = (function (_super) { - __extends(ControlGroup, _super); - function ControlGroup(controls, optionals, validator, asyncValidator) { - if (optionals === void 0) { optionals = null; } - if (validator === void 0) { validator = null; } - if (asyncValidator === void 0) { asyncValidator = null; } - _super.call(this, validator, asyncValidator); - this.controls = controls; - this._optionals = lang_1.isPresent(optionals) ? optionals : {}; - this._initObservables(); - this._setParentForControls(); - this.updateValueAndValidity({ onlySelf: true, emitEvent: false }); - } - /** - * Add a control to this group. - */ - ControlGroup.prototype.addControl = function (name, control) { - this.controls[name] = control; - control.setParent(this); - }; - /** - * Remove a control from this group. - */ - ControlGroup.prototype.removeControl = function (name) { collection_1.StringMapWrapper.delete(this.controls, name); }; - /** - * Mark the named control as non-optional. - */ - ControlGroup.prototype.include = function (controlName) { - collection_1.StringMapWrapper.set(this._optionals, controlName, true); - this.updateValueAndValidity(); - }; - /** - * Mark the named control as optional. - */ - ControlGroup.prototype.exclude = function (controlName) { - collection_1.StringMapWrapper.set(this._optionals, controlName, false); - this.updateValueAndValidity(); - }; - /** - * Check whether there is a control with the given name in the group. - */ - ControlGroup.prototype.contains = function (controlName) { - var c = collection_1.StringMapWrapper.contains(this.controls, controlName); - return c && this._included(controlName); - }; - /** @internal */ - ControlGroup.prototype._setParentForControls = function () { - var _this = this; - collection_1.StringMapWrapper.forEach(this.controls, function (control, name) { control.setParent(_this); }); - }; - /** @internal */ - ControlGroup.prototype._updateValue = function () { this._value = this._reduceValue(); }; - /** @internal */ - ControlGroup.prototype._anyControlsHaveStatus = function (status) { - var _this = this; - var res = false; - collection_1.StringMapWrapper.forEach(this.controls, function (control, name) { - res = res || (_this.contains(name) && control.status == status); - }); - return res; - }; - /** @internal */ - ControlGroup.prototype._reduceValue = function () { - return this._reduceChildren({}, function (acc, control, name) { - acc[name] = control.value; - return acc; - }); - }; - /** @internal */ - ControlGroup.prototype._reduceChildren = function (initValue, fn) { - var _this = this; - var res = initValue; - collection_1.StringMapWrapper.forEach(this.controls, function (control, name) { - if (_this._included(name)) { - res = fn(res, control, name); - } - }); - return res; - }; - /** @internal */ - ControlGroup.prototype._included = function (controlName) { - var isOptional = collection_1.StringMapWrapper.contains(this._optionals, controlName); - return !isOptional || collection_1.StringMapWrapper.get(this._optionals, controlName); - }; - return ControlGroup; - })(AbstractControl); - exports.ControlGroup = ControlGroup; - /** - * Defines a part of a form, of variable length, that can contain other controls. - * - * A `ControlArray` aggregates the values and errors of each {@link Control} in the group. Thus, if - * one of the controls in a group is invalid, the entire group is invalid. Similarly, if a control - * changes its value, the entire group changes as well. - * - * `ControlArray` is one of the three fundamental building blocks used to define forms in Angular, - * along with {@link Control} and {@link ControlGroup}. {@link ControlGroup} can also contain - * other controls, but is of fixed length. - * - * ## Adding or removing controls - * - * To change the controls in the array, use the `push`, `insert`, or `removeAt` methods - * in `ControlArray` itself. These methods ensure the controls are properly tracked in the - * form's hierarchy. Do not modify the array of `AbstractControl`s used to instantiate - * the `ControlArray` directly, as that will result in strange and unexpected behavior such - * as broken change detection. - * - * ### Example ([live demo](http://plnkr.co/edit/23DESOpbNnBpBHZt1BR4?p=preview)) - */ - var ControlArray = (function (_super) { - __extends(ControlArray, _super); - function ControlArray(controls, validator, asyncValidator) { - if (validator === void 0) { validator = null; } - if (asyncValidator === void 0) { asyncValidator = null; } - _super.call(this, validator, asyncValidator); - this.controls = controls; - this._initObservables(); - this._setParentForControls(); - this.updateValueAndValidity({ onlySelf: true, emitEvent: false }); - } - /** - * Get the {@link AbstractControl} at the given `index` in the array. - */ - ControlArray.prototype.at = function (index) { return this.controls[index]; }; - /** - * Insert a new {@link AbstractControl} at the end of the array. - */ - ControlArray.prototype.push = function (control) { - this.controls.push(control); - control.setParent(this); - this.updateValueAndValidity(); - }; - /** - * Insert a new {@link AbstractControl} at the given `index` in the array. - */ - ControlArray.prototype.insert = function (index, control) { - collection_1.ListWrapper.insert(this.controls, index, control); - control.setParent(this); - this.updateValueAndValidity(); - }; - /** - * Remove the control at the given `index` in the array. - */ - ControlArray.prototype.removeAt = function (index) { - collection_1.ListWrapper.removeAt(this.controls, index); - this.updateValueAndValidity(); - }; - Object.defineProperty(ControlArray.prototype, "length", { - /** - * Length of the control array. - */ - get: function () { return this.controls.length; }, - enumerable: true, - configurable: true - }); - /** @internal */ - ControlArray.prototype._updateValue = function () { this._value = this.controls.map(function (control) { return control.value; }); }; - /** @internal */ - ControlArray.prototype._anyControlsHaveStatus = function (status) { - return this.controls.some(function (c) { return c.status == status; }); - }; - /** @internal */ - ControlArray.prototype._setParentForControls = function () { - var _this = this; - this.controls.forEach(function (control) { control.setParent(_this); }); - }; - return ControlArray; - })(AbstractControl); - exports.ControlArray = ControlArray; - - -/***/ }, -/* 125 */ -/***/ function(module, exports, __webpack_require__) { - - var lang_1 = __webpack_require__(5); - var exceptions_1 = __webpack_require__(14); - /** - * Base class for control directives. - * - * Only used internally in the forms module. - */ - var AbstractControlDirective = (function () { - function AbstractControlDirective() { - } - Object.defineProperty(AbstractControlDirective.prototype, "control", { - get: function () { return exceptions_1.unimplemented(); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "value", { - get: function () { return lang_1.isPresent(this.control) ? this.control.value : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "valid", { - get: function () { return lang_1.isPresent(this.control) ? this.control.valid : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "errors", { - get: function () { - return lang_1.isPresent(this.control) ? this.control.errors : null; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "pristine", { - get: function () { return lang_1.isPresent(this.control) ? this.control.pristine : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "dirty", { - get: function () { return lang_1.isPresent(this.control) ? this.control.dirty : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "touched", { - get: function () { return lang_1.isPresent(this.control) ? this.control.touched : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "untouched", { - get: function () { return lang_1.isPresent(this.control) ? this.control.untouched : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "path", { - get: function () { return null; }, - enumerable: true, - configurable: true - }); - return AbstractControlDirective; - })(); - exports.AbstractControlDirective = AbstractControlDirective; - - -/***/ }, -/* 126 */ -/***/ function(module, exports, __webpack_require__) { - - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var abstract_control_directive_1 = __webpack_require__(125); - /** - * A directive that contains multiple {@link NgControl}s. - * - * Only used by the forms module. - */ - var ControlContainer = (function (_super) { - __extends(ControlContainer, _super); - function ControlContainer() { - _super.apply(this, arguments); - } - Object.defineProperty(ControlContainer.prototype, "formDirective", { - /** - * Get the form to which this container belongs. - */ - get: function () { return null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ControlContainer.prototype, "path", { - /** - * Get the path to this container. - */ - get: function () { return null; }, - enumerable: true, - configurable: true - }); - return ControlContainer; - })(abstract_control_directive_1.AbstractControlDirective); - exports.ControlContainer = ControlContainer; - - -/***/ }, -/* 127 */ -/***/ function(module, exports, __webpack_require__) { - - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - }; - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - }; - var __param = (this && this.__param) || function (paramIndex, decorator) { - return function (target, key) { decorator(target, key, paramIndex); } - }; - var lang_1 = __webpack_require__(5); - var async_1 = __webpack_require__(60); - var core_1 = __webpack_require__(2); - var control_container_1 = __webpack_require__(126); - var ng_control_1 = __webpack_require__(128); - var control_value_accessor_1 = __webpack_require__(129); - var shared_1 = __webpack_require__(130); - var validators_1 = __webpack_require__(131); - var controlNameBinding = lang_1.CONST_EXPR(new core_1.Provider(ng_control_1.NgControl, { useExisting: core_1.forwardRef(function () { return NgControlName; }) })); - /** - * Creates and binds a control with a specified name to a DOM element. - * - * This directive can only be used as a child of {@link NgForm} or {@link NgFormModel}. - - * ### Example - * - * In this example, we create the login and password controls. - * We can work with each control separately: check its validity, get its value, listen to its - * changes. - * - * ``` - * @Component({ - * selector: "login-comp", - * directives: [FORM_DIRECTIVES], - * template: ` - * - * `}) - * class LoginComp { - * onLogIn(value): void { - * // value === {login: 'some login', password: 'some password'} - * } - * } - * ``` - * - * We can also use ngModel to bind a domain model to the form. - * - * ``` - * @Component({ - * selector: "login-comp", - * directives: [FORM_DIRECTIVES], - * template: ` - * - * `}) - * class LoginComp { - * credentials: {login:string, password:string}; - * - * onLogIn(): void { - * // this.credentials.login === "some login" - * // this.credentials.password === "some password" - * } - * } - * ``` - */ - var NgControlName = (function (_super) { - __extends(NgControlName, _super); - function NgControlName(_parent, _validators, _asyncValidators, valueAccessors) { - _super.call(this); - this._parent = _parent; - this._validators = _validators; - this._asyncValidators = _asyncValidators; - /** @internal */ - this.update = new async_1.EventEmitter(); - this._added = false; - this.valueAccessor = shared_1.selectValueAccessor(this, valueAccessors); - } - NgControlName.prototype.ngOnChanges = function (changes) { - if (!this._added) { - this.formDirective.addControl(this); - this._added = true; - } - if (shared_1.isPropertyUpdated(changes, this.viewModel)) { - this.viewModel = this.model; - this.formDirective.updateModel(this, this.model); - } - }; - NgControlName.prototype.ngOnDestroy = function () { this.formDirective.removeControl(this); }; - NgControlName.prototype.viewToModelUpdate = function (newValue) { - this.viewModel = newValue; - async_1.ObservableWrapper.callEmit(this.update, newValue); - }; - Object.defineProperty(NgControlName.prototype, "path", { - get: function () { return shared_1.controlPath(this.name, this._parent); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "formDirective", { - get: function () { return this._parent.formDirective; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "validator", { - get: function () { return shared_1.composeValidators(this._validators); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "asyncValidator", { - get: function () { return shared_1.composeAsyncValidators(this._asyncValidators); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "control", { - get: function () { return this.formDirective.getControl(this); }, - enumerable: true, - configurable: true - }); - NgControlName = __decorate([ - core_1.Directive({ - selector: '[ngControl]', - bindings: [controlNameBinding], - inputs: ['name: ngControl', 'model: ngModel'], - outputs: ['update: ngModelChange'], - exportAs: 'ngForm' - }), - __param(0, core_1.Host()), - __param(0, core_1.SkipSelf()), - __param(1, core_1.Optional()), - __param(1, core_1.Self()), - __param(1, core_1.Inject(validators_1.NG_VALIDATORS)), - __param(2, core_1.Optional()), - __param(2, core_1.Self()), - __param(2, core_1.Inject(validators_1.NG_ASYNC_VALIDATORS)), - __param(3, core_1.Optional()), - __param(3, core_1.Self()), - __param(3, core_1.Inject(control_value_accessor_1.NG_VALUE_ACCESSOR)), - __metadata('design:paramtypes', [control_container_1.ControlContainer, Array, Array, Array]) - ], NgControlName); - return NgControlName; - })(ng_control_1.NgControl); - exports.NgControlName = NgControlName; - - -/***/ }, -/* 128 */ -/***/ function(module, exports, __webpack_require__) { - - var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - var abstract_control_directive_1 = __webpack_require__(125); - var exceptions_1 = __webpack_require__(14); - /** - * A base class that all control directive extend. - * It binds a {@link Control} object to a DOM element. - * - * Used internally by Angular forms. - */ - var NgControl = (function (_super) { - __extends(NgControl, _super); - function NgControl() { - _super.apply(this, arguments); - this.name = null; - this.valueAccessor = null; - } - Object.defineProperty(NgControl.prototype, "validator", { - get: function () { return exceptions_1.unimplemented(); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControl.prototype, "asyncValidator", { - get: function () { return exceptions_1.unimplemented(); }, - enumerable: true, - configurable: true - }); - return NgControl; - })(abstract_control_directive_1.AbstractControlDirective); - exports.NgControl = NgControl; - - -/***/ }, -/* 129 */ -/***/ function(module, exports, __webpack_require__) { - - var core_1 = __webpack_require__(2); - var lang_1 = __webpack_require__(5); - /** - * Used to provide a {@link ControlValueAccessor} for form controls. - * - * See {@link DefaultValueAccessor} for how to implement one. - */ - exports.NG_VALUE_ACCESSOR = lang_1.CONST_EXPR(new core_1.OpaqueToken("NgValueAccessor")); - - -/***/ }, -/* 130 */ -/***/ function(module, exports, __webpack_require__) { - - var collection_1 = __webpack_require__(12); - var lang_1 = __webpack_require__(5); - var exceptions_1 = __webpack_require__(14); - var validators_1 = __webpack_require__(131); - var default_value_accessor_1 = __webpack_require__(132); - var number_value_accessor_1 = __webpack_require__(133); - var checkbox_value_accessor_1 = __webpack_require__(134); - var select_control_value_accessor_1 = __webpack_require__(135); - var normalize_validator_1 = __webpack_require__(136); - function controlPath(name, parent) { - var p = collection_1.ListWrapper.clone(parent.path); - p.push(name); - return p; - } - exports.controlPath = controlPath; - function setUpControl(control, dir) { - if (lang_1.isBlank(control)) - _throwError(dir, "Cannot find control"); - if (lang_1.isBlank(dir.valueAccessor)) - _throwError(dir, "No value accessor for"); - control.validator = validators_1.Validators.compose([control.validator, dir.validator]); - control.asyncValidator = validators_1.Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); - dir.valueAccessor.writeValue(control.value); - // view -> model - dir.valueAccessor.registerOnChange(function (newValue) { - dir.viewToModelUpdate(newValue); - control.updateValue(newValue, { emitModelToViewChange: false }); - control.markAsDirty(); - }); - // model -> view - control.registerOnChange(function (newValue) { return dir.valueAccessor.writeValue(newValue); }); - // touched - dir.valueAccessor.registerOnTouched(function () { return control.markAsTouched(); }); - } - exports.setUpControl = setUpControl; - function setUpControlGroup(control, dir) { - if (lang_1.isBlank(control)) - _throwError(dir, "Cannot find control"); - control.validator = validators_1.Validators.compose([control.validator, dir.validator]); - control.asyncValidator = validators_1.Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); - } - exports.setUpControlGroup = setUpControlGroup; - function _throwError(dir, message) { - var path = dir.path.join(" -> "); - throw new exceptions_1.BaseException(message + " '" + path + "'"); - } - function composeValidators(validators) { - return lang_1.isPresent(validators) ? validators_1.Validators.compose(validators.map(normalize_validator_1.normalizeValidator)) : null; - } - exports.composeValidators = composeValidators; - function composeAsyncValidators(validators) { - return lang_1.isPresent(validators) ? validators_1.Validators.composeAsync(validators.map(normalize_validator_1.normalizeValidator)) : null; - } - exports.composeAsyncValidators = composeAsyncValidators; - function isPropertyUpdated(changes, viewModel) { - if (!collection_1.StringMapWrapper.contains(changes, "model")) - return false; - var change = changes["model"]; - if (change.isFirstChange()) - return true; - return !lang_1.looseIdentical(viewModel, change.currentValue); - } - exports.isPropertyUpdated = isPropertyUpdated; - // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented - function selectValueAccessor(dir, valueAccessors) { - if (lang_1.isBlank(valueAccessors)) - return null; - var defaultAccessor; - var builtinAccessor; - var customAccessor; - valueAccessors.forEach(function (v) { - if (v instanceof default_value_accessor_1.DefaultValueAccessor) { - defaultAccessor = v; - } - else if (v instanceof checkbox_value_accessor_1.CheckboxControlValueAccessor || v instanceof number_value_accessor_1.NumberValueAccessor || - v instanceof select_control_value_accessor_1.SelectControlValueAccessor) { - if (lang_1.isPresent(builtinAccessor)) - _throwError(dir, "More than one built-in value accessor matches"); - builtinAccessor = v; - } - else { - if (lang_1.isPresent(customAccessor)) - _throwError(dir, "More than one custom value accessor matches"); - customAccessor = v; - } - }); - if (lang_1.isPresent(customAccessor)) - return customAccessor; - if (lang_1.isPresent(builtinAccessor)) - return builtinAccessor; - if (lang_1.isPresent(defaultAccessor)) - return defaultAccessor; - _throwError(dir, "No valid value accessor for"); - return null; - } - exports.selectValueAccessor = selectValueAccessor; - - -/***/ }, -/* 131 */ -/***/ function(module, exports, __webpack_require__) { - - var lang_1 = __webpack_require__(5); - var promise_1 = __webpack_require__(61); - var async_1 = __webpack_require__(60); - var collection_1 = __webpack_require__(12); - var core_1 = __webpack_require__(2); - /** - * Providers for validators to be used for {@link Control}s in a form. - * - * Provide this using `multi: true` to add validators. - * - * ### Example - * - * {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'} - */ - exports.NG_VALIDATORS = lang_1.CONST_EXPR(new core_1.OpaqueToken("NgValidators")); - /** - * Providers for asynchronous validators to be used for {@link Control}s - * in a form. - * - * Provide this using `multi: true` to add validators. - * - * See {@link NG_VALIDATORS} for more details. - */ - exports.NG_ASYNC_VALIDATORS = lang_1.CONST_EXPR(new core_1.OpaqueToken("NgAsyncValidators")); - /** - * Provides a set of validators used by form controls. - * - * A validator is a function that processes a {@link Control} or collection of - * controls and returns a map of errors. A null map means that validation has passed. - * - * ### Example - * - * ```typescript - * var loginControl = new Control("", Validators.required) - * ``` - */ - var Validators = (function () { - function Validators() { - } - /** - * Validator that requires controls to have a non-empty value. - */ - Validators.required = function (control) { - return lang_1.isBlank(control.value) || control.value == "" ? { "required": true } : null; - }; - /** - * Validator that requires controls to have a value of a minimum length. - */ - Validators.minLength = function (minLength) { - return function (control) { - if (lang_1.isPresent(Validators.required(control))) - return null; - var v = control.value; - return v.length < minLength ? - { "minlength": { "requiredLength": minLength, "actualLength": v.length } } : - null; - }; - }; - /** - * Validator that requires controls to have a value of a maximum length. - */ - Validators.maxLength = function (maxLength) { - return function (control) { - if (lang_1.isPresent(Validators.required(control))) - return null; - var v = control.value; - return v.length > maxLength ? - { "maxlength": { "requiredLength": maxLength, "actualLength": v.length } } : - null; - }; - }; - /** - * No-op validator. - */ - Validators.nullValidator = function (c) { return null; }; - /** - * Compose multiple validators into a single function that returns the union - * of the individual error maps. - */ - Validators.compose = function (validators) { - if (lang_1.isBlank(validators)) - return null; - var presentValidators = validators.filter(lang_1.isPresent); - if (presentValidators.length == 0) - return null; - return function (control) { - return _mergeErrors(_executeValidators(control, presentValidators)); - }; - }; - Validators.composeAsync = function (validators) { - if (lang_1.isBlank(validators)) - return null; - var presentValidators = validators.filter(lang_1.isPresent); - if (presentValidators.length == 0) - return null; - return function (control) { - var promises = _executeValidators(control, presentValidators).map(_convertToPromise); - return promise_1.PromiseWrapper.all(promises).then(_mergeErrors); - }; - }; - return Validators; - })(); - exports.Validators = Validators; - function _convertToPromise(obj) { - return promise_1.PromiseWrapper.isPromise(obj) ? obj : async_1.ObservableWrapper.toPromise(obj); - } - function _executeValidators(control, validators) { - return validators.map(function (v) { return v(control); }); - } - function _mergeErrors(arrayOfErrors) { - var res = arrayOfErrors.reduce(function (res, errors) { - return lang_1.isPresent(errors) ? collection_1.StringMapWrapper.merge(res, errors) : res; - }, {}); - return collection_1.StringMapWrapper.isEmpty(res) ? null : res; - } - - -/***/ }, -/* 132 */ -/***/ function(module, exports, __webpack_require__) { - - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - }; - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - }; - var core_1 = __webpack_require__(2); - var control_value_accessor_1 = __webpack_require__(129); - var lang_1 = __webpack_require__(5); - var DEFAULT_VALUE_ACCESSOR = lang_1.CONST_EXPR(new core_1.Provider(control_value_accessor_1.NG_VALUE_ACCESSOR, { useExisting: core_1.forwardRef(function () { return DefaultValueAccessor; }), multi: true })); - /** - * The default accessor for writing a value and listening to changes that is used by the - * {@link NgModel}, {@link NgFormControl}, and {@link NgControlName} directives. - * - * ### Example - * ``` - * - * ``` - */ - var DefaultValueAccessor = (function () { - function DefaultValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this.onChange = function (_) { }; - this.onTouched = function () { }; - } - DefaultValueAccessor.prototype.writeValue = function (value) { - var normalizedValue = lang_1.isBlank(value) ? '' : value; - this._renderer.setElementProperty(this._elementRef, 'value', normalizedValue); - }; - DefaultValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; }; - DefaultValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - DefaultValueAccessor = __decorate([ - core_1.Directive({ - selector: 'input:not([type=checkbox])[ngControl],textarea[ngControl],input:not([type=checkbox])[ngFormControl],textarea[ngFormControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]', - // TODO: vsavkin replace the above selector with the one below it once - // https://github.com/angular/angular/issues/3011 is implemented - // selector: '[ngControl],[ngModel],[ngFormControl]', - host: { '(input)': 'onChange($event.target.value)', '(blur)': 'onTouched()' }, - bindings: [DEFAULT_VALUE_ACCESSOR] - }), - __metadata('design:paramtypes', [core_1.Renderer, core_1.ElementRef]) - ], DefaultValueAccessor); - return DefaultValueAccessor; - })(); - exports.DefaultValueAccessor = DefaultValueAccessor; - - -/***/ }, -/* 133 */ -/***/ function(module, exports, __webpack_require__) { - - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - }; - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - }; - var core_1 = __webpack_require__(2); - var control_value_accessor_1 = __webpack_require__(129); - var lang_1 = __webpack_require__(5); - var NUMBER_VALUE_ACCESSOR = lang_1.CONST_EXPR(new core_1.Provider(control_value_accessor_1.NG_VALUE_ACCESSOR, { useExisting: core_1.forwardRef(function () { return NumberValueAccessor; }), multi: true })); - /** - * The accessor for writing a number value and listening to changes that is used by the - * {@link NgModel}, {@link NgFormControl}, and {@link NgControlName} directives. - * - * ### Example - * ``` - * - * ``` - */ - var NumberValueAccessor = (function () { - function NumberValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this.onChange = function (_) { }; - this.onTouched = function () { }; - } - NumberValueAccessor.prototype.writeValue = function (value) { - this._renderer.setElementProperty(this._elementRef, 'value', value); - }; - NumberValueAccessor.prototype.registerOnChange = function (fn) { - this.onChange = function (value) { fn(lang_1.NumberWrapper.parseFloat(value)); }; - }; - NumberValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - NumberValueAccessor = __decorate([ - core_1.Directive({ - selector: 'input[type=number][ngControl],input[type=number][ngFormControl],input[type=number][ngModel]', - host: { - '(change)': 'onChange($event.target.value)', - '(input)': 'onChange($event.target.value)', - '(blur)': 'onTouched()' - }, - bindings: [NUMBER_VALUE_ACCESSOR] - }), - __metadata('design:paramtypes', [core_1.Renderer, core_1.ElementRef]) - ], NumberValueAccessor); - return NumberValueAccessor; - })(); - exports.NumberValueAccessor = NumberValueAccessor; - - -/***/ }, -/* 134 */ -/***/ function(module, exports, __webpack_require__) { - - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - }; - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - }; - var core_1 = __webpack_require__(2); - var control_value_accessor_1 = __webpack_require__(129); - var lang_1 = __webpack_require__(5); - var CHECKBOX_VALUE_ACCESSOR = lang_1.CONST_EXPR(new core_1.Provider(control_value_accessor_1.NG_VALUE_ACCESSOR, { useExisting: core_1.forwardRef(function () { return CheckboxControlValueAccessor; }), multi: true })); - /** - * The accessor for writing a value and listening to changes on a checkbox input element. - * - * ### Example - * ``` - * - * ``` - */ - var CheckboxControlValueAccessor = (function () { - function CheckboxControlValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this.onChange = function (_) { }; - this.onTouched = function () { }; - } - CheckboxControlValueAccessor.prototype.writeValue = function (value) { - this._renderer.setElementProperty(this._elementRef, 'checked', value); - }; - CheckboxControlValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; }; - CheckboxControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - CheckboxControlValueAccessor = __decorate([ - core_1.Directive({ - selector: 'input[type=checkbox][ngControl],input[type=checkbox][ngFormControl],input[type=checkbox][ngModel]', - host: { '(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()' }, - bindings: [CHECKBOX_VALUE_ACCESSOR] - }), - __metadata('design:paramtypes', [core_1.Renderer, core_1.ElementRef]) - ], CheckboxControlValueAccessor); - return CheckboxControlValueAccessor; - })(); - exports.CheckboxControlValueAccessor = CheckboxControlValueAccessor; - - -/***/ }, -/* 135 */ -/***/ function(module, exports, __webpack_require__) { - - var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; - }; - var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); - }; - var __param = (this && this.__param) || function (paramIndex, decorator) { - return function (target, key) { decorator(target, key, paramIndex); } - }; - var core_1 = __webpack_require__(2); - var async_1 = __webpack_require__(60); - var control_value_accessor_1 = __webpack_require__(129); - var lang_1 = __webpack_require__(5); - var SELECT_VALUE_ACCESSOR = lang_1.CONST_EXPR(new core_1.Provider(control_value_accessor_1.NG_VALUE_ACCESSOR, { useExisting: core_1.forwardRef(function () { return SelectControlValueAccessor; }), multi: true })); - /** - * Marks `