mercredi 8 novembre 2017

Ember.JS - Submit button runs a query and returns JSON object to template. Do I run the query in a service, as a model or in a route?

I am still a novice and I am converting an application from Node Express to Ember I'm confused on some of the methodology involved in Ember.

In the current application there is a form that is submitted and then executes a query based on the input. In the app.js of the current application there is a switch statement on POST:

app.post('/test', function(req, res){
switch(req.body.module) {
    case "Option 1":
  getOption1Results(req, res);
    break;
    case "Option2":
  getOption2Results(req, res)
  break;
    case "Option 3":
  getOptio3Results(req, res)
  break;
  case "Option 4":
  getOption4Results(req, res)
  break;
  default:
    console.log("didn't work")

}

To get the same results in Ember I don't know whether I should be creating a service to do the above or creating a route and executing the query in a model that's passed to the template.

Any advice is very much appreciated.




Redefine null value to string

try to study ember...

as you can see, backend returned some properties with null value

How to transform this false value to .. for example, string like "n/a"




mardi 7 novembre 2017

Tracing API in flask

I have a following front-end code in js(/ember/create/app/components/someFile.js):

component.$('.city-select-autocomplete').marcoPolo({
      url: '/api/objects/cities',
      data: {range_size: 8, order_by: '-population'},
      minChars: 3,
      required: true,
      param: 'search',
      formatData: function (data) {
        return data.cities.sortBy('population').reverse();
      },
      formatItem: function (data, $item) {
        var state = data.country_code === 'US' ? data.admin1_code + ', ' : '';
        return data.name + ', ' + state + data.country_code;
      },

I am trying to find out where the implementation(server code) is written for url "/api/objects/cities". I tried searching URL mappings but couldn't find it.

Project structure:

config/
controllers/
deploy/
docs/
ember/
env/
models/
static/
tasks/
templates/
tests/
tools/
utils/
vacuum/
web/
serve.py
..
..
..

There must be some url mapping with ("/api/objects/cities") using @app.route annotation but I wasn't able to find it.

There must be some convention. api/objects is constant but the last part obj_type varies so there must be a method with the name "cities" and it might be matching by method name. /api/objects/ maps to method with name ? Right ? But I am not finding any such method in controller/web folder.




Ember: Re-render a route's template when the model changes

I've noticed that a route doesn't re-render when the model changes (i.e. transitionTo the same route with a different model). I have some jQuery plugins set up on a particular page and I need them to re-render when the model changes, so it appears as a fresh page.

Is there a way to do this? Perhaps by observing the model's ID and firing a re-render of the route somehow?

Thanks in advance




Calling Cordova Plugin from Ember Controller

I am trying to create a cordova plugin for android which I can call from an Ember controller.

I created this simple plugin for testing this out using the command: cordova plugin add TestPlugin which I used as a stub to build this on.

When the controller runs the action that contains the call it doesn't seem to fire as there is no alert when running the app to show a success or failure response. I am testing using an android emulator.

I've seen many examples of where this has been implemented and works for cordova apps but nowhere within an Ember-Cordova app.

Perhaps I'm missing a reference from within my controller to be able to use cordova.exec? If so, what could this possibly be? Your help is greatly appreciated. Let me know if any further detail is required.

TestPlugin.java

package cordova.plugin.test.plugin;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class TestPlugin extends CordovaPlugin {

    public static String TAG = "TestPlugin";

    @Override
    public boolean execute(String action, JSONArray args,
        CallbackContext callbackContext)
    throws JSONException {
        Log.d(TAG, "called execute on TestPlugin");
        Log.d(TAG, "action is: " + action);
        if (action.equals("sayHello")) {
            this.sayHello(args.getString(0), callbackContext);
            return true;
        } else {
            Log.d(TAG, "Did not match any registered actions");
            callbackContext.error("Invalid action: " + action);
            return false;
        }
    }

    private void sayHello(string name, CallbackContext callbackContext) {
        try {
            String responseText = "Hello world, " + name;
            callbackContext.success(responseText);
        } catch (JSONException e) {
            callbackContext.error("Failed to parse parameters.");
        }
    }
}

config.xml

<feature name="TestPlugin">
    <param name="android-package" value="cordova.plugin.test.plugin.TestPlugin" />
    <param name="onload" value="true" />
</feature>

Controller

cordova.exec(function(successData){
    alert("OK: " + successData);
}, function(failureData){
    alert("FAIL: " + failureData);
},
"TestPlugin",
"sayHello",
["Oliver"]);




Flask url route tracing

I have a following front-end code in js(/ember/create/app/components/someFile.js):

component.$('.city-select-autocomplete').marcoPolo({
      url: '/api/objects/cities',
      data: {range_size: 8, order_by: '-population'},
      minChars: 3,
      required: true,
      param: 'search',
      formatData: function (data) {
        return data.cities.sortBy('population').reverse();
      },
      formatItem: function (data, $item) {
        var state = data.country_code === 'US' ? data.admin1_code + ', ' : '';
        return data.name + ', ' + state + data.country_code;
      },

I am trying to find out where the implementation(server code) is written for url "/api/objects/cities". I tried searching URL mappings but couldn't find it.

Project structure:

config/
controllers/
deploy/
docs/
ember/
env/
models/
static/
tasks/
templates/
tests/
tools/
utils/
vacuum/
web/
serve.py
..
..
..

There must be some url mapping with ("/api/objects/cities") using @app.route annotation but I wasn't able to find it in the whole project.




Build error on ember-cli-growl

So i was using ember-cli-growl when i found a build error related to growl-manager.css.

ENOENT: no such file or directory, stat '/Users/****/****/*********/tmp/concat_with_maps-input_base_path-http://ift.tt/2zqQYFs'

It seems the respected was on tmp/**/app/styles/components/growl-manager.css but the module called it in 'tmp/**/components/growl-manager.css'.

Anyone has experience this before?