Skip to content

Instantly share code, notes, and snippets.

@Mariusio
Created March 3, 2016 18:37
Show Gist options
  • Save Mariusio/f743c6d21e16d2ad8e79 to your computer and use it in GitHub Desktop.
Save Mariusio/f743c6d21e16d2ad8e79 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import ENV from 'zenline-frontend/config/environment';
export default Ember.Route.extend({
model: function(params) {
return new Promise((resolve, reject) => {
Em.$.ajax(ENV.api.host + '/dashboards/' + params["dashboard_share_token"] + "/public", {
type: 'GET', // HTTP method
dataType: 'JSON', // type of data expected from the API response
contentType: "application/json",
success: (data, textStatus, jqXHR) => {
this.store.pushPayload(data);
console.log(data);
var model = Ember.RSVP.hash({
dashboard: this.store.peekRecord('dashboard', parseInt(data.data["id"])),
reports: this.store.peekRecord('dashboard', parseInt(data.data["id"])).get('reports')
});
console.log("model");
console.log(model);
resolve(model);
},
error: (jqXHR, textStatus, errorThrown) => {
console.log("ajax error");
resolve(jqXHR);
}
});
}).then((model) => {
console.log("model");
console.log(model);
return model;
}, (error) => {
console.log("error");
console.log(error);
return error;
});
},
setupController(controller, model) {
console.log("model.dashboard");
console.log(model.dashboard);
console.log(model.dashboard == true);
if (model.dashboard) {
console.log(model);
console.log(model);
console.log(model.reports);
console.log(model.dashboard);
var reports = model.reports;
var dashboard = model.dashboard;
controller.set('dashboard', dashboard);
controller.set('reports', reports);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment