From 1fb6c20b8691091add56722b9454042289cfc733 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 7 May 2012 00:54:18 +0800 Subject: [PATCH] Add site_info --- app/controllers/admin/sites_controller.rb | 46 +++++++++++++++++---- app/helpers/application_helper.rb | 14 +++++-- app/models/meta.rb | 15 ------- app/models/meta/meta.rb | 8 ++++ app/models/site.rb | 30 ++++++++++++++ app/views/admin/sites/language.html.erb | 1 + app/views/admin/sites/mail_setting.html.erb | 1 + app/views/admin/sites/site_info.html.erb | 36 ++++++++++++++++ app/views/admin/sites/system_info.html.erb | 1 + app/views/admin/sites/ui_theme.html.erb | 1 + app/views/layouts/_side_bar.html.erb | 17 +++++--- app/views/layouts/page_layout.html.erb | 1 - config/routes.rb | 8 +++- 13 files changed, 147 insertions(+), 32 deletions(-) delete mode 100644 app/models/meta.rb create mode 100644 app/views/admin/sites/language.html.erb create mode 100644 app/views/admin/sites/mail_setting.html.erb create mode 100644 app/views/admin/sites/site_info.html.erb create mode 100644 app/views/admin/sites/system_info.html.erb create mode 100644 app/views/admin/sites/ui_theme.html.erb diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 9475e708..1a19aebd 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,16 +1,48 @@ class Admin::SitesController < ApplicationController - layout "admin" + layout "new_admin" before_filter :authenticate_user! before_filter :is_admin? + before_filter :get_site - def index - @site = Site.first - redirect_to :action => :new unless @site + # def index + # @site = Site.first + # # redirect_to :action => :new unless @site + # end + + # def new + # @site = Site.new + # end + + def update + @site.update_attributes(params[:site]) + redirect_to :back end - - def new - @site = Site.new + + def site_info + + end + + def system_info + + end + + def language + + end + + def mail_setting + + end + + def ui_theme + + end + + private + + def get_site + @site ||= Site.first end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c59f16c3..8829dfef 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -95,12 +95,20 @@ module ApplicationHelper end def page_metas(page) + tmp_meta = {} metas = '' - @site.page_metas.each do |meta| + @site.site_metas.each do |meta| name, content = meta.get_name_content - metas << "\n" + tmp_meta.merge!(name => content) end rescue nil - return metas + page.page_metas.each do |meta| + name, content = meta.get_name_content + tmp_meta.merge!(name => content) + end rescue nil + tmp_meta.each_pair{|name, content| + metas << "\n" + } if !tmp_meta.blank? + metas end def page_title(page) diff --git a/app/models/meta.rb b/app/models/meta.rb deleted file mode 100644 index dbeac167..00000000 --- a/app/models/meta.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Meta - - include Mongoid::Document - include Mongoid::Timestamps - - field :key - field :value, :default => nil - - has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy - - def get_name_content - [self.key, self.value ? self.value : self.i18n_variable[I18n.locale]] - end - -end diff --git a/app/models/meta/meta.rb b/app/models/meta/meta.rb index 411a4f0c..cd713d83 100644 --- a/app/models/meta/meta.rb +++ b/app/models/meta/meta.rb @@ -7,5 +7,13 @@ class Meta field :value, :default => nil has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + + def get_name_content + [self.key, get_content] + end + + def get_content + self.value ? self.value : self.i18n_variable[I18n.locale] + end end diff --git a/app/models/site.rb b/app/models/site.rb index 8f367c0a..4a4c05e8 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,5 +1,7 @@ class Site + METAS = ['description', 'keywords'] + include Mongoid::Document include Mongoid::Timestamps @@ -13,8 +15,11 @@ class Site field :school field :department + has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_many :site_metas, :autosave => true, :dependent => :destroy + before_save :set_key + def generate_keys private_key = OpenSSL::PKey::RSA.generate(2048) self.public_key = private_key.public_key.to_s @@ -30,5 +35,30 @@ class Site res = res.split('rails_3_1').pop.gsub('(', '').gsub(')','').strip rescue nil res.eql?('local out of date') ? false : true end + + def title + @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil + end + + METAS.each do |meta| + define_method meta do + fetch_meta = self.site_metas.where(key: meta).limit(1) + fetch_meta.blank? ? nil : fetch_meta[0].i18n_variable + end + define_method "#{meta}=" do |values| + if a = self.send(meta) + a.update_attributes(values) + else + a = self.site_metas.build(key: meta) + a.build_i18n_variable(values) + end + end + end + + protected + + def set_key + title.key = 'title' if title + end end diff --git a/app/views/admin/sites/language.html.erb b/app/views/admin/sites/language.html.erb new file mode 100644 index 00000000..ceb9b012 --- /dev/null +++ b/app/views/admin/sites/language.html.erb @@ -0,0 +1 @@ +language.html.erb \ No newline at end of file diff --git a/app/views/admin/sites/mail_setting.html.erb b/app/views/admin/sites/mail_setting.html.erb new file mode 100644 index 00000000..3a52ede2 --- /dev/null +++ b/app/views/admin/sites/mail_setting.html.erb @@ -0,0 +1 @@ +mail_setting.html.erb \ No newline at end of file diff --git a/app/views/admin/sites/site_info.html.erb b/app/views/admin/sites/site_info.html.erb new file mode 100644 index 00000000..5fce6331 --- /dev/null +++ b/app/views/admin/sites/site_info.html.erb @@ -0,0 +1,36 @@ +<%= form_for @site, :url => admin_site_path(@site) do |f| %> +
+
+ +
+ <% @site_valid_locales.each do |locale|%> + <%= content_tag :div, :class => "tab-pane #{active_when_current_locale_eq locale}", :id => "#{locale}" do %> + <%= t :title %> + <%= f.fields_for :title, @site.title do |f| %> + <%= f.text_field locale %> + <% end %> + <%= t :keywords %> + <%= f.fields_for :keywords, @site.keywords do |f| %> + <%= f.text_field locale %> + <% end %> + <%= t :description %> + <%= f.fields_for :description, @site.description do |f| %> + <%= f.text_field locale %> + <% end %> + <% end %> + <% end %> +
+ +
+
+ +<% end %> \ No newline at end of file diff --git a/app/views/admin/sites/system_info.html.erb b/app/views/admin/sites/system_info.html.erb new file mode 100644 index 00000000..45535dac --- /dev/null +++ b/app/views/admin/sites/system_info.html.erb @@ -0,0 +1 @@ +system_info.html.erb \ No newline at end of file diff --git a/app/views/admin/sites/ui_theme.html.erb b/app/views/admin/sites/ui_theme.html.erb new file mode 100644 index 00000000..222f5969 --- /dev/null +++ b/app/views/admin/sites/ui_theme.html.erb @@ -0,0 +1 @@ +ui_theme.html.erb \ No newline at end of file diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 41416bc4..f127a73c 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -7,7 +7,7 @@ <%= content_tag :li, :class => active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals') || active_sys_call_for_app('module_apps','edit','Announcement') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + 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')) do -%> + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')) do -%> <%= content_tag :li, link_to(t('announcement.all_articles'), panel_announcement_back_end_bulletins_path), :class => active_for_action('bulletins', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %> @@ -21,7 +21,7 @@ <%= content_tag :li, :class => active_for_controllers('news_bulletins', '/panel/news/back_end/tags', 'news_bulletin_categorys', 'news_approvals') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + 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 :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'), panel_news_back_end_news_bulletins_path), :class => active_for_action('news_bulletins', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_news_back_end_news_bulletin_path), :class => active_for_action('news_bulletins', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_news_back_end_news_bulletin_categorys_path), :class => active_for_action('news_bulletin_categorys', 'index') %> @@ -59,7 +59,7 @@ <%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + 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 :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'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %> @@ -67,6 +67,13 @@ <% end -%> <% end -%> -<%= content_tag :li, :class => active_for_controllers(nil) do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), nil %> +<%= content_tag :li, :class => active_for_controllers('sites') do -%> + <%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %> + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('sites')) do -%> + <%= content_tag :li, link_to(t('admin.site_info'), admin_site_site_info_path(@site)), :class => active_for_action('sites', 'site_info') %> + <%= content_tag :li, link_to(t('admin.system_info'), admin_site_system_info_path(@site)), :class => active_for_action('sites', 'system_info') %> + <%= content_tag :li, link_to(t('admin.language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %> + <%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %> + <%= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %> + <% end -%> <% end -%> diff --git a/app/views/layouts/page_layout.html.erb b/app/views/layouts/page_layout.html.erb index 8fb884b0..dd9aa94a 100644 --- a/app/views/layouts/page_layout.html.erb +++ b/app/views/layouts/page_layout.html.erb @@ -4,7 +4,6 @@ <%= page_title(@item).html_safe %> <%= page_metas(@item).html_safe %> - <%= @metas %> diff --git a/config/routes.rb b/config/routes.rb index 6ded5149..1b98bcc2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -93,7 +93,13 @@ Orbit::Application.routes.draw do get 'add_sub_role' get 'add_attribute_field' end - resources :sites + resources :sites do + get 'site_info' + get 'system_info' + get 'language' + get 'mail_setting' + get 'ui_theme' + end resources :snippets resources :tags resources :translations