Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into yslcompetition
commit
07a8062ac9
@ -0,0 +1,73 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-competitions-index-page').length > 0) {
|
||||||
|
$('.modal.admin-upload-file-modal').on('upload:success', function(e, data){
|
||||||
|
var $imageElement = $('.competition-image-' + data.source_id);
|
||||||
|
$imageElement.attr('src', data.url);
|
||||||
|
$imageElement.show();
|
||||||
|
$imageElement.next().html('重新上传');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".admin-competition-list-form").on("change", '.competitions-hot-select', function () {
|
||||||
|
var s_value = $(this).get(0).checked ? 1 : 0;
|
||||||
|
var json = {};
|
||||||
|
json["hot"] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/competitions/hot_setting",
|
||||||
|
type: "POST",
|
||||||
|
dataType:'json',
|
||||||
|
data: json,
|
||||||
|
success: function(){
|
||||||
|
$.notify({ message: '操作成功' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ============== 新增竞赛 ===============
|
||||||
|
var $modal = $('.modal.admin-create-competition-modal');
|
||||||
|
var $form = $modal.find('form.admin-create-competition-form');
|
||||||
|
var $competitionNameInput = $form.find('input[name="competition_name"]');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
competition_name: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// modal ready fire
|
||||||
|
$modal.on('show.bs.modal', function () {
|
||||||
|
$competitionNameInput.val('');
|
||||||
|
});
|
||||||
|
|
||||||
|
$modal.on('click', '.submit-btn', function(){
|
||||||
|
$form.find('.error').html('');
|
||||||
|
|
||||||
|
if ($form.valid()) {
|
||||||
|
var url = $form.data('url');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: url,
|
||||||
|
data: $form.serialize(),
|
||||||
|
success: function(){
|
||||||
|
$.notify({ message: '创建成功' });
|
||||||
|
$modal.modal('hide');
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.reload();
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$form.find('.error').html(data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,9 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if($('body.admins-enroll-lists-index-page').length > 0){
|
||||||
|
let search_form = $(".search-form");
|
||||||
|
//导出
|
||||||
|
$(".competition-enroll-list-form").on("click","#enroll-lists-export",function () {
|
||||||
|
window.location.href = "/admins/competitions/"+$(this).attr("data-competition-id")+"/enroll_lists.xls?" + search_form.serialize();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,73 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-user-statistics-index-page').length > 0) {
|
||||||
|
var $form = $('.user-statistic-list-form');
|
||||||
|
|
||||||
|
// ************** 学校选择 *************
|
||||||
|
var matcherFunc = function(params, data){
|
||||||
|
if ($.trim(params.term) === '') {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if (typeof data.text === 'undefined') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.name && data.name.indexOf(params.term) > -1) {
|
||||||
|
var modifiedData = $.extend({}, data, true);
|
||||||
|
return modifiedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return `null` if the term should not be displayed
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var defineSchoolSelect = function (schools) {
|
||||||
|
$form.find('.school-select').select2({
|
||||||
|
theme: 'bootstrap4',
|
||||||
|
placeholder: '选择学校/单位',
|
||||||
|
minimumInputLength: 1,
|
||||||
|
data: schools,
|
||||||
|
templateResult: function (item) {
|
||||||
|
if(!item.id || item.id === '') return item.text;
|
||||||
|
return item.name;
|
||||||
|
},
|
||||||
|
templateSelection: function(item){
|
||||||
|
if (item.id) {
|
||||||
|
$form.find('#school_id').val(item.id);
|
||||||
|
}
|
||||||
|
return item.name || item.text;
|
||||||
|
},
|
||||||
|
matcher: matcherFunc
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 初始化学校选择器
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/schools/for_option.json',
|
||||||
|
dataType: 'json',
|
||||||
|
type: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
defineSchoolSelect(data.schools);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 清空
|
||||||
|
$form.on('click', '.clear-btn', function(){
|
||||||
|
$form.find('select[name="date"]').val('');
|
||||||
|
$form.find('.school-select').val('').trigger('change');
|
||||||
|
$form.find('input[type="submit"]').trigger('click');
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// 导出
|
||||||
|
$('.export-action').on('click', function(){
|
||||||
|
var form = $(".user-statistic-list-form .search-form")
|
||||||
|
var exportLink = $(this);
|
||||||
|
var date = form.find("select[name='date']").val();
|
||||||
|
var schoolId = form.find('input[name="school_id"]').val();
|
||||||
|
|
||||||
|
var url = exportLink.data("url").split('?')[0] + "?date=" + date + "&school_id=" + schoolId;
|
||||||
|
window.open(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,124 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-weapp-adverts-index-page').length > 0) {
|
||||||
|
var resetNo = function(){
|
||||||
|
$('#adverts-container .advert-item-no').each(function(index, ele){
|
||||||
|
$(ele).html(index + 1);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------ 保存链接 -----------
|
||||||
|
$('.adverts-card').on('click', '.save-data-btn', function(){
|
||||||
|
var $link = $(this);
|
||||||
|
var id = $link.data('id');
|
||||||
|
var link = $('.advert-item-' + id).find('.link-input').val();
|
||||||
|
$link.attr('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/weapp_adverts/' + id,
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { link: link },
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '操作成功' });
|
||||||
|
},
|
||||||
|
error: ajaxErrorNotifyHandler,
|
||||||
|
complete: function(){
|
||||||
|
$link.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
// -------------- 是否在首页展示 --------------
|
||||||
|
$('.adverts-card').on('change', '.online-check-box', function(){
|
||||||
|
var $checkbox = $(this);
|
||||||
|
var id = $checkbox.data('id');
|
||||||
|
var checked = $checkbox.is(':checked');
|
||||||
|
$checkbox.attr('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/weapp_adverts/' + id,
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { online: checked },
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '保存成功' });
|
||||||
|
var box = $('.advert-item-' + id).find('.drag');
|
||||||
|
if(checked){
|
||||||
|
box.removeClass('not_active');
|
||||||
|
}else{
|
||||||
|
box.addClass('not_active');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: ajaxErrorNotifyHandler,
|
||||||
|
complete: function(){
|
||||||
|
$checkbox.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// ------------ 拖拽 -------------
|
||||||
|
var onDropFunc = function(el, _target, _source, sibling){
|
||||||
|
var moveId = $(el).data('id');
|
||||||
|
var insertId = $(sibling).data('id') || '';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/weapp_adverts/drag',
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { move_id: moveId, after_id: insertId },
|
||||||
|
success: function(data){
|
||||||
|
resetNo();
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$.notify({message: '移动失败,原因:' + data.message}, {type: 'danger'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
var ele1 = document.getElementById('adverts-container');
|
||||||
|
dragula([ele1], { mirrorContainer: ele1 }).on('drop', onDropFunc);
|
||||||
|
|
||||||
|
|
||||||
|
// ----------- 新增 --------------
|
||||||
|
var $createModal = $('.modal.admin-add-weapp-advert-modal');
|
||||||
|
var $createForm = $createModal.find('form.admin-add-weapp-advert-form');
|
||||||
|
|
||||||
|
$createForm.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
"weapp_settings_advert[image]": {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$createModal.on('show.bs.modal', function(event){
|
||||||
|
resetFileInputFunc($createModal.find('.img-file-input'));
|
||||||
|
$createModal.find('.file-names').html('选择文件');
|
||||||
|
});
|
||||||
|
|
||||||
|
$createModal.on('click', '.submit-btn', function() {
|
||||||
|
$createForm.find('.error').html('');
|
||||||
|
|
||||||
|
if ($createForm.valid()) {
|
||||||
|
$createForm.submit();
|
||||||
|
} else {
|
||||||
|
$createForm.find('.error').html('请选择图片');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$createModal.on('change', '.img-file-input', function(){
|
||||||
|
var file = $(this)[0].files[0];
|
||||||
|
$createModal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||||
|
})
|
||||||
|
|
||||||
|
// -------------- 重新上传图片 --------------
|
||||||
|
//replace_image_url
|
||||||
|
$('.modal.admin-upload-file-modal').on('upload:success', function(e, data){
|
||||||
|
var $advertItem = $('.advert-item-' + data.source_id);
|
||||||
|
$advertItem.find('.advert-item-img img').attr('src', data.url);
|
||||||
|
})
|
||||||
|
|
||||||
|
// 删除后
|
||||||
|
$(document).on('delete_success', resetNo)
|
||||||
|
}
|
||||||
|
})
|
@ -0,0 +1,123 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-weapp-carousels-index-page').length > 0) {
|
||||||
|
var resetNo = function(){
|
||||||
|
$('#carousels-container .custom-carousel-item-no').each(function(index, ele){
|
||||||
|
$(ele).html(index + 1);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// ------------ 保存链接 -----------
|
||||||
|
$('.carousels-card').on('click', '.save-data-btn', function(){
|
||||||
|
var $link = $(this);
|
||||||
|
var id = $link.data('id');
|
||||||
|
var link = $('.custom-carousel-item-' + id).find('.link-input').val();
|
||||||
|
$link.attr('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/weapp_carousels/' + id,
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { link: link },
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '操作成功' });
|
||||||
|
},
|
||||||
|
error: ajaxErrorNotifyHandler,
|
||||||
|
complete: function(){
|
||||||
|
$link.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
// -------------- 是否在首页展示 --------------
|
||||||
|
$('.carousels-card').on('change', '.online-check-box', function(){
|
||||||
|
var $checkbox = $(this);
|
||||||
|
var id = $checkbox.data('id');
|
||||||
|
var checked = $checkbox.is(':checked');
|
||||||
|
$checkbox.attr('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/weapp_carousels/' + id,
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { online: checked },
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '保存成功' });
|
||||||
|
var box = $('.custom-carousel-item-' + id).find('.drag');
|
||||||
|
if(checked){
|
||||||
|
box.removeClass('not_active');
|
||||||
|
}else{
|
||||||
|
box.addClass('not_active');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: ajaxErrorNotifyHandler,
|
||||||
|
complete: function(){
|
||||||
|
$checkbox.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// ------------ 拖拽 -------------
|
||||||
|
var onDropFunc = function(el, _target, _source, sibling){
|
||||||
|
var moveId = $(el).data('id');
|
||||||
|
var insertId = $(sibling).data('id') || '';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/weapp_carousels/drag',
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { move_id: moveId, after_id: insertId },
|
||||||
|
success: function(data){
|
||||||
|
resetNo();
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$.notify({message: '移动失败,原因:' + data.message}, {type: 'danger'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
var ele1 = document.getElementById('carousels-container');
|
||||||
|
dragula([ele1], { mirrorContainer: ele1 }).on('drop', onDropFunc);
|
||||||
|
|
||||||
|
|
||||||
|
// ----------- 新增 --------------
|
||||||
|
var $createModal = $('.modal.admin-add-weapp-carousel-modal');
|
||||||
|
var $createForm = $createModal.find('form.admin-add-weapp-carousel-form');
|
||||||
|
|
||||||
|
$createForm.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
"weapp_settings_carousel[image]": {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$createModal.on('show.bs.modal', function(event){
|
||||||
|
resetFileInputFunc($createModal.find('.img-file-input'));
|
||||||
|
$createModal.find('.file-names').html('选择文件');
|
||||||
|
});
|
||||||
|
|
||||||
|
$createModal.on('click', '.submit-btn', function() {
|
||||||
|
$createForm.find('.error').html('');
|
||||||
|
|
||||||
|
if ($createForm.valid()) {
|
||||||
|
$createForm.submit();
|
||||||
|
} else {
|
||||||
|
$createForm.find('.error').html('请选择图片');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$createModal.on('change', '.img-file-input', function(){
|
||||||
|
var file = $(this)[0].files[0];
|
||||||
|
$createModal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||||
|
})
|
||||||
|
|
||||||
|
// -------------- 重新上传图片 --------------
|
||||||
|
//replace_image_url
|
||||||
|
$('.modal.admin-upload-file-modal').on('upload:success', function(e, data){
|
||||||
|
var $carouselItem = $('.custom-carousel-item-' + data.source_id);
|
||||||
|
$carouselItem.find('.custom-carousel-item-img img').attr('src', data.url);
|
||||||
|
})
|
||||||
|
|
||||||
|
// 删除后
|
||||||
|
$(document).on('delete_success', resetNo)
|
||||||
|
}
|
||||||
|
})
|
@ -0,0 +1,130 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.cooperative-carousels-index-page').length > 0) {
|
||||||
|
var resetNo = function(){
|
||||||
|
$('#carousels-container .custom-carousel-item-no').each(function(index, ele){
|
||||||
|
$(ele).html(index + 1);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 删除后
|
||||||
|
$(document).on('delete_success', resetNo);
|
||||||
|
// ------------ 保存链接 -----------
|
||||||
|
$('.carousels-card').on('click', '.save-data-btn', function(){
|
||||||
|
var $link = $(this);
|
||||||
|
var id = $link.data('id');
|
||||||
|
var link = $('.custom-carousel-item-' + id).find('.link-input').val();
|
||||||
|
var name = $('.custom-carousel-item-' + id).find('.name-input').val();
|
||||||
|
if(!name || name.length == 0){
|
||||||
|
$.notify({ message: '名称不能为空' },{ type: 'danger' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$link.attr('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/cooperative/carousels/' + id,
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { link: link, name: name },
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '操作成功' });
|
||||||
|
},
|
||||||
|
error: ajaxErrorNotifyHandler,
|
||||||
|
complete: function(){
|
||||||
|
$link.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
// -------------- 是否在首页展示 --------------
|
||||||
|
$('.carousels-card').on('change', '.online-check-box', function(){
|
||||||
|
var $checkbox = $(this);
|
||||||
|
var id = $checkbox.data('id');
|
||||||
|
var checked = $checkbox.is(':checked');
|
||||||
|
$checkbox.attr('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/cooperative/carousels/' + id,
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { status: checked },
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '保存成功' });
|
||||||
|
var box = $('.custom-carousel-item-' + id).find('.drag');
|
||||||
|
if(checked){
|
||||||
|
box.removeClass('not_active');
|
||||||
|
}else{
|
||||||
|
box.addClass('not_active');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: ajaxErrorNotifyHandler,
|
||||||
|
complete: function(){
|
||||||
|
$checkbox.removeAttr('disabled');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// ------------ 拖拽 -------------
|
||||||
|
var onDropFunc = function(el, _target, _source, sibling){
|
||||||
|
var moveId = $(el).data('id');
|
||||||
|
var insertId = $(sibling).data('id') || '';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/cooperative/carousels/drag',
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { move_id: moveId, after_id: insertId },
|
||||||
|
success: function(data){
|
||||||
|
resetNo();
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$.notify({message: '移动失败,原因:' + data.message}, {type: 'danger'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
var ele1 = document.getElementById('carousels-container');
|
||||||
|
dragula([ele1], { mirrorContainer: ele1 }).on('drop', onDropFunc);
|
||||||
|
|
||||||
|
|
||||||
|
// ----------- 新增 --------------
|
||||||
|
var $createModal = $('.modal.cooperative-add-carousel-modal');
|
||||||
|
var $createForm = $createModal.find('form.cooperative-add-carousel-form');
|
||||||
|
|
||||||
|
$createForm.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
"portal_image[image]": {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
"portal_image[name]": {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$createModal.on('show.bs.modal', function(event){
|
||||||
|
resetFileInputFunc($createModal.find('.img-file-input'));
|
||||||
|
$createModal.find('.file-names').html('选择文件');
|
||||||
|
});
|
||||||
|
|
||||||
|
$createModal.on('click', '.submit-btn', function() {
|
||||||
|
$createForm.find('.error').html('');
|
||||||
|
|
||||||
|
if ($createForm.valid()) {
|
||||||
|
$createForm.submit();
|
||||||
|
} else {
|
||||||
|
$createForm.find('.error').html('请选择图片');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$createModal.on('change', '.img-file-input', function(){
|
||||||
|
var file = $(this)[0].files[0];
|
||||||
|
$createModal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||||
|
})
|
||||||
|
|
||||||
|
// -------------- 重新上传图片 --------------
|
||||||
|
//replace_image_url
|
||||||
|
$('.modal.cooperative-upload-file-modal').on('upload:success', function(e, data){
|
||||||
|
var $carouselItem = $('.custom-carousel-item-' + data.source_id);
|
||||||
|
$carouselItem.find('.custom-carousel-item-img img').attr('src', data.url);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
@ -0,0 +1,62 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.cooperative-laboratory-users-index-page').length > 0) {
|
||||||
|
// ============= 添加管理员 ==============
|
||||||
|
var $addMemberModal = $('.cooperative-add-laboratory-user-modal');
|
||||||
|
var $addMemberForm = $addMemberModal.find('.cooperative-add-laboratory-user-form');
|
||||||
|
var $memberSelect = $addMemberModal.find('.laboratory-user-select');
|
||||||
|
|
||||||
|
$addMemberModal.on('show.bs.modal', function(event){
|
||||||
|
$memberSelect.select2('val', ' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
$memberSelect.select2({
|
||||||
|
theme: 'bootstrap4',
|
||||||
|
placeholder: '请输入要添加的管理员姓名',
|
||||||
|
multiple: true,
|
||||||
|
minimumInputLength: 1,
|
||||||
|
ajax: {
|
||||||
|
delay: 500,
|
||||||
|
url: '/cooperative/users',
|
||||||
|
dataType: 'json',
|
||||||
|
data: function(params){
|
||||||
|
return { name: params.term };
|
||||||
|
},
|
||||||
|
processResults: function(data){
|
||||||
|
return { results: data.users }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
templateResult: function (item) {
|
||||||
|
if(!item.id || item.id === '') return item.text;
|
||||||
|
return item.real_name + "--" + item.identity;
|
||||||
|
},
|
||||||
|
templateSelection: function(item){
|
||||||
|
if (item.id) {
|
||||||
|
}
|
||||||
|
return item.real_name || item.text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$addMemberModal.on('click', '.submit-btn', function(){
|
||||||
|
$addMemberForm.find('.error').html('');
|
||||||
|
|
||||||
|
var memberIds = $memberSelect.val();
|
||||||
|
if (memberIds && memberIds.length > 0) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/cooperative/laboratory_users',
|
||||||
|
data: { user_ids: memberIds },
|
||||||
|
success: function(data){
|
||||||
|
if(data && data.status == 0){
|
||||||
|
show_success_flash();
|
||||||
|
$addMemberModal.modal('hide');
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$addMemberModal.modal('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,62 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
var $modal = $('.modal.cooperative-upload-file-modal');
|
||||||
|
if ($modal.length > 0) {
|
||||||
|
var $form = $modal.find('form.cooperative-upload-file-form')
|
||||||
|
var $sourceIdInput = $modal.find('input[name="source_id"]');
|
||||||
|
var $sourceTypeInput = $modal.find('input[name="source_type"]');
|
||||||
|
|
||||||
|
$modal.on('show.bs.modal', function(event){
|
||||||
|
var $link = $(event.relatedTarget);
|
||||||
|
var sourceId = $link.data('sourceId');
|
||||||
|
var sourceType = $link.data('sourceType');
|
||||||
|
|
||||||
|
$sourceIdInput.val(sourceId);
|
||||||
|
$sourceTypeInput.val(sourceType);
|
||||||
|
|
||||||
|
$modal.find('.upload-file-input').trigger('click');
|
||||||
|
});
|
||||||
|
|
||||||
|
$modal.find('.upload-file-input').on('change', function(e){
|
||||||
|
var file = $(this)[0].files[0];
|
||||||
|
|
||||||
|
if(file){
|
||||||
|
$modal.find('.file-names').html(file.name);
|
||||||
|
$modal.find('.submit-btn').trigger('click');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var formValid = 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
$modal.on('click', '.submit-btn', function(){
|
||||||
|
$form.find('.error').html('');
|
||||||
|
|
||||||
|
if (formValid()) {
|
||||||
|
var formDataString = $form.serialize();
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/cooperatives/files?' + formDataString,
|
||||||
|
data: new FormData($form[0]),
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function(data){
|
||||||
|
$.notify({ message: '上传成功' });
|
||||||
|
$modal.trigger('upload:success', data);
|
||||||
|
$modal.modal('hide');
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$form.find('.error').html(data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,60 @@
|
|||||||
|
.admins-weapp-adverts-index-page {
|
||||||
|
.adverts-card {
|
||||||
|
.advert-item {
|
||||||
|
& > .drag {
|
||||||
|
cursor: move;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 1px 2px 5px 3px #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-no {
|
||||||
|
font-size: 28px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-img {
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
|
||||||
|
& > img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
background: #F5F5F5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.not_active {
|
||||||
|
background: #F0F0F0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
font-size: 20px;
|
||||||
|
color: red;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-url-btn {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operate-box {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.online-check-box {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name-input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.link-input {
|
||||||
|
flex: 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
.admins-weapp-carousels-index-page {
|
||||||
|
.carousels-card {
|
||||||
|
.custom-carousel-item {
|
||||||
|
& > .drag {
|
||||||
|
cursor: move;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 1px 2px 5px 3px #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-no {
|
||||||
|
font-size: 28px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-img {
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
|
||||||
|
& > img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
background: #F5F5F5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.not_active {
|
||||||
|
background: #F0F0F0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
font-size: 20px;
|
||||||
|
color: red;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-url-btn {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operate-box {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.online-check-box {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name-input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.link-input {
|
||||||
|
flex: 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
.cooperative-carousels-index-page {
|
||||||
|
.carousels-card {
|
||||||
|
.custom-carousel-item {
|
||||||
|
& > .drag {
|
||||||
|
cursor: move;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 1px 2px 5px 3px #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-no {
|
||||||
|
font-size: 28px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-img {
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
|
||||||
|
& > img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 60px;
|
||||||
|
background: #F5F5F5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.not_active {
|
||||||
|
background: #F0F0F0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
font-size: 20px;
|
||||||
|
color: red;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-url-btn {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operate-box {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.online-check-box {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.name-input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.link-input {
|
||||||
|
flex: 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
class Admins::EnrollListsController < Admins::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@competition = current_competition
|
||||||
|
default_sort('created_at', 'desc')
|
||||||
|
enroll_lists = Admins::CompetitionEnrollListQuery.call(@competition, params)
|
||||||
|
|
||||||
|
@params_page = params[:page] || 1
|
||||||
|
@enroll_lists = paginate enroll_lists.preload(competition_team: [:user, :teachers], user: { user_extension: :school })
|
||||||
|
@personal = @competition.personal?
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
format.html
|
||||||
|
format.xls{
|
||||||
|
filename = "#{@competition.name}竞赛报名列表_#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}.xls"
|
||||||
|
send_data(shixun_list_xls(shixuns), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def export
|
||||||
|
default_sort('created_at', 'desc')
|
||||||
|
@enroll_lists = Admins::CompetitionEnrollListQuery.call(current_competition, params)
|
||||||
|
|
||||||
|
filename = ["#{current_competition.name}竞赛报名列表", Time.zone.now.strftime('%Y-%m-%d%H:%M:%S')].join('-') << '.xlsx'
|
||||||
|
render xlsx: 'export', filename: filename
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def current_competition
|
||||||
|
@_current_competition ||= Competition.find(params[:competition_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,19 @@
|
|||||||
|
class Admins::UserStatisticsController < Admins::BaseController
|
||||||
|
def index
|
||||||
|
default_sort('finish_shixun_count', 'desc')
|
||||||
|
|
||||||
|
total_count, users = Admins::UserStatisticQuery.call(params)
|
||||||
|
|
||||||
|
@users = paginate users, total_count: total_count
|
||||||
|
end
|
||||||
|
|
||||||
|
def export
|
||||||
|
default_sort('finish_shixun_count', 'desc')
|
||||||
|
|
||||||
|
params[:per_page] = 10000
|
||||||
|
_count, @users = Admins::UserStatisticQuery.call(params)
|
||||||
|
|
||||||
|
filename = ['用户实训情况', Time.zone.now.strftime('%Y%m%d%H%M%S')].join('-') << '.xlsx'
|
||||||
|
render xlsx: 'export', filename: filename
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,79 @@
|
|||||||
|
class Admins::WeappAdvertsController < Admins::BaseController
|
||||||
|
before_action :convert_file!, only: [:create]
|
||||||
|
def index
|
||||||
|
@adverts = WeappSettings::Advert.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
position = WeappSettings::Advert.count + 1
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
advert = WeappSettings::Advert.create!(create_params.merge(position: position))
|
||||||
|
|
||||||
|
file_path = Util::FileManage.source_disk_filename(advert)
|
||||||
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||||
|
Util.write_file(@file, file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
flash[:success] = '保存成功'
|
||||||
|
redirect_to admins_weapp_adverts_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
current_advert.update!(update_params)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
current_advert.destroy!
|
||||||
|
# 前移
|
||||||
|
WeappSettings::Advert.where('position > ?', current_advert.position)
|
||||||
|
.update_all('position = position - 1')
|
||||||
|
|
||||||
|
file_path = Util::FileManage.source_disk_filename(current_advert)
|
||||||
|
File.delete(file_path) if File.exist?(file_path)
|
||||||
|
end
|
||||||
|
render_delete_success
|
||||||
|
end
|
||||||
|
|
||||||
|
def drag
|
||||||
|
move = WeappSettings::Advert.find_by(id: params[:move_id])
|
||||||
|
after = WeappSettings::Advert.find_by(id: params[:after_id])
|
||||||
|
|
||||||
|
Admins::DragWeappAdvertService.call(move, after)
|
||||||
|
render_ok
|
||||||
|
rescue ApplicationService::Error => e
|
||||||
|
render_error(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_advert
|
||||||
|
@_current_advert ||= WeappSettings::Advert.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_params
|
||||||
|
params.require(:weapp_settings_advert).permit(:link)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_params
|
||||||
|
params.permit(:link, :online)
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_file!
|
||||||
|
max_size = 10 * 1024 * 1024 # 10M
|
||||||
|
file = params.dig('weapp_settings_advert', 'image')
|
||||||
|
if file.class == ActionDispatch::Http::UploadedFile
|
||||||
|
@file = file
|
||||||
|
render_error('请上传文件') if @file.size.zero?
|
||||||
|
render_error('文件大小超过限制') if @file.size > max_size
|
||||||
|
else
|
||||||
|
file = file.to_s.strip
|
||||||
|
return render_error('请上传正确的图片') if file.blank?
|
||||||
|
@file = Util.convert_base64_image(file, max_size: max_size)
|
||||||
|
end
|
||||||
|
rescue Base64ImageConverter::Error => ex
|
||||||
|
render_error(ex.message)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,80 @@
|
|||||||
|
class Admins::WeappCarouselsController < Admins::BaseController
|
||||||
|
before_action :convert_file!, only: [:create]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@carousels = WeappSettings::Carousel.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
position = WeappSettings::Carousel.count + 1
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
carousel = WeappSettings::Carousel.create!(create_params.merge(position: position))
|
||||||
|
|
||||||
|
file_path = Util::FileManage.source_disk_filename(carousel)
|
||||||
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||||
|
Util.write_file(@file, file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
flash[:success] = '保存成功'
|
||||||
|
redirect_to admins_weapp_carousels_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
current_carousel.update!(update_params)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
current_carousel.destroy!
|
||||||
|
# 前移
|
||||||
|
WeappSettings::Carousel.where('position > ?', current_carousel.position)
|
||||||
|
.update_all('position = position - 1')
|
||||||
|
|
||||||
|
file_path = Util::FileManage.source_disk_filename(current_carousel)
|
||||||
|
File.delete(file_path) if File.exist?(file_path)
|
||||||
|
end
|
||||||
|
render_delete_success
|
||||||
|
end
|
||||||
|
|
||||||
|
def drag
|
||||||
|
move = WeappSettings::Carousel.find_by(id: params[:move_id])
|
||||||
|
after = WeappSettings::Carousel.find_by(id: params[:after_id])
|
||||||
|
|
||||||
|
Admins::DragWeappCarouselService.call(move, after)
|
||||||
|
render_ok
|
||||||
|
rescue ApplicationService::Error => e
|
||||||
|
render_error(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_carousel
|
||||||
|
@_current_carousel ||= WeappSettings::Carousel.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_params
|
||||||
|
params.require(:weapp_settings_carousel).permit(:link)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_params
|
||||||
|
params.permit(:link, :online)
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_file!
|
||||||
|
max_size = 10 * 1024 * 1024 # 10M
|
||||||
|
file = params.dig('weapp_settings_carousel', 'image')
|
||||||
|
if file.class == ActionDispatch::Http::UploadedFile
|
||||||
|
@file = file
|
||||||
|
render_error('请上传文件') if @file.size.zero?
|
||||||
|
render_error('文件大小超过限制') if @file.size > max_size
|
||||||
|
else
|
||||||
|
file = file.to_s.strip
|
||||||
|
return render_error('请上传正确的图片') if file.blank?
|
||||||
|
@file = Util.convert_base64_image(file, max_size: max_size)
|
||||||
|
end
|
||||||
|
rescue Base64ImageConverter::Error => ex
|
||||||
|
render_error(ex.message)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,80 @@
|
|||||||
|
class Cooperative::CarouselsController < Cooperative::BaseController
|
||||||
|
before_action :convert_file!, only: [:create]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@images = current_laboratory.portal_images.order(position: :asc)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
position = current_laboratory.portal_images.count + 1
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
image = current_laboratory.portal_images.create!(create_params.merge(position: position))
|
||||||
|
|
||||||
|
file_path = Util::FileManage.disk_filename('PortalImage', image.id)
|
||||||
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||||
|
Util.write_file(@file, file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
flash[:success] = '保存成功'
|
||||||
|
redirect_to cooperative_carousels_path(current_laboratory)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
current_image.update!(update_params)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
current_image.destroy!
|
||||||
|
# 前移
|
||||||
|
current_laboratory.portal_images.where('position > ?', current_image.position)
|
||||||
|
.update_all('position = position - 1')
|
||||||
|
|
||||||
|
file_path = Util::FileManage.disk_filename('PortalImage', current_image.id)
|
||||||
|
File.delete(file_path) if File.exist?(file_path)
|
||||||
|
end
|
||||||
|
render_delete_success
|
||||||
|
end
|
||||||
|
|
||||||
|
def drag
|
||||||
|
move = current_laboratory.portal_images.find_by(id: params[:move_id])
|
||||||
|
after = current_laboratory.portal_images.find_by(id: params[:after_id])
|
||||||
|
|
||||||
|
Admins::DragPortalImageService.call(current_laboratory, move, after)
|
||||||
|
render_ok
|
||||||
|
rescue Admins::DragPortalImageService::Error => e
|
||||||
|
render_error(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_image
|
||||||
|
@_current_image ||= current_laboratory.portal_images.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_params
|
||||||
|
params.require(:portal_image).permit(:name, :link)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_params
|
||||||
|
params.permit(:name, :link, :status)
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_file!
|
||||||
|
max_size = 10 * 1024 * 1024 # 10M
|
||||||
|
file = params.dig('portal_image', 'image')
|
||||||
|
if file.class == ActionDispatch::Http::UploadedFile
|
||||||
|
@file = file
|
||||||
|
render_error('请上传文件') if @file.size.zero?
|
||||||
|
render_error('文件大小超过限制') if @file.size > max_size
|
||||||
|
else
|
||||||
|
file = file.to_s.strip
|
||||||
|
return render_error('请上传正确的图片') if file.blank?
|
||||||
|
@file = Util.convert_base64_image(file, max_size: max_size)
|
||||||
|
end
|
||||||
|
rescue Base64ImageConverter::Error => ex
|
||||||
|
render_error(ex.message)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,46 @@
|
|||||||
|
class Cooperative::FilesController < Cooperative::BaseController
|
||||||
|
before_action :convert_file!, only: [:create]
|
||||||
|
|
||||||
|
def create
|
||||||
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||||
|
|
||||||
|
Util.write_file(@file, file_path)
|
||||||
|
|
||||||
|
render_ok(source_id: params[:source_id], source_type: params[:source_type].to_s, url: file_url + "?t=#{Random.rand}")
|
||||||
|
rescue StandardError => ex
|
||||||
|
logger_error(ex)
|
||||||
|
render_error('上传失败')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def convert_file!
|
||||||
|
max_size = 10 * 1024 * 1024 # 10M
|
||||||
|
if params[:file].class == ActionDispatch::Http::UploadedFile
|
||||||
|
@file = params[:file]
|
||||||
|
render_error('请上传文件') if @file.size.zero?
|
||||||
|
render_error('文件大小超过限制') if @file.size > max_size
|
||||||
|
else
|
||||||
|
file = params[:file].to_s.strip
|
||||||
|
return render_error('请上传正确的图片') if file.blank?
|
||||||
|
@file = Util.convert_base64_image(file, max_size: max_size)
|
||||||
|
end
|
||||||
|
rescue Base64ImageConverter::Error => ex
|
||||||
|
render_error(ex.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_path
|
||||||
|
@_file_path ||= begin
|
||||||
|
case params[:source_type].to_s
|
||||||
|
when 'Shixun' then
|
||||||
|
Util::FileManage.disk_filename('Shixun', params[:source_id])
|
||||||
|
else
|
||||||
|
Util::FileManage.disk_filename(params[:source_type].to_s, params[:source_id].to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_url
|
||||||
|
Util::FileManage.disk_file_url(params[:source_type].to_s, params[:source_id].to_s)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,24 @@
|
|||||||
|
class Cooperative::LaboratoryUsersController < Cooperative::BaseController
|
||||||
|
def index
|
||||||
|
laboratory_users = current_laboratory.laboratory_users
|
||||||
|
@laboratory_users = paginate laboratory_users.includes(user: { user_extension: [:school, :department] })
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
Admins::AddLaboratoryUserService.call(current_laboratory, params.permit(user_ids: []))
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
return render_error('不能删除自己', type: :notify) if current_laboratory_user.user_id == current_user.id
|
||||||
|
current_laboratory_user.destroy!
|
||||||
|
|
||||||
|
render_delete_success
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_laboratory_user
|
||||||
|
@_current_laboratory_user ||= current_laboratory.laboratory_users.find(params[:id])
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
class Cooperative::UsersController < Cooperative::BaseController
|
||||||
|
def index
|
||||||
|
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||||
|
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||||
|
params[:school_id] = current_laboratory.school_id
|
||||||
|
|
||||||
|
users = Admins::UserQuery.call(params)
|
||||||
|
@users = paginate users.includes(user_extension: :school)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
class HotKeywordsController < ApplicationController
|
||||||
|
def index
|
||||||
|
keywords = []
|
||||||
|
keywords = HotSearchKeyword.hot(8) if HotSearchKeyword.available?
|
||||||
|
render_ok(keywords: keywords)
|
||||||
|
end
|
||||||
|
end
|
@ -1,5 +1,5 @@
|
|||||||
class MainController < ApplicationController
|
class MainController < ApplicationController
|
||||||
def index
|
def index
|
||||||
render file: 'public/react/build/index', formats: [:html]
|
render file: 'public/react/build/index.html', :layout => false
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,9 +1,12 @@
|
|||||||
class SearchsController < ApplicationController
|
class SearchsController < ApplicationController
|
||||||
|
after_action :record_search_keyword, only: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@results = SearchService.call(search_params)
|
@results = SearchService.call(search_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def search_params
|
def search_params
|
||||||
params.permit(:keyword, :type, :page, :per_page)
|
params.permit(:keyword, :type, :page, :per_page)
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
class Weapps::HomesController < Weapps::BaseController
|
class Weapps::HomesController < Weapps::BaseController
|
||||||
def show
|
def show
|
||||||
# banner图
|
# banner
|
||||||
@images = PortalImage.where(status: true).order(position: :asc)
|
@carousels = WeappSettings::Carousel.only_online
|
||||||
|
# 广告
|
||||||
|
@advert = WeappSettings::Advert.only_online.first
|
||||||
|
|
||||||
# 热门实训
|
# 热门实训
|
||||||
@shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(4)
|
@shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(4)
|
||||||
|
|
||||||
# 热门实践课程
|
# 热门实践课程
|
||||||
@subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(4)
|
@subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(4)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class Weapps::SearchsController < Weapps::BaseController
|
||||||
|
after_action :record_search_keyword, only: [:index]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@results = Weapps::SearchQuery.call(search_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:keyword, :type, :page, :per_page)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,54 @@
|
|||||||
|
module CompetitionsHelper
|
||||||
|
def chart_school_str user_ids
|
||||||
|
chart_school_name = ""
|
||||||
|
chart_school_name = School.where(id: UserExtension.where(user_id: user_ids).pluck(:school_id).uniq).pluck(:name).join("、")
|
||||||
|
end
|
||||||
|
|
||||||
|
# 耗时:小时、分、秒 00:00:00
|
||||||
|
# 小于1秒钟则不显示
|
||||||
|
def com_spend_time time
|
||||||
|
hour = time / (60*60)
|
||||||
|
min = time % (60*60) / 60
|
||||||
|
sec = time % (60*60) % 60
|
||||||
|
hour_str = "00"
|
||||||
|
min_str = "00"
|
||||||
|
sec_str = "00"
|
||||||
|
if hour >= 1 && hour < 10
|
||||||
|
hour_str = "0#{hour}"
|
||||||
|
elsif hour >= 10
|
||||||
|
hour_str = "#{hour}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if min >= 1 && min < 10
|
||||||
|
min_str = "0#{min}"
|
||||||
|
elsif min >= 10
|
||||||
|
min_str = "#{min}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if sec >= 1 && sec < 10
|
||||||
|
sec_str = "0#{sec}"
|
||||||
|
elsif sec >= 10
|
||||||
|
sec_str = "#{sec}"
|
||||||
|
end
|
||||||
|
|
||||||
|
time = "#{hour_str} : #{min_str} : #{sec_str}"
|
||||||
|
return time
|
||||||
|
end
|
||||||
|
|
||||||
|
def chart_stages competition
|
||||||
|
stages = []
|
||||||
|
statistic_stages = competition.competition_stages.where("rate > 0")
|
||||||
|
if competition.end_time && competition.end_time < Time.now && statistic_stages.size > 1
|
||||||
|
stages << {id: nil, name: "总排行榜", rate: 1.0, start_time: competition.start_time, end_time: competition.end_time}
|
||||||
|
end
|
||||||
|
|
||||||
|
statistic_stages.each do |stage|
|
||||||
|
if stage.max_end_time && stage.max_end_time < Time.now
|
||||||
|
stages << {id: stage.id, name: "#{stage.name}排行榜", rate: stage.score_rate, start_time: stage.min_start_time, end_time: stage.max_end_time}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stages = stages.sort { |a, b| b[:end_time] <=> a[:end_time] } if stages.size > 0
|
||||||
|
return stages
|
||||||
|
end
|
||||||
|
end
|
@ -1,9 +1,15 @@
|
|||||||
class ApplicationRecord < ActiveRecord::Base
|
class ApplicationRecord < ActiveRecord::Base
|
||||||
include NumberDisplayHelper
|
include NumberDisplayHelper
|
||||||
|
|
||||||
|
attr_accessor :_extra_data
|
||||||
|
|
||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
|
|
||||||
def format_time(time)
|
def format_time(time)
|
||||||
time.present? ? time.strftime('%Y-%m-%d %H:%M') : ''
|
time.present? ? time.strftime('%Y-%m-%d %H:%M') : ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def display_extra_data(key)
|
||||||
|
_extra_data&.[](key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
class ChartRule < ApplicationRecord
|
||||||
|
belongs_to :competition
|
||||||
|
belongs_to :competition_stage, optional: true
|
||||||
|
|
||||||
|
validates :content, length: { maximum: 1000 }
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class CompetitionAward < ApplicationRecord
|
||||||
|
belongs_to :competition
|
||||||
|
end
|
@ -1,3 +1,4 @@
|
|||||||
class CompetitionModeSetting < ApplicationRecord
|
class CompetitionModeSetting < ApplicationRecord
|
||||||
belongs_to :course
|
belongs_to :course, optional: true
|
||||||
|
belongs_to :competition
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
class CompetitionScore < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :competition
|
||||||
|
belongs_to :competition_stage, optional: true
|
||||||
|
belongs_to :competition_team, optional: true
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
class ModuleSetting < ApplicationRecord
|
||||||
|
end
|
@ -0,0 +1,4 @@
|
|||||||
|
class ShixunReview < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :shixun
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class WeappSetting < ApplicationRecord
|
||||||
|
scope :only_online, -> { where(online: true) }
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
class WeappSettings::Advert < WeappSetting
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class WeappSettings::Carousel < WeappSetting
|
||||||
|
default_scope { order(position: :asc) }
|
||||||
|
end
|
@ -0,0 +1,40 @@
|
|||||||
|
class Admins::CompetitionEnrollListQuery < ApplicationQuery
|
||||||
|
include CustomSortable
|
||||||
|
|
||||||
|
attr_reader :competition, :params
|
||||||
|
|
||||||
|
sort_columns :created_at, :competition_team_id, default_by: :created_at, default_direction: :desc
|
||||||
|
|
||||||
|
def initialize(competition, params)
|
||||||
|
@competition = competition
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
members = competition.team_members
|
||||||
|
only_teacher = competition.competition_staffs.count == 1 && competition.competition_staffs.first.category == 'teacher'
|
||||||
|
members = members.where("team_members.is_teacher = 0") unless only_teacher # 只有老师报名时才显示老师,此时老师作为队员
|
||||||
|
|
||||||
|
|
||||||
|
school = params[:school].to_s.strip
|
||||||
|
if school.present?
|
||||||
|
school_ids = School.where("schools.name like ?", "%#{school}%").pluck(:id)
|
||||||
|
school_ids = school_ids.size == 0 ? "(-1)" : "(" + school_ids.join(",") + ")"
|
||||||
|
members = members.joins(user: :user_extension).where("user_extensions.school_id in #{school_ids}")
|
||||||
|
end
|
||||||
|
|
||||||
|
location = params[:location].to_s.strip
|
||||||
|
if location.present?
|
||||||
|
members = members.joins(user: { user_extension: :school }).where("schools.province like ?", "%#{location}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
# 关键字模糊查询
|
||||||
|
keyword = params[:keyword].to_s.strip
|
||||||
|
if keyword.present?
|
||||||
|
members = members.joins(:competition_team)
|
||||||
|
.where('competition_teams.name LIKE :keyword', keyword: "%#{keyword}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
custom_sort(members, params[:sort_by], params[:sort_direction])
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,142 @@
|
|||||||
|
class Admins::UserStatisticQuery < ApplicationQuery
|
||||||
|
include CustomSortable
|
||||||
|
|
||||||
|
attr_reader :params
|
||||||
|
|
||||||
|
sort_columns :study_challenge_count, :finish_challenge_count, :study_shixun_count, :finish_shixun_count,
|
||||||
|
default_by: :finish_shixun_count, default_direction: :desc
|
||||||
|
|
||||||
|
def initialize(params)
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
users = User.where(type: 'User').group(:id)
|
||||||
|
|
||||||
|
users = users.joins(:user_extension).where(user_extensions: { school_id: params[:school_id] }) if params[:school_id].present?
|
||||||
|
|
||||||
|
total = users.count.count
|
||||||
|
|
||||||
|
# 根据排序字段进行查询
|
||||||
|
users = query_by_sort_column(users, params[:sort_by])
|
||||||
|
users = custom_sort(users, params[:sort_by], params[:sort_direction])
|
||||||
|
|
||||||
|
users = users.includes(user_extension: [:school, :department])
|
||||||
|
users = users.limit(page_size).offset(offset).to_a
|
||||||
|
# 查询并组装其它数据
|
||||||
|
users = package_other_data(users)
|
||||||
|
|
||||||
|
[total, users]
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def package_other_data(users)
|
||||||
|
ids = users.map(&:id)
|
||||||
|
|
||||||
|
study_myshixun = Myshixun.where(user_id: ids)
|
||||||
|
finish_myshixun = Myshixun.where(user_id: ids, status: 1)
|
||||||
|
study_challenge = Game.joins(:myshixun).where(myshixuns: { user_id: ids }).where(status: [0, 1, 2])
|
||||||
|
finish_challenge = Game.joins(:myshixun).where(myshixuns: { user_id: ids }).where(status: 2)
|
||||||
|
|
||||||
|
if time_range.present?
|
||||||
|
study_myshixun = study_myshixun.where(updated_at: time_range)
|
||||||
|
finish_myshixun = finish_myshixun.where(updated_at: time_range)
|
||||||
|
study_challenge = study_challenge.where(updated_at: time_range)
|
||||||
|
finish_challenge = finish_challenge.where(updated_at: time_range)
|
||||||
|
end
|
||||||
|
|
||||||
|
study_myshixun_map = study_myshixun.group(:user_id).count
|
||||||
|
finish_myshixun_map = finish_myshixun.group(:user_id).count
|
||||||
|
study_challenge_map = study_challenge.group(:user_id).count
|
||||||
|
finish_challenge_map = finish_challenge.group(:user_id).count
|
||||||
|
evaluate_count_map = study_challenge.group(:user_id).sum(:evaluate_count)
|
||||||
|
cost_time_map = study_challenge.group(:user_id).sum(:cost_time)
|
||||||
|
|
||||||
|
users.each do |user|
|
||||||
|
user._extra_data = {
|
||||||
|
study_shixun_count: study_myshixun_map.fetch(user.id, 0),
|
||||||
|
finish_shixun_count: finish_myshixun_map.fetch(user.id, 0),
|
||||||
|
study_challenge_count: study_challenge_map.fetch(user.id, 0),
|
||||||
|
finish_challenge_count: finish_challenge_map.fetch(user.id, 0),
|
||||||
|
evaluate_count: evaluate_count_map.fetch(user.id, 0),
|
||||||
|
cost_time: cost_time_map.fetch(user.id, 0),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
users
|
||||||
|
end
|
||||||
|
|
||||||
|
def query_by_sort_column(users, sort_by_column)
|
||||||
|
base_query_column = 'users.*'
|
||||||
|
|
||||||
|
case sort_by_column.to_s
|
||||||
|
when 'study_shixun_count' then
|
||||||
|
users =
|
||||||
|
if time_range.present?
|
||||||
|
users.joins("LEFT JOIN myshixuns ON myshixuns.user_id = users.id "\
|
||||||
|
"AND myshixuns.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
|
||||||
|
else
|
||||||
|
users.left_joins(:myshixuns)
|
||||||
|
end
|
||||||
|
|
||||||
|
users.select("#{base_query_column}, COUNT(*) study_shixun_count")
|
||||||
|
when 'finish_shixun_count' then
|
||||||
|
users =
|
||||||
|
if time_range.present?
|
||||||
|
users.joins("LEFT JOIN myshixuns ON myshixuns.user_id = users.id AND myshixuns.status = 1 AND "\
|
||||||
|
"myshixuns.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
|
||||||
|
else
|
||||||
|
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id AND myshixuns.status = 1')
|
||||||
|
end
|
||||||
|
|
||||||
|
users.select("#{base_query_column}, COUNT(*) finish_shixun_count")
|
||||||
|
when 'study_challenge_count' then
|
||||||
|
users =
|
||||||
|
if time_range.present?
|
||||||
|
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
|
||||||
|
.joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id "\
|
||||||
|
"AND games.status IN (0,1,2) AND games.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
|
||||||
|
else
|
||||||
|
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
|
||||||
|
.joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id AND games.status IN (0,1,2)")
|
||||||
|
end
|
||||||
|
|
||||||
|
users.select("#{base_query_column}, COUNT(*) study_challenge_count")
|
||||||
|
when 'finish_challenge_count' then
|
||||||
|
users =
|
||||||
|
if time_range.present?
|
||||||
|
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
|
||||||
|
.joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id "\
|
||||||
|
"AND games.status = 2 AND games.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
|
||||||
|
else
|
||||||
|
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
|
||||||
|
.joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id AND games.status = 2")
|
||||||
|
end
|
||||||
|
|
||||||
|
users.select("#{base_query_column}, COUNT(*) finish_challenge_count")
|
||||||
|
else
|
||||||
|
users
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def time_range
|
||||||
|
@_time_range ||= begin
|
||||||
|
case params[:date]
|
||||||
|
when 'weekly' then 1.weeks.ago..Time.now
|
||||||
|
when 'monthly' then 1.months.ago..Time.now
|
||||||
|
when 'quarterly' then 3.months.ago..Time.now
|
||||||
|
when 'yearly' then 1.years.ago..Time.now
|
||||||
|
else ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_size
|
||||||
|
params[:per_page].to_i.zero? ? 20 : params[:per_page].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def offset
|
||||||
|
(params[:page].to_i.zero? ? 0 : params[:page].to_i - 1) * page_size
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,37 @@
|
|||||||
|
class Weapps::SearchQuery < ApplicationQuery
|
||||||
|
include ElasticsearchAble
|
||||||
|
|
||||||
|
attr_reader :params
|
||||||
|
|
||||||
|
def initialize(params)
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
modal_name.search(keyword, search_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_options
|
||||||
|
hash = {
|
||||||
|
fields: [:name],
|
||||||
|
page: page,
|
||||||
|
per_page: per_page
|
||||||
|
}
|
||||||
|
hash.merge(where: { status: 2 }) if modal_name == Shixun
|
||||||
|
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def modal_name
|
||||||
|
@_modal_name ||= begin
|
||||||
|
case params[:type].to_s
|
||||||
|
when 'subject' then Subject
|
||||||
|
when 'shixun' then Shixun
|
||||||
|
when 'course' then Course
|
||||||
|
else Subject
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,32 @@
|
|||||||
|
class Admins::DragWeappAdvertService < ApplicationService
|
||||||
|
attr_reader :move, :after
|
||||||
|
|
||||||
|
def initialize(move, after)
|
||||||
|
@move = move
|
||||||
|
@after = after # 移动后下一个位置的元素
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
return if move.position + 1 == after&.position # 未移动
|
||||||
|
|
||||||
|
carousels = WeappSettings::Advert.all
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
if after.blank? || move.id == after.id # 移动至末尾
|
||||||
|
total = carousels.count
|
||||||
|
|
||||||
|
carousels.where('position > ?', move.position).update_all('position = position - 1')
|
||||||
|
move.update!(position: total)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if move.position > after.position # 前移
|
||||||
|
carousels.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1')
|
||||||
|
move.update!(position: after.position)
|
||||||
|
else # 后移
|
||||||
|
carousels.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1')
|
||||||
|
move.update!(position: after.position - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,32 @@
|
|||||||
|
class Admins::DragWeappCarouselService < ApplicationService
|
||||||
|
attr_reader :move, :after
|
||||||
|
|
||||||
|
def initialize(move, after)
|
||||||
|
@move = move
|
||||||
|
@after = after # 移动后下一个位置的元素
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
return if move.position + 1 == after&.position # 未移动
|
||||||
|
|
||||||
|
carousels = WeappSettings::Carousel.all
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
if after.blank? || move.id == after.id # 移动至末尾
|
||||||
|
total = carousels.count
|
||||||
|
|
||||||
|
carousels.where('position > ?', move.position).update_all('position = position - 1')
|
||||||
|
move.update!(position: total)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if move.position > after.position # 前移
|
||||||
|
carousels.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1')
|
||||||
|
move.update!(position: after.position)
|
||||||
|
else # 后移
|
||||||
|
carousels.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1')
|
||||||
|
move.update!(position: after.position - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,16 @@
|
|||||||
|
<%
|
||||||
|
define_admin_breadcrumbs do
|
||||||
|
add_admin_breadcrumb('竞赛列表', admins_competitions_path)
|
||||||
|
add_admin_breadcrumb(@competition.name)
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
|
||||||
|
<div class="card mb-5">
|
||||||
|
<div class="card-header d-flex justify-content-between align-items-center">
|
||||||
|
<span class="flex-1">基础设置</span>
|
||||||
|
</div>
|
||||||
|
<div class="card-body row">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1 @@
|
|||||||
|
$('.competitions-list-container').html("<%= j( render partial: 'admins/competitions/shared/list', locals: { competitions: @competitions } ) %>");
|
@ -0,0 +1,4 @@
|
|||||||
|
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
|
||||||
|
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
|
||||||
|
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
|
||||||
|
show_success_flash();
|
@ -0,0 +1,4 @@
|
|||||||
|
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
|
||||||
|
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
|
||||||
|
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
|
||||||
|
show_success_flash();
|
@ -0,0 +1,28 @@
|
|||||||
|
<div class="modal fade admin-create-competition-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">新增竞赛</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="admin-create-competition-form" data-url="<%= admins_competitions_path %>">
|
||||||
|
<div class="form-group d-flex">
|
||||||
|
<label for="new_mirror_id" class="col-form-label">竞赛名称:</label>
|
||||||
|
<div class="w-75 d-flex flex-column">
|
||||||
|
<%= text_field_tag(:competition_name, nil, class: 'form-control', placeholder: '请输入竞赛名称') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="error text-danger"></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||||
|
<button type="button" class="btn btn-primary submit-btn">确认</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,4 @@
|
|||||||
|
var page_no = $("#competition-item-<%= @competition.id %>").children(":first").html();
|
||||||
|
$("#competition-item-<%= @competition.id %>").html("<%= j render partial: "admins/competitions/shared/td", locals: {competition: @competition, page_no: 1} %>");
|
||||||
|
$("#competition-item-<%= @competition.id %>").children(":first").html(page_no);
|
||||||
|
show_success_flash();
|
@ -0,0 +1,42 @@
|
|||||||
|
<table class="table text-center shixun-settings-list-table">
|
||||||
|
<thead class="thead-light">
|
||||||
|
<tr>
|
||||||
|
<th width="4%" class="text-left">序号</th>
|
||||||
|
<th width="6%"><%= sort_tag('战队ID', name: 'competition_team_id', path: admins_competition_enroll_lists_path(@competition)) %></th>
|
||||||
|
<th width="12%">战队名称</th>
|
||||||
|
<th width="10%">创建者</th>
|
||||||
|
<th width="10%">队员姓名</th>
|
||||||
|
<th width="6%">职业</th>
|
||||||
|
<th width="12%">学号</th>
|
||||||
|
<th width="10%">队员学校</th>
|
||||||
|
<th width="6%">地区</th>
|
||||||
|
<th width="16%">指导老师</th>
|
||||||
|
<th width="8%"><%= sort_tag('报名时间', name: 'created_at', path: admins_competition_enroll_lists_path(@competition)) %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% if enroll_lists.present? %>
|
||||||
|
<% enroll_lists.each_with_index do |member, index| %>
|
||||||
|
<tr id="competition-team-member-<%= member.id %>">
|
||||||
|
<% team = member.competition_team %>
|
||||||
|
<% page_no = list_index_no(@params_page.to_i, index) %>
|
||||||
|
<td><%= page_no %></td>
|
||||||
|
<td><%= member.competition_team_id %></td>
|
||||||
|
<td><%= @personal ? "--" : team.name %></td>
|
||||||
|
<td><%= team.user.real_name %></td>
|
||||||
|
<td><%= member.user.real_name %></td>
|
||||||
|
<td><%= member.user.identity %></td>
|
||||||
|
<td><%= member.user.student_id %></td>
|
||||||
|
<td><%= member.user.school_name %></td>
|
||||||
|
<td><%= member.user.school_province %></td>
|
||||||
|
<td><%= @personal ? "--" : team.teachers_info %></td>
|
||||||
|
<td><%= member.created_at.strftime('%Y-%m-%d %H:%M') %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= render 'admins/shared/no_data_for_table' %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= render partial: 'admins/shared/paginate', locals: { objects: enroll_lists } %>
|
@ -0,0 +1,33 @@
|
|||||||
|
<%
|
||||||
|
define_admin_breadcrumbs do
|
||||||
|
add_admin_breadcrumb('竞赛列表', admins_competitions_path)
|
||||||
|
add_admin_breadcrumb(@competition.name)
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
|
||||||
|
<div class="box search-form-container flex-column mb-0 pb-0 competition-enroll-list-form">
|
||||||
|
<ul class="nav nav-tabs w-100 search-form-tabs">
|
||||||
|
<li class="nav-item">
|
||||||
|
<%= link_to '报名列表', admins_competition_enroll_lists_path(@competition), class: "nav-link search-form-tab active" %>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<%= link_to '获奖证书审批', admins_competition_enroll_lists_path(@competition), class: "nav-link search-form-tab" %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="d-flex">
|
||||||
|
<%= form_tag(admins_competition_enroll_lists_path(unsafe_params), method: :get, class: 'form-inline search-form mt-3 flex-1 d-flex', remote: true) do %>
|
||||||
|
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '战队名称检索') %>
|
||||||
|
<%= text_field_tag(:school, params[:school], class: 'form-control col-sm-2 ml-3', placeholder: '队员学校名称检索') %>
|
||||||
|
<%= text_field_tag(:location, params[:location], class: 'form-control col-sm-2 ml-3', placeholder: '队员地区检索') %>
|
||||||
|
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||||
|
<%= link_to "清除", admins_competition_enroll_lists_path(@competition), class: "btn btn-default",'data-disable-with': '清除中...' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<a href="javascript:void(0)" class="btn btn-primary mt-3" id="enroll-lists-export" data-competition-id="<%= @competition.id %>" data-disable-with = '导出中...'>导出</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box competition-enroll-list-container">
|
||||||
|
<%= render(partial: 'admins/enroll_lists/list', locals: { enroll_lists: @enroll_lists }) %>
|
||||||
|
</div>
|
@ -0,0 +1 @@
|
|||||||
|
$('.competition-enroll-list-container').html("<%= j( render(partial: 'admins/enroll_lists/list', locals: { enroll_lists: @enroll_lists }) ) %>");
|
@ -0,0 +1,18 @@
|
|||||||
|
wb = xlsx_package.workbook
|
||||||
|
wb.add_worksheet(name: '用户实训情况') do |sheet|
|
||||||
|
sheet.add_row %w(姓名 单位部门 学习关卡数 完成关卡数 学习实训数 完成实训数 评测次数 实战时间)
|
||||||
|
|
||||||
|
@users.each do |user|
|
||||||
|
data = [
|
||||||
|
user.real_name,
|
||||||
|
[user.school_name.presence, user.department_name.presence].compact.join(' - '),
|
||||||
|
user.display_extra_data(:study_challenge_count),
|
||||||
|
user.display_extra_data(:finish_challenge_count),
|
||||||
|
user.display_extra_data(:study_shixun_count),
|
||||||
|
user.display_extra_data(:finish_shixun_count),
|
||||||
|
user.display_extra_data(:evaluate_count),
|
||||||
|
Util.display_cost_time(user.display_extra_data(:cost_time)),
|
||||||
|
]
|
||||||
|
sheet.add_row(data)
|
||||||
|
end
|
||||||
|
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue