Nested layouts in admin-on-rest - reactjs

I've started investigating admin-on-rest. It works fine for 'flat' REST-endpoints, e.g.:
/posts/
/users/
etc.
But how do I implement nesting? I mean if I click on some post-entry in 'posts' table - I want not the actual post to be opened in a <Show> view, but a list of it's comments (fetched from URL /{postId}/comments)? And I need also to keep the navigation functionality (some back-arrow button or hierarchy in the header to return to previous page).
Is this even possible with admin-or-rest?

If you want to show a list of comments for a post, use the <ReferenceField>. You can see an example in the demo: https://marmelab.com/admin-on-rest-demo/#/customers/77 (click on the "orders" and "reviews" tabs to see an embedded datagrid).
If you want to link to a filtered list of comments from the post list, you'll have to create a custom button component. Once again, you can find an example in the demo: https://github.com/marmelab/admin-on-rest-demo/blob/master/src/segments/LinkToRelatedCustomers.js

Related

How can I detect the state of Content at View startup?

Lets assume I have created my own custom view for a Link content type. When the user adds a 2sxc Content app to a Pane, then picks the Content Type (Link) then my custom View, when it first starts up, how can I detect that a) the View does not use a Demo item vs. b) the View uses a demo item and is showing the Demo item vs. c) its not the first time and there is a real user added Content (Entity) in place?
I have done stuff like this for the a) case:
var link = AsDynamic(Data["Default"]).First();
then checked if it was null, but it looks like my View code never executes and instead I just see, "No demo item exists for the selected template."
If I do assign a demo, is there a more elegant way to know that the Entity I am handed as Content.First() or Data["Default"]).First() is a Demo item and now a user created Entity? Currently I am hard-coding the EntityId in the template and testing for that.
The template system does not render the template if there is no demo item (unless it's a template without a content-type).
When we need this, we have two ways
give the demo item a unique value in one of the fields and check for that in the template
check the demo-item ID on GUID and check for that (Content.EntityGuid == ...)
IsDemoItem property added in 2sxc 10.06
Dynamic Entity
If a Content Editor "Hides" the only Content Item, the anonymous user will then see a Demo Item where the item was. This is confusing and unexpected from the Content Editor's point of view (as well as the public/anonymous user). If anyone else runs in to it, here is the simple code snippet to add to the start of your view. Basically, if the current user is not logged in and the item to display is a demo item, exit the View w/o displaying anything.
if(!Request.IsAuthenticated) {
if(Content.IsDemoItem ?? false) {
return;
}
}
Best to put it near the start of your first #{} Razor block.
Note: this will not throw an error in 2sxc prior to 10.6.x (because of the "?? false"), but it will not work either.

How can i have a link field in a content type display a default text when the field is empty

How can i have a link field in a content type display a default text when the field is empty.
For now i have a field as a link - and the link is set to have a static title. This Works fine.
But i'd like to display a default title if the field is empty with no link (but still rendered as a link/button).
It's not a view - so i can't use "rewrite output if empty".
I'm a newbee to drupal - so please help
This shows what I've got so far:
http://1fb72c32b5e90467b795f388746f7501b3ad8021.web9.temporaryurl.org/tmp/link2.PNG
When the link field is empty the button doesn't show. Instead of not showing when empty I'd like it to show someting like this as default:
http://1fb72c32b5e90467b795f388746f7501b3ad8021.web9.temporaryurl.org/tmp/link3.PNG (the button "Bestil på tlf...")
By simply using Link module, i don't think this is possible. But, follow below steps in your environment and i think you might achieve the goal:
Make custom template file for the page (i think, its product details page)
In that template file, check whether the link is empty or not
If link is not empty, show the link. If link is empty, show your custom HTML.

Why is my Angular JS ng-show empty list div shows up for a split second while API is being called?

<div ng-show="!activities.length">No items in feed</div>
I use the above code to show a message when a user has no items in their feed. On that same page I have a radio button to show different types of feeds (e.g. just yours, or all your friends, etc.). When the user selects a different option, it makes a post back to my API which takes a second, but while the api is grabbing the data the empty list message displays for a second.
Is there an easy way to resolve this?
Use the ngCloack directive for this:
http://docs.angularjs.org/api/ng.directive:ngCloak
The other option is to use ng-bind as many people recommend it over ng-cloak:
http://docs.angularjs.org/api/ng.directive:ngBind
I personally have had issues where even using ng-cloak there is a slight markup flash.

Meteor - how to link html element to database entry on click event?

I'm trying to figure out how to link an html picture element back to the database entry that was originally used to generate the picture link.
I am using Meteor:
- I have a database that contains photosets data from Flickr API
- In the HTML, I have a handlebar "each" script that iterates through each photoset in the database and then uses this info to generate the html for the photoset cover picture links.
- When the html renders, the photoset cover pictures are downloaded from Flickr and displayed to the screen.
I would like to be able to click on the photoset cover picture and then automatically generate the links to the pictures in the photoset. But I don't understand how to dynamically link the html picture elements back to their respective database entries that were originally used for generating the picture links. I need to be able to find the original database entries so that I can load the info needed for generation of subsequent links.
As a newb to all of this I'm not really sure where to start looking or what to try. I've wondered about creating an object with custom key pairs to 'memorise' the identity of each photoset picture. Is this the way to go, or is there an easier way that I am overlooking?
Thanks.
Say you have your pictures being put out this way:
Template.mytemplate.helpers({
picture:function() {
return pictures.find()
}
});
You can also do this instead, which is pretty much the same thing:
Template.mytemplate.picture = function() {
return pictures.find();
}
With the html
<template name="pictures">
{{#each picture}}
<img src="{{src}}" class="pictureselector"/>
{{/each}}
</template>
You can use events which can get data from that particular picture document/record
Template.mytemplate.events({
'click .pictureselector':function(event,template) {
console.log(this._id); //Should give you the `_id` of the picture that was clicked
}
});
this is the data context of the element that was clicked & generate the link you want using the data inside this.
Be careful if you use something with a callback inside the click like Meteor.call, you will have to relay the message down via var self = this otherwise the context of this would become the one of Meteor.call

Can we have links of related lists in a VF page

I have a VF page in which i have related lists displayed using
<apex:relatedList list="NOTESANDATTACHMENTS"/>
Is there a way i can have the link of the related list on the top of the page like the ones in standard page? The reason for this is that my VF page is pretty long and the user needs to scroll to get the view the notes and attachment list.
is there any way we can achieve this?
Thanks
Not directly, but you can always use anchor links.
Go to related list
...
<a id="mylist" />
<apex:relatedList list="NOTESANDATTACHMENTS"/>
The relationship name for the Notes and Attachments related list has been changed in winter 14 release.
you can show the attachement in the relatedlist tag.
apex:relatedList list="CombinedAttachments" subject="{!$CurrentPage.parameters.id}"
in the VF page if you are using Standard controller then there is no need to add subject attribute.

Resources