Commit 967dd862 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Limpia y organiza, amplía datos de redpromar

parent d62b32f9
Loading
Loading
Loading
Loading
+8 −17
Original line number Diff line number Diff line
@@ -9,32 +9,20 @@ module.exports = function(grunt) {
					knownHelpers: {
						// legacy (ir eliminando)
						DetailsTitle: true,
						PropertiesAtlas: true,
						TimeCumulative: true,
						Progress: true,
						qualityControl: true,
						GroupIcon: true,
						GroupIconInspire: true,
						URL: true,
						UrlWebcam: true,
						TextURL: true,
						Icon: true,
						Href: true,
						Badge: true,
						Email: true,
						Array: true,
						Hierarchy: true,
						listSeparate: true,
						RowColBibliography: true,
						RowColActivityCatalog: true,
						RowColSpeciesCatalog: true,
						RowColServiceOGCCatalog: true,
						URLDetails: true,
						ancestorsSpecies: true,
						ancestorsActivity: true,
						insertButton: true,
						Date: true,
						DateTime: true,
						lang: true,
						Translate: true,
						ChartsHierarchicalListParse: true,
@@ -46,16 +34,11 @@ module.exports = function(grunt) {
						Keyword: true,
						ArrayString: true,
						Classifications: true,
						bold: true,
						IterateJSON: true,
						ProtocolsServiceOGC: true,
						DownloadServiceOGC: true,
						breaklines: true,
						textOrSpace: true,
						PrintProperty: true,
						SafeUrl: true,
						concat: true,
						showBoolean: true,
						reverse: true,
						PathLength: true,
						Parents: true,
@@ -77,9 +60,17 @@ module.exports = function(grunt) {
						DocumentInternalUrlStatus: true,
						DocumentUrl: true,
						Image: true,
						AtlasProperties: true,

						// string
						bold: true,
						Boolean: true,
						breaklines: true,
						Capitalize: true,
						concat: true,
						Date: true,
						DateTime: true,
						TextURL: true,

						// subExpression
						PropertyIsDefinedAndFalse: true
+30 −25
Original line number Diff line number Diff line
<span class='spanTemplate'>
	{{#if data.properties.taxondescription}}
	<span class='subtitle'>
		{{bold i18n.scientificName}}: <span class="scientificName">{{data.properties.taxondescription}}</span>
	{{#if data.properties.code}}
	<span class='paddingItemInRow'>
		{{bold i18n.code}}: {{#if data.properties.url}}{{TextURL data.properties.url data.properties.code i18n.viewAtRedpromar}}{{else}}{{data.properties.code}}{{/if}}
	</span>
	{{/if}}
	{{#if data.properties.collectorname}}
	<span class='subtitle'>
	<span class='paddingItemInRow'>
		{{bold i18n.author}}: {{data.properties.collectorname}}
	</span>
	{{/if}}
	{{#if data.properties.date}}
	<span class='subtitle'>
	<span class='paddingItemInRow'>
		{{bold i18n.date}}: {{DateTime data.properties.date}}
	</span>
	{{/if}}
	{{#if data.geometry.coordinates}}
	<span class='subtitle'>
	<span class='paddingItemInRow'>
		{{bold i18n.x}}: {{toFixed data.geometry.coordinates.[0] 5}}
	</span>
	<span class='subtitle'>
	<span class='paddingItemInRow'>
		{{bold i18n.y}}: {{toFixed data.geometry.coordinates.[1] 5}}
	</span>
	{{/if}}
	{{#if data.properties.code}}
	<span class='subtitle'>
		{{bold i18n.code}}: {{data.properties.code}}
	</span>
	{{/if}}
	{{#if data.properties.remark}}
	<span class='subtitle'>
		{{bold i18n.remark}}: {{data.properties.remark}}
	</span>
	{{/if}}
	{{#if data.properties.specimencount}}
	<span class='subtitle'>
	<span class='paddingItemInRow'>
		{{bold i18n.count}}: {{data.properties.specimencount}}
	</span>
	{{/if}}
	{{#if data.properties.z}}
	<span class='subtitle'>
	<span class='paddingItemInRow'>
		{{bold i18n.z}}: {{data.properties.z}}
	</span>
	{{/if}}
	{{#if data.properties.taxonid}}
	<span class='subtitle'>
		{{bold i18n.taxonid}}: {{data.properties.taxonid}}
	{{#if data.properties.scientificname}}
	<span class='paddingItemInRow'>
		{{bold i18n.scientificname}}: {{#if data.properties.taxonurl}}{{TextURL data.properties.taxonurl data.properties.scientificname i18n.viewAtRedpromar}}{{else}}{{data.properties.scientificname}}{{/if}}
	</span>
	{{/if}}
	{{#if data.properties.divulgativename}}
	<span class='paddingItemInRow'>
		{{bold i18n.commonName}}: {{data.properties.divulgativename}}
	</span>
	{{/if}}
	{{#if data.properties.scientificcategory}}
	<span class='paddingItemInRow'>
		{{bold i18n.scientificcategory}}: {{data.properties.scientificcategory}}
	</span>
	{{/if}}
	{{#if data.properties.divulgativecategory}}
	<span class='paddingItemInRow'>
		{{bold i18n.divulgativecategory}}: {{data.properties.divulgativecategory}}
	</span>
	{{/if}}
	{{#if data.properties.images}}
	<span class='subtitle'>
		{{ServiceOGCImageList data.properties.images}}
	{{#if data.properties.activityid}}
	<span class='paddingItemInRow'>
		{{bold i18n.activity}}: {{TextURL (concat 'catalog/activity-info/' data.properties.activityid) data.properties.activityid i18n.goToActivity}}
	</span>
	{{/if}}
</span>
+2 −2
Original line number Diff line number Diff line
<span class='spanTemplate'>
	{{PropertiesAtlas data i18n}}
	{{AtlasProperties data i18n}}
</span>
+104 −0
Original line number Diff line number Diff line
@@ -3,11 +3,13 @@ define([
	, 'dojo/_base/lang'
	, 'handlebars/handlebars.runtime.min'
	, 'redmic/base/Credentials'
	, 'redmic/validation/stringFormats'
], function(
	redmicConfig
	, lang
	, handlebars
	, Credentials
	, stringFormats
) {

	'use strict';
@@ -247,6 +249,108 @@ define([
			var imgItem = '<img src="' + imgSrc + '"/><br>';

			return new handlebars.SafeString(imgItem);
		},

		AtlasProperties: function(data, i18n) {

			// TODO esto hay que revisarlo, es un monstruo con utilidad dudosa
			var addWebcam = function (url, notHref) {

				var content = "",
					classContainer = 'containerImageOrWebcam fWidth fHeight',
					link = "<a href=" + url + " target='_blank' title=''>" +
						"<i class='paddingContainerWebcam fa fa-link'></i> " + Utilities.capitalize(i18n.link) + "</a>";

				if (url.includes("youtube")) {
					var urlFormat = url;

					urlFormat += '?rel=0&amp;controls=0&amp;showinfo=0&autoplay=1';

					urlFormat = urlFormat.replace('watch?v=', 'embed/');

					content = "<iframe class='" + classContainer + "' src=" + urlFormat + " allowfullscreen></iframe>";
				}

				if (isImage(url)) {
					content = "<a href=" + url + " target='_blank' title=''>";
					content += "<img class='" + classContainer + " loadingByImg' src=" + url + " title='" + url +
						"' onerror=\"this.src = '/resources/images/noIMG.png';this.style='max-width: 20rem;'\"" +
						" onload=\"this.classList.remove('loadingByImg');\"></img></a>";
				}

				if (!content && notHref) {
					return;
				}

				if (!notHref) {
					content += link;
				}

				return new handlebars.SafeString(content);
			},
			isImage = function(value) {

				var typeFormats = ["jpg", "cgi"],
					checkImage = false;

				for (var i = 0; i < typeFormats.length; i++) {
					if (value.includes(typeFormats[i])) {
						checkImage = true;
						break;
					}
				}

				return checkImage;
			},
			atlasProperty = function(key, value, i18n) {

				if (value === null || value === undefined || value === '') {
					return '';
				}

				var content = '<span class="paddingItemInRow"><span class="bold fontExo2">' + (i18n[key] || key) +
					'</span>: ';

				if (value === 0 || value === false) {
					content += handlebars.helpers.breaklines(value);
				} else if (!stringFormats.url(value)) {
					content += handlebars.helpers.TextURL(value, i18n.link, i18n[key]);
				} else if (!stringFormats['date-time'](value)) {
					content += handlebars.helpers.DateTime(value);
				} else if (!stringFormats.date(value)) {
					content += handlebars.helpers.Date(value);
				} else if (typeof value === 'string' && value.indexOf('</') !== -1) {
					content += value;
				} else {
					content += handlebars.helpers.breaklines(value);
				}

				content += '</span>';

				return content;
			};

			var content = '',
				props = data.properties || data,
				value = props.url;

			if (value && !stringFormats.url(value)) {
				var imageOrWebcam = addWebcam(value, true);
				if (imageOrWebcam) {
					content = '<span class="paddingItemInRow">' + imageOrWebcam + '</span>';
				}
			}

			if (data.geometry && data.geometry.type && data.geometry.type === 'Point') {
				content += atlasProperty('x', data.geometry.coordinates[0], i18n);
				content += atlasProperty('y', data.geometry.coordinates[1], i18n);
			}

			for (var key in props) {
				content += atlasProperty(key, props[key], i18n);
			}

			return new handlebars.SafeString(content);
		}
	};
});
+0 −264
Original line number Diff line number Diff line
@@ -3,14 +3,12 @@ define([
	, 'handlebars/handlebars.runtime.min'
	, 'moment/moment.min'
	, 'redmic/base/Credentials'
	, 'redmic/validation/stringFormats'
	, 'RWidgets/Utilities'
], function(
	i18n
	, handlebars
	, moment
	, Credentials
	, stringFormats
	, Utilities
) {

@@ -59,140 +57,9 @@ define([
			}

			return new handlebars.SafeString(result);
		},
		breaklines = function (text) {

			text = handlebars.Utils.escapeExpression(text);
			text = text.replace(/(\r\n|\n|\r)/gm, '<br>');

			return new handlebars.SafeString(text);
		},
		textUrl = function (url, text, title) {

			return new handlebars.SafeString("<a href='" + url + "' target='_blank' title='" + title + "'>" + text + "</a>");
		},
		dateTime = function (dateTime) {

			if (dateTime) {
				var format = dojoConfig.locale === "en" ? "MM/DD/YYYY HH:mm:ss" : "DD/MM/YYYY HH:mm:ss",
					formatted = moment(dateTime).format(format);

				return new handlebars.SafeString(formatted);
			}
		},
		date = function (date) {

			if (date) {
				var format = dojoConfig.locale === "en" ? "MM/DD/YYYY" : "DD/MM/YYYY",
					formatted = moment(date).format(format);

				return new handlebars.SafeString(formatted);
			}
		},
		addWebcam = function (url, notHref) {

			var content = "",
				classContainer = 'containerImageOrWebcam fWidth fHeight',
				link = "<a href=" + url + " target='_blank' title=''>" +
					"<i class='paddingContainerWebcam fa fa-link'></i> " + Utilities.capitalize(i18n.link) + "</a>";

			if (url.includes("youtube")) {
				var urlFormat = url;

				urlFormat += '?rel=0&amp;controls=0&amp;showinfo=0&autoplay=1';

				urlFormat = urlFormat.replace('watch?v=', 'embed/');

				content = "<iframe class='" + classContainer + "' src=" + urlFormat + " allowfullscreen></iframe>";
			}

			if (isImage(url)) {
				content = "<a href=" + url + " target='_blank' title=''>";
				content += "<img class='" + classContainer + " loadingByImg' src=" + url + " title='" + url +
					"' onerror=\"this.src = '/resources/images/noIMG.png';this.style='max-width: 20rem;'\"" +
					" onload=\"this.classList.remove('loadingByImg');\"></img></a>";
			}

			if (!content && notHref) {
				return;
			}

			if (!notHref) {
				content += link;
			}

			return new handlebars.SafeString(content);
		},
		isImage = function(value) {

			var typeFormats = ["jpg", "cgi"],
				checkImage = false;

			for (var i = 0; i < typeFormats.length; i++) {
				if (value.includes(typeFormats[i])) {
					checkImage = true;
					break;
				}
			}

			return checkImage;
		},
		propToAtlas = function(key, value) {

			var content = '',
				classRow = 'paddingItemInRow';

			if (value !== null && value !== undefined && value !== '') {

				content += '<span class="' + classRow + '"><span class="bold fontExo2">' + (i18n[key] || key) +
					'</span>: ';

				if (value === 0 || value === false) {
					content += breaklines(value);
				} else if (!stringFormats.url(value)) {
					content += textUrl(value, i18n.link, i18n[key]);
				} else if (!stringFormats['date-time'](value)) {
					content += dateTime(value);
				} else if (!stringFormats.date(value)) {
					content += date(value);
				} else if (typeof value === 'string' && value.indexOf('</') !== -1) {
					content += value;
				} else {
					content += breaklines(value);
				}

				content += '</span>';
			}

			return content;
		};

	return {
		'PropertiesAtlas': function(data) {

			var content = '',
				props = data.properties || data,
				value = props.url;

			if (value && !stringFormats.url(value)) {
				var imageOrWebcam = addWebcam(value, true);
				if (imageOrWebcam) {
					content = '<span class="paddingItemInRow">' + imageOrWebcam + '</span>';
				}
			}

			if (data.geometry && data.geometry.type && data.geometry.type === 'Point') {
				content += propToAtlas('x', data.geometry.coordinates[0]);
				content += propToAtlas('y', data.geometry.coordinates[1]);
			}

			for (var key in props) {
				content += propToAtlas(key, props[key]);
			}

			return new handlebars.SafeString(content);
		},

		'TimeCumulative': function(time, unitTime, i18n) {

			if (time) {
@@ -282,18 +149,6 @@ define([
			}
		},

		'qualityControl': function(data, i18n) {

			// TODO no se esta usando actualmente porque no esta implementado

			var result = '';
			if (!data.qualityControl) {
				result += "<i title='" + i18n.qualityControl + "' class='fa fa-check greenIcon'></i>";
			}

			return new handlebars.SafeString(result);
		},

		'GroupIcon': function(icon) {

			if (icon) {
@@ -331,25 +186,6 @@ define([
			return new handlebars.SafeString(content + "'></i>");
		},

		'URL': function(url) {

			if (url) {
				return new handlebars.SafeString("<a href=" + url + " target='_blank' title='" + url + "'>" + url + "</a>");
			}
		},

		'UrlWebcam': addWebcam,

		'TextURL': textUrl,

		'Icon': function(url, type) {

			if (type === 'PDF') {
				return new handlebars.SafeString("<a href=" + url + "?access_token=" + Credentials.get("accessToken") +
					" target='_blank' title='" + type + "'><div class='detailsBottomBarButton pdfLogo'></div></a>");
			}
		},

		'Href': function(href, id) {

			var content = "href='" + href;
@@ -361,24 +197,6 @@ define([
			return new handlebars.SafeString(content + "' d-state-url=true");
		},

		'Badge': function(url, classBadge, title, label, subLabel, aphia) {

			var content = '';

			if (url) {
				content += "<a href=" + url + " target='_blank' class='noDecoratedLink' title='" + title + "'>";
			}

			content += "<div class='badge " + classBadge + "'><span class='badgeLabel'>" + label +
				"</span><span class='badgeSubLabel'>(" + subLabel + ": " + aphia + ")</span></div>";

			if (url) {
				content += "</a>";
			}

			return new handlebars.SafeString(content);
		},

		'Email': function(email) {

			if (email) {
@@ -407,26 +225,6 @@ define([
			return new handlebars.SafeString(content);
		},

		'Hierarchy': function(data) {

			var ord = ["kingdom", "phylum", "subphylum", "class", "order", "family", "genus", "species", "subspecies", "variety"],
				content = '';

			for (var i = 0; i < ord.length; i++) {
				if (data[ord[i]]) {
					if (content.length > 0) {
						content += " > ";
					}

					content += data[ord[i]].scientificName;
				}
			}

			if (content.length > 0) {
				return new handlebars.SafeString("<span>" + content + "</span>");
			}
		},

		'listSeparate': function(data, separate, path) {

			var content = '';
@@ -488,19 +286,6 @@ define([
			}
		},

		'URLDetails': function(url) {

			var content;

			if (url) {
				content = url + "?access_token=" + Credentials.get("accessToken");
			} else {
				content = "";
			}

			return new handlebars.SafeString(content);
		},

		'ancestorsSpecies': function(data) {

			var rankList = ["Kingdom", "Phylum", "Subphylum", "Class", "Order", "Family", "Genus", "Species", "Subspecies", "Variety"],
@@ -559,21 +344,6 @@ define([
			return new handlebars.SafeString(content);
		},

		'insertButton': function() {

			var content = '';

			for (var item in this.listButton) {
				content += "<i class='fa " + this.listButton[item].icon + " iconList'></i>";
			}

			return new handlebars.SafeString(content);
		},

		'Date': date,

		'DateTime': dateTime,

		'lang': function(data) {

			if (data) {
@@ -721,13 +491,6 @@ define([
			return new handlebars.SafeString(content);
		},

		'bold': function(text) {

			var boldClass = "bold";

			return new handlebars.SafeString('<span class="' + boldClass + '">' + text + '</span>');
		},

		'IterateJSON': function(obj) {

			// TODO creo que mejor la versión descomentada (respetando json pero con saltos de linea)
@@ -756,17 +519,6 @@ define([
			return new handlebars.SafeString(content);
		},

		'breaklines': breaklines,

		'textOrSpace': function(text) {

			if (text) {
				return new handlebars.SafeString(text);
			}

			return new handlebars.SafeString('<br>');
		},

		'PrintProperty': function(data, property, separate) {

			if (data[property]) {
@@ -788,22 +540,6 @@ define([
			return new handlebars.SafeString(result);
		},

		'concat': function() {

			var result = "";

			for (var i = 0; i < arguments.length - 1; i++) {
				result += arguments[i];
			}

			return new handlebars.SafeString(result);
		},

		'showBoolean': function(value) {

			return new handlebars.SafeString(value ? i18n.yes : i18n.no);
		},

		'reverse': function(/*Array*/ value) {

			return value && value.reverse ? value.reverse() : value;
Loading