So, I am trying to figure out how to get URL to an image in Freebase database. I want an image of San Francisco. This is how I get the San Francisco topic:
https://www.googleapis.com/freebase/v1sandbox/topic/%2Fen%2Fsan_francisco?key=MY_API_KEY
The response contains images, for example:
{
text: "San Francisco Skyline",
lang: "en",
id: "/m/04j74yh",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z"
}
So I then call the GET API again to get the image:
https://www.googleapis.com/freebase/v1sandbox/topic/%2Fm%2F04j74yh?key=MY_API_KEY
This returns lots of information about the image such as media type, size etc. But I don't see any URL there. There are some IDs (blob id, mid). I am not sure how to proceed to get a URL to the image. Any ideas?
This is the full response:
{
id: "/m/04j74yh",
property: {
/common/image/appears_in_topic_gallery: {
valuetype: "object",
values: [
{
text: "San Francisco",
lang: "en",
id: "/m/0d6lp",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z"
}
],
count: 1
},
/common/image/size: {
valuetype: "compound",
values: [
{
text: "640.0 - 330.0 - Freebase Data Team - Rectangle Size",
lang: "en",
id: "/m/02bpzld",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z",
property: {
/measurement_unit/rect_size/x: {
valuetype: "float",
values: [
{
text: "640.0",
lang: "en",
value: 640,
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
},
/measurement_unit/rect_size/y: {
valuetype: "float",
values: [
{
text: "330.0",
lang: "en",
value: 330,
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
},
/type/object/attribution: {
valuetype: "object",
values: [
{
text: "Freebase Data Team",
lang: "en",
id: "/m/0220tm0",
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
},
/type/object/type: {
valuetype: "object",
values: [
{
text: "Rectangle Size",
lang: "en",
id: "/measurement_unit/rect_size",
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
}
}
}
],
count: 1
},
/common/licensed_object/license: {
valuetype: "object",
values: [
{
text: "CC-BY-2.5",
lang: "en",
id: "/m/01xrw11",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z"
}
],
count: 1
},
/common/topic/notable_for: {
valuetype: "object",
values: [
{
text: "Content",
lang: "en",
id: "/type/content"
}
],
count: 1
},
/common/topic/notable_types: {
valuetype: "object",
values: [
{
text: "Content",
lang: "en",
id: "/type/content",
timestamp: "2013-05-17T00:04:43.942Z"
}
],
count: 1
},
/type/content/blob_id: {
valuetype: "string",
values: [
{
text: "8debf723b25edb43b413bcb2890c4f4fe6ec5e5b2c7ce9c7e1f2aee273b0d0fe",
lang: "",
value: "8debf723b25edb43b413bcb2890c4f4fe6ec5e5b2c7ce9c7e1f2aee273b0d0fe",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/content/length: {
valuetype: "int",
values: [
{
text: "47162",
lang: "en",
value: 47162,
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/content/media_type: {
valuetype: "object",
values: [
{
text: "image/jpeg",
lang: "en",
id: "/m/08x8",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/attribution: {
valuetype: "object",
values: [
{
text: "Freebase Staff",
lang: "en",
id: "/m/05g",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/mid: {
valuetype: "key",
values: [
{
text: "/m/04j74yh",
lang: "",
value: "/m/04j74yh"
}
],
count: 1
},
/type/object/name: {
valuetype: "string",
values: [
{
text: "San Francisco Skyline",
lang: "en",
value: "San Francisco Skyline",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:42:34.000Z"
}
],
count: 1
},
/type/object/type: {
valuetype: "object",
values: [
{
text: "Image",
lang: "en",
id: "/common/image",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
},
{
text: "Content",
lang: "en",
id: "/type/content",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 2
},
/type/object/guid: {
valuetype: "string",
values: [
{
text: "#9202a8c04000641f80000000090393af",
lang: "",
value: "#9202a8c04000641f80000000090393af"
}
],
count: 1
},
/type/object/creator: {
valuetype: "object",
values: [
{
text: "content_administrator",
lang: "",
id: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/timestamp: {
valuetype: "datetime",
values: [
{
text: "2008-09-01T13:37:20.000Z",
lang: "en",
value: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/permission: {
valuetype: "object",
values: [
{
text: "/boot/all_permission",
lang: "",
id: "/boot/all_permission"
}
],
count: 1
}
}
}
It's kind of buried in the documentation since it doesn't have a section of its own, but is instead referenced from the Topic API documentation, but you can find the necessary info here
URLs are of the form:
https://usercontent.googleapis.com/freebase/v1/image/<image ID>
Related
I have a Model named Ad and it has a JSONfield named location_details.
while fetching the list of objects from Ad Model, I am applying filter for the location_details field
http://127.0.0.1:8000/ad-list/?limit=10&offset=0&ordering=-start_date&location_category=bus_station%2Chospital
While creating an ad, I compute the nearby places and store it as a JSON field as shown below
[ { name: "transit", label: "Transit", sub_categories: [ { name: "bus_station", label: "Bus Stop", values: [{name: 'A'}, {name: 'B'}], }, { name: "airport", label: "Airport", values: [], }, { name: "train_station", label: "Train Station", values: [], }, ], }, { name: "essentials", label: "Essentials", sub_categories: [ { name: "hospital", label: "Hospital", values: [{name: 'te'}], }, { name: "school", label: "Schools", values: [{name: 'B'}], }, { name: "atm", label: "ATMs", values: [], }, { name: "gas_station", label: "Gas Stations", values: [{name: 'C'}], }, { name: "university", label: "Universities", values: [], }, ], }, { name: "utility", label: "Utility", sub_categories: [ { name: "movie_theater", label: "Movie Theater", values: [], }, { name: "shopping_mall", label: "Shopping Mall", values: [], }, ], }, ];
I want to filter the ad list with multiple location_categories with the above JSON object, only if the location category has some data in it.
I don't know how to start with it, this is how my code looks like now
location_category = django_filters.CharFilter(method="filter_location_category")
def filter_location_category(self, queryset, name, value):
return queryset.filter(location_details__sub_categories__name__in=value.split(","))
For example, with the below request
http://127.0.0.1:8000/ad-list/?limit=10&offset=0&ordering=-start_date&location_category=bus_station%2Chospital
I want to get all the ads where bus_station and hospital have some data in it (inside the values key) and want to ignore it if the values list is empty in the JSON.
Any help would be highly appreciated. Thank you so much for your attention and participation.
I have modeled this:
type FreightDriver
#model
#key(
name: "byCityByState"
fields: ["state", "city"]
queryField: "freightDriversByStateByCity"
) {
id: ID!
name: String!
state: String!
city: String!
trucks: [Truck] #connection(keyName: "byFreightDriver", fields: ["id"])
}
type Truck
#model
#key(name: "byFreightDriver", fields: ["freightDriverId", "tons"]) {
id: ID!
freightDriverId: ID!
boxId: ID!
brand: String!
model: String!
tons: Float!
box: Box #connection(fields: ["boxId"])
}
type Box #model {
id: ID!
type: String!
width: Float!
height: Float!
depth: Float!
}
And I'm querying the data like this:
query {
freightDriversByStateByCity(state: "Jalisco", city: { eq: "Guadalajara" }) {
items {
id
name
city
state
trucks(tons: { eq: 12 }) {
items {
brand
model
box {
type
}
}
}
}
}
}
And I'm getting as a response this:
{
"data": {
"freightDriversByStateByCity": {
"items": [
{
"id": "aebb6696-573d-41ed-894e-22b69264cace",
"name": "Diey",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"box": {
"type": "Refrigerada"
}
}
]
}
},
{
"id": "6e8e6772-61e7-47d6-b134-d615a3c65f62",
"name": "Roberto Mendez",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"id": "d314808c-64e7-421d-b83b-008177ab6b25",
"name": "Roberto Mendez",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"id": "19847d0c-185c-48f6-9e5c-435e3907133a",
"name": "Andrés",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "1234",
"box": {
"type": "Refrigerada"
}
},
{
"brand": "chevrolet",
"model": "1234",
"box": {
"type": "Grúa"
}
},
{
"brand": "chevrolet",
"model": "12",
"box": {
"type": "Refrigerada"
}
}
]
}
},
{
"id": "2c4c9e3a-bfe5-4d4e-bee7-3eddb1b8ef1b",
"name": "Roberto Mendez ",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": []
}
},
{
"id": "cb4eb22c-aa54-416e-aecc-305a18bc9c83",
"name": "Roberto Mendez",
"city": "Guadalajara",
"state": "Jalisco",
"trucks": {
"items": []
}
}
]
}
}
}
If you check, there are some with this:
"trucks": {
"items": []
}
How can I avoid them? Is my model wrongly model? Thank you!
You can use mapping templates to modify the response data before it is returned to the client:
The response mapping template is written with the Apache Velocity templating language (VTL) and translates the results of the resolver back into GraphQL.
In this case you could check if trucks.items is empty and, if so, remove the items array from trucks before it's returned.
More details here: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-programming-guide.html
I installed web3 to link Solidity to React-native. As in the code below, I deployed it from Remix and entered the address and ABI.
import Web3 from "web3";
const web3 = new Web3(
new Web3.providers.HttpProvider("https://127.0.0.1:8545")
);
const address = "0x6cc33e32853a7fb0ac9ac2fb0d54cb56e4fb0f30";
const abi = [
{
constant: false,
inputs: [
{
name: "_MASTER",
type: "address"
},
{
name: "_sitter",
type: "address"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "CompleteSharePet",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_OWNER",
type: "address"
},
{
name: "_ownersharetext",
type: "string"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "OwnerShareText",
outputs: [
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_ownerseller",
type: "address"
},
{
name: "_petsitter",
type: "address"
},
{
name: "_MASTER",
type: "address"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "PetChange",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_PETSITTER",
type: "address"
},
{
name: "_master",
type: "address"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "PetChangeTransaction",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_petsittertext",
type: "string"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "PetSitterShareText",
outputs: [
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_sitter",
type: "address"
}
],
name: "testsitter",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_master",
type: "address"
},
{
name: "_OWNER",
type: "address"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "TransactionSharePet",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "hash",
type: "string"
},
{
name: "ipfs",
type: "string"
}
],
name: "uploadImage",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "AllOwnerCount",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "AllPetSitter",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "getOwnerAddresses",
outputs: [
{
name: "",
type: "address[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_owner",
type: "address"
}
],
name: "getOwnerInfo",
outputs: [
{
name: "",
type: "string"
},
{
name: "",
type: "string"
},
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "getPetSitterAddresses",
outputs: [
{
name: "",
type: "address[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_petsitter",
type: "address"
}
],
name: "getPetSitterInfo",
outputs: [
{
name: "",
type: "string"
},
{
name: "",
type: "string"
},
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "OwnerAddresses",
outputs: [
{
name: "",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "PetSitterAddresses",
outputs: [
{
name: "",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_OWNER",
type: "address"
}
],
name: "test",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_MASTER",
type: "address"
}
],
name: "test2",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
}
];
export class WalletSetting extends Component {
test() {
web3.eth.getAccounts().then(console.log);
}
render() {
return this.test;
}
}
export default (myContract = new web3.eth.Contract(abi, address));
The setting was error-free, but the error occurred when import was made to use mycontact
import WalletSetting from "../web3";
.
.
.
</TouchableOpacity>
<WalletSetting />
</LinearGradient>
Error Image
I deleted all the node_modules and all the cache, just like the way in the picture. However, the same error occurred.
I downloaded the web3 version as "^1.0.0-beta.34" to resolve the existing error, but another error occurred.
Error is
Unable to resolve module crypto from /Users/lucky/pettest/node_modules/web3-eth-accounts/src/index.js: Module crypto does not exist in the Haste module map
So I went to Google for reference https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766
And install "node-libs-browser": "^2.2.0", "babelpresetes2015":"^6.24.1",
and create a file called rn-cli.config.js, global.js and import the globaljs file into your web3.js file, but the error was the same.
How can I fix this?
https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766
This linked solution will not solve my problem.
web3 was made to work in a browser environment. The native android environment is different than that of a browser, for example, it doesn't have the crypto class that web3 uses. Using web3 with react native will require some extra configuration. You can follow this guide: https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766.
Also you can find a boilerplate here: https://github.com/dougbacelar/react-native-web3
I have a solution to part of your problem, regarding crypto. Install react-native-crypto and save it as a dependency, then babel-plugin-module-resolver as a dev-dependency, and put a .babelrc file in your project root that contains something like this:
{
"plugins": [
["module-resolver", {
"root": ["."],
"alias": {
"crypto": "react-native-crypto"
}
}]
]
}
This replaces any require('crypto') in your installed packages with require('react-native-crypto'), and it worked for me. In my case however, the same package I had that was missing crypto is also missing http so I came to this thread to hopefully find a polyfill for that too. I am on RN v0.60.3, npm v6.9.0, and node v10.16.0 for anyone interested. Also the package I needed this 'shim' for is the request package, which seems to be a sub-sub-sub-sub-dependency of jest. (npm list request).
I hope this helps somebody!
I found this solution here: https://stackoverflow.com/a/46605706/12375465
and here: https://medium.com/studioarmix/the-joy-of-joi-hacking-node-deps-1337fd5e586f
I'm working on a Sencha Touch App. This App have 3 lists: clients, tasks and asignations. Each one has its own model and store. The 3rd one, asignations lists, is an asignations of a task to a client, so that list must show which task and client are asignated.
Models
Ext.define('TasksApp.model.Asignation',{
extend: 'Ext.data.Model',
config: {
idProperty: 'id',
fields: [
{name: 'asignID'},
{name: 'nombreasignacion', type: 'string'},
{name: 'clienteasignacion', type: 'string'},
{name: 'tareaasignacion', type: 'string'},
{name: 'finasignacion', type: 'date'},
{name: 'obsasignacion', type: 'string'},
{name: 'recordatorio', type: 'string'},
{name: 'estadoasignacion', type: 'string'}
],
}
});
Ext.define('TasksApp.model.Client',{
extend: 'Ext.data.Model',
config: {
idProperty: 'id',
fields: [
{name: 'clientID'},
{name: 'nombrecliente', type: 'string'},
{name: 'obscliente', type: 'string'},
{name: 'tlfcliente', type: 'int'},
{name: 'emailcliente', type: 'string'},
{name: 'urlcliente', type: 'string'},
{name: 'asigncliente', type: 'int', defaultValue: 0}
],
}
});
Ext.define('TasksApp.model.Task',{
extend: 'Ext.data.Model',
config:
{
idProperty: 'id',
fields: [
{name: 'tareaID'},
{name: 'nombretarea', type: 'string'},
{name: 'descripciontarea', type: 'string'},
{name: 'tdesarrollotarea', type: 'int'},
{name: 'asigntarea', type: 'int', defaultValue: 0}
],
}
});
Asignations List View + Asignation Template
var plantillaAsignacion = new Ext.XTemplate(
'<tpl for=".">',
'<div class="tplAsignacion">',
'<div class="asignacionCabecera">',
'<DIV ALIGN=center><B><I>{nombreasignacion}</i></B></DIV>',
'</div>',
'<div class="clienteCuerpo">',
'<div class="asignacionImagen" style= "float: left;"><img src="resources/images/asign_icon.png"/></div>',
'<ol>',
'<li><pre> Cliente: {clienteasignacion}</a></pre></li>',
'<li><pre> Tarea: {tareaasignacion}</pre></li>',
'<li><pre> Finalización: {finasignacion:date("d/m/Y")}<div align="right">Estado: {estadoasignacion} <span class="status {estadoasignacion}"></span> </pre></li>', //("l, F d, Y")("d/m/Y")
'</ol>',
'</div>',
'</div>',
'</tpl>'
);
Ext.define('TasksApp.view.AsignationsList', {
extend: 'Ext.Container',
requires: [ 'Ext.TitleBar', 'Ext.dataview.List' ],
alias: 'widget.asignationslistview',
config: {
layout: {
type: 'fit',
},
items:
[
{
xtype: 'titlebar',
title: 'Lista de asignaciones',
docked: 'top',
items:
[
{
xtype: 'button',
iconCls: 'add',
ui: 'action',
itemId: 'newButton',
align: 'right'
},{
xtype: 'button',
text: 'Clientes',
ui: 'action',
itemId: 'goToClients', iconCls: 'team',
align: 'left'
},
{
xtype: 'button',
text: 'Tareas',
ui: 'action',
itemId: 'goToTasks', iconCls: 'bookmarks',
align: 'left'
},
]
},
{
xtype: 'list',
store: 'Asignations',
itemId: 'asignationsList',
cls: 'estado-asignacion',
loadingText: 'Cargando Asignaciones...',
emptyText: 'No hay asignaciones actualmente',
onItemDisclosure: true,
//grouped: true,
itemTpl: plantillaAsignacion,
}
],
listeners:
[
{
delegate: '#newButton',
event: 'tap',
fn: 'onNewButtonTap'
},
{
delegate: '#asignationsList',
event: 'disclose',
fn: 'onAsignationsListDisclose'
},
{
delegate: '#goToClients',
event: 'tap',
fn: 'onGoToClients'
},
{
delegate: '#goToTasks',
event: 'tap',
fn: 'onGoToTasks'
}
]
},
onNewButtonTap: function () {
console.log('newAsignationCommand');
this.fireEvent('newAsignationCommand', this);
},
onAsignationsListDisclose: function (list, record, target, index, evt, options) {
console.log('editAsignationCommand');
this.fireEvent('editAsignationCommand', this, record);
},
onGoToClients: function () {
console.log ('goToClientsCommand');
this.fireEvent('goToClientsCommand', this);
},
onGoToTasks: function () {
console.log ('goToTasksCommand');
this.fireEvent('goToTasksCommand', this);
}
});
Asignation Editor View ( form of the asignation )
Ext.define('TasksApp.view.AsignationEditor', {
extend: 'Ext.form.Panel',
requires: [
'Ext.TitleBar', 'Ext.form.FieldSet', 'Ext.field.Text','Ext.field.Select', 'Ext.field.DatePicker', 'Ext.field.TextArea','Ext.form.Panel'
],
alias: 'widget.asignationeditorview',
config: {
scrollable: 'vertical',
items:
[
{
xtype: 'titlebar',
docked: 'top',
title: 'Editar Asignación',
items:
[
{
xtype: 'button',
ui: 'back',
text: 'Volver',
itemId: 'backButton',
align: 'left'
},
{
xtype: 'button',
ui: 'action',
text: 'Guardar',
itemId: 'saveButton',
align: 'right'
}
]
},
{
xtype: 'toolbar',
docked: 'bottom',
items: [
{
xtype: 'button',
iconCls: 'trash',
iconMask: true,
itemId: 'deleteButton'
}
]
},
{
xtype: 'fieldset',
items:
[
{
xtype: 'textfield',
name: 'nombreasignacion',
label: 'Nombre',
required: true,
autoCapitalize: true,
placeHolder: 'Nombre de la asignación...'
},
{
xtype: 'selectfield',
name: 'clienteasignacion',
label: 'Cliente',
valueField: 'clientID',
displayField: 'nombrecliente',
store: 'Clients',
autoSelect: false,
placeHolder: 'Seleccione un cliente...',
required: true,
},
{
xtype: 'selectfield',
name: 'tareaasignacion',
label: 'Tarea',
valueField: 'tareaID',
displayField: 'nombretarea',
store: 'Tasks',
autoSelect: false,
placeHolder: 'Seleccione una tarea...',
required: true,
},
{
xtype: 'datepickerfield',
name: 'finasignacion',
label: 'Vencimiento',
dateFormat: 'd/m/Y',
value: (new Date()),
picker:
{
yearFrom: new Date().getFullYear(),
yearTo: 2040,
slotOrder: [ 'day', 'month', 'year' ]
}
},
{
xtype: 'textareafield',
name: 'obsasignacion',
label: 'Observaciones',
autoCapitalize: true,
autoCorrect: true,
placeHolder: 'Observaciones de la asignación...',
maxRows: 5
},
{
xtype: 'selectfield',
name: 'recordatorio',
label: 'Recordatorio',
autoSelect: true,
placeHolder: 'Seleccione el método recordatorio...',
required: true,
options:
[
{
text: 'Ninguno',
value: 0
},
{
text: 'eMail',
value: 2
},
{
text: 'SMS',
value: 1
},
{
text: 'Notificación',
value: 3
}
]
},
{
xtype: 'selectfield',
name: 'estadoasignacion',
label: 'Estado',
autoSelect: true,
placeHolder: 'Seleccione el estado...',
required: true,
options:
[
{
text: 'Activa',
value: 'Activa'
},
{
text: 'Caducada',
value: 'Caducada'
},
{
text: 'Cancelada',
value: 'Cancelada'
},
{
text: 'Realizada',
value: 'Realizada'
}
]
},
]
}
],
listeners: [
{
delegate: '#saveButton',
event: 'tap',
fn: 'onSaveButtonTap'
},
{
delegate: '#deleteButton',
event: 'tap',
fn: 'onDeleteButtonTap'
},
{
delegate: '#backButton',
event: 'tap',
fn: 'onBackButtonTap'
}
]
},
onSaveButtonTap: function () {
console.log('saveAsignationCommand');
this.fireEvent('saveAsignationCommand', this);
},
onDeleteButtonTap: function () {
console.log('deleteAsignationCommand');
this.fireEvent('deleteAsignationCommand', this);
},
onBackButtonTap: function () {
console.log('backToHomeCommand');
this.fireEvent('backToHomeCommand', this);
}
});
Asignation Controller
Ext.define('TasksApp.controller.Asignations', {
extend: 'Ext.app.Controller',
config: {
refs: {
asignationsListView: 'asignationslistview',
asignationEditorView: 'asignationeditorview'
},
control: {
asignationsListView: {
newAsignationCommand: 'onNewAsignationCommand',
editAsignationCommand: 'onEditAsignationCommand'
},
asignationEditorView: {
saveAsignationCommand: 'onSaveAsignationCommand',
deleteAsignationCommand: 'onDeleteAsignationCommand',
backToHomeCommand: 'onBackToHomeCommand'
}
}
},
getSlideLeftTransition: function () {
return { type: 'slide', direction: 'left' };
},
getSlideRightTransition: function () {
return { type: 'slide', direction: 'right' };
},
getRandomInt: function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
activateAsignationEditor: function (record) {
var asignationEditorView = this.getAsignationEditorView();
asignationEditorView.setRecord(record); // load() is deprecated.
Ext.Viewport.animateActiveItem(asignationEditorView, this.getSlideLeftTransition());
},
activateAsignationsList: function () {
Ext.Viewport.animateActiveItem(this.getAsignationsListView(), this.getSlideRightTransition());
},
onNewAsignationCommand: function () {
console.log('onNewAsignationCommand');
var now = new Date();
var asignationId = (now.getTime()).toString() + (this.getRandomInt(0, 100)).toString();
var newAsignation = Ext.create('TasksApp.model.Asignation', {
id: asignationId,
nombreasignacion: '',
clienteasignacion: '',
tareaasignacion: '',
finasignacion: '',
obsasignacion: '',
recordatorio: '',
estadoasignacion: ''
});
this.activateAsignationEditor(newAsignation);
},
onEditAsignationCommand: function (list, record) {
console.log('onEditAsignationCommand');
this.activateAsignationEditor(record);
},
onSaveAsignationCommand: function () {
console.log('onSaveAsignationCommand');
var asignationEditorView = this.getAsignationEditorView();
var currentAsignation = asignationEditorView.getRecord();
var newValues = asignationEditorView.getValues();
currentAsignation.set('nombreasignacion', newValues.nombreasignacion);
currentAsignation.set('clienteasignacion.nombrecliente', newValues.clienteasignacion);
currentAsignation.set('tareaasignacion.nombretarea', newValues.tareaasignacion);
currentAsignation.set('finasignacion', newValues.finasignacion);
currentAsignation.set('obsasignacion', newValues.obsasignacion);
currentAsignation.set('recordatorio', newValues.recordatorio);
currentAsignation.set('estadoasignacion', newValues.estadoasignacion);
var asignationsStore = Ext.getStore('Asignations');
if (null == asignationsStore.findRecord('id', currentAsignation.data.id)) {
asignationsStore.add(currentAsignation);
}
asignationsStore.sync();
asignationsStore.sort([{ property: 'dateCreated', direction: 'DESC'}]);
this.activateAsignationsList();
},
onDeleteAsignationCommand: function () {
console.log('onDeleteAsignationCommand');
var asignationEditorView = this.getAsignationEditorView();
var currentAsignation = asignationEditorView.getRecord();
var asignationsStore = Ext.getStore('Asignations');
asignationsStore.remove(currentAsignation);
asignationsStore.sync();
this.activateAsignationsList();
},
onBackToHomeCommand: function () {
console.log('onBackToHomeCommand');
this.activateAsignationsList();
},
launch: function () {
this.callParent(arguments);
var asignationsStore = Ext.getStore('Asignations');
asignationsStore.load();
console.log('launch');
},
init: function () {
this.callParent(arguments);
console.log('init');
}
});
I want the asignations list to show the client name ( nombrecliente ) and the task name ( nombretarea ), but it shows nothing at all. I don't know how to refer to this values so the list shows them. I tried to modify the asignations controller, the selectfield int the asignation editor ( form ) and the asignations template, but I simply don't know how this works and what I have to do to show that values ( if they are saved in the asignations store at this moment via selectfield, or am I doing anything wrong? )
I would appreciate any help. Thank you in advance.
PS: sorry for my English, it's not my native language :)
Please create array in the key value pair with the key name as your model field and then set that data into your asign Asignations store like:
Asignations.setdata({fieldName:"value"});
I have 3 emberData models:
App.Product = DS.Model.extend({
page_title: DS.attr('string'),
shop: DS.belongsTo('App.Shop'),
user: DS.belongsTo('App.User')
});
App.Shop = DS.Model.extend({
name: DS.attr('string'),
});
App.User = DS.Model.extend({
name: DS.attr('string')
});
and the JSON data looks like this:
{
products: [
{
id: "1",
page_title: "Product 1",
user_id: "1",
shop_id: "1",
},
{
id: "2",
page_title: "Product 2",
user_id: "2",
shop_id: "1",
}
],
users: [
{
id: "1",
name: "User 1"
},
{
id: "2",
name: "User 2"
}
],
shops: [
{
id: "1",
name: "Shop 1"
}
]
}
But when I load the data I got the following error:
Assertion failed: Your server returned a hash with the key shops but you have no mapping for it
Ok, the documentaion is very unclear about the fact that when you have a belongsTo relationship the key for the sideload must be singular not plural even if its a list. So the JSON has to look like this:
{
products: [
{
id: "1",
page_title: "Product 1",
user_id: "1",
shop_id: "1",
},
{
id: "2",
page_title: "Product 2",
user_id: "2",
shop_id: "1",
}
],
user: [
{
id: "1",
name: "User 1"
},
{
id: "2",
name: "User 2"
}
],
shop: [
{
id: "1",
name: "Shop 1"
}
]
}