From 058118a4f97d9d911d65b88074bab4a8fe373a46 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 4 Sep 2019 09:35:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E8=BF=9B=E5=85=A5=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- app/controllers/shixuns_controller.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 89b6dca27..c8627a642 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -916,7 +916,8 @@ class GamesController < ApplicationController # 更新关卡状态和一些学习进度 def update_game_parameter game game.update_attribute(:status, 0) if game.status == 1 - game.update_attributes(status: 0, open_time: Time.now) if game.status == 3 + # 第一次进入关卡更新时间 + game.update_attributes(status: 0, open_time: Time.now) if game.open_time.blank? # 开启实训更新myshixuns的时间,方便跟踪用于的学习进度。 game.myshixun.update_column(:updated_at, Time.now) end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8591f9821..74d1d05e2 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -601,7 +601,7 @@ class ShixunsController < ApplicationController challenges.each_with_index do |challenge, index| status = (index == 0 ? 0 : 3) game_identifier = generate_identifier(Game, 12) - worker.add(base_attr.merge(challenge_id: challenge.id, status: status, open_time: Time.now, + worker.add(base_attr.merge(challenge_id: challenge.id, status: status, identifier: game_identifier, modify_time: challenge.modify_time)) end end From 1600ce7e12ac021fbd9093449f4ac5f2a6defe36 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 4 Sep 2019 09:35:22 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E8=BF=9B=E5=85=A5=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index c8627a642..2807a0215 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -917,7 +917,7 @@ class GamesController < ApplicationController def update_game_parameter game game.update_attribute(:status, 0) if game.status == 1 # 第一次进入关卡更新时间 - game.update_attributes(status: 0, open_time: Time.now) if game.open_time.blank? + game.update_attributes(status: 0, open_time: Time.now) if game.open_time.blank? || game.status == 3 # 开启实训更新myshixuns的时间,方便跟踪用于的学习进度。 game.myshixun.update_column(:updated_at, Time.now) end From c410b547098b9c5440a0ae06b670d923291cf711 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 4 Sep 2019 09:40:32 +0800 Subject: [PATCH 3/4] admin: import course member entry --- .../javascripts/admins/message-modal.js | 10 ++- .../admin-import-customer-member-modal.js | 78 +++++++++++++++++++ app/assets/javascripts/admins/users/index.js | 12 ++- .../_import_course_member_modal.html.erb | 30 +++++++ .../shared/modal/_message_modal.html.erb | 2 +- app/views/admins/users/index.html.erb | 6 +- .../users/shared/_import_user_modal.html.erb | 4 +- 7 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/admins/modals/admin-import-customer-member-modal.js create mode 100644 app/views/admins/courses/shared/_import_course_member_modal.html.erb diff --git a/app/assets/javascripts/admins/message-modal.js b/app/assets/javascripts/admins/message-modal.js index 227d75776..2c9ce27a7 100644 --- a/app/assets/javascripts/admins/message-modal.js +++ b/app/assets/javascripts/admins/message-modal.js @@ -1,14 +1,22 @@ $(document).on('turbolinks:load', function() { var $modal = $('.modal.admin-message-modal'); + var $submitBtn = $modal.find('.submit-btn'); if ($modal.length > 0) { $modal.on('hide.bs.modal', function(){ $modal.find('.modal-body').html(''); + $submitBtn.unbind(); }); } }); -function showMessageModal(html) { +function showMessageModal(html, callback) { var $modal = $('.modal.admin-message-modal'); + var $submitBtn = $modal.find('.submit-btn'); + $submitBtn.unbind(); + if(callback !== undefined && typeof callback === 'function'){ + $submitBtn.on('click', callback); + } + $modal.find('.modal-body').html(html); $modal.modal('show'); } \ No newline at end of file diff --git a/app/assets/javascripts/admins/modals/admin-import-customer-member-modal.js b/app/assets/javascripts/admins/modals/admin-import-customer-member-modal.js new file mode 100644 index 000000000..01038c7de --- /dev/null +++ b/app/assets/javascripts/admins/modals/admin-import-customer-member-modal.js @@ -0,0 +1,78 @@ +$(document).on('turbolinks:load', function() { + var $modal = $('.modal.admin-import-course-member-modal'); + if ($modal.length > 0) { + var $form = $modal.find('form.admin-import-course-member-form'); + + var resetFileInputFunc = function(file){ + file.after(file.clone().val("")); + file.remove(); + } + + $modal.on('show.bs.modal', function(){ + $modal.find('.file-names').html('选择文件'); + $modal.find('.upload-file-input').trigger('click'); + }); + $modal.on('hide.bs.modal', function(){ + resetFileInputFunc($modal.find('.upload-file-input')); + }); + $modal.on('change', '.upload-file-input', function(e){ + var file = $(this)[0].files[0]; + $modal.find('.file-names').html(file ? file.name : '请选择文件'); + }) + + var importFormValid = function(){ + if($form.find('input[name="file"]').val() == undefined || $form.find('input[name="file"]').val().length == 0){ + $form.find('.error').html('请选择文件'); + return false; + } + + return true; + }; + + var buildResultMessage = function(data){ + var messageHtml = "
导入结果:成功" + data.success + "条,失败"+ data.fail.length + "条
"; + + if(data.fail.length > 0){ + messageHtml += ''; + + data.fail.forEach(function(item){ + messageHtml += ''; + }); + + messageHtml += '
数据失败原因
' + item.data + '' + item.message + '
' + } + + return messageHtml; + } + + $modal.on('click', '.submit-btn', function(){ + $form.find('.error').html(''); + + if (importFormValid()) { + $('body').mLoading({ text: '正在导入...' }); + + $.ajax({ + method: 'POST', + dataType: 'json', + url: '/admins/import_course_members', + data: new FormData($form[0]), + processData: false, + contentType: false, + success: function(data){ + $('body').mLoading('destroy'); + $modal.modal('hide'); + + showMessageModal(buildResultMessage(data), function(){ + window.location.reload(); + }); + }, + error: function(res){ + $('body').mLoading('destroy'); + var data = res.responseJSON; + $form.find('.error').html(data.message); + } + }); + } + }); + } +}); \ No newline at end of file diff --git a/app/assets/javascripts/admins/users/index.js b/app/assets/javascripts/admins/users/index.js index 4d4f0f945..1ac936df5 100644 --- a/app/assets/javascripts/admins/users/index.js +++ b/app/assets/javascripts/admins/users/index.js @@ -122,14 +122,18 @@ $(document).on('turbolinks:load', function(){ // 导入学生 var $importUserModal = $('.modal.admin-import-user-modal'); var $importUserForm = $importUserModal.find('form.admin-import-user-form') + var resetFileInputFunc = function(file){ + file.after(file.clone().val("")); + file.remove(); + } $importUserModal.on('show.bs.modal', function(){ + resetFileInputFunc($importUserModal.find('.upload-file-input')); $importUserModal.find('.file-names').html('选择文件'); $importUserModal.find('.upload-file-input').trigger('click'); }); - $importUserModal.find('.upload-file-input').on('change', function(e){ + $importUserModal.on('change', '.upload-file-input', function(e){ var file = $(this)[0].files[0]; - $importUserModal.find('.file-names').html(file ? file.name : '请选择文件'); }) @@ -175,7 +179,9 @@ $(document).on('turbolinks:load', function(){ $('body').mLoading('destroy'); $importUserModal.modal('hide'); - showMessageModal(buildResultMessage(data)); + showMessageModal(buildResultMessage(data), function(){ + window.location.reload(); + }); }, error: function(res){ $('body').mLoading('destroy'); diff --git a/app/views/admins/courses/shared/_import_course_member_modal.html.erb b/app/views/admins/courses/shared/_import_course_member_modal.html.erb new file mode 100644 index 000000000..d52a60b09 --- /dev/null +++ b/app/views/admins/courses/shared/_import_course_member_modal.html.erb @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/app/views/admins/shared/modal/_message_modal.html.erb b/app/views/admins/shared/modal/_message_modal.html.erb index 94454ca2d..17c02ea14 100644 --- a/app/views/admins/shared/modal/_message_modal.html.erb +++ b/app/views/admins/shared/modal/_message_modal.html.erb @@ -11,7 +11,7 @@ 保存成功 diff --git a/app/views/admins/users/index.html.erb b/app/views/admins/users/index.html.erb index fa6d67a64..0892b5641 100644 --- a/app/views/admins/users/index.html.erb +++ b/app/views/admins/users/index.html.erb @@ -28,6 +28,7 @@ <% end %> <%= javascript_void_link '导入用户', class: 'btn btn-secondary btn-sm', data: { toggle: 'modal', target: '.admin-import-user-modal'} %> + <%= javascript_void_link '导入课堂成员', class: 'btn btn-secondary btn-sm ml-2', data: { toggle: 'modal', target: '.admin-import-course-member-modal'} %>
@@ -35,4 +36,7 @@
<%= render partial: 'admins/users/shared/reward_grade_modal' %> -<%= render partial: 'admins/users/shared/import_user_modal' %> \ No newline at end of file +<%= render partial: 'admins/users/shared/import_user_modal' %> + + +<%= render partial: 'admins/courses/shared/import_course_member_modal' %> \ No newline at end of file diff --git a/app/views/admins/users/shared/_import_user_modal.html.erb b/app/views/admins/users/shared/_import_user_modal.html.erb index ff3c725b9..b0d3c9a77 100644 --- a/app/views/admins/users/shared/_import_user_modal.html.erb +++ b/app/views/admins/users/shared/_import_user_modal.html.erb @@ -14,8 +14,8 @@ 文件
- - + +
From 45606550beddda31ede7fba943eae80a6fb8fe96 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 4 Sep 2019 09:44:00 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=09=09=09//=20=E7=BB=9F=E4=B8=80=E8=BD=AC?= =?UTF-8?q?=E6=88=90\r\n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/tpm/challengesnew/TPMevaluation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/react/src/modules/tpm/challengesnew/TPMevaluation.js b/public/react/src/modules/tpm/challengesnew/TPMevaluation.js index 60161d829..491751b6a 100644 --- a/public/react/src/modules/tpm/challengesnew/TPMevaluation.js +++ b/public/react/src/modules/tpm/challengesnew/TPMevaluation.js @@ -561,7 +561,8 @@ export default class TPMevaluation extends Component { if(type==="sr"){ newevaluationlist[key].input=e.target.value }else if(type==="yq"){ - newevaluationlist[key].output=e.target.value + // 统一转成\r\n + newevaluationlist[key].output= e.target.value ? e.target.value.replace(/\r?\n/g, "\r\n") : e.target.value } this.setevaluationlist(newevaluationlist); }