Locations Plugin

Repo: GitHub - paviliondev/discourse-locations

This plugin allows you to associate locations with topics, and list topics with locations on a map.

Additionally it allows users to record their position (voluntarily) and this can show up on a map of Users in the Users directory.

You can see an example of it here.

Maps are handled by Leaflet.js and multiple geocoding providers are supported. Both are customizable via admin settings as explained below in ‘Admin Settings’.

Features:

  • A map of Users (whose locations have been set) can be turned on.

  • Locations can be turned on for specific categories by toggling ‘Allow locations to be added to topics in this category’ in the Category settings.

  • When locations are turned on a for a category:

    • The composer will include an ‘Add Location’ button when composing a new topic in that category.

      11 PM

      This opens a modal which allows the user to enter the location details, including a geocoded address:

    • ‘Map’ will be added to the category nav items. This will display a map in place of the topic list with topics that have geocoded locations associated with them marked on it. This list can be set as the default for the category in the category settings. When multiple topics are associated with the same location, they are grouped into expandable clusters (using the Marker Cluster plugin for Leaflet). Clicking on the markers navigates the user to the associated topic.

  • When a location is added to a topic:

    • The location details will appear underneath the topic title. If the location is geocoded a ‘Show Map’ button appears to the right of the location details. This button toggles a mini-map showing the location.

    • Locations can be edited in the ‘topic title’ edit controls.

  • The map controls available to users are:

    • Expand 01 PM. This will expand the map to take over the whole window aside from the Header bar.

    • Zoom 13 PM. These are standard leaflet zoom controls.

    • Attribution 12 PM. This toggles the visibility of the attribution.

Admin Settings:

  • location input fields enabled: toggles whether ‘Add Location’ modal displays specific location input fields or a single location query input

    51 PM
    OR
    10 PM

  • location input fields: sets what input fields are used if location input fields enabled is true

  • location geocoding:

    • none: User is required to enter either a name or an address when adding a location. Addresses are stored as a string.

    • optional: User is required to enter either a name or an address when adding a location. Addresses are geocoded and will display on any associated maps.

    • required: User is required to enter an address when adding a location. Addresses are geocoded and will display on any associated maps.

  • location geocoding provider: the service that translates user input into coordinates that can be displayed on a map. Geocoding is handled by the Geocoder gem, which supports a number of geocoding providers. Think of these providers like you would a transactional email provider. The list of providers available in this plugin is a sub-set of the list in the gem. The providers currently supported by this plugin are:

    Nominatim is the default, as it doesn’t require an api key, has no (relevant) restrictions in terms of use and is good for testing and light use. Each provider has strengths and weaknesses. I suggest you review each of them (e.g. check the Terms; test relevant addresses) if you’re serious about using this plugin.

    This sub-set of providers available through the Geocoder gem were chosen according to these criteria:

    • Ease of integration. The reason I didn’t include Google is because Google Maps is not designed to be used with Leaflet.js (or any other 3rd party software). I did get it working, however it requires multiple customizations specific to Google and the end result is not great, so I don’t want to support it considering there are a number of other more customizable providers that can do the job just as well. If for some reason you must use Google Maps with this plugin, it is possible, but you will need to handle and support the integration yourself.

    • Terms of Service. A number of the Geocoding providers only allow you to use their geocoding data in conjunction with their own maps. This is true of some of the providers this plugin does support. For example, you can’t use Mapbox data on non-Mapbox maps. For the providers that have this restriction I have only included those that make it relatively easy to use both their geocoding service and their mapping service with Leaflet.js, so the service can be used without breaching the provider’s terms.

    • Functionality. Some of the providers listed in the Geocoder gem docs no longer work.

  • location geocoding api key: When a geocoding provider requires an API key, enter it here before you switch to that service in the location geocoding provider setting. If you switch to a provider that requires a key before entering a key you will get an error.

  • location geocoding timeout: This sets the timeout for the Geocoder gem. It is unlikely you will need to change this.

  • location map tile layer: Aka the “basemap”. This is the actual map image on which locations are shown. There is a large variety of basemaps that can be used. Keep in mind that some Geocoding providers require you to use their basemaps when using their geocoding service. There’s a nice basemap showcase here.

  • location map tile layer subdomains: Relevant for some basemap providers. It is unlikely you will need to use this.

  • location map attribution: This string will appear when the ‘i’ button in the bottom right corner of the map is clicked. Please always give attribution to the providers you are using.

How to safely install or update when using our plugins:

Pavilion’s update schedule and support policy

This plugin is one of the Pavilion family of open source plugins.

Pavilion focuses on ensuring compatibility of a core set of its plugins with Discourse Core tests-passed branch during the first 5 days of every month only.

Any bugs which arise because of an incompatibility will be addressed asap during this ‘supported period’, preferably by the 7th day. Low severity or Beta feature bugs may not be addressed by this date, but obvious things which are ‘breaking’ a forum should be resolved.

If you’ve not used the plugin before, it is safer to adopt it within the support window, so add it and rebuild your site within the first five days of any month, otherwise it’s possible you may be introducing an incompatibility and we might not be around to help.

More about this policy here: Pavilion's Support Policy and Schedule - Support - Pavilion

77 Likes

I am very new with this technology. I have installed the plugin (I see the Map command in the hamburger menu and I have a location field in my User profile page (with working georeference with nominatim) BUT…

I don’t see “Add location” button in the editor.

This is my configuration:

And this is the editor window:

Finally, this is the way I have installed the plugin:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-math.git
          - git clone https://github.com/paviliondev/discourse-events.git
          - git clone https://github.com/paviliondev/discourse-locations.git
          - git clone https://github.com/davidtaylorhq/discourse-whos-online.git
          - git clone https://github.com/discourse/twitter-profile-link.git
          - git clone https://github.com/discourse/discourse-tooltips.git

I have tried with locale= en with the same results.

1 Like

Well, well, correction: the plugin works as expected in the User Profile.

According to the map, I am a dead person since the map indicates a point in the middle of the largest Montreal graveyard:

4 Likes

It has to be enabled for each of the categories that you wish to use it also.

3 Likes

Thank you! It has worked.

By the way, the check mark was “on” by default BUT!! you have to show the setup panel, uncheck and recheck to have the feature actually works.

3 Likes

Glad you got it working. It’s been a while since I used the plugin so it was kinda my best guess.

1 Like

@angus I’ve noticed this issue recently when people don’t have a location entered on their profile:

Screen Shot 2020-04-21 at 21.18.40

Screen Shot 2020-04-21 at 21.18.05

It’s not occurring on every user though, can’t quite work out the pattern to it.

Maybe those who have deleted a location on their profile? Or maybe it’s and empty string eg “”, rather than NULL? :thinking:

It looks like the recent update removed the location from the user card altogether.

User card:

User profile:

2 Likes

This is very likely caused by this change in core:

4 Likes

@omarfilip @david Thanks for the insight :+1:t2:

@angus is this something you’ll be able to modify?

2 Likes

@david @Richie Thanks, this plugin has been updated to support the change.

https://github.com/paviliondev/discourse-locations/commit/5c762ccc1f34d190fafec49498e95a395c73c2bb

Just a heads up that this plugin will soon be moving to the same update schedule as the rest of Pavilion’s main plugins. This means that it will be brought in line with the latest Discourse core in the first week of every month. Details to follow specific to this plugin, but see further here:

4 Likes

Thanks for the quick fix, Angus.

2 Likes

Hi @angus confirmed the locations are now displaying on the user card but we’re still seeing the issue whereby some users have a map pin and map icon showing even if they don’t have a location entered:

image

And on their full profile page:

1 Like

I cannot start the Discourse app because of the locations plugin currently. Attaching log below, it works if I comment out locations in app.yml. Can someone prioritize this and fix it?

Also, is there a way to only upgrade to tests-passed version of the plugin (if there is such a thing), like how the main discourse app does? So that we do not run into such issues in future.

Log
5: from /var/www/discourse/plugins/discourse-layouts/plugin.rb:49:in `block in activate!'
4: from /var/www/discourse/lib/discourse_event.rb:13:in `trigger'
3: from /usr/local/lib/ruby/2.6.0/set.rb:338:in `each'
2: from /usr/local/lib/ruby/2.6.0/set.rb:338:in `each_key'
1: from /var/www/discourse/lib/discourse_event.rb:14:in `block in trigger'
/var/www/discourse/plugins/discourse-locations/plugin.rb:234:in `block in activate!': uninitialized constant DiscourseLayouts::WidgetHelper
Did you mean?  DiscourseLayouts::WidgetSerializer (NameError)

** INCOMPATIBLE PLUGIN **

You are unable to build Discourse due to errors in the plugin at
/var/www/discourse/plugins/discourse-locations

Please try removing this plugin and rebuilding again!
I, [2020-04-25T20:32:06.399307 #1]  INFO -- : gem install icalendar -v 2.4.1 -i /var/www/discourse/plugins/discourse-events/gems/2.6.5 --no-document --ignore-dependencies --no-user-install
HEADS UP! iCalendar 2.0 is not backwards-compatible with 1.x. Please see the README for the new syntax

HEADS UP! icalendar 2.2.0 switches to non-strict parsing as default. Please see the README if you
rely on strict parsing for information on how to enable it.

ActiveSupport is required for TimeWithZone support, but not required for general use.
Successfully installed icalendar-2.4.1
1 gem installed
gem install geocoder -v 1.4.4 -i /var/www/discourse/plugins/discourse-locations/gems/2.6.5 --no-document --ignore-dependencies --no-user-install
Successfully installed geocoder-1.4.4
1 gem installed

I, [2020-04-25T20:32:06.400580 #1]  INFO -- : Terminating async processes
I, [2020-04-25T20:32:06.400773 #1]  INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/10/bin/postmaster -D /etc/postgresql/10/main pid: 50
I, [2020-04-25T20:32:06.400979 #1]  INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 167
167:signal-handler (1587846726) Received SIGTERM scheduling shutdown...
2020-04-25 20:32:06.401 UTC [50] LOG:  received fast shutdown request
2020-04-25 20:32:06.403 UTC [50] LOG:  aborting any active transactions
2020-04-25 20:32:06.406 UTC [50] LOG:  worker process: logical replication launcher (PID 59) exited with exit code 1
167:M 25 Apr 2020 20:32:06.406 # User requested shutdown...
167:M 25 Apr 2020 20:32:06.406 * Saving the final RDB snapshot before exiting.
2020-04-25 20:32:06.409 UTC [54] LOG:  shutting down
2020-04-25 20:32:06.439 UTC [50] LOG:  database system is shut down
167:M 25 Apr 2020 20:32:06.502 * DB saved on disk
167:M 25 Apr 2020 20:32:06.502 # Redis is now ready to exit, bye bye...


FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 13098 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
b5a02d7f9df6b6a9dc160e269de30eef49bb0aeaf5dcb1b712bab5e6edad4030
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
root@discuss:/var/discourse#
1 Like

@k4rtik Thanks for your report, and sorry you’ve been impacted. Your issue arose because:

  1. The layouts plugin was updated 2 days ago.
  2. The locations plugin was supporting the existing version of the layouts plugin.
  3. You use both plugins.
  4. You updated your Discourse in between the initial update of the layouts plugin and support being added to the locations plugin.

I’ve updated the locations plugin to support the new layouts plugin version: https://github.com/paviliondev/discourse-locations/commit/52aec30461f8439c6658fdc401127cb52881ab49. When you update now with both plugins installed, it will work. @Richie This will fix your issue: https://github.com/paviliondev/discourse-locations/commit/51850630187c43df8e2c8186a2943e20eeaadda2

Having a tests-passed branch in the plugin would unforatunately not help too much in this particuar situation, or a not-insignificant portion of other plugin incompatibility situations. People update at many different frequencies and have many different combinations of customisations.

That said, we’re starting to make some steps to address this problem. We’re moving to a schedule of ensuring Pavilion’s primary open source plugins (this plugin, Events, Topic List Previews etc) are up to date with Discourse every 24 hours in the first 5 days of every month, starting May 1 to 5.

This gives you a safe window to update all the plugins on try.thepavilion.io along with Discourse itself with greater certainty that:

  1. You won’t experience conflicts between the plugin and Discourse, and if you do they will be addressed within less than 24 hrs.

  2. You won’t experience any issues due to changes in the plugin itself. Any potentially breaking changes to the plugin itself will happen outside this window.

This applies to all the plugins listed here:

This list may be expanded over time. See further: https://try.thepavilion.io.

If you have any questions about this, feel free to PM me, or contact us over at thepavilion.io.

5 Likes

Thanks, yeah, I was trying to figure out why my custom layout was not showing up either with the last update. It still doesn’t seem to appear but I see on Pavilion that you are in the process to release updated doc for the changes in the plugin so I will wait a while.

1 Like

@angus confirmed - issue resolved :clap:t2:

Thanks again for your continued support of this plugin :smiley:

3 Likes

Hi @angus I saw a notification to say the first post in this thread was edited.

Looks like the location of the repo has moved.

Should we all update our discourse settings to the new location or will the existing / old location still be updated?

Do we need to rebuild anything after changing the plugin source location?

2 Likes

Hey @Richie, you can continue using the old url of https://github.com/angusmcleod/discourse-locations. You can wait to update it when you naturally get a chance, i.e. you have to rebuild your site for some other reason.

The plugin was transferred from my personal github to Pavilion’s some time ago. When a repository is transferred, Github automatically redirects all links to the old location to the new one.

The first post will be changing a bit more in the coming weeks. I’m going to write some documentation for this over on thepavilion.io and a shorter description here on meta.

3 Likes

Excellent, I didn’t know that :+1:t2:

Thanks once again for the support!

2 Likes