web_resource rake web_link_url:web_link_url_i18n

This commit is contained in:
Spen 2013-04-10 15:26:57 +08:00 committed by Matt K. Fu
parent aedab01ae6
commit c94a86c3a4
18 changed files with 307 additions and 113 deletions

View File

@ -0,0 +1,52 @@
# encoding: utf-8
namespace :web_link_url do
task :web_link_url_i18n => :environment do
puts 'start'
@weblinks = WebLink.all
@weblinks.each do |wl|
if wl.url.nil?
@wlurl = wl.url_translations
wl.url_translations = {}
wl.url_translations["zh_tw"] = @wlurl
wl.url_translations["en"] = @wlurl
wl.save
else
puts 'no data'
end
end
puts 'end'
puts @weblinks.count
end
task :web_link_url_i18n_test => :environment do
@test = WebLink.find("50aca25583e75204c00009f4")
@testurl = @test.url_translations
@test.url_translations = {}
@test.url_translations["zh_tw"] = @testurl
@test.url_translations["en"] = @testurl
@test.save
end
end

View File

@ -0,0 +1,69 @@
/* General style with default layout */
.o-links {}
.o-links-group {
margin: 20px 0 0 0;
padding: 20px 0 0 0;
border-top: dashed 1px #EEE;
}
.o-links-group:first-child {
margin: 0;
padding: 0;
border: 0;
}
.o-links-category {
padding-bottom: 16px;
border-bottom: solid 2px #CCC;
font-weight: bold;
}
.o-links-content {}
.o-links-content > ul {
margin: 0;
padding: 0;
list-style: none;
}
.o-links-content > ul > li {}
.o-links-list {}
.o-links-list > ul {}
.o-links-list > ul > li {
padding: 10px 0 0 0;
margin: 10px 0 0 0;
border-top: solid 1px #eee;
}
.o-links-list > ul > li:first-child {
padding: 0;
margin: 0;
border: 0;
}
.o-links-title {}
.o-links-link {
font-weight: bold;
}
.o-links-link:hover {}
.o-links-description {}
/* Tag list */
.o-links-tag-list {
margin: 0 0 16px 0;
}
.o-links-tag-list ul {
margin: 0 -4px;
padding: 0;
list-style: none;
}
.o-links-tag-list ul:after {
content: ".";
clear: both;
display: block;
height: 0;
visibility: hidden;
}
.o-links-tag-list li {
float: left;
margin: 0 4px 8px 4px;
}
.o-links-tag {
display: block;
border: solid 1px #ccc;
padding: 2px 6px;
}
.o-links-tag:hover {}

View File

@ -10,32 +10,48 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController
def index
date_now = Time.now
@item = Page.find(params[:page_id])
@title = @item.title
if @item.frontend_data_count
@page_num = @item.frontend_data_count
else
@page_num = 0
end
date_now = Time.now
@archive_file_categorys = WebLinkCategory.all
if !params[:category_id].blank?
@web_links = WebLink.where( :is_hidden => false ).where(:web_link_category_id => params[:category_id]).desc( :is_top ).page( params[:page_main] ).per(10)
@current_category = WebLinkCategory.from_id(params[:category_id]) rescue nil
@web_links = WebLink.all.can_display.any_in(:web_link_category_id => params[:category_id]).merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@web_link_categorys = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@tag = WebResourceTag.find(params[:tag_id]) rescue nil
@tag = WebResourceTag.where(key: params[:tag_id])[0] unless @tag
@web_links = @tag.archive_files.where( :is_hidden => false ).desc( :is_top ).page( params[:page_main] ).per(10)
@web_links = @tag.web_links.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
get_categorys
else
@web_links = WebLink.where( :is_hidden => false ).desc( :is_top ).page( params[:page_main] ).per(10)
@web_links = WebLink.all.can_display.merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
get_categorys
end
get_categorys
end
def show
@item = Page.find(params[:page_id])
@title = @item.title
@web_link = WebLink.find(params[:id])
get_categorys
get_categorys
end
protected
def get_categorys
@web_link_categorys = WebLinkCategory.all
@web_link_categorys = WebLinkCategory.excludes('disabled' => true)
end
end

View File

@ -7,52 +7,44 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
# GET /web_links
# GET /web_links.xml
def index
@part = PagePart.find(params[:part_id])
if @part.widget_data_count
@page_num = @part.widget_data_count
else
@page_num = 4
end
if @part.widget_field
@widget_fields = @part.widget_field
else
@widget_fields = []
end
@widget_style = @part.widget_style
@category_id = @part.category
date_now = Time.now
if !params[:category_id].blank?
@web_links = WebLink.where(:web_link_category => params[:category_id]).available_for_lang(I18n.locale).desc( :is_top, :postdate).page( params[:page]).per(10)
@current_category = WebLinkCategory.from_id(params[:category_id]) rescue nil
@web_links = WebLink.all.can_display.any_in(:web_link_category_id => params[:category_id]).merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@web_link_categorys = WebLinkCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@tag = WebResourceTag.find(params[:tag_id]) rescue nil
@tag = WebResourceTag.where(key: params[:tag_id])[0] unless @tag
@web_links = @tag.web_links.desc( :is_top, :postdate).page( params[:page]).per(10)
get_categorys
else
@web_links = WebLink.available_for_lang(I18n.locale).desc( :is_top, :postdate).page( params[:page]).per(10)
@web_links = WebLink.all.can_display.merge(WebLinkCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
get_categorys
end
end
def home_list
@title = params[:part_title]
# deadline
# @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :title).first
@web_links = WebLink.widget_datas.available_for_lang(I18n.locale).page(params[:page]).per(5)
# get_categorys
module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id})
end
def reload_web_links
@web_links = WebLink.widget_datas.available_for_lang(I18n.locale).page(params[:page]).per(5)
end
protected
def get_categorys
@web_link_categorys = WebLinkCategory.all
end
def get_tags
module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id}) rescue []
@web_link_categorys = WebLinkCategory.excludes('disable' => true)
end
end

View File

@ -12,7 +12,7 @@ class WebLink
has_and_belongs_to_many :tags, :class_name => "WebResourceTag"
field :url
field :url, localize: true
field :create_user_id
field :update_user_id
@ -20,6 +20,8 @@ class WebLink
field :is_hot, :type => Boolean, :default => false
field :is_hidden, :type => Boolean, :default => false
scope :can_display,where(is_hidden: false)
belongs_to :web_link_category
before_save :update_avliable_language, :clean_tags
@ -27,7 +29,7 @@ class WebLink
validates :title, :at_least_one => true
before_validation :add_http
validates :url, :presence => true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?/i
# validates :url, :presence => true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?/i
def self.search( category_id = nil )

View File

@ -0,0 +1,3 @@
<div class="filter-clear">
<%= link_to content_tag(:i, nil, :class => 'icons-cycle') + t(:clear), panel_web_resource_back_end_web_links_path(:filter => @filter, :sort => params[:sort], :direction => params[:direction], :clear => true, :type => type), :class => "btn btn-small js_history" %>
</div>

View File

@ -0,0 +1,6 @@
<div class="accordion-inner" data-toggle="buttons-checkbox">
<% @web_link_categories.each do |category| -%>
<%= link_to category.title, panel_web_resource_back_end_web_links_path(:filter => @filter, :new_filter => {:type => 'categories', :id => category.id}, :sort => params[:sort], :direction => params[:direction], :sort_options => params[:sort_options]), :class => "btn btn-small js_history#{is_filter_active?('categories', category.id)}" %>
<% end -%>
</div>
<%= render :partial => 'clear_filters', :locals => {:type => 'categories'} %>

View File

@ -0,0 +1,6 @@
<div class="accordion-inner" data-toggle="buttons-checkbox">
<%= link_to t(:top), panel_web_resource_back_end_web_links_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_top'}, :sort => params[:sort], :direction => params[:direction], :sort_options => params[:sort_options]), :class => "btn btn-small js_history#{is_filter_active?('status', 'is_top')}" %>
<%= link_to t(:hot), panel_web_resource_back_end_web_links_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_hot'}, :sort => params[:sort], :direction => params[:direction], :sort_options => params[:sort_options]), :class => "btn btn-small js_history#{is_filter_active?('status', 'is_hot')}" %>
<%= link_to t(:hidden), panel_web_resource_back_end_web_links_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_hidden'}, :sort => params[:sort], :direction => params[:direction], :sort_options => params[:sort_options]), :class => "btn btn-small js_history#{is_filter_active?('status', 'is_hidden')}" unless(is_guest?)%>
</div>
<%= render :partial => 'clear_filters', :locals => {:type => 'status'} %>

View File

@ -0,0 +1,6 @@
<div class="accordion-inner" data-toggle="buttons-checkbox">
<% @tags.each do |tag| -%>
<%= link_to tag[I18n.locale], panel_web_resource_back_end_web_links_path(:filter => @filter, :new_filter => {:type => 'tags', :id => tag.id}, :sort => params[:sort], :direction => params[:direction], :sort_options => params[:sort_options]), :class => "btn btn-small js_history#{is_filter_active?('tags', tag.id)}" %>
<% end -%>
</div>
<%= render :partial => 'clear_filters', :locals => {:type => 'tags'} %>

View File

@ -85,17 +85,20 @@
<% end %>
</div>
<div class="title">
<%= f.label :url , t(:url) %>
<%= f.fields_for :url_translations do |f| %>
<%= I18nVariable.from_locale(locale) %>
<%= f.text_field locale, :class=>'post-title', :value => (@web_link.url_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
<% end %>
</div>
<div class="title">
<%= f.label :url, t('nccu.url') %>
<%= f.text_field :url %>
</div>
</div>
<!--Post End-->

View File

@ -21,7 +21,8 @@
</td>
<td><%= web_link.web_link_category.title rescue nil %></td>
<td>
<%= link_to web_link.title, 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) %>
<%= link_to web_link.title, web_link.url, {:target => '_blank', :title => web_link.title} %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<%if at_least_module_manager || web_link.web_link_category.cur_user_is_sub_manager_of(:edit)%>

View File

@ -1,24 +1,34 @@
<% # encoding: utf-8 %>
<%= flash_messages %>
<div class="o-links">
<div class="o-links-content">
<ul>
<!-- <h1><%#= t('web_link.list_web_resource') %></h1> -->
<% @web_link_categorys.each do |wlcg| %>
<% if wlcg.web_links.count > 0 %>
<li>
<h3 class="o-links-category"><%= wlcg.title rescue nil%></h3>
<div class="o-links-list">
<ul>
<h3><%= @current_category.title rescue nil %></h3>
<table>
<tr>
<th><%= t(:category) %></th>
<th><%= t(:name) %></th>
</tr>
<% wlcg.web_links.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num).each do |post| %>
<li>
<%= link_to post.title, post.url, {:target => '_blank', :title => post.title, :class=>"o-links-title"} %>
<div class="o-links-description"><%= post.context %></div>
</li>
<% end %>
<% @web_links.each do |post| %>
<tr>
<td><%= post.web_link_category.title rescue nil %></td>
<td><%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %></td>
</tr>
</ul>
</div>
</li>
<% end %>
<% end %>
<% end %>
</table>
</ul>
</div>
</div>
<%= paginate @web_links, :param_name => :page_main, :params => {:inner => false}%>
<%= stylesheet_link_tag "web_resource/links" %>

View File

@ -1,27 +1,36 @@
<% if @current_category %>
<h1 class="h1"><%= @current_category.title + " " + t(:list_lower) %></h1>
<% elsif @tag %>
<h1 class="h1"><%= @tag[I18n.locale] + " " + t(:list_lower) %></h1>
<div class="o-links">
<div class="o-links-content">
<ul>
<% @web_link_categorys.each do |wlcg| %>
<% if wlcg.web_links.count > 0 %>
<li>
<h3 class="o-links-category"><%= wlcg.title rescue nil%></h3>
<div class="o-links-list">
<ul>
<% wlcg.web_links.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num).each do |post| %>
<li>
<%= link_to post.title, post.url, {:target => '_blank', :title => post.title, :class=>"o-links-title"} %>
<div class="o-links-description"><%= post.context %></div>
</li>
<% end %>
</ul>
</div>
</li>
<% end %>
<% end %>
</ul>
</div>
</div>
<div class="pull_right">
<% if !params[:category_id].blank? %>
<%= link_to t(:more_plus), panel_web_resource_front_end_web_links_path(:category_id => @part.category) %>
<% else %>
<h1 class="h1"><%= t('list.link') %></h1>
<%= link_to t(:more_plus), panel_web_resource_front_end_web_links_path %>
<% end %>
<table class="table table-bordered">
<tbody>
<tr>
<th><%= t(:category) %></th>
<th><%= t(:name) %></th>
</tr>
<% @web_links.each do |post| %>
<tr>
<td><%= post.web_link_category.title rescue nil %></td>
<td>
<%= link_to post.title, post.url, {:target => '_blank', :title => post.title} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%#= paginate @web_links, :params => {:inner => 'true'}, :remote => true %>
<%= paginate @web_links, :params => {:inner => 'false'}, :remote => true %>
</div>

View File

@ -1,3 +1,7 @@
<div id="web_link_widget">
<%= render 'index' %>
</div>
<%= stylesheet_link_tag "web_resource/links" %>

View File

@ -1,5 +1,12 @@
en:
web_resource:
web_link: Web resource
frontend:
web_link: Web resource Frontend
widget:
index: Web resource Widget
web_link:
create_web_link_category_success: Web resource category was successfully created
editing_web_resource: Editing web resource

View File

@ -1,5 +1,12 @@
zh_tw:
web_resource:
web_link: 網路資源
frontend:
web_link: 網路資源前台
widget:
index: 網路資源Widget
web_link:
create_web_link_category_success: 網路資源類別已成功建立
editing_web_resource: 編輯網路資源

View File

@ -1,24 +1,21 @@
Rails.application.routes.draw do
namespace :panel do
namespace :web_resource do
namespace :back_end do
root :to => "web_links#index"
resources :web_links do
collection do
get 'delete'
end
end
resources :web_link_categorys
resources :web_link_categorys
resources :tags
end
namespace :front_end do
match "web_links" => "web_links#index"
resources :web_links
end
namespace :widget do
match "web_links" => "web_links#index"
match "home_list" => "web_links#home_list"
match "reload_web_links" => "web_links#reload_web_links"
match "index" => "web_links#index"
end
end
end

View File

@ -10,7 +10,11 @@ module WebResource
intro "I am intro"
update_info 'some update_info'
category ["WebLinkCategory"]
front_end do
app_page 'web_links' do
frontend_i18n "web_resource.frontend.web_link"
end
end
widgets do
# default_widget do
@ -18,11 +22,11 @@ module WebResource
# image :image
# end
categories_query 'BulletinCategory.all'
categories_query 'WebLinkCategory.all'
tags_query 'WebResourceTag.all'
customize_widget "home_list" do
widget_i18n "web_resource.widget.home_list"
customize_widget "index" do
widget_i18n "web_resource.widget.index"
end
end