announcement widget query
This commit is contained in:
parent
3e912b6262
commit
4cfae9c107
|
@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
|
|||
def front_end_available(module_app_title='')
|
||||
app_controller = ModuleApp.first(conditions: {:title => module_app_title} )
|
||||
unless app_controller.enable_frontend?
|
||||
render :nothing
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
</r:content>
|
||||
<div class="dymanic_load" path="/panel/new_blog/widget/latest_post"></div>
|
||||
<div class="dymanic_load" path="/panel/new_blog/widget/"></div>
|
||||
<div class="dymanic_load" path="/panel/announcement/widget/"></div>
|
||||
</div>
|
||||
|
||||
<div id="footer" class="footer">
|
||||
|
|
|
@ -12,11 +12,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
|||
|
||||
# @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id]
|
||||
|
||||
if params[:search]
|
||||
@bulletins = Bulletin.search(params[:search])
|
||||
else
|
||||
@bulletins = Bulletin.desc( :is_top, :postdate)
|
||||
end
|
||||
@bulletins = Bulletin.search(params[:search],params[:category_id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
class Panel::Announcement::Widget::BulletinsController < ObitWidgetController
|
||||
|
||||
def initialize
|
||||
super
|
||||
@app_title = NewBlog::MOUDLEAPP_TITLE
|
||||
end
|
||||
|
||||
# GET /bulletins
|
||||
# GET /bulletins.xml
|
||||
|
||||
def index
|
||||
|
||||
# deadline
|
||||
|
||||
@bulletin = Bulletin.where( :postdate.lte => Date.today ).desc(:is_top, :postdate).first
|
||||
|
||||
@bulletins = Bulletin.widget_datas
|
||||
|
||||
get_categorys
|
||||
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def get_categorys
|
||||
@bulletin_categorys = BulletinCategory.excludes('disabled' => true)
|
||||
end
|
||||
|
||||
end
|
|
@ -33,13 +33,43 @@ class Bulletin
|
|||
after_save :save_bulletin_files
|
||||
|
||||
|
||||
def self.search(search)
|
||||
|
||||
find(:all, :conditions => {title: search}).desc( :is_top, :postdate)
|
||||
def self.search( search = nil, category_id = nil )
|
||||
|
||||
if category_id.to_s.size > 0 and search.to_s.size > 0
|
||||
|
||||
key = /#{search}/
|
||||
|
||||
find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate )
|
||||
|
||||
elsif category_id.to_s.size > 0 and search.to_s.size < 1
|
||||
|
||||
find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate )
|
||||
|
||||
elsif search.to_s.size > 0 and category_id.to_s.size < 1
|
||||
|
||||
key = /#{search}/
|
||||
|
||||
find(:all, :conditions => {title: key}).desc( :is_top, :postdate )
|
||||
else
|
||||
|
||||
find(:all).desc( :is_top, :postdate)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.widget_datas
|
||||
|
||||
date_now = Date.today
|
||||
|
||||
# find(:all, :conditions => {:postdate => {"$lte" => Date.today}, deadline: nil} ).desc( :is_top, :postdate)
|
||||
where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate)
|
||||
# any_of({ :title => "test" },{:deadline => nil, :title => "123"})
|
||||
|
||||
end
|
||||
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
|
|
@ -23,7 +23,9 @@
|
|||
|
||||
<%= form_for :bulletin, :action => 'search', :method => 'get', :url => panel_announcement_back_end_bulletins_path do |f| %>
|
||||
|
||||
Category <%= f.select :bulletin_category_id, @bulletin_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ] },{ :include_blank => t('bulletin.select') }%>
|
||||
<%#= f.select :bulletin_category_id, @bulletin_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ] },{ :include_blank => t('bulletin.select') }%>
|
||||
|
||||
Category <%= select_tag "category_id", options_for_select(@bulletin_categorys.collect{|t| [t.i18n_variable[I18n.locale], t.id]}), :prompt => t('bulletin.select') %>
|
||||
|
||||
KeyWord <%= text_field_tag :search, params[:search], :id => 'search_field' %>
|
||||
|
||||
|
|
|
@ -4,31 +4,30 @@
|
|||
|
||||
<h1><%= t('bulletin.list_announcement') %></h1>
|
||||
|
||||
<% @bulletin_categorys.each do |t| %>
|
||||
|
||||
<h4><%= t.name %></h4>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th><%= t('bulletin.category') %></th>
|
||||
<th><%= t('bulletin.status') %></th>
|
||||
<th><%= t('bulletin.postdate') %></th>
|
||||
<th><%= t('bulletin.deadline') %></th>
|
||||
<th><%= t('bulletin.category') %></th>
|
||||
<th><%= t('bulletin.title') %></th>
|
||||
<th><%= t('bulletin.text') %></th>
|
||||
</tr>
|
||||
|
||||
<% @bulletins.each do |post| %>
|
||||
<tr>
|
||||
<td><%= post.bulletin_category.name rescue nil %></td>
|
||||
<td></td>
|
||||
<td><%= post.postdate %></td>
|
||||
<td><%= link_to post.title, panel_announcement_front_end_bulletin_path(post) %></td>
|
||||
<td><%= post.text %></td>
|
||||
<td><%= (post.deadline) ? post.deadline : t('bulletin.no_deadline') %></td>
|
||||
<td><%= post.bulletin_category.i18n_variable[I18n.locale] %></td>
|
||||
<td><%= link_to post.title, panel_announcement_front_end_bulletin_path(post) %>
|
||||
<%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% end %>
|
||||
|
||||
</table>
|
||||
|
||||
<% end %>
|
||||
|
||||
<br />
|
||||
|
||||
|
|
|
@ -1,40 +1,57 @@
|
|||
<% # encoding: utf-8 %>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<p id="notice"><%= flash_messages %></p>
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
<li>
|
||||
<b><%= t('announcement.category') %></b>
|
||||
<%= @bulletin.bulletin_category.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= @bulletin.bulletin_category.i18n_variable[I18n.locale] %>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.postdate') %></b>
|
||||
<%= @bulletin.postdate %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.title') %></b>
|
||||
<%= @bulletin.title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
</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_filename} if @bulletin.image.file %>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.subtitle') %></b>
|
||||
<%= @bulletin.subtitle %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b><%= t('announcement.image') %></b>
|
||||
<%= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.text') %></b>
|
||||
<%= @bulletin.text %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
</li>
|
||||
<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>
|
||||
<% if @bulletin.url? %>
|
||||
<b><%= t('announcement.url') %></b>
|
||||
<%= link_to @bulletin.url, @bulletin.url, :target => '_blank' %>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.張貼者') %></b>
|
||||
<%= User.find(@bulletin.create_user_id).name %>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.最後修改時間') %></b>
|
||||
<%= @bulletin.updated_at %>
|
||||
</p>
|
||||
</li>
|
||||
|
||||
|
||||
<%= link_back %>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
|
||||
<div id="col1" class="col">
|
||||
|
||||
<h1 class="h1 ini_heading col_title"><%= @bulletin.title %></h1>
|
||||
<p class="ini_txt"><%= @bulletin.subtitle %></p>
|
||||
<%= link_to "read more >",panel_announcement_front_end_bulletin_path(@bulletin.id) %>
|
||||
<a class="btn" href="">read more ></a>
|
||||
</div>
|
||||
|
||||
<div id="col2" class="col">
|
||||
<h1 class="h1 ini_heading col_title">news</h1>
|
||||
<ul class="ini_list">
|
||||
<% @bulletins.each do |post| %>
|
||||
<li><span class="time"><%= post.postdate.to_s.gsub("-", "") %></span><%= link_to post.title,panel_announcement_front_end_bulletin_path(post) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= link_to "read more >",panel_announcement_front_end_bulletins_path(), :class => "btn" %>
|
||||
<a class="btn" href="announcement">read more ></a>
|
||||
</div>
|
|
@ -11,7 +11,9 @@ Rails.application.routes.draw do
|
|||
root :to => "bulletins#index"
|
||||
resources :bulletins
|
||||
match "show/:id" => "bulletins#show" ,:as => :bulletin
|
||||
# match "comments" => "comments#create",:as => :comments
|
||||
end
|
||||
namespace :widget do
|
||||
root :to => "bulletins#index"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue