mardi 4 octobre 2016

CSS broken after ember init?

I recently changed my project name using ember init (after I made the changes in the config/environment.js, and package.json file).

Unfortunately when I ember serve now it's says it gives me 404 errors when I try accessing the site.




Ember open new window avoiding pop-up blocker in a successful promise

I am struggling to find a way to open a new window inside a then() promise after creating a store record and persisting.

The following code is blocked by chrome's pop-up blocker

var obj = this.get('store').createRecord('user', {
  first_name: 'John',
  last_name: 'Smith'
});

obj.save()
  .then(function (user) {
    window.open('http://google.com', '_blank'); // this is blocked by chrome pop-up blocker
  })
  .catch(function (error) {
    this.set('errors', error.errorArray); // display errors in the template
  });

This code works and bypasses the pop-up blocker but my problem is that if the backend throws errors during save, I don't want to open the new window since in the end the user was not successfully created and I want them to still be on the main window where they can see the error. I can close the window if I get errors but that does not feel right since it will look like a flicker of opening and closing the window immediately.

var window_handle = window.open('', '_blank');

var obj = this.get('store').createRecord('user', {
  first_name: 'John',
  last_name: 'Smith'
});

obj.save()
  .then(function (user) {
    window_handle.location.href = 'http://google.com'; // this is NOT blocked by chrome pop-up blocker
  })
  .catch(function (error) {
    this.set('errors', error.errorArray); // display errors in the template
  });

Does anyone have a better idea?




How to request x amount of objects from server?

How would I go about requesting a limited amount of objects from the server in ember? I have

import Ember from 'ember';

export default Ember.Route.extend({
  model(){
    return this.store.findAll('game');
  }
});

currently as my route. But say I only want to get the last 10 games?




Ember log every click

I would like to log every click (whether that is through transitions, views, auto generations, ect ...) in some datastore for later analysis.

I realize this is probably a deal breaker for using ember as there are a lot of these activities that do not depend on a server side api call, so there will be no record on the server of a link clicked that transitions to another page.

However, that app I wish to analyze is already created in ember, thus my post.

I am aware of the following attributes that can be added the Ember.Application:

LOG_TRANSITIONS: true,
LOG_VIEW_LOOKUPS: true,
LOG_ACTIVE_GENERATION: true

They produce helpful information. However, I do not know how to capture the output that it generates in the console and put it in variables for use later; possibly to send to a datastore each time a click happens, or perhaps to accumulate and then send based on some threshold. I realize this may affect the performance of the app.

Any help would be greatly appreciated.




Handling Ember model error w/ JSONAPI

This has been answer for the MOST part here: Handling errors with the (now default) Ember Data JSON-API adapter

I won't even go into how Ember docs stress to follow JSON API specs (http://ift.tt/17ykFBl), yet as far as I've read they don't even adhere to them (based off the answer linked to above)... but I digress!

I am not sure how to get errors into my model from the model() hook itself.

For example:

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
        return this.get('store').findAll('page').catch(function(){});
    }
});

I am unable to access the errors in my template as such:


    <div class="error msg_animate">}</div>


I know I am missing a key factor here. Anyone able to point me in the right direction?




In Ember, how can I find out the exact URL a call like store.query will hit?

When debugging my API, I want to know, for a given line of code

store.query('foo', {filter: ...})

exactly what URL this causes Ember to hit. Currently, to find this out, I just open devtools and look for the request in the network tab.

This isn't ideal because: * it's harder to find the relevant network request if there are a lot of them * I have to do a whole refresh and wait for the page to load

Is there a better way, maybe a programmatic one using a low-level API? I'm looking for something like:

store.buildRequest('query', 'foo', {filter: ...}).url()




spring boot pagination with ember data

Hi I want to create a pagination for my application for that i am using spring-boot Pagination and ember-cli-pagination. Before using spring-boot pagination, rest controller returns data in the following format,

[{
"id" : 56789,
"name" : "sample book",
"status": "available",
},{
"id" : 56789,
"name" : "sample book",
"status": "available",
}]

after using spring-pagination my rest controller returns data in the format,

{
"content": 
[{
"id" : 56789,
"name" : "sample book",
"status": "available",
},{
"id" : 56789,
"name" : "sample book",
"status": "available",
}],
"last": true,
"totalElements": 5,
"totalPages": 2,
"size": 3,
"number": 1,
"sort": null,
"first": false,
"numberOfElements": 2
}

Now the structure of the data completely changes so i need to modify my ember model so that ember data will properly serialize my data.

Is there any other way to apply spring-boot-pagination to ember data with minimal changes?Any standard or guided way to do that?

Do i really need to change my ember model?

Ember Model :

export default DS.Model.extend({
   id: DS.attr(),
   name: DS.attr(),
   status: DS.attr()
});

Any help should be appreciable.