From 4d0ed530b71ce9b872ac69c381288d3cb2e3d7cd Mon Sep 17 00:00:00 2001 From: feng <281221230@qq.com> Date: Thu, 23 Jan 2025 10:08:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?nps=20=E7=BB=9F=E8=AE=A1=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/nps_controller.rb | 2 +- app/views/admins/nps/_user_np_list.html.erb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admins/nps_controller.rb b/app/controllers/admins/nps_controller.rb index bfb72f730..2817cd0c6 100644 --- a/app/controllers/admins/nps_controller.rb +++ b/app/controllers/admins/nps_controller.rb @@ -2,7 +2,7 @@ class Admins::NpsController < Admins::BaseController before_action :require_business def index @on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true' - @user_nps = UserNp.joins(:user).order(created_at: :desc) + @user_nps = UserNp.order(created_at: :desc) keyword = params[:keyword].to_s.strip.presence if keyword sql = 'CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword OR users.login LIKE :keyword OR users.mail LIKE :keyword OR users.phone LIKE :keyword' diff --git a/app/views/admins/nps/_user_np_list.html.erb b/app/views/admins/nps/_user_np_list.html.erb index f2d5196e9..474fe8b86 100644 --- a/app/views/admins/nps/_user_np_list.html.erb +++ b/app/views/admins/nps/_user_np_list.html.erb @@ -12,15 +12,15 @@ <% if user_nps.present? %> <% user_nps.each_with_index do |nps, index| %> - + "> <%= list_index_no((params[:page] || 1).to_i, index) %> - <%= link_to "/#{nps.user.login}", target: '_blank' do %> - <%= overflow_hidden_span nps.user.real_name, width: 100 %> + <%= link_to "/#{nps.user.nil? ? "用户已注销" : nps.user.login}", target: '_blank' do %> + <%= overflow_hidden_span (nps.user.nil? ? "用户已注销" : nps.user.real_name), width: 100 %> <% end %> <%= display_text(nps.created_at&.strftime('%Y-%m-%d %H:%M')) %> - <%= display_text(nps.user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %> + <%= display_text(nps.user.nil? ? "用户已注销" : nps.user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %> <%= nps.action_type == 'close' ? '--' : nps.score %> <%= nps.memo %> From 4dd920313cda73fef09ae7f5129c687e42513d20 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Jan 2025 11:50:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fixed:=20=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=9F=A5=E8=AF=A2=E8=BF=90=E8=A1=8C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/action_runs_controller.rb | 48 +++++++++++++++++++ .../v1/projects/actions/actions_controller.rb | 4 +- config/routes/api.rb | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/pm/action_runs_controller.rb diff --git a/app/controllers/api/pm/action_runs_controller.rb b/app/controllers/api/pm/action_runs_controller.rb new file mode 100644 index 000000000..0e69d56a9 --- /dev/null +++ b/app/controllers/api/pm/action_runs_controller.rb @@ -0,0 +1,48 @@ +class Api::Pm::ActionRunsController < Api::Pm::BaseController + before_action :require_login + + def index + render_error('请输入workflows') if params[:workflows].blank? + @owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s) + render_error('组织未找到') if @owner.blank? + action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid) + group_data = action_runs.where(workflow_id: params[:workflows].to_s.split(",")).group(:workflow_id, :status).count + @result = [] + params[:workflows].to_s.split(",").each do |file| + last_action_run = action_runs.where(workflow_id: file).order(updated: :desc).first + last_action_run_json = last_action_run.present? ? { + id: last_action_run.id, + schedule: last_action_run.schedule_id > 0, + title: last_action_run.title, + index: last_action_run.index, + status: last_action_run.status, + started: last_action_run.started, + stopped: last_action_run.stopped, + length: last_action_run.stopped - last_action_run.started, + created: last_action_run.created, + updated: last_action_run.updated, + } : {} + + total = 0 + success = 0 + failure = 0 + group_data.each do |k,v| + total += v if k[0] == file + success += v if k[0] == file && k[1] == 1 + failure += v if k[0] == file && k[1] == 2 + end + + @result << { + name: file, + last_action_run: last_action_run_json, + history: { + total: total, + success: success, + failure: failure + } + } + end + render :json => @result + end + +end \ No newline at end of file diff --git a/app/controllers/api/v1/projects/actions/actions_controller.rb b/app/controllers/api/v1/projects/actions/actions_controller.rb index 5a34847e2..1e9177144 100644 --- a/app/controllers/api/v1/projects/actions/actions_controller.rb +++ b/app/controllers/api/v1/projects/actions/actions_controller.rb @@ -3,8 +3,8 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions def new_index @files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") puts @files - @action_runs = Gitea::ActionRun.where(repo_id: @project.gpid, status: [1,2]) - group_data = @action_runs.group(:workflow_id, :status).count + @action_runs = Gitea::ActionRun.where(repo_id: @project.gpid) + group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count @result = [] @files.map{|i|i['name']}.each do |file| last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first diff --git a/config/routes/api.rb b/config/routes/api.rb index ec8031fd8..629ea93f7 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -50,6 +50,7 @@ defaults format: :json do get :polyline end end + resources :action_runs, only: [:index] end namespace :v1 do