What is the correct syntax for saving a GeoPoint in Baqend? - baqend

What is the correct syntax for saving latitude and longitude in Baqend?
I am successfully saving the normal fields (all of them are strings):
handleSubmit(event) {
event.preventDefault();
var newcompany = new db.Companies({
name: this.state.name,
photo: '',
geo: '47.626814;-122.357345',
address1: this.state.address1,
address2: this.state.address2,
city: this.state.city,
state: this.state.state,
zip: this.state.zip,
});
newcompany.insert().then(() => {
//console.log(newcompany)
this.setState({
redirect: true,
newcompanykey: newcompany.key
})
})
}
But I can't seem to get the geo to save correctly. Probably because I'm treating it as a string and that is not correct?
In the example code I'm just hardcoding it now to values I know are good so we can get this working.

I think the answer here is that the sdk provides a function that encodes it correctly:
handleSubmit(event) {
event.preventDefault();
var geo = new db.GeoPoint(47.626814, -122.357345)
var newcompany = new db.Companies({
name: this.state.name,
photo: '',
geo: geo,
address1: this.state.address1,
address2: this.state.address2,
city: this.state.city,
state: this.state.state,
zip: this.state.zip,
});
newcompany.insert().then(() => {
//console.log(newcompany)
this.setState({
redirect: true,
newcompanykey: newcompany.key
})
})
}

Related

Description field is coming as [ARRAY] instead of the actual array([1,2,3]) in dynamodb when I try to get data using query

Items: [
{
Continent: 'Continent#Antarctica',
SKCountry: 'Country#Chile',
CreatedAt: 1668579154424,
description: [Array],
PKContinent: 'PKContinent',
id: 16,
UpdatedAt: 1668579154424
},
{
Continent: 'Continent#Antarctica',
SKCountry: 'Country#France',
CreatedAt: 1668579154424,
description: [Array],
PKContinent: 'PKContinent',
id: 15,
UpdatedAt: 1668579154424
}]
, this is what I am getting but instead of "description: [Array],", I want this, description: [value1, value2, value3]. Also, I am getting this data in console but in browser I am getting an error in console (Uncaught TypeError: Cannot read properties of undefined (reading 'tagName')).
this is the code snippet in getAllItems.
var AWS = require("aws-sdk");
AWS.config.update({
region: "local",
endpoint: "http://localhost:8000"
});
var docClient = new AWS.DynamoDB.DocumentClient()
var table = "Tourism";
const getAllItems = async ()=> {
var PKContinent = "PKContinent";
//console.log("check",PKContinent)
const params = {
TableName: table,
KeyConditionExpression: "PKContinent = :pkUpdate AND begins_with(SKCountry, :SKCountry)",
ExpressionAttributeValues: {
":pkUpdate": PKContinent,
":SKCountry": "Country#"
}
}
docClient.query(params, function (error, data) {
if (error) {
console.log(error)
} else {
var viewArray = [];
if (data.Items.length === 0) {
console.log("data doesn't exists.")
}
else {
console.log(data);
}
}
})
}
module.exports = {
docClient,
getAllItems
};
this is the code in getAll
var express = require('express');
var router = express.Router();
const { getAllItems} = require('../getAllItems');
router.get('/', async (req, res, next) => {
try {
const getData = await getAllItems();
res.json(getData);
} catch (err) {
console.error(err);
res.status(500).json({ err: 'Something went wrong with get' });
}
});
module.exports = router;
For me I believe the issue is when saving the data, not reading it.
You mention you cannot read the data in tbe console? Can you share a screenshot of how that looks in your question.
And can you also share the output of the console which you stated worked, I'll be able to guide you to the issue then.

Trying To Do A Simple Add Item To FIXTURE

I have a simple fixture:
App.User.FIXTURES = [
{ userid: 1, name: 'George', email: 'george#gmail.com', bio: 'Lorem Ipsum', created: 'Jan 5, 2015' },
{ userid: 2, name: 'Tom', email: 'tom#hotmail.com', bio: 'Lorem Ipsum 2', created: 'Jan 15, 2015' },
{ userid: 3, name: 'Mary', email: 'mary#aol.com', bio: 'Lorem Ipsum 3', created: 'Jan 25, 2015' }
];
And I have a simple submit: (snippet)
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
App.User.createRecord({ id: 4, userid: 4, name: 'Created person', email: 'sdh', bio: 'my bio', created: '6543456' });
I THINK this is right as I'm not getting an error on createRecord anymore, but now I'm getting an error, any ideas? One more step I'm missing just to shove something into a fixture?
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
Kingpin2k is correct in that calling createRecord on the UserModel itself is an older way of using Ember Data. If you're using the latest version you should call createRecord from the store object.
Here's what it should look like:
App.AddController = Ember.ArrayController.extend({
actions: {
save: function () {
//Create a new user
var user = this.store.createRecord('user',{
id: 4,
userid: 4,
name: 'Created person',
email: 'sdh',
bio: 'my bio',
created: '6543456'
});
// Saves the new model, but not needed if you're just using FIXTURES
// Making the call shouldn't throw any errors though and is used in the Guide
user.save();
// Now you can find your record in the store
this.store.find('user', 4).then(function(user){
console.info(user);
});
}
}
});
This was tested on:
DEBUG: -------------------------------
DEBUG: Ember : 1.6.0-beta.1+canary.24b19e51
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery : 2.0.2
DEBUG: -------------------------------
I'd recommend reviewing the "Creating a New Model Instance" portion of the Ember getting started guide as they cover this topic there:
http://emberjs.com/guides/getting-started/creating-a-new-model/

How to update/edit record in emberjs?

I have collected data from fixture and displayed in form of table.
Also,i have added two column one is edit another is delete now i want to edit specific row.
On click of edit i have populated data on modal window with one update button and i want to update changes on click of update.
Here is my code :
Store :
Grid.Store = DS.Store.extend({adapter: 'DS.FixtureAdapter'});
Router:
Grid.Router.map(function () {
this.resource('mainview', { path: '/' });
});
Grid.MainviewRoute = Ember.Route.extend({
model: function () {
return Grid.ModalModel.find();
}
});
Model :
Grid.ModalModel = DS.Model.extend({
fname: DS.attr('string'),
lname: DS.attr('string'),
email: DS.attr('string'),
contactno: DS.attr('string'),
gendertype: DS.attr('boolean'),
contactype: DS.attr('number')
});
Grid.ModalModel.FIXTURES = [
{
id: 1,
fname: "sachin",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
},
{
id: 2,
fname: "amit",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
},
{
id: 3,
fname: "namit",
lname: "gh",
email: "gh",
contactno: "4542154",
gendertype: true,
contactype: 1
}
];
Controller :
Grid.MainviewController = Ember.ArrayController.extend({
contentChanged: function() {
this.get('content').forEach(function(item){
var serializer = DS.RESTSerializer.create();
var json_data = serializer.serialize(item);
console.log(JSON.stringify(json_data));
});
}.observes('content.#each'),
showmodal: function(){
$('#modal').modal();
},
showeditmodal: function(){
var rowindex_table = 1;
var contactype = 0;
var post = Grid.ModalModel.find(rowindex_table);
var serializer = DS.RESTSerializer.create();
var cont_edit_data = serializer.serialize(post);
console.log(JSON.stringify(cont_edit_data));
this.set('obj_form_edit_data.cont_data.fname', cont_edit_data["fname"]);
this.set('obj_form_edit_data.cont_data.lname', cont_edit_data["lname"]);
this.set('obj_form_edit_data.cont_data.email', cont_edit_data["email"]);
this.set('obj_form_edit_data.cont_data.contactno', cont_edit_data["contactno"]);
if(cont_edit_data["gendertype"] == true){
this.set('male', true);
$(".cssmale").addClass("active");
}else{
this.set('female', true);
$(".cssfemale").addClass("active");
}
$('.selectpicker').val(cont_edit_data['contactype']);
$('.selectpicker').selectpicker('render');
$('#editmodal').modal();
},
isMale: false,
isFemale: false,
obj_form_edit_data : Ember.Object.create({
cont_data:{
fname : "",
lname : "",
email : "",
contactno : "",
gendertype : "",
contactype : 0
}
}),
gendertype: function(){
this.set('isMale', !this.get('isMale'));
},
savecontact: function(){//save data in local storage
var fname = this.obj_form_edit_data.get('cont_data.fname');
var lname = this.obj_form_edit_data.get('cont_data.lname');
var email = this.obj_form_edit_data.get('cont_data.email');
var contactno = this.obj_form_edit_data.get('cont_data.contactno');
var gendertype = ((this.get('isMale') == true) ? true : false);
var contactype = $(".selectpicker").text();
//Clear view first
this.set('obj_form_edit_data.cont_data.fname', '');
this.set('obj_form_edit_data.cont_data.lname', '');
this.set('obj_form_edit_data.cont_data.email', '');
this.set('obj_form_edit_data.cont_data.contactno', '');
this.set('isMale',false);
this.set('isFemale',false);
$('.selectpicker').val('0');
$('.selectpicker').selectpicker('render');
Grid.ModalModel.createRecord({
fname: fname,
lname: lname,
email: email,
contactno: contactno,
gendertype: gendertype,
contactype: contactype
});
this.get('store').commit();
},
updatecontact: function(){
this.get('store').commit();
}
updatecontact is used to update record on click of update button but it is throwing an error
Uncaught TypeError: Object [object Object] has no method 'commit'
Can anyone tell me how to update record in such case?

Correct usage of store.loadMany() function

I'm trying to figure out how to populate a table from a JSON object.
My JSON is a structurated object:
{
id: 0,
list: [{ username:'user_1',online:true, user:0 },
{ username:'user_2',online:true, user:0 }]
}
My Model is defined as follow:
MyTalk.WUser = DS.Model.extend({
list: DS.hasMany('MyTalk.User')
});
MyTalk.User = DS.Model.extend({
username: DS.attr('string'), // primary key
online: DS.attr('boolean'),
user: DS.belongsTo('MyTalk.WUser')
});
I am using a custom Adapter for ember-data:
DS.SocketAdapter = DS.RESTAdapter.extend(MyTalk.WebSocketConnection, {
// code not relevant
}
DS.SocketAdapter.map('MyTalk.WUser', {
list: {embedded: 'always'}
});
DS.SocketAdapter.map('MyTalk.User', {
primaryKey: 'username'
});
MyTalk.Store = DS.Store.extend({
revision: 12,
adapter: DS.SocketAdapter.create({})
});
Now I would load my data. I run in Chrome command line the following statements:
var store = DS.get('defaultStore');
var obj = {
id: 0,
list: [{ username:'user_1',online:true, user:0 },
{ username:'user_2',online:true, user:0 }]
};
var store.loadMany(MyTalk.WUser,obj);
var record = MyTalk.WUser.find(0);
record.serialize();
But it returns no record:
> Object {list: Array[0]}
thanks in advance!!
If you want to allow the adapter to deserialize embedded records (or perform any custom deserialization, for that matter), you'll need to load your data through the adapter rather than directly into the store.
var store = DS.get('defaultStore'),
obj = {
id: 0,
list: [{ username:'user_1', online:true, user:0 },
{ username:'user_2', online:true, user:0 }]
},
type = MyTalk.WUser,
adapter = store.adapterForType(type);
adapter.load(store, type, obj);

extjs dataview not loading data store

I'm baffled that this dataView is empty! I have this same setup working with images but it's not displaying here. Am I missing something? Thanks for your help.
json:
{rows:[{"noteid":"4","txid":"97","contactid":"38","displayname":"Jeb Hafkin","txdate":"08\/20\/2010","date":"12\/08\/2011","type":"Treatment Note","content":"new test<img src=\"..\/logos\/1912323619.jpg\">","subject":"Jeb's note","firstname":"Jeb","lastname":"Hafkin"},{"noteid":"6","txid":"0","contactid":"51","displayname":"Bill Hyyman","txdate":null,"date":"12\/12\/2011","type":"","content":"test","subject":"","firstname":"Bill","lastname":"Hyyman"}], "success": true}
data Store, tpl, dataview:
var noteStore = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['noteid','txid','contactid', 'displayname', 'date',
'subject','txdate','type','amtpd','content' ],
root: 'rows',
id: 'noteid'
}),
proxy: new Ext.data.HttpProxy({
url: '/request.php?x=noteStore'
})
});
var tpl = new Ext.XTemplate (
'<tpl for ".">',
'<p class="note">noteid = {noteid} </p>',
'</tpl>'
);
var noteDataView = new Ext.DataView({
store: noteStore,
tpl: tpl,
autoHeight:true,
multiSelect: true,
overClass:'x-view-over',
itemSelector:'p.note',
emptyText: 'No notes to display'
});
var notePanel = new Ext.Panel ({
layout: 'fit',
padding: 10,
items: [noteDataView],
tbar: noteTb
});
The store needs to be loaded. Try adding autoLoad: true to your store:
var noteStore = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['noteid','txid','contactid', 'displayname', 'date',
'subject','txdate','type','amtpd','content' ],
root: 'rows',
id: 'noteid',
}),
proxy: new Ext.data.HttpProxy({
url: '/request.php?x=noteStore'
}),
autoLoad: true
});