Skip to content

Commit

Permalink
Fix remaining typechecks in gmf
Browse files Browse the repository at this point in the history
  • Loading branch information
adube committed Feb 6, 2019
1 parent 8f1a3a6 commit baf6df1
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 92 deletions.
1 change: 1 addition & 0 deletions contribs/gmf/src/authentication/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import olEventsEventTarget from 'ol/events/Target.js';
* @property {Array.<string>} default_theme Theme to use by default.
* @property {Array.<string>} [filtrable_layers] A list of layer names that can be filtered.
* @property location: {Array.<string>} Availables locations.
* @property {Array.<!string>} [open_panel] When set, contains the name of the panel to open upon loading an application.
*/


Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/controllers/AbstractAPIController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as olInteraction from 'ol/interaction.js';
*/
export class AbstractAPIController extends AbstractAppController {
/**
* @param {Config} config A part of the application config.
* @param {import('gmf/controllers/AbstractAppController.js').Config} config A part of the application
* @param {angular.IScope} $scope Scope.
* @param {angular.auto.IInjectorService} $injector Main injector.
* @ngInject
Expand Down
55 changes: 14 additions & 41 deletions contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import olStyleFill from 'ol/style/Fill.js';
import olStyleStroke from 'ol/style/Stroke.js';
import olStyleStyle from 'ol/style/Style.js';
import {ThemeEventType} from 'gmf/theme/Manager.js';
import gmfThemeThemes from 'gmf/theme/Themes.js';
import {findThemeByName} from 'gmf/theme/Themes.js';


/**
Expand All @@ -40,7 +40,7 @@ import gmfThemeThemes from 'gmf/theme/Themes.js';
* @property {import("ol/style/Style.js").default} [positionFeatureStyle]
* @property {import("ol/style/Style.js").default} [accuracyFeatureStyle]
* @property {number} [geolocationZoom]
* @property {string} [autorotate]
* @property {boolean|undefined} [autorotate]
* @property {olx.ViewOptions} [mapViewConfig]
* @property {import("ol/Collection.js").default.<import('ol/control/Control.js').default>|Array.<import('ol/control/Control.js').default>} [mapControls]
* @property {import("ol/Collection.js").default.<import('"ol/interaction/Interaction.js').default>|Array.<import('ol/interaction/Interaction.js').default>} [mapInteractions]
Expand All @@ -49,38 +49,6 @@ import gmfThemeThemes from 'gmf/theme/Themes.js';
*/


/**
* Static function to create a popup with html content.
* @typedef {Function} openTextPopup
* @param {string} content (text or html).
* @param {string} title (text).
* @param {string=} opt_width CSS width.
* @param {string=} opt_height CSS height.
* @param {boolean=} opt_apply If true, trigger the Angular digest loop. Default to true.
*/


/**
* Static function to create a popup with an iframe.
* @typedef {Function} openInfoWindow
* @param {string} url an url.
* @param {string} title (text).
* @param {string=} opt_width CSS width.
* @param {string=} opt_height CSS height.
* @param {boolean=} opt_apply If true, trigger the Angular digest loop. Default to true.
*/


/**
* @typedef {Function} openPopup_
* @param {import("ngeo/message/Popup.js").default!} popup a ngeoPopup.
* @param {string} title (text).
* @param {string=} opt_width CSS width.
* @param {string=} opt_height CSS height.
* @param {boolean=} opt_apply If true, trigger the Angular digest loop. Default to true.
*/


/**
* Application abstract controller.
*
Expand All @@ -105,6 +73,7 @@ export function AbstractAppController(config, map, $scope, $injector) {
this.ngeoLocation = $injector.get('ngeoLocation');
if (this.ngeoLocation.hasParam('debug')) {
// make the injector globally available
// @ts-ignore: available in debug mode only
window.injector = $injector;
}

Expand Down Expand Up @@ -223,11 +192,11 @@ export function AbstractAppController(config, map, $scope, $injector) {
});

/**
* @param {AuthenticationEvent} evt Event.
* @param {import('gmf/authentication/Service.js').AuthenticationEvent} evt Event.
*/
const userChange = (evt) => {
if (this.loginRedirectUrl) {
window.location = this.loginRedirectUrl;
window.location.href = this.loginRedirectUrl;
return;
}
const user = evt.detail.user;
Expand Down Expand Up @@ -265,6 +234,7 @@ export function AbstractAppController(config, map, $scope, $injector) {
* @export
*/
this.searchDatasources = [{
datasetTitle: undefined,
labelKey: 'label',
groupValues: /** @type {Array.<string>} **/ ($injector.get('gmfSearchGroups')),
groupActions: /** @type {Array.<string>} **/ ($injector.get('gmfSearchActions')),
Expand Down Expand Up @@ -432,7 +402,7 @@ export function AbstractAppController(config, map, $scope, $injector) {
this.gmfUser = $injector.get('gmfUser');

/**
* @type {miscGetBrowserLanguage}
* @type {import('ngeo/misc/getBrowserLanguage.js').miscGetBrowserLanguage}
*/
this.getBrowserLanguage = $injector.get('ngeoGetBrowserLanguage');

Expand All @@ -442,7 +412,7 @@ export function AbstractAppController(config, map, $scope, $injector) {
this.stateManager = $injector.get('ngeoStateManager');

/**
* @type {tmhDynamicLocale}
* @type {angular.dynamicLocale.tmhDynamicLocaleService}
*/
this.tmhDynamicLocale = $injector.get('tmhDynamicLocale');

Expand Down Expand Up @@ -591,6 +561,7 @@ export function AbstractAppController(config, map, $scope, $injector) {
/**
* @export
*/
// @ts-ignore: todo
window.gmfx = gmfx;

/**
Expand Down Expand Up @@ -643,6 +614,7 @@ export function AbstractAppController(config, map, $scope, $injector) {
/**
* @export
*/
// @ts-ignore: todo
window.cgxp = cgxp;
/**
* @export
Expand Down Expand Up @@ -810,7 +782,7 @@ AbstractAppController.prototype.updateCurrentTheme_ = function(fallbackThemeName
this.gmfThemes_.getThemesObject().then((themes) => {
const themeName = this.permalink_.defaultThemeNameFromFunctionalities();
if (themeName) {
const theme = gmfThemeThemes.findThemeByName(themes, /** @type {string} */ (themeName));
const theme = findThemeByName(themes, /** @type {string} */ (themeName));
if (theme) {
this.gmfThemeManager.addTheme(theme, true);
}
Expand All @@ -822,7 +794,7 @@ AbstractAppController.prototype.updateCurrentTheme_ = function(fallbackThemeName

/**
* @protected
* @return {Element} Span element with font-awesome inside of it
* @return {HTMLSpanElement} Span element with font-awesome inside of it
*/
export function getLocationIcon() {
const arrow = document.createElement('span');
Expand Down Expand Up @@ -868,7 +840,8 @@ module.value('ngeoExportFeatureFormats', [

module.config(['tmhDynamicLocaleProvider', 'angularLocaleScript',
/**
* @param {tmhDynamicLocaleProvider} tmhDynamicLocaleProvider angular-dynamic-locale provider.
* @param {angular.dynamicLocale.tmhDynamicLocaleProvider} tmhDynamicLocaleProvider
* angular-dynamic-locale provider.
* @param {string} angularLocaleScript the script.
*/
function(tmhDynamicLocaleProvider, angularLocaleScript) {
Expand Down
3 changes: 2 additions & 1 deletion contribs/gmf/src/controllers/AbstractDesktopController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import olStyleText from 'ol/style/Text.js';
*/
export class AbstractDesktopController extends AbstractAPIController {
/**
* @param {Config} config A part of the application config.
* @param {import('gmf/controllers/AbstractAppController.js').Config} config A part of the application
* config.
* @param {angular.IScope} $scope Scope.
* @param {angular.auto.IInjectorService} $injector Main injector.
* @ngInject
Expand Down
5 changes: 3 additions & 2 deletions contribs/gmf/src/controllers/AbstractMobileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import olStyleStyle from 'ol/style/Style.js';
*/
export class AbstractMobileController extends AbstractAppController {
/**
* @param {Config} config A part of the application config.
* @param {import('gmf/controllers/AbstractAppController.js').Config} config A part of the application
* config.
* @param {angular.IScope} $scope Scope.
* @param {angular.auto.IInjectorService} $injector Main injector.
* @ngInject
Expand Down Expand Up @@ -166,7 +167,7 @@ export class AbstractMobileController extends AbstractAppController {
openNavMenu(target) {
const navElements = document.getElementsByClassName('gmf-mobile-nav-button');
for (let i = 0; i < navElements.length; i++) {
const element = navElements[i];
const element = /** @type HTMLElement */ (navElements[i]);
if (element.dataset && element.dataset.target === target) {
element.click();
}
Expand Down
7 changes: 5 additions & 2 deletions contribs/gmf/src/controllers/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// FIXME DocumentTouch is deprecated, see:
// https://developer.mozilla.org/en-US/docs/Web/API/DocumentTouch
/* global DocumentTouch */

import $ from 'jquery';
import angular from 'angular';

function bootstrap(module) {
const interface_ = $('meta[name=interface]')[0].attributes.content.value;
const dynamicUrl_ = $('meta[name=dynamicUrl]')[0].attributes.content.value;
const interface_ = $('meta[name=interface]')[0].getAttribute('content');
const dynamicUrl_ = $('meta[name=dynamicUrl]')[0].getAttribute('content');
const dynamicUrl = `${dynamicUrl_}?interface=${interface_}&query=${encodeURIComponent(document.location.search)}`;
const request = $.ajax(dynamicUrl, {
'dataType': 'json',
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/datasource/ExternalDataSourcesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ export class ExternalDatSourcesManager {
* using the `ol.getUid` method, plus a million.
*
* @param {!Object} layer WMS/WMTS Capability Layer object.
* @return {string} Data source id.
* @return {number} Data source id.
* @export
*/
function getId(layer) {
return `${olUtilGetUid(layer)}+1000000`;
return Number(olUtilGetUid(layer)) + 1000000;
}


Expand Down
10 changes: 5 additions & 5 deletions contribs/gmf/src/datasource/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class DatasourceHelper {
// (2) The attribute names that are in the `enumeratedAttributes`
// metadata are the ones that need to have their values fetched.
// Do that once then set the type to SELECT and the choices.
const meta = dataSource.gmfLayer.metadata || {};
const enumAttributes = meta.enumeratedAttributes;
const enumAttributes = dataSource.gmfLayer.metadata ?
dataSource.gmfLayer.metadata.enumeratedAttributes : undefined;
if (enumAttributes && enumAttributes.length) {
const promises = [];
for (const attribute of attributes) {
Expand All @@ -114,9 +114,9 @@ export class DatasourceHelper {
);
}
}
return this.q_.all(promises).then(
prepareFiltrableDataSourceDefer.resolve(dataSource)
);
return this.q_.all(promises).then(() => {
prepareFiltrableDataSourceDefer.resolve(dataSource);
});
} else {
prepareFiltrableDataSourceDefer.resolve(dataSource);
}
Expand Down
35 changes: 20 additions & 15 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import olSourceTileWMS from 'ol/source/TileWMS.js';
* @property {Function} stateWatcherUnregister
* @property {Function} [timeLowerValueWatcherUnregister]
* @property {Function} [timeUpperValueWatcherUnregister]
* @property {ngeo.layertree.Controller} treeCtrl
* @property {import('ngeo/layertree/Controller.js').LayertreeController} treeCtrl
* @property {import("ol/layer/Image.js").default} [wmsLayer]
*/

Expand Down Expand Up @@ -248,9 +248,10 @@ export class DatasourceManager {

const dataSources = this.dataSources_.getArray();
for (const dataSource of dataSources) {
if (dataSource.dimensionsFiltersConfig) {
for (const key in dataSource.dimensionsFiltersConfig) {
if (dataSource.dimensionsFiltersConfig[key].value === null) {
const gmfOGCDataSource = /** @type import('gmf/datasource/OGC').default */ (dataSource);
if (gmfOGCDataSource.dimensionsFiltersConfig) {
for (const key in gmfOGCDataSource.dimensionsFiltersConfig) {
if (gmfOGCDataSource.dimensionsFiltersConfig[key].value === null) {
const layer = this.getDataSourceLayer_(dataSource);
if (layer == undefined) {
return;
Expand Down Expand Up @@ -347,7 +348,8 @@ export class DatasourceManager {
const visitor = (treeCtrls, treeCtrl) => {
const node = /** @type {!import('gmf/themes.js').GmfGroup|!import('gmf/themes.js').GmfLayer} */ (
treeCtrl.node);
const children = node.children;
const groupNode = /** @type {!import('gmf/themes.js').GmfGroup} */ (node);
const children = groupNode.children;
if (!children) {
treeCtrls.push(treeCtrl);
}
Expand Down Expand Up @@ -414,7 +416,8 @@ export class DatasourceManager {
*/
createDataSource_(firstLevelGroup, node, ogcServers) {

const children = node.children;
const groupNode = /** @type {!import('gmf/themes.js').GmfGroup} */ (node);
const children = groupNode.children;

// (1) Group node (node that has children). Loop in the children
// individually and create a data source for each one of them. The
Expand All @@ -431,7 +434,7 @@ export class DatasourceManager {
const gmfLayer = /** @type import('gmf/themes.js').GmfLayer */ (node);

// (2) Skip layer node if a data source with the same id exists
const id = olUtilGetUid(gmfLayer);
const id = Number(olUtilGetUid(gmfLayer));
if (this.dataSourcesCache_[id]) {
return;
}
Expand Down Expand Up @@ -531,7 +534,7 @@ export class DatasourceManager {
// (7) Dimensions
const dimensions = this.dimensions_;
const dimensionsConfig = node.dimensions || firstLevelGroup.dimensions;
const dimensionsFiltersConfig = node.dimensionsFilters;
const dimensionsFiltersConfig = gmfLayer.dimensionsFilters;

// (8) Time values (lower or lower/upper)
let timeLowerValue;
Expand Down Expand Up @@ -735,16 +738,16 @@ export class DatasourceManager {

/**
* Return the layer corresponding to the data source.
* @param {!import("ngeo/DataSource.js").default} dataSource The data source.
* @param {!import("ngeo/datasource/DataSource.js").default} dataSource The data source.
* @return {import("ol/layer/Base.js").default|undefined} The layer.
* @private
*/
getDataSourceLayer_(dataSource) {
dataSource = /** @type {!import("gmf/DataSource.js").default} */ (dataSource);
if (dataSource.gmfLayer == undefined) {
const gmfOGCDataSource = /** @type {!import("gmf/datasource/OGC.js").default} */ (dataSource);
if (gmfOGCDataSource.gmfLayer == undefined) {
return;
}
const id = olUtilGetUid(dataSource.gmfLayer);
const id = olUtilGetUid(gmfOGCDataSource.gmfLayer);
if (id == undefined) {
return;
}
Expand All @@ -768,7 +771,7 @@ export class DatasourceManager {
layer instanceof olLayerTile
);

const source = layer.getSource();
const source = /** @type {olLayerImage|olLayerTile} */ (layer).getSource();
if (!(source instanceof olSourceImageWMS ||
source instanceof olSourceTileWMS)) {
return;
Expand All @@ -791,11 +794,13 @@ export class DatasourceManager {
if (dsLayer == undefined) {
continue;
}
const gmfOGCDataSource = /** @type import('gmf/datasource/OGC.js').default */ (dataSource);
const gmfLayerWMS = /** @type import('gmf/themes.js').GmfLayerWMS */ (gmfOGCDataSource.gmfLayer);
if (olUtilGetUid(dsLayer) == olUtilGetUid(layer) &&
layer.get('querySourceIds').indexOf(dataSource.id) >= 0 &&
dataSource.gmfLayer.layers.split(',').indexOf(wmsLayerName) >= 0) {
gmfLayerWMS.layers.split(',').indexOf(wmsLayerName) >= 0) {

const id = olUtilGetUid(dataSource.gmfLayer);
const id = olUtilGetUid(gmfOGCDataSource.gmfLayer);
const item = this.treeCtrlCache_[id];
console.assert(item);
const treeCtrl = item.treeCtrl;
Expand Down

0 comments on commit baf6df1

Please sign in to comment.