Add site_info
This commit is contained in:
parent
48f8fbde7f
commit
1fb6c20b86
|
@ -1,16 +1,48 @@
|
||||||
class Admin::SitesController < ApplicationController
|
class Admin::SitesController < ApplicationController
|
||||||
|
|
||||||
layout "admin"
|
layout "new_admin"
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :is_admin?
|
before_filter :is_admin?
|
||||||
|
before_filter :get_site
|
||||||
|
|
||||||
def index
|
# def index
|
||||||
@site = Site.first
|
# @site = Site.first
|
||||||
redirect_to :action => :new unless @site
|
# # redirect_to :action => :new unless @site
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def new
|
||||||
|
# @site = Site.new
|
||||||
|
# end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@site.update_attributes(params[:site])
|
||||||
|
redirect_to :back
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def site_info
|
||||||
@site = Site.new
|
|
||||||
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -95,12 +95,20 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_metas(page)
|
def page_metas(page)
|
||||||
|
tmp_meta = {}
|
||||||
metas = ''
|
metas = ''
|
||||||
@site.page_metas.each do |meta|
|
@site.site_metas.each do |meta|
|
||||||
name, content = meta.get_name_content
|
name, content = meta.get_name_content
|
||||||
metas << "<meta name=#{name} content=#{content} />\n"
|
tmp_meta.merge!(name => content)
|
||||||
end rescue nil
|
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 << "<meta name='#{name}' content='#{content}' />\n"
|
||||||
|
} if !tmp_meta.blank?
|
||||||
|
metas
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_title(page)
|
def page_title(page)
|
||||||
|
|
|
@ -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
|
|
|
@ -8,4 +8,12 @@ class Meta
|
||||||
|
|
||||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
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
|
end
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
class Site
|
class Site
|
||||||
|
|
||||||
|
METAS = ['description', 'keywords']
|
||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
@ -13,8 +15,11 @@ class Site
|
||||||
field :school
|
field :school
|
||||||
field :department
|
field :department
|
||||||
|
|
||||||
|
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
has_many :site_metas, :autosave => true, :dependent => :destroy
|
has_many :site_metas, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
|
before_save :set_key
|
||||||
|
|
||||||
def generate_keys
|
def generate_keys
|
||||||
private_key = OpenSSL::PKey::RSA.generate(2048)
|
private_key = OpenSSL::PKey::RSA.generate(2048)
|
||||||
self.public_key = private_key.public_key.to_s
|
self.public_key = private_key.public_key.to_s
|
||||||
|
@ -31,4 +36,29 @@ class Site
|
||||||
res.eql?('local out of date') ? false : true
|
res.eql?('local out of date') ? false : true
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
language.html.erb
|
|
@ -0,0 +1 @@
|
||||||
|
mail_setting.html.erb
|
|
@ -0,0 +1,36 @@
|
||||||
|
<%= form_for @site, :url => admin_site_path(@site) do |f| %>
|
||||||
|
<div id="post-body">
|
||||||
|
<div id="post-body-content" class="clear">
|
||||||
|
<ul class="nav nav-tabs">
|
||||||
|
<% @site_valid_locales.each do |locale|%>
|
||||||
|
<%#= raise @site_valid_locales.inspect %>
|
||||||
|
<%= content_tag :li, link_to(I18nVariable.from_locale(locale), "##{locale}", :data => {:toggle => "tab"}), :class => (active_when_current_locale_eq locale) %>
|
||||||
|
<% end %>
|
||||||
|
<li>
|
||||||
|
<%= f.submit t("submit"), :class => "btn btn-primary" %>
|
||||||
|
<%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<% @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 %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -0,0 +1 @@
|
||||||
|
system_info.html.erb
|
|
@ -0,0 +1 @@
|
||||||
|
ui_theme.html.erb
|
|
@ -67,6 +67,13 @@
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<%= content_tag :li, :class => active_for_controllers(nil) do -%>
|
<%= content_tag :li, :class => active_for_controllers('sites') do -%>
|
||||||
<%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), nil %>
|
<%= 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 -%>
|
<% end -%>
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<%= page_title(@item).html_safe %>
|
<%= page_title(@item).html_safe %>
|
||||||
<%= page_metas(@item).html_safe %>
|
<%= page_metas(@item).html_safe %>
|
||||||
<%= @metas %>
|
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<%= javascript_include_tag "html5" %>
|
<%= javascript_include_tag "html5" %>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
|
@ -93,7 +93,13 @@ Orbit::Application.routes.draw do
|
||||||
get 'add_sub_role'
|
get 'add_sub_role'
|
||||||
get 'add_attribute_field'
|
get 'add_attribute_field'
|
||||||
end
|
end
|
||||||
resources :sites
|
resources :sites do
|
||||||
|
get 'site_info'
|
||||||
|
get 'system_info'
|
||||||
|
get 'language'
|
||||||
|
get 'mail_setting'
|
||||||
|
get 'ui_theme'
|
||||||
|
end
|
||||||
resources :snippets
|
resources :snippets
|
||||||
resources :tags
|
resources :tags
|
||||||
resources :translations
|
resources :translations
|
||||||
|
|
Reference in New Issue