I am fairly new to ember. I have an existing Ember App and i need to implement a functionality in it. I have a Ember Object as below
`import Ember from 'ember'`
CallService = Ember.Object.extend
... other code here
_updateConnectedLeadId: (->
console.log "Do i get here??"
**pass the route action here**
).observes('some_other_here')
`export default CallService`
Unfortunately, i couldn't put the whole code here.
My route looks like
ApplicationRoute = Ember.Route.extend
actions:
showLead: ->
console.log data
console.log "did i get here?"
#transitionTo('dashboard')
`export default ApplicationRoute`
I tried using #send('showLead'), #sendAction('showLead') in my method but no luck.
My main intention is to make a transition once the console.log "Do i get here??" is displayed. I am not sure if i am on the right way here.
I also tried using #transitionTo('dashboard') and #transitionToRote('dashboard') directly but it throws me errors.
I have been stuck for a day on this now and i am clueless.
I'll be grateful for any guidance and help. Thanks
You have the problem that you are trying to trigger a route action or trigger a transition from within an Ember.Object, named call service. The code you create is unclear about where your custom object is being created; where the observer is triggered due to a change to object's property update, and so on.
Nevertheless, I tried to provide a working example for you. If you open the twiddle, you will see that I created a my-object instance within index.js route and pass it as model to my-component. When you click the button within my-component.hbs. The my-object instances dummyVariable is toggled and the observer within my-object executes. The tricky part here is that I passed index route itself as ownerRoute property to my-object instance; so that I can trigger the index route's dummyAction from within my-object.js with
ownerRoute.send('dummyAction');
so that related action executes and transition to my-route is performed. Although, I believe this might solve your question; I am not quite happy about the design. I do not think, it is a good way for Ember.Objects to know about routes, actions, controllers, etc. I believe the proper way is observing object's relevant properties from within this constructs and perform necessary actions by their own. Moreover, you might consider creating a service instead of an object and inject the service directly to your route instead of creating an instance of your class extending Ember.Object. If you have to extend from Ember.Object you can just inject relevant route, controller, etc to the instances of that particular object class by using an instance-initializer if you need.
Anyway, please take a look at the twiddle and ask more if you need to. I will be happy to help if I can.
Related
I have a general JSF problem, I found no nice solution for yet. See the picture for a general idea. I have a workaround solution (sorry for the typo in the image) in place that solves the problem by a listbox. However the desired solution is to display all existing versions next to each other (probably always around 1-3).
I have a view with a tree and picklist. There is a complex flow regarding the interaction between list and tree, e.g. you can only move models to subgroups, not top-level-groups and much more. I created a handler class that manages this behavior and translates it to service calls.
Now, a new requirement came up. There are several versions of this tree that should be displayed all together on one page. My gut feeling is that managing n versions in one handler is a big mess as I need to store several things in the handler already for one version.
In React, I would create a component that wraps the tree and all of the interaction. However, in JSF I'm not so sure what is the best practice here?
I would be happy about suggestions and ideas, I'm not expecting Code :)
I found a solution that fits my needs and I post it here hoping that it might help other people as well :)
So on my view I have several tree views with complex interactions. For example, if an item within the tree is moved, the operation is immediately reflected in the database. As I use JPA, I need to translate this to an entitymanager call.
The views are either displayed in a list or just one-at-a-time via a dropdown select.
Anyway, the idea is that every complex view component has its own controller with a reference to an entitymanager and a transaction, while having just one JSF handler class. If JSF would allow to create multiple handlers (like #{handler_1}, {handler_2}), the problem could be solved in a different way. But as JSF works name based and the name {#handler} always refers to the same container managed thing, this is no option.
The handler class is ViewScoped (or SessionScoped, if you prefer). For each tree component it has a ComponentController class that receives the EntityManager and the UserTransaction as well as the related data form the handler via constructor injection. This way, the handler can delegate all commands to the Controller while being DRY.
With this solution, the controller logic can be re-used regardless how many tree components exist. Each view elements binds a specific controller via handler.controllers.get(id).
All other solutions did not work for me as they are not able to perform database operations on view interactions.
I recently load several versions of MEANJS (meanjs.org) to understand the file structure better and view the changes.
In 4.0, articles.client.controller.js to be specific they have:
and I'm able to make changes to new Articles there as I appended new fields to the mongoose Schema.
$scope.create = function () {
// Create new Article object
var article = new Articles({
title: this.title,
content: this.content
});
In 4.1, it comes like this.
// Create new Article object
var article = new Articles({
title: this.title,
content: this.content
});
Now with 4.2, I don't see that in articles.client.controller.js,
vm.article = article;
I have my modified Schema version. How to make changes to the creation of a new Articles object? This is a good question for upgrading app from 4.0, 4.1 to 4.2.
It’s changed slightly.
Trying to use the resources directly as was done in version 4 may cause problems where the page is ready but not the resource (Article).
To get around this problem angular uses resolves which which use promises to handle the timing issues.
The important thing to know is that the promise will give you some answer at some point in the future - Just, it may not be the answer you'd like!
Either way, it always tells you once it has the answer - or more correctly once it has resolved.
Angular uses the promises to help out with the timing issues mentioned above. The resolves are keyed to a promise and will only load the controller once the resolve(s)... erm... resolve!
This means we will always have articles when we expect.
Promises, resolves - Let me at'em - Let me at'em!!
The resolves option is used in the updated articles.client.routes. Here we see that articleResolve is keyed to getArticle which isn't a promise itself but is instead a function which returns one (which is just a good!)
If we look at the lines below we can see how we create this promise returning function. It's a function which uses Angular's $stateParams (to inspect the state) and fill in the articleId for the requested article. We get the articles using the injected and familiar Articles service.
In your case you want to know how new articles are created so we must travel a little further into the articles service which has recently been updated.
This is almost the same as the Articles service which you are used to using, however the additional lines add an extra method to this service which allow it to create, or if existing to save the article details.
These lines are how we extend a service in angular and the below implementation basically checks the article to see wether it has the ._id property. This is the string representation of the .id property that all saved mongo db documents get.
It uses this information call the appropriate method.
Finally, back where we began
In the controller we see the earlier created promise key articleResolve used as the second injected argument; As if to say "when you have this articles service resolved use it as this second parameter when I'm injecting the arguments".
When we look at the controller definition, we notice that the corresponding second parameter is named article.
Background: Within any controller this actually points to the scope (or $scope). As convention†, and to make things in angular look like standard JavaScript where we often say var that = this, we create a variable to reference our scope.
Within the controller we attach this article to the scope so that it is accessible in the views via vm.article.
Fin!
† Graze at Papa John's style guide when you get chances and slowly evolve your code style to match it. It will help you avoid traps and as a side effect makes lot of the angular code examples/tutorial more understandable, especially where the authors also follow it.
How can I implement a Multi-DataTriggerBehavior?
I already have one DataTriggerBehavior in place. But I need a trigger that is based on an event and multiple conditions.
I'd recommend you to create your own Behavior to handle this.
These are the steps for a possible solution.
Because you will need to somehow invoke a VisualState in your Behavior's code behind, you have to change the VisualStateManager defined in your xaml to ExtendedVisualStateManager (see the implementation in this post) as the built-in VisualStateManager's GoToState method doesn't accept Grid as its parameter.
Create a Behavior and attach it to a proper Control. I assume you want to do something when an event of the Control is raised. So you need to create a handler for this in your Behavior code-behind.
Create dependency properties that map the properties defined in your viewmodel and subscribe to all their property changed callbacks. You might need local flags to tell whether all of them are updated or not. If they are, in your event handler, call ExtendedVisualStateManager.GoToElementState. Note that you might also need to create a dependency property to reference your Grid and a few others to map your VisualState names.
Attach the Behavior to your Control in xaml and data-bind all its dependency properties.
Hope this makes sense.
I m working on a user interface in JavaFX. It is the front-end of an infrastructure service that I have already developed and is operational. I read here and there that mock can be used to avoid running all the system when it is to heavy to run, but also for isolation purpose.
At present I want to run some basic test as I am also learning how to use JavaFX and I would not want to run all my infrastructure for the matter.
Basically I have a TreeView that I would like to update based on what is coming from the service. Normally the service that runs in background would update the model and call a Platform.runlater() method to ask the UI to refresh.
I was wondering how can I achieve that using mocking. How can I have a mock object update a simplified shared structure such as a list(model) and then call Platform.runlater()? Actually I would first ask: is it a possible and appropriate usage of mock and if yes how can it be done, with which framework?
Personally what is a bit not clear to me is the involvement of multi-threading. Indeed my object under test which is the interface would not be calling any method of my mock, expect indirectly, the Run() method, given that my service is a runnable.
Hence I would appreciate if anyone could enlighten me a bit further on the matter. I'm confused....
Best,
Maatari
First prepare applications (or change your current app to support test mode) which can populate your TreeView with specific data. The entity which will provide fake data for TreeView will be your mock object for specific data. It should look like a service from TreeView point of view, which means you need to extract common methods from your services class into interface and make TreeView use this interface instead of concrete class.
To handle UI testing you can you use JemmyFX library. You can create simple test which will verify any UI properties of your TestView or imitate user actions like mouse clicks or text input. You may not worry about threading issues, jemmy will handle it for you.
It can look next way (I use junit as test harness here):
public class TreeTest {
#BeforeClass
public static void setUpClass() throws Exception {
// running your specially crafted FX application with mock service data
// you can do it any way, e.g. by calling main() method with some parameters
AppExecutor.executeNoBlock(TreeApp.class);
}
#Test // this is junit annotation for test
public void fooTest() {
// here we are receiving special jemmyfx entity which knows how to handle
// tree views and is attached to your TreeView
// (if you app has only one TreeView, you may need additional logic for several ones)
TreeViewDock tree = new TreeViewDock(new SceneDock().asParent());
// this way we can find some item which you expected to see in you TreeView
// because you've created you mock data this way.
// Note that underlying code will respect UI threading,
// will understand that UI can have delay and will give it certain time without blocking
// and will throw descriptive exception in case expected item wasn't found
tree.asTree().selector().select(new ByToStringLookup("item1"));
// you can find subitems
tree.asTree().selector().select(new ByToStringLookup("item1"), new ByToStringLookup("subitem1");
// and perform operations on them, e.g. expand:
new TreeItemDock(tree.asItemParent(), new EqualsLookup("item2")).asTreeItem().expand();
//etc
}
You can find more info on site on just by code completion hints
It seems controllerDidChangeContent: is being called as soon as I create a new managed object in my context. The documentation seems to suggest this method is called only once you save: the context.
This "bug" if it is one, is causing my application to crash because as part of my table view cell, I need to load other managed objects that don't exist at the time of creating the main managed object.
Someone seems to have spotted this too, please check out the following link and I would love to hear your opinions on this: http://openradar.appspot.com/10207615
More information
Although the link I added to this post showcases an example using two NSManagedObjectContext, my application is using one context, but the controllerDidChangeContent: is being messaged none the less as soon as an object is created in the one and only context, and controllerDidChangeContent: is being called a second time when I save: this context. It is to my understanding that this method should only be messaged when the context is saved.
The solution is to avoid dealing with more than one managedObjectContext. If your cell needs to load other managed objects, it should still use the same managed object context as the main managed object.
I have yet to see a use case where it is absolutely unavoidable to use more than one managed object context referring to the same model active at the same time.