As I transition to my new route, I set the reportName property and I want to trigger an AJAX request based on changes in the reportname. The response from the AJAX call contains data that I need to pass to a graph component as a property, which should then trigger a function within the component. However, I am having trouble implementing this. Could you please advise me on what I might be doing wrong? I am new to Ember.
export default Ember.Controller.extend(ApplicationRouteMixin, {
sessionService: Ember.inject.service('session'),
nameOfReport: null,
postObject: function(){
return {
Name: this.get('nameOfReport'),
Take: 30,
Skip: 0,
};
}.property('nameOfReport'),
ajaxResponse: function(){
var restApiHost = serverPath + '/report';
var postobj= this.get('postObject');
var token =this.get('sessionService.session.authenticated.access_token');
Ember.$.ajax({
url: restApiHost,
type: 'POST',
data: JSON.stringify(postobj),
contentType: 'application/json; charset=utf-8',
dataType: "json",
beforeSend: function (xhr) {
var bearer = 'Bearer ' + token ;
xhr.setRequestHeader('Authorization', bearer);
xhr.setRequestHeader('Content-type', 'application/json');
},
success: function (data) {
var graphobj= {
data: data.data,
graphModel: GraphModel.create({
graphHeight: "320",
graphMargin: [40, 80, 40, 60],
xDomain: [1, 10],
yDomain: [1, 100]
…
})};
Ember.set(this,'graphobject', graphobj);
},
fail: function () {
alert('Could not contact server');
},
});
}.property('postObject'),
graphobject: function(){
this.get('ajaxResponse');
}.property('ajaxResponse'),
});
Pod Template:
<div>
{{line-graph model= graphobject }}
</div>
Component:
drawGraph: function() {
// define dimensions of graph
var graphdata = this.get('model.data');
var graphmodel = this.get('model.graphModel');
...
}.property('graphobject'),