How to call a parse-cloud function in ember.js controller? - ember.js

I am working on a ember-cli app which fetch data from parse-cloud using ember-parse-adapter . It was working fine until recently i need to call a parse-cloud function in my ember controller. So, is there a way that i could use ember-parse-adapter to call parse-cloud function or any other approach to do that.

I don't know of a way with the ember-parse-adapter BUT:
You can make your own AJAX calls via jQuery $.ajax and the Parse REST API
You can use the npm package for Parse.
npm install parse
Go to node_modules/parse/build and copy parse-latest.js to your /vendor directory
Import into your app using Brocfile.js - app.import('vendor/parse-latest.js').
The Parse namespace and SDK are now available everywhere in your app.
Keep in mind both these approaches have security concerns as you will be making your API key available to anyone who inspects your app.

Related

Ember server does not serve dummy app while creating an addon

I am trying to write an Ember component addon. After complete the template structure I think it would be nice to see the layout inside the dummy application as a sanity test.
Follow the instruction below,
The Ember CLI uses a dummy app in tests/dummy for testing. In tests/dummy/app/templates/application.hbs you can put calls to both the helper and component. Then, with ember serve, you can navigate to localhost:4200 to ensure that everything is working as expected.
http://johnotander.com/ember/2014/12/14/creating-an-emberjs-addon-with-the-ember-cli/
I generate application route using code below,
ember g route application --dummy
However when I use ember s it seems run the addon's app folder instead of tests/dummy. What should I do?
Update
I have also try to start ember s inside dummy app seems no effect. It keep show me the ember-welcome-screen instead.
The solution is simple DELETE ember-welcome-page from package.json file and then run npm install.
The reason is that ember-welcome-page only get disabled when it can find custom route defined inside your app directory.

Why does Ember.js require a server?

I've downloaded Ember.js ver 1.13.13 for a test drive.
With other js frameworks, I am able to run from a file system. Does Ember require a server? I could not run directly from a file system. I did find some old tutorials that allows this. Is this a new thing?
You are using Ember-CLI which requires running ember serve in order to view your ember app. Ember-CLI uses conventions so that it knows where to locate the files that compose your ember app. As Ember-CLI locates your files, it knows how to combine them in a manner that ultimately results in the single JavaScript file that is executed in your browser. In theory you could use the globals style of development-which is the style reflected in the 'old tutorials' that you reference-and run the app directly without using any sort of "server." But, I don't recommend that. Learning Ember-CLI is useful as it is the preferred method of development moving forward. And, in my opinion, gives you a number of features that allow you to more quickly prototype apps. You can read more about that in the link I provided to the Ember-CLI website.

Ember.js consuming REST Services

I have been working on a web app using .NET web forms. Now I'm trying to move to a Web API and a client side application. I'm trying to use Ember.js right now. I'm starting to get confused with Ember 2.0, Ember-Data and stuff.
My problem right now is that I'm trying to consume some of the REST services in order to show a list of things in my Ember app. Is it mandatory for me to use Ember-Data? If not, how can I consume the services to create, read, update and delete items (I mean, am I able to use only ajax or something)?
The Web API was built in order to be usable for many technologies. I need to build an specific URL for each request (even a simple GET has some mandatory parameters). That's why ember-data is not working well for me, at least not what I have learnt about it. Because this.store.find won't allow me to build the URL I need.
Greetings.
Is it mandatory for me to use Ember-Data?
No, it's not. You can use other libraries such as Ember RESTless, or write your own.
You can even use simple jQuery AJAX calls whenever you need to fire a request to your API, however, you'll loose many benefits of Ember Data, such as lazy, asynchronous loading of models when they are needed.
That's why ember-data is not working well for me, at least not what I
have learnt about it. Because this.store.find won't allow me to build
the URL I need.
You can override buildURL method of adapter you're using(for example RESTAdapter), source code on GitHub could be helpful if you would like to do that, and you can find everything you need to create your own behavior for buildURL method in Ember API documentation.

What should I use instead of DS.FixtureAdapter

You gotta love ember.js team... I'm getting this depreciation message saying that: "DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master". Guys maintaining that addon advise that we should use a library similar to Pretender. Has anybody done that? Is there a tutorial showing how to integrate this lib so that everything would work as before?
If you are using ember-cli it comes with an http-mock out of the box letting you quickly setup fixtures in a more realistic test scenario. For instance, for a Conversation model you would mock it by running the following prompt on your command line.
ember g http-mock conversations
This will scaffold an endpoint located at server/mocks/conversations.js that your real adapters will use to get data when you run ember serve. You can modify this file to your liking to return whatever fixtures / mock data you want for the various CRUD operations you need.
Server mocks:
Ember CLI's http-mock
Clientside mocks:
Pretender.js
jQuery mockjax
Ember CLI Mirage, basically sugar around Pretender
Clientside mocking has some advantages like portability, making it easy to use in a CI environment, but server mocks let you take advantage of express middleware.
Note: I maintain Mirage. You can watch a screencast & overview here.
I like to use http-mocks with ember-cli. In addition I like to use raw JSON files as the payloads for each endpoint here is an example setup https://github.com/pixelhandler/ember-fixturific/pull/1/files

Sails.js and Ember.js integration

Has anyone tried to use sails as ember's backend API?
How would you go about it?
Is there an example available?
Since Sails has a different format in its built-in blueprints, is it better to make sails rest json format confirm to what ember expects or the other way around?
Thanks!
Edit
So there are two approaches:
change the sails format, maybe with: CRUD blueprint overriding in sails.js
change what ember expects: http://discuss.emberjs.com/t/sails-js-as-the-backend/5233
There is a project called Sane Stack that uses a Sails blueprint to generate the appropriate setup for Ember and Sails, as well as provides a generator for creating resources in Ember and Sails at the same time.
QUICKSTART
npm install -g sails sane-cli
sane new project --docker creates project with sails-disk and Docker. For production databases see Options.
sane generate resource user name:string age:number to generate a new API on the backend and models on the frontend
sane up to start the sails server on localhost:1337 as well as the ember dev server on localhost:4200.
To work on your frontend-app you work as you would normally do with ember-cli on localhost:4200.
You are now good to go.
Note: If you use Docker, make sure you have fig installed. On Mac or Windows also boot2docker and for Linux see: https://docs.docker.com/installation/ubuntulinux/
I can't speak for the "change what Ember expects" option, but I can say that this is precisely what blueprint overrides in Sails were invented for. This would be a perfectly reasonable way to make your app Ember-compatible.
Also keep in mind that all of the CRUD blueprints use the res.ok() response to actually send data down to the client; if you like, you can just override that with your own api/responses/ok.js, perhaps using req.url to determine the resource that was being requested, and use that to wrap your JSON object in the manner that Ember expects.
I just put up a few blueprint overrides that can be used as a starting point for using Sails as an Ember Data backend: https://github.com/mphasize/sails-ember-blueprints
Please let me know if you find a bug or have some suggestions for improvements!
Haven't used ember in a few months, but the default blueprints responses are not compatible with ember-data.
Ember seems to be trying to conform to the jsonapi spec.
Sails default blueprint responses do not.
That being said, it would be pretty easy to roll your own responses with sails.