Many improvements in SelectionMap
This commit is contained in:
parent
7a672bca87
commit
e3eddd6b85
13 changed files with 173 additions and 132 deletions
|
|
@ -37,10 +37,42 @@ Subscriptions.deny({
|
|||
* }
|
||||
* */
|
||||
|
||||
// https://stackoverflow.com/questions/24492333/meteor-simple-schema-for-mongo-geo-location-data
|
||||
// https://github.com/aldeed/meteor-simple-schema/issues/606
|
||||
const LocationSchema = new SimpleSchema({
|
||||
type: {
|
||||
type: String,
|
||||
allowedValues: ['Point']
|
||||
},
|
||||
coordinates: {
|
||||
type: Array,
|
||||
minCount: 2,
|
||||
maxCount: 2,
|
||||
custom: function custom() {
|
||||
if (!(this.value[0] >= -90 && this.value[0] <= 90)) {
|
||||
return 'lngOutOfRange';
|
||||
}
|
||||
if (!(this.value[1] >= -180 && this.value[1] <= 180)) {
|
||||
return 'latOutOfRange';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
'coordinates.$': {
|
||||
type: Number
|
||||
}
|
||||
});
|
||||
|
||||
LocationSchema.messageBox.messages({
|
||||
lonOutOfRange: '[label] longitude should be between -90 and 90',
|
||||
latOutOfRange: '[label] latitude should be between -180 and 180'
|
||||
});
|
||||
|
||||
Subscriptions.schema = new SimpleSchema({
|
||||
location: Object,
|
||||
'location.lat': Number,
|
||||
'location.lon': Number,
|
||||
geo: LocationSchema,
|
||||
distance: Number,
|
||||
owner: String,
|
||||
type: String
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@ import { check, Match } from 'meteor/check';
|
|||
import Subscriptions from './Subscriptions';
|
||||
import rateLimit from '../../modules/rate-limit';
|
||||
|
||||
function geo(doc) {
|
||||
return {
|
||||
type: 'Point',
|
||||
coordinates: [doc.location.lon, doc.location.lat]
|
||||
};
|
||||
}
|
||||
|
||||
Meteor.methods({
|
||||
'subscriptions.insert': function subscriptionsInsert(doc) {
|
||||
check(doc, {
|
||||
|
|
@ -10,10 +17,17 @@ Meteor.methods({
|
|||
distance: Number
|
||||
});
|
||||
const type = 'web';
|
||||
|
||||
try {
|
||||
return Subscriptions.insert({ owner: this.userId, type, ...doc });
|
||||
const newDoc = {
|
||||
owner: this.userId,
|
||||
type,
|
||||
geo: geo(doc),
|
||||
...doc
|
||||
};
|
||||
// console.log(newDoc);
|
||||
return Subscriptions.insert(newDoc);
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
throw new Meteor.Error('500', exception);
|
||||
}
|
||||
},
|
||||
|
|
@ -25,8 +39,10 @@ Meteor.methods({
|
|||
});
|
||||
|
||||
try {
|
||||
const dup = doc;
|
||||
const subscriptionId = doc._id;
|
||||
Subscriptions.update(subscriptionId, { $set: doc });
|
||||
dup.geo = geo(doc);
|
||||
Subscriptions.update(subscriptionId, { $set: dup });
|
||||
return subscriptionId; // Return _id so we can redirect to subscription after update.
|
||||
} catch (exception) {
|
||||
throw new Meteor.Error('500', exception);
|
||||
|
|
@ -38,6 +54,7 @@ Meteor.methods({
|
|||
try {
|
||||
return Subscriptions.remove(subscriptionId);
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
throw new Meteor.Error('500', exception);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ Meteor.publishTransformed('userSubsToFires', function transform() {
|
|||
}
|
||||
// console.log(`with noise: [${doc.lat}, ${doc.lon}]`);
|
||||
delete doc.chatId;
|
||||
delete doc.geo;
|
||||
// delete doc.geo;
|
||||
return doc;
|
||||
});
|
||||
});
|
||||
|
||||
Meteor.publish('mysubscriptions', function subscriptions() {
|
||||
return Subscriptions.find({ owner: this.userId });
|
||||
return Subscriptions.find({ owner: this.userId, type: 'web' });
|
||||
});
|
||||
|
||||
// Note: subscriptions.view is also used when editing an existing subscription.
|
||||
|
|
@ -49,5 +49,5 @@ Meteor.publish('subscriptions.view', function subscriptionsView(subscriptionId)
|
|||
check(subscriptionId, String);
|
||||
const id = new Mongo.ObjectID(subscriptionId);
|
||||
check(id, Meteor.Collection.ObjectID);
|
||||
return Subscriptions.find({ _id: id, owner: this.userId });
|
||||
return Subscriptions.find({ _id: id, owner: this.userId, type: 'web' });
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue