result-view. Match. Multiple from-output - bixby

I have main result-view which matching CommandResult (commandResult)
This response can be from different actions, how I can catch all commandResult in one match in from-output?
Example:
result-view {
match: CommandResult (commandResult) {
from-output: Command1Context
from-output: Command2Context
}
}

If you just want ONE result-view for all CommandResult, you can remove from-output. Think it this way, if you don't specify any from-output, you get all for free.
Have fun with Bixby!

There are a couple of ways to achieve this
The simplest way is to create two different Views, each specific to the action that outputs them.
If you would rather have just a single View then you may want to look at 'information' (some sort of state information like a value, a variable etc inside CommandResult) that necessitates having a separate View. You can then review this information in the View or Layout and decide on what content needs to be displayed.
Hope this helps.

Related

Problem ordering nested entities in TypeORM

I've got a self-referencing entity called Category. Basically, it's just a folder that may contain subfolders, but the subfolders cannot contain any other folders. Simple as that. It's possible for the user to move these folders around this way changing their positions relative to each other. On the Category entity I've got a prop called position and when I return all the categories for a specific user I need to order them by position. That's to say the query should look something like this:
const categories = await this.categoryRepository.createQueryBuilder('category')
.where('category.user.id = :userId', { userId })
.leftJoinAndSelect('category.entries', 'catEntries')
.leftJoinAndSelect('catEntries.images', 'catImages')
.leftJoinAndSelect('category.subcategories', 'subs')
.leftJoinAndSelect('subs.entries', 'subCatEntries')
.leftJoinAndSelect('subCatEntries.images', 'subCatImages')
.orderBy('category.position', 'ASC')
.getMany();
The problem with this piece of code is that the ordering doesn't apply to the subcategories.
Hence my question is "How do I write a query that would order not only categories but also subcategories?".
Thank you a lot!
Try adding an addOrderBy('subs.SORT', 'ASC') where SORT is the property you want to sort your subs on (position?)
Take note of the difference between OrderBy() and addOrderBy(). The former overrides previous ones, the latter lets you add multiple order by clauses.

How to attach Content Parts only to specific Types or specific Content Items?

I have two similar problems that I suspect have a common solution.
1) I'd like to create custom Parts that are Attachable, but only to specific content types, only Taxonomies for example. It would be really cool if that was possible out of the box through migrations e.g something like .Attachable(cfg => cfg.ToType("Taxonomy")) but I don't think it is.
Currently, to prevent my custom Part from being used on content that it's not intended for, I just write checks in the driver methods:
protected override DriverResult Editor(CustomPart part, dynamic shapeHelper)
{
if (part.ContentItem.ContentType != "Taxonomy") return null;
return ContentShape("Parts_Custom_Edit", ...
}
Is this a good way to go about it? Would the Handler be better fit for this kind of logic?
2) Similarly, I'd like to be able to conditionally attach different Parts to different individual Content Items. For example, I would like only first level parent Terms in a Taxonomy to have some fields while child Terms have some others.
The best way I can currently come up with to handle this is to just create one Part that holds all fields and run similar checks to the one above in its Driver methods to return different models depending on its container. Then in the template View I check which fields to render:
#if (Model.ThisField != null) {
<div>#Html.EditorFor(m => m.ThisField)</div>
}
else {
<div>#Html.EditorFor(m => m.ThatField)</div>
}
Ideally I'd like to create one attachable Part that's capable of adding several non-attachable secondary Parts to existing Content Items when it is attached to a Type and to new Content Items when they are created or updated. Is there a painless way to do this? I think 'Welding' might be what I need but I haven't been able to find any documentation or tutorials that can explain Welding to me like I'm five.
I think you need to implement a dynamic welding approach. I had to solve a similar issue, it is posted here. Hope this helps.

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.

Is list function a good candidate for my scenario?

I have a view in couchDb that is defined like this
function (doc) {
if (doc.url) {
var a = new Date(doc.postedOn);
emit([a.toLocaleDateString(), doc.count, doc.userId], {
_id: doc.userId,
postTitle: doc.postTitle,
postSummary: doc.postSummary,
url: doc.url,
count: doc.count
});
}
};
This gives me the result in a format that I want.Sorted first by date then by count and then by userID.
However I have trouble querying it.What I want is to query this view just by userId.That is leave the date and the count parameter null.
_view/viewName?limit=20&descending=true&endkey=["","","userId"]
does not give me the desired result.
Should I be using list function to filter out the results of the view.Is there any impact on performance if I do this?
This quote from the definitive guide first gave me the idea that list functions could be used to filter and aggregate results.
The powerful iterator API allows for flexibility to filter and aggregate rows on the fly, as well as output raw transformations for an easy way to make Atom feeds, HTML lists, CSV files, config files, or even just modified JSON.
List function has nothing to do with your case. From the docs you've linked to yourself:
While Show functions are used to customize document presentation, List functions are used for same purpose, but against View functions results.
Show functions are used to represent documents in various formats, commonly as HTML page with nicer formatting. They can also be used to run server-side functions without requiring a pre-existing document.
To solve your problem just change the order of the emitted keys, putting userId first, i.e.:
[ doc.userId, a.toLocaleDateString(), doc.count ]
and update your query appropriately.
If changing the order of emitted keys is not an option, just create another view.

couchdb: is there an identity list function?

I'm learning about list functions in couchdb, and I'm wondering what the identity function looks like, if one exists. (i.e. a list that emits the same output as a raw view)
If you understand list functions, could you help me write one?
I expect it would look something like
function(head, req) {
while (var row = getRow()) {
send(row)
}
}
but I'm not sure, and that doesn't sound right because I don't use head and req anywhere.
I have an example list function. It's purpose is to do an intersection of tags, you pass in a key (as the view key), and extra_keys which are the additional tags to include in the intersection. I am just telling this as the purpose of this view does not relate to your question, but it will help you understand what you are looking at.
The list mimics view output, mostly. My app only really looks at rows, so that is the only property I add. YMMV. You can cut the cruft in the middle, if you like. The example is here:
https://github.com/ryanramage/eckoit/blob/master/app.js#L209
I found this blog post which seems to be close to what you want. The only difference would be that in the real view results there is a total_rows and offset field (as long as there isn't a reduce function).

Resources