Active admin defining scope for custom page - activeadmin

I have created a custom page by using register_page method. I want to display result by defining scope. I know how to use scope for a model, but have no idea how to define scope for custom page. How do I define the scope?

You should register resouce with alias for this:
ActiveAdmin.register Post, as: 'post_statistics' do
But if you have opportunity to not use ActiveAdmin - please don't use it. It will save you a lot of time and nerves.

Related

Shopware 5 accessing controller variables (Template Variables) on frontend

The technical term given in many articles for this is Template Variables. I am trying to understand how we can find the variable name given in the controller for a specific field of Shopware 5 front end (ex. Product Name)
For example, I can see the template variable for article name has been given as $sArticle.articleName. I found this when I checked the source code manually.
Let’s say I want to find the discount value given for particular product, How can I print this on my theme? What variable I should use and what is the easy way to find it.
I can assign values from back end for all the variables but my question is how I can access them on my theme file when I update my theme when it comes to technical development side.
Please Note: I am trying to understand the shopware5 technical side.
Using the {debug} function will usually give you a list of all assigned variables. This list should also include a variable $Controller which will give you a hint to the currently related Controller.
Unfortunately you are not able to identify where the assigned variables come from. Due to the event driven architecture of Shopware the variables can be assigned to the view after the request has been dispatched to the related Controller. This means that variables might he assigned through third party plugins as well as specific event listeners and store front decorators (in Shopware 5).
Kind regards!
If you want to use your variables inside the template you have to write a plugin and assign your controller-variables to the view.
Check out Globale Variablen im Template verwenden in the shopware documentation.
If you want to use see which variables are allready assigned, you can use {debug} in the template. Also {$sArticle|var_dump} is really helpful, if you want to debug a specific variable ($sArticle} in this example).
You have to known that shopware assigns the members of an object to the view.

Detect first log of user

I'm realizing a theme with liferay using velocity. I would like to add some functions to the theme homepage only in the case the user logs in the portal for the first time.
How can I use velocity (portal_normal.vm) to achieve that?
As stated by #Olaf Kock it is not suggested to use the business logic in the theme section.
But, If you want to do it anyway then Liferay provides a set of Velocity Variables that can be accessed in the Themes. Which includes the User details too.
These are some of the User related Variables available globally in themes,
$user_id,$is_default_user,$user_first_name,$user_middle_name .... $user_login_ip, $user_last_login_ip
You can check out more at : themes\_unstyled\templates\init.vm inside ROOT.WAR.
So, For your specific purpose here you can use $user_last_login_ip. If the value is null then it would be the first time the user has logged into the portal.So, use this inside the portal_normal.vm,
#if (!$user_last_login_ip)
... do stuff here if the variable is null
#end
And, Alternately you can fetch the User last login date using and check null to ensure whether it is his first login,
#if (!$user.getLastLoginDate())
... do stuff here if the variable is null
#end
Don't add this to the theme. Rather have a separate custom LoginAction for this. This will be executed on every login (you can choose pre- or post-login, I'm assuming that post-login will be appropriate) and should find some more information than I linked on this topic all over the net.
A theme is made for look&feel and should not contain any business logic - especially not when it's for a one-off purpose.

Xpages: Code a new page button so that I can repopulate some fields in new Xpage

This seems like it should be easy to do but I cannot get it done.
I have an Xpage called Location. There are two general types, A and B. I have a series of views for A and B. They are the same except for the value of that one field.
In the views I want my "New Location" button to automatically populate the type to A or B, depending on whether the user is in one of the A views or B views.
Seems like I would set a scoped variable and then check for that on document creation, but it doesn't seem to work. What is the best practice to do this?
Jesse Gallagher's frostillicus framework on OpenNTF (XPages Scaffolding - http://openntf.org/main.nsf/project.xsp?r=project/XPages%20Scaffolding&SessionID=DN6QBBFGEB) includes flashScopes, which give the facility to pass information from one page to another and get cleared when the page is loaded.
You can use sessionScope variable to transfer data from one XPage to another.
A better approach might be to use URL parameter for your case.
Add for example &type=A to your URL like
http://server/database.nsf/Location.xsp?action=newDocument&type=A
Then you can read this parameter in your destination XPage with param.type like
var type = param.type;
The disadvantage of sessionScope is that it's the same for all browser tabs. So, you need to delete it right after usage in this case. Using an URL parameter instead you don't have to think about that.

Best practice: sessionscope variable or property definition

To hand over values from an XPage to a custom control, which approach should be used ?
a) Define properties in the custom control at design time. Fill in the properties at the XPage with computed values. Use the value via 'compositeData' in the custom control at runtime.
or
b) Put the value in a session scope variable at the XPage in BeforePageLoad event. Bind the session scope variable to the field in the custom control.
The session scope is primarily intended for ensuring that values persist as the user navigates between pages. I like to call it the "shopping cart" scope: if you built an e-commerce site in Domino, you wouldn't want the site to forget that a user had added a product to their cart just because they clicked back to the home page. So this scope is also useful for features like remembering search / sort / filter options as the user navigates the app so each time they navigate somewhere else and come back, it remembers their prior behavior without having to store this information permanently in the NSF.
For passing in-page information to a Custom Control from a container, however, compositeData is definitely the way to go. This is because that variable is populated with the passed parameters only for the duration of the processing of the relevant control. Once that control has been dealt with, all pointers to the passed parameters are cleaned up automatically, which provides incremental scalability improvement for each instance compared to storing the same information for the duration of each user's session.
There will be cases where there is overlap: a given Custom Control might reference information that is appropriate to store in the session scope. In this scenario I like to mix the two techniques... for example:
<xp:inputText value="#{sessionScope[compositeData.scopeKey]}" />
The above syntax allows a Custom Control to be passed by its container the identifier for where in the session scope the relevant information is stored. This provides some serious flexibility, because I can drop the same control into multiple contexts, with each telling the control which information it should retrieve / store in scope.

OpenCms Element (may be page) properties

I am working with OpenCms 8, I having a problem I am suppose to define custom properties to page and external links, but when we define new properties one can add any input, I want to limit that input, i.e. Yes/No, is it possible any suggestions?
Best Regards
With custom properties, do you mean 'properties' as the one you define when clicking on the page's icon and the selecting 'properties', or do you mean custom fields (let's call it attributes) in the schema xsd for your specific page type? Because that's a difference.
For properties, you can't validate the user's input, for attributes (which you can also map to properties on the other hand), you can restrict the user's input, i.e. by still keeping the type to 'string', however, only providing a selection list with 'yes'/'no' as the options.
To answer your question more precisely, please let me know which schema/xsd you're using for your page.
Are you new to OpenCms, or have you used it before? Just to understand your experience level with it.

Resources