diff --git a/src/app/api.js b/src/app/api.js index 4896ec724..a0ad288d5 100644 --- a/src/app/api.js +++ b/src/app/api.js @@ -2,38 +2,39 @@ * @file api file interface for external plugins */ -import G3W_CONSTANT from 'constant'; +import G3W_CONSTANT from 'constant'; -import ApplicationState from 'store/application-state'; -import ApplicationService from 'services/application'; +import GUI from 'services/gui'; + +import ApplicationState from 'store/application-state'; +import ApplicationService from 'services/application'; /** * Single File Components */ -import G3WInput from 'components/InputG3W.vue'; -import G3wFormInputs from 'components/InputG3WFormInputs.vue'; -import FormBody from 'components/FormBody.vue'; -import FormFooter from 'components/FormFooter.vue'; -import C3XYLine from 'components/C3XYLine.vue'; +import G3WInput from 'components/InputG3W.vue'; +import G3wFormInputs from 'components/InputG3WFormInputs.vue'; +import FormBody from 'components/FormBody.vue'; +import FormFooter from 'components/FormFooter.vue'; +import C3XYLine from 'components/C3XYLine.vue'; +import G3WField from 'components/FieldG3W.vue'; /** * CORE modules */ -import CatalogLayersStoresRegistry from 'store/catalog-layers'; -import DataRouterService from 'services/data'; -import IFrameRouterService from 'services/iframe'; -import MapLayersStoresRegistry from 'store/map-layers'; -import PluginsRegistry from 'store/plugins'; -import ProjectsRegistry from 'store/projects'; -import RelationsService from 'services/relations'; -import TaskService from 'services/tasks'; -import WorkflowsStack from 'services/workflows'; -import ApiService from 'services/api'; -import RouterService from 'services/router'; +import CatalogLayersStoresRegistry from 'store/catalog-layers'; +import DataRouterService from 'services/data'; +import IFrameRouterService from 'services/iframe'; +import MapLayersStoresRegistry from 'store/map-layers'; +import PluginsRegistry from 'store/plugins'; +import ProjectsRegistry from 'store/projects'; +import RelationsService from 'services/relations'; +import TaskService from 'services/tasks'; +import WorkflowsStack from 'services/workflows'; +import ApiService from 'services/api'; +import RouterService from 'services/router'; -import GUI from 'services/gui'; -//MIXINS -import Mixins from 'mixins'; +import Mixins from 'mixins'; import { reverseGeometry } from 'utils/reverseGeometry'; import { getExtentForViewAndSize } from 'utils/getExtentForViewAndSize'; @@ -54,67 +55,77 @@ import { getResolutionFromScale } from 'utils/getResolutionFromScale'; import { getScaleFromResolution } from 'utils/getScaleFromResolution'; import { mergeOptions } from 'utils/mergeOptions'; -const G3WObject = require('core/g3wobject'); -const utils = require('utils'); -const geoutils = require('utils/geo'); -const i18n = require('core/i18n/i18n.service'); -const Server = require('core/errors/parser/servererrorparser'); -const Geom = require('utils/geo'); -const { Geometry } = require('utils/geo'); -const Project = require('core/project/project'); -const LayersStoreRegistry = require('core/layers/layersstoresregistry'); -const LayersStore = require('core/layers/layersstore'); -const Layer = require('core/layers/layer'); -const LayerFactory = require('core/layers/layerfactory'); -const TableLayer = require('core/layers/tablelayer'); -const VectorLayer = require('core/layers/vectorlayer'); -const ImageLayer = require('core/layers/imagelayer'); -const WmsLayer = require('core/layers/map/wmslayer'); -const XYZLayer = require('core/layers/map/xyzlayer'); -const MapLayer = require('core/layers/map/maplayer'); -const Feature = require('core/layers/features/feature'); -const FeaturesStore = require('core/layers/features/featuresstore'); -const OlFeaturesStore = require('core/layers/features/olfeaturesstore'); -const Filter = require('core/layers/filter/filter'); -const Expression = require('core/layers/filter/expression'); -const Plugin = require('core/plugin/plugin'); -const PluginService = require('core/plugin/pluginservice'); -const Task = require('core/workflow/task'); -const Step = require('core/workflow/step'); -const Flow = require('core/workflow/flow'); -const Workflow = require('core/workflow/workflow'); +import G3WObject from 'core/g3wobject'; +import LayersStoreRegistry from 'core/layers/layersstoresregistry'; + +const utils = require('core/utils/utils'); +const geoutils = require('core/utils/geo'); +const i18n = require('core/i18n/i18n.service'); +const Server = require('core/errors/parser/servererrorparser'); +const Session = require('core/editing/session'); +const Editor = require('core/editing/editor'); +const Geom = require('core/utils/geo'); +const { Geometry } = require('core/utils/geo'); +const Project = require('core/project/project'); +const LayersStore = require('core/layers/layersstore'); +const Layer = require('core/layers/layer'); +const LayerFactory = require('core/layers/layerfactory'); +const TableLayer = require('core/layers/tablelayer'); +const VectorLayer = require('core/layers/vectorlayer'); +const ImageLayer = require('core/layers/imagelayer'); +const WmsLayer = require('core/layers/map/wmslayer'); +const XYZLayer = require('core/layers/map/xyzlayer'); +const MapLayer = require('core/layers/map/maplayer'); +const Feature = require('core/layers/features/feature'); +const FeaturesStore = require('core/layers/features/featuresstore'); +const OlFeaturesStore = require('core/layers/features/olfeaturesstore'); +const Filter = require('core/layers/filter/filter'); +const Expression = require('core/layers/filter/expression'); +const Plugin = require('core/plugin/plugin'); +const PluginService = require('core/plugin/pluginservice'); +const Task = require('core/workflow/task'); +const Step = require('core/workflow/step'); +const Flow = require('core/workflow/flow'); +const Workflow = require('core/workflow/workflow'); /** * GUI modules */ -const Panel = require('gui/panel'); -const { ControlFactory } = require('gui/map/mapservice'); -const ComponentsFactory = require('gui/component/componentsfactory'); -const FieldsService = require('gui/fields/fieldsservice'); -const Component = require('gui/component/component'); -const MetadataComponent = require('gui/metadata/vue/metadata'); -const SearchComponent = require('gui/search/vue/search'); -const SearchPanel = require('gui/search/vue/panel/searchpanel'); -const PrintComponent = require('gui/print/vue/print'); -const CatalogComponent = require('gui/catalog/vue/catalog'); -const MapComponent = require('gui/map/vue/map'); -const ToolsComponent = require('gui/tools/vue/tools'); -const QueryResultsComponent = require('gui/queryresults/vue/queryresults'); -const FormComponent = require('gui/form/vue/form'); -const FormService = require('gui/form/formservice'); -const InputsComponents = require('gui/inputs/inputs'); -const ChartsFactory = require('gui/charts/chartsfactory'); -const Fields = require('gui/fields/fields'); -const SearchPanelService = require('gui/search/vue/panel/searchservice'); +const Panel = require('gui/panel'); +const { ControlFactory } = require('gui/map/mapservice'); +const ComponentsFactory = require('gui/component/componentsfactory'); +const FieldsService = Mixins.fieldsMixin.methods.getFieldService(); +const Component = require('gui/component/component'); +const MetadataComponent = require('gui/metadata/vue/metadata'); +const SearchComponent = require('gui/search/vue/search'); +const SearchPanel = require('gui/search/vue/panel/searchpanel'); +const PrintComponent = require('gui/print/vue/print'); +const CatalogComponent = require('gui/catalog/vue/catalog'); +const MapComponent = require('gui/map/vue/map'); +const ToolsComponent = require('gui/tools/vue/tools'); +const QueryResultsComponent = require('gui/queryresults/vue/queryresults'); +const FormComponent = require('gui/form/vue/form'); +const FormService = require('gui/form/formservice'); +const ChartsFactory = require('gui/charts/chartsfactory'); +const Fields = G3WField.components; +const InputsComponents = G3WInput.components; +const SearchPanelService = require('gui/search/vue/panel/searchservice'); /** * G3W-OL modules */ -const PickFeatureInteraction = require('g3w-ol/interactions/pickfeatureinteraction'); -const PickCoordinatesInteraction = require('g3w-ol/interactions/pickcoordinatesinteraction'); -const DeleteFeatureInteraction = require('g3w-ol/interactions/deletefeatureinteraction'); -const AreaInteraction = require('g3w-ol/interactions/areainteraction'); -const LengthInteraction = require('g3w-ol/interactions/lengthinteraction'); +const PickFeatureInteraction = require('g3w-ol/interactions/pickfeatureinteraction'); +const PickCoordinatesInteraction = require('g3w-ol/interactions/pickcoordinatesinteraction'); +const DeleteFeatureInteraction = require('g3w-ol/interactions/deletefeatureinteraction'); +const AreaInteraction = require('g3w-ol/interactions/areainteraction'); +const LengthInteraction = require('g3w-ol/interactions/lengthinteraction'); + +/** + * Test assertions + */ +console.assert(undefined !== InputsComponents, 'InputsComponents is undefined'); +console.assert(undefined !== FieldsService, 'FieldsService is undefined'); +console.assert(undefined !== Fields, 'Fields is undefined'); module.exports = { @@ -229,9 +240,7 @@ module.exports = { MapComponent, ToolsComponent, QueryResultsComponent, - // main Form Component FormComponent, - // Form Components FormComponents: { Body: FormBody, Footer: FormFooter diff --git a/src/app/constant.js b/src/app/constant.js index 9a6801785..d7922bc1c 100644 --- a/src/app/constant.js +++ b/src/app/constant.js @@ -444,125 +444,125 @@ export const API_BASE_URLS = { * @since v3.8 */ export const FONT_AWESOME_ICONS = { - 'change-map': "fas fa-map-signs", - map: "far fa-map", - file: "fas fa-file-code", - marker: "fas fa-map-marker-alt", - relation: "fas fa-sitemap", - tools: "fas fa-cogs", - tool: "fas fa-cog", - search: "fas fa-search", - print: "fas fa-print", - info: "fas fa-info-circle", - 'info-circle': "fas fa-info-circle", - globe: "fas fa-globe", - mail: "fas fa-envelope", - mobile: "fas fa-mobile", - fax: "fas fa-fax", - user: "fas fa-user", - bars: "fas fa-bars", - uncheck: "far fa-square", - check: "far fa-check-square", - filluncheck: "fas fa-square", - table: "fas fa-table", - trash: "fas fa-trash", - 'trash-o':"far fa-trash-alt", - pencil: "fas fa-pencil-alt", - 'ellips-h': "fas fa-ellipsis-h", - 'ellips-v': "fas fa-ellipsis-v", - 'arrow-up': "fas fa-chevron-up", - 'arrow-down': "fas fa-chevron-down", - 'arrow-left': "fas fa-chevron-left", - 'arrow-right': "fas fa-chevron-right", - 'resize-h': "fas fa-arrows-alt-h", - 'resize-v': "fas fa-arrows-alt-v", + 'change-map': "fas fa-map-signs", + map: "far fa-map", + file: "fas fa-file-code", + marker: "fas fa-map-marker-alt", + relation: "fas fa-sitemap", + tools: "fas fa-cogs", + tool: "fas fa-cog", + search: "fas fa-search", + print: "fas fa-print", + info: "fas fa-info-circle", + 'info-circle': "fas fa-info-circle", + globe: "fas fa-globe", + mail: "fas fa-envelope", + mobile: "fas fa-mobile", + fax: "fas fa-fax", + user: "fas fa-user", + bars: "fas fa-bars", + uncheck: "far fa-square", + check: "far fa-check-square", + filluncheck: "fas fa-square", + table: "fas fa-table", + trash: "fas fa-trash", + 'trash-o': "far fa-trash-alt", + pencil: "fas fa-pencil-alt", + 'ellips-h': "fas fa-ellipsis-h", + 'ellips-v': "fas fa-ellipsis-v", + 'arrow-up': "fas fa-chevron-up", + 'arrow-down': "fas fa-chevron-down", + 'arrow-left': "fas fa-chevron-left", + 'arrow-right': "fas fa-chevron-right", + 'resize-h': "fas fa-arrows-alt-h", + 'resize-v': "fas fa-arrows-alt-v", 'resize-default': "fas fa-compress", - 'caret-up': "fas fa-caret-up", - 'caret-down': "fas fa-caret-down", - 'caret-left': "fas fa-caret-left", - 'caret-right': "fas fa-caret-right", - 'empty-circle': "far fa-circle", - 'cloud-upload': "fas fa-cloud-upload-alt", - spinner: "fas fa-spinner", - minus: "fas fa-minus", - "minus-square":"far fa-minus-square", - plus: "fas fa-plus", - 'plus-circle': "fas fa-plus-circle", - 'plus-square': "far fa-plus-square", - grid: "fas fa-th", - home: "fas fa-home", - folder: "fas fa-folder", - 'sign-out': "fas fa-sign-out-alt", - close: "fas fa-times", - time: "far fa-clock", - calendar: "fas fa-calendar-alt", - list: "fas fa-list-alt", - link: "fas fa-link", - unlink: "fas fa-unlink", - eye: "far fa-eye", - 'eye-close': "far fa-eye-slash", - save: "far fa-save", - pdf: "fas fa-file-pdf", - image: "far fa-image", - video: "far fa-file-video", - unknow:"far fa-question-circle", - zip: "far fa-file-archive", - text: "far fa-file-alt", - excel: "far fa-file-excel", - xls:"far fa-file-excel", - gpx: "fas fa-location-arrow", - gpkg: "fas fa-box-open", - shapefile:"fas fa-file-archive", - csv: "fas fa-file-csv", - geotiff: "fas fa-th", - ppt: "far fa-file-powerpoint", - circle: "fas fa-circle", - calculator: "fas fa-calculator", - picture: "far fa-image", - keyboard: "far fa-keyboard", - 'file-download':"fas fa-file-download", - copy: "far fa-copy", - draw: "fas fa-draw-polygon", - chart: "fas fa-chart-bar", - 'chart-line': "fas fa-chart-line", - 'chart-area': "fas fa-chart-area", - 'chart-pie': "fas fa-chart-pie", - run: "fas fa-play", - warning: "fas fa-exclamation-circle", - alert: "fas fa-exclamation-triangle", - crosshairs: "fas fa-crosshairs", - success: "far fa-check-circle", - back: "fas fa-chevron-circle-left", - 'file-upload': "fas fa-file-upload", - wifi: "fas fa-wifi", - mouse: "fas fa-mouse", - 'copy-paste': "far fa-copy", - 'vector-square': "fas fa-vector-square", - download: "fas fa-download", - credits: "fas fa-euro-sign", - filter: "fas fa-filter", - plugin: "fas fa-plug", - invert: "fas fa-exchange-alt", - clear: "fas fa-broom", - palette: "fas fa-palette", - layers: "fas fa-layer-group", - 'sign-in': "fas fa-sign-in-alt", - language: "fas fa-language", - target: "fas fa-bullseye", - pin: "fas fa-map-pin", - square: "far fa-square", - move: "fas fa-arrows-alt", - moon: "fas fa-moon", - sun: "fas fa-sun", - refresh: "fas fa-sync-alt", - pause:"fas fa-pause", - 'step-backward': "fas fa-step-backward", - 'fast-backward': "fas fa-fast-backward", - 'step-forward': "fas fa-step-forward", - 'fast-forward': "fas fa-fast-forward", - crop: "fas fa-crop-alt", - exit: "fas fa-door-open", - slider: "fas fa-sliders-h", + 'caret-up': "fas fa-caret-up", + 'caret-down': "fas fa-caret-down", + 'caret-left': "fas fa-caret-left", + 'caret-right': "fas fa-caret-right", + 'empty-circle': "far fa-circle", + 'cloud-upload': "fas fa-cloud-upload-alt", + spinner: "fas fa-spinner", + minus: "fas fa-minus", + "minus-square": "far fa-minus-square", + plus: "fas fa-plus", + 'plus-circle': "fas fa-plus-circle", + 'plus-square': "far fa-plus-square", + grid: "fas fa-th", + home: "fas fa-home", + folder: "fas fa-folder", + 'sign-out': "fas fa-sign-out-alt", + close: "fas fa-times", + time: "far fa-clock", + calendar: "fas fa-calendar-alt", + list: "fas fa-list-alt", + link: "fas fa-link", + unlink: "fas fa-unlink", + eye: "far fa-eye", + 'eye-close': "far fa-eye-slash", + save: "far fa-save", + pdf: "fas fa-file-pdf", + image: "far fa-image", + video: "far fa-file-video", + unknow: "far fa-question-circle", + zip: "far fa-file-archive", + text: "far fa-file-alt", + excel: "far fa-file-excel", + xls: "far fa-file-excel", + gpx: "fas fa-location-arrow", + gpkg: "fas fa-box-open", + shapefile: "fas fa-file-archive", + csv: "fas fa-file-csv", + geotiff: "fas fa-th", + ppt: "far fa-file-powerpoint", + circle: "fas fa-circle", + calculator: "fas fa-calculator", + picture: "far fa-image", + keyboard: "far fa-keyboard", + 'file-download': "fas fa-file-download", + copy: "far fa-copy", + draw: "fas fa-draw-polygon", + chart: "fas fa-chart-bar", + 'chart-line': "fas fa-chart-line", + 'chart-area': "fas fa-chart-area", + 'chart-pie': "fas fa-chart-pie", + run: "fas fa-play", + warning: "fas fa-exclamation-circle", + alert: "fas fa-exclamation-triangle", + crosshairs: "fas fa-crosshairs", + success: "far fa-check-circle", + back: "fas fa-chevron-circle-left", + 'file-upload': "fas fa-file-upload", + wifi: "fas fa-wifi", + mouse: "fas fa-mouse", + 'copy-paste': "far fa-copy", + 'vector-square': "fas fa-vector-square", + download: "fas fa-download", + credits: "fas fa-euro-sign", + filter: "fas fa-filter", + plugin: "fas fa-plug", + invert: "fas fa-exchange-alt", + clear: "fas fa-broom", + palette: "fas fa-palette", + layers: "fas fa-layer-group", + 'sign-in': "fas fa-sign-in-alt", + language: "fas fa-language", + target: "fas fa-bullseye", + pin: "fas fa-map-pin", + square: "far fa-square", + move: "fas fa-arrows-alt", + moon: "fas fa-moon", + sun: "fas fa-sun", + refresh: "fas fa-sync-alt", + pause: "fas fa-pause", + 'step-backward': "fas fa-step-backward", + 'fast-backward': "fas fa-fast-backward", + 'step-forward': "fas fa-step-forward", + 'fast-forward': "fas fa-fast-forward", + crop: "fas fa-crop-alt", + exit: "fas fa-door-open", + slider: "fas fa-sliders-h", /** * @since 3.8.0 diff --git a/src/app/core/applicationservice.js b/src/app/core/applicationservice.js deleted file mode 100644 index 17a34aa0c..000000000 --- a/src/app/core/applicationservice.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * DEPRECATED: this file will be removed after v3.4 (use "services/application.js" instead) - */ -import ApplicationService from 'services/application'; - -/** - * @FIXME application is broken using like the following line - */ -// import { ApplicationService } from 'services'; - -module.exports = ApplicationService; \ No newline at end of file diff --git a/src/app/core/data/service.js b/src/app/core/data/service.js index 604e5e683..62a7a6df8 100644 --- a/src/app/core/data/service.js +++ b/src/app/core/data/service.js @@ -1,56 +1,57 @@ import ProjectsRegistry from 'store/projects'; -import GUI from 'services/gui'; +import GUI from 'services/gui'; const { resolve } = require('utils'); -function BaseService(){ - ProjectsRegistry.onbefore('setCurrentProject' , project => this.project = project); - this.project = ProjectsRegistry.getCurrentProject(); -} - -const proto = BaseService.prototype; -/** - * - * @param request is a Promise(jquery promise at moment - * @returns {Promise} - */ -proto.handleRequest = function(request){ - // OVERWRITE TO SERVICE -}; - -proto.handleResponse = async function(response){ - // OVERWRITE TO SERVICE -}; - -/** - * @param {{ type: 'vector' }} - * - * @returns { unknown[] } array of external layer add on project - * - * @since 3.8.0 - */ -proto.getSelectedExternalLayers = function({type = 'vector'}) { - return GUI.getService('catalog').getExternalSelectedLayers({ type }); -}; - -/** - * @returns {Promise<[]>} a resolved request (empty array) - * - * @since 3.8.0 - */ -proto.getEmptyRequest = function(){ - return resolve([]); -}; - -/** - * @param {{ type: 'vector' }} - * - * @returns {boolean} - * - * @since 3.8.0 - */ -proto.hasExternalLayerSelected = function({type = 'vector'}) { - return this.getSelectedExternalLayers({ type }).length > 0; -}; - -module.exports = BaseService; \ No newline at end of file +export class BaseService { + + constructor() { + ProjectsRegistry.onbefore('setCurrentProject' , project => this.project = project); + this.project = ProjectsRegistry.getCurrentProject(); + } + + /** + * @param request a jQuery Promise + * + * @returns {Promise} + */ + handleRequest(request) { + // OVERWRITE TO SERVICE + }; + + async handleResponse(response) { + // OVERWRITE TO SERVICE + } + + /** + * @param {{ type: 'vector' }} + * + * @returns { unknown[] } array of external layer add on project + * + * @since 3.8.0 + */ + getSelectedExternalLayers({ type = 'vector' }) { + return GUI.getService('catalog').getExternalSelectedLayers({ type }); + } + + /** + * @returns {Promise<[]>} a resolved request (empty array) + * + * @since 3.8.0 + */ + getEmptyRequest() { + return resolve([]); + } + + /** + * @param {{ type: 'vector' }} + * + * @returns {boolean} + * + * @since 3.8.0 + */ + hasExternalLayerSelected({ type = 'vector' }) { + return this.getSelectedExternalLayers({ type }).length > 0; + } + +} \ No newline at end of file diff --git a/src/app/core/g3wobject.js b/src/app/core/g3wobject.js index fd30742c6..f2b3cbd4c 100644 --- a/src/app/core/g3wobject.js +++ b/src/app/core/g3wobject.js @@ -1,214 +1,243 @@ -const { inherit, noop, debounce, throttle } = require('utils'); +const { noop, debounce, throttle } = require('utils'); + +/** + * Mimics the behavior of child class fields in parent class, + * which is the only way to define a property (eg `this.setters = { ... }`) + * before invoking the `super()` constructor. + * + * @TODO upgrade babel version in order to declare `setters`, `throttles` `debounces` as class fields + * + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields + */ +function defineClassField(obj, key, cb, initVal) { + // Field is already available within parent constructor + // in case of ES5 inheritance (ie. `inherit(ChildClass, G3WObject);`) + if (initVal) { + return cb.call(obj, initVal); + } + // Field is not available within parent constructor + // in case ES6 inheritance (ie. `class ChildClass extends G3WObject { };`); + let currVal = initVal; + return Object.defineProperty(obj, key, { + get() { return currVal; }, + set(value) { + currVal = value; + if (value) { cb.call(obj, value); } + }, + }); +} /** * Base object to handle a setter and its listeners. - * @constructor */ -const G3WObject = function() { - //check if setters property is set. Register the chain of events - this.setters && this._setupListenersChain(this.setters); - // check debounces - this.debounces && this._setupDebounces(this.debounces); - //check throttles - this.throttles && this._setupThrottles(this.throttles); -}; +export default class G3WObject extends EventEmitter { -inherit(G3WObject, EventEmitter); + constructor() { + super(); -const proto = G3WObject.prototype; + // Register the chain of events -/** - * Insert a listener on afeter setter was executed - * @param {string} setter - IMethod name to register a listener function - * @param {function} listener - listener function (only syncron) - * @param {number} priority - Priorità di esecuzione: valore minore viene eseuito prima - */ -proto.onafter = function(setter, listener, priority){ - return this._onsetter('after', setter, listener, false, priority); -}; + defineClassField(this, 'setters', this._setupListenersChain, this.setters); + defineClassField(this, 'throttles', this._setupThrottles, this.throttles); + defineClassField(this, 'debounces', this._setupDebounces, this.debounces); + } -proto.onceafter = function(setter, listener, priority){ - return this._onsetter('after', setter, listener, false, priority, true); -}; + /** + * Attatch an event listener after executing a setter method + * + * @param {string} setter - function name to listen for + * @param {function} listener - event listener (sync) + * @param {number} priority - priority (lowest value executes first) + */ + onafter(setter, listener, priority) { + return this._onsetter('after', setter, listener, false, priority); + } -/** - * Listern before cal sesster - * @param {string} setter - Method name setter - * @param {function} listener - function to call - * @param {number} priority - Priority - */ -proto.onbefore = function(setter, listener, priority) { - return this._onsetter('before', setter, listener, false, priority); -}; + /** + * Attatch an event listener after executing a setter method (once) + * + * @param {string} setter - function name to listen for + * @param {function} listener - event listener (sync) + * @param {number} priority - priority (lowest value executes first) + */ + onceafter(setter, listener, priority) { + return this._onsetter('after', setter, listener, false, priority, true); + } -// once before -proto.oncebefore = function(setter, listener, priority){ - return this._onsetter('before', setter, listener, false, priority, true); -}; + /** + * Attatch an event listener before executing a setter method + * + * @param {string} setter - function name to listen for + * @param {function} listener - event listener (sync) + * @param {number} priority - priority (lowest value executes first) + */ + onbefore(setter, listener, priority) { + return this._onsetter('before', setter, listener, false, priority); + } -/** - * @param {string} setter - Method name setter - * @param {function} listener - function to call - * @param {number} priority - Priority - */ -proto.onbeforeasync = function(setter, listener, priority) { - return this._onsetter('before', setter, listener, true, priority); -}; - -proto.un = function(setter, key) { - // cicle on after before (key) and for each settersListeners (array) find key - Object.entries(this.settersListeners).forEach(([_key, settersListeners]) => { - if (key === undefined) settersListeners[setter].splice(0); - else settersListeners[setter].forEach((setterListener, idx) => { - if (setterListener.key === key) { - settersListeners[setter].splice(idx, 1); - } - }) - }); -}; - -// base function to register and handle on setter listeners -/* - when=before|after, - type=sync|async -*/ -proto._onsetter = function(when, setter, listener, async, priority=0, once=false) { - let listenerKey; - // check if setter function is register. - if (typeof this.settersListeners[when][setter] !== "undefined") { - // set unique listenerKey value - listenerKey = `${Math.floor(Math.random()*1000000) + Date.now()}`; - // add info object to setters listeners - this.settersListeners[when][setter].push({ - key: listenerKey, - fnc: listener, - async, - priority, - once - }); - // set lineners base on priority - this.settersListeners[when][setter] = _.sortBy(this.settersListeners[when][setter], setterListener => setterListener.priority); + /** + * Attatch an event listener before executing a setter method (once) + * + * @param {string} setter - function name to listen for + * @param {function} listener - event listener (sync) + * @param {number} priority - priority (lowest value executes first) + */ + oncebefore(setter, listener, priority) { + return this._onsetter('before', setter, listener, false, priority, true); } - // return key - return listenerKey // in case of no setter register return undefined listerKey -}; - -proto._setupListenersChain = function(setters) { - // initialize all methods inside object "setters" of child class. - this.settersListeners = { - after: {}, - before: {} + + /** + * Attatch an event listener before executing a setter method (once) + * + * @param {string} setter - function name to listen for + * @param {function} listener - event listener (async) + * @param {number} priority - priority (lowest value executes first) + */ + onbeforeasync(setter, listener, priority) { + return this._onsetter('before', setter, listener, true, priority); + } + + /** + * Cicle each settersListeners (array) and find setter key (before/after) to be removed + */ + un(setter, key) { + Object.entries(this.settersListeners) + .forEach(([_key, setters]) => { + if (undefined === key) { + setters[setter].splice(0); + } else { + setters[setter].forEach((listener, idx) => { listener.key === key && setters[setter].splice(idx, 1); }) + } + }); }; - for (const setter in setters) { - const setterOption = setters[setter]; - let setterFnc = noop; - let setterFallback = noop; - if (_.isFunction(setterOption)) setterFnc = setterOption; - else { - setterFnc = setterOption.fnc; - setterFallback = setterOption.fallback || noop; // method called in case of error + +/** + * Register and handle listeners + * + * @param { 'before' | 'after' } when + * @param { 'sync' | 'async' } type + */ + _onsetter(when, setter, listener, async, priority = 0, once = false) { + // unique listenerKey + let key; + // check if setter function is registered + // and then add info object to setters listeners + // (sorted based on priority) + if (this.settersListeners && undefined !== this.settersListeners[when][setter]) { + key = `${Math.floor(Math.random() * 1000000) + Date.now()}`; + this.settersListeners[when][setter].push({ key, fnc: listener, async, priority, once}); + this.settersListeners[when][setter] = _.sortBy(this.settersListeners[when][setter], listener => listener.priority); } - // create array to push before and after subscribers - this.settersListeners.after[setter] = []; - this.settersListeners.before[setter] = []; - // assign the property settern name to the object as own method - this[setter] = function(...args) { - const deferred = $.Deferred(); - let returnVal = null; - let counter = 0; - // function to call original function(setter function) - const callSetter = () => { - // run setter function - returnVal = setterFnc.apply(this, args); - // resolve promise - deferred.resolve(returnVal); - //call all subscribed methods afet setter - const onceListenerKeys = []; - const afterListeners = this.settersListeners.after[setter]; - afterListeners.forEach(listener => { - listener.fnc.apply(this, args); - listener.once && onceListenerKeys.push(listener.key); - }); - onceListenerKeys.forEach(key => this.un(setter, key)); - }; - // abort function - const abort = () => { - setterFallback.apply(this, args); - deferred.reject(); - }; - // get all before listeners functions of setter - const beforeListeners = this.settersListeners['before'][setter]; - // listener counter - counter = 0; - const next = bool => { - // initilize cont to true (continue) - let cont = true; - // check if bool is Boolean - if (_.isBoolean(bool)) cont = bool; - // check if count is false or we are arrived to the end of onbefore subscriber - if (cont === false) { - // found an error so we can abort - abort.apply(this, args); - } else if (counter === beforeListeners.length) { - // call complete method methods - const completed = callSetter(); - //verifico che cosa ritorna - if (completed === undefined || completed === true) { + return key // in case of no setter register return undefined listenerKey + } + + /** + * @returns {Promise} + */ + _setupListenersChain(setters) { + + // all methods inside object "setters" of child class. + this.settersListeners = { + after: {}, + before: {}, + }; + + for (const setter in setters) { + + // Array to push before and after subscribers + this.settersListeners.after[setter] = []; + this.settersListeners.before[setter] = []; + + // assign the property setter name to the object as own method + this[setter] = function(...args) { + + // listener count + let count = 0; + + const deferred = $.Deferred(); + + const next = (bool) => { + let skip = _.isBoolean(bool) ? !bool : false; + const len = this.settersListeners.before[setter].length; + + // abort in case of error + // check if count is false or we reached the end of onbefore subscriber + if (skip !== false) { + (_.isFunction(setters[setter]) ? noop : (setters[setter].fallback || noop)).apply(this, args); + deferred.reject(); + } + + // call complete method methods and check what returns + if ( + skip === false && + count === len && + [undefined, true].includes(( + () => { + // run setter function (resolve promise) + deferred.resolve((_.isFunction(setters[setter]) ? setters[setter] : setters[setter].fnc).apply(this, args)); + // call all subscribed methods afet setter + const onceListeners = []; + this + .settersListeners + .after[setter] + .forEach(listener => { + listener.fnc.apply(this, args); + if (listener.once) { + onceListeners.push(listener.key); + } + }); + onceListeners.forEach(key => this.un(setter, key)); + } + )()) + ) { this.emitEvent(`set:${setter}`,args); } - } else if (cont) { - const listenerObj = beforeListeners[counter]; - const currentCounter = counter; - // if is async functtion - if (beforeListeners[counter].async) { - //add function next to argument of listnerFunction - args.push(next); - // update counter - counter += 1; - listenerObj.fnc.apply(this, args) - } else { - // return or undefine or a boolen to tell if ok(true) can conitnue or not (false) - const bool = listenerObj.fnc.apply(this, args); - //update counter - counter += 1; - next(bool); + + if (!skip && skip === false && count !== len) { + const listener = this.settersListeners.before[setter][count++]; + if (listener.async) { + // add function next to argument of listener function + args.push(next); + listener.fnc.apply(this, args) + } else { + // return or undefined or a boolen to tell if ok(true) can conitnue or not (false) + next(listener.fnc.apply(this, args)); + } + if (listener.once) { + this.settersListeners.before[setter].splice(count - 1, 1); + } } - listenerObj.once && beforeListeners.splice(currentCounter, 1); - } - }; - // run next to start to run all the subscribers and setrer its self - next(); - // retun a promise - return deferred.promise(); + + }; + + // run all the subscribers and setters + next(); + + return deferred.promise(); + } + } + return this.settersListeners; } - return this.settersListeners -}; - -proto._setupDebounces = function(debounces) { - for (const name in debounces) { - const delay = debounces[name].delay; - const fnc = debounces[name].fnc; - this[name] = debounce(fnc, delay); + + _setupDebounces(debounces) { + for (const name in debounces) { + this[name] = debounce(debounces[name].fnc, debounces[name].delay); + } } -}; -proto._setupThrottles = function(throttles) { - for (const name in throttles) { - const delay = throttles[name].delay; - const fnc = throttles[name].fnc; - this[name] = throttle(fnc, delay); + _setupThrottles(throttles) { + for (const name in throttles) { + this[name] = throttle(throttles[name].fnc, throttles[name].delay); + } } -}; -//method get -proto.get = function(key) { - return this[key] && !(this[key] instanceof Function) ? this[key] : null; -}; + get(key) { + return this[key] && !(this[key] instanceof Function) ? this[key] : null; + } -//method set -proto.set = function(key, value) { - this[key] = value; -}; + set(key, value) { + this[key] = value; + } -module.exports = G3WObject; +} \ No newline at end of file diff --git a/src/app/core/layers/features/featuresstore.js b/src/app/core/layers/features/featuresstore.js index c7e519805..3bf70c42c 100644 --- a/src/app/core/layers/features/featuresstore.js +++ b/src/app/core/layers/features/featuresstore.js @@ -1,5 +1,5 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; /** @deprecated */ const _cloneDeep = require('lodash.clonedeep'); diff --git a/src/app/core/layers/layer.js b/src/app/core/layers/layer.js index c109dd9ed..419159a58 100644 --- a/src/app/core/layers/layer.js +++ b/src/app/core/layers/layer.js @@ -1,25 +1,19 @@ -import ApplicationState from 'store/application-state'; -import DataRouterService from 'services/data'; -import ProjectsRegistry from 'store/projects'; -import DownloadMixin from 'core/layers/mixins/download'; -import SelectionMixin from 'core/layers/mixins/selection'; -import { SELECTION as SELECTION_STATE } from 'core/layers/mixins/selection'; -import RelationsMixin from 'core/layers/mixins/relations'; - -const { t } = require('core/i18n/i18n.service'); -const { - inherit, - base, - XHR, -} = require('utils'); -const G3WObject = require('core/g3wobject'); -const { - geometryFields, - parseAttributes, -} = require('utils/geo'); -const ProviderFactory = require('core/layers/providersfactory'); - -const deprecate = require('util-deprecate'); +import ApplicationState from 'store/application-state'; +import DataRouterService from 'services/data'; +import ProjectsRegistry from 'store/projects'; +import G3WObject from 'core/g3wobject'; + +import DownloadMixin from 'core/layers/mixins/download'; +import SelectionMixin from 'core/layers/mixins/selection'; +import { SELECTION as SELECTION_STATE } from 'core/layers/mixins/selection'; +import RelationsMixin from 'core/layers/mixins/relations'; + +const { t } = require('core/i18n/i18n.service'); +const { inherit, base, XHR } = require('utils'); +const { geometryFields, parseAttributes } = require('utils/geo'); +const ProviderFactory = require('core/layers/providers/providersfactory'); + +const deprecate = require('util-deprecate'); // Base Class of all Layer function Layer(config={}, options={}) { diff --git a/src/app/core/layers/layersstore.js b/src/app/core/layers/layersstore.js index 256a7c74b..323c0d7dd 100644 --- a/src/app/core/layers/layersstore.js +++ b/src/app/core/layers/layersstore.js @@ -1,5 +1,5 @@ -const { base, inherit, uniqueId } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit, uniqueId } from 'utils'; // Interface for Layers function LayersStore(config={}) { diff --git a/src/app/core/layers/layersstoresregistry.js b/src/app/core/layers/layersstoresregistry.js index 3bb1f47ab..02fdee105 100644 --- a/src/app/core/layers/layersstoresregistry.js +++ b/src/app/core/layers/layersstoresregistry.js @@ -1,70 +1,74 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; -// Registy Layers -function LayersStoresRegistry() { - this.stores = {}; - this.storesArray = []; - // to react some application components that are binding to Layerstore - this.setters = { - addLayersStore: this._addLayersStore.bind(this), - removeLayersStore: this._removeLayersStore.bind(this), - removeLayersStores: this._removeLayersStores.bind(this), - }; +/** + * Layers registry + */ +export default class LayersStoresRegistry extends G3WObject { - base(this); -} + constructor() { -inherit(LayersStoresRegistry, G3WObject); + super(); -const proto = LayersStoresRegistry.prototype; + this.stores = {}; + this.storesArray = []; -proto.getLayerById = function(layerId) { - let layer; - for (const storeId in this.stores) { - const layerStore = this.stores[storeId]; - layer = layerStore.getLayerById(layerId); - if (layer) break; - } - return layer -}; + /** + * to react some application components that are binding to Layerstore + */ + this.setters = { + addLayersStore: this._addLayersStore.bind(this), + removeLayersStore: this._removeLayersStore.bind(this), + removeLayersStores: this._removeLayersStores.bind(this), + }; -proto.getLayers = function(filter) { - return Object.values(this.stores).flatMap(store => store.getLayers(filter)); -}; + } -proto.getQuerableLayersStores = function() { - return this.getLayersStores().filter(store => store.isQueryable()); -}; + getLayerById(layerId) { + let layer; + for (const id in this.stores) { + layer = this.stores[id].getLayerById(layerId); + if (layer) break; + } + return layer + } -proto.getLayersStore = function(id) { - return this.stores[id]; -}; + getLayers(filter) { + return Object.values(this.stores).flatMap(store => store.getLayers(filter)); + } -proto.getLayersStores = function() { - return this.storesArray.map(storeId => this.stores[storeId]); -}; + getQuerableLayersStores() { + return this.getLayersStores().filter(store => store.isQueryable()); + } -proto._addLayersStore = function(layersStore, idx) { - const storeId = layersStore.getId(); - this.stores[storeId] = layersStore; - if (!_.isNil(idx)) this.storesArray.splice(idx,0, storeId); - else this.storesArray.push(storeId); + getLayersStore(id) { + return this.stores[id]; + } -}; + getLayersStores() { + return this.storesArray.map(storeId => this.stores[storeId]); + } -proto._removeLayersStore = function(layerStore) { - if (layerStore) { - const storeId = layerStore.getId(); - this.storesArray = this.storesArray.filter((_storeId) => _storeId != storeId); - delete this.stores[storeId]; + _addLayersStore(layersStore, idx) { + const id = layersStore.getId(); + this.stores[id] = layersStore; + if (!_.isNil(idx)) { + this.storesArray.splice(idx, 0, id); + } else { + this.storesArray.push(id); + } } -}; -proto._removeLayersStores = function() { - this.storesArray = []; - this.stores = {}; -}; + _removeLayersStore(layerStore) { + if (layerStore) { + const id = layerStore.getId(); + this.storesArray = this.storesArray.filter((_id) => _id != id); + delete this.stores[id]; + } + } + _removeLayersStores() { + this.storesArray = []; + this.stores = {}; + } -module.exports = LayersStoresRegistry; +} \ No newline at end of file diff --git a/src/app/core/layers/map/maplayer.js b/src/app/core/layers/map/maplayer.js index 6aa829354..f605fc356 100644 --- a/src/app/core/layers/map/maplayer.js +++ b/src/app/core/layers/map/maplayer.js @@ -1,5 +1,5 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; function MapLayer(config={}) { this.config = config; diff --git a/src/app/core/layers/map/vectorlayer.js b/src/app/core/layers/map/vectorlayer.js index f9480d049..fc534e925 100644 --- a/src/app/core/layers/map/vectorlayer.js +++ b/src/app/core/layers/map/vectorlayer.js @@ -1,8 +1,8 @@ -import GUI from 'services/gui'; +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; +import { inherit } from 'utils'; -const { inherit } = require('utils'); const { createOlLayer, createLayerStyle } = require('utils/geo'); -const G3WObject = require('core/g3wobject'); function VectorLayer(options = {}) { this.mapService = GUI.getComponent('map').getService(); diff --git a/src/app/core/plugin/plugin.js b/src/app/core/plugin/plugin.js index 0e4d72f1d..41bdd97f9 100644 --- a/src/app/core/plugin/plugin.js +++ b/src/app/core/plugin/plugin.js @@ -1,12 +1,12 @@ -import PluginsRegistry from 'store/plugins'; -import ProjectsRegistry from 'store/projects'; -import ApplicationService from 'services/application'; -import GUI from 'services/gui'; - -const { base, inherit, toRawType } = require('utils'); -const G3WObject = require('core/g3wobject'); -const ComponentsFactory = require('gui/component/componentsfactory'); -const { addI18nPlugin } = require('core/i18n/i18n.service'); +import PluginsRegistry from 'store/plugins'; +import ProjectsRegistry from 'store/projects'; +import ApplicationService from 'services/application'; +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; +import { base, inherit, toRawType } from 'utils'; + +const ComponentsFactory = require('gui/component/componentsfactory'); +const { addI18nPlugin } = require('core/i18n/i18n.service'); const TIMEOUT = 10000; diff --git a/src/app/core/plugin/pluginservice.js b/src/app/core/plugin/pluginservice.js index d450dd68e..f49fb972c 100644 --- a/src/app/core/plugin/pluginservice.js +++ b/src/app/core/plugin/pluginservice.js @@ -1,8 +1,7 @@ -import ApplicationState from 'store/application-state'; +import ApplicationState from 'store/application-state'; import ApplicationService from 'services/application'; - -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; function PluginService(options={}) { base(this, options); diff --git a/src/app/core/project/project.js b/src/app/core/project/project.js index 15d3f4b81..bf1cb0db1 100644 --- a/src/app/core/project/project.js +++ b/src/app/core/project/project.js @@ -1,13 +1,17 @@ -import { QUERY_POINT_TOLERANCE, TOC_LAYERS_INIT_STATUS, TOC_THEMES_INIT_STATUS } from 'app/constant'; -import ApplicationState from 'store/application-state'; -import ApplicationService from 'services/application'; - -const { base, inherit, XHR } = require('utils'); -const { crsToCrsObject } = require('utils/geo'); -const G3WObject = require('core/g3wobject'); -const LayerFactory = require('core/layers/layerfactory'); -const LayersStore = require('core/layers/layersstore'); -const Projections = require('g3w-ol/projection/projections'); +import { + QUERY_POINT_TOLERANCE, + TOC_LAYERS_INIT_STATUS, + TOC_THEMES_INIT_STATUS +} from 'app/constant'; +import ApplicationState from 'store/application-state'; +import ApplicationService from 'services/application'; +import G3WObject from 'core/g3wobject'; +import { base, inherit, XHR } from 'utils'; + +const { crsToCrsObject } = require('utils/geo'); +const LayerFactory = require('core/layers/layerfactory'); +const LayersStore = require('core/layers/layersstore'); +const Projections = require('g3w-ol/projection/projections'); /** * @FIXME options param appears to be unusued diff --git a/src/app/core/project/projecttypes.js b/src/app/core/project/projecttypes.js deleted file mode 100644 index 4831cafcf..000000000 --- a/src/app/core/project/projecttypes.js +++ /dev/null @@ -1,6 +0,0 @@ -const ProjectTypes = { - QDJANGO: 'qdjango', - OGR: 'ogr' -}; - -module.exports = ProjectTypes; diff --git a/src/app/core/relations/relation.js b/src/app/core/relations/relation.js index 438089058..43e688705 100644 --- a/src/app/core/relations/relation.js +++ b/src/app/core/relations/relation.js @@ -1,5 +1,6 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from '/utils'; + /** * Relation Class diff --git a/src/app/core/relations/relations.js b/src/app/core/relations/relations.js index 065ee92b1..7074f28ff 100644 --- a/src/app/core/relations/relations.js +++ b/src/app/core/relations/relations.js @@ -1,6 +1,7 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); -const Relation = require('core/relations/relation'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; + +const Relation = require('core/relations/relation'); /** * Relations Class diff --git a/src/app/core/workflow/flow.js b/src/app/core/workflow/flow.js index 2ea982e67..d9f34fbb7 100644 --- a/src/app/core/workflow/flow.js +++ b/src/app/core/workflow/flow.js @@ -1,6 +1,7 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); -const Queque = require('core/workflow/queque'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; + +const Queque = require('core/workflow/queque'); //Class Flow of workflow step by step function Flow() { diff --git a/src/app/core/workflow/step.js b/src/app/core/workflow/step.js index 86e65f292..9bf1c65fc 100644 --- a/src/app/core/workflow/step.js +++ b/src/app/core/workflow/step.js @@ -1,5 +1,5 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; /** * @param options.input @@ -13,7 +13,6 @@ const G3WObject = require('core/g3wobject'); * @param options.message */ function Step(options = {}) { - base(this); const { diff --git a/src/app/core/workflow/task.js b/src/app/core/workflow/task.js index 077c06382..565b77105 100644 --- a/src/app/core/workflow/task.js +++ b/src/app/core/workflow/task.js @@ -1,5 +1,5 @@ -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; function Task(options={}) { base(this, options); diff --git a/src/app/core/workflow/workflow.js b/src/app/core/workflow/workflow.js index 126b687c0..255ee6a64 100644 --- a/src/app/core/workflow/workflow.js +++ b/src/app/core/workflow/workflow.js @@ -1,16 +1,11 @@ -import WorkflowsStack from 'services/workflows'; -import GUI from 'services/gui'; - -import UserMessageSteps from 'components/UserMessageSteps'; - -const { - base, - inherit, - resolve -} = require('utils'); -const G3WObject = require('core/g3wobject'); -const Flow = require('core/workflow/flow'); -const { MESSAGES } = require('core/workflow/step'); +import WorkflowsStack from 'services/workflows'; +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; +import UserMessageSteps from 'components/UserMessageSteps'; +import { base, inherit, resolve } from 'utils'; + +const Flow = require('core/workflow/flow'); +const { MESSAGES } = require('core/workflow/step'); /** * Workflow Class (manage flow of steps) diff --git a/src/app/gui/catalog/catalogservice.js b/src/app/gui/catalog/catalogservice.js index 2a95cefb1..fd25662c5 100644 --- a/src/app/gui/catalog/catalogservice.js +++ b/src/app/gui/catalog/catalogservice.js @@ -1,9 +1,8 @@ import CatalogLayersStoresRegistry from 'store/catalog-layers'; -import ProjectsRegistry from 'store/projects'; -import ApplicationService from 'services/application'; - -const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +import ProjectsRegistry from 'store/projects'; +import ApplicationService from 'services/application'; +import G3WObject from 'core/g3wobject'; +import { base, inherit } from 'utils'; function CatalogService() { this.state = { diff --git a/src/app/gui/component/component.js b/src/app/gui/component/component.js index 8a0b41a99..68f09561a 100644 --- a/src/app/gui/component/component.js +++ b/src/app/gui/component/component.js @@ -1,5 +1,12 @@ -const { base, inherit, merge, noop, capitalize_first_letter, resolve } = require('utils'); -const G3WObject = require('core/g3wobject'); +import G3WObject from 'core/g3wobject'; +import { + base, + inherit, + merge, + noop, + capitalize_first_letter, + resolve, +} from 'utils'; /** @deprecated */ const _cloneDeep = require('lodash.clonedeep'); diff --git a/src/app/gui/fields/fields.js b/src/app/gui/fields/fields.js deleted file mode 100644 index 158f32b32..000000000 --- a/src/app/gui/fields/fields.js +++ /dev/null @@ -1,19 +0,0 @@ -import Text from 'components/FieldText.vue'; -import Link from 'components/FieldLink.vue'; -import Image from 'components/FieldImage.vue' -import Geo from 'components/FieldGeo.vue'; -import Media from 'components/FieldMedia.vue'; -import VueField from 'components/FieldVue.vue'; - -const Fields = { - simple_field: Text, - text_field: Text, - link_field: Link, - image_field: Image, - geo_field: Geo, - photo_field: Image, - media_field: Media, - vue_field: VueField -}; - -module.exports = Fields; diff --git a/src/app/gui/fields/fieldsservice.js b/src/app/gui/fields/fieldsservice.js deleted file mode 100644 index 6c73f1171..000000000 --- a/src/app/gui/fields/fieldsservice.js +++ /dev/null @@ -1,96 +0,0 @@ -import CatalogLayersStoresRegistry from 'store/catalog-layers'; - -const Fields = require('./fields'); -const { toRawType } = require('utils'); - -const URLPattern = /^(https?:\/\/[^\s]+)/g; -const PhotoPattern = /[^\s]+.(png|jpg|jpeg|gif)$/g; - -const FieldType = { - SIMPLE:'simple', - GEO:'geo', - LINK:'link', - PHOTO: 'photo', - PHOTOLINK: "photolink", - IMAGE:'image', - POINTLINK:'pointlink', - ROUTE: 'route', - VUE: 'vue' -}; - -module.exports = { - /** - * Get Type field from field value - * field : Object contain the value of the field - * @param field - * @returns {string} - */ - getType(field){ - let type = field.type; - if (type !== 'vue'){ - const fieldValue = field.value; - const value = fieldValue && toRawType(fieldValue) === 'Object' && !fieldValue.coordinates && !fieldValue.vue ? fieldValue.value : fieldValue; - if (!value) type = FieldType.SIMPLE; - else if (value && typeof value == 'object') { - if (value.coordinates) type = FieldType.GEO; - else if (value.vue) type = FieldType.VUE; - } else if(value && Array.isArray(value)) { - if (value.length && value[0].photo) type = FieldType.PHOTO; - else type = FieldType.SIMPLE - } else if (value.toString().toLowerCase().match(PhotoPattern)) { - type = FieldType.PHOTO; - } else if (value.toString().match(URLPattern)) { - type = FieldType.LINK; - } else type = FieldType.SIMPLE; - } - return `${type}_field`; - }, - isSimple(field){ - return this.getType(field) === `${FieldType.SIMPLE}_field`; - }, - isLink(field){ - return this.getType(field) === `${FieldType.LINK}_field`; - }, - isImage(field){ - return this.getType(field) === `${FieldType.IMAGE}_field`; - }, - isPhoto(field){ - return this.getType(field) === `${FieldType.PHOTO}_field`; - }, - isVue(field){ - return this.getType(field) === `${FieldType.VUE}_field`; - }, - /** - * Method to add a new field type to Fields - * @param type - * @param field - */ - add({type, field}){ - Fields[type] = field; - }, - /** - * Remove field from Fields list - * @param type - */ - remove(type){ - delete Fields[type]; - }, - /** - * chenge type of field (example to set vue type) - * @param layerId - * @param field - */ - changeConfigFieldType({layerId, field={}}){ - const layer = CatalogLayersStoresRegistry.getLayerById(layerId); - layer.changeConfigFieldType(field); - }, - /** - * Reset origin type - * @param layerId - * @param field - */ - resetConfigFieldType({layerId, field={}}){ - const layer = CatalogLayersStoresRegistry.getLayerById(layerId); - layer.resetConfigField(field); - } -}; \ No newline at end of file diff --git a/src/app/gui/form/formservice.js b/src/app/gui/form/formservice.js index 7f905f224..a8b7bb774 100644 --- a/src/app/gui/form/formservice.js +++ b/src/app/gui/form/formservice.js @@ -1,10 +1,10 @@ -import DataRouterService from 'services/data'; +import inputService from 'core/expression/inputservice'; +import G3WObject from 'core/g3wobject'; +import { inherit, base } from 'utils'; +import DataRouterService from 'services/data'; const { convertFeatureToGEOJSON } = require('utils/geo'); -const { inherit, base } = require('utils'); -const G3WObject = require('core/g3wobject'); - function FormService() { this.state = null; diff --git a/src/app/gui/inputs/checkbox/service.js b/src/app/gui/inputs/checkbox/service.js deleted file mode 100644 index b6e694c13..000000000 --- a/src/app/gui/inputs/checkbox/service.js +++ /dev/null @@ -1,37 +0,0 @@ -const { inherit, base } = require('utils'); -const Service = require('gui/inputs/service'); - -function CheckBoxService(options={}) { - const value = options.state.input.options.values.find(value => value.checked === false); - options.validatorOptions = { - values: options.state.input.options.values.map(value => value) - }; - if (options.state.value === null && !options.state.forceNull) - options.state.value = value.value; - base(this, options); -} - -inherit(CheckBoxService, Service); - -const proto = CheckBoxService.prototype; - -proto.convertCheckedToValue = function(checked) { - checked = checked === null || checked === undefined ? false : checked; - const option = this.state.input.options.values.find(value => value.checked === checked); - this.state.value = option.value; - return this.state.value; -}; - -proto.convertValueToChecked = function() { - const valueToCheck = this.state.value; - if (valueToCheck === null || valueToCheck === undefined) return false; - let option = this.state.input.options.values.find(value => value.value == valueToCheck); - if (option === undefined) { - option = this.state.input.options.values.find(value => value.checked === false); - this.state.value = option.value; - } - return option.checked; -}; - - -module.exports = CheckBoxService; diff --git a/src/app/gui/inputs/checkbox/vue/checkbox.js b/src/app/gui/inputs/checkbox/vue/checkbox.js deleted file mode 100644 index 6e9688577..000000000 --- a/src/app/gui/inputs/checkbox/vue/checkbox.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputCheckbox.vue'; - -const CheckBoxInput = Vue.extend(vueComponentOptions); - -module.exports = CheckBoxInput; diff --git a/src/app/gui/inputs/color/vue/color.js b/src/app/gui/inputs/color/vue/color.js deleted file mode 100644 index 9682eae0f..000000000 --- a/src/app/gui/inputs/color/vue/color.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputColor.vue'; - -const TextInput = Vue.extend(vueComponentOptions); - -module.exports = TextInput; diff --git a/src/app/gui/inputs/datetimepicker/service.js b/src/app/gui/inputs/datetimepicker/service.js deleted file mode 100644 index 512de20d1..000000000 --- a/src/app/gui/inputs/datetimepicker/service.js +++ /dev/null @@ -1,28 +0,0 @@ -import ApplicationService from 'services/application'; - -const { inherit, base, convertQGISDateTimeFormatToMoment } = require('utils'); -const Service = require('gui/inputs/service'); - -function DateTimePickerService(options={}) { - this.validatorOptions = {}; - base(this, options); -} - -inherit(DateTimePickerService, Service); - -const proto = DateTimePickerService.prototype; - -proto.getLocale = function() { - const applicationConfig = ApplicationService.getConfig(); - return applicationConfig.user.i18n ? applicationConfig.user.i18n : 'en'; -}; - -proto.convertQGISDateTimeFormatToMoment = function(datetimeformat) { - return convertQGISDateTimeFormatToMoment(datetimeformat); -}; - -proto.setValidatorOptions = function(options) { - this.validatorOptions = options; -}; - -module.exports = DateTimePickerService; diff --git a/src/app/gui/inputs/datetimepicker/vue/datetimepicker.js b/src/app/gui/inputs/datetimepicker/vue/datetimepicker.js deleted file mode 100644 index a659667e5..000000000 --- a/src/app/gui/inputs/datetimepicker/vue/datetimepicker.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputDateTimePicker.vue'; - -const DateTimePickerInput = Vue.extend(vueComponentOptions); - -module.exports = DateTimePickerInput; diff --git a/src/app/gui/inputs/float/service.js b/src/app/gui/inputs/float/service.js deleted file mode 100644 index 0feaa42ac..000000000 --- a/src/app/gui/inputs/float/service.js +++ /dev/null @@ -1,11 +0,0 @@ -const { base, inherit } = require('utils'); -const Service = require('gui/inputs/service'); - -function FloatService(options={}) { - base(this, options); -} - -inherit(FloatService, Service); - - -module.exports = FloatService; diff --git a/src/app/gui/inputs/float/vue/float.js b/src/app/gui/inputs/float/vue/float.js deleted file mode 100644 index f031e0c61..000000000 --- a/src/app/gui/inputs/float/vue/float.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputFloat.vue'; - -const FloatInput = Vue.extend(vueComponentOptions); - -module.exports = FloatInput; diff --git a/src/app/gui/inputs/input.js b/src/app/gui/inputs/input.js deleted file mode 100644 index 12c825d64..000000000 --- a/src/app/gui/inputs/input.js +++ /dev/null @@ -1,59 +0,0 @@ -import ApplicationState from 'store/application-state'; -import BaseInputComponent from 'components/InputBase.vue' -import { baseInputMixin as BaseInputMixin } from 'mixins'; -const InputServices = require('./services'); - -const Input = { - props: ['state'], - mixins: [BaseInputMixin], - components: { - 'baseinput': BaseInputComponent - }, - watch: { - 'notvalid'(notvalid){ - notvalid && this.service.setErrorMessage(this.state) - }, - 'state.value'(){ - if ("undefined" !== typeof this.state.input.options.default_expression) { - // need to postpone state.value watch parent that use mixin - setTimeout(() => this.change()); - } - } - }, - created() { - this.service = new InputServices[this.state.input.type]({ - state: this.state, - }); - this.$watch(() => ApplicationState.language, () => this.service.setErrorMessage(this.state)); - this.state.editable && this.state.validate.required && this.service.validate(); - this.$emit('addinput', this.state); - /** - * in case of input value is fill with default value option we need to emit changeinput event - * without check validation. Example: - * { - "name": "id", - "type": "integer", - "label": "id", - "editable": false, - "validate": { - "required": true, - "unique": true - }, - "pk": true, - "default": "nextval('g3wsuite.zone_id_seq'::regclass)", - "input": { - "type": "text", - "options": {} - } - } - in this case if we start a validation, it fail because default value is a string while input is interger - */ - this.state.value_from_default_value && this.$emit('changeinput', this.state); - }, - destroyed(){ - // emit remove input to form (in case for example tab visibility condition) - this.$emit('removeinput', this.state); - } -}; - -module.exports = Input; diff --git a/src/app/gui/inputs/inputs.js b/src/app/gui/inputs/inputs.js deleted file mode 100644 index 7c9238d15..000000000 --- a/src/app/gui/inputs/inputs.js +++ /dev/null @@ -1,22 +0,0 @@ -const InputsComponents = { - 'text_input': require('./text/vue/text'), - 'texthtml_input': require('./texthtml/vue/texthtml'), - 'textarea_input': require('./textarea/vue/textarea'), - 'integer_input': require('./integer/vue/integer'), - 'string_input':require('./text/vue/text'), //temporary - 'float_input': require('./float/vue/float'), - 'radio_input': require('./radio/vue/radio'), - 'check_input': require('./checkbox/vue/checkbox'), - 'range_input': require('./range/vue/range'), - 'datetimepicker_input': require('./datetimepicker/vue/datetimepicker'), - 'unique_input': require('./unique/vue/unique'), - 'select_input': require('./select/vue/select'), - 'media_input': require('./media/vue/media'), - 'select_autocomplete_input': require('./select/vue/select'), - 'picklayer_input': require('./picklayer/vue/picklayer'), - 'color_input': require('./color/vue/color'), - 'slider_input': require('./sliderrange/vue/sliderrange'), - 'lonlat_input': require('./lonlat/vue/lonlat') -}; - -module.exports = InputsComponents; diff --git a/src/app/gui/inputs/integer/service.js b/src/app/gui/inputs/integer/service.js deleted file mode 100644 index 7b674b767..000000000 --- a/src/app/gui/inputs/integer/service.js +++ /dev/null @@ -1,11 +0,0 @@ -const { base, inherit } = require('utils'); -const Service = require('gui/inputs/service'); - -function IntegerService(options={}) { - base(this, options); -} - -inherit(IntegerService, Service); - - -module.exports = IntegerService; diff --git a/src/app/gui/inputs/integer/vue/integer.js b/src/app/gui/inputs/integer/vue/integer.js deleted file mode 100644 index f119cba45..000000000 --- a/src/app/gui/inputs/integer/vue/integer.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputInteger.vue'; - -const IntegerInput = Vue.extend(vueComponentOptions); - -module.exports = IntegerInput; diff --git a/src/app/gui/inputs/lonlat/service.js b/src/app/gui/inputs/lonlat/service.js deleted file mode 100644 index e95b78802..000000000 --- a/src/app/gui/inputs/lonlat/service.js +++ /dev/null @@ -1,65 +0,0 @@ -import GUI from 'services/gui'; - -const { base, inherit } = require('utils'); -const Service = require('gui/inputs/service'); - -function LonLatService(options={}) { - base(this, options); - this.coordinatebutton; - this.mapService = GUI.getComponent('map').getService(); - this.mapEpsg = this.mapService.getCrs(); - this.mapControlToggleEventHandler = evt =>{ - if (evt.target.isToggled() && evt.target.isClickMap()){ - this.coordinatebutton.active && this.toggleGetCoordinate(); - } - }; - this.map = GUI.getComponent('map').getService().getMap(); - this.outputEpsg = this.state.epsg || this.mapEpsg; - this.eventMapKey; -} - -inherit(LonLatService, Service); - -const proto = LonLatService.prototype; - -proto.setCoordinateButtonReactiveObject = function(coordinatebutton){ - this.coordinatebutton = coordinatebutton; -}; - -proto.validate = function(){ - if (this.state.values.lon < -180) this.state.values.lon = -180; - else if (this.state.values.lon > 180) this.state.values.lon = 180; - if (this.state.values.lat < -90) this.state.values.lon = -90; - else if (this.state.values.lat > 90) this.state.values.lon = 90; - this.state.validate.valid = !Number.isNaN(1*this.state.values.lon); -}; - -proto.toggleGetCoordinate = function(){ - this.coordinatebutton.active = !this.coordinatebutton.active; - this.coordinatebutton.active ? this.startToGetCoordinates() : this.stopToGetCoordinates(); -}; - -proto.startToGetCoordinates = function(){ - this.mapService.deactiveMapControls(); - this.mapService.on('mapcontrol:toggled', this.mapControlToggleEventHandler); - this.eventMapKey = this.map.on('click', evt =>{ - evt.originalEvent.stopPropagation(); - evt.preventDefault(); - const coordinate = this.mapEpsg !== this.outputEpsg ? ol.proj.transform(evt.coordinate, this.mapEpsg, this.outputEpsg) : evt.coordinate; - this.state.value = [coordinate]; - const [lon, lat] = coordinate; - this.state.values.lon = lon; - this.state.values.lat = lat; - }) -}; - -proto.stopToGetCoordinates = function(){ - ol.Observable.unByKey(this.eventMapKey); - this.mapService.off('mapcontrol:toggled', this.mapControlToggleEventHandler) -}; - -proto.clear = function(){ - this.stopToGetCoordinates(); -}; - -module.exports = LonLatService; diff --git a/src/app/gui/inputs/lonlat/vue/lonlat.js b/src/app/gui/inputs/lonlat/vue/lonlat.js deleted file mode 100644 index e311bcc6d..000000000 --- a/src/app/gui/inputs/lonlat/vue/lonlat.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputLonLat.vue'; - -const LatLontInput = Vue.extend(vueComponentOptions); - -module.exports = LatLontInput; diff --git a/src/app/gui/inputs/media/service.js b/src/app/gui/inputs/media/service.js deleted file mode 100644 index b5a04e8eb..000000000 --- a/src/app/gui/inputs/media/service.js +++ /dev/null @@ -1,10 +0,0 @@ -const { inherit, base } = require('utils'); -const Service = require('gui/inputs/service'); - -function MediaService(options={}) { - base(this, options); -} - -inherit(MediaService, Service); - -module.exports = MediaService; diff --git a/src/app/gui/inputs/media/vue/media.js b/src/app/gui/inputs/media/vue/media.js deleted file mode 100644 index 947755c72..000000000 --- a/src/app/gui/inputs/media/vue/media.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputMedia.vue'; - -const MediaInput = Vue.extend(vueComponentOptions); - -module.exports = MediaInput; diff --git a/src/app/gui/inputs/picklayer/service.js b/src/app/gui/inputs/picklayer/service.js deleted file mode 100644 index e0eb047fe..000000000 --- a/src/app/gui/inputs/picklayer/service.js +++ /dev/null @@ -1,92 +0,0 @@ -import MapLayersStoresRegistry from 'store/map-layers'; -import GUI from 'services/gui'; - -const PickFeatureInteraction = require('g3w-ol/interactions/pickfeatureinteraction'); -const PickCoordinatesInteraction = require('g3w-ol/interactions/pickcoordinatesinteraction'); -const { getQueryLayersPromisesByCoordinates } = require('utils/geo'); - -function PickLayerService(options={}) { - this.pick_type = options.pick_type || 'wms'; - this.ispicked = false; - this.fields = options.fields || [options.value]; - this.layerId = options.layer_id; - this.mapService = GUI.getService('map'); - this.interaction = this.pick_type === 'map' ? new PickFeatureInteraction({ - layers: [this.mapService.getLayerById(this.layerId)] - }) : new PickCoordinatesInteraction(); -} - -const proto = PickLayerService.prototype; - -proto.isPicked = function(){ - return this.ispicked; -}; - -//bind interrupt event -proto.escKeyUpHandler = function({keyCode, data:{owner}}) { - keyCode === 27 && owner.unpick(); -}; - -proto.unbindEscKeyUp = function() { - $(document).unbind('keyup', this.escKeyUpHandler); -}; - -proto.bindEscKeyUp = function() { - $(document).on('keyup', {owner: this}, this.escKeyUpHandler); -}; - -proto.pick = function() { - return new Promise((resolve, reject) => { - this.bindEscKeyUp(); - const values = {}; - this.ispicked = true; - const afterPick = feature => { - if (feature) { - const attributes = feature.getProperties(); - this.fields.forEach(field =>{ - values[field] = attributes[field]; - }); - resolve(values); - } else reject(); - this.ispicked = false; - this.unpick(); - }; - GUI.setModal(false); - this.mapService.addInteraction(this.interaction); - this.interaction.once('picked', event => { - if (this.pick_type === 'map') { - const feature = event.feature; - afterPick(feature); - } else if (this.pick_type === 'wms'){ - const layer = MapLayersStoresRegistry.getLayerById(this.layerId); - if (layer) { - getQueryLayersPromisesByCoordinates( - [layer], - { - map: this.mapService.getMap(), - feature_count: 1, - coordinates: event.coordinate - }).then(response => { - const {data=[]} = response[0]; - const feature = data.length && data[0].features[0] || null; - afterPick(feature); - }) - } - } - }) - }) -}; - -proto.unpick = function() { - this.mapService.removeInteraction(this.interaction); - GUI.setModal(true); - this.unbindEscKeyUp(); - this.ispicked = false; -}; - -proto.clear = function() { - this.isPicked() && this.unpick(); - this.mapService = this.interaction = this.field = null; -}; - -module.exports = PickLayerService; diff --git a/src/app/gui/inputs/picklayer/vue/picklayer.js b/src/app/gui/inputs/picklayer/vue/picklayer.js deleted file mode 100644 index 271f82ddc..000000000 --- a/src/app/gui/inputs/picklayer/vue/picklayer.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputPickLayer.vue'; - -const PickLayerInput = Vue.extend(vueComponentOptions); - -module.exports = PickLayerInput; diff --git a/src/app/gui/inputs/radio/service.js b/src/app/gui/inputs/radio/service.js deleted file mode 100644 index bca3373db..000000000 --- a/src/app/gui/inputs/radio/service.js +++ /dev/null @@ -1,10 +0,0 @@ -const { inherit, base } = require('utils'); -const Service = require('gui/inputs/service'); - -function RadioService(options={}) { - base(this, options); -} - -inherit(RadioService, Service); - -module.exports = RadioService; diff --git a/src/app/gui/inputs/radio/vue/radio.js b/src/app/gui/inputs/radio/vue/radio.js deleted file mode 100644 index 96ae2f72d..000000000 --- a/src/app/gui/inputs/radio/vue/radio.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputRadio.vue'; - -const RadioInput = Vue.extend(vueComponentOptions); - -module.exports = RadioInput; diff --git a/src/app/gui/inputs/range/service.js b/src/app/gui/inputs/range/service.js deleted file mode 100644 index 566b279f4..000000000 --- a/src/app/gui/inputs/range/service.js +++ /dev/null @@ -1,24 +0,0 @@ -const { inherit, base } = require('utils'); -const Service = require('gui/inputs/service'); -const Validators = require('utils/validators'); - -function RangeService(options={}) { - const {min, max} = options.state.input.options.values[0]; - options.state.info = `[MIN: ${min} - MAX: ${max}]`; - base(this, options); - const validator = Validators.get('range', { - min: 1*min, - max: 1*max - }); - this.setValidator(validator); -} - -inherit(RangeService, Service); - -const proto = Service.prototype; - -proto.isValueInRange = function(value, min, max) { - return value <= max && value >= min; -}; - -module.exports = RangeService; diff --git a/src/app/gui/inputs/range/vue/range.js b/src/app/gui/inputs/range/vue/range.js deleted file mode 100644 index 73d57146e..000000000 --- a/src/app/gui/inputs/range/vue/range.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputRange.vue'; - -const RangeInput = Vue.extend(vueComponentOptions); - -module.exports = RangeInput; diff --git a/src/app/gui/inputs/select/service.js b/src/app/gui/inputs/select/service.js deleted file mode 100644 index 4e02ad03a..000000000 --- a/src/app/gui/inputs/select/service.js +++ /dev/null @@ -1,62 +0,0 @@ -import CatalogLayersStoresRegistry from 'store/catalog-layers'; - -const { inherit, base } = require('utils'); -const Service = require('gui/inputs/service'); - -function SelectService(options={}) { - base(this, options); - this.layer = null; -} - -inherit(SelectService, Service); - -const proto = SelectService.prototype; - -proto._getLayerById = function(layer_id) { - return CatalogLayersStoresRegistry.getLayerById(layer_id); -}; - -proto.addValue = function(value) { - this.state.input.options.values.push(value); -}; - -proto.getKeyByValue = function({search}={}) { - const options = this.state.input.options; - const {value, key} = options; - this.getData({ - key:value, - value: key, - search - }).then(arrayValues => { - const [_value] = arrayValues; - const {$value : key, text: value} = _value; - this.addValue({ - key, - value - }) - }).catch(err => console.log(err)); -}; - -proto.getData = function({layer_id= this.state.input.options.layer_id, key=this.state.input.options.key, value=this.state.input.options.value, search} = {}) { - const search_value = `${key}|${search}`.trim(); - return new Promise((resolve, reject) => { - if (!this._layer) this._layer = this._getLayerById(layer_id); - this._layer.getDataTable({ - suggest: search_value, - ordering: key - }).then(response => { - const values = []; - const features = response.features; - for (let i=0; i < features.length; i++) { - values.push({ - text:features[i].properties[key], - id: i, - $value: features[i].properties[value] - }) - } - resolve(values); - }).fail(err => reject(err)); - }); -}; - -module.exports = SelectService; diff --git a/src/app/gui/inputs/select/vue/select.js b/src/app/gui/inputs/select/vue/select.js deleted file mode 100644 index c4452f592..000000000 --- a/src/app/gui/inputs/select/vue/select.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputSelect.vue'; - -const SelectInput = Vue.extend(vueComponentOptions); - -module.exports = SelectInput; diff --git a/src/app/gui/inputs/service.js b/src/app/gui/inputs/service.js deleted file mode 100644 index e981b22c5..000000000 --- a/src/app/gui/inputs/service.js +++ /dev/null @@ -1,155 +0,0 @@ -const Validators = require('utils/validators'); -const {toRawType} = require('utils'); -const {t} = require('core/i18n/i18n.service'); - -function Service(options = {}) { - // set state of input - this.state = options.state || {}; - // type of input - //this.state.validate.required && this.setValue(this.state.value); - /* - * set starting value of input based on value or default value on options - */ - this.setValue(this.state.value); - this.setEmpty(this.state.value); - const type = this.state.type; - const validatorOptions = (options.validatorOptions || this.state.input.options) || {}; - // useful for the validator to validate input - this._validator = Validators.get(type, validatorOptions); - this.setErrorMessage(options.state); -} - -const proto = Service.prototype; - -proto.getState = function() { - return this.state; -}; - -proto.getValue = function() { - return this.state.value; -}; - -/** - * @param value - * - * @returns {void} - */ -proto.setValue = function(value) { - if (null !== value && "undefined" !== typeof value) { - return; - } - - const {options} = this.state.input; - let default_value = options.default; - - /** @TODO (maybe need to removed in v3.9.0) double check G3W-ADMIN server configuration. */ - if (Array.isArray(options)) { - if (options[0].default) { - default_value = options[0].default; - } else if (Array.isArray(options.values) && options.values.length > 0) { - default_value = options.values[0] && (options.values[0].value || options.values[0]); - } - } - - // check if default value is set - const get_default_value = ( - this.state.get_default_value && // ref: core/layers/tablelayer.js::getFieldsWithValues() - undefined !== default_value && - null !== default_value - ); - - // check if we can state.check get_default_value from input.options.default is set - if (get_default_value && undefined === options.default_expression) { - this.state.value = default_value; - } - - this.state.value_from_default_value = get_default_value; - -}; - -proto.addValueToValues = function(value) { - this.state.input.options.values.unshift(value) -}; - -proto._getValidatorType = function() { - return this.state.type; -}; - -proto.setState = function(state={}) { - this.state = _.isObject(state) ? state : {}; -}; - -// return validator -proto.getValidator = function() { - return this._validator; -}; - -proto.setValidator = function(validator) { - this._validator = validator; -}; - -proto.setEmpty = function(){ - this.state.validate.empty = !((Array.isArray(this.state.value) && this.state.value.length) || !_.isEmpty(_.trim(this.state.value))); -}; - -// general method to check the value of the state is valid or not -proto.validate = function() { - if (this.state.validate.empty) { - this.state.validate.empty = true; - this.state.value = null; - this.state.validate.unique = true; - // check if require or check validation - this.state.validate.valid = this.state.validate.required ? false : this._validator.validate(this.state.value); - } else { - if (this.state.input.type === 'integer' || this.state.input.type === 'float') { - if (+this.state.value < 0) { - this.state.value = null; - this.state.validate.empty = true; - this.state.validate.valid = !this.state.validate.required; - } else this.state.validate.valid = this._validator.validate(this.state.value); - } - if (this.state.validate.exclude_values && this.state.validate.exclude_values.size) { - this.state.validate.valid = !this.state.validate.exclude_values.has(this.state.value); - } else this.state.validate.valid = this._validator.validate(this.state.value); - } - return this.state.validate.valid; -}; - -proto.setErrorMessage = function(input) { - let message; - if (input.validate.mutually && !input.validate.mutually_valid) - this.state.validate.message = `${t("sdk.form.inputs.input_validation_mutually_exclusive")} ( ${input.validate.mutually.join(',')} )`; - else if (input.validate.max_field) - this.state.validate.message = `${t("sdk.form.inputs.input_validation_max_field")} (${input.validate.max_field})`; - else if (input.validate.min_field) - this.state.validate.message = `${t("sdk.form.inputs.input_validation_min_field")} (${input.validate.min_field})`; - else if (input.validate.unique && input.validate.exclude_values && input.validate.exclude_values.size) - this.state.validate.message = `${t("sdk.form.inputs.input_validation_exclude_values")}`; - else if (input.validate.required) { - message = `${t("sdk.form.inputs.input_validation_error")} ( ${t("sdk.form.inputs." + input.type)} )`; - if (this.state.info) { - message = `${message} -
- ${this.state.info} -
- `; - } - this.state.validate.message = this.state.info || message; - } else this.state.validate.message = this.state.info; -}; -/** - * Method to set update - */ -proto.setUpdate = function(){ - const {value, _value} = this.state; - if (this.state.input.type === 'media' && toRawType(value) !== 'Object' && toRawType(_value) !== 'Object') { - this.state.update = value.value != _value.value; - } else if (this.state.input.type === "datetimepicker") { - //check - this.state.update = (null !== value ? value.toUpperCase(): value) != (_value ? _value.toUpperCase(): _value); - } else { - this.state.update = value != _value; - } -}; - -module.exports = Service; diff --git a/src/app/gui/inputs/services.js b/src/app/gui/inputs/services.js deleted file mode 100644 index 180550203..000000000 --- a/src/app/gui/inputs/services.js +++ /dev/null @@ -1,22 +0,0 @@ -const InputsServices = { - 'text': require('./service'), - 'textarea': require('./service'), - 'texthtml': require('./service'), - 'integer': require('./integer/service'), - 'string':require('./service'), - 'float': require('./float/service'), - 'radio': require('./radio/service'), - 'check': require('./checkbox/service'), - 'range': require('./range/service'), - 'datetimepicker': require('./datetimepicker/service'), - 'unique': require('./unique/service'), - 'select': require('./select/service'), - 'media': require('./media/service'), - 'select_autocomplete': require('./select/service'), - 'picklayer': require('./service'), - 'color': require('./service'), - 'slider': require('./sliderrange/service'), - 'lonlat': require('./lonlat/service') -}; - -module.exports = InputsServices; diff --git a/src/app/gui/inputs/sliderrange/service.js b/src/app/gui/inputs/sliderrange/service.js deleted file mode 100644 index dfbeb1ca6..000000000 --- a/src/app/gui/inputs/sliderrange/service.js +++ /dev/null @@ -1,29 +0,0 @@ -const { base, inherit } = require('utils'); -const Service = require('gui/inputs/service'); -const Validators = require('utils/validators'); - -function SliderRangeService(options={}) { - const {state} = options; - options.state.info = `[MIN: ${state.input.options.min} - MAX: ${state.input.options.max}]`; - base(this, options); - const validator = Validators.get('range', { - min: 1*state.input.options.min, - max: 1*state.input.options.max - }); - this.setValidator(validator); - this.validate = function(){ - this.state.value = 1*this.state.value; - this.state.validate.valid = this.state.value >= this.state.input.options.min || this.state.value <= this.state.input.options.max; - } -} - -inherit(SliderRangeService, Service); - -const proto = SliderRangeService.prototype; - -proto.changeInfoMessage = function(){ - this.state.info = `[MIN: ${this.state.input.options.min} - MAX: ${this.state.input.options.max}]`; -}; - - -module.exports = SliderRangeService; \ No newline at end of file diff --git a/src/app/gui/inputs/sliderrange/vue/sliderrange.js b/src/app/gui/inputs/sliderrange/vue/sliderrange.js deleted file mode 100644 index 7fa39bd18..000000000 --- a/src/app/gui/inputs/sliderrange/vue/sliderrange.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputSliderRange.vue'; - -const RangeInput = Vue.extend(vueComponentOptions); - -module.exports = RangeInput; diff --git a/src/app/gui/inputs/table/vue/table.js b/src/app/gui/inputs/table/vue/table.js deleted file mode 100644 index 4cb8e7a8c..000000000 --- a/src/app/gui/inputs/table/vue/table.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputTable.vue'; - -const TableInput = Vue.extend(vueComponentOptions); - -module.exports = TableInput; diff --git a/src/app/gui/inputs/text/vue/text.js b/src/app/gui/inputs/text/vue/text.js deleted file mode 100644 index a9a86f7d8..000000000 --- a/src/app/gui/inputs/text/vue/text.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputText.vue'; - -const TextInput = Vue.extend(vueComponentOptions); - -module.exports = TextInput; diff --git a/src/app/gui/inputs/textarea/vue/textarea.js b/src/app/gui/inputs/textarea/vue/textarea.js deleted file mode 100644 index 757c434a7..000000000 --- a/src/app/gui/inputs/textarea/vue/textarea.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputTextArea.vue'; - -const TextAreaInput = Vue.extend(vueComponentOptions); - -module.exports = TextAreaInput; diff --git a/src/app/gui/inputs/texthtml/vue/texthtml.js b/src/app/gui/inputs/texthtml/vue/texthtml.js deleted file mode 100644 index 7adf8f1ec..000000000 --- a/src/app/gui/inputs/texthtml/vue/texthtml.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputTextHtml.vue'; - -const TextHtmlInput = Vue.extend(vueComponentOptions); - -module.exports = TextHtmlInput; \ No newline at end of file diff --git a/src/app/gui/inputs/unique/service.js b/src/app/gui/inputs/unique/service.js deleted file mode 100644 index f29cf34dc..000000000 --- a/src/app/gui/inputs/unique/service.js +++ /dev/null @@ -1,10 +0,0 @@ -const { inherit, base } = require('utils'); -const Service = require('gui/inputs/service'); - -function UniqueService(options={}) { - base(this, options); -} - -inherit(UniqueService, Service); - -module.exports = UniqueService; diff --git a/src/app/gui/inputs/unique/vue/unique.js b/src/app/gui/inputs/unique/vue/unique.js deleted file mode 100644 index dd0ba6c5b..000000000 --- a/src/app/gui/inputs/unique/vue/unique.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as vueComponentOptions from 'components/InputUnique.vue'; - -const UniqueInput = Vue.extend(vueComponentOptions); - -module.exports = UniqueInput; diff --git a/src/app/gui/map/mapservice.js b/src/app/gui/map/mapservice.js index 5281c8a4e..9be37c4c8 100644 --- a/src/app/gui/map/mapservice.js +++ b/src/app/gui/map/mapservice.js @@ -5,28 +5,33 @@ import ProjectsRegistry from 'store/projects'; import ApplicationService from 'services/application'; import ControlsRegistry from 'store/map-controls'; import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; import MapControlZoomHistory from "components/MapControlZoomHistory.vue"; import MapControlGeocoding from 'components/MapControlGeocoding.vue'; import { getScaleFromResolution } from 'utils/getScaleFromResolution'; import { getResolutionFromScale } from 'utils/getResolutionFromScale'; +const { t } = require('core/i18n/i18n.service'); + const { inherit, base, copyUrl, uniqueId, throttle, - toRawType, createFilterFromString, } = require('utils'); -const G3WObject = require('core/g3wobject'); const { createVectorLayerFromFile, createWMSLayer, createSelectedStyle, getMapLayersByFilter, getGeoTIFFfromServer, -} = require('utils/geo'); +} = require('core/utils/geo'); +const { + getScaleFromResolution, + getResolutionFromScale, +} = require('utils/ol'); const BaseLayers = require('g3w-ol/layers/bases'); const VectorLayer = require('core/layers/vectorlayer'); diff --git a/src/app/gui/metadata/metadataservice.js b/src/app/gui/metadata/metadataservice.js index ecfbe7941..e97e6d9e1 100644 --- a/src/app/gui/metadata/metadataservice.js +++ b/src/app/gui/metadata/metadataservice.js @@ -1,8 +1,8 @@ -import ProjectsRegistry from 'store/projects'; -import GUI from 'services/gui'; +import ProjectsRegistry from 'store/projects'; +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; +import { inherit } from 'utils'; -const { inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); const ProjectMetadataComponent = require('gui/metadata/vue/components/project/project'); const METADATAGROUPS = { diff --git a/src/app/gui/panel.js b/src/app/gui/panel.js index e9bf731ab..6abbe421d 100644 --- a/src/app/gui/panel.js +++ b/src/app/gui/panel.js @@ -1,7 +1,9 @@ -import GUI from 'services/gui'; - -const { inherit, resolve: resolvedValue } = require('utils'); -const G3WObject = require('core/g3wobject'); +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; +import { + inherit, + resolve as resolvedValue, +} from 'utils'; const Panel = function(options={}) { this.id = options.id || null; diff --git a/src/app/gui/print/printservice.js b/src/app/gui/print/printservice.js index 65c2d58f3..0ed724929 100644 --- a/src/app/gui/print/printservice.js +++ b/src/app/gui/print/printservice.js @@ -2,11 +2,12 @@ import ProjectsRegistry from 'store/projects'; import ApplicationService from 'services/application'; import ApplicationState from 'store/application-state'; import { - PRINT_SCALES as scale, + PRINT_SCALES as scale, PRINT_RESOLUTIONS as dpis, - PRINT_FORMATS as formats + PRINT_FORMATS as formats } from 'app/constant'; import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; import { getScaleFromResolution } from 'utils/getScaleFromResolution'; import { getResolutionFromScale } from 'utils/getResolutionFromScale'; import { getMetersFromDegrees } from 'utils/getMetersFromDegrees'; diff --git a/src/app/gui/queryresults/queryresultsservice.js b/src/app/gui/queryresults/queryresultsservice.js index 46af5587e..02e67f1d2 100644 --- a/src/app/gui/queryresults/queryresultsservice.js +++ b/src/app/gui/queryresults/queryresultsservice.js @@ -10,6 +10,7 @@ import CatalogLayersStoresRegistry from 'store/catalog-layers'; import DownloadFormats from 'components/QueryResultsActionDownloadFormats.vue'; import QueryPolygonCsvAttributesComponent from 'components/QueryResultsActionQueryPolygonCSVAttributes.vue'; import ApplicationService from 'services/application'; +import G3WObject from 'core/g3wobject'; import { addToSelection } from 'core/layers/utils/addToSelection'; import { removeFromSelection } from 'core/layers/utils/removeFromSelection'; @@ -32,7 +33,6 @@ const { const { t } = require('core/i18n/i18n.service'); const Layer = require('core/layers/layer'); -const G3WObject = require('core/g3wobject'); const VectorLayer = require('core/layers/vectorlayer'); const { PRINT_UTILS } = require('gui/print/printservice'); const RelationsPage = require('gui/relations/vue/relationspage'); diff --git a/src/app/gui/relations/relationsservice.js b/src/app/gui/relations/relationsservice.js index d62586e0c..8974035b2 100644 --- a/src/app/gui/relations/relationsservice.js +++ b/src/app/gui/relations/relationsservice.js @@ -1,10 +1,10 @@ -import { G3W_FID } from 'app/constant'; -import RelationsService from 'services/relations'; +import { G3W_FID } from 'app/constant'; +import RelationsService from 'services/relations'; import ApplicationService from 'services/application'; -import GUI from 'services/gui'; +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; const { inherit, base } = require('utils'); -const G3WObject = require('core/g3wobject'); function RelationsComponentService(options={}) { this.state = {}; diff --git a/src/app/gui/search/service.js b/src/app/gui/search/service.js index eff5c459b..e826f2b89 100644 --- a/src/app/gui/search/service.js +++ b/src/app/gui/search/service.js @@ -1,9 +1,8 @@ import QueryBuilderService from 'services/querybuilder'; -import ProjectsRegistry from 'store/projects'; +import ProjectsRegistry from 'store/projects'; +import G3WObject from 'core/g3wobject'; const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); -const SearchPanel = require('gui/search/vue/panel/searchpanel'); function Service() { base(this); diff --git a/src/app/gui/search/vue/panel/searchservice.js b/src/app/gui/search/vue/panel/searchservice.js index 28285f031..7d4a6d3d2 100644 --- a/src/app/gui/search/vue/panel/searchservice.js +++ b/src/app/gui/search/vue/panel/searchservice.js @@ -1,8 +1,9 @@ import { SEARCH_ALLVALUE as ALLVALUE } from 'app/constant'; -import CatalogLayersStoresRegistry from 'store/catalog-layers'; -import DataRouterService from 'services/data'; -import ProjectsRegistry from 'store/projects'; -import GUI from 'services/gui'; +import CatalogLayersStoresRegistry from 'store/catalog-layers'; +import DataRouterService from 'services/data'; +import ProjectsRegistry from 'store/projects'; +import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; const { base, @@ -16,7 +17,6 @@ const { sortNumericArray } = require('utils'); -const G3WObject = require('core/g3wobject'); const NONVALIDVALUES = [null, undefined, ALLVALUE]; diff --git a/src/app/gui/table/tableservice.js b/src/app/gui/table/tableservice.js index 50b21de3f..06fb25611 100644 --- a/src/app/gui/table/tableservice.js +++ b/src/app/gui/table/tableservice.js @@ -1,12 +1,12 @@ import CatalogLayersStoresRegistry from 'store/catalog-layers'; import DataRouterService from 'services/data'; import GUI from 'services/gui'; +import G3WObject from 'core/g3wobject'; -const { inherit, noop } = require('utils'); -const G3WObject = require('core/g3wobject'); -const { t } = require('core/i18n/i18n.service'); -const { coordinatesToGeometry } = require('utils/geo'); -const { SELECTION_STATE } = require('core/layers/layer'); +const { inherit, noop } = require('utils'); +const { t } = require('core/i18n/i18n.service'); +const { coordinatesToGeometry } = require('utils/geo'); +const { SELECTION_STATE } = require('core/layers/layer'); const PAGELENGTHS = [10, 25, 50]; diff --git a/src/app/gui/tools/service.js b/src/app/gui/tools/service.js index 0c2b51643..28bd710c1 100644 --- a/src/app/gui/tools/service.js +++ b/src/app/gui/tools/service.js @@ -1,7 +1,7 @@ import ProjectsRegistry from 'store/projects'; +import G3WObject from 'core/g3wobject'; const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); function Service(options={}){ this.config = null; diff --git a/src/app/gui/utils/barstack.js b/src/app/gui/utils/barstack.js index 6f557421d..12ac3b770 100644 --- a/src/app/gui/utils/barstack.js +++ b/src/app/gui/utils/barstack.js @@ -1,7 +1,8 @@ +import G3WObject from 'core/g3wobject'; + const { resolve, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); -const Component = require('gui/component/component'); -const Panel = require('gui/panel'); +const Component = require('gui/component/component'); +const Panel = require('gui/panel'); //Barstack Class // It used to mount panels stack diff --git a/src/components/Catalog.vue b/src/components/Catalog.vue index 3db37791c..4b7aa91b5 100644 --- a/src/components/Catalog.vue +++ b/src/components/Catalog.vue @@ -122,14 +122,14 @@ - \ No newline at end of file + created() { + this.type = fieldsMixin.methods.getFieldService().getType(this.state); + }, + +}; + \ No newline at end of file diff --git a/src/components/FieldGallery.vue b/src/components/FieldGallery.vue index 114daa4d3..1a78d4e74 100644 --- a/src/components/FieldGallery.vue +++ b/src/components/FieldGallery.vue @@ -6,26 +6,34 @@ --> - - \ No newline at end of file + }; + \ No newline at end of file diff --git a/src/components/Relation.vue b/src/components/Relation.vue index 066308687..176fb1e1c 100644 --- a/src/components/Relation.vue +++ b/src/components/Relation.vue @@ -4,6 +4,7 @@ -->