I am working on Redmine 1.4.x. I have two roles: client and employee. To separate the roles I have added is_client boolean attribute to the database. Here is the use case:
if is_client?
puts "it is client"
else
puts "it is employee"
end
Now depending upon this role I have to display Portal tab in the top menu. To achieve this I tried the following:
Redmine::MenuManager.map :top_menu do |menu|
menu.push :portal, "#", :html => {:id => "emp_portal", :onclick => "OpenEmployeePortal()"} , :if => (Proc.new { User.current.is_client? } && Proc.new { User.current.logged? })
end
But I couldn't succeed. It is showing the portal tab for both roles.
So how can I achieve this?
Try this
Redmine::MenuManager.map :top_menu do |menu|
menu.push :portal, "#", :html => {:id => "emp_portal", :onclick => "OpenEmployeePortal()"} , :if => (Proc.new { User.current.is_client? && User.current.logged? })
end
Related
I am working on Rails 3, Redmine, Redmin Plugin. Following are the codes in init.rb.
Redmine::Plugin.register :my_utilization do
name 'Name'
author 'Author'
description 'Plugin Description'
version '0.0.1'
url ''
author_url 'site.com'
menu :top_menu, :utilization, { :controller => 'utilization', :action => 'index' }, :caption => 'Reports' }
menu :application_menu, :utilization, { :controller => 'utilization', :action => 'index' }, :caption => 'Utilization', :if => Proc.new { User.current.logged? }
menu :application_menu, :project_reports, { :controller => 'project_reports', :action => 'index' }, :caption => 'Projects', :if => Proc.new { User.current.logged? }
permission :my_utilization, { :utilization => [:index], :project_reports => [:index]}
end
Below is the picture displaying top menu and application menu items.
As shown in image, Home, My page, Projects, **Reports**, Help are the top menu items and **Utilization**, **Projects** are the application menu items. Present application menu Utilization and Projects are displaying when I clicked any of the top menu either Home, My page, Projects, Reports. But I want to display Utilization, Projects application menu only when Reports top menu is clicked.
Any solution would be appreciated. Thanks in advance.
I have this line in my helper method
links << {:link => link_to('Overview', overview_index_path, :class => "bold"),
:active => (params[:controller] == "Overview")}
I want to link to a font-awesone icon instead of the text "Overview"
<i class="icon-bar-chart"></i>
I know this is something easy, but i can't remember it right now. Any help is very much appreciated.
Try
links << {:link => link_to('<i class="icon-bar-chart"></i>'.html_safe, overview_index_path, :class => "bold"),
:active => (params[:controller] == "Overview")}
How do you add your own custom links dynamically to the ActiveAdmin global navigation header other than registering the pages/models? For example, if I want a link that can direct users to my home page for instance.
Seems like ActiveAdmin made it somewhat easier. I upgraded to version 0.6.2 and here is what you can do to add custom links anywhere in your navigation (the example below will add one custom menu item, and one custom dropdown):
In # config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
config.namespace :admin do |admin|
admin.build_menu do |menu|
menu.add :label => "My Custom Link", :url => "/", :priority => 0
menu.add :label => "Pages" do |pages|
pages.add :label => "Homepage", :url => "/admin/homepage"
pages.add :label => "About Us", :url => "/admin/about-us"
pages.add :label => "Facebook", :url => "http://www.facebook.com", :html_options => { :target => "_blank" }
end
end
end
end
In case you already registered models with "Pages" as a parent menu (ie: in your app/admin/ folder, a model with menu :priority => 2, parent: 'Pages') it will keep those as well automatically!
I managed to to this by adding the ActiveAdmin::MenuItem to the current AdminAdmin controller. For example,
ActiveAdmin.register User, :name_space => :example_namespace do
controller do
private
def current_menu
item = ActiveAdmin::MenuItem.new :label => "Link Name", :url => 'http://google.com'
ActiveAdmin.application.namespaces[:example_namespace].menu.add(item)
ActiveAdmin.application.namespaces[:example_namespace].menu
end
end
end
I basically created a new ActiveAdmin::MenuItem and add it to the current ActiveAdmin menu with the namespace example_namespace and return the menu in the end of the current_menu method. Note: current_menu is a method expected by ActiveAdmin so don't change the name of it. You can add as many items you like and each of these items will be converted to a link on your navigation header. Note this works for ActiveAdmin version > 0.4.3 so you might need to do your own digging if you want to do it for version <= 0.4.3.
ActiveAdmin.register AdminPage do
menu :url => proc{ "#{AppConfig.url}/checkins/#{current_admin_user.try(:id)}" }
end
Here, you can use any of your db field values in the URL parameter to construct your own URL.
You can configure the site title in your active admin initializer. For example:
config.site_title_link = "/"
This will give you a link to your rootpage.
A 'product' has many 'parallel_products':
class Product < ActiveRecord::Base
has_many :parallel_products, :class_name => "Product", :foreign_key => "master_product_id"
end
In the controller I add the 'parallel_products' column to the list view:
class ProductsController < ApplicationController
active_scaffold :product do |config|
config.list.columns = [ :parallel_products ]
end
end
This gives me a ActiveScaffold generated link in the list view to view, create and edit parallel products of the selected product.
So far so good.
Now, I want to specify this 'parallel_products' link in the helper instead. No changes to the link itself, it should be exactly as the ActiveScaffold generated link. The reason is that I need to add a condition, so that the link is only shown under certain circumstances.
The ActiveScaffold generated link looks like this in the log:
Started GET "/products?assoc_id=6&association=parallel_products&eid=products_6_parallel_products&parent_scaffold=products&adapter=_list_inline_adapter" for 172.16.99.11 at 2012-03-05 09:37:45 +0100
Processing by ProductsController#index as JS
Parameters: {"assoc_id"=>"6", "association"=>"parallel_products", "eid"=>"products_6_parallel_products", "parent_scaffold"=>"products", "adapter"=>"_list_inline_adapter"}
My best proposal for the ActiveScaffold has_many relation link in the helper is:
link_to("link text", :controller => "products", :assoc_id => record.id, :association => "parallel_products", :eid => "products_#{record.id}_parallel_products", :parent_scaffold => "products", :adapter => "_list_inline_adapter")
This gives me in the log:
Started GET "/products?adapter=_list_inline_adapter&assoc_id=6&association=parallel_products&eid=products_6_parallel_products&parent_scaffold=products" for 172.16.99.11 at 2012-03-05 09:39:38 +0100
Processing by ProductsController#index as HTML
Parameters: {"adapter"=>"_list_inline_adapter", "assoc_id"=>"6", "association"=>"parallel_products", "eid"=>"products_6_parallel_products", "parent_scaffold"=>"products"}
My link does not work, but it seems to be very close. Only difference is that the generated link state 'ProductsController#index as JS' and my syntax state 'ProductsController#index as HTML'.
What is the correct ActiveScaffold syntax for making a 'has_many' relation list view link in the helper?
Thanks to Sergio Cambra for helping to solve this.
This is the syntax for a 'has_many' association link if placed in the helper:
link_to("link text", {:controller => "products", :association => "parallel_products",
:parent_scaffold => "products", :product_id => record.id}, :class => 'index as_action',
:id => "as_products-index-parallel_products-#{record.id}-link",
:remote => true, :data => {:position => :after, :action => 'index'})
To answer the question in full, this is how it can be implemented to exactly replace the autogenerated AS association link:
def parallel_products_column(record)
if product.parallel_products.blank?
link_text = "-"
css_class = "index as_action empty"
else
link_text = product.parallel_products[0...3].map{ |p| p.name }.join(", ")
if product.parallel_products.length > 3
link_text += ", … (#{product.parallel_products.length})"
end
css_class = "index as_action"
end
link_to(link_text.html_safe, {:controller => "products", :association => "parallel_products",
:parent_scaffold => "products", :product_id => record.id}, :class => css_class,
:id => "as_products-index-parallel_products-#{record.id}-link",
:remote => true, :data => {:position => :after, :action => 'index'})
end
You will need a small 'hack' for the css 'empty' class, example:
.active-scaffold a.empty {
display: block;
text-align: center;
}
Note:
This is for Rails/AS 3.1 or newer.
I have this
<%= link_to_remote "Next",
{:url => { :controller=>:objects,
:action=>:filter_recent,
:page=>#objects.next_page},
:with => "Form.serialize('filter')" },
:after => "alert('hello')"%>
I've tried :before, :after, :loading, :complete... none of them appear to be working... I know the button works, cause the table advances to the next page.
It looks like your arguments are incorrectly split up by the hash you wrapped them in.
Your :after JS snippet/callback is being passed to the html_options argument hash, not the options hash (where it would be used).
Change to the following:
<%= link_to_remote "Next",
:url => {
:controller=>:objects,
:action=>:filter_recent,
:page=>#objects.next_page
},
:with => "Form.serialize('filter')",
:after => "alert('hello')"%>