postNotification expecting an OSNotification object that contains irrelevant fields - ionic2

I am using Ionic 2 with the OneSignal native plugin.
I am trying to use the postNotification function but I can not compile my code:
let notificationObj = {
contents: { en: content },
headings: { en: title },
include_player_ids: [playerIds],
ios_badgeType: 'Increase',
ios_badgeCount: 1
};
return this.oneSignal.postNotification(notificationObj);
The error tells me that my OSNotification is missing fields such as isAppInFocus, shown, etc.
But this looks like what would be expected when you handle a notificationReceived not when sending it has I cannot know in advance these values... any clue?

Related

Prettier formatting a Vue component when I don't want it to

I've got Prettier configured to format on save.
I'm using a Vue component I got from npm to display data from an API.
<ExampleComponent
:aDynamicProp="foo"
dataset="bar"
/>
The prop dataset is required by the component.
The issue is Prettier wants to change dataset to data-set every time I save. I imagine because it thinks i'm trying to create a HTML data attribute.
As per Prettier docs i've tried adding <!-- prettier-ignore-attribute --> above the component but this doesn't seem to work (perhaps because I'm triggering formatting on save, or because it's a Vue template and not HTML?).
Can anyone shed light as to how I can force Prettier to ignore the prop?
Many thanks!
Add colon : to :dataset and that should do the trick, if it's just static string that's doing inside dataset then do :dataset="`my string`" with backtick (`). If you are getting data from data(){}, computed or from methods as mentioned below then just do :dataset="yourData":
export default {
data() {
return {
yourData: 'Your String'
}
},
// or
computed: {
yourData() {
return 'Your String'
},
},
// or
methods: {
yourData() {
return 'Your String'
},
},
};

Ionic2: invalid page component: ProjectInfoPage

export class ProjectDetail {
page: string;
}
the page info contained in json, like this:
{
"data":[
{
page: "PageInfoPage"
},
{
page: "PageInfoPage1"
}
]
}
I parse info from this json,then saved in Array.
when execute this.nav.push(pd.page),throw exception as title described.I don't know how to convert 'string' to 'component'.
============================================================
I use the method like Angular 2 - Resolve Component Factory with a string described. This is my code:
itemClick(pd: ProjectDetail) {
var factories = Array.from(this.resolver['_factories'].keys());
var factoryClass = <Type<any>>factories.find((x: any) => x.name === pd.page);
const factory = this.resolver.resolveComponentFactory(factoryClass);
const compRef = this.vcRef.createComponent(factory);
if (this.componentRef) {
this.componentRef.destroy();
}
this.componentRef = compRef;
this.nav.push(compRef, {
item: pd,
pid: this.project.pid
});
}
it still does not work.Thank you for your answer.
At last,I solved it with a stupid method.As I create a map like this:
componentRegistry = {
'ProjectInfoPage': ProjectInfoPage
};
And then push like this:
this.nav.push(this.componentRegistry[pd.page], {
item: pd,
pid: this.project.pid
});
Normally, you have to import the actual component class for the page that you want to navigate to and then push that class onto the stack. By default, there is no way built into ionic2 to navigate via string references. I had the same problem today where I wanted to be able to navigate using strings rather than pushing the component class on the stack.
Check out the following link from the ionic forums on how to accomplish this. Look at the last two responses to the thread, which include how to solve this problem from beta stages and then an updated answer for how to do so with ionic 2.2.0. Although I'm pretty sure the same solution will work for all versions of ionic 2 since final release.
https://forum.ionicframework.com/t/ionic2-navigation-circular-depencies/41123/5

Sublimelinter & JSHint complaining about Facebook's Open Graph objects {og:url: "example.com"}

I'm using JSHint and SublimeLinter with Sublime Text 3, but when using Facebooks API it doesnt like the object double : in the structure, eg. { og:url: 'example.com' }
FB.api(
'me/objects/my-app:object',
'post',
{
og:url: http://samples.ogp.me/12345678910,
og:title: Sample Object,
og:type: my-app:object,
og:image: https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png,
og:description: ,
fb:app_id: 12345678910,
place:location:latitude: Sample Location: Latitude,
place:location:longitude: Sample Location: Longitude
},
function(response) {
// handle the response
}
);
I know how to ignore certain variables and names in the .jshintrc file on the root of my project, but not sure how to stop it complaining about this structure. I thought since the Facebook API is popular it's worth posting it here.
Wrap them in quotes.
eg. { 'og:url': 'example.com' }

How to load RubyMotion table view cell data from file

I'm getting started with RubyMotion and ProMotion. I'm building a table view and I would like to move the data out into an external file to make it easier to manage. Here's what I have so far:
class MasterScreen < PM::TableScreen
title 'States'
def table_data
[{
title: "Northwest States",
cells: [
{ title: "Oregon", action: :view_details, arguments: { state: #oregon }},
{ title: "Washington", action: :view_details, arguments: { state: #washington }}
]
}]
end
def view_details
open DetailScreen.new(nav_bar: true)
end
end
I'd like to move the names of the states (basically the cell titles) into something like a YAML or JSON file that I can load and iterate over. How can I achieve something like this?
Update: I managed to figure out how to load text from a file.
First I added bubble-wrap to my Gemfile and ran bundle install. BubbleWrap provides the helper method App.resources_path.
In my_app/resources/states.txt I have a list of states, separated by new lines:
Oregon
Washington
Foobar
In my Table View Controller, I read the file and split the file into an array of lines.
class MasterScreen < PM::TableScreen
title 'States'
def on_load
data = File.read("#{App.resources_path}/states.txt")
#states = data.lines
end
def table_data
[{
title: "Northwest States",
cells: #states.map do |state|
{
title: state,
action: :view_details,
arguments: { state: state }
}
end
}]
end
def view_details(arguments)
open DetailScreen.new(nav_bar: true, title: arguments[:state])
end
end
This works, but it's only part of what I was trying to do. I would still like to use a structure like YAML to represent titles and subtitles. What would be the RubyMotion way to do this sort of thing?
Figured out how to do it. I came across a RubyMotion gem called motion-yaml. Simply add it to your Gemfile, add your YAML file to your resources directory, and use it like you would YAML in Ruby.
data = YAML.load(File.read("#{App.resources_path}/my_yaml_file.yml"))
Note: You will need to add bubble-wrap to your Gemfile in order to have the App.resources_path. I'm not sure if there is an easy way to do it without bubble-wrap.

jqgrid dropdown select editoptions

I am trying to use the edittype:"select", formatter:"select" and editoptions:{values:'1:Type1;2:Type2'} in my colModel
colModel : [
{name:'pk', index:'pk', width:20, sortable:true, jsonmap:'pk',
sorttype:'integer'},
{name:'id', index:'id', align:'left', jsonmap:'fields.id',
sortable:true, editable:true, edittype:'select', formatter:'select',
editoptions:{value:'1:value1;2:value2;3:value3'},
{name:'type', index:'type', width:100,align:'center',
jsonmap:'fields.type', sortable:true,editable:true}
]
but the value for id returned in the json object is not a string (it doesn't have quotes around it). If I remove the edittype and editoptions the id value appears in the column of the grid but when I include the edittype, formatter and editoptions in the colMode definition I get the javascript error
(E||"").replace is not a function
The json object that fails looks like
{ "pk": 120
"model": "myModel"
"fields": {
"id": 1,
"type": "aType"
}
}
The id value has no quotes.
I am using the edittype, formatter and editoptions in other grids but the value I am macthing against is a character (in the json object it is surrounded by quotes) and it works perfectly.
I am only guessing that the problem is with the unquoted number but I am not sure. Has anyone seen this before?
Regards
Andrew
Ok,
I found that the problm is on line 1067 of the jquery.1.3.2 file. It is the trim function and the code looks like this:
trim:function(text) {
return (text||"").replace(/^\s+|\s+$/g, "")
}
I changed it to this:
trim:function(E) {
return (text.toString()||"").replace(/^\s+|\s+$/g, "")
}
and now it works.
Can anyone tellme if this is a bug or is there something else I can do to overide ths function without changing the jquery file.
Function Override: Placed in the head of any page that shows this problem.
$.extend({
trim:function(E) {
return (text.toString()||"").replace(/^\s+|\s+$/g, "")
}
});
Thanks
Andrew