FIX dynamic_news search

This commit is contained in:
Jasder 2019-10-21 16:47:21 +08:00
parent fdcc46afef
commit 50e31873dc
8 changed files with 110 additions and 89 deletions

View File

@ -714,11 +714,17 @@ class AdminController < ApplicationController
# 动态消息列表
def dynamic_news
scope = DynamicNew.desc
@category_id = params[:category_id] || 0
scope = DynamicNew.desc.like(params[:title])
scope = scope.by_category(@category_id.to_i) unless @category_id.to_i == 0
@dynamic_news_count = scope.count
@dynamic_news = paginateHelper scope, 15
@page = (params['page'] || 1).to_i - 1
respond_to do |format|
format.js
format.html
end
end
# 单位审核

View File

@ -24,4 +24,8 @@ module AdminHelper
[l(:project_status_closed), '5'],
[l(:project_status_archived), '9']], selected.to_s)
end
def dynamic_news_category_options_for_select(selected)
options_for_select(Category.all.collect{|item| [item.name, item.id]}.insert(0, ['全部', 0]), selected)
end
end

View File

@ -3,7 +3,9 @@ class DynamicNew < ActiveRecord::Base
validates_presence_of :title, :simple_intruduce, :category_id
scope :desc, -> { order('id desc') }
scope :desc, -> { order('id desc') }
scope :like, ->(q) { where("title LIKE ?", "#{q.to_s.strip.downcase}") unless q.blank? }
scope :by_category, ->(category_id) { where(category_id: category_id) }
def cover_url
cover_remote_url || "/images/dynamic_new/default.png"

View File

@ -0,0 +1,75 @@
<table class="list" style="width: 100%;table-layout: fixed">
<thead>
<tr>
<th style="width: 15px;">
序号
</th>
<th style="width: 40px;">
封面
</th>
<th style="width: 60px;">
标题
</th>
<th style="width: 60px;" class = "">
简介
</th>
<th style="width: 60px;" class = "">
所属分类
</th>
<th style="width: 50px;">
创建时间
</th>
<th style="width: 80px;">
</th>
</tr>
</thead>
<tbody>
<% @count= @page * 15 %>
<% @dynamic_news.each do |dynamic_new| %>
<tr class="<%= cycle("odd", "even") %>">
<!td style="text-align:center;vertical-align: middle;">
<!%= dynamic_new.id %>
<% @count +=1 %>
<td align="center">
<%=@count %>
</td>
<td align="center">
<%= image_tag(dynamic_new.cover_url, width:40, height:40) %>
<!%= dynamic_new.title %>
</td>
<td style="text-align:center;vertical-align: middle;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=dynamic_new.title%>'>
<span>
<%= link_to dynamic_new.title, dynamic_new.remote_url %>
</span>
</td>
<td style="vertical-align: middle;text-align:center">
<%= truncate(dynamic_new.simple_intruduce, :length => 30) %>
</td>
<td style="vertical-align: middle;text-align:center">
<%= dynamic_new.category&.name %>
</td>
<td style="vertical-align: middle;text-align:center">
<%= format_time(dynamic_new.created_at) %>
</td>
<td class="buttons" style="vertical-align: middle;text-align:center">
<%= link_to("修改", upload_logo_school_path(dynamic_new.id,:school_name => @school_name), :class => 'icon icon-copy') %>
<%#= link_to(l(:button_delete), organization_path(school.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="pagination">
<%= pagination_links_full @obj_pages, @obj_count ,:per_page_links => true, :remote => true, :flag => true, :is_new => true %>
</div>
<script>
function delcfm() {
if (!confirm("删除项目会一并删除项目的关联信息,确认要删除吗?")) {
window.event.returnValue = false;
}
}
</script>

View File

@ -7,93 +7,24 @@
</h3>
<%= form_tag({}, :method => :get) do %>
<fieldset>
<legend>
<%= l(:label_filter_plural) %>
</legend>
<label for='status'>
<%= l(:field_status) %> :
</label>
<%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
<label for='name'>
<%= l(:label_project) %>:
</label>
<%= text_field_tag 'name', params[:name], :size => 30, :placeholder => '输入项目名称进行搜索' %>
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
<%= link_to l(:button_clear), {:controller => 'admin', :action => 'dynamic_news'}, :class => 'icon icon-reload' %>
</fieldset>
<fieldset>
<legend>
<%= l(:label_filter_plural) %>
</legend>
<label for='status'>
<%= l(:field_category) %> :
</label>
<%= select_tag 'category_id', dynamic_news_category_options_for_select(@category_id), :class => "small", :onchange => "this.form.submit(); return false;" %>
<label for='name'>
<%= l(:label_project) %>:
</label>
<%= text_field_tag 'title', params[:title], :size => 30, :placeholder => '输入新闻标题进行搜索' %>
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
<%= link_to l(:button_clear), {:controller => 'admin', :action => 'dynamic_news'}, :class => 'icon icon-reload' %>
</fieldset>
<% end %>
&nbsp;
<div class="autoscroll">
<table class="list" style="width: 100%;table-layout: fixed">
<thead>
<tr>
<th style="width: 35px;">
序号
</th>
<th style="width: 60px;">
封面
</th>
<th style="width: 100px;">
标题
</th>
<th style="width: 35px;" class = "">
简介
</th>
<th style="width: 90px;">
创建时间
</th>
<th style="width: 80px;">
</th>
</tr>
</thead>
<tbody>
<% @count= @page * 15 %>
<% @dynamic_news.each do |dynamic_new| %>
<tr class="<%= cycle("odd", "even") %>">
<!td style="text-align:center;vertical-align: middle;">
<!%= dynamic_new.id %>
<% @count +=1 %>
<td align="center">
<%=@count %>
</td>
<td align="center">
<%= image_tag(dynamic_new.cover_url, width:40, height:40) %>
<!%= dynamic_new.title %>
</td>
<td style="text-align:center;vertical-align: middle;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=dynamic_new.title%>'>
<span>
<%= link_to dynamic_new.title, "" %>
</span>
</td>
<td style="vertical-align: middle;text-align:center">
<%= dynamic_new.simple_intruduce %>
</td>
<td style="vertical-align: middle;text-align:center">
<%= format_time(dynamic_new.created_at) %>
</td>
<td class="buttons" style="vertical-align: middle;text-align:center">
<%= link_to("修改", upload_logo_school_path(dynamic_new.id,:school_name => @school_name), :class => 'icon icon-copy') %>
<%#= link_to(l(:button_delete), organization_path(school.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="autoscroll" id="admin_dynamic_news_list">
<%= render :partial => "dynamic_news" %>
</div>
<div class="pagination">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
</div>
<script>
function delcfm() {
if (!confirm("删除项目会一并删除项目的关联信息,确认要删除吗?")) {
window.event.returnValue = false;
}
}
</script>

View File

@ -0,0 +1 @@
$("#admin_dynamic_news_list").html("<%= escape_javascript(render :partial => 'dynamic_news') %>");

View File

@ -208,6 +208,8 @@ zh:
field_text: 文本字段
field_visible: 可见的
field_category: 分类
setting_app_title: 应用程序标题
setting_app_subtitle: 应用程序子标题
setting_welcome_text: 欢迎文字

View File

@ -1369,7 +1369,7 @@ RedmineApp::Application.routes.draw do
get 'admin/code_work_tests'
post 'admin/select_course_syllabus'
post 'admin/create_syllabus'
match 'admin/dynamic_news', :via => :get
match 'admin/dynamic_news', :via => [:get, :post]
resources :auth_sources do
member do