Remove i18n_variable for web_resource

This commit is contained in:
Christophe Vilayphiou 2012-07-26 04:10:15 +08:00
parent 30624c0bd8
commit 207b0c5886
17 changed files with 46 additions and 238 deletions

View File

@ -156,6 +156,23 @@ namespace :migrate do
end end
p 'End PageContext' p 'End PageContext'
p '====================================================='
p '====================================================='
p 'Start WebLink'
links = WebLink.admin_manager_all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
name = I18nVariable.first(:conditions => {:key => 'name', :language_value_id => link.id, :language_value_type => link.class})
link.name_translations = {'en' => name['en'], 'zh_tw' => name['zh_tw']} if name
context = I18nVariable.first(:conditions => {:key => 'context', :language_value_id => link.id, :language_value_type => link.class})
link.context_translations = {'en' => context['en'], 'zh_tw' => context['zh_tw']} if context
link.save(:validate => false)
i += 1
end
p 'End WebLink'
end end
end end

View File

@ -161,75 +161,5 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
module_app = ModuleApp.first(:conditions => {:key => 'web_resource'}) module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}) @tags = Tag.all(:conditions => {:module_app_id => module_app.id})
end end
def get_sorted_and_filtered_web_links
web_links = WebLink.all
case params[:sort]
when 'category'
category_ids = web_links.distinct(:web_link_category_id)
categories = WebLinkCategory.find(category_ids) rescue nil
if categories
h = Hash.new
categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted_categorys = sorted.collect {|a| web_links.where(:web_link_category_id => a[1]).entries }
web_links = sorted_categorys.flatten!
end
when 'name'
h = Array.new
web_links.each { |web_link| h << [web_link.name[I18n.locale].downcase, web_link] }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
web_links = sorted.collect {|a| a[1] }
when 'status'
web_links = web_links.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction])
when 'tags'
a = Array.new
WebResourceTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.web_links }
a.flatten!
a.uniq!
tmp = Array.new
web_links.where(:tag_ids => []).each { |web_link| tmp << [web_link.name[I18n.locale].downcase, web_link] }
sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse!
sorted_names = sorted.collect {|a| a[1] }
a = params[:direction].eql?('asc') ? (sorted_names + a) : (a + sorted_names)
web_links = a.flatten
end
# if @filter
# @filter.each do |key, value|
# case key
# when 'status'
# a = Array.new
# web_links.each do |web_link|
# value.each do |v|
# case v
# when 'pending'
# a << web_link if web_link.is_checked.nil?
# when 'rejected'
# a << web_link if web_link.is_checked.eql?(false)
# else
# a << web_link if web_link[v]
# end
# end
# end
# web_links = a.uniq
# when 'categories'
# a = Array.new
# web_links.each do |web_link|
# a << web_link if value.include?(web_link.web_link_category.id.to_s)
# end
# web_links = a.uniq
# when 'tags'
# a = Array.new
# web_links.each do |web_link|
# web_link.tags.each do |tag|
# a << web_link if value.include?(tag.id.to_s)
# end
# end
# web_links = a.uniq
# end if value.size > 0
# end
# end
Kaminari.paginate_array(web_links).page(params[:page]).per(10)
end
end end

View File

@ -12,7 +12,7 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController
date_now = Time.now date_now = Time.now
@web_links = WebLink.where( :is_hidden => false ).desc(:is_top, :name).page(params[:page]).per(10) @web_links = WebLink.where( :is_hidden => false ).desc(:is_top, :title).page(params[:page]).per(10)
get_categorys get_categorys
end end

View File

@ -28,7 +28,7 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
# deadline # deadline
# @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :name).first # @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :title).first
@web_links = WebLink.widget_datas.page(params[:page]).per(5) @web_links = WebLink.widget_datas.page(params[:page]).per(5)

View File

@ -6,8 +6,8 @@ class WebLink
include Mongoid::MultiParameterAttributes include Mongoid::MultiParameterAttributes
has_one :name, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy field :title, localize: true
has_one :context, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy field :context, localize: true
has_and_belongs_to_many :tags, :class_name => "WebResourceTag" has_and_belongs_to_many :tags, :class_name => "WebResourceTag"
@ -21,19 +21,17 @@ class WebLink
belongs_to :web_link_category belongs_to :web_link_category
validates_presence_of :name validates_presence_of :title
before_save :set_key
def self.search( category_id = nil ) def self.search( category_id = nil )
if category_id.to_s.size > 0 if category_id.to_s.size > 0
find(:all, :conditions => {web_link_category_id: category_id}).desc( :is_top, :name ) find(:all, :conditions => {web_link_category_id: category_id}).desc( :is_top, :title )
else else
find(:all).desc( :is_top, :name) find(:all).desc( :is_top, :title)
end end
@ -42,39 +40,16 @@ class WebLink
def self.widget_datas def self.widget_datas
where( :is_hidden => false ).desc(:is_top, :name) where( :is_hidden => false ).desc(:is_top, :title)
end end
def is_top? def is_top?
self.is_top self.is_top
end end
def name
@name ||= I18nVariable.first(:conditions => {:key => 'name', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def context
@context ||= I18nVariable.first(:conditions => {:key => 'context', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def text
@text ||= I18nVariable.first(:conditions => {:key => 'text', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end
def sorted_tags def sorted_tags
tags.order_by(I18n.locale, :asc) tags.order_by(I18n.locale, :asc)
end end
protected
def set_key
if name && name.new_record?
name.key = 'name'
end
if context && context.new_record?
context.key = 'context'
end
end
end end

View File

@ -12,12 +12,12 @@ class WebLinkCategory
field :key field :key
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy field :title, localize: true
has_many :web_links has_many :web_links
def pp_object def pp_object
i18n_variable[I18n.locale] title
end end
end end

View File

@ -3,7 +3,7 @@ class WebResourceTag < Tag
has_and_belongs_to_many :web_links has_and_belongs_to_many :web_links
def get_visible_links(sort = :name) def get_visible_links(sort = :title)
self.web_links.where(:is_hidden => false).desc(:is_top, sort) self.web_links.where(:is_hidden => false).desc(:is_top, sort)
end end

View File

@ -10,12 +10,12 @@
</div> </div>
<div id="widget-title"> <div id="widget-title">
<%= f.fields_for :i18n_variable, (@web_link_category.new_record? ? @web_link_category.build_i18n_variable : @web_link_category.i18n_variable) do |f| %> <%= f.fields_for :title_translations do |f| %>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<div class="control-group"> <div class="control-group">
<%= label_tag "name-#{locale}", "Name-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %> <%= label_tag "name-#{locale}", "Name-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %>
<div class="controls"> <div class="controls">
<%= f.text_field locale, :class => 'input-xxlarge' %> <%= f.text_field locale, :class => 'input-xxlarge', :value => (@web_link_category.title_translations[locale] rescue nil) %>
</div> </div>
</div> </div>
<% end %> <% end %>

View File

@ -14,6 +14,6 @@
<% end -%> <% end -%>
</td> </td>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td><%= web_link_category.i18n_variable[locale] rescue nil %></td> <td><%= web_link_category.title_translations[locale] rescue nil %></td>
<% end %> <% end %>
</tr> </tr>

View File

@ -69,17 +69,17 @@
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>"> <div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<div class="title"> <div class="title">
<%= f.label :name ,t("web_resource.name")%> <%= f.label :name ,t("web_resource.name")%>
<%= f.fields_for :name, (@web_link.new_record? ? @web_link.build_name : @web_link.name ) do |f| %> <%= f.fields_for :title_translations do |f| %>
<%= I18nVariable.from_locale(locale) %> <%= I18nVariable.from_locale(locale) %>
<%= f.text_field locale, :class=>'post-title' %> <%= f.text_field locale, :class=>'post-title', :value => (@web_link.title_translations[locale] rescue nil) %>
<% end %> <% end %>
</div> </div>
<div class="title"> <div class="title">
<%= f.label :describe,t("web_resource.describe") %> <%= f.label :describe,t("web_resource.describe") %>
<%= f.fields_for :context, (@web_link.new_record? ? @web_link.build_context : @web_link.context ) do |f| %> <%= f.fields_for :context_translations do |f| %>
<%= I18nVariable.from_locale(locale) %> <%= I18nVariable.from_locale(locale) %>
<%= f.text_area locale, :style=>"width:100%" %> <%= f.text_area locale, :style=>"width:100%", :value => (@web_link.context_translations[locale] rescue nil) %>
<% end %> <% end %>
</div> </div>

View File

@ -1,4 +1,4 @@
<%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'], <%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'],
['category', 'bulletin_category', 'span2', 'bulletin.category'], ['category', 'bulletin_category', 'span2', 'bulletin.category'],
['name', 'name','span3', 'bulletin.title'], ['title', 'title','span3', 'bulletin.title'],
['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %> ['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %>

View File

@ -19,9 +19,9 @@
</div> </div>
</div> </div>
</td> </td>
<td><%= web_link.web_link_category.i18n_variable[I18n.locale] rescue nil %></td> <td><%= web_link.web_link_category.title rescue nil %></td>
<td> <td>
<%= link_to web_link.name[I18n.locale], panel_web_resource_back_end_web_link_path(web_link) %> <%= link_to web_link.title, panel_web_resource_back_end_web_link_path(web_link) %>
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills hide"> <ul class="nav nav-pills hide">
<%if at_least_module_manager || web_link.web_link_category.cur_user_is_sub_manager_of(:edit)%> <%if at_least_module_manager || web_link.web_link_category.cur_user_is_sub_manager_of(:edit)%>

View File

@ -1,57 +0,0 @@
<% # encoding: utf-8 %>
<br />
<br />
<br />
<p id="notice"><%= flash_messages %></p>
<ul>
<li>
<b><%= t('announcement.category') %></b>
<%= @bulletin.bulletin_category.i18n_variable[I18n.locale] rescue nil %>
</li>
<li>
<b><%= t('announcement.postdate') %></b>
<%= display_date(@bulletin.postdate) %>
</li>
<li>
<b><%= t('announcement.title') %></b>
<%= @bulletin.title %>
</li>
<li>
<%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
<%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
</li>
<li>
<b><%= t('announcement.subtitle') %></b>
<%= @bulletin.subtitle %>
</li>
<li>
<b><%= t('announcement.text') %></b>
<%= @bulletin.text %>
</li>
<li>
<li>
<b><%= t('announcement.link') %></b>
<% @bulletin.bulletin_links.each do | blink | %>
<%= link_to blink.name, blink.url, :target => '_blank' %>
<% end %>
</li>
<li>
<b><%= t('announcement.file') %></b>
<% @bulletin.bulletin_files.each do | bfile | %>
<%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
<% end %>
</li>
<li>
<b><%= t('announcement.張貼者') %></b>
<%= User.find(@bulletin.create_user_id).name %>
</li>
<li>
<b><%= t('announcement.最後修改時間') %></b>
<%= display_date(@bulletin.updated_at) %>
</li>
<%= link_back %>

View File

@ -15,10 +15,10 @@
<% @web_links.each do |post| %> <% @web_links.each do |post| %>
<tr> <tr>
<td><%= post.web_link_category.i18n_variable[I18n.locale] rescue nil %></td> <td><%= post.web_link_category.title rescue nil %></td>
<td> <td>
<%#= link_to post.name[I18n.locale], panel_web_resource_front_end_web_link_path(post) %> <%#= link_to post.title, panel_web_resource_front_end_web_link_path(post) %>
<%= link_to post.name[I18n.locale], post.url, {:target => '_blank', :title => post.name[I18n.locale]} %> <%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %>
</td> </td>
</tr> </tr>

View File

@ -1,57 +0,0 @@
<% # encoding: utf-8 %>
<br />
<br />
<br />
<p id="notice"><%= flash_messages %></p>
<ul>
<li>
<b><%= t('announcement.category') %></b>
<%= @bulletin.bulletin_category.i18n_variable[I18n.locale] rescue nil %>
</li>
<li>
<b><%= t('announcement.postdate') %></b>
<%= display_date(@bulletin.postdate) %>
</li>
<li>
<b><%= t('announcement.title') %></b>
<%= @bulletin.title %>
</li>
<li>
<%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
<%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
</li>
<li>
<b><%= t('announcement.subtitle') %></b>
<%= @bulletin.subtitle %>
</li>
<li>
<b><%= t('announcement.text') %></b>
<%= @bulletin.text %>
</li>
<li>
<li>
<b><%= t('announcement.link') %></b>
<% @bulletin.bulletin_links.each do | blink | %>
<%= link_to blink.name, blink.url, :target => '_blank' %>
<% end %>
</li>
<li>
<b><%= t('announcement.file') %></b>
<% @bulletin.bulletin_files.each do | bfile | %>
<%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
<% end %>
</li>
<li>
<b><%= t('announcement.張貼者') %></b>
<%= User.find(@bulletin.create_user_id).name %>
</li>
<li>
<b><%= t('announcement.最後修改時間') %></b>
<%= display_date_time(@bulletin.updated_at) %>
</li>
<%#= link_back %>

View File

@ -1,6 +1,6 @@
<ul> <ul>
<% @web_links.each do |widget| -%> <% @web_links.each do |widget| -%>
<li><%= link_to widget.name[I18n.locale], widget.url, {:target => '_blank', :title => widget.name[I18n.locale]} %></li> <li><%= link_to widget.title, widget.url, {:target => '_blank', :title => widget.title} %></li>
<% end -%> <% end -%>
</ul> </ul>

View File

@ -1,5 +1,5 @@
<% if @current_category %> <% if @current_category %>
<h1 class="h1"><%= @current_category.i18n_variable[I18n.locale] + " " + t('web_resource.list_lower') %></h1> <h1 class="h1"><%= @current_category.title + " " + t('web_resource.list_lower') %></h1>
<% elsif @tag %> <% elsif @tag %>
<h1 class="h1"><%= @tag[I18n.locale] + " " + t('web_resource.list_lower') %></h1> <h1 class="h1"><%= @tag[I18n.locale] + " " + t('web_resource.list_lower') %></h1>
<% else %> <% else %>
@ -14,9 +14,9 @@
</tr> </tr>
<% @web_links.each do |post| %> <% @web_links.each do |post| %>
<tr> <tr>
<td><%= post.web_link_category.i18n_variable[I18n.locale] rescue nil %></td> <td><%= post.web_link_category.title rescue nil %></td>
<td> <td>
<%= link_to post.name[I18n.locale], post.url, {:target => '_blank', :title => post.name[I18n.locale]} %> <%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %>
</td> </td>
</tr> </tr>
<% end %> <% end %>