Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{~location-format context.topic.location}}
293 changes: 146 additions & 147 deletions assets/javascripts/discourse/initializers/location-edits.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@ export default {
withPluginApi('0.8.23', api => {
api.decorateWidget('post-body:after-meta-data', (helper) => {
const model = helper.getModel();

if (siteSettings.location_user_post &&
currentUser &&
currentUser.custom_fields.geo_location &&
currentUser.id === model.user_id) {
model.user_custom_fields &&
model.user_custom_fields["geo_location"]) {
let format = siteSettings.location_user_post_format.split('|');
let opts = {};
if (format.length) {
opts['geoAttrs'] = format;
}
let locationText = geoLocationFormat(model.user_custom_fields["geo_location"], site.country_codes, opts);
return helper.h('div.user-location',
geoLocationFormat(currentUser.custom_fields.geo_location, site.country_codes, opts)
locationText
);
}
});

api.modifyClass("controller:users", {
pluginId: "locations-plugin",

loadUsers(params) {
if (params !== undefined && params.period === "location") {
return;
Expand All @@ -49,181 +48,181 @@ export default {
pluginId: "locations-plugin",

@discourseComputed('subtype', 'categoryId', 'topicFirstPost', 'forceLocationControls')
showLocationControls(subtype, categoryId, topicFirstPost, force) {
if (!topicFirstPost) return false;
if (force) return true;
if (categoryId) {
const category = this.site.categories.findBy('id', categoryId);
if (category && category.custom_fields.location_enabled) return true;
}
return false;
},

clearState() {
this._super(...arguments);
this.set('location', null);
},

@observes('draftKey')
_setupDefaultLocation() {
if (this.draftKey === 'new_topic') {
const topicDefaultLocation = siteSettings.location_topic_default;
if (topicDefaultLocation === 'user' && currentUser.custom_fields.geo_location) {
this.set('location', { geo_location: currentUser.custom_fields.geo_location });
}
showLocationControls(subtype, categoryId, topicFirstPost, force) {
if (!topicFirstPost) return false;
if (force) return true;
if (categoryId) {
const category = this.site.categories.findBy('id', categoryId);
if (category && category.custom_fields.location_enabled) return true;
}
return false;
},

clearState() {
this._super(...arguments);
this.set('location', null);
},

@observes('draftKey')
_setupDefaultLocation() {
if (this.draftKey === 'new_topic') {
const topicDefaultLocation = siteSettings.location_topic_default;
if (topicDefaultLocation === 'user' && currentUser.custom_fields.geo_location) {
this.set('location', { geo_location: currentUser.custom_fields.geo_location });
}
}
});
}
});

api.modifyClass("component:composer-body", {
pluginId: "locations-plugin",
api.modifyClass("component:composer-body", {
pluginId: "locations-plugin",

@observes('composer.location')
resizeWhenLocationAdded: function() {
this._triggerComposerResized();
},
resizeWhenLocationAdded: function() {
this._triggerComposerResized();
},

@observes('composer.showLocationControls', 'composer.composeState')
applyLocationInlineClass() {
scheduleOnce('afterRender', this, () => {
const showLocationControls = this.get('composer.showLocationControls');
const $container = $('.composer-fields .title-and-category');
@observes('composer.showLocationControls', 'composer.composeState')
applyLocationInlineClass() {
scheduleOnce('afterRender', this, () => {
const showLocationControls = this.get('composer.showLocationControls');
const $container = $('.composer-fields .title-and-category');

$container.toggleClass('show-location-controls', showLocationControls);
$container.toggleClass('show-location-controls', showLocationControls);

if (showLocationControls) {
const $anchor = this.site.mobileView ? $container.find('.title-input') : $container;
$('.composer-controls-location').appendTo($anchor);
}

this._triggerComposerResized();
});
if (showLocationControls) {
const $anchor = this.site.mobileView ? $container.find('.title-input') : $container;
$('.composer-controls-location').appendTo($anchor);
}

this._triggerComposerResized();
});
}
});

const subtypeShowLocation = ['event', 'question', 'general'];
api.modifyClass("model:topic", {
pluginId: "locations-plugin",
const subtypeShowLocation = ['event', 'question', 'general'];
api.modifyClass("model:topic", {
pluginId: "locations-plugin",

@discourseComputed('subtype', 'category.custom_fields.location_enabled')
showLocationControls(subtype, categoryEnabled) {
return subtypeShowLocation.indexOf(subtype) > -1 || categoryEnabled;
}
showLocationControls(subtype, categoryEnabled) {
return subtypeShowLocation.indexOf(subtype) > -1 || categoryEnabled;
}
});

// necessary because topic-title plugin outlet only recieves model
api.modifyClass("controller:topic", {
pluginId: "locations-plugin",
// necessary because topic-title plugin outlet only recieves model
api.modifyClass("controller:topic", {
pluginId: "locations-plugin",

@observes('editingTopic')
setEditingTopicOnModel() {
this.set('model.editingTopic', this.get('editingTopic'));
}
setEditingTopicOnModel() {
this.set('model.editingTopic', this.get('editingTopic'));
}
});

api.modifyClass("component:edit-category-settings", {
pluginId: "locations-plugin",
api.modifyClass("component:edit-category-settings", {
pluginId: "locations-plugin",

@discourseComputed('category')
availableViews(category) {
let views = this._super(...arguments);
availableViews(category) {
let views = this._super(...arguments);

if (category.get('custom_fields.location_enabled') && this.siteSettings.location_category_map_filter) {
views.push(
{name: I18n.t('filters.map.title'), value: 'map'}
);
}
if (category.get('custom_fields.location_enabled') && this.siteSettings.location_category_map_filter) {
views.push(
{ name: I18n.t('filters.map.title'), value: 'map' }
);
}

return views;
},
return views;
},
});

const mapRoutes = [
`Map`,
`MapCategory`,
`MapCategoryNone`
];

mapRoutes.forEach(function(route){
api.modifyClass(`route:discovery.${route}`, {
pluginId: "locations-plugin",

afterModel(model) {
if (!this.siteSettings.location_category_map_filter) {
this.replaceWith(`/c/${this.Category.slugFor(model.category)}`);
}
return this._super(...arguments);
},

renderTemplate(controller, model) {
let navTemplate = this.routeName.indexOf('Category') > -1 ? 'navigation/category' : 'navigation/default';
this.render(navTemplate, { outlet: 'navigation-bar' } );
this.render("discovery/map", { outlet: "list-container", controller: 'discovery/topics' });
}
});
});
const mapRoutes = [
`Map`,
`MapCategory`,
`MapCategoryNone`
];

const categoryRoutes = [
'category',
'categoryNone'
];

categoryRoutes.forEach(function(route){
api.modifyClass(`route:discovery.${route}`, {
pluginId: "locations-plugin",

afterModel(model, transition) {
if (this.filter(model.category) === 'map' && this.siteSettings.location_category_map_filter) {
transition.abort();
return this.replaceWith(`/c/${this.Category.slugFor(model.category)}/l/${this.filter(model.category)}`);
} else {
return this._super(...arguments);
}
}
});
});
mapRoutes.forEach(function (route) {
api.modifyClass(`route:discovery.${route}`, {
pluginId: "locations-plugin",

afterModel(model) {
if (!this.siteSettings.location_category_map_filter) {
this.replaceWith(`/c/${this.Category.slugFor(model.category)}`);
}
return this._super(...arguments);
},

renderTemplate(controller, model) {
let navTemplate = this.routeName.indexOf('Category') > -1 ? 'navigation/category' : 'navigation/default';
this.render(navTemplate, { outlet: 'navigation-bar' });
this.render("discovery/map", { outlet: "list-container", controller: 'discovery/topics' });
}
});
});

const categoryRoutes = [
'category',
'categoryNone'
];

categoryRoutes.forEach(function (route) {
api.modifyClass(`route:discovery.${route}`, {
pluginId: "locations-plugin",

afterModel(model, transition) {
if (this.filter(model.category) === 'map' && this.siteSettings.location_category_map_filter) {
transition.abort();
return this.replaceWith(`/c/${this.Category.slugFor(model.category)}/l/${this.filter(model.category)}`);
} else {
return this._super(...arguments);
}
}
});
});
});

TopicStatus.reopen({
TopicStatus.reopen({
@discourseComputed
statuses() {
const topic = this.get("topic");
const category = this.get('parent.parentView.category');
let results = this._super(...arguments);

if ((this.siteSettings.location_topic_status_icon ||
(category && category.get('custom_fields.location_topic_status'))) &&
topic.get('location')) {
const url = topic.get('url');
results.push({
icon: 'map-marker-alt',
title: I18n.t(`topic_statuses.location.help`),
href: url,
openTag: 'a href',
closeTag: 'a'
});
}

return results;
}
statuses() {
const topic = this.get("topic");
const category = this.get('parent.parentView.category');
let results = this._super(...arguments);

if ((this.siteSettings.location_topic_status_icon ||
(category && category.get('custom_fields.location_topic_status'))) &&
topic.get('location')) {
const url = topic.get('url');
results.push({
icon: 'map-marker-alt',
title: I18n.t(`topic_statuses.location.help`),
href: url,
openTag: 'a href',
closeTag: 'a'
});
}

Composer.serializeOnCreate('location');
Composer.serializeToTopic('location', 'topic.location');
return results;
}
});

NavItem.reopenClass({
buildList(category, args) {
let items = this._super(category, args);
Composer.serializeOnCreate('location');
Composer.serializeToTopic('location', 'topic.location');

if (category) {
items = items.reject((item) => item.name === 'map' ); // Don't show Site Level "/map"
if (category.custom_fields.location_enabled && category.siteSettings.location_category_map_filter) {
items.push(NavItem.fromText('map', args)); // Show category level "/map" instead
}
}
NavItem.reopenClass({
buildList(category, args) {
let items = this._super(category, args);

return items;
if (category) {
items = items.reject((item) => item.name === 'map'); // Don't show Site Level "/map"
if (category.custom_fields.location_enabled && category.siteSettings.location_category_map_filter) {
items.push(NavItem.fromText('map', args)); // Show category level "/map" instead
}
});
}

return items;
}
});
}
};
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# name: discourse-locations
# about: Tools for handling locations in Discourse
# version: 6.2.8
# version: 6.2.9
# authors: Angus McLeod, Robert Barrow
# contact_emails: development@pavilion.tech
# url: https://github.com/angusmcleod/discourse-locations
Expand Down
10 changes: 8 additions & 2 deletions test/javascripts/acceptance/user-card-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ acceptance("User Card - Show Correct User Location Format", function (needs) {
needs.settings({
location_enabled: true,
location_user_profile_format: "city|countrycode",
location_user_post_format: "city|countrycode",
location_user_post: true,
location_users_map: true,
hide_user_profiles_from_public: false
hide_user_profiles_from_public: false,
});
needs.site(cloneJSON(siteFixtures["country_codes.json"]));
needs.pretender((server, helper) => {
Expand All @@ -26,12 +28,16 @@ acceptance("User Card - Show Correct User Location Format", function (needs) {
server.get("/t/51/1.json", () => helper.response(topicResponse));
});

test("user card location - shows correct format", async function (assert) {
test("post user & user card location - shows correct format", async function (assert) {
await visit("/t/online-learning/51/1");
assert.equal(
query(".small-action-desc.timegap").innerText,
"2 years later"
);
assert.equal(
query("#post_3 .user-location").innerText,
"Paris, France"
);
assert.equal(
query('a[data-user-card="merefield"]').innerText,
""
Expand Down
Loading