RailsAdmin: how to render a different model index from a custom action - rails-admin

On my website I have users that can apply to jobs, creating a candidacy in my database.
In the jobs index of the admin, I created a custom action so next to each job I have a button that I can press to access the index of the candidacies for this job.
Except that this custom action doesn't work:
class Candidacies < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :member? do true end
register_instance_option :only do [Job] end
register_instance_option :link_icon do 'fa fa-users' end
register_instance_option :controller do
proc do
#id = params[:id]
#objects = Candidacy.where(job_id: #id)
render :index
end
end
end
I load all the candidacies for the job but when I try to redirect to the candidacies index, RailsAdmin tries to load the job index but with candidacies instead of jobs so it lead to an error 500 because candidacies and job do not share the same fields.
Do someone knows how can I load the index candidacies with the candidacies of a specific job?

You can add a jobs filter on the candidacies index and then build a link to the candidacies with that job pre-filtered.
First add the job field to the candidacies admin config
rails_admin do
list do
field :job do
filterable true
end
end
end
Then i believe the url would look like something this:
"/admin/candidacy?model_name=candidacy&utf8=✓&f[job][52801][o]=is&f[job][52801][v]=#{job.id}"
You can get it from your browser filtering the view with the UI and decoding the url with a tool like this
So when your users click the link they'll be taken to the candidacies with job prefiltered.
You can then modify your action to redirect instead to the url of render the :index

Related

How to customize Sales Order form with SuiteScript 2.0?

I didn't find any documentation on advanced customization.
I need to customize Sales Order in a more advanced way than basic customization offered in UI Customization Menu.
For example, add some sublists under Item section with a relation one to many between Item and Messages (1), or add a new button to display a new page to create a messages record page linked with the selected item (2).
Thank you!
Explicative Screenshot
NetSuite's current API does not accommodate the use of custom buttons inside sublists (unless you are using the native REFRESH or MARKALL button within a custom Suitelet).
An alternative solution to bridge the gap between the item record and the message record you want to create, why not do the following:
First, create a SUITELET which opens as a CHILD window of the current window on FIELDCHANGE of the item.
Second, add a basic TEXTAREA field and include the SUBMIT button to the suitelet.
On SUBMIT of the Suitelet, ccreate a new message record, attaching it to the current sales order.
Lastly - ensure the Suitelet closes itself.
Note: This solution will only work on EDIT of a sales order. It will not work on CREATE because no order ID would exist at the time you submit a message. (You need the order ID to attach the message to).
I hope this suggestion is clear.
You can do your customization on BeforeLoad in a UserEvent script : you can access the current form from the context and do somethings like adding buttons, sublists, hiding fields...
You can not add a button, but you can add a link pointing to a Suitelet where you can execute your actions. As an example, I created a sublist with a View link that points out to the line's custom record:
To define the field:
var idField = appStepsSublist.addField({
id: 'id',
type: serverWidget.FieldType.URL,
label: 'View'
});
idField.linkText = 'View';
To set Value :
var viewUrl = url.resolveRecord({
recordType: 'customrecord_nab_approval_step',
recordId: appStep.id,
isEditMode: false
});
usedSublist.setSublistValue({
id: 'id',
line: index,
value: viewUrl
});
In your case, you can use the URL module to get a Suitelet link and append to it the needed data from your current line.

How to set up submit alert with bootstrap and react.js?

I am new in React.js, and I am trying to figure it out how to set up some functionality in form.
What I trying to do is the following:
1) Delete the records/inputs after clicking on the submit button (After submitting the information, the records are stored in the database, but the record/inputs are still displayed in the form.
2) After clicking the submit button, I would love to receive the following message in order to let the user know that the information was successfully submitted
This is part of my code in my component:
For value reset :
Bind a custom function to the onSubmit form method, this function will reset the form value, submit the data and display the success alert
Reset the field values using setState
Submit the data using the API system you use
Add a new boolean state to tell the page to display your alert or not.
Set the boolean state to true in your submit method
Add a display condition in the render method, displaying the alert if the boolean is set to true, and else nothing

Hierarchical menu with Contentful

Contentful has a notion of "Links" which can be to many objects or one. However I can't find a way to model the reverse relationship without doubling the work (i.e. specify the children AND parent of each object).
I would like to use Contentful to power a simple navigation like so:
Menu Item 1
Sub menu item 1
Sub menu item 2
Sub menu item 3
Menu Item 2
Sub menu item 4
Sub menu item 5
Sub menu item 6
-- Sub sub menu item 1
Where the links might look like /<parent.slug>/<child.slug>/<child.slug>/
I could find the page entry to render by traversing up the parent relationships to ensure I get a page with a slug, and a parent with a specific slug.
However, It's hard to render out child menu items without resorting to multiple API calls unless you include a "children" field in the object - which is prone to error and inconsistency.
Yes we had this same issue. We have a Page model, with a refLink called 'parentPage'. Our middleware makes 1 call to CF to get ALL pages and builds a site tree model in memory.
From this model we have methods to get children, and get URL slug.
If your items only has a child relationship you can leverage the includes concept. Simply fetch the furthest down child item and set the includes parameter to a high enough value (10 is max) and Contentfuls API will include all referenced content in a single API call.
You can read more about includes here: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links

context.redirectToPage & $$PreviousPage

i have a button that is calling an agent , and i would like to return to the calling page as the last line of the button.
Is there a way to use context.redirectToPage() in conjunction with "$$PreviousPage" instead of capturing the previous page via a before page load scope variable?
Thanks !
If you just want to 'stay on page' use a partial refresh and eventually the standby control. If you want to get to the previous page you can chain simple actions. Action 1 would be 'run code' action 2 the redirect.
You might want to check your response time. Converting your agent to a Java class will most likely give you better response times

CollectionAction route being skipped, action treated as ID

I'm trying to create a collection_action in ActiveAdmin which allows me to Import a CSV file and generate Subscribers from it. I want to be able to click an action_item link and be taken to a form in which I input the CSV file, and then do some work with it.
This is what I have so far:
ActiveAdmin.register Subscriber do
collection_action :import_csv, :method => :post do
render "import_csv"
end
action_item do
link_to "Import from CSV", import_csv_admin_subscribers_path
end
The view is also created, just blank at the moment. I've restarted the rails server, and rake routes outputs:
import_csv_admin_subscribers POST /admin/subscribers/import_csv(.:format) admin/subscribers#import_csv
batch_action_admin_subscribers POST /admin/subscribers/batch_action(.:format) admin/subscribers#batch_action
admin_subscribers GET /admin/subscribers(.:format) admin/subscribers#index
POST /admin/subscribers(.:format) admin/subscribers#create
new_admin_subscriber GET /admin/subscribers/new(.:format) admin/subscribers#new
edit_admin_subscriber GET /admin/subscribers/:id/edit(.:format) admin/subscribers#edit
admin_subscriber GET /admin/subscribers/:id(.:format) admin/subscribers#show
PUT /admin/subscribers/:id(.:format) admin/subscribers#update
DELETE /admin/subscribers/:id(.:format) admin/subscribers#destroy
However when I click the action item I get the error Couldn't find Subscriber with id=import_csv
If I change the method to :get it renders the view fine. I'm assuming the problem is my use of :post? Is it not possible to render a view if you're calling a controller action with that method?
edit Ok, yeah, it doesn't make sense to render a view with a post but then why does the ActiveAdmin doc suggest that you do the action this way for CSV imports? How are you supposed to # Do some CSV importing work here... without generation a form?
You need to add the method: :post option to the link to invocation, since there's no get action for that url.

Resources