mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Moved places package to https://github.com/VulcanJS/vulcan-places
This commit is contained in:
parent
f63939534d
commit
62f3b03476
14 changed files with 0 additions and 300 deletions
|
@ -1,3 +0,0 @@
|
|||
# Vulcan Forms Place
|
||||
|
||||
Uses https://github.com/kenny-hibino/react-places-autocomplete
|
|
@ -1,4 +0,0 @@
|
|||
import { Places } from '../modules/index.js';
|
||||
|
||||
export * from '../modules/index.js';
|
||||
export default Places;
|
|
@ -1,82 +0,0 @@
|
|||
import { Components, registerComponent } from 'meteor/vulcan:core';
|
||||
import React, { PropTypes, Component } from 'react';
|
||||
import PlacesAutocomplete from 'react-places-autocomplete';
|
||||
import FRC from 'formsy-react-components';
|
||||
|
||||
const Input = FRC.Input;
|
||||
|
||||
class PlaceControl extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { address: props.value, placeName: props.value, placeId: props.document.placeId };
|
||||
this.onChange = (address) => this.setState({ address });
|
||||
this.onSelect = (address, placeId) => this.setState({ address, placeId });
|
||||
this.onBlur = this.onBlur.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (typeof window !== 'undefined') {
|
||||
this.placesService = new window.google.maps.places.PlacesService(document.createElement('div'))
|
||||
}
|
||||
}
|
||||
|
||||
onBlur() {
|
||||
|
||||
const {placeId} = this.state;
|
||||
|
||||
this.placesService.getDetails({placeId}, (result) => {
|
||||
console.log(result)
|
||||
|
||||
this.setState({placeName: result.name});
|
||||
|
||||
this.context.addToAutofilledValues({
|
||||
placeName: result.name,
|
||||
placeId: placeId,
|
||||
});
|
||||
});
|
||||
|
||||
// geocodeByAddress(address, (err, latLng) => {
|
||||
// if (err) { console.log(err) }
|
||||
// this.context.addToAutofilledValues({
|
||||
// placeName: address,
|
||||
// placeLat: latLng.lat,
|
||||
// placeLong: latLng.lng
|
||||
// });
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const inputProps = {
|
||||
value: this.state.address,
|
||||
onChange: this.onChange,
|
||||
onBlur: this.onBlur
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="form-group row">
|
||||
<label className="control-label col-sm-3">{this.props.label}</label>
|
||||
<div className="col-sm-9">
|
||||
<PlacesAutocomplete inputProps={inputProps} onSelect={this.onSelect} />
|
||||
<Input name={this.props.name} type="hidden" readOnly value={this.state.placeName} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PlaceControl.propTypes = {
|
||||
name: React.PropTypes.string,
|
||||
value: React.PropTypes.any,
|
||||
label: React.PropTypes.string
|
||||
};
|
||||
|
||||
PlaceControl.contextTypes = {
|
||||
addToAutofilledValues: React.PropTypes.func,
|
||||
}
|
||||
|
||||
registerComponent('PlaceControl', PlaceControl);
|
||||
|
||||
export default PlaceControl;
|
|
@ -1,23 +0,0 @@
|
|||
import { createCollection } from 'meteor/vulcan:core';
|
||||
import schema from './schema.js';
|
||||
import resolvers from './resolvers.js';
|
||||
|
||||
const Places = createCollection({
|
||||
|
||||
collectionName: 'Places',
|
||||
|
||||
typeName: 'Place',
|
||||
|
||||
schema,
|
||||
|
||||
resolvers,
|
||||
|
||||
});
|
||||
|
||||
Places.addDefaultView(terms => {
|
||||
return {
|
||||
options: {sort: {createdAt: -1}}
|
||||
};
|
||||
});
|
||||
|
||||
export default Places;
|
|
@ -1,12 +0,0 @@
|
|||
import { Headtags, getSetting } from 'meteor/vulcan:core';
|
||||
|
||||
const googlemaps = getSetting('googlemaps');
|
||||
|
||||
if (googlemaps && googlemaps.apiKey) {
|
||||
|
||||
Headtags.script.push({
|
||||
type: 'text/javascript',
|
||||
src: `https://maps.googleapis.com/maps/api/js?key=${googlemaps.apiKey}&libraries=places`
|
||||
});
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
import './headtags.js';
|
||||
|
||||
export { default as PlaceControl } from '../components/PlaceControl.jsx';
|
||||
export { default as Places } from './collection.js';
|
|
@ -1,18 +0,0 @@
|
|||
import Places from './collection.js';
|
||||
|
||||
const resolvers = {
|
||||
|
||||
single: {
|
||||
|
||||
name: 'placesSingle',
|
||||
|
||||
async resolver(root, {documentId}, {currentUser, Users, Posts}) {
|
||||
const place = await Places.loader.load(documentId);
|
||||
return place;
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
export default resolvers;
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
|
||||
A SimpleSchema-compatible JSON schema
|
||||
|
||||
*/
|
||||
|
||||
const schema = {
|
||||
|
||||
// default properties
|
||||
|
||||
_id: { // use place id from google
|
||||
type: String,
|
||||
optional: true,
|
||||
viewableBy: ['guests'],
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
optional: true,
|
||||
viewableBy: ['guests'],
|
||||
onInsert: (document, currentUser) => {
|
||||
return new Date();
|
||||
}
|
||||
},
|
||||
|
||||
// custom properties
|
||||
|
||||
name: {
|
||||
type: String,
|
||||
viewableBy: ['guests'],
|
||||
},
|
||||
|
||||
location: {
|
||||
type: Object,
|
||||
viewableBy: ['guests'],
|
||||
blackbox: true
|
||||
},
|
||||
|
||||
url: {
|
||||
type: String,
|
||||
viewableBy: ['guests'],
|
||||
},
|
||||
|
||||
website: {
|
||||
type: String,
|
||||
viewableBy: ['guests'],
|
||||
},
|
||||
|
||||
adr_address: {
|
||||
type: String,
|
||||
viewableBy: ['guests'],
|
||||
},
|
||||
};
|
||||
|
||||
export default schema;
|
|
@ -1,41 +0,0 @@
|
|||
import { addCallback, newMutation } from 'meteor/vulcan:core';
|
||||
import Places from '../modules/collection.js';
|
||||
import { getPlaceDetails } from './googlemaps.js';
|
||||
|
||||
const formatPlace = result => {
|
||||
const data = result.json.result;
|
||||
const place = _.pick(data, ['name', 'url', 'website', 'adr_address']);
|
||||
place._id = result.json.result.place_id;
|
||||
place.location = { type: 'Point', coordinates: [ data.geometry.location.lat, data.geometry.location.lng ] }
|
||||
return place;
|
||||
}
|
||||
|
||||
const checkAndAddPlace = placeId => {
|
||||
const existingPlace = Places.findOne({placeId});
|
||||
|
||||
if (!existingPlace) {
|
||||
|
||||
getPlaceDetails(placeId, (error, result) => {
|
||||
|
||||
const place = formatPlace(result);
|
||||
|
||||
return newMutation({
|
||||
collection: Places,
|
||||
document: place,
|
||||
validate: false,
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function postsNewCheckForNewPlace (document, user) {
|
||||
if (document.placeId) checkAndAddPlace(document.placeId);
|
||||
}
|
||||
addCallback('posts.new.async', postsNewCheckForNewPlace);
|
||||
|
||||
function postsEditCheckForNewPlace (document) {
|
||||
if (document.placeId) checkAndAddPlace(document.placeId);
|
||||
}
|
||||
addCallback('posts.edit.async', postsEditCheckForNewPlace);
|
|
@ -1,19 +0,0 @@
|
|||
import googleMaps from '@google/maps';
|
||||
import { getSetting } from 'meteor/vulcan:core';
|
||||
|
||||
const googleMapsSetting = getSetting('googlemaps');
|
||||
|
||||
if (!googleMapsSetting) {
|
||||
throw new Error('Please fill in your Google Maps API Key or disable the Places package.');
|
||||
}
|
||||
|
||||
const googleMapsClient = googleMaps.createClient({
|
||||
key: googleMapsSetting.apiKey
|
||||
});
|
||||
|
||||
export const getPlaceDetails = (placeId, callback) => {
|
||||
googleMapsClient.place({
|
||||
placeid: placeId,
|
||||
language: getSetting('language', 'en')
|
||||
}, Meteor.bindEnvironment(callback));
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
import './callbacks.js';
|
||||
import { Places } from '../modules/index.js';
|
||||
|
||||
export { getPlaceDetails } from "./googlemaps.js";
|
||||
export * from '../modules/index.js';
|
||||
export default Places;
|
|
@ -1,9 +0,0 @@
|
|||
#PlacesAutocomplete__autocomplete-container{
|
||||
z-index: 100;
|
||||
}
|
||||
#PlacesAutocomplete__root{
|
||||
input{
|
||||
border-radius: 3px;
|
||||
border: 1px solid rgba(0,0,0,.15);
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
Package.describe({
|
||||
name: 'vulcan:places',
|
||||
summary: 'Google Maps Places package.',
|
||||
version: '1.3.2',
|
||||
git: 'https://github.com/vulcanjs/vulcan.git'
|
||||
});
|
||||
|
||||
Package.onUse( function(api) {
|
||||
|
||||
api.versionsFrom('METEOR@1.0');
|
||||
|
||||
api.use([
|
||||
'vulcan:core@1.3.2',
|
||||
'vulcan:forms@1.3.2',
|
||||
'fourseven:scss@4.5.0'
|
||||
]);
|
||||
|
||||
api.addFiles([
|
||||
'lib/style.scss'
|
||||
], 'client');
|
||||
|
||||
api.mainModule('lib/client/main.js', 'client');
|
||||
api.mainModule('lib/server/main.js', 'server');
|
||||
|
||||
});
|
Loading…
Add table
Reference in a new issue