vendredi 31 mai 2019

EmberJS: overwriting ember-ajax error helper

I'm overwriting the isUnauthorizedError function of ember-ajax in order to invalidate the user's session, but only if the host of the request matches a specific host. However, I can't find a way to determine the host inside that function. Is there any way?

import AjaxService from 'ember-ajax/services/ajax';

export default AjaxService.extend({
   isUnauthorizedError(arg1, arg2, arg3) {
     // retrieve host
   }
});




Ember not setting hasMany relationship attribute after retrieving data

Foreward: There are a lot of firsts in this project, such as building my first API, first time using JSON API, first time using Ember, first time posting on SO, etc.

I'm trying to access an 'authors' hasMany attribute in my template containing the latest updates. What I access it in the template, however, nothing is returned. The models are being saved correctly, but the relationship is not being set it appears, as the length of the DS.PromiseManyArray on latest.contentAuthors is 0 while the promise is fulfilled ({ _length: 0, isFulfilled: true, isRejected: false }).

I'm using Ember 3.10 (with CLI). I have full control over my backend (LAMP running ExpressionEngine 5) and am serving API requests through a custom built plugin, though I'm not sure that matters to much as this seems to largely be a frontend problem from what I can discern.

Route

import Route from '@ember/routing/route';

export default Route.extend({
    model(){
        let latest = this.store.peekAll('latest');
        if (latest.length < 2){
            latest = this.store.query('latest', { limit: 2, include: "people" });
        }
        return latest;
    }
});

Base Model

import DS from 'ember-data';
const { Model } = DS;

export default Model.extend({
    title: DS.attr()
});

Latest Model

import DS from 'ember-data';
import ExpressionEngineBase from './expression-engine-base';

export default ExpressionEngineBase.extend({
    title: DS.attr(),
    blurb: DS.attr(),
    contentAuthors: DS.hasMany('person')
});

Person Model

import DS from 'ember-data';
import ExpressionEngineBase from './expression-engine-base';

export default ExpressionEngineBase.extend({
    title: DS.attr(),
    latest: DS.hasMany('latest')
});

Template


    <h2></h2>
    
        <div></div>
    
        <div>Can't find author(s)</div>
    
    <p></p>


Data sent from server

{
    "data": [{
        "id": 3161,
        "type": "latest",
        "attributes": {
            "title": "Amazing Video 1"
        },
        "links": {
            "self": "https:\/\/cms.example.com\/api\/v1\/video\/3161"
        },
        "relationships": {
            "people": {
                "data": [{
                    "id": 1,
                    "type": "people",
                    "links": {
                        "self": "https:\/\/cms.example.com\/api\/v1\/people\/1",
                        "channel": "https:\/\/cms.example.com\/api\/v1\/people"
                    }
                }]
            }
        }
    }, {
        "id": 2573,
        "type": "latest",
        "attributes": {
            "title": "Amazing Article 1"
        },
        "links": {
            "self": "https:\/\/cms.example.com\/api\/v1\/white_papers_insights\/2573"
        },
        "relationships": {
            "people": {
                "data": [{
                    "id": 1,
                    "type": "people",
                    "links": {
                        "self": "https:\/\/cms.example.com\/api\/v1\/people\/1",
                        "channel": "https:\/\/cms.example.com\/api\/v1\/people"
                    }
                }, {
                    "id": 52,
                    "type": "people",
                    "links": {
                        "self": "https:\/\/cms.example.com\/api\/v1\/people\/52",
                        "channel": "https:\/\/cms.example.com\/api\/v1\/people"
                    }
                }]
            }
        }
    }],
    "links": {
        "self": "https:\/\/cms.example.com\/api\/v1\/latest?include=people&limit=2"
    },
    "included": [{
        "id": 1,
        "type": "people",
        "links": {
            "self": "https:\/\/cms.example.com\/api\/v1\/people\/1",
            "channel": "https:\/\/cms.example.com\/api\/v1\/people"
        },
        "attributes": {
            "title": "Great Author"
        }
    }, {
        "id": 52,
        "type": "people",
        "links": {
            "self": "https:\/\/cms.example.com\/api\/v1\/people\/52",
            "channel": "https:\/\/cms.example.com\/api\/v1\/people"
        },
        "attributes": {
            "title": "Great Co-Author"
        }
    }]
}

To reiterate, the relationship model is saving and is viewable in Ember Inspector, but the actual link/relationship is not being set.




Ember : dedounce called multiple times on scroll event listener

I added a debounce method inside a scroll event listener. Something like this.

$group.on("scroll.topFix",() => {
   console.log('scroll event');
   debounce(this, ()=> {
     console.log('debounce called);
   },1000);
});

When I do the scroll on $group the debounce is also called the same number of times the scroll event called. I don't know where is the loophole in this thing.

For example, if 5 times the scroll event printed then debounce called is also called 5 times.

This is the link for ember debounce documentation.




jeudi 30 mai 2019

How to fix 'Webpack Returned Errors to ember-auto-import' Build Error in Ember.js

I have a problem build error like title of my topic, anyone can help me? error

Here's my package.json devDependencies: { "@ember/jquery": "^0.5.2", "@ember/optional-features": "^0.6.3", "broccoli-asset-rev": "^2.7.0", "ember-ajax": "^3.1.0", "ember-cached-shoe": "^0.2.0", "ember-cli": "^3.8.1", "ember-cli-app-version": "^3.2.0", "ember-cli-babel": "^6.16.0", "ember-cli-bundle-analyzer": "0.0.3", "ember-cli-concat": "^1.3.0", "ember-cli-dependency-checker": "^3.0.0", "ember-cli-eslint": "^4.2.3", "ember-cli-fastboot": "^2.0.0", "ember-cli-head": "^0.4.1", "ember-cli-htmlbars": "^3.0.0", "ember-cli-htmlbars-inline-precompile": "^1.0.3", "ember-cli-inject-live-reload": "^1.8.2", "ember-cli-less": "^1.5.5", "ember-cli-moment-shim": "^3.7.1", "ember-cli-qunit": "^4.3.2", "ember-cli-shims": "^1.2.0", "ember-cli-sri": "^2.1.1", "ember-cli-string-helpers": "^1.9.0", "ember-cli-template-lint": "^1.0.0-beta.1", "ember-cli-uglify": "^2.1.0", "ember-concurrency": "^0.8.19", "ember-data": "~3.4.0", "ember-export-application-global": "^2.0.0", "ember-font-awesome": "^4.0.0-rc.4", "ember-in-viewport": "^3.1.5", "ember-link-action": "^0.1.3", "ember-load-initializers": "^1.1.0", "ember-maybe-import-regenerator": "^0.1.6", "ember-moment": "^7.7.0", "ember-resolver": "^5.0.1", "ember-screen": "^1.0.0", "ember-service-worker": "^0.7.0", "ember-source": "~3.4.0", "ember-web-app": "^2.3.0", "eslint-plugin-ember": "^5.2.0", "loader.js": "^4.7.0", "qunit-dom": "^0.7.1" }

I’am using ember-cli: 3.10.1, node: 10.16.0, os: win32 x64.

Please someone help me, thanks.




How to prevent pasting text in ember input helper?

I'm using ember input helper to get some value in the application. The text field should not allow any text to be pasted. (Something like re-enter some value)

I've just tried



This didn't work. But in normal html, The following works.

<input value=inputText onpaste="return false">

But the problem here is no two-way binding (which supports in ember input helper).




merge function occuring error while executing the code

I have the javascript file which not validating the below ember js code:

helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
var buffer = '', stack1, escapeExpression=this.escapeExpression, self=this;

While I'm executing the above code, I'm getting this.merge is not a function. (Note: I'm upgrading ember from 1.4.0 to 1.12.2 and I'm using Handlebars 2.0.0). Please provide me the suggestion




mercredi 29 mai 2019

Is it possible to extract some files from ember static files?

There is a task to change translations dynamically. Admin should be able to rewrite language constants file. But that won't work till ember rebuild. Can I somehow extract lang files from the dist and use them like "outside of app"?

I guess I can place them on the server and try to load into the Ember app with each refresh. But maybe there is a more interesting way?