From c94a86c3a4adbdcd67b646b757c913a77e6c1cda Mon Sep 17 00:00:00 2001 From: Spen Date: Wed, 10 Apr 2013 15:26:57 +0800 Subject: [PATCH] web_resource rake web_link_url:web_link_url_i18n --- lib/tasks/web_link_url.rake | 52 ++++++++++++++ .../assets/stylesheets/web_resource/links.css | 69 +++++++++++++++++++ .../front_end/web_links_controller.rb | 46 +++++++++---- .../widget/web_links_controller.rb | 64 ++++++++--------- .../web_resource/app/models/web_link.rb | 6 +- .../web_links/_clear_filters.html.erb | 3 + .../web_links/_filter_categories.html.erb | 6 ++ .../web_links/_filter_status.html.erb | 6 ++ .../back_end/web_links/_filter_tags.html.erb | 6 ++ .../back_end/web_links/_form.html.erb | 13 ++-- .../back_end/web_links/_web_link.html.erb | 3 +- .../front_end/web_links/index.html.erb | 44 +++++++----- .../widget/web_links/_index.html.erb | 59 +++++++++------- .../widget/web_links/index.html.erb | 6 +- .../web_resource/config/locales/en.yml | 7 ++ .../web_resource/config/locales/zh_tw.yml | 7 ++ .../web_resource/config/routes.rb | 11 ++- vendor/built_in_modules/web_resource/init.rb | 12 ++-- 18 files changed, 307 insertions(+), 113 deletions(-) create mode 100644 lib/tasks/web_link_url.rake create mode 100755 vendor/built_in_modules/web_resource/app/assets/stylesheets/web_resource/links.css create mode 100644 vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_clear_filters.html.erb create mode 100644 vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_categories.html.erb create mode 100644 vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_status.html.erb create mode 100644 vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_tags.html.erb diff --git a/lib/tasks/web_link_url.rake b/lib/tasks/web_link_url.rake new file mode 100644 index 00000000..eccb90c4 --- /dev/null +++ b/lib/tasks/web_link_url.rake @@ -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 \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/assets/stylesheets/web_resource/links.css b/vendor/built_in_modules/web_resource/app/assets/stylesheets/web_resource/links.css new file mode 100755 index 00000000..f6b9561f --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/assets/stylesheets/web_resource/links.css @@ -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 {} \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb index f99ce86b..f803e9c7 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb @@ -7,35 +7,51 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController # GET /web_links # GET /web_links.xml - + def index + + @item = Page.find(params[:page_id]) + + @title = @item.title - date_now = Time.now - + 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 + end + + def show + @item = Page.find(params[:page_id]) + @title = @item.title + @web_link = WebLink.find(params[:id]) get_categorys end - def show - @web_link = WebLink.find(params[:id]) - get_categorys - end - - protected - + def get_categorys - @web_link_categorys = WebLinkCategory.all + @web_link_categorys = WebLinkCategory.excludes('disabled' => true) end end diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb index deb9d0c8..0693d305 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/widget/web_links_controller.rb @@ -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 diff --git a/vendor/built_in_modules/web_resource/app/models/web_link.rb b/vendor/built_in_modules/web_resource/app/models/web_link.rb index 68b94cff..f5f8028c 100644 --- a/vendor/built_in_modules/web_resource/app/models/web_link.rb +++ b/vendor/built_in_modules/web_resource/app/models/web_link.rb @@ -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 ) diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_clear_filters.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_clear_filters.html.erb new file mode 100644 index 00000000..142e1833 --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_clear_filters.html.erb @@ -0,0 +1,3 @@ +
+ <%= 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" %> +
\ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_categories.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_categories.html.erb new file mode 100644 index 00000000..f601e3bc --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_categories.html.erb @@ -0,0 +1,6 @@ +
+ <% @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 -%> +
+<%= render :partial => 'clear_filters', :locals => {:type => 'categories'} %> \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_status.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_status.html.erb new file mode 100644 index 00000000..a138f524 --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_status.html.erb @@ -0,0 +1,6 @@ +
+ <%= 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?)%> +
+<%= render :partial => 'clear_filters', :locals => {:type => 'status'} %> \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_tags.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_tags.html.erb new file mode 100644 index 00000000..1cd21900 --- /dev/null +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_filter_tags.html.erb @@ -0,0 +1,6 @@ +
+ <% @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 -%> +
+<%= render :partial => 'clear_filters', :locals => {:type => 'tags'} %> \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb index fbef1954..70654690 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_form.html.erb @@ -84,17 +84,20 @@ <%= f.text_area locale, :style=>"width:100%", :value => (@web_link.context_translations[locale] rescue nil) %> <% end %> + +
+ <%= 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 %> +
<% end %> - -
- <%= f.label :url, t('nccu.url') %> - <%= f.text_field :url %> -
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb index 7032d761..aae595a6 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb @@ -21,7 +21,8 @@ <%= web_link.web_link_category.title rescue nil %> - <%= 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} %>
+ + + +<%= stylesheet_link_tag "web_resource/links" %> \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/config/locales/en.yml b/vendor/built_in_modules/web_resource/config/locales/en.yml index 570c6a53..e5eac0c7 100644 --- a/vendor/built_in_modules/web_resource/config/locales/en.yml +++ b/vendor/built_in_modules/web_resource/config/locales/en.yml @@ -1,5 +1,12 @@ en: + web_resource: + web_link: Web resource + frontend: + web_link: Web resource Front-end + widget: + index: Web resource Widget + web_link: create_web_link_category_success: Web resource category was successfully created editing_web_resource: Editing web resource diff --git a/vendor/built_in_modules/web_resource/config/locales/zh_tw.yml b/vendor/built_in_modules/web_resource/config/locales/zh_tw.yml index 6976e6cb..b49e7800 100644 --- a/vendor/built_in_modules/web_resource/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/web_resource/config/locales/zh_tw.yml @@ -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: 編輯網路資源 diff --git a/vendor/built_in_modules/web_resource/config/routes.rb b/vendor/built_in_modules/web_resource/config/routes.rb index d585c6b3..0ab9fa1d 100644 --- a/vendor/built_in_modules/web_resource/config/routes.rb +++ b/vendor/built_in_modules/web_resource/config/routes.rb @@ -1,24 +1,21 @@ -Rails.application.routes.draw do - +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 diff --git a/vendor/built_in_modules/web_resource/init.rb b/vendor/built_in_modules/web_resource/init.rb index 4827211d..9f52da85 100644 --- a/vendor/built_in_modules/web_resource/init.rb +++ b/vendor/built_in_modules/web_resource/init.rb @@ -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