From c6894be962a27dec205fcbc12c4a537f7e1d0581 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 20 Nov 2012 15:56:52 +0800 Subject: [PATCH] first version of confined sidebar render --- .../object_auths_new_interface_controller.rb | 8 +- .../admin/users_new_interface_controller.rb | 2 +- app/models/user/attribute_value.rb | 2 +- app/views/layouts/_side_bar.html.erb | 3 +- app/views/layouts/_side_bar_content.html.erb | 109 +------------ app/views/layouts/new_admin.html.erb | 1 + config/mongoid.yml | 2 +- lib/orbit_app.rb | 5 +- lib/orbit_app/helper/context_link_renderer.rb | 12 ++ lib/orbit_app/helper/renderer.rb | 62 +++++++ lib/orbit_app/helper/side_bar_renderer.rb | 43 +++++ lib/orbit_app/module/backend_side_bar.rb | 17 -- lib/orbit_app/module/registration.rb | 8 +- lib/orbit_app/module/side_bar.rb | 151 ++++++++++++++++++ lib/orbit_app/plugin/registration.rb | 15 +- lib/orbit_app/summary.rb | 2 +- .../back_end/bulletin_categorys_controller.rb | 7 +- vendor/built_in_modules/announcement/init.rb | 62 ++++--- 18 files changed, 353 insertions(+), 158 deletions(-) create mode 100644 lib/orbit_app/helper/context_link_renderer.rb create mode 100644 lib/orbit_app/helper/renderer.rb create mode 100644 lib/orbit_app/helper/side_bar_renderer.rb delete mode 100644 lib/orbit_app/module/backend_side_bar.rb create mode 100644 lib/orbit_app/module/side_bar.rb diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index 973f4215..7e0763ff 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -1,10 +1,13 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController include OrbitCoreLib::PermissionUnility before_filter :force_order - + + def set_module_app + @module_app = ModuleApp.where(:title=>'Announcement').first + end + def setting - @sys_users = User.all(conditions: {admin: false}).includes(:avatar) @ob_auth = ObjectAuth.find params[:object_auth_id] @options_from_collection_for_select_ob_auth = @ob_auth.siblings.collect{|oa| [oa.auth_obj.pp_object,oa.id] } @@ -60,6 +63,7 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController def force_order authenticate_user! + set_module_app check_if_user_can_do_object_auth end diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 01f44016..8302e4d7 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -26,7 +26,7 @@ class Admin::UsersNewInterfaceController < ApplicationController def show @user = User.find(params[:id]) - @plugins = OrbitApp::Module::Registration.all + @plugins = OrbitApp::Plugin::Registration.all @profile_data = [] @teacher_data = [] diff --git a/app/models/user/attribute_value.rb b/app/models/user/attribute_value.rb index e335451a..f3995796 100644 --- a/app/models/user/attribute_value.rb +++ b/app/models/user/attribute_value.rb @@ -94,7 +94,7 @@ def unset_all_lang_values unless self[:temp_data].nil? case self.attribute_field.markup when "address" - binding.pry + # binding.pry when 'text_field','text_area' if self.attribute_field.add_more self["val"] = self["temp_data"] diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 32876b9f..c2c1536b 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -13,7 +13,8 @@
diff --git a/app/views/layouts/_side_bar_content.html.erb b/app/views/layouts/_side_bar_content.html.erb index 66e4542d..479d6216 100644 --- a/app/views/layouts/_side_bar_content.html.erb +++ b/app/views/layouts/_side_bar_content.html.erb @@ -1,4 +1,3 @@ - <%#= content_tag :li, :class => active_for_controllers('purchases') do -%> <%#= link_to content_tag(:i, nil, :class => 'icons-purchase') + t('admin.purchase'), admin_purchases_path %> <%# end -%> @@ -6,113 +5,7 @@ <%= javascript_include_tag "/static/kernel.js" %> <% end %> -<%= content_tag :li, :class => (active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals') || active_for_app_auth('Announcement') || active_for_ob_auths_object("BulletinCategory") ) do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + content_tag(:span, t('admin.announcement')), panel_announcement_back_end_bulletins_path %> - <%= content_tag :ul, :class => ("nav nav-list " + (visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory"))) do -%> - <%= content_tag :li, link_to((t('announcement.all_articles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_announcement_back_end_bulletins_path), :class => active_for_action('bulletins', 'index') %> - <%= content_tag :li, link_to((t('announcement.add_new') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('announcement.categories') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_announcement_back_end_bulletin_categorys_path), :class =>( active_for_action('bulletin_categorys', 'index') || active_for_ob_auths_object("BulletinCategory") )if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('announcement.tags') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_announcement_back_end_tags_path), :class => active_for_action('/panel/announcement/back_end/tags', 'index')if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('announcement.bulletin.approval_setting') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_announcement_back_end_approval_setting_path), :class => active_for_action('approvals', 'setting') if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('admin.module.authorization') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "announcement"}))), :class => active_for_app_auth('Announcement') if (is_admin? rescue nil) %> - - <% end -%> - -<% end -%> - -<%= content_tag :li, :class =>( active_for_controllers('news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals')|| active_for_app_auth('news') || active_for_ob_auths_object("NewsBulletinCategory")) do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + content_tag(:span, t('admin.news')), panel_news_back_end_news_bulletins_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals')) do -%> - <%= content_tag :li, link_to((t('announcement.all_articles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_news_back_end_news_bulletins_path), :class => active_for_action('news_bulletins', 'index') %> - <%= content_tag :li, link_to((t('announcement.add_new') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_panel_news_back_end_news_bulletin_path), :class => active_for_action('news_bulletins', 'new') if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('announcement.categories') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_news_back_end_news_bulletin_categorys_path), :class => active_for_action('news_bulletin_categorys', 'index') || active_for_ob_auths_object("NewsBulletinCategory") if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('announcement.tags') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_news_back_end_tags_path), :class => active_for_action('/panel/news/back_end/tags', 'index') if (is_manager? rescue nil)%> - <%= content_tag :li, link_to((t('announcement.bulletin.approval_setting') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_news_back_end_approval_setting_path), :class => active_for_action('news_approvals', 'setting') if (is_manager? rescue nil) %> - <%= content_tag :li, link_to((t('admin.module.authorization') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "news"}))), :class => active_for_app_auth('news') if (is_admin? rescue nil) %> - <% end -%> - -<% end -%> - -<%#= content_tag :li, :class => active_for_controllers('users') do -%> - <%#= link_to content_tag(:i, nil, :class => 'icons-member') + t('admin.member'), admin_users_path %> -<%# end -%> - -<%= content_tag :li, :class => active_for_controllers('page_contexts') || active_for_app_auth('page_content') || active_for_ob_auths_object("PageContext") do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-page') + content_tag(:span, t('admin.page')), panel_page_content_back_end_page_contexts_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('page_contexts')) do -%> - <%#= content_tag :li, link_to(t('admin.all_articles'), panel_page_content_back_end_page_contexts_path), :class => active_for_action('page_context', 'index') %> - <%= content_tag :li, link_to((t('admin.module.authorization') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "page_content"}))), :class => active_for_app_auth('page_content') if (is_admin? rescue nil) %> - <% end -%> - -<% end -%> - -<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') ||active_for_ob_auths_object("AdBanner") ||active_for_app_auth('ad_banner') do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-link') + content_tag(:span, t('admin.ad_banner')), admin_ad_banners_path %> - - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('ad_banners', 'ad_images') ) do -%> - <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> - <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> - <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%= content_tag :li, link_to((t('admin.module.authorization') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "ad_banner"}))), :class => active_for_app_auth('ad_banners') if (is_admin? rescue nil) %> - <% end -%> -<% end %> - - -<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') || active_for_ob_auths_object("WebLinkCategory") do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-link') + content_tag(:span, t('admin.link')), panel_web_resource_back_end_web_links_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> - <%= content_tag :li, link_to((t('admin.all_articles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %> - <%= content_tag :li, link_to((t('announcement.add_new') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') if (is_manager? rescue nil)%> - <%= content_tag :li, link_to((t('announcement.categories') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_web_resource_back_end_web_link_categorys_path), :class => (active_for_action('web_link_categorys', 'index') || active_for_ob_auths_object("WebLinkCategory")) if (is_manager? rescue nil)%> - <%= content_tag :li, link_to((t('announcement.tags') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') if (is_manager? rescue nil)%> - <%= content_tag :li, link_to((t('admin.module.authorization') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "web_resource"}))), :class => active_for_app_auth('web_resource') if (is_admin? rescue nil) %> - <% end -%> -<% end -%> - -<%= content_tag :li, :class => active_for_controllers('albums','album_images','gallery_categories','/panel/gallery/back_end/tags') || active_for_app_auth("gallery") do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-picture') + content_tag(:span, t('admin.orbit_gallery')), panel_gallery_back_end_albums_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('albums') ) do -%> - <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> - <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> - <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%= content_tag :li, link_to((t('gallery.categories') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_gallery_back_end_gallery_categories_path), :class => active_for_action('gallery_categories','index') %> - <%= content_tag :li, link_to((t('gallery.tags') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_gallery_back_end_tags_path), :class => active_for_action('/panel/gallery/back_end/tags', 'index') %> - <%= content_tag :li, link_to((t('admin.module.authorization') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe,admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "gallery"}))), :class => active_for_app_auth('gallery') if (is_admin? rescue nil) %> - <% end -%> -<% end %> - -<%= content_tag :li, :class => active_for_controllers('archive_files', 'panel/archive/back_end/tags', 'archive_file_categorys') do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-asset') + content_tag(:span, t('admin.archive')), panel_archive_back_end_archive_files_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('archive_files', 'tags', 'archive_file_categorys')) do -%> - <%= content_tag :li, link_to((t('admin.all_articles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_archive_back_end_archive_files_path), :class => active_for_action('archive_file', 'index') %> - <%= content_tag :li, link_to((t('admin.add_new') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_panel_archive_back_end_archive_file_path), :class => active_for_action('archive_file', 'new') %> - <%= content_tag :li, link_to((t('admin.categories') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_archive_back_end_archive_file_categorys_path), :class => active_for_action('archive_file_categorys', 'index') %> - <%= content_tag :li, link_to((t('admin.tags') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, panel_archive_back_end_tags_path), :class => active_for_action('tags', 'index') %> - <% end -%> -<% end -%> - -<%= content_tag :li, :class => active_for_controllers('cals','panel/calendar/back_end/tags') || active_for_app_auth("calendar") do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-calendar') + content_tag(:span, t('admin.calendar')), panel_calendar_back_end_cals_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('cals','calendar_categories') ) do -%> - <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> - <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> - <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%= content_tag :li, link_to((t('admin.calendars') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_panel_calendar_back_end_cal_path), :class => active_for_action('cals','new') %> - <%= content_tag :li, link_to(t('admin.tags'), panel_calendar_back_end_tags_path), :class => active_for_action('/panel/calendar/back_end/tags', 'index') %> - <%#= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "gallery"}))), :class => active_for_app_auth('gallery') if (is_admin? rescue nil) %> - <% end -%> -<% end %> -<%= content_tag :li, :class => active_for_controllers('locations') || active_for_app_auth("gprs") do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-link') + content_tag(:span, t('admin.gprs')), panel_gprs_back_end_locations_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('locations') ) do -%> - <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> - <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> - <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%#= content_tag :li, link_to((t('calendar.calendars') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, new_panel_calendar_back_end_cal_path), :class => active_for_action('cals','new') %> - <%#= content_tag :li, link_to(t('gallery.tags'), panel_gallery_back_end_tags_path), :class => active_for_action('/panel/gallery/back_end/tags', 'index') %> - <%#= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "gallery"}))), :class => active_for_app_auth('gallery') if (is_admin? rescue nil) %> - <% end -%> -<% end %> +<%=OrbitApp::Module::SideBarRegisition.all.first.render(request,params,current_user) %>
<% flash.each do |key, msg| %> diff --git a/app/views/layouts/new_admin.html.erb b/app/views/layouts/new_admin.html.erb index 7659a38f..26f299fb 100644 --- a/app/views/layouts/new_admin.html.erb +++ b/app/views/layouts/new_admin.html.erb @@ -20,6 +20,7 @@ <% else %> <%= render 'layouts/side_bar' %> <% end %> +
<%= yield %>
diff --git a/config/mongoid.yml b/config/mongoid.yml index 9ed585f0..c41c3db6 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -3,7 +3,7 @@ defaults: &defaults port: 37017 # slaves: # - host: slave1.local - port: 27017 + # port: 27017 # - host: slave2.local # port: 27019 diff --git a/lib/orbit_app.rb b/lib/orbit_app.rb index b0e5a735..f218c1e4 100644 --- a/lib/orbit_app.rb +++ b/lib/orbit_app.rb @@ -1,6 +1,9 @@ require "orbit_app/summary" require "orbit_app/dsl" -require "orbit_app/module/backend_side_bar" +require "orbit_app/helper/renderer" +require "orbit_app/helper/side_bar_renderer" +require "orbit_app/helper/context_link_renderer" +require "orbit_app/module/side_bar" require "orbit_app/plugin/summary" require "orbit_app/plugin/registration" require "orbit_app/module/summary" diff --git a/lib/orbit_app/helper/context_link_renderer.rb b/lib/orbit_app/helper/context_link_renderer.rb new file mode 100644 index 00000000..9e1af318 --- /dev/null +++ b/lib/orbit_app/helper/context_link_renderer.rb @@ -0,0 +1,12 @@ +module ContextLinkRenderer + include Renderer + + def render(request,params) + @request = request + @params = params + if display? + content_tag :li, link_to((I18n.t(@label_i18n) + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, eval(@path)), :class => (active? ? 'active' : nil) + end + end + +end \ No newline at end of file diff --git a/lib/orbit_app/helper/renderer.rb b/lib/orbit_app/helper/renderer.rb new file mode 100644 index 00000000..3eb09b86 --- /dev/null +++ b/lib/orbit_app/helper/renderer.rb @@ -0,0 +1,62 @@ +module Renderer + include Rails.application.routes.url_helpers + include ActionView::Helpers::UrlHelper + include ActionView::Helpers::TagHelper + include ActionView::Helpers::RenderingHelper + include ActionView::Context + include OrbitBasis::RenderAnywhere + +protected + def active_for_app_auth? + @module_app.id.to_s == @params[:module_app_id] ? true : false + end + + def active_for_ob_auths? + if @params.has_key? :object_auth_id + oa = ObjectAuth.find @params[:object_auth_id] + check_controller = @params[:controller] == 'admin/object_auths_new_interface' + check_object_class = @active_for_object_auth.include? oa.obj_authable_type + return (check_controller and check_object_class) + else + return false + end + end + + def current_user + current_or_guest_user + end + + def current_or_guest_user + @current_user + end + + def request + @request + end + + def default_url_options + _routes.default_url_options + end + + def _routes + @request.env["action_dispatch.routes"] + end + + def controller + @params[:controller] + end + + def action + @params[:action] + end + + def check_user_available_for + + end + + protected + def display? + true + end + +end \ No newline at end of file diff --git a/lib/orbit_app/helper/side_bar_renderer.rb b/lib/orbit_app/helper/side_bar_renderer.rb new file mode 100644 index 00000000..5e04f69e --- /dev/null +++ b/lib/orbit_app/helper/side_bar_renderer.rb @@ -0,0 +1,43 @@ +module SideBarRenderer + include Renderer + include AdminHelper + + def render(request,params,user) + @request = request + @params = params + @current_user = user + if display? + content_tag :li, :class => (module_sidebar_active? ? 'active' : nil) do + buf = link_to( content_tag(:i, nil, :class => @icon_class ) + content_tag(:span, I18n.t( @head_label )), eval(@head_link)) + buf << content_tag( :ul, :class => ("nav nav-list active") )do # visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory")) + @context_links.sort_by! {| obj | obj.priority}.collect do |link| + link.render(request,params) + end.join.html_safe + end + end + end + end + + protected + + def display? #控制sidebar 要不要算圖 + if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員 + true + elsif (@module_app.open rescue false) # 如果app 被設定成 開放 + true + elsif is_member? #如果app 是封閉 那至少需要是 member + true + else + false + end + end + + def module_sidebar_active? + active_for_controller? or active_for_app_auth? or active_for_ob_auths? + end + + def active_for_controller? + @active_for_controllers.include? controller + end + +end \ No newline at end of file diff --git a/lib/orbit_app/module/backend_side_bar.rb b/lib/orbit_app/module/backend_side_bar.rb deleted file mode 100644 index de0ef750..00000000 --- a/lib/orbit_app/module/backend_side_bar.rb +++ /dev/null @@ -1,17 +0,0 @@ -module OrbitApp - module Module - class BackendSideBar - attr_reader :name - - def initialize(name, &block) - @name = name - block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? - end - - # def personal_plugin(*args) - # binding.pry - # end - - end - end -end \ No newline at end of file diff --git a/lib/orbit_app/module/registration.rb b/lib/orbit_app/module/registration.rb index 2f98592d..9a40eda3 100644 --- a/lib/orbit_app/module/registration.rb +++ b/lib/orbit_app/module/registration.rb @@ -33,11 +33,15 @@ module OrbitApp def initialize(name, &block) @name = name + @side_bar = nil block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end - def plugin - + def side_bar(&block) + @side_bar = SideBarRegisition::SideBar.new(&block) + @side_bar.module_app_key = @name + @side_bar.finalize! + OrbitApp::Module::SideBarRegisition.add(@side_bar) end def personal_plugin(params) diff --git a/lib/orbit_app/module/side_bar.rb b/lib/orbit_app/module/side_bar.rb new file mode 100644 index 00000000..a1ca3e63 --- /dev/null +++ b/lib/orbit_app/module/side_bar.rb @@ -0,0 +1,151 @@ +module OrbitApp + module Module + module SideBarRegisition + Version = "0.1" + + module ClassMethods + @@side_bars = [] + + def add(var) + @@side_bars << var + end + + def find_by_key(key) + @@side_bars.each{|t| + return t if t.name == key + } + return nil + end + + def all + return @@side_bars + end + end + + extend ClassMethods + def self.included( other ) + other.extend( ClassMethods ) + end + + class SideBar + # include ApplicationHelper + # include AdminHelper + include SideBarRenderer + # def is_admin? + # binding.pry + # end + # def is_manager? + # binding.pry + # end + def initialize( &block) + name = '' + @head_label = name + @context_links = [] + @available_for = [] + @active_for_controllers = [] + @active_for_object_auth = [] + @active_for_app_auth = [] + @head_link = "" + @app_base_path = '' + block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? + end + + + def module_app_key=(var) + @module_app_title = var + @module_app = ModuleApp.where(:title=>var).desc(:create_date).first + @module_app_key = @module_app.key + end + + def head_label_i18n(var,optoins =nil) + @head_label = var + @icon_class = optoins[:icon_class] + end + + def available_for(var) + @available_for = var + end + + def active_for_controllers(var) + @active_for_controllers = var + end + + def active_for_object_auth(var) + @active_for_object_auth = var + end + + def head_link_path(var) + @head_link = var + end + + def context_link(*var) + new_context_link = ContextLink.new(*var) + @context_links << new_context_link + end + + def finalize! + set_controllers_scope + set_default_active_app_auth + @context_links.each do |t| + t.set_module_app = @module_app + t.finalize! + end + end + + protected + def set_default_active_app_auth + @active_for_app_auth = @module_app.title + end + + def set_controllers_scope + var = @active_for_controllers + @active_for_controllers = [] + var[:private].each do |controller| + @active_for_controllers << "panel/#{@module_app_key}/back_end/"+controller + end unless var[:private].nil? + var[:public].each do |controller| + @active_for_controllers << controller + end unless var[:public].nil? + end + end + + class ContextLink + include ContextLinkRenderer + attr_reader :label_i18n,:available_for,:priority,:path,:active_for_action + + def initialize(label_i18n="NoNameLink",options={}) + @label_i18n = label_i18n + @available_for = options[:available_for] + @priority = options[:priority] || 0 + @path = options[:link_path] || "" + @active_for_action = options[:active_for_action] || [] + @active_for_object_auth = options[:active_for_object_auth] || [] + @active_for_app_auth = options[:active_for_app_auth] || [] + end + + def active? + active_for_action? || active_for_app_auth? || active_for_ob_auths? + end + + def active_for_action? + @active_for_action[controller] == action + end + + def set_module_app=(var) + @module_app = var + @module_app_key = var.key + end + + def finalize! + set_active_actions + end + + protected + def set_active_actions + controller_action_hash = @active_for_action + @active_for_action = Hash[controller_action_hash.map{|controller,action| ["panel/#{@module_app_key}/back_end/"+controller.to_s,action.to_s]}] + end + end + end + end +end \ No newline at end of file diff --git a/lib/orbit_app/plugin/registration.rb b/lib/orbit_app/plugin/registration.rb index f996fc6d..1a6f63f3 100644 --- a/lib/orbit_app/plugin/registration.rb +++ b/lib/orbit_app/plugin/registration.rb @@ -10,8 +10,8 @@ module OrbitApp @@registrations << DataSheet.new(name,&block) end - def new_from_module_app(name,base_path,arg) - @@registrations << DataSheet.new(name,arg,:base_path=>base_path) + def new_from_module_app(name,base_path,*args) + @@registrations << DataSheet.new(name,args,:base_path=>base_path) end def find_by_key(key) @@ -35,14 +35,21 @@ module OrbitApp attr_reader :name attr_reader :base_path + def name + if @name.is_a? Proc + @name.call + else + @name + end + end def initialize(name,partial=nil,*args ,&block) @base_path = args[0][:base_path] - @name = name + @name = partial[0][:i18n].nil? ? name : lambda{ I18n.t(partial[0][:i18n]) } @partial_path = '' unless partial.nil? - @partial_path = partial[:path] + @partial_path = partial[0][:path] end block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? diff --git a/lib/orbit_app/summary.rb b/lib/orbit_app/summary.rb index 05c22f89..d936aa87 100644 --- a/lib/orbit_app/summary.rb +++ b/lib/orbit_app/summary.rb @@ -7,7 +7,7 @@ module OrbitApp def new( name ,&block) @@summaries << Item.new(name,&block) - binding.pry + # binding.pry end def all diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb index c0ae8244..92c841e3 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb @@ -1,7 +1,12 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController include OrbitControllerLib::DivisionForDisable before_filter :for_app_manager,:except => [:index] - + before_filter :set_module_app + + def set_module_app + @module_app = ModuleApp.where(:title=>'Announcement').first + end + def index @bulletin_categorys = get_categories_for_index("BulletinCategory") #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 diff --git a/vendor/built_in_modules/announcement/init.rb b/vendor/built_in_modules/announcement/init.rb index 9a2c0d43..67be8242 100644 --- a/vendor/built_in_modules/announcement/init.rb +++ b/vendor/built_in_modules/announcement/init.rb @@ -2,24 +2,50 @@ module Announcement OrbitApp.registration "Announcement",:type=> 'ModuleApp' do base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true,:path=>"panel/announcement/plugin/profile" + personal_plugin :enable => true,:path=>"panel/announcement/plugin/profile",:i18n=>'admin.announcement' + side_bar do + head_label_i18n 'admin.announcement',:icon_class=>"icons-announcement" + available_for [:admin,:guest,:manager,:sub_manager] + active_for_controllers ({:private=>['bulletins', 'bulletin_categorys', 'approvals','tags']}) + active_for_object_auth ['BulletinCategory'] + head_link_path "panel_announcement_back_end_bulletins_path" + + context_link 'announcement.all_articles', + :link_path=>"panel_announcement_back_end_bulletins_path" , + :priority=>1, + :active_for_action=>{:bulletins=>:index} + + context_link 'announcement.add_new', + :link_path=>"new_panel_announcement_back_end_bulletin_path" , + :priority=>2, + :active_for_action=>{:bulletins=>:new}, + :available_for => [:manager] + + context_link 'announcement.categories', + :link_path=>"panel_announcement_back_end_bulletin_categorys_path" , + :priority=>3, + :active_for_action=>{:bulletin_categorys=>:index}, + :available_for => [:manager] + + context_link 'announcement.tags', + :link_path=>"panel_announcement_back_end_tags_path" , + :priority=>4, + :active_for_action=>{:bulletin_categorys=>:index}, + :available_for => [:manager] + + context_link 'announcement.approval_setting', + :link_path=>"panel_announcement_back_end_approval_setting_path" , + :priority=>5, + :active_for_object_auth => 'BulletinCategory', + :available_for => [:manager] + + context_link 'admin.module.authorization', + :link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: 'Announcement'}))", + :priority=>6, + :active_for_app_auth => 'Announcement', + :available_for => [:manager] + end end - -end - - -# OrbitApp.backend_side_bar 'News' do - -# block :available_for => [:admin,:guest,:manager,:sub_manager], -# :active_for_controllers=> ['news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals'], -# :active_for_ob_auths_object => ['NewsBulletinCategory'], -# :head_link => panel_news_back_end_news_bulletins_path , -# :head_label=> I18n.t('admin.news') - -# context_link :link=>new_panel_news_back_end_news_bulletin_path , -# :priority=>1,:label=>I18n.t('announcement.add_new'), -# :active_for_action=>{:news_bulletins=>:new} - -# end \ No newline at end of file +end \ No newline at end of file