From d04ed7e00820ce9925f80736652aea7ddb210d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Mon, 29 Aug 2022 10:05:56 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fixed=20=E7=BB=84=E7=BB=87=E6=88=90?= =?UTF-8?q?=E5=91=98=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/organization_users_controller.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/organizations/organization_users_controller.rb b/app/controllers/organizations/organization_users_controller.rb index 5f358858d..b31ca1e40 100644 --- a/app/controllers/organizations/organization_users_controller.rb +++ b/app/controllers/organizations/organization_users_controller.rb @@ -4,12 +4,14 @@ class Organizations::OrganizationUsersController < Organizations::BaseController def index @organization_users = @organization.organization_users.includes(:user) - search = params[:search].to_s.downcase - user_condition_users = User.like(search).to_sql - team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql - users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users") - - @organization_users = @organization_users.where(user_id: users).distinct + if params[:search].present? + search = params[:search].to_s.downcase + user_condition_users = User.like(search).to_sql + team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql + users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users") + + @organization_users = @organization_users.where(user_id: users).distinct + end @organization_users = kaminari_paginate(@organization_users) end From 0f41cabe71907f9b16df185d318b3eb8b13d5527 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 30 Aug 2022 10:23:35 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=A8=E9=83=A8=E6=88=96=E8=80=85=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=9B=A2=E9=98=9F=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/team_projects_controller.rb | 24 ++++++++++++++++++- .../team_project/create_all_service.rb | 23 ++++++++++++++++++ .../team_project/delete_all_service.rb | 23 ++++++++++++++++++ config/routes.rb | 7 +++++- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 app/services/gitea/organization/team_project/create_all_service.rb create mode 100644 app/services/gitea/organization/team_project/delete_all_service.rb diff --git a/app/controllers/organizations/team_projects_controller.rb b/app/controllers/organizations/team_projects_controller.rb index 2badca177..bbf3264f0 100644 --- a/app/controllers/organizations/team_projects_controller.rb +++ b/app/controllers/organizations/team_projects_controller.rb @@ -21,6 +21,17 @@ class Organizations::TeamProjectsController < Organizations::BaseController tip_exception(e.message) end + def create_all + tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project + ActiveRecord::Base.transaction do + @organization.projects.each do |project| + TeamProject.build(@organization.id, @team.id, project.id) + end + Gitea::Organization::TeamProject::CreateAllService.call(@organization.gitea_token, @team.gtid, @organization.login) + render_ok + end + end + def destroy tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project ActiveRecord::Base.transaction do @@ -33,6 +44,17 @@ class Organizations::TeamProjectsController < Organizations::BaseController tip_exception(e.message) end + def destroy_all + tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project + ActiveRecord::Base.transaction do + @team.team_projects.each do |project| + project.destroy! + end + Gitea::Organization::TeamProject::DeleteAllService.call(@organization.gitea_token, @team.gtid, @organization.login) + render_ok + end + end + private def load_organization @organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id]) @@ -47,7 +69,7 @@ class Organizations::TeamProjectsController < Organizations::BaseController end def load_operate_project - @operate_project = Project.find_by(id: project_mark) || Project.find_by(identifier: project_mark) + @operate_project = @organization.projects.find_by(id: project_mark) || @organization.find_by(identifier: project_mark) tip_exception("项目不存在") if @operate_project.nil? end diff --git a/app/services/gitea/organization/team_project/create_all_service.rb b/app/services/gitea/organization/team_project/create_all_service.rb new file mode 100644 index 000000000..5ba6b58b2 --- /dev/null +++ b/app/services/gitea/organization/team_project/create_all_service.rb @@ -0,0 +1,23 @@ +class Gitea::Organization::TeamProject::CreateAllService < Gitea::ClientService + attr_reader :token, :gtid, :org_name + + def initialize(token, gtid, org_name) + @token = token + @gtid = gtid + @org_name = org_name + end + + def call + response = put(url, request_params) + render_status(response) + end + + private + def request_params + Hash.new.merge(token: token) + end + + def url + "/teams/#{gtid}/repos/#{org_name}".freeze + end +end \ No newline at end of file diff --git a/app/services/gitea/organization/team_project/delete_all_service.rb b/app/services/gitea/organization/team_project/delete_all_service.rb new file mode 100644 index 000000000..e7b9f932f --- /dev/null +++ b/app/services/gitea/organization/team_project/delete_all_service.rb @@ -0,0 +1,23 @@ +class Gitea::Organization::TeamProject::DeleteAllService < Gitea::ClientService + attr_reader :token, :gtid, :org_name + + def initialize(token, gtid, org_name) + @token = token + @gtid = gtid + @org_name = org_name + end + + def call + response = delete(url, params) + render_status(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/teams/#{gtid}/repos/#{org_name}".freeze + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5f8f9f74d..01cfe2b7d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -135,7 +135,12 @@ Rails.application.routes.draw do delete :quit end end - resources :team_projects, only: [:index, :create, :destroy] do ;end + resources :team_projects, only: [:index, :create, :destroy] do + collection do + post :create_all + delete :destroy_all + end + end end resources :projects, only: [:index] do collection do From 60b3c7925d71ba4f6cb92d4167d446b54efba501 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 30 Aug 2022 10:34:37 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=A8=E9=83=A8=E6=88=96=E8=80=85=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=9B=A2=E9=98=9F=E9=A1=B9=E7=9B=AE[?= =?UTF-8?q?=E6=96=87=E6=A1=A3]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/docs/slate/source/includes/_teams.md | 77 ++++++++++++++++ public/docs/api.html | 106 ++++++++++++++++++++++- 2 files changed, 182 insertions(+), 1 deletion(-) diff --git a/app/docs/slate/source/includes/_teams.md b/app/docs/slate/source/includes/_teams.md index c50f6973a..eaaf6bf63 100644 --- a/app/docs/slate/source/includes/_teams.md +++ b/app/docs/slate/source/includes/_teams.md @@ -1 +1,78 @@ # Teams + +## 团队下新增所有的项目 +团队下新增所有的项目 + +> 示例: + +```shell +curl -X POST \ +http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/create_all +``` + +```javascript +await octokit.request('POST /api/organizations/ceshi_org/teams/28/team_projects/create_all.json') +``` + +### HTTP 请求 +`POST /api/organizations/:organization/teams/:id/team_projects/create_all.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|organization |是| | string |组织标识 | +|id |是| | integer|团队 ID| + +### 返回字段说明: + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + + + +## 团队下删除所有的项目 +团队下删除所有的项目 + +> 示例: + +```shell +curl -X DELETE \ +http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/destroy_all +``` + +```javascript +await octokit.request('DELETE /api/organizations/ceshi_org/teams/28/team_projects/destroy_all.json') +``` + +### HTTP 请求 +`DELETE /api/organizations/:organization/teams/:id/team_projects/destroy_all.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|organization |是| | string |组织标识 | +|id |是| | integer|团队 ID| + +### 返回字段说明: + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + \ No newline at end of file diff --git a/public/docs/api.html b/public/docs/api.html index c43f7c403..b41272321 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -646,6 +646,14 @@
  • Teams +
  • Errors @@ -15446,7 +15454,103 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json -

    Issues

    Organizations

    Teams

    Errors

    +

    Issues

    Organizations

    Teams

    团队下新增所有的项目

    +

    团队下新增所有的项目

    + +
    +

    示例:

    +
    +
    curl -X POST \
    +http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/create_all
    +
    await octokit.request('POST /api/organizations/ceshi_org/teams/28/team_projects/create_all.json')
    +

    HTTP 请求

    +

    POST /api/organizations/:organization/teams/:id/team_projects/create_all.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    organizationstring组织标识
    idinteger团队 ID
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    团队下删除所有的项目

    +

    团队下删除所有的项目

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/destroy_all
    +
    await octokit.request('DELETE /api/organizations/ceshi_org/teams/28/team_projects/destroy_all.json')
    +

    HTTP 请求

    +

    DELETE /api/organizations/:organization/teams/:id/team_projects/destroy_all.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    organizationstring组织标识
    idinteger团队 ID
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    Errors

    From aa50c50254ad1278462c3a2083f48303d314cf88 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 30 Aug 2022 10:40:27 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/team_projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/organizations/team_projects_controller.rb b/app/controllers/organizations/team_projects_controller.rb index bbf3264f0..7dfab8e96 100644 --- a/app/controllers/organizations/team_projects_controller.rb +++ b/app/controllers/organizations/team_projects_controller.rb @@ -69,7 +69,7 @@ class Organizations::TeamProjectsController < Organizations::BaseController end def load_operate_project - @operate_project = @organization.projects.find_by(id: project_mark) || @organization.find_by(identifier: project_mark) + @operate_project = @organization.projects.where(id: project_mark).take || @organization.projects.where(identifier: project_mark).take tip_exception("项目不存在") if @operate_project.nil? end From 7148957368e7b1dfc0ce1381a677820cec66f192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Tue, 30 Aug 2022 18:10:27 +0800 Subject: [PATCH 5/9] =?UTF-8?q?nps=E7=94=A8=E6=88=B7=E8=B0=83=E7=A0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/admin.js | 271 +++++++++--------- .../javascripts/bootstrap/bootstrap-toggle.js | 180 ++++++++++++ .../bootstrap/bootstrap-toggle.min.js | 9 + .../bootstrap/bootstrap-toggle.min.js.map | 1 + .../bootstrap/bootstrap2-toggle.js | 180 ++++++++++++ .../bootstrap/bootstrap2-toggle.min.js | 9 + .../bootstrap/bootstrap2-toggle.min.js.map | 1 + app/assets/stylesheets/admin.scss | 1 + .../bootstrap/bootstrap-toggle.css | 83 ++++++ .../bootstrap/bootstrap-toggle.min.css | 28 ++ .../bootstrap/bootstrap2-toggle.css | 85 ++++++ .../bootstrap/bootstrap2-toggle.min.css | 28 ++ app/controllers/admins/nps_controller.rb | 22 ++ app/controllers/application_controller.rb | 10 +- app/controllers/nps_controller.rb | 28 ++ app/helpers/admins/nps_helper.rb | 2 + app/models/user_np.rb | 21 ++ app/queries/admins/user_query.rb | 3 + app/views/admins/nps/_user_np_list.html.erb | 34 +++ app/views/admins/nps/index.html.erb | 45 +++ app/views/admins/nps/index.js.erb | 1 + app/views/admins/shared/_sidebar.html.erb | 1 + app/views/admins/users/index.html.erb | 17 +- app/views/users/get_user_info.json.jbuilder | 53 ++-- config/routes.rb | 4 + db/migrate/20220826034622_create_user_nps.rb | 12 + 26 files changed, 953 insertions(+), 176 deletions(-) create mode 100644 app/assets/javascripts/bootstrap/bootstrap-toggle.js create mode 100644 app/assets/javascripts/bootstrap/bootstrap-toggle.min.js create mode 100644 app/assets/javascripts/bootstrap/bootstrap-toggle.min.js.map create mode 100644 app/assets/javascripts/bootstrap/bootstrap2-toggle.js create mode 100644 app/assets/javascripts/bootstrap/bootstrap2-toggle.min.js create mode 100644 app/assets/javascripts/bootstrap/bootstrap2-toggle.min.js.map create mode 100644 app/assets/stylesheets/bootstrap/bootstrap-toggle.css create mode 100644 app/assets/stylesheets/bootstrap/bootstrap-toggle.min.css create mode 100644 app/assets/stylesheets/bootstrap/bootstrap2-toggle.css create mode 100644 app/assets/stylesheets/bootstrap/bootstrap2-toggle.min.css create mode 100644 app/controllers/admins/nps_controller.rb create mode 100644 app/controllers/nps_controller.rb create mode 100644 app/helpers/admins/nps_helper.rb create mode 100644 app/models/user_np.rb create mode 100644 app/views/admins/nps/_user_np_list.html.erb create mode 100644 app/views/admins/nps/index.html.erb create mode 100644 app/views/admins/nps/index.js.erb create mode 100644 db/migrate/20220826034622_create_user_nps.rb diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index d738e5caa..9b7a96e57 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -1,136 +1,137 @@ -//= require rails-ujs -//= require activestorage -//= require turbolinks -//= require jquery3 -//= require popper -//= require bootstrap-sprockets -//= require jquery.validate.min -//= require additional-methods.min -//= require bootstrap-notify -//= require jquery.cookie.min -//= require select2 -//= require moment.min -//= require jquery.cxselect -//= require bootstrap-datepicker -//= require bootstrap-datetimepicker -//= require bootstrap.viewer -//= require jquery.mloading -//= require jquery-confirm.min -//= require common - -//= require echarts -//= require codemirror/lib/codemirror -//= require codemirror/mode/shell/shell -//= require editormd/editormd -//= require editormd/languages/zh-tw -//= require dragula/dragula - -//= require_tree ./i18n -//= require_tree ./admins - - -$.ajaxSetup({ - beforeSend: function(xhr) { - xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); - } -}); - -// ******** select2 global config ******** -$.fn.select2.defaults.set('theme', 'bootstrap4'); -$.fn.select2.defaults.set('language', 'zh-CN'); - -Turbolinks.setProgressBarDelay(200); - -$.notifyDefaults({ - type: 'success', - z_index: 9999, - delay: 2000 -}); - -function show_success_flash(){ - $.notify({ - message: '操作成功' - },{ - type: 'success' - }); -} - -$(document).on('turbolinks:load', function(){ - $('[data-toggle="tooltip"]').tooltip({ trigger : 'hover' }); - $('[data-toggle="popover"]').popover(); - - // 图片查看大图 - $('img.preview-image').bootstrapViewer(); - - // flash alert提示框自动关闭 - if($('.admin-alert-container .alert').length > 0){ - setTimeout(function(){ - $('.admin-alert-container .alert:not(.alert-danger)').alert('close'); - }, 2000); - setTimeout(function(){ - $('.admin-alert-container .alert.alert-danger').alert('close'); - }, 5000); - } -}); - -$(document).on("turbolinks:before-cache", function () { - $('[data-toggle="tooltip"]').tooltip('hide'); - $('[data-toggle="popover"]').popover('hide'); -}); -// var progressBar = new Turbolinks.ProgressBar(); - -// $(document).on('ajax:send', function(event){ -// console.log('ajax send', event); -// progressBar.setValue(0) -// progressBar.show() -// }); -// -// $(document).on('ajax:complete', function(event){ -// console.log('ajax complete', event); -// progressBar.setValue(1) -// progressBar.hide() // 分页时不触发,奇怪 -// }); -// $(document).on('ajax:success', function(event){ -// console.log('ajax success', event); -// }); -// $(document).on('ajax:error', function(event){ -// console.log('ajax error', event); -// }); - -$(function () { -}); - -$(document).on('turbolinks:load', function() { - - $('.logo-item-left').on("change", 'input[type="file"]', function () { - var $fileInput = $(this); - var file = this.files[0]; - var imageType = /image.*/; - if (file && file.type.match(imageType)) { - var reader = new FileReader(); - reader.onload = function () { - var $box = $fileInput.parent(); - $box.find('img').attr('src', reader.result).css('display', 'block'); - $box.addClass('has-img'); - }; - reader.readAsDataURL(file); - } else { - } - }); - - $('.attachment-item-left').on("change", 'input[type="file"]', function () { - var $fileInput = $(this); - var file = this.files[0]; - var imageType = /image.*/; - if (file && file.type.match(imageType)) { - var reader = new FileReader(); - reader.onload = function () { - var $box = $fileInput.parent(); - $box.find('img').attr('src', reader.result).css('display', 'block'); - $box.addClass('has-img'); - }; - reader.readAsDataURL(file); - } else { - } - }); +//= require rails-ujs +//= require activestorage +//= require turbolinks +//= require jquery3 +//= require popper +//= require bootstrap-sprockets +//= require jquery.validate.min +//= require additional-methods.min +//= require bootstrap-notify +//= require jquery.cookie.min +//= require select2 +//= require moment.min +//= require jquery.cxselect +//= require bootstrap-datepicker +//= require bootstrap-datetimepicker +//= require bootstrap.viewer +//= require bootstrap/bootstrap-toggle +//= require jquery.mloading +//= require jquery-confirm.min +//= require common + +//= require echarts +//= require codemirror/lib/codemirror +//= require codemirror/mode/shell/shell +//= require editormd/editormd +//= require editormd/languages/zh-tw +//= require dragula/dragula + +//= require_tree ./i18n +//= require_tree ./admins + + +$.ajaxSetup({ + beforeSend: function(xhr) { + xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); + } +}); + +// ******** select2 global config ******** +$.fn.select2.defaults.set('theme', 'bootstrap4'); +$.fn.select2.defaults.set('language', 'zh-CN'); + +Turbolinks.setProgressBarDelay(200); + +$.notifyDefaults({ + type: 'success', + z_index: 9999, + delay: 2000 +}); + +function show_success_flash(){ + $.notify({ + message: '操作成功' + },{ + type: 'success' + }); +} + +$(document).on('turbolinks:load', function(){ + $('[data-toggle="tooltip"]').tooltip({ trigger : 'hover' }); + $('[data-toggle="popover"]').popover(); + + // 图片查看大图 + $('img.preview-image').bootstrapViewer(); + + // flash alert提示框自动关闭 + if($('.admin-alert-container .alert').length > 0){ + setTimeout(function(){ + $('.admin-alert-container .alert:not(.alert-danger)').alert('close'); + }, 2000); + setTimeout(function(){ + $('.admin-alert-container .alert.alert-danger').alert('close'); + }, 5000); + } +}); + +$(document).on("turbolinks:before-cache", function () { + $('[data-toggle="tooltip"]').tooltip('hide'); + $('[data-toggle="popover"]').popover('hide'); +}); +// var progressBar = new Turbolinks.ProgressBar(); + +// $(document).on('ajax:send', function(event){ +// console.log('ajax send', event); +// progressBar.setValue(0) +// progressBar.show() +// }); +// +// $(document).on('ajax:complete', function(event){ +// console.log('ajax complete', event); +// progressBar.setValue(1) +// progressBar.hide() // 分页时不触发,奇怪 +// }); +// $(document).on('ajax:success', function(event){ +// console.log('ajax success', event); +// }); +// $(document).on('ajax:error', function(event){ +// console.log('ajax error', event); +// }); + +$(function () { +}); + +$(document).on('turbolinks:load', function() { + + $('.logo-item-left').on("change", 'input[type="file"]', function () { + var $fileInput = $(this); + var file = this.files[0]; + var imageType = /image.*/; + if (file && file.type.match(imageType)) { + var reader = new FileReader(); + reader.onload = function () { + var $box = $fileInput.parent(); + $box.find('img').attr('src', reader.result).css('display', 'block'); + $box.addClass('has-img'); + }; + reader.readAsDataURL(file); + } else { + } + }); + + $('.attachment-item-left').on("change", 'input[type="file"]', function () { + var $fileInput = $(this); + var file = this.files[0]; + var imageType = /image.*/; + if (file && file.type.match(imageType)) { + var reader = new FileReader(); + reader.onload = function () { + var $box = $fileInput.parent(); + $box.find('img').attr('src', reader.result).css('display', 'block'); + $box.addClass('has-img'); + }; + reader.readAsDataURL(file); + } else { + } + }); }) \ No newline at end of file diff --git a/app/assets/javascripts/bootstrap/bootstrap-toggle.js b/app/assets/javascripts/bootstrap/bootstrap-toggle.js new file mode 100644 index 000000000..533914edd --- /dev/null +++ b/app/assets/javascripts/bootstrap/bootstrap-toggle.js @@ -0,0 +1,180 @@ +/*! ======================================================================== + * Bootstrap Toggle: bootstrap-toggle.js v2.2.0 + * http://www.bootstraptoggle.com + * ======================================================================== + * Copyright 2014 Min Hur, The New York Times Company + * Licensed under MIT + * ======================================================================== */ + + + +function ($) { + 'use strict'; + + // TOGGLE PUBLIC CLASS DEFINITION + // ============================== + + var Toggle = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, this.defaults(), options) + this.render() + } + + Toggle.VERSION = '2.2.0' + + Toggle.DEFAULTS = { + on: 'On', + off: 'Off', + onstyle: 'primary', + offstyle: 'default', + size: 'normal', + style: '', + width: null, + height: null + } + + Toggle.prototype.defaults = function() { + return { + on: this.$element.attr('data-on') || Toggle.DEFAULTS.on, + off: this.$element.attr('data-off') || Toggle.DEFAULTS.off, + onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle, + offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle, + size: this.$element.attr('data-size') || Toggle.DEFAULTS.size, + style: this.$element.attr('data-style') || Toggle.DEFAULTS.style, + width: this.$element.attr('data-width') || Toggle.DEFAULTS.width, + height: this.$element.attr('data-height') || Toggle.DEFAULTS.height + } + } + + Toggle.prototype.render = function () { + this._onstyle = 'btn-' + this.options.onstyle + this._offstyle = 'btn-' + this.options.offstyle + var size = this.options.size === 'large' ? 'btn-lg' + : this.options.size === 'small' ? 'btn-sm' + : this.options.size === 'mini' ? 'btn-xs' + : '' + var $toggleOn = $('
  • <%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
  • <%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %>
  • +
  • <%= sidebar_item(admins_nps_path, 'NPS用户调研', icon: 'question-circle', controller: 'admins-nps') %>
  • <% end %>
  • diff --git a/app/views/admins/users/index.html.erb b/app/views/admins/users/index.html.erb index 2f41ffdb6..42d85108d 100644 --- a/app/views/admins/users/index.html.erb +++ b/app/views/admins/users/index.html.erb @@ -16,18 +16,15 @@ <%= select_tag(:identity, options_for_select(identity_options), class: 'form-control') %> -
    - - <% auto_trial_options = [['全部', ''], ['自动授权', 1], ['手动授权', 0]] %> - <%= select_tag(:auto_trial, options_for_select(auto_trial_options), class: 'form-control') %> -
    <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'ID/姓名/邮箱/手机号检索') %> - <% -=begin%> - <%= text_field_tag(:school_name, params[:school_name], class: 'form-control col-sm-2', placeholder: '学校/单位检索') %> -<% -=end%> + + + <%= check_box_tag("admin", true, false, id: "user_admin", style: 'margin-left: 2px;') %> + + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> <% end %> diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 8fcadb1c8..611a09d50 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -1,26 +1,27 @@ -json.username @user.full_name -json.real_name @user.real_name -json.nickname @user.nickname -json.gender @user.gender -json.login @user.login -json.user_id @user.id -json.image_url url_to_avatar(@user) -json.admin @user.admin? -json.is_teacher @user.user_extension&.teacher? -json.user_identity @user.identity -json.tidding_count 0 -json.user_phone_binded @user.phone.present? -# json.phone @user.phone -# json.email @user.mail -json.profile_completed @user.profile_is_completed? -json.professional_certification @user.professional_certification -json.devops_step @user.devops_step -json.ci_certification @user.ci_certification? -json.email @user.mail -json.province @user.province -json.city @user.city -json.custom_department @user.custom_department -json.description @user.description -json.super_description @user.super_description -json.(@user, :show_email, :show_department, :show_location, :show_super_description) -json.message_unread_total @message_unread_total +json.username @user.full_name +json.real_name @user.real_name +json.nickname @user.nickname +json.gender @user.gender +json.login @user.login +json.user_id @user.id +json.image_url url_to_avatar(@user) +json.admin @user.admin? +json.is_teacher @user.user_extension&.teacher? +json.user_identity @user.identity +json.tidding_count 0 +json.user_phone_binded @user.phone.present? +# json.phone @user.phone +# json.email @user.mail +json.profile_completed @user.profile_is_completed? +json.professional_certification @user.professional_certification +json.devops_step @user.devops_step +json.ci_certification @user.ci_certification? +json.email @user.mail +json.province @user.province +json.city @user.city +json.custom_department @user.custom_department +json.description @user.description +json.super_description @user.super_description +json.(@user, :show_email, :show_department, :show_location, :show_super_description) +json.message_unread_total @message_unread_total +json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? diff --git a/config/routes.rb b/config/routes.rb index 5f8f9f74d..1c0e4a49c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,6 +82,7 @@ Rails.application.routes.draw do resources :project_rank, only: [:index] resources :user_rank, only: [:index] + resources :nps, only: [:create] resources :statistic, only: [:index] do collection do @@ -889,6 +890,9 @@ Rails.application.routes.draw do post :replace_image_url, on: :member end resources :faqs + resources :nps do + post :switch_change, on: :collection + end resources :laboratories, only: [:index, :create, :destroy, :update] do member do get :shixuns_for_select diff --git a/db/migrate/20220826034622_create_user_nps.rb b/db/migrate/20220826034622_create_user_nps.rb new file mode 100644 index 000000000..f9bcc70f7 --- /dev/null +++ b/db/migrate/20220826034622_create_user_nps.rb @@ -0,0 +1,12 @@ +class CreateUserNps < ActiveRecord::Migration[5.2] + def change + create_table :user_nps do |t| + t.references :user + t.string :action_type + t.integer :action_id + t.float :score + t.text :memo + t.timestamps + end + end +end From a7c24dea64da900ac411bf0ce2d2a971534f95da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Wed, 31 Aug 2022 10:38:21 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E8=B0=83=E6=95=B4nps=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=B0=83=E7=A0=94=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/nps_controller.rb | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/app/controllers/nps_controller.rb b/app/controllers/nps_controller.rb index 2e1b552b0..35dac164c 100644 --- a/app/controllers/nps_controller.rb +++ b/app/controllers/nps_controller.rb @@ -1,28 +1,15 @@ class NpsController < ApplicationController + # close,关闭 + # createIssue,创建issue + # createPullRequest,创建PR + # auditPullRequest,审核PR + # indexProject,项目主页 + # createProject,创建项目 + # createOrganization,创建组织 def create - tip_exception "缺少参数" if params[:action_id].blank? - action_type ||= begin - case params[:action_id].to_s - when '0' then - 'close' - when '1' then - 'createIssue' - when '2' then - 'createPullRequest' - when '3' then - 'auditPullRequest' - when '4' then - 'forkProject' - when '5' then - 'createProject' - when '6' then - 'createOrganization' - else - "#{params[:action_type].to_s}" - end - end - UserNp.create(:action_id => params[:action_id], :action_type => "#{action_type}", :user_id => User.current.id, :score => params[:score].to_f, memo: params[:memo]) + tip_exception "缺少参数" if params[:action_id].blank? || params[:action_type].blank? + UserNp.create(:action_id => params[:action_id].to_i, :action_type => params[:action_type], :user_id => User.current.id, :score => params[:score].to_f, memo: params[:memo]) render_ok end end From eb1a3f8e2304703a870253cb9a6257aad3747074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Wed, 31 Aug 2022 10:39:52 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E8=B0=83=E6=95=B4nps=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=B0=83=E7=A0=94=E6=8E=A5=E5=8F=A3,=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/nps_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/nps_controller.rb b/app/controllers/nps_controller.rb index 35dac164c..f16b2606f 100644 --- a/app/controllers/nps_controller.rb +++ b/app/controllers/nps_controller.rb @@ -1,5 +1,7 @@ class NpsController < ApplicationController + before_action :require_login + # close,关闭 # createIssue,创建issue # createPullRequest,创建PR From c60e80da98cc8e0bf2a75cb292dd1843db90e7d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Thu, 1 Sep 2022 15:13:49 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E8=B0=83=E6=95=B4nps=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=B0=83=E7=A0=94=E6=8E=A5=E5=8F=A3,=E6=B5=8B=E8=AF=9530?= =?UTF-8?q?=E5=88=86=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index be27eb932..5ea4f4bab 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -27,4 +27,5 @@ json.(@user, :show_email, :show_department, :show_location, :show_super_descript json.message_unread_total @message_unread_total json.has_trace_user @user.trace_user.present? json.is_new @user.login.present? && params[:login].to_s.include?("#{@user.login}") -json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? +# json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? +json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", Time.now - 30.minutes ).blank? From 4a6e94a98f381515a480c31bbea64d2422fd0b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 2 Sep 2022 15:50:15 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=B0=83=E6=95=B4nps=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=B0=83=E7=A0=94=E6=8E=A5=E5=8F=A3,30=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 5ea4f4bab..be27eb932 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -27,5 +27,4 @@ json.(@user, :show_email, :show_department, :show_location, :show_super_descript json.message_unread_total @message_unread_total json.has_trace_user @user.trace_user.present? json.is_new @user.login.present? && params[:login].to_s.include?("#{@user.login}") -# json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank? -json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", Time.now - 30.minutes ).blank? +json.nps EduSetting.get("nps-on-off-switch").to_s == 'true' && UserNp.where(user_id: current_user.id).where("created_at >= ?", (Time.now - 30.days).beginning_of_day ).blank?