Here are some new fixes on HTML export from Gehad. I did quite a few white
space fixes and some typo corrections as well when adding my SOB.

Gehad, you could hide the trip 'Other' when it is empty. And similarly the
weight under the equipment info (and probably some other "empty" data as
well).

miika
From 5c69c8b7c00e4545872c8862425464962472f72d Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Thu, 14 Aug 2014 06:32:47 +0300
Subject: [PATCH 7/7] HTML: Add coordinates to the HTML exports

- Export dive coordinates (if exist) to JSON file.
- Add dive coordinates to list view and detailed dive view.
- Add hyperlink that opens the dive location in a new tab viewed in
Google maps.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 save-html.c       | 18 +++++++++++++++++-
 theme/list_lib.js | 31 +++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/save-html.c b/save-html.c
index 1efc6b9..0288d44 100644
--- a/save-html.c
+++ b/save-html.c
@@ -122,6 +122,21 @@ void put_HTML_samples(struct membuffer *b, struct dive *dive)
 	put_string(b, "],");
 }
 
+void put_HTML_coordinates(struct membuffer *b, struct dive *dive)
+{
+	degrees_t latitude = dive->latitude;
+	degrees_t longitude = dive->longitude;
+
+	//don't put coordinates if in (0,0)
+	if (!latitude.udeg && !longitude.udeg)
+		return;
+
+	put_string(b, "\"coordinates\":{");
+	put_degrees(b, latitude, "\"lat\":\"", "\",");
+	put_degrees(b, longitude, "\"lon\":\"", "\",");
+	put_string(b, "},");
+}
+
 void put_HTML_date(struct membuffer *b, struct dive *dive, const char *pre, const char *post)
 {
 	struct tm tm;
@@ -207,6 +222,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, const char *photos_d
 	put_HTML_date(b, dive, "\"date\":\"", "\",");
 	put_HTML_time(b, dive, "\"time\":\"", "\",");
 	write_attribute(b, "location", dive->location);
+	put_HTML_coordinates(b, dive);
 	put_format(b, "\"rating\":%d,", dive->rating);
 	put_format(b, "\"visibility\":%d,", dive->visibility);
 	put_format(b, "\"dive_duration\":\"%u:%02u min\",",
@@ -390,7 +406,7 @@ void export_translation(const char *file_name)
 	write_attribute(b, "Events", translate("gettextFromC", "Events"));
 	write_attribute(b, "Name", translate("gettextFromC", "Name"));
 	write_attribute(b, "Value", translate("gettextFromC", "Value"));
-
+	write_attribute(b, "Coordinates", translate("gettextFromC", "Coordinates"));
 	write_attribute(b, "Dive_Status", translate("gettextFromC", "Dive Status"));
 
 	put_format(b, "}");
diff --git a/theme/list_lib.js b/theme/list_lib.js
index abd7901..c5171ce 100644
--- a/theme/list_lib.js
+++ b/theme/list_lib.js
@@ -208,7 +208,7 @@ function getExpanded(dive)
 {
 	var res = '<table><tr><td class="words">' + translate.Date + ': </td><td>' + dive.date +
 		  '</td><td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Time + ': </td><td>' + dive.time +
-		  '</td><td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Location + ': </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\', {location:true, divemaster:false, buddy:false, notes:false, tags:false,})\">' + dive.location + '</a>' +
+		  '</td><td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Locaiton + ': </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\', {location:true, divemaster:false, buddy:false, notes:false, tags:false,})\">' + dive.location + '</a>' + getDiveCoor(dive) +
 		  '</td></tr></table><table><tr><td class="words">' + translate.Rating + ':</td><td>' + putRating(dive.rating) +
 		  '</td><td class="words">&nbsp;&nbsp;&nbsp;' + translate.Visibility + ':</td><td>' + putRating(dive.visibility) +
 		  '</td></tr></table>' +
@@ -499,7 +499,7 @@ Set.prototype.intersect = function(another_set)
 	}
 	var result = new Array();
 	for (var i = 0; i < another_set.keys.length; i++) {
-		if(this.contains(another_set.keys[i])) {
+		if (this.contains(another_set.keys[i])) {
 			result.push(another_set.keys[i]);
 		}
 	};
@@ -896,6 +896,21 @@ function get_bookmarks_HTML(dive)
 	return result;
 }
 
+function getDiveCoorString(coordinates){
+	res = "";
+	lat = coordinates.lat;
+	lon = coordinates.lon;
+	res += float_to_deg(lat) + ' , ' + float_to_deg(lon);
+	return res;
+}
+
+function getDiveCoor(dive)
+{
+	if (!dive.coordinates)
+		return "";
+	return '<td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Coordinates + ': </td><td>' + '<a href="http://www.google.com/maps/@' + dive.coordinates.lat + ',' + dive.coordinates.lon + ',13z" target="_blank">' + getDiveCoorString(dive.coordinates) + '</a></td>';
+}
+
 /**
 *Return HTML main data of a dive
 */
@@ -903,8 +918,8 @@ function get_dive_HTML(dive)
 {
 	var res = '<h2 class="det_hed">' + translate.Dive_information + '</h2><table><tr><td class="words">' + translate.Date + ': </td><td>' + dive.date +
 		  '</td><td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Time + ': </td><td>' + dive.time +
-		  '</td><td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Location + ': </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\', {location:true, divemaster:false, buddy:false, notes:false, tags:false,})\">' + dive.location + '</a>' +
-		  '</td></tr></table><table><tr><td class="words">' + translate.Rating + ':</td><td>' + putRating(dive.rating) +
+		  '</td><td class="words">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + translate.Locaiton + ': </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\', {location:true, divemaster:false, buddy:false, notes:false, tags:false,})\">' + dive.location + '</a></td>' + getDiveCoor(dive) +
+		  '</tr></table><table><tr><td class="words">' + translate.Rating + ':</td><td>' + putRating(dive.rating) +
 		  '</td><td class="words">&nbsp;&nbsp;&nbsp;' + translate.Visibility + ':</td><td>' + putRating(dive.visibility) +
 		  '</td></tr></table>' +
 		  '<table><tr><td class="words">' + translate.Air_Temp + ': </td><td>' + dive.temperature.air +
@@ -1000,6 +1015,14 @@ function int_to_time(n)
 	return Math.floor((n) / 60) + ":" + format_two_digit((n) % (60)) + " min";
 }
 
+function float_to_deg(flt){
+	var deg = 0 | flt;
+	flt = (flt < 0 ? flt =- flt : flt);
+        var min = 0 | flt % 1 * 60;
+        var sec = (0 | flt * 60 % 1 * 6000) / 100;
+        return deg + "&deg; " + min + "' " + sec + "\"";
+}
+
 /**
 *Main canvas draw function
 *this calls the axis and grid initialization functions.
-- 
1.9.1

From f78c6efcd265ec709abbdd4d6960b0a088ff13a0 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Thu, 14 Aug 2014 05:38:40 +0300
Subject: [PATCH 6/7] HTML: Sort by number based on the chosen number format.

Sorting by the number must be based on either subsurface number or the
regular indexing as choosed in settings.json

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 theme/list_lib.js | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/theme/list_lib.js b/theme/list_lib.js
index ecdf5df..abd7901 100644
--- a/theme/list_lib.js
+++ b/theme/list_lib.js
@@ -374,9 +374,14 @@ function cmpNumAsc(j, iSmaller)
 	return items[j].subsurface_number < items[iSmaller].subsurface_number;
 }
 
+function cmpNumAsc(j, iSmaller)
+{
+	return settings.subsurfaceNumbers === '0' ? items[j].number < items[iSmaller].number : items[j].subsurface_number < items[iSmaller].subsurface_number;
+}
+
 function cmpNumDes(j, iSmaller)
 {
-	return items[j].subsurface_number > items[iSmaller].subsurface_number;
+	return settings.subsurfaceNumbers === '0' ? items[j].number > items[iSmaller].number : items[j].subsurface_number > items[iSmaller].subsurface_number;
 }
 
 function cmpTimeAsc(j, iSmaller)
-- 
1.9.1

From 128cfd55b1520baa6b66ec1598ac1a58db701260 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Thu, 14 Aug 2014 05:30:36 +0300
Subject: [PATCH 5/7] HTML: export selected dives in trips.

When exporting selected dives, traverse the trips and export the trip if
it contains at least one selected dive then search for all selected
dives in this trip.

Exporting selected dives only must contain trip infromation.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 save-html.c | 63 +++++++++++++++++++++++++++++--------------------------------
 1 file changed, 30 insertions(+), 33 deletions(-)

diff --git a/save-html.c b/save-html.c
index 695221e..1efc6b9 100644
--- a/save-html.c
+++ b/save-html.c
@@ -232,7 +232,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, const char *photos_d
 	(*dive_no)++;
 }
 
-void write_no_trip(struct membuffer *b, int *dive_no, const char *photos_dir, const bool list_only)
+void write_no_trip(struct membuffer *b, int *dive_no, bool selected_only, const char *photos_dir, const bool list_only)
 {
 	int i;
 	struct dive *dive;
@@ -242,25 +242,36 @@ void write_no_trip(struct membuffer *b, int *dive_no, const char *photos_dir, co
 	put_format(b, "\"dives\":[");
 
 	for_each_dive (i, dive) {
-		if (!dive->divetrip)
+		// write dive if it doesn't belong to any trip and the dive is selected
+		// or we are in exporting all dives mode.
+		if (!dive->divetrip && (dive->selected || !selected_only))
 			write_one_dive(b, dive, photos_dir, dive_no, list_only);
 	}
 	put_format(b, "]},\n\n");
 }
 
-void write_trip(struct membuffer *b, dive_trip_t *trip, int *dive_no, const char *photos_dir, const bool list_only)
+void write_trip(struct membuffer *b, dive_trip_t *trip, int *dive_no, bool selected_only, const char *photos_dir, const bool list_only)
 {
 	struct dive *dive;
-
-	put_format(b, "{");
-	put_format(b, "\"name\":\"%s\",", trip->location);
-	put_format(b, "\"dives\":[");
+	bool found_sel_dive = 0;
 
 	for (dive = trip->dives; dive != NULL; dive = dive->next) {
+		if (!dive->selected && selected_only)
+			continue;
+
+		// save trip if found at least one selected dive.
+		if (!found_sel_dive) {
+			found_sel_dive = 1;
+			put_format(b, "{");
+			put_format(b, "\"name\":\"%s\",", trip->location);
+			put_format(b, "\"dives\":[");
+		}
 		write_one_dive(b, dive, photos_dir, dive_no, list_only);
 	}
 
-	put_format(b, "]},\n\n");
+	// close the trip object if contain dives.
+	if (found_sel_dive)
+		put_format(b, "]},\n\n");
 }
 
 void write_trips(struct membuffer *b, const char *photos_dir, bool selected_only, const bool list_only)
@@ -272,34 +283,20 @@ void write_trips(struct membuffer *b, const char *photos_dir, bool selected_only
 	for (trip = dive_trip_list; trip != NULL; trip = trip->next)
 		trip->index = 0;
 
-	if (selected_only) {
-		put_format(b, "{");
-		put_format(b, "\"name\":\"Other\",");
-		put_format(b, "\"dives\":[");
-
-		for_each_dive (i, dive) {
-			if (!dive->selected)
-				continue;
-			write_one_dive(b, dive, photos_dir, &dive_no, list_only);
-		}
-		put_format(b, "]},\n\n");
-	} else {
-
-		for_each_dive (i, dive) {
-			trip = dive->divetrip;
-
-			/*Continue if the dive have no trips or we have seen this trip before*/
-			if (!trip || trip->index)
-				continue;
+	for_each_dive (i, dive) {
+		trip = dive->divetrip;
 
-			/* We haven't seen this trip before - save it and all dives */
-			trip->index = 1;
-			write_trip(b, trip, &dive_no, photos_dir, list_only);
-		}
+		/*Continue if the dive have no trips or we have seen this trip before*/
+		if (!trip || trip->index)
+			continue;
 
-		/*Save all remaining trips into Others*/
-		write_no_trip(b, &dive_no, photos_dir, list_only);
+		/* We haven't seen this trip before - save it and all dives */
+		trip->index = 1;
+		write_trip(b, trip, &dive_no, selected_only, photos_dir, list_only);
 	}
+
+	/*Save all remaining trips into Others*/
+	write_no_trip(b, &dive_no, selected_only, photos_dir, list_only);
 }
 
 void export_list(struct membuffer *b, const char *photos_dir, bool selected_only, const bool list_only)
-- 
1.9.1

From 2f336ef4f13b9be8416182b94987a63d855ac2a7 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Wed, 13 Aug 2014 06:38:33 +0300
Subject: [PATCH 4/7] HTML: arrow navigation is based on full dive list.

The navigation arrows from the detailed dive view is based on the full
dive list, regardless of 'items_to_show' list.

This can introduce unexpected behaviour if some search results or
explicitly sorted list are shown in the list view. Restoring this
list view from the detailed dive view after some arrow navigation.

Arrow navigation must be separte and don't change the 'start_id'
variable.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 theme/list_lib.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/theme/list_lib.js b/theme/list_lib.js
index ed9bc2c..ecdf5df 100644
--- a/theme/list_lib.js
+++ b/theme/list_lib.js
@@ -1182,7 +1182,6 @@ function setDiveTitle(dive)
 */
 function unshowDiveDetails(dive)
 {
-	start = dive_id;
 	viewInPage();
 	plot1 = null;
 	document.getElementById("diveListPanel").style.display = 'block';
-- 
1.9.1

From 5c1d3d8956436dbbdec07dde7157d97b8df13e21 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Tue, 12 Aug 2014 13:30:18 +0300
Subject: [PATCH 3/7] HTML: Scroll page to the top before showing the detailed
 view.

When looking at the dive list view, clicking on the 'show more details'
retains the view at the current vertical position, meaning that the
graph is somewhere above, outside the page view.

Page must be scrolled to the top before viewing the detailed dive view.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 theme/list_lib.js | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/theme/list_lib.js b/theme/list_lib.js
index 8c365d5..ed9bc2c 100644
--- a/theme/list_lib.js
+++ b/theme/list_lib.js
@@ -1166,6 +1166,7 @@ function showDiveDetails(dive)
 	document.getElementById("diveListPanel").style.display = 'none';
 	document.getElementById("divePanel").style.display = 'block';
 	canvas_draw();
+	scrollToTheTop();
 }
 
 function setDiveTitle(dive)
@@ -1218,6 +1219,11 @@ function switchDives(e)
 	}
 }
 
+function scrollToTheTop()
+{
+	window.scrollTo(0, 0);
+}
+
 window.onresize = function(event)
 {
 	if (plot1)
-- 
1.9.1

From 44da5f65e5b7a46ac0184af61436c0175ece7f14 Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Mon, 11 Aug 2014 17:25:13 +0300
Subject: [PATCH 2/7] HTML: don't update axis on window resize

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 theme/list_lib.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/theme/list_lib.js b/theme/list_lib.js
index 085d049..8c365d5 100644
--- a/theme/list_lib.js
+++ b/theme/list_lib.js
@@ -1222,7 +1222,7 @@ window.onresize = function(event)
 {
 	if (plot1)
 		plot1.replot({
-			resetAxes : true
+			resetAxes : false
 		});
 };
 
-- 
1.9.1

From d0521853fd43449aa551e3eecac0883554c1f14b Mon Sep 17 00:00:00 2001
From: Gehad elrobey <gehadelro...@gmail.com>
Date: Mon, 11 Aug 2014 17:20:34 +0300
Subject: [PATCH 1/7] HTML: Fix sorting water and air temperature values

Parse values by float instead of integer.

Signed-off-by: Gehad elrobey <gehadelro...@gmail.com>
Signed-off-by: Miika Turkia <miika.tur...@gmail.com>
---
 theme/list_lib.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/theme/list_lib.js b/theme/list_lib.js
index 348765b..085d049 100644
--- a/theme/list_lib.js
+++ b/theme/list_lib.js
@@ -401,22 +401,22 @@ function cmpDateDes(j, iSmaller)
 
 function cmpAtempAsc(j, iSmaller)
 {
-	return parseInt(items[j].temperature.air, 10) < parseInt(items[iSmaller].temperature.air, 10);
+	return parseFloat(items[j].temperature.air, 10) < parseFloat(items[iSmaller].temperature.air, 10);
 }
 
 function cmpAtempDes(j, iSmaller)
 {
-	return parseInt(items[j].temperature.air, 10) > parseInt(items[iSmaller].temperature.air, 10);
+	return parseFloat(items[j].temperature.air, 10) > parseFloat(items[iSmaller].temperature.air, 10);
 }
 
 function cmpWtempAsc(j, iSmaller)
 {
-	return parseInt(items[j].temperature.water, 10) < parseInt(items[iSmaller].temperature.water, 10);
+	return parseFloat(items[j].temperature.water, 10) < parseFloat(items[iSmaller].temperature.water, 10);
 }
 
 function cmpWtempDes(j, iSmaller)
 {
-	return parseInt(items[j].temperature.water, 10) > parseInt(items[iSmaller].temperature.water, 10);
+	return parseFloat(items[j].temperature.water, 10) > parseFloat(items[iSmaller].temperature.water, 10);
 }
 
 function sort_it(sortOn, function_)
-- 
1.9.1

_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to