diff --git a/app/controllers/managements/project_packages_controller.rb b/app/controllers/managements/project_packages_controller.rb new file mode 100644 index 00000000..3ea574c0 --- /dev/null +++ b/app/controllers/managements/project_packages_controller.rb @@ -0,0 +1,55 @@ +class Managements::ProjectPackagesController < Managements::BaseController + before_filter :set_menu_type, only: [:index] + + def index + packages = ProjectPackage.where(nil) + + # 任务标题 + keyword = params[:keyword].to_s.strip + packages = packages.where('title LIKE ?', "%#{keyword}%") if keyword.present? + + # 发布者姓名 + creator_name = params[:creator_name].to_s.strip + if creator_name.present? + sql = 'LOWER(concat(users.lastname, users.firstname)) LIKE ?' + packages = packages.joins(:creator).where(sql, "%#{creator_name}%") + end + + # 状态 + status = + case params[:status] + when 'pending' then %w(pending refused) + when 'applying' then %w(applying) + when 'published' then %w(published bidding_end) + when 'finished' then %w(bidding_finished) + end + packages = packages.where(status: status) if status.present? + + # 发布时间 + begin_date = (params[:begin_date].to_time.beginning_of_day rescue nil) + end_date = (params[:end_date].to_time.end_of_day rescue nil) + packages = packages.where('published_at >= ?', begin_date) if begin_date.present? + packages = packages.where('published_at <= ?', end_date) if end_date.present? + + @count = packages.count + + # 排序 + params[:sort_by] ||= 'created_at' + params[:sort_direction] ||= 'desc' + packages = packages.order("#{params[:sort_by]} #{params[:sort_direction]}") + + @packages = paginateHelper packages.preload(:creator) + end + + def destroy + ProjectPackage.find(params[:id]).destroy + render json: { status: 0 } + end + + private + + def set_menu_type + @menu_type = 14 + @sub_type = 1 + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 51825709..05e1e2ce 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -772,6 +772,10 @@ module ApplicationHelper ) ) ) + when 14 + case sub_type + when 1 then '任务列表' + end end end diff --git a/app/models/project_package.rb b/app/models/project_package.rb index f957dc5d..8f9035f6 100644 --- a/app/models/project_package.rb +++ b/app/models/project_package.rb @@ -89,4 +89,8 @@ class ProjectPackage < ActiveRecord::Base def category_text I18n.t("project_package.category.#{category}") end + + def status_text + I18n.t("project_package.status.#{status}") + end end \ No newline at end of file diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index c59f80a8..f0fefec5 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -77,6 +77,11 @@
  • <%= link_to "竞赛列表", competition_managements_path %>
  • +
  • 众包+ + +
  • 单位