JSON Store change method with replaceCriteria MobileFirst 6.3 - windows-phone-8

i have used JSON store change method with replaceCriteria
var changeOptions = {
replaceCriteria : ['chartName','periode','office_id','parent_office_id'],
addNew : true,
markDirty : false //data came from the server
};
WL.JSONStore.get(collectionName).change(data, changeOptions);
my input data :
[{ chartName:"disiplin",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-06",
value:100,
title:"tes"
},
{ chartName:"portofolio",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-06",
value:90,
title:"tes2"
}]
my new data :
[{ chartName:"disiplin",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-07",
value:100,
title:"tes3"
},
{ chartName:"portofolio",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-07",
value:90,
title:"tes4"
}]
my changed data on windows phone :
[{
id:4,
json:{
chartName:"portofolio",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-07",
value:90,
title:"tes4"
}
}]
Expected data (Android, iOS, BB10) :
[{
id:1,
json:{
chartName:"disiplin",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-06",
value:100,
title:"tes"
}
},
{
id:2,
json:{
chartName:"portofolio",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-06",
value:90,
title:"tes2"
}
},
{
id:3,
json:{
chartName:"disiplin",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-07",
value:100,
title:"tes3"
}
},
{
id:4,
json:{
chartName:"portofolio",
parent_office_id:"1",
office_id:"HO",
periode:"2014-12-07",
value:90,
title:"tes4"
}
}]
The code above is working fine on Android, iOS, and BB10. But when i tried on my Windows Phone 8 app, my new data always overwrite the data before. I think replaceCriteria is not working on windows phone 8. Is it true ?

Replace criteria is working correctly but the behavior on Windows is different than in Android/iOS/Blackberry.
In Windows the replace criteria uses OR operations rather than AND operations. So as long as it can find any of the search fields with the same values in your store it will replace it.
If you wish to change this use fewer replaceCriteria. You can also ask for a feature request.

Related

Google Embed API: GEO chart - show specific country

I'm using Google Embed API to show data from google analytics visually.
I was trying to display only a specific country to show users from each of its regions.
I create a "DataChart" which has a "query" and "chart" object. In the chart object, you specify a type of chart, and some extra options.
If I choose "GEO", then it will use the "Geocoding" api, as I've understood it.
I am not able to show the country (Sweden) with its regions however, I don't know what to specify in the chart "options" object.
var location = new gapi.analytics.googleCharts.DataChart({
query: {
'ids': viewId,
'start-date': '90daysAgo',
'end-date': 'today',
'metrics': 'ga:users',
'sort': '-ga:users',
'dimensions': 'ga:region',
'max-results': 10
},
chart: {
'container': 'location',
'type': 'GEO',
'options': {
region: 150, // <-- Europe
country: 'SE', // <-- just guessing
}
}
});
This shows the whole world. If I remove "country", it shows Europe, with the top part cropped away. So I haven't specified "country" in the correct way (I am only guessing since there is no info).
The only info I can find on the GEO chart is here Visualization: GeoChart, but it's not specific for the Embed API.
So does anyone have a solution for this case, and is there info on different properties for the chart object? ( For the query object, there is Dimensions & Metrics Explorer )
Update:
The main question was solved with a below answer:
'options': {
region: 'SE',
resolution: 'provinces'
}
, but the data is not displayed in the regions, so if you have any clues around that, you could perhaps mention it as a comment.
Here is part of the data response from the query (with regions):
"dataTable": {
"cols": [
{
"id": "ga:region",
"label": "ga:region",
"type": "string"
},
{
"id": "ga:users",
"label": "ga:users",
"type": "number"
}
],
"rows": [
{
"c": [
{
"v": "Stockholm County"
},
{
"v": "15"
}
]
},
{
"c": [
{
"v": "Vastra Gotaland County"
},
{
"v": "6"
}
]
},
here are the only configuration options for the GeoChart that I'm aware of...
to display only sweden...
var options = {
region: 'SE'
};
(remove the country option)
see following working snippet...
google.charts.load('current', {
'packages':['geochart'],
'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
});
google.charts.setOnLoadCallback(drawRegionsMap);
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country', 'Popularity'],
]);
var options = {
region: 'SE',
resolution: 'provinces'
};
var chart = new google.visualization.GeoChart(document.getElementById('chart'));
chart.draw(data, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>

How to bind json data to screen with tpl config?

I'm working on Sencha's Admin Dashboard sample and trying to customize 'Weather' panel.
I've created a JSON format url with OpenWeatherMap's Current weather data API. The thing I can't bind JSON data to Weather panel with tpl config. I've created a ViewModel and called it within Component but it did not worked as well.
Here is the component class;
Ext.define('OWeb.view.dashboard.Weather', {
extend: 'Ext.Component',
xtype: 'weather',
baseCls: 'weather-panel',
border: false,
height: 80,
store: {
proxy: {
type: 'ajax',
url: 'http://api.openweathermap.org/data/2.5/weather?q=Antalya,TR&appid=9b59049894d42af608baf69f869b9ace&units=metric',
reader: {
type: 'json'
}
},
autoLoad: true
},
tpl: '<div class="weather-image-container"><img src="resources/img/{icon}" alt="{weather.description}"/></div>'+
'<div class="weather-details-container">' +
'<div>{main.temp}°</div>' +
'<div>{weather.main}</div>' +
'</div>'
});
And this is link for JSON data which returns via OpenWeatherMap and snippet;
{
"coord": {
"lon": 30.72,
"lat": 36.77
},
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"base": "stations",
"main": {
"temp": 25,
"pressure": 1015,
"humidity": 23,
"temp_min": 25,
"temp_max": 25
},
"visibility": 10000,
"wind": {
"speed": 5.7,
"deg": 320
},
"clouds": {
"all": 0
},
"dt": 1507184400,
"sys": {
"type": 1,
"id": 6028,
"message": 0.0025,
"country": "TR",
"sunrise": 1507175759,
"sunset": 1507217657
},
"id": 323776,
"name": "Antalya",
"cod": 200
}
Thanks, any advice is welcome.
UPDATE
I've found this post and I tried same thing; extend from Ext.DataView, setting proxy type jsonp and using itemTpl config. Now I can bind to JSON data but only can displaying {main.temp}. Any idea please?
Ext.define('OWeb.view.dashboard.Weather', {
//extend: 'Ext.Component',
extend: 'Ext.DataView',
xtype: 'weather',
baseCls: 'weather-panel',
border: false,
height: 80,
store: {
proxy: {
type: 'jsonp',
url: 'http://api.openweathermap.org/data/2.5/weather?q=Antalya,TR&appid=9b59049894d42af608baf69f869b9ace&units=metric',
reader: {
type: 'json'
}
},
autoLoad: true
},
itemTpl: '<div class="weather-image-container"><img src="{weather.icon}" alt="{weather.description}"/></div>'+
'<div class="weather-details-container">' +
'<div>{main.temp}°</div>' +
'<div>{weather.description}</div>' +
'</div>'
});
Please look at the points below to understand this.
Ext.Component class does not work with store because of which your code was not working. You could have created the store elsewhere and then retrieved the data from store and set the data property of the component to it. (Note that for Ext.Component, the tpl property works with data property:
var data = store.getData();
component.setData(data);
jsonP proxy is needed only when you need to fetch data from a different domain.
If you are getting data in a store then better option is to extend your class from Ext.DataView because it works with store.
The values were not properly showing in the template because weather property was an array of objects and we needed something like weather[0].icon. So for this, Model was required with fields properly mapped.(Look at the mapping property.)
I have created a Fiddle for your code. Image is not showing because url is not returning any image. Rest is working. Hope this is helpful to you.

Mongoose - How can I make this data more usable?

I have the following data strucutre outputting form my Schema in a node/express app. I'd like to have the feeds array simply an array of name:key pairs. I don't like the sort of weird numbered object structure going on between "feeds" and the actual feeds data. But i can't figure out how to manually define that in mongoose. any help would be awesome. thanks!
outputted JSON
{
"title": "Testing",
"created_at": "2011-10-05T16:23:26.217Z",
"feeds": [{
"0": {
"name": "twitter",
"key": "person1"
},
"1": {
"name": "twitter",
"key": "person2"
},
"_id": "4e8c847e02edc10035000003"
}]
}
i want this:
{
"title": "Testing",
"created_at": "2011-10-05T16:23:26.217Z",
"feeds": [
{
"name": "twitter",
"key": "person1"
},
{
"name": "twitter",
"key": "person2"
}
],
"_id": "4e8c847e02edc10035000003"
}
this is my schema:
var Feed = new Schema({
name : { type: String }
, key : { type: String }
});
var Page = new Schema({
title : { type: String, required: true, index: { unique: true } }
, feeds : [Feed]
, created_at : { type: Date, required: true, default: Date.now }
});
Ok, a colleague was able to answer this for me. My bad for not posting the relevant code, I didn't realize where the problem actually was. But for those who may encounter this problem:
If you push your embedded docs into the model when saving, you may need to do a forEach loop rather than pushing the embedded docs (in this case Feeds) together. Using forEach, the database saved the feeds directly to the feeds array rather than creating those weird groupings.
This pushed the feeds in properly:
req.body.feed.forEach(function(feed){
page.feeds.push(feed);
});
Let me know if you have the same problem and need more explanation.

json not loading in iphone device while using sencha touch and phonegap

I'm trying to load a json into my view. Im using phonegap with sencha touch and when I load the app to my phone the json does not load at all.. It works fine in the browser and in the simulator.
I would really appreciate some help from the experts
Here is the main code that im trying:
the store:
App.stores.freebees = new Ext.data.Store({
model: 'Freebee',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'fixtures/freebees',
reader: {
type: 'json'
}
}
});
the list view:
App.views.FreebeesList = Ext.extend(Ext.List, {
id: 'indexlist',
layout: 'fit',
store: App.stores.freebees,
itemTpl: '{companyName}, {title}, {address}',
listeners: {
'itemtap': function(list, index, item, obj) {
Ext.dispatch({
controller: 'Freebee',
action: 'showDetails',
id: list.getRecord(item).data.id,
lat: list.getRecord(item).data.lat,
longitude: list.getRecord(item).data.longitude,
companyName: list.getRecord(item).data.companyName,
address: list.getRecord(item).data.address,
});
}
},
initComponent: function() {
App.views.FreebeesList.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('App.views.FreebeesList', App.views.FreebeesList);
the json:
[
{
"id": 1,
"title": "Freebee 1",
"companyName": "Företaget AB 1",
"address": "Ekuddsvägen 1 Nacka 131 38 Sweden",
"lat": 59.3058,
"longitude": 18.1463
},
{
"id": 2,
"title": "Freebee 2",
"companyName": "Företaget AB 2",
"address": "Ekuddsvägen 2 Nacka 131 38 Sweden",
"lat": 59.305,
"longitude": 18.1478
}
]
From my limited experiece with ST so far, you cant load a file which is on the device like that. You may have to load the json file using a script tag and pass it in as data.
data = [ { "id": 1, "title": "Freebee 1", "companyName": "Företaget AB 1", "address": "Ekuddsvägen 1 Nacka 131 38 Sweden", "lat": 59.3058, "longitude": 18.1463 }, { "id": 2, "title": "Freebee 2", "companyName": "Företaget AB 2", "address": "Ekuddsvägen 2 Nacka 131 38 Sweden", "lat": 59.305, "longitude": 18.1478 } ];
then load it into your store like so:
App.stores.freebees = new Ext.data.Store({ model: 'Freebee', root:data, autoLoad: true, proxy: { type: 'ajax', url: 'fixtures/freebees', reader: { type: 'json' } } });
(added root:data)
I had a similar error.. Please see my question and answer here:
Sencha parses JSON in iphone simulator, but not on iPhone - phonegap

extJS: reading a nested JSON

I have a pretty nested JSON coming from a ldap_search() call. I would like to use this information to populate an ExtJS ComboBox, but I am facing some troubles with the reader. Apparently, I am not able to read the information that I need in the ComboBox, that is the mail address of the people, the uid and the cn
I think the whole problem lies in the store. I was trying the following code:
var store= new Ext.data.JsonStore({
url:'search.php',
root: '',
totalProperty: 'count',
fields: [
{name:'cn', type: 'string', mapping:'cn.0'},
{name:'mail', type: 'string', mapping:'mail.0'},
{name:'uid', type: 'string', mapping:'uid.0'}
]
});
but FireBug told me missing ; before statement return obj.cn.0 in ext-all.js (line 7). I tried with another, easier JSON array and it works, that is why I really think the problem lies in this part of code, especially in the mapping.
an example of JSON returned by search.php is:
{
"count": 2,
"0": {
"mail": {
"count": 1,
"0": "Mail address not registered."
},
"0": "mail",
"uid": {
"count": 1,
"0": "name0.surname0#domain.com"
},
"1": "uid",
"cn": {
"count": 1,
"0": "Surname0 Name0"
},
"2": "cn",
"count": 3,
"dn": "cn=Surname0 Name0,ou=personal,dc=domain,dc=com"
},
"1": {
"mail": {
"count": 1,
"0": "name1.surname1#domain.com"
},
"0": "mail",
"uid": {
"count": 1,
"0": "name1.surname1"
},
"1": "uid",
"cn": {
"count": 1,
"0": "Surname 1 Name 1"
},
"2": "cn",
"count": 3,
"dn": "cn=Surname1 Name1,ou=personal,dc=domain,dc=com"
}
}
Thanks for your time.
Yep, that JSON structure is not going to work straight away with standard ExtJS JSONReader. Take a look at this example taken from the ExtJS API documentation on how the JSON should look like.
{
results: 2000, // Reader's configured totalProperty
rows: [ // Reader's configured root
// record data objects:
{ id: 1, firstname: 'Bill', occupation: 'Gardener' },
{ id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
...
]
}
Also, the root config option is required, you cannot leave it empty. In the above example your root would be "rows".
You are probably going to need to parse that JSON of yours into a simpler format at first, before feeding it to the JSONReader.
I was looking to do the same thing, but have one of the nested items be a field in my chart. This post kept coming up, so I thought it might be helpful to see what I did to solve the chart issue. The key to solving it is knowing that the label config exists: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.chart.Label. Using that you can override the default render of what you pass in. In this example the field is "key" (Not shown here, but my model is using the default type for 'key' (ie., not string)). The key object gets passed to renderer. Using function(t), I can now access that object like javascript and pass back the name under the object.
json
key : {
wholePath : "c:/.../fileName.txt",
fileName : "fileName.txt",
}
code:
axes: [
{
title: 'Values',
type: 'Numeric',
position: 'left',
fields: ['value'],
minimum: 0,
maximum: 100,
minorTickSteps: 1
},
{
title: 'File Name',
type: 'Category',
position: 'bottom',
fields: ['key'],
label: {
renderer: function(t) {
var fileName = t.name;
return fileName;
}
}
}