diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dc56fb47a..994c6357c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -382,7 +382,7 @@ class ApplicationController < ActionController::Base def current_user if Rails.env.development? - User.current = User.find 36480 + User.current = User.find 1 else User.current end diff --git a/app/controllers/compose_projects_controller.rb b/app/controllers/compose_projects_controller.rb new file mode 100644 index 000000000..4355571c7 --- /dev/null +++ b/app/controllers/compose_projects_controller.rb @@ -0,0 +1,38 @@ +class ComposeProjectsController < ApplicationController + #未做完 + before_action :require_login + before_action :set_compose + + def create + project_ids = params[:project_ids] + ComposeProject.transaction do + project_ids.each do |p| + project = Project.select(:id, :user_id).find(p) + unless project.blank? || ComposeProject.exists?(user_id: project.user_id, project_id: p, compose_id: @compose.id) + ComposeProject.create!(user_id: project.user_id, project_id: p, compose_id: @compose.id, position: p) + end + end + end + normal_status(0, "添加成功") + end + + def destroy + project_ids = params[:project_ids] + if ComposeProject.where(project_id: project_ids, compose_id: @compose.id).delete_all + normal_status(0, "项目删除成功") + else + normal_status(-1, "项目删除失败") + end + end + + + private + + def set_compose + @compose = Compose.find(params[:compose_id]) + unless @compose.present? + normal_status(-1, "组织不存在") + end + end + +end \ No newline at end of file diff --git a/app/controllers/composes_controller.rb b/app/controllers/composes_controller.rb new file mode 100644 index 000000000..c1a7f524f --- /dev/null +++ b/app/controllers/composes_controller.rb @@ -0,0 +1,99 @@ +class ComposesController < ApplicationController + before_action :require_login, except: [:index] + before_action :find_compose, except: [:index, :new,:create] + + def index + @order_type = params[:order] || "created_at" + @search_name = params[:search] + composes = Compose.compose_includes + if @search_name.present? + composes = composes.where("title like ?", "%#{@search_name}%") + end + composes = composes.order("#{@order_type} desc") + @page = params[:page] || 1 + @limit = params[:limit] || 15 + @composes_size = composes.size + @composes = composes.page(@page).per(@limit) + end + + def new + + end + + def create + ActiveRecord::Base.transaction do + begin + @compose = Compose.new(compose_params.merge(user_id: current_user.id)) + if @compose.save + ComposeUser.create!(user_id: current_user.id, compose_id: @compose.id, is_manager: 1) + normal_status(0,"组织创建成功") + else + error_messages = @compose.errors.messages[:title][0] + normal_status(-1,"组织创建失败:#{error_messages}") + end + rescue Exception => e + tip_exception("#{e}") + raise ActiveRecord::Rollback + end + end + end + + def edit + + end + + def update + if @compose.update_attributes(compose_params) + normal_status(0,"组织更新成功") + else + error_messages = @compose.errors.messages[:title][0] + normal_status(-1,"组织更新失败:#{error_messages}") + end + end + + def destroy + if @compose.destroy + normal_status(0,"组织删除成功") + else + normal_status(-1,"组织删除失败,请稍后重试") + end + end + + def show + compose_projects_ids = @compose&.compose_projects&.pluck(:project_id) + search = params[:search] + if compose_projects_ids.size > 0 + compose_projects = Project.where(id: compose_projects_ids) + + if search.present? + compose_projects = compose_projects.where("name like ? ", "%#{search.to_s.strip}%") + end + else + compose_projects = [] + end + + @compose_projects_size = compose_projects.size + + if @compose_projects_size > 0 + @page = params[:page] || 1 + @limit = params[:limit] || 15 + @compose_projects = compose_projects.page(@page).per(@limit) + else + @compose_projects = compose_projects + end + end + + private + + def compose_params + params.require(:compose).permit(:user_id, :title, :description, :show_mode, :compose_mode, :compose_users_count, :compose_projects_count) + end + + def find_compose + @compose = Compose.find(params[:compose_id]) + unless @compose.present? + normal_status(-1, "组织不存在") + end + end + +end \ No newline at end of file diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 6481dcc42..653e53dda 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -111,7 +111,7 @@ class IssuesController < ApplicationController type: "user" }.merge(tokens_params(@project)) user_tokens = Gitea::Repository::Hooks::QueryService.new(query_params).call - return normal_status(-1, "悬赏的奖金不足") if user_tokens[:value].to_i < params[:token].to_i + return normal_status(-1, "您的token值不足") if user_tokens[:value].to_i < params[:token].to_i else issue_params = issue_send_params(params) @@ -159,8 +159,8 @@ class IssuesController < ApplicationController end def edit - @all_branches = get_branches - @issue_chosen = issue_left_chosen(@project, @issue.id) + # @all_branches = get_branches + # @issue_chosen = issue_left_chosen(@project, @issue.id) @issue_attachments = @issue.attachments end @@ -454,7 +454,7 @@ class IssuesController < ApplicationController issue_type: params[:issue_type] || "1", token: params[:token], issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "", - closed_on: (params[:status_id].to_i == 5) ? Time.now : nil, + closed_on: (params[:status_id].to_i == 5) ? Time.current : nil, branch_name: params[:branch_name].to_s, issue_classify: "issue", author_id: current_user.id, diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e722d681d..86e8d5e2a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -86,7 +86,13 @@ class UsersController < ApplicationController end # 个人主页信息 - def homepage_info;end + def homepage_info + #待办事项,现在未做 + @undo_events = 10 + #用户的组织数量 + # @user_composes_count = @user.composes.size + @user_composes_count = 10 + end def brief_introduction content = params[:content].to_s.strip diff --git a/app/models/compose.rb b/app/models/compose.rb new file mode 100644 index 000000000..0b3733943 --- /dev/null +++ b/app/models/compose.rb @@ -0,0 +1,12 @@ +class Compose < ApplicationRecord + #组织 + belongs_to :user + has_many :compose_projects + has_many :compose_users + + validates :title, presence: {message: "组织名称不能为空"}, uniqueness: {message: "组织名称已存在"} + + scope :compose_includes, ->{includes(:compose_projects, :compose_users, :user)} + +end + diff --git a/app/models/compose_project.rb b/app/models/compose_project.rb new file mode 100644 index 000000000..3c2d099e1 --- /dev/null +++ b/app/models/compose_project.rb @@ -0,0 +1,4 @@ +class ComposeProject < ApplicationRecord + #组织的项目记录表 + belongs_to :compose +end diff --git a/app/models/compose_user.rb b/app/models/compose_user.rb new file mode 100644 index 000000000..e3b514b3e --- /dev/null +++ b/app/models/compose_user.rb @@ -0,0 +1,4 @@ +class ComposeUser < ApplicationRecord + belongs_to :compose + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 3d946731e..7e69e4b10 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -45,7 +45,8 @@ class User < ApplicationRecord enumerize :platform, in: [:forge, :educoder, :trustie, :military], default: :forge, scope: :shallow belongs_to :laboratory, optional: true - + has_many :composes, dependent: :destroy + has_many :compose_users, dependent: :destroy has_one :user_extension, dependent: :destroy has_many :open_users, dependent: :destroy has_one :wechat_open_user, class_name: 'OpenUsers::Wechat' diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index d2677d93c..69cd8a9fe 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -14,6 +14,11 @@ class Projects::ListMyQuery < ApplicationQuery projects = Project.joins(:members).where(members: { user_id: user.id }) elsif params[:category].to_s == "manage" projects = Project.where(user_id: user.id) + elsif params[:category].to_s == "watched" #我关注的 + projects = Project.joins(:watchers).where("watchable_type = ? and user_id = ?", "Project", user.id) + elsif params[:category].to_s == "forked" #我fork的 + fork_ids = user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) + projects = Project.where(id: fork_ids) else projects = Project.where.not(user_id: user.id).joins(:members).where(members: { user_id: user.id }) end diff --git a/app/views/issues/edit.json.jbuilder b/app/views/issues/edit.json.jbuilder index a7937b19f..382dab1ba 100644 --- a/app/views/issues/edit.json.jbuilder +++ b/app/views/issues/edit.json.jbuilder @@ -3,8 +3,8 @@ json.extract! @issue, :id,:subject,:description,:is_private,:assigned_to_id,:tra :start_date,:due_date,:estimated_hours, :issue_type, :token,:issue_classify, :branch_name json.done_ratio @issue.done_ratio.to_s + "%" json.issue_tags @issue.get_issue_tags -json.issue_chosen @issue_chosen -json.branches @all_branches +# json.issue_chosen @issue_chosen +# json.branches @all_branches json.attachments do json.array! @issue_attachments do |attachment| json.partial! "attachments/attachment_simple", locals: {attachment: attachment} diff --git a/app/views/issues/show.json.jbuilder b/app/views/issues/show.json.jbuilder index 0624ee439..cc70d1107 100644 --- a/app/views/issues/show.json.jbuilder +++ b/app/views/issues/show.json.jbuilder @@ -15,7 +15,7 @@ json.priority @issue.priority.try(:name) json.version @issue.version.try(:name) json.issue_tags @issue.get_issue_tags json.done_ratio @issue.done_ratio.to_s + "%" -json.issue_type @issue.issue_type == "1" ? "普通" : "悬赏" +json.issue_type @issue.issue_type json.token @issue.issue_type == "2" ? @issue.token : "" json.join_users @join_users json.cost_time @cost_time_array diff --git a/app/views/repositories/show.json.jbuilder b/app/views/repositories/show.json.jbuilder index 0e1e1fb84..30ec73e1c 100644 --- a/app/views/repositories/show.json.jbuilder +++ b/app/views/repositories/show.json.jbuilder @@ -17,6 +17,7 @@ json.branches_count @branches_count json.commits_count @commits_count json.permission render_edit_project_permission(current_user, @project) if current_user json.mirror_url @project&.repository.mirror_url +json.mirror @project&.repository.mirror_url.present? json.watched current_user&.watched?(@project) json.praised current_user&.liked?(@project) json.status @project.status @@ -35,6 +36,6 @@ json.clone_url @result['clone_url'] json.default_branch @result['default_branch'] json.empty @result['empty'] json.full_name @result['full_name'] -json.mirror @result['mirror'] + json.private @result['private'] json.partial! 'author', locals: { user: @project.owner } diff --git a/app/views/users/homepage_info.json.jbuilder b/app/views/users/homepage_info.json.jbuilder index 1a52cee0f..2cf6a4661 100644 --- a/app/views/users/homepage_info.json.jbuilder +++ b/app/views/users/homepage_info.json.jbuilder @@ -8,7 +8,8 @@ json.brief_introduction @user.user_extension&.brief_introduction json.professional_certification @user.professional_certification json.followed User.current.watched?(@user) json.projects_count @user.projects_count - +json.undo_events @undo_events +json.user_composes_count @user_composes_count # json.id @user.id # json.name @user.full_name # json.avatar_url url_to_avatar(@user) diff --git a/config/routes.rb b/config/routes.rb index dc06da01c..a5be9be67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,9 @@ Rails.application.routes.draw do resources :edu_settings scope '/api' do + resources :composes do + resources :compose_projects, only: [:create, :destroy] + end resources :attachments do collection do delete :destroy_files