From 05bd1ca0c82eb124373e097acf291a0bbe18cc50 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 10 Jul 2019 14:25:52 +0800 Subject: [PATCH] user center project package list --- .../project_packages_controller.rb | 4 + app/controllers/users_controller.rb | 50 ++++++++++ app/models/bidding_user.rb | 4 + app/models/user.rb | 2 + app/views/users/_project_package.html.erb | 82 ++++++++++++++++ app/views/users/show.html.erb | 16 +++ app/views/users/show.js.erb | 4 + config/locales/bidding_users/zh.yml | 6 ++ config/routes.rb | 4 +- .../images/educoder/project_packages/ai.png | Bin 0 -> 1459 bytes .../educoder/project_packages/backend.png | Bin 0 -> 1404 bytes .../cloud_compute_and_big_data.png | Bin 0 -> 1506 bytes .../educoder/project_packages/database.png | Bin 0 -> 1627 bytes .../project_packages/devops_and_test.png | Bin 0 -> 1312 bytes .../educoder/project_packages/front.png | Bin 0 -> 1322 bytes .../educoder/project_packages/mobile.png | Bin 0 -> 1367 bytes .../educoder/project_packages/other.png | Bin 0 -> 1107 bytes public/stylesheets/educoder/edu-main.css | 91 ++++++++++++++++++ 18 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 app/views/users/_project_package.html.erb create mode 100644 config/locales/bidding_users/zh.yml create mode 100755 public/images/educoder/project_packages/ai.png create mode 100755 public/images/educoder/project_packages/backend.png create mode 100755 public/images/educoder/project_packages/cloud_compute_and_big_data.png create mode 100755 public/images/educoder/project_packages/database.png create mode 100755 public/images/educoder/project_packages/devops_and_test.png create mode 100755 public/images/educoder/project_packages/front.png create mode 100755 public/images/educoder/project_packages/mobile.png create mode 100755 public/images/educoder/project_packages/other.png diff --git a/app/controllers/project_packages_controller.rb b/app/controllers/project_packages_controller.rb index cdedea9e..3945f978 100644 --- a/app/controllers/project_packages_controller.rb +++ b/app/controllers/project_packages_controller.rb @@ -21,6 +21,10 @@ class ProjectPackagesController < ApplicationController render_react end + def apply_success + render_react + end + private def render_react render file: 'public/react/build/index.html', :layout => false diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4fae7ff7..3306326e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2558,6 +2558,56 @@ class UsersController < ApplicationController @tag = params[:tag] @objects = @objects.where(:course_list_id => params[:tag]).order("#{@sort} #{order}") end + when 'a_package' + bidding_packages = @user.bidding_project_packages + bidding_packages = bidding_packages.none if @show_all && params[:q] == 0 # 参与的不存在未发布的 + packages = @user.project_packages + + if @show_all + status = + case params[:q] + when '0' then %w(pending applying refused) + when '1' then %w(published) + when '2' then %w(bidding_ended bidding_finished) + end + if status.present? + packages = packages.where(status: status) + bidding_packages = bidding_packages.where(status: status) + end + else + packages = packages.where(status: %w(published bidding_ended bidding_finished)) + end + + ids = bidding_packages.pluck(:id) + packages.pluck(:id) + @objects = ProjectPackage.where(id: ids).order("published_at #{order}") + when 'p_package' + packages = @user.project_packages + if @show_all + status = + case params[:q] + when '0' then %w(pending applying refused) + when '1' then %w(published) + when '2' then %w(bidding_ended bidding_finished) + end + if status.present? + packages = packages.where(status: status) + end + else + packages = packages.where(status: %w(published bidding_ended bidding_finished)) + end + @objects = packages.order("published_at #{order}") + when 'l_package' + packages = @user.bidding_project_packages + if @show_all + status = + case params[:q] + when '0' then %w(bidding_lost) + when '1' then %w(bidding_won) + end + + packages = packages.where(bidding_users: { status: status }) if status.present? + end + @objects = packages.order("published_at #{order}") end @objects_count = @objects.size diff --git a/app/models/bidding_user.rb b/app/models/bidding_user.rb index 5869b6d4..9f368b2a 100644 --- a/app/models/bidding_user.rb +++ b/app/models/bidding_user.rb @@ -17,4 +17,8 @@ class BiddingUser < ActiveRecord::Base transitions from: [:pending], to: :bid_lost end end + + def status_text + I18n.t("bidding_user.status.#{status}") + end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index b5545206..0e034d32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -276,6 +276,8 @@ class User < Principal # 众包 has_many :project_packages, foreign_key: :creator_id, dependent: :destroy + has_many :bidding_users, dependent: :destroy + has_many :bidding_project_packages, through: :bidding_users, source: :project_package ## end diff --git a/app/views/users/_project_package.html.erb b/app/views/users/_project_package.html.erb new file mode 100644 index 00000000..d8ca475e --- /dev/null +++ b/app/views/users/_project_package.html.erb @@ -0,0 +1,82 @@ +<% if @type == 'p_package' && User.current == @user %> +
+
  • <%= link_to "全部", user_path(@user, :type => @type), :remote => true %>
  • +
  • <%= link_to "未发布", user_path(@user, :type => @type, :p => "0"), :remote => true %>
  • +
  • <%= link_to "竞标中", user_path(@user, :type => @type, :p => "1"), :remote => true %>
  • +
  • <%= link_to "已完成", user_path(@user, :type => @type, :p => "2"), :remote => true %>
  • +
    +<% elsif @type == 'l_package' && User.current == @user %> +
    +
  • <%= link_to "全部", user_path(@user, :type => @type, :p => "a"), :remote => true %>
  • +
  • <%= link_to "未中标", user_path(@user, :type => @type, :p => "0"), :remote => true %>
  • +
  • <%= link_to "已中标", user_path(@user, :type => @type, :p => "1"), :remote => true %>
  • +
    +<% end %> + +
    + 共<%= @objects_count %>个 +
    + <%= link_to '发布时间', user_path(@user, :order => @new_order, :sort => @sort, :type => @type), :class => "fl color-grey-9", :remote => true %> +
    +
    + +<% if @objects_count > 0 %> +
    + <% @objects.each do |object| %> +
    +
    + <%= image_tag("educoder/project_packages/#{object.category}.png") %> +
    +
    +
    +
    + <%= link_to object.title, project_package_path(object) %> +
    +
    + <% if object.creator_id != @user.id %> + <% bidding_user = object.bidding_users.find_by_user_id(@user.id) %> + <%= raw content_tag(:span, bidding_user.status_text, class: bidding_user.status) %> + <% end %> +
    +
    +
    + <%= object.min_price %> + <% if object.max_price && object.max_price != object.min_price %> + ~<%= object.max_price %> + <% end %> +
    +
    +
    +
    人工智能
    +
    +
    +
    + + <%= object.visit_count %>人浏览 +
    +
    + <% if object.published? %> + + 内竞标截止 + <% end %> +
    +
    + <% if object.bidding_users_count > 0 %> + + <%= object.bidding_users_count %>人竞标 + <% end %> +
    +
    +
    + <% if object.published_at.present? %> + 发布日期:<%= object.published_at.try(:strftime, '%Y-%m-%d') %> + <% end %> +
    +
    +
    +
    + <% end %> +
    +<% else %> + <%= render :partial => "welcome/no_data" %> +<% end %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 6d42f201..fb459160 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,6 +1,8 @@ <% current_user = @user == User.current %> <% str = current_user ? '我' : 'TA' %> +<% show_package = @user.project_packages.count.nonzero? || @user.bidding_project_packages.count.nonzero? %> +