Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directive to component for examples #3136

Merged
1 commit merged into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions examples/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,22 @@ app.module = angular.module('app', ['ngeo']);


/**
* App-specific directive wrapping the ngeo map directive. The directive's
* App-specific component wrapping the ngeo map component. The component's
* controller has a property "map" including a reference to the OpenLayers
* map.
*
* @return {angular.Directive} The directive specs.
* @ngInject
* @type {!angular.Component}
*/
app.mapDirective = function() {
return {
restrict: 'E',
scope: {
'map': '=appMap',
'class': '=appMapClass'
},
controller: () => {},
bindToController: true,
template: '<div ngeo-map="$ctrl.map"></div>'
};
app.mapComponent = {
bindings: {
'map': '=appMap',
'class': '=appMapClass'
},
template: '<div ngeo-map="$ctrl.map"></div>'
};


app.module.directive('appMap', app.mapDirective);
app.module.component('appMap', app.mapComponent);


/**
Expand Down
28 changes: 12 additions & 16 deletions examples/backgroundlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,29 @@ app.module = angular.module('app', ['ngeo']);


/**
* The application-specific background layer directive.
* The application-specific background layer component.
*
* The directive is based on Angular's select, ngOptions, ngModel, and
* ngChange directives. ngChange is used to avoid adding a watcher on
* The component is based on Angular's select, ngOptions, ngModel, and
* ngChange components. ngChange is used to avoid adding a watcher on
* the ngModel expression.
*
* Note: we don't need two-way binding for ngModel here, but using ::
* for the ngModel expression doesn't actually make a difference. This
* is because ngModel doesn't actually watch the ngModel expression.
*
* @return {angular.Directive} Directive Definition Object.
* @ngInject
* @type {!angular.Component}
*/
app.backgroundlayerDirective = function() {
return {
restrict: 'E',
scope: {
'map': '=appBackgroundlayerMap'
},
templateUrl: 'partials/backgroundlayer.html',
bindToController: true,
controller: 'AppBackgroundlayerController as ctrl'
};
app.backgroundlayerComponent = {
bindings: {
'map': '=appBackgroundlayerMap'
},
templateUrl: 'partials/backgroundlayer.html',
controller: 'AppBackgroundlayerController',
controllerAs: 'ctrl'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we remove that ? Then use "$ctrl" in the partial ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but then we need to update partials, I am not sure that it is critical and/or should be done in that PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not critical. That's why we'll probably never do that if we don't do that right now.
But it's not really important. If you think it takes too much time to do the change (and test) leave it like that :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine to leave as it for the examples but it would be nice to do it the all the ngeo and gmf components (in the others pull requests).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it as another PR on monday

};


app.module.directive('appBackgroundlayer', app.backgroundlayerDirective);
app.module.component('appBackgroundlayer', app.backgroundlayerComponent);


/**
Expand Down
26 changes: 11 additions & 15 deletions examples/backgroundlayerdropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@ app.module = angular.module('app', ['ngeo']);


/**
* The application-specific background layer directive.
* The application-specific background layer component.
*
* The directive is based on Bootstrap's dropdown jQuery plugin and on
* The component is based on Bootstrap's dropdown jQuery plugin and on
* the ngeoBackgroundLayerMgr service.
*
* @return {angular.Directive} Directive Definition Object.
* @ngInject
* @type {!angular.Component}
*/
app.backgroundlayerDirective = function() {
return {
restrict: 'E',
scope: {
'map': '=appBackgroundlayerMap'
},
templateUrl: 'partials/backgroundlayerdropdown.html',
bindToController: true,
controller: 'AppBackgroundlayerController as ctrl'
};
app.backgroundlayerComponent = {
bindings: {
'map': '=appBackgroundlayerMap'
},
templateUrl: 'partials/backgroundlayerdropdown.html',
controller: 'AppBackgroundlayerController',
controllerAs: 'ctrl'
Copy link
Member

@ger-benjamin ger-benjamin Nov 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same (etc. please verify also in other components)

};


app.module.directive('appBackgroundlayer', app.backgroundlayerDirective);
app.module.component('appBackgroundlayer', app.backgroundlayerComponent);


/**
Expand Down
19 changes: 7 additions & 12 deletions examples/bboxquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,17 @@ app.module.value('ngeoQueryOptions', {


/**
* A sample directive to display the result.
* A sample component to display the result.
*
* @return {angular.Directive} The directive specs.
* @ngInject
* @type {!angular.Component}
*/
app.queryresultDirective = function() {
return {
restrict: 'E',
scope: {},
controller: 'AppQueryresultController as qrCtrl',
bindToController: true,
templateUrl: 'partials/queryresult.html'
};
app.queryresultComponent = {
controller: 'AppQueryresultController',
controllerAs: 'qrCtrl',
templateUrl: 'partials/queryresult.html'
};

app.module.directive('appQueryresult', app.queryresultDirective);
app.module.component('appQueryresult', app.queryresultComponent);


/**
Expand Down
21 changes: 8 additions & 13 deletions examples/colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ app.module = angular.module('app', ['ngeo']);


/**
* The application-specific color picker directive, based on the
* ngeo-colorpicker directive.
* The application-specific color picker component, based on the
* ngeo-colorpicker component.
*
* @return {angular.Directive} Directive Definition Object.
* @ngInject
* @type {!angular.Component}
*/
app.colorpickerDirective = function() {
return {
restrict: 'E',
scope: true,
template: '<div ngeo-colorpicker="ctrl.colors" ngeo-colorpicker-color="mainCtrl.color"></div>',
bindToController: true,
controller: 'AppColorpickerController as ctrl'
};
app.colorpickerComponent = {
template: '<div ngeo-colorpicker="ctrl.colors" ngeo-colorpicker-color="mainCtrl.color"></div>',
controller: 'AppColorpickerController',
controllerAs: 'ctrl'
};


app.module.directive('appColorpicker', app.colorpickerDirective);
app.module.component('appColorpicker', app.colorpickerComponent);


/**
Expand Down
41 changes: 19 additions & 22 deletions examples/layertree.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,29 @@ app.module = angular.module('app', ['ngeo']);


/**
* An application-specific directive wrapping the ngeo tree layer directive.
* The directive includes a controller defining the tree tree.
* @return {angular.Directive} The Directive Definition Object.
* @ngInject
* An application-specific component wrapping the ngeo tree layer component.
* The component includes a controller defining the tree tree.
*
* @type {!angular.Component}
*/
app.layertreeDirective = function() {
return {
restrict: 'E',
scope: {
'map': '=appLayertreeMap'
},
controller: 'AppLayertreeController as ctrl',
bindToController: true,
// use "::ctrl.tree" for the "tree" expression as we know the
// layer tree won't change
template:
'<div ngeo-layertree="::ctrl.tree" ' +
'ngeo-layertree-templateurl="partials/layertree.html" ' +
'ngeo-layertree-map="ctrl.map" ' +
'ngeo-layertree-nodelayer="ctrl.getLayer(node)">' +
'</div>'
};
app.layertreeComponent = {
bindings: {
'map': '=appLayertreeMap'
},
controller: 'AppLayertreeController',
controllerAs: 'ctrl',
// use "::ctrl.tree" for the "tree" expression as we know the
// layer tree won't change
template:
'<div ngeo-layertree="::ctrl.tree" ' +
'ngeo-layertree-templateurl="partials/layertree.html" ' +
'ngeo-layertree-map="ctrl.map" ' +
'ngeo-layertree-nodelayer="ctrl.getLayer(node)">' +
'</div>'
};


app.module.directive('appLayertree', app.layertreeDirective);
app.module.component('appLayertree', app.layertreeComponent);


/**
Expand Down
30 changes: 13 additions & 17 deletions examples/locationsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@ app.module = angular.module('app', [ngeo.module.name]);


/**
* @return {angular.Directive} Directive Definition Object.
* @ngInject
* @type {!angular.Component}
*/
app.locationSearchDirective = function() {
return {
restrict: 'E',
scope: {
'map': '=appSearchMap'
},
controller: 'AppSearchController as ctrl',
bindToController: true,
template:
'<input type="text" placeholder="Search…" ' +
'ngeo-search="ctrl.options" ' +
'ngeo-search-datasets="ctrl.datasets" ' +
'ngeo-search-listeners="ctrl.listeners">'
};
app.locationSearchComponent = {
bindings: {
'map': '=appSearchMap'
},
controller: 'AppSearchController',
controllerAs: 'ctrl',
template:
'<input type="text" placeholder="Search…" ' +
'ngeo-search="ctrl.options" ' +
'ngeo-search-datasets="ctrl.datasets" ' +
'ngeo-search-listeners="ctrl.listeners">'
};


app.module.directive('appLocationSearch', app.locationSearchDirective);
app.module.component('appLocationSearch', app.locationSearchComponent);


/**
Expand Down
19 changes: 7 additions & 12 deletions examples/mapquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,17 @@ app.module.value('ngeoQueryOptions', {


/**
* A sample directive to display the result.
* A sample component to display the result.
*
* @return {angular.Directive} The directive specs.
* @ngInject
* @type {!angular.Component}
*/
app.queryresultDirective = function() {
return {
restrict: 'E',
scope: {},
controller: 'AppQueryresultController as qrCtrl',
bindToController: true,
templateUrl: 'partials/queryresult.html'
};
app.queryresultComponent = {
controller: 'AppQueryresultController',
controllerAs: 'qrCtrl',
templateUrl: 'partials/queryresult.html'
};

app.module.directive('appQueryresult', app.queryresultDirective);
app.module.component('appQueryresult', app.queryresultComponent);


/**
Expand Down
2 changes: 1 addition & 1 deletion examples/measure.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</head>
<body ng-controller="MainController as ctrl">
<div id="map" ngeo-map="::ctrl.map"></div>
<div app-measuretools app-measuretools-map="::ctrl.map" app-measuretools-lang="ctrl.lang"></div>
<app-measuretools app-measuretools-map="::ctrl.map" app-measuretools-lang="ctrl.lang"></app-measuretools>
<p>Use the following selector to change the language used for the measure tooltips.</p>
<label>Select language:</label>
<select ng-options="lang for lang in ['en', 'fr']" ng-model="ctrl.lang"></select>
Expand Down
37 changes: 12 additions & 25 deletions examples/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,23 @@ app.module = angular.module('app', ['ngeo']);


/**
* App-specific directive wrapping the measure tools. The directive's
* App-specific component wrapping the measure tools. The component's
* controller has a property "map" including a reference to the OpenLayers
* map.
*
* @return {angular.Directive} The directive specs.
* @ngInject
* @type {!angular.Component}
*/
app.measuretoolsDirective = function() {
return {
restrict: 'A',
scope: {
'map': '=appMeasuretoolsMap',
'lang': '=appMeasuretoolsLang'
},
controller: 'AppMeasuretoolsController as ctrl',
bindToController: true,
templateUrl: 'partials/measuretools.html',
/**
* @param {angular.Scope} scope Scope.
* @param {angular.JQLite} element Element.
* @param {angular.Attributes} attrs Attributes.
* @param {app.MeasuretoolsController} controller Controller.
*/
link: (scope, element, attrs, controller) => {
controller.init();
}
};
app.measuretoolsComponent = {
bindings: {
'map': '=appMeasuretoolsMap',
'lang': '=appMeasuretoolsLang'
},
controller: 'AppMeasuretoolsController',
controllerAs: 'ctrl',
templateUrl: 'partials/measuretools.html'
};

app.module.directive('appMeasuretools', app.measuretoolsDirective);
app.module.component('appMeasuretools', app.measuretoolsComponent);


/**
Expand Down Expand Up @@ -225,7 +212,7 @@ app.MeasuretoolsController = function($scope, $compile, $sce,

app.module.controller('AppMeasuretoolsController', app.MeasuretoolsController);

app.MeasuretoolsController.prototype.init = function() {
app.MeasuretoolsController.prototype.$onInit = function() {
this.map.addInteraction(this.measureLength);
this.map.addInteraction(this.measureArea);
this.map.addInteraction(this.measureAzimut);
Expand Down
Loading