Commit ead460f2 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Integra petición de env con RestManager

Elimina otro uso directo de dojo/request, aprovechando las
funcionalidades del módulo RestManager. El módulo Router ahora pide los
valores del entorno a través suyo, como el resto.
Define nombre de variable para prefijo de servicios de REDMIC en
redmicConfig, para poder referenciarla desde todos sitios.
parent 2ff762f4
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ define([
	, 'dojo/has'
	, 'dojo/io-query'
	, 'dojo/mouse'
	, 'dojo/request'
	, 'put-selector/put'
	, 'redmic/base/CheckBrowser'
	, 'redmic/modules/notification/CommunicationCenter'
@@ -22,6 +21,7 @@ define([
	//, 'redmic/modules/base/NavegationHistory'
	, 'redmic/modules/base/MetaTags'
	, 'redmic/modules/base/_Module'
	, 'redmic/modules/base/_Store'
	, 'redmic/modules/base/Loading'
	, 'redmic/modules/store/RestManagerImpl'
	, 'templates/LoadingCustom'
@@ -39,7 +39,6 @@ define([
	, has
	, ioQuery
	, mouse
	, request
	, put
	, CheckBrowser
	, CommunicationCenter
@@ -49,6 +48,7 @@ define([
	//, NavegationHistory
	, MetaTags
	, _Module
	, _Store
	, Loading
	, RestManagerImpl
	, LoadingCustomTemplate
@@ -85,7 +85,7 @@ define([
		return;
	}

	return declare(_Module, {
	return declare([_Module, _Store], {
		//	summary:
		//		Módulo encargado de controlar el acceso a la aplicación.
		//	description:
@@ -133,6 +133,7 @@ define([
					HOME: 'home',
					LOGIN: 'login'
				},
				target: '/env',
				_reconnectTimeout: 10000
			};

@@ -141,8 +142,6 @@ define([
			new CookieLoader();

			this._setRouterListeners();

			this._getEnv();
		},

		_initialize: function() {
@@ -218,6 +217,8 @@ define([

		postCreate: function() {

			this._getEnv();

			this._emitEvt('GET_CREDENTIALS');

			this.inherited(arguments);
@@ -330,16 +331,22 @@ define([
			var envDfd = getGlobalContext().env;

			if (envDfd && !envDfd.isFulfilled()) {
				request('/env', {
					handleAs: 'json'
				}).then(lang.hitch(envDfd, function(data) {
				this._emitEvt('GET', {
					target: this.target
				});
			}
		},

					this.resolve(data);
				}),lang.hitch(envDfd, function(error) {
		_itemAvailable: function(res) {

					this.reject(error);
				}));
			}
			var envDfd = getGlobalContext().env;
			envDfd.resolve(res.data);
		},

		_errorAvailable: function(error, status, resWrapper) {

			var envDfd = getGlobalContext().env;
			envDfd.reject(error);
		},

		_subCredentialsRemoved: function() {
+2 −0
Original line number Diff line number Diff line
@@ -124,6 +124,8 @@ define([], function() {
	var baseUri = '{apiUrl}/',
		baseMediastorageUploads = baseUri + 'mediastorage/uploads/';

	retObj.apiUrlVariable = baseUri.slice(0, -1);

	retObj.services = {
		'grafcan': 'https://visor.grafcan.es/busquedas/toponimo',
		'socket': baseUri + 'socket',
+5 −3
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	'app/redmicConfig'
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "dojo/Deferred"
@@ -8,7 +9,8 @@ define([
	, "./_NodesCreation"
	, "./_InputItfc"
], function(
	declare
	redmicConfig
	, declare
	, lang
	, aspect
	, Deferred
@@ -397,7 +399,7 @@ define([
					apiPrefix = '/api/';

				if (url.indexOf(apiPrefix) === 0) {
					url = url.replace(apiPrefix, '{apiUrl}/');
					url = url.replace(apiPrefix, redmicConfig.apiUrlVariable + '/');
				}
				this._inputProps.target = url;
			}
+14 −7
Original line number Diff line number Diff line
define([
	'dojo/_base/declare'
	'app/redmicConfig'
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'dojo/Deferred'
	, 'dojo/promise/all'
@@ -9,7 +10,8 @@ define([
	, './_SelectorItfc'
	, './_SelectorPersistence'
], function(
	declare
	redmicConfig
	, declare
	, lang
	, Deferred
	, all
@@ -104,6 +106,11 @@ define([
			});
		},

		_targetHasRedmicPrefixForReplacement: function(target) {

			return target.indexOf(redmicConfig.apiUrlVariable) !== -1;
		},

		_subSelect: function(req) {

			var items = req.items,
@@ -117,7 +124,7 @@ define([
				req.items = items;
			}

			if (target.indexOf('{apiUrl}') !== -1) {
			if (this._targetHasRedmicPrefixForReplacement(target)) {
				this._emitSave(this._getDataToSave('SELECT', req));
			} else {
				this._select(items, target);
@@ -199,7 +206,7 @@ define([
				req.items = items;
			}

			if (target.indexOf('{apiUrl}') !== -1) {
			if (this._targetHasRedmicPrefixForReplacement(target)) {
				this._emitSave(this._getDataToSave('DESELECT', req));
			} else {
				this._deselect(items, target);
@@ -272,7 +279,7 @@ define([

			var target = req.target;

			if (target.indexOf('{apiUrl}') !== -1) {
			if (this._targetHasRedmicPrefixForReplacement(target)) {
				this._emitSelectionTargetLoading(target);
				this._emitSave(this._getDataToSave('CLEAR_SELECTION', req));
			} else {
@@ -364,7 +371,7 @@ define([

			var target = req.target;

			if (target.indexOf('{apiUrl}') !== -1) {
			if (this._targetHasRedmicPrefixForReplacement(target)) {
				this._storeSelection(req);
			} else {
				console.error('Local selection cannot be stored for "%s"', target);
@@ -375,7 +382,7 @@ define([

			var target = req.target;

			if (target.indexOf('{apiUrl}') !== -1) {
			if (this._targetHasRedmicPrefixForReplacement(target)) {
				this._retrieveSelectionsTarget(req);
			} else {
				console.error('Local selection cannot be retrieved for "%s"', target);
+13 −8
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ define([

		_subGet: function(req) {

			this._getEnvironmentData(lang.hitch(this, this._doGet, req));
			this._getEnvironmentData(lang.hitch(this, this._doGet), req);
		},

		_doGet: function(req) {
@@ -165,7 +165,7 @@ define([

		_subRequest: function(req) {

			this._getEnvironmentData(lang.hitch(this, this._doRequest, req));
			this._getEnvironmentData(lang.hitch(this, this._doRequest), req);
		},

		_doRequest: function(req) {
@@ -246,7 +246,7 @@ define([

		_subSave: function(req) {

			this._getEnvironmentData(lang.hitch(this, this._doSave, req));
			this._getEnvironmentData(lang.hitch(this, this._doSave), req);
		},

		_doSave: function(req) {
@@ -303,7 +303,7 @@ define([

		_subRemove: function(req) {

			this._getEnvironmentData(lang.hitch(this, this._doRemove, req));
			this._getEnvironmentData(lang.hitch(this, this._doRemove), req);
		},

		_doRemove: function(req) {
@@ -345,10 +345,10 @@ define([
			});
		},

		_getEnvironmentData: function(callback) {
		_getEnvironmentData: function(callback, req) {

			if (this._env) {
				callback && callback();
			if (this._env || !this._targetNeedRedmicPrefixReplacement(req.target)) {
				callback(req);
				return;
			}

@@ -357,11 +357,16 @@ define([
				envDfd.then(lang.hitch(this, function(envData) {

					this._env = envData;
					callback && callback();
					callback(req);
				}));
			}
		},

		_targetNeedRedmicPrefixReplacement: function(target) {

			return target.indexOf(redmicConfig.apiUrlVariable) !== -1;
		},

		_getResolvedTarget: function(target) {

			return redmicConfig.getServiceUrl(target, this._env);