How to recreate an element in Threepenny GUI? - haskell

If I use the delete function on some Elements, how can I then recreate them (as in make them appear again)?
I have looked around the examples and documentation, but I couldn't find any function that would allow me to do this except maybe mkElement which requires me to pass it a String. However since I'm working with Elements getting the String that would create it would be a bit difficult.
So is there any way to do that?

(Library author here)
Actually the, delete function does more than just remove the element from the DOM tree — it tries to delete any references to it in the JS and Haskell side. Essentially the element is (should be) unuseable after a delete.
If you want to temporarily hide an element, you can
Hide it via the CSS display property.
Rest the children of the parent element, e.g. by element parent # set children [].

Given that delete has the signature delete :: Element -> UI (), it follows that when you call delete, you have an Element in hand. Why can't you just hold onto this Element somewhere? (By which I mean maintain a reference to it in any number of ways.) Then just use (#+) :: UI Element -> [UI Element] -> UI Element to attach it as a child to another element later. If you just want it to reappear where it was before, you'd just attach it as a child to the very element that was its parent to begin with. Is this what you had in mind, or did I misunderstand the question?

Related

anytree nodemixin using property or reference

I have an existing tree and I would like to add anytree functionality by adding NodeMixin. The problem is that NodeMixin wants a fixed name 'children' for its sub-elements and I already have a list with a different name.
Another problem (I am using mypy) is that the exiting sub-elements list is not optional - terminal nodes have empty lists and NodeMixin wants 'None' as 'children' of terminal objects.
It will create a lot of changes if I have to rename the object and to deal with the optional nature of the children.
Is it possible to define children as #property or as a reference of the existing sub-elements?
(a) it is possible to use properties for parent and children, (b) it was easy to write custom iterable class for children to account for differences between anytree and my tree iterations.
Update: is_leaf property has to be overridden too - otherwise it will be true for every node.

Can i get all components of an xsp document in xpages?

I have a simple document with 3 fields and 1 rich text field. I also have an xpage with 3 simple edit box controls and 1 rich text. The name of my NotesXSPDocument is document1.
Question 1:
Can i get a vector with all the controls of the xsp document? for example, instead of using getComponent("fld1"), getComponent("fld2") ... etc, can i use something like getAllComponents() or document1.getControls()? These methods do not exist of course so i am asking if there is a way to do it. I know i can get all items of a document (not XSP) by calling document1.getDocument().getItems(). IS there anything similar for xsp?
Question2:
Lets say we can get a vector as i described above. Then if i iterate through this vector to get each control's value, is there a method to check if it is rich text or simple text field?
Technically, yes, but not readily and this is one of those situations where there's likely a better way to approach whatever underlying problem it is you want to solve.
Nonetheless, if you're looking to get a list of inputs on the page, XspQuery is your friend: http://avatar.red-pill.mobi/tim/blog.nsf/d6plinks/TTRY-96R5ZT . With that, you could use "locateInputs" to get a List of all the inputs on the page, and then check their value method bindings to see if the string version is referencing your variable name. Error-prone and not pretty, but it'd work. Since they're property bindings, I don't think the startsWith filter in there would do what you want.
Alternatively, you could bind the components to something in a Java class from the start. I've been doing just such a thing recently (for a different end) and initially described it here: https://frostillic.us/f.nsf/posts/my-black-magic-for-the-day . The upshot is that, with the right cleverness for how you do your binding="" property, you could get a list of all the components that reference a property of a given object.
As for the second part of the question, if you DO get a handle on the components one way or another, you can check to see if it's a rich text control by doing "component instanceof com.ibm.xsp.UIInputRichText".
A bit complex but yes. facesContext.getViewRoot() is an UIViewRoot object so it has List<UIComponent> getChildren() method which returns its children.
However, since it's a tree-structure, some of its children will have additional children components. You have to traverse the entire tree to build a list of components you want to see.
For types, you can decide what type a component is by its class. For instance, UIInput is a text box, etc.

Attaching arbitrary data to objects in D3.js

This relates mostly with what a "best practice" would be with D3.js. I want to attach arbitrary information to different svg elements that I have on a page, after they are created. In D3, it looks like one generally generates svg elements from a dataset. I want to attach data to these svg elements at any time, without adding their HTML attributes.
Is there a good way of doing this? Do I need to use an auxillary array/object or is there a way to apply data to the elements themselves?
You would use the datum method if you want to attach arbitrary data:
D3.select('#mynodeId').datum( mydata );
And then later you could access the value again:
var mydata = D3.select('#mynodeId').datum();
Internally, D3 is going to use the __data__ property of the node, just like it does when the nodes were created from a data set via the selectAll, enter, append sequence.
Note that if you already have a reference to a DOM node you can pass it as the parameter to D3.select rather than making it re-look-up based on selector syntax:
D3.select( anExistingDOMNodeReference ).datum( mydata );
From the API doc:
d3.select(node): Selects the specified node. This is useful if you already have a reference to a node, such as d3.select(this) within an event listener, or a global such as document.body.

Breadcrumbs error in Kohana

I am implementing breadcrumbs on my application using Kohana framework using https://github.com/RaymondCrandall/kohana-breadcrumbs
I have a Category section which internally has many other sub categories n so on. One controller called Category.php having two action:
1. index($cat) (called when I click on each category until it reaches the last sub category)
2. category($cat) (called when I click on last sub category i.e. on leaf node )
The way I wrote my code into both action is:
Breadcrumbs::add(Breadcrumb::factory()->set_title("Home")->set_url(url::site()));
Breadcrumbs::add(Breadcrumb::factory()->set_title("Categories")->set_url(url::site('categories')));
if($cat != NUll) {
Breadcrumbs::add(Breadcrumb::factory()->set_title($cat)->set_url(url::site('categories/' .$cat )));
}
$actual = Breadcrumbs::get();
$view->breadcrumbs = $actual;
The problem is it shows me only three levels. How can I extend it to 4th level or more.
Eg. home>category>stationary>dress. How can I save my previous values of $actual?
So when I click on dress, index action is called and replaces my array with
home>category>dress since parameter '$cat= dress'.
I don't think this is much related to the mentioned plugin.
You are just using the category name string, a simple string doesn't even know what is a category, event less what is it's name, and hierarchy.
I see three options:
Get all your parent relations from the DB, or wherever you store them, run a loop that prints breadcrumbs, until it reaches the leaf.
Map your actions so they accept full path, for example "index/stationary/dress", and extract all the values from the path parameters (no need for DB call in this case)
Store an array with previous values in session, and recreate breadcrumb from that array. Also no DB calls here. Note that, in this case you have to be careful when to empty the array. Depends on your logic. You would have to recognize when a leaf has been hit, and empty the array then.

NSArrayController that is sorted and unique (no duplicates) for use in a pop-up in a core-data app

I have core data app with an entity OBSERVATION that has as one of its attributes DEALNAME.
I want to reference through Interface Builder or by making custom modifications to an NSArrayController a list of unique sorted dealnames so that I can use them in a pop-up.
I have attempted to use #distinctUnionOfSets (and #distinctUnionOfArrays) but am unable to locate the proper key sequence.
I can sort the ArrayController by providing a sort descriptor, but do not know how to eliminate duplicates.
Are the #distinct... keys the right methodology? It would seem to provide the easiest way to optimize the use of IB.
Is there a predicate form for removing duplicates?
Or do I need to use my custom controller to extract an NSSet of the specific dealnames, put them back in an array and sort it and reference the custom array from IB?
Any help would be appreciated. I am astounded that other have not tried to create a sorted-unique pop-up in tableviews.
You need to take a look at -[NSFetchRequest returnsDistinctResults]. That is the level you need to be handling the uniquing of data.
Although I do not have a definitive answer for you, I think there are two ways you can go about it.
The way you already started. You need to bind the contents array of the PopUp button, not just against the arrayController.arrangedObjects, but continue on the path and somehow filter only objects with distinct "DealName"s. This means - the arrayController presents ALL the entities (and may sort them for you) but the PopUp button will have its contents filter via some sophisticated binding to the array controller.
Make your filtering at the ArrayController level (as suggested in another answer here). Here it depends how you set up the array controller. If It is set up to use an "Entity" (vs. "Class") which means the array controller will fetch CoreData entities directly - you can modify its "Fetch" to only bring a subset of the "OBSERVATION" entities with distinct values of "DEALNAME". I don't know how to control WHICH entities are filtered out in this case. Otherwise, you can setup the arrayController to work with "Class" objects, and then you can fetch the entities yourself (in code) and populate the arrayController programmatically, with just the entities you like.
In the second option, the Popup button should be bound normally to the arrayController's arrangedObjects.

Resources