Skip to content

Commit 6153477

Browse files
committed
Add new MapPoint code for geolocation, Thingy searching and indexing and a macro for rendering thing data outside of the Thingy.
1 parent 944c760 commit 6153477

File tree

24 files changed

+1443
-177
lines changed

24 files changed

+1443
-177
lines changed

docs/changelog/7.x.x.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- fixed #12106: CalendarUpdateFeeds activity does not handle time zones correctly
66
- fixed #11213: Gooey on the Go format problem
77
- mark makeUrlCompliant as deprecated.
8+
- fixed #12059: WebGUI::Asset::Wobject::Map - Set Default Viewing Area button does not work.
9+
- added: Setting MapPoint locations via address.
10+
- added: Make Thing data searchable
11+
- added: AssetProxy like macro for Thing data, ViewThingData
812

913
7.10.14
1014
- fixed #12094: Cannot enter in Macros in URLs inside TinyMCE.

docs/gotcha.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ upgrading from one version to the next, or even between multiple
77
versions. Be sure to heed the warnings contained herein as they will
88
save you many hours of grief.
99

10+
7.10.15
11+
--------------------------------------------------------------------
12+
* WebGUI now depends on Geo::Coder::Googlev3 for it's Map asset
13+
1014
7.10.13
1115
--------------------------------------------------------------------
1216
* WebGUI now depends on XML::FeedPP::MediaRSS.
2.69 KB
Binary file not shown.

docs/upgrades/upgrade_7.10.14-7.10.15.pl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ BEGIN
2222
use WebGUI::Session;
2323
use WebGUI::Storage;
2424
use WebGUI::Asset;
25-
25+
use WebGUI::AssetAspect::Installable;
26+
use WebGUI::Asset::MapPoint;
27+
use WebGUI::Asset::Wobject::Thingy;
2628

2729
my $toVersion = '7.10.15';
2830
my $quiet; # this line required
@@ -31,6 +33,10 @@ BEGIN
3133
my $session = start(); # this line required
3234

3335
# upgrade functions go here
36+
alterAssetIndexTable($session);
37+
reindexAllThingys($session);
38+
WebGUI::AssetAspect::Installable::upgrade("WebGUI::Asset::MapPoint",$session);
39+
addRenderThingDataMacro($session);
3440

3541
finish($session); # this line required
3642

@@ -44,6 +50,37 @@ BEGIN
4450
# print "DONE!\n" unless $quiet;
4551
#}
4652

53+
sub addRenderThingDataMacro {
54+
my $session = shift;
55+
print "\tAdd the new RenderThingData macro to the site config... " unless $quiet;
56+
$session->config->addToHash('macros', 'RenderThingData', 'RenderThingData');
57+
print "DONE!\n" unless $quiet;
58+
}
59+
60+
sub alterAssetIndexTable {
61+
my $session = shift;
62+
print "\tExtend the assetIndex table so we can search things other than assets... " unless $quiet;
63+
$session->db->write(<<EOSQL);
64+
alter table assetIndex
65+
drop primary key,
66+
add column subId char(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
67+
add primary key (assetId, url)
68+
EOSQL
69+
print "DONE!\n" unless $quiet;
70+
}
71+
72+
sub reindexAllThingys {
73+
my $session = shift;
74+
print "\tReindex all Thingys... " unless $quiet;
75+
my $get_thingy = WebGUI::Asset::Wobject::Thingy->getIsa($session);
76+
THINGY: while (1) {
77+
my $thingy = eval { $get_thingy->() };
78+
next THINGY if Exception::Class->caught();
79+
last THINGY unless $thingy;
80+
$thingy->indexContent;
81+
}
82+
print "DONE!\n" unless $quiet;
83+
}
4784

4885
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
4986

etc/WebGUI.conf.original

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@
848848
"PickLanguage" : "PickLanguage",
849849
"RandomAssetProxy" : "RandomAssetProxy",
850850
"RandomThread" : "RandomThread",
851+
"RenderThingData" : "RenderThingData",
851852
"RootTitle" : "RootTitle",
852853
"r" : "r_printable",
853854
"Spacer" : "Spacer",

lib/WebGUI/Asset/MapPoint.pm

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use strict;
1818
use Tie::IxHash;
1919
use base 'WebGUI::Asset';
2020
use WebGUI::Utility;
21+
use Geo::Coder::Googlev3;
22+
use Data::Dumper;
23+
2124

2225
# To get an installer for your wobject, add the Installable AssetAspect
2326
# See WebGUI::AssetAspect::Installable and sbin/installClass.pl for more
@@ -143,6 +146,12 @@ sub definition {
143146
hoverHelp => $i18n->get("storageIdPhoto description"),
144147
noFormPost => 1,
145148
},
149+
isGeocoded => {
150+
fieldType => "yesNo",
151+
tab => "properties",
152+
label => $i18n->get("isGeocoded label"),
153+
hoverHelp => $i18n->get("isGeocoded description"),
154+
},
146155
userDefined1 => {
147156
fieldType => "hidden",
148157
},
@@ -159,6 +168,7 @@ sub definition {
159168
fieldType => "hidden",
160169
},
161170
);
171+
162172
push @{$definition}, {
163173
assetName => $i18n->get('assetName'),
164174
icon => 'mappoint.png',
@@ -212,6 +222,7 @@ AT LEAST the following keys:
212222
title - The title of the point
213223
content - HTML content to show details about the point
214224
url - The URL of the point
225+
userDefined1-5 - The userDefined fields
215226
216227
The following keys are optional
217228
@@ -227,7 +238,7 @@ sub getMapInfo {
227238
# Get asset properties
228239
$var->{ url } = $self->getUrl;
229240
$var->{ assetId } = $self->getId;
230-
my @keys = qw( latitude longitude title );
241+
my @keys = qw( latitude longitude title userDefined1 userDefined2 userDefined3 userDefined4 userDefined5 isGeocoded );
231242
for my $key ( @keys ) {
232243
$var->{ $key } = $self->get( $key );
233244
}
@@ -274,6 +285,15 @@ sub getTemplateVarsEditForm {
274285
my $session = $self->session;
275286
my $var = $self->getTemplateVars;
276287

288+
my $parent = $self->getParent;
289+
#If it's a new point, we have to get the parent from the url
290+
unless ($parent) {
291+
my $url = $session->url->page;
292+
$parent = WebGUI::Asset->newByUrl($session,$url);
293+
}
294+
295+
$var->{'can_edit_map'} = $parent->canEdit;
296+
277297
$var->{ form_header }
278298
= WebGUI::Form::formHeader( $session )
279299
. WebGUI::Form::hidden( $session, {
@@ -323,8 +343,25 @@ sub getTemplateVarsEditForm {
323343
name => "synopsis",
324344
value => $self->get("synopsis"),
325345
resizable => 0,
326-
} );
346+
} );
327347

348+
#Only allow people who can edit the parent to change isHidden
349+
if($var->{'can_edit_map'}) {
350+
my $isHidden = (defined $self->get("isHidden")) ? $self->get("isHidden") : 1;
351+
$var->{ "form_isHidden" }
352+
= WebGUI::Form::yesNo( $session, {
353+
name => "isHidden",
354+
value => $isHidden,
355+
} );
356+
}
357+
358+
my $isGeocoded = ( $self->getId ) ? $self->get("isGeocoded") : 1;
359+
$var->{"form_isGeocoded"}
360+
= WebGUI::Form::checkbox( $session, {
361+
name => "isGeocoded",
362+
value => 1,
363+
checked => $isGeocoded
364+
} );
328365
# Fix storageIdPhoto because scripts do not get executed in ajax requests
329366
$var->{ "form_storageIdPhoto" }
330367
= '<input type="file" name="storageIdPhoto" />';
@@ -339,6 +376,35 @@ sub getTemplateVarsEditForm {
339376

340377
#-------------------------------------------------------------------
341378

379+
=head2 indexContent ( )
380+
381+
Indexing the content of attachments and user defined fields. See WebGUI::Asset::indexContent() for additonal details.
382+
383+
=cut
384+
385+
sub indexContent {
386+
my $self = shift;
387+
my $indexer = $self->SUPER::indexContent;
388+
$indexer->addKeywords($self->get("website"));
389+
$indexer->addKeywords($self->get("address1"));
390+
$indexer->addKeywords($self->get("address2"));
391+
$indexer->addKeywords($self->get("city"));
392+
$indexer->addKeywords($self->get("region"));
393+
$indexer->addKeywords($self->get("zipCode"));
394+
$indexer->addKeywords($self->get("country"));
395+
$indexer->addKeywords($self->get("phone"));
396+
$indexer->addKeywords($self->get("fax"));
397+
$indexer->addKeywords($self->get("email"));
398+
$indexer->addKeywords($self->get("userDefined1"));
399+
$indexer->addKeywords($self->get("userDefined2"));
400+
$indexer->addKeywords($self->get("userDefined3"));
401+
$indexer->addKeywords($self->get("userDefined4"));
402+
$indexer->addKeywords($self->get("userDefined5"));
403+
return $indexer;
404+
}
405+
406+
#-------------------------------------------------------------------
407+
342408
=head2 processAjaxEditForm ( )
343409
344410
Process the Ajax Edit Form from the Map. If any errors occur, return
@@ -367,6 +433,29 @@ sub processAjaxEditForm {
367433
$prop->{ synopsis } = $form->get('synopsis');
368434
$prop->{ url } = $session->url->urlize( $self->getParent->getUrl . '/' . $prop->{title} );
369435
$prop->{ ownerUserId } = $form->get('ownerUserId') || $session->user->userId;
436+
#Only users who can edit the map can set this property
437+
if($self->getParent->canEdit) {
438+
$prop->{ isHidden } = $form->get('isHidden');
439+
}
440+
$prop->{isGeocoded } = $form->get('isGeocoded') || 0;
441+
if($prop->{isGeocoded} &&
442+
(
443+
( $form->get("address1") ne $self->get("address1") )
444+
|| ( $form->get("address2") ne $self->get("address2") )
445+
|| ( $form->get("city") ne $self->get("city") )
446+
|| ( $form->get("region") ne $self->get("region") )
447+
|| ( $form->get("zipCode") ne $self->get("zipCode") )
448+
|| ( $form->get("country") ne $self->get("country") )
449+
)
450+
) {
451+
my $geocoder = Geo::Coder::Googlev3->new;
452+
my $address_str = $form->get("address1");
453+
$address_str .= " ".$form->get("address2") if($form->get("address2"));
454+
$address_str .= ", ".$form->get("city").", ".$form->get("region").", ".$form->get("zipCode").", ".$form->get("country");
455+
my $location = $geocoder->geocode( location => $address_str );
456+
$prop->{latitude } = $location->{geometry}->{location}->{lat};
457+
$prop->{longitude} = $location->{geometry}->{location}->{lng};
458+
}
370459

371460
$self->update( $prop );
372461

@@ -420,6 +509,7 @@ sub www_view {
420509
return "redirect";
421510
}
422511

512+
423513
1;
424514

425515
#vim:ft=perl

lib/WebGUI/Asset/Wobject/Map.pm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use WebGUI::International;
1818
use WebGUI::Utility;
1919
use HTML::Entities qw(encode_entities);
2020
use base 'WebGUI::Asset::Wobject';
21+
use Data::Dumper;
2122

2223
# To get an installer for your wobject, add the Installable AssetAspect
2324
# See WebGUI::AssetAspect::Installable and sbin/installClass.pl for more
@@ -387,14 +388,20 @@ sub view {
387388
google.setOnLoadCallback( function() {
388389
var mapId = "%s";
389390
var mapUrl = "%s";
390-
var map = new GMap2( document.getElementById("map_" + mapId) );
391+
var element = document.getElementById("map_" + mapId);
392+
var map = new GMap2( element );
393+
element.mapObject = map;
391394
map.url = mapUrl;
392395
map.assetId = mapId;
393396
map.setCenter(new GLatLng(%s, %s), %s);
394397
map.setUIToDefault();
395398
map.extrasUrl = "%s";
396399
397400
var markermanager = new MarkerManager(map, {trackMarkers: true});
401+
map.markermanager = markermanager;
402+
map.fancyClickHandler = null;
403+
map.panOnClick = true;
404+
map.clickToEdit = false;
398405
ENDHTML
399406

400407

@@ -408,9 +415,9 @@ ENDHTML
408415
for my $pointId ( @{$pointIds} ) {
409416
my $point = WebGUI::Asset->newByDynamicClass( $session, $pointId );
410417
next unless $point;
411-
$mapHtml .= sprintf ' points.push(%s);'."\n",
412-
JSON->new->encode($point->getMapInfo),
413-
;
418+
my $buffer = JSON->new->encode( $point->getMapInfo );
419+
420+
$mapHtml .= sprintf ' points.push(%s);'."\n", $buffer;
414421

415422
push @{$var->{ mapPoints }}, $point->getTemplateVars;
416423
}
@@ -432,11 +439,11 @@ ENDHTML
432439
}
433440

434441
# Script to control addPoint and setPoint buttons
435-
$mapHtml .= <<'ENDHTML';
442+
$mapHtml .= sprintf <<'ENDHTML', $self->getUrl;
436443
if ( document.getElementById( "setCenter_" + mapId ) ) {
437444
var button = document.getElementById( "setCenter_" + mapId );
438445
GEvent.addDomListener( button, "click", function () {
439-
WebGUI.Map.setCenter( map );
446+
WebGUI.Map.setCenter( map, '%s' );
440447
} );
441448
}
442449
if ( document.getElementById( "addPoint_" + mapId ) ) {

lib/WebGUI/Asset/Wobject/Search.pm

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,30 +213,31 @@ sub view {
213213
);
214214

215215
my @results = ();
216-
foreach my $data (@{$p->getPageData}) {
217-
next unless (
216+
ENTRY: foreach my $data (@{$p->getPageData}) {
217+
next ENTRY unless (
218218
$user->userId eq $data->{ownerUserId}
219219
|| $user->isInGroup($data->{groupIdView})
220220
|| $user->isInGroup($data->{groupIdEdit})
221221
);
222222

223223
my $asset = WebGUI::Asset->new($session, $data->{assetId}, $data->{className});
224-
if (defined $asset) {
225-
my $properties = $asset->get;
226-
if ( $self->get("useContainers") && $asset->getContainer->canView ) {
227-
$properties->{url} = $asset->isa('WebGUI::Asset::Post::Thread') ? $asset->getCSLinkUrl()
228-
: $asset->getContainer->get("url");
229-
}
230-
#Add highlighting
231-
$properties->{'title' } = $hl->highlight($properties->{title} || '');
232-
$properties->{'title_nohighlight' } = $properties->{title};
233-
my $synopsis = $data->{'synopsis'} || '';
234-
WebGUI::Macro::process($self->session, \$synopsis);
235-
$properties->{'synopsis' } = $hl->highlight($synopsis);
236-
$properties->{'synopsis_nohighlight'} = $synopsis;
237-
push(@results, $properties);
238-
$var{results_found} = 1;
239-
}
224+
next ENTRY unless defined $asset;
225+
my $properties = $asset->get;
226+
##Overlay the asset properties with the original data to handle sub-entries for assets
227+
$properties = { %{ $properties }, %{ $data} };
228+
if ( $self->get("useContainers") && $asset->getContainer->canView ) {
229+
$properties->{url} = $asset->isa('WebGUI::Asset::Post::Thread') ? $asset->getCSLinkUrl()
230+
: $asset->getContainer->get("url");
231+
}
232+
#Add highlighting
233+
$properties->{'title' } = $hl->highlight($properties->{title} || '');
234+
$properties->{'title_nohighlight' } = $properties->{title};
235+
my $synopsis = $properties->{'synopsis'} || '';
236+
WebGUI::Macro::process($self->session, \$synopsis);
237+
$properties->{'synopsis' } = $hl->highlight($synopsis);
238+
$properties->{'synopsis_nohighlight'} = $synopsis;
239+
push(@results, $properties);
240+
$var{results_found} = 1;
240241
}
241242

242243
$var{result_set} = \@results;

0 commit comments

Comments
 (0)