Merge branch 'dev_item_bank' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_jupyter
commit
0a33fc8cfe
@ -0,0 +1,31 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-repertoire-modal', function(){
|
||||||
|
var $modal = $('.modal.admin-edit-repertoire-modal');
|
||||||
|
var $form = $modal.find('form.admin-edit-repertoire-form');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
'repertoire[name]': {
|
||||||
|
required: true,
|
||||||
|
maxlength: 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$modal.on('click', '.submit-btn', function(){
|
||||||
|
$form.find('.error').html('');
|
||||||
|
var url = $form.attr('action');
|
||||||
|
|
||||||
|
if ($form.valid()) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'script',
|
||||||
|
url: url,
|
||||||
|
data: $form.serialize()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,31 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-sub-repertoire-modal', function(){
|
||||||
|
var $modal = $('.modal.admin-edit-sub-repertoire-modal');
|
||||||
|
var $form = $modal.find('form.admin-edit-sub-repertoire-form');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
'sub_repertoire[name]': {
|
||||||
|
required: true,
|
||||||
|
maxlength: 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$modal.on('click', '.submit-btn', function(){
|
||||||
|
$form.find('.error').html('');
|
||||||
|
var url = $form.attr('action');
|
||||||
|
|
||||||
|
if ($form.valid()) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'script',
|
||||||
|
url: url,
|
||||||
|
data: $form.serialize()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,31 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-tag-repertoire-modal', function(){
|
||||||
|
var $modal = $('.modal.admin-edit-tag-repertoire-modal');
|
||||||
|
var $form = $modal.find('form.admin-edit-tag-repertoire-form');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
'tag_repertoire[name]': {
|
||||||
|
required: true,
|
||||||
|
maxlength: 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$modal.on('click', '.submit-btn', function(){
|
||||||
|
$form.find('.error').html('');
|
||||||
|
var url = $form.attr('action');
|
||||||
|
|
||||||
|
if ($form.valid()) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'PATCH',
|
||||||
|
dataType: 'script',
|
||||||
|
url: url,
|
||||||
|
data: $form.serialize()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,65 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-repertoires-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============== 新建 ===============
|
||||||
|
var $modal = $('.modal.admin-create-repertoire-modal');
|
||||||
|
var $form = $modal.find('form.admin-create-repertoire-form');
|
||||||
|
var $nameInput = $form.find('input[name="name"]');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
name: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// modal ready fire
|
||||||
|
$modal.on('show.bs.modal', function () {
|
||||||
|
$nameInput.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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".repertoire-list-container").on("change", '.repertoire-source-form', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var s_value = $(this).val();
|
||||||
|
var s_name = $(this).attr("name");
|
||||||
|
var json = {};
|
||||||
|
json[s_name] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/repertoires/" + s_id,
|
||||||
|
type: "PUT",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,74 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-salesmans-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============= 添加销售人员 ==============
|
||||||
|
var $addMemberModal = $('.admin-add-salesman-customer-user-modal');
|
||||||
|
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-customer-user-form');
|
||||||
|
var $memberSelect = $addMemberModal.find('.salesman-user-select');
|
||||||
|
// var $salesmanIdInput = $addMemberForm.find('input[name="salesman_id"]')
|
||||||
|
|
||||||
|
$addMemberModal.on('show.bs.modal', function(event){
|
||||||
|
var $link = $(event.relatedTarget);
|
||||||
|
var salesmanId = $link.data('salesman-id');
|
||||||
|
$salesmanIdInput.val(salesmanId);
|
||||||
|
|
||||||
|
$memberSelect.select2('val', ' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
$memberSelect.select2({
|
||||||
|
theme: 'bootstrap4',
|
||||||
|
placeholder: '请输入要添加的销售姓名',
|
||||||
|
multiple: true,
|
||||||
|
minimumInputLength: 1,
|
||||||
|
ajax: {
|
||||||
|
delay: 500,
|
||||||
|
url: '/admins/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 $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
|
||||||
|
},
|
||||||
|
templateSelection: function(item){
|
||||||
|
if (item.id) {
|
||||||
|
}
|
||||||
|
return item.real_name || item.text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$addMemberModal.on('click', '.submit-btn', function(){
|
||||||
|
$addMemberForm.find('.error').html('');
|
||||||
|
|
||||||
|
// var salesmanId = $salesmanIdInput.val();
|
||||||
|
var memberIds = $memberSelect.val();
|
||||||
|
if (memberIds && memberIds.length > 0) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/admins/salesman_customers/batch_add',
|
||||||
|
data: { user_ids: memberIds },
|
||||||
|
success: function(){
|
||||||
|
$.notify({ message: '创建成功' });
|
||||||
|
$addMemberModal.modal('hide');
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.reload();
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$form.find('.error').html(data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$addMemberModal.modal('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,99 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-salesmans-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============= 添加销售人员 ==============
|
||||||
|
var $addMemberModal = $('.admin-add-salesman-user-modal');
|
||||||
|
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-user-form');
|
||||||
|
var $memberSelect = $addMemberModal.find('.salesman-user-select');
|
||||||
|
// var $salesmanIdInput = $addMemberForm.find('input[name="salesman_id"]')
|
||||||
|
|
||||||
|
$addMemberModal.on('show.bs.modal', function(event){
|
||||||
|
var $link = $(event.relatedTarget);
|
||||||
|
// var salesmanId = $link.data('salesman-id');
|
||||||
|
// $salesmanIdInput.val(salesmanId);
|
||||||
|
|
||||||
|
$memberSelect.select2('val', ' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
$memberSelect.select2({
|
||||||
|
theme: 'bootstrap4',
|
||||||
|
placeholder: '请输入要添加的销售姓名',
|
||||||
|
multiple: true,
|
||||||
|
minimumInputLength: 1,
|
||||||
|
ajax: {
|
||||||
|
delay: 500,
|
||||||
|
url: '/admins/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 $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
|
||||||
|
},
|
||||||
|
templateSelection: function(item){
|
||||||
|
if (item.id) {
|
||||||
|
}
|
||||||
|
return item.real_name || item.text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$addMemberModal.on('click', '.submit-btn', function(){
|
||||||
|
$addMemberForm.find('.error').html('');
|
||||||
|
|
||||||
|
// var salesmanId = $salesmanIdInput.val();
|
||||||
|
var memberIds = $memberSelect.val();
|
||||||
|
if (memberIds && memberIds.length > 0) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: '/admins/salesmans/batch_add',
|
||||||
|
data: { user_ids: memberIds },
|
||||||
|
success: function(){
|
||||||
|
$.notify({ message: '创建成功' });
|
||||||
|
$addMemberModal.modal('hide');
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.reload();
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
error: function(res){
|
||||||
|
var data = res.responseJSON;
|
||||||
|
$form.find('.error').html(data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$addMemberModal.modal('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".salesman-list-container").on("change", '.salesman-sync-course', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var json = {};
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/salesmans/" + s_id + "/update_sync_course",
|
||||||
|
type: "POST",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".salesman-list-container").on("change", '.salesman-sync-form', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var s_value = $(this).val();
|
||||||
|
var s_name = $(this).attr("name");
|
||||||
|
var json = {};
|
||||||
|
json[s_name] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/salesmans/" + s_id,
|
||||||
|
type: "PUT",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,65 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-sub-repertoires-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============== 新建 ===============
|
||||||
|
var $modal = $('.modal.admin-create-sub-repertoire-modal');
|
||||||
|
var $form = $modal.find('form.admin-create-sub-repertoire-form');
|
||||||
|
var $nameInput = $form.find('input[name="name"]');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
name: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// modal ready fire
|
||||||
|
$modal.on('show.bs.modal', function () {
|
||||||
|
$nameInput.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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".sub-repertoire-list-container").on("change", '.sub-repertoire-source-form', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var s_value = $(this).val();
|
||||||
|
var s_name = $(this).attr("name");
|
||||||
|
var json = {};
|
||||||
|
json[s_name] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/sub_repertoires/" + s_id,
|
||||||
|
type: "PUT",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,71 @@
|
|||||||
|
$(document).on('turbolinks:load', function () {
|
||||||
|
if ($('body.admins-subject-settings-index-page').length > 0) {
|
||||||
|
var $form = $('.subject-setting-list-form');
|
||||||
|
|
||||||
|
// ************** 学校选择 *************
|
||||||
|
$form.find('.school-select').select2({
|
||||||
|
theme: 'bootstrap4',
|
||||||
|
placeholder: '请选择创建者单位',
|
||||||
|
minimumInputLength: 1,
|
||||||
|
ajax: {
|
||||||
|
delay: 500,
|
||||||
|
url: '/api/schools/search.json',
|
||||||
|
dataType: 'json',
|
||||||
|
data: function (params) {
|
||||||
|
return {keyword: params.term};
|
||||||
|
},
|
||||||
|
processResults: function (data) {
|
||||||
|
return {results: data.schools}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
templateResult: function (item) {
|
||||||
|
if (!item.id || item.id === '') return item.text;
|
||||||
|
return item.name;
|
||||||
|
},
|
||||||
|
templateSelection: function (item) {
|
||||||
|
if (item.id) {
|
||||||
|
}
|
||||||
|
return item.name || item.text;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".subject-setting-list-container").on("change", '.subject-setting-form', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var s_value = $(this).val();
|
||||||
|
var s_name = $(this).attr("name");
|
||||||
|
var json = {};
|
||||||
|
json[s_name] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/subject_settings/" + s_id,
|
||||||
|
type: "PUT",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// 清空
|
||||||
|
$form.on('click', '.clear-btn', function () {
|
||||||
|
$form.find('select[name="status"]').val('');
|
||||||
|
$form.find('.school-select').val('').trigger('change');
|
||||||
|
$form.find('input[name="keyword"]').val('');
|
||||||
|
$form.find('#homepage_show').attr('checked', false);
|
||||||
|
$form.find('#excellent').attr('checked', false);
|
||||||
|
$form.find('input[type="submit"]').trigger('click');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 上传图片
|
||||||
|
$('.modal.admin-upload-file-modal').on('upload:success', function (e, data) {
|
||||||
|
if(data.suffix == '_qrcode'){
|
||||||
|
var $imageElement = $('.subject-weapp-image-' + data.source_id);
|
||||||
|
$imageElement.attr('src', data.url);
|
||||||
|
$imageElement.show();
|
||||||
|
$imageElement.next().html('重新上传');
|
||||||
|
} else {
|
||||||
|
var $imageElement = $('.subject-image-' + data.source_id);
|
||||||
|
$imageElement.attr('src', data.url);
|
||||||
|
$imageElement.show();
|
||||||
|
$imageElement.next().html('重新上传');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,65 @@
|
|||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
if ($('body.admins-tag-repertoires-index-page').length > 0) {
|
||||||
|
|
||||||
|
// ============== 新建 ===============
|
||||||
|
var $modal = $('.modal.admin-create-tag-repertoire-modal');
|
||||||
|
var $form = $modal.find('form.admin-create-tag-repertoire-form');
|
||||||
|
var $nameInput = $form.find('input[name="name"]');
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorElement: 'span',
|
||||||
|
errorClass: 'danger text-danger',
|
||||||
|
rules: {
|
||||||
|
name: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// modal ready fire
|
||||||
|
$modal.on('show.bs.modal', function () {
|
||||||
|
$nameInput.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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".tag-repertoire-list-container").on("change", '.tag-repertoire-source-form', function () {
|
||||||
|
var s_id = $(this).attr("data-id");
|
||||||
|
var s_value = $(this).val();
|
||||||
|
var s_name = $(this).attr("name");
|
||||||
|
var json = {};
|
||||||
|
json[s_name] = s_value;
|
||||||
|
$.ajax({
|
||||||
|
url: "/admins/tag_repertoires/" + s_id,
|
||||||
|
type: "PUT",
|
||||||
|
dataType:'script',
|
||||||
|
data: json
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,36 @@
|
|||||||
|
class Admins::RepertoiresController < Admins::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@repertoires = Repertoire.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@repertoire = current_repertoire
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
Rails.logger.info("#################--------")
|
||||||
|
if params[:repertoire] && params[:repertoire][:name].present?
|
||||||
|
name = params[:repertoire][:name].to_s.strip
|
||||||
|
current_repertoire.update_attributes!(name: name)
|
||||||
|
end
|
||||||
|
@repertoires = Repertoire.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
name = params[:name].to_s.strip
|
||||||
|
return render_error('名称重复') if Repertoire.where(name: name).exists?
|
||||||
|
Repertoire.create!(name: name)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@repertoire_id = params[:id]
|
||||||
|
current_repertoire.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def current_repertoire
|
||||||
|
@_current_repertoire = Repertoire.find params[:id]
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class Admins::SalesmanCustomersController < Admins::BaseController
|
||||||
|
before_action :set_salesman
|
||||||
|
|
||||||
|
def index
|
||||||
|
@customers = @salesman.salesman_customers.includes(:user, :school)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_salesman
|
||||||
|
@salesman = Salesman.find params[:salesman_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,29 @@
|
|||||||
|
class Admins::SalesmansController < Admins::BaseController
|
||||||
|
before_action :set_salesman, except: [:index, :batch_add]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@salesmans = Salesman.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@salesman.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
# 批量增加销售人员
|
||||||
|
def batch_add
|
||||||
|
salesman_user_ids = Salesman.where(id: params[:user_ids]).pluck(:user_id)
|
||||||
|
user_ids = params[:user_ids] - salesman_user_ids
|
||||||
|
user_ids.each do |user_id|
|
||||||
|
user = User.find_by(id: user_id)
|
||||||
|
next if user.blank?
|
||||||
|
Salesman.create!(user_id: user.id, name: user.real_name)
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_salesman
|
||||||
|
@salesman = Salesman.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,45 @@
|
|||||||
|
class Admins::SubRepertoiresController < Admins::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@repertoire = current_repertoire
|
||||||
|
@sub_repertoires = current_repertoire.sub_repertoires
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
name = params[:name].to_s.strip
|
||||||
|
return render_error('名称重复') if current_repertoire.sub_repertoires.where(name: name).exists?
|
||||||
|
SubRepertoire.create!(name: name, repertoire_id: current_repertoire.id)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@sub_repertoire = current_sub_repertoire
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if params[:sub_repertoire] && params[:sub_repertoire][:name].present?
|
||||||
|
name = params[:sub_repertoire][:name].to_s.strip
|
||||||
|
current_sub_repertoire.update_attributes!(name: name)
|
||||||
|
end
|
||||||
|
@sub_repertoires = current_sub_repertoire.repertoire&.sub_repertoires
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@sub_repertoire_id = params[:id]
|
||||||
|
current_sub_repertoire.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_sub_repertoire
|
||||||
|
@_current_sub_repertoire = SubRepertoire.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_repertoire
|
||||||
|
@_current_repertoire = Repertoire.find params[:repertoire_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def setting_params
|
||||||
|
params.permit(:shixun, :subject, :question)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,29 @@
|
|||||||
|
class Admins::SubjectSettingsController < Admins::BaseController
|
||||||
|
def index
|
||||||
|
default_sort('created_at', 'desc')
|
||||||
|
|
||||||
|
subjects = Admins::SubjectQuery.call(params)
|
||||||
|
@sub_disciplines = SubDiscipline.where(subject: 1).pluck(:name,:id)
|
||||||
|
@subjects = paginate subjects.includes(:repertoire, :subject_level_system, :sub_disciplines)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
sub_discipline_ids = params[:sub_disciplines] || []
|
||||||
|
sub_ids = sub_discipline_ids.reject(&:blank?).map(&:to_i)
|
||||||
|
old_sub_ids = current_subject.sub_discipline_containers.pluck(:sub_discipline_id)
|
||||||
|
new_ids = sub_ids - old_sub_ids
|
||||||
|
delete_ids = old_sub_ids - sub_ids
|
||||||
|
sub_params = new_ids.map{|sub| {sub_discipline_id: sub}}
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
current_subject.sub_discipline_containers.where(sub_discipline_id: delete_ids).destroy_all
|
||||||
|
current_subject.sub_discipline_containers.create!(sub_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_subject
|
||||||
|
@_current_subject ||= Subject.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,43 @@
|
|||||||
|
class Admins::TagRepertoiresController < Admins::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@sub_repertoire = current_sub_repertoire
|
||||||
|
@tag_repertoires = current_sub_repertoire.tag_repertoires
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
name = params[:name].to_s.strip
|
||||||
|
return render_error('名称重复') if current_sub_repertoire.tag_repertoires.where(name: name).exists?
|
||||||
|
TagRepertoire.create!(name: name, sub_repertoire_id: current_sub_repertoire.id)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@tag_repertoire = current_tag_repertoire
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if params[:tag_repertoire] && params[:tag_repertoire][:name].present?
|
||||||
|
name = params[:tag_repertoire][:name].to_s.strip
|
||||||
|
current_tag_repertoire.update_attributes!(name: name)
|
||||||
|
end
|
||||||
|
@tag_repertoires = current_tag_repertoire.sub_repertoire&.tag_repertoires
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@tag_repertoire_id = params[:id]
|
||||||
|
current_tag_repertoire.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_sub_repertoire
|
||||||
|
@_current_sub_repertoire = SubRepertoire.find params[:sub_repertoire_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_tag_repertoire
|
||||||
|
@_current_tag_repertoire = TagRepertoire.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,69 @@
|
|||||||
|
class LiveLinksController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
before_action :find_course, only: [:index, :create]
|
||||||
|
before_action :user_course_identity, :teacher_allowed, only: [:create]
|
||||||
|
before_action :edit_auth, only: [:edit, :update]
|
||||||
|
before_action :delete_auth, only: [:destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
lives = @course.live_links
|
||||||
|
order_str = "on_status desc, live_time desc"
|
||||||
|
@total_count = lives.size
|
||||||
|
@my_live_id = @course.live_links.find_by(user_id: current_user.id)&.id
|
||||||
|
# order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present?
|
||||||
|
lives = lives.order("#{order_str}")
|
||||||
|
@lives = paginate lives.includes(user: :user_extension)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
|
||||||
|
@course.live_links.create!(create_params.merge(user_id: current_user.id, on_status: on_status))
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@live = current_live
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if params[:on_status]
|
||||||
|
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
current_live.update!(on_status: params[:on_status])
|
||||||
|
|
||||||
|
# 开启时发送消息,关闭直播时删除对应的消息
|
||||||
|
if params[:on_status].to_i == 1
|
||||||
|
LivePublishJob.perform_later(current_live.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
|
||||||
|
current_live.update!(create_params.merge(on_status: on_status))
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
current_live.destroy!
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_params
|
||||||
|
params.permit(:url, :description, :course_name, :platform, :live_time, :duration)
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_live
|
||||||
|
@_current_live = LiveLink.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit_auth
|
||||||
|
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin_or_business?
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_auth
|
||||||
|
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,26 @@
|
|||||||
|
class Weapps::ChallengesController < Weapps::BaseController
|
||||||
|
before_action :require_login
|
||||||
|
before_action :set_challenge
|
||||||
|
|
||||||
|
def is_play
|
||||||
|
# 关卡有展示效果 || 选择题 || jupyter实训 || vnc || 隐藏代码窗口 || html+css实训
|
||||||
|
# @challenge.show_type != -1 || @challenge.st == 1 || @shixun.is_jupyter? || @shixun.vnc ||
|
||||||
|
# @shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
|
||||||
|
play = @challenge.st == 1 || @shixun.is_jupyter? || @shixun.vnc ||
|
||||||
|
@shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
|
||||||
|
|
||||||
|
if play
|
||||||
|
normal_status(-5, "该关卡暂不支持小程序")
|
||||||
|
else
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_challenge
|
||||||
|
@challenge = Challenge.find_by!(id: params[:id])
|
||||||
|
@shixun = @challenge.shixun
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,15 @@
|
|||||||
|
class Weapps::ShixunListsController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
|
||||||
|
def index
|
||||||
|
results = Weapps::ShixunSearchService.call(search_params, current_laboratory)
|
||||||
|
@total_count = results.size
|
||||||
|
@results = paginate results
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:keyword, :type, :page, :limit, :order, :status, :diff, :sort, :no_jupyter)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,28 @@
|
|||||||
|
class Weapps::SubjectsController < Weapps::BaseController
|
||||||
|
before_action :require_login
|
||||||
|
before_action :find_subject, except: [:index]
|
||||||
|
|
||||||
|
# 首页
|
||||||
|
def index
|
||||||
|
subjects = Weapps::SubjectQuery.call(current_laboratory, params)
|
||||||
|
@subject_count = subjects.map(&:id).size
|
||||||
|
@subjects = paginate subjects
|
||||||
|
end
|
||||||
|
|
||||||
|
# 详情
|
||||||
|
def show
|
||||||
|
# 合作团队
|
||||||
|
Rails.logger.info("##########subject: #{@subject.id}")
|
||||||
|
@members = @subject.subject_members.includes(:user)
|
||||||
|
shixuns = @subject.shixuns.published.pluck(:id)
|
||||||
|
challenge_ids = Challenge.where(shixun_id: shixuns).pluck(:id)
|
||||||
|
# 实训路径中的所有实训标签
|
||||||
|
@tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_subject
|
||||||
|
@subject = Subject.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,16 @@
|
|||||||
|
class Weapps::UnbindAccountsController < Weapps::BaseController
|
||||||
|
before_action :require_login
|
||||||
|
|
||||||
|
def show
|
||||||
|
@user = current_user
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
open_user = OpenUsers::Wechat.find_by!(user_id: current_user.id)
|
||||||
|
session[:unionid] = open_user.uid
|
||||||
|
open_user.destroy!
|
||||||
|
UserAction.create(action_id: current_user.id, action_type: "UnbindWechat", user_id: current_user.id, :ip => request.remote_ip)
|
||||||
|
logout_user
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,27 @@
|
|||||||
|
# 直播开启的消息通知
|
||||||
|
class LivePublishJob < ApplicationJob
|
||||||
|
queue_as :notify
|
||||||
|
|
||||||
|
def perform(live_id)
|
||||||
|
live = LiveLink.find_by(id: live_id)
|
||||||
|
return if live.blank? || live.course.blank?
|
||||||
|
course = live.course
|
||||||
|
|
||||||
|
attrs = %i[
|
||||||
|
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
|
||||||
|
belong_container_id belong_container_type viewed tiding_type created_at updated_at
|
||||||
|
]
|
||||||
|
|
||||||
|
same_attrs = {
|
||||||
|
trigger_user_id: live.user_id, container_id: live.id, container_type: 'LiveLink',
|
||||||
|
parent_container_id: live.id, parent_container_type: 'LiveLink',
|
||||||
|
belong_container_id: live.course_id, belong_container_type: 'Course',
|
||||||
|
viewed: 0, tiding_type: 'LiveLink'
|
||||||
|
}
|
||||||
|
Tiding.bulk_insert(*attrs) do |worker|
|
||||||
|
course.students.pluck(:user_id).each do |user_id|
|
||||||
|
worker.add same_attrs.merge(user_id: user_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,4 @@
|
|||||||
|
class CourseVideo < ApplicationRecord
|
||||||
|
belongs_to :course
|
||||||
|
belongs_to :video
|
||||||
|
end
|
@ -1,3 +1,4 @@
|
|||||||
class ItemAnalysis < ApplicationRecord
|
class ItemAnalysis < ApplicationRecord
|
||||||
belongs_to :item_bank, touch: true
|
belongs_to :item_bank, touch: true
|
||||||
|
validates :analysis, length: { maximum: 5000, too_long: "不能超过5000个字符" }
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
class ItemChoice < ApplicationRecord
|
class ItemChoice < ApplicationRecord
|
||||||
belongs_to :item_bank, touch: true
|
belongs_to :item_bank, touch: true
|
||||||
|
validates :choice_text, presence: true, length: { maximum: 500, too_long: "不能超过500个字符" }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
class LiveLink < ApplicationRecord
|
||||||
|
belongs_to :course
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
has_many :tidings, as: :container, dependent: :destroy
|
||||||
|
|
||||||
|
# validates :url, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }
|
||||||
|
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }
|
||||||
|
validates :course_name, presence: true
|
||||||
|
validates :platform, presence: true
|
||||||
|
# validates :live_time, presence: true
|
||||||
|
validates :duration, numericality: { only_integer: true, greater_than: 0}, allow_blank: true
|
||||||
|
|
||||||
|
def op_auth?
|
||||||
|
user == User.current || User.current.admin_or_business?
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_auth?
|
||||||
|
user == User.current || User.current.admin?
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
class Salesman < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
# 渠道
|
||||||
|
has_many :salesman_channels, dependent: :destroy
|
||||||
|
# 客户
|
||||||
|
has_many :salesman_customers, dependent: :destroy
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class SalesmanChannel < ApplicationRecord
|
||||||
|
belongs_to :salesman, :touch => true, counter_cache: true
|
||||||
|
end
|
@ -0,0 +1,22 @@
|
|||||||
|
class SalesmanCustomer < ApplicationRecord
|
||||||
|
belongs_to :salesman, :touch => true, counter_cache: true
|
||||||
|
belongs_to :school
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
def name
|
||||||
|
user.real_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def school_name
|
||||||
|
school.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def courses_count
|
||||||
|
CourseMember.where(user_id: id).teachers_and_admin.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def shixuns_count
|
||||||
|
ShixunMember.where(user_id: id, role: [1, 2]).count
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,9 +1,13 @@
|
|||||||
class SubDiscipline < ApplicationRecord
|
class SubDiscipline < ApplicationRecord
|
||||||
belongs_to :discipline
|
belongs_to :discipline
|
||||||
has_many :tag_disciplines, dependent: :destroy
|
has_many :tag_disciplines, dependent: :destroy
|
||||||
|
has_many :sub_discipline_containers, dependent: :destroy
|
||||||
has_one :hack
|
has_one :hack
|
||||||
|
|
||||||
has_many :shixun_tag_disciplines, -> { where("shixun = 1") }, class_name: "TagDiscipline"
|
has_many :shixun_tag_disciplines, -> { where("shixun = 1") }, class_name: "TagDiscipline"
|
||||||
has_many :subject_tag_disciplines, -> { where("subject = 1") }, class_name: "TagDiscipline"
|
has_many :subject_tag_disciplines, -> { where("subject = 1") }, class_name: "TagDiscipline"
|
||||||
has_many :question_tag_disciplines, -> { where("question = 1") }, class_name: "TagDiscipline"
|
has_many :question_tag_disciplines, -> { where("question = 1") }, class_name: "TagDiscipline"
|
||||||
|
|
||||||
|
validates_presence_of :name
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class SubDisciplineContainer < ApplicationRecord
|
||||||
|
belongs_to :sub_discipline
|
||||||
|
|
||||||
|
belongs_to :container, polymorphic: true, optional: true, touch: true
|
||||||
|
end
|
@ -0,0 +1,37 @@
|
|||||||
|
class Weapps::SubjectQuery < ApplicationQuery
|
||||||
|
include CustomSortable
|
||||||
|
attr_reader :params
|
||||||
|
|
||||||
|
def initialize(current_laboratory, params)
|
||||||
|
@current_laboratory = current_laboratory
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
subjects = @current_laboratory.subjects.unhidden.visible
|
||||||
|
|
||||||
|
# 课程体系的过滤
|
||||||
|
if params[:sub_discipline_id].present?
|
||||||
|
subjects = subjects.joins(:sub_disciplines).where(sub_disciplines: {id: params[:sub_discipline_id]})
|
||||||
|
elsif params[:discipline_id].present?
|
||||||
|
subjects = subjects.joins(:sub_disciplines).where(sub_disciplines: {discipline_id: params[:discipline_id]})
|
||||||
|
else
|
||||||
|
subjects = subjects.joins(:sub_discipline_containers).where(sub_discipline_containers: {container_type: "Subject"})
|
||||||
|
end
|
||||||
|
|
||||||
|
subjects = subjects.left_joins(:shixuns).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show,
|
||||||
|
subjects.shixuns_count, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count')
|
||||||
|
.group('subjects.id').order("subjects.homepage_show #{sort_type}, #{order_type} #{sort_type}")
|
||||||
|
subjects
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def order_type
|
||||||
|
params[:order] || "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_type
|
||||||
|
params[:sort] || "desc"
|
||||||
|
end
|
||||||
|
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue