commit
c8b6786063
@ -0,0 +1,5 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-abouts-edit-page, body.admins-abouts-update-page').length > 0) {
|
||||
createMDEditor('about-us-editor', {});
|
||||
}
|
||||
})
|
@ -0,0 +1,5 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-agreements-edit-page, body.admins-agreements-update-page').length > 0) {
|
||||
createMDEditor('agreement-editor', {});
|
||||
}
|
||||
})
|
@ -0,0 +1,6 @@
|
||||
|
||||
function show_add_manager(id) {
|
||||
$(".auth-schools-user-add").modal("show");
|
||||
|
||||
$(".auth-schools-user-add").find("#school_id_input").val(id)
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
$(document).on('turbolinks:load', function(){
|
||||
$(document).on('click', '.batch-all-check-box', function(){
|
||||
var $checkAll = $(this);
|
||||
|
||||
$('.batch-check-box').prop('checked', $checkAll.is(':checked'));
|
||||
})
|
||||
|
||||
$(document).on('click', '.batch-check-box', function(){
|
||||
var allChecked = $('.batch-check-box:checked').length === $('.batch-check-box').length
|
||||
$('.batch-all-check-box').prop('checked', allChecked);
|
||||
})
|
||||
});
|
@ -0,0 +1,96 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-cooperatives-index-page').length > 0) {
|
||||
// ------------ 保存链接 -----------
|
||||
$('.coo-img-card').on('click', '.save-url-btn', function(){
|
||||
var $link = $(this);
|
||||
var cooId = $link.data('id');
|
||||
var url = $('.coo-img-item-' + cooId).find('.url-input').val();
|
||||
$link.attr('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: '/admins/cooperatives/' + cooId,
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
data: { url: url },
|
||||
success: function(data){
|
||||
$.notify({ message: '保存成功' });
|
||||
},
|
||||
error: ajaxErrorNotifyHandler,
|
||||
complete: function(){
|
||||
$link.removeAttr('disabled');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// ------------ 拖拽 -------------
|
||||
var onDropFunc = function(el, _target, _source, sibling){
|
||||
var moveId = $(el).data('id');
|
||||
var insertId = $(sibling).data('id') || '';
|
||||
|
||||
$.ajax({
|
||||
url: '/admins/cooperatives/drag',
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
data: { move_id: moveId, after_id: insertId },
|
||||
success: function(data){
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$.notify({message: '移动失败,原因:' + data.message}, {type: 'danger'});
|
||||
}
|
||||
})
|
||||
};
|
||||
var ele1 = document.getElementById('coo-img-container-alliance_coop');
|
||||
dragula([ele1], { mirrorContainer: ele1 }).on('drop', onDropFunc);
|
||||
var ele2 = document.getElementById('coo-img-container-com_coop');
|
||||
dragula([ele2], { mirrorContainer: ele2 }).on('drop', onDropFunc);
|
||||
var ele3 = document.getElementById('coo-img-container-edu_coop');
|
||||
dragula([ele3], { mirrorContainer: ele3 }).on('drop', onDropFunc);
|
||||
|
||||
|
||||
// ----------- 新增 --------------
|
||||
var $createModal = $('.modal.admin-add-cooperative-modal');
|
||||
var $createForm = $createModal.find('form.admin-add-cooperative-form');
|
||||
|
||||
$createForm.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
"coo_img[image]": {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$createModal.on('show.bs.modal', function(event){
|
||||
resetFileInputFunc($createModal.find('.img-file-input'));
|
||||
$createModal.find('.file-names').html('选择文件');
|
||||
|
||||
var $link = $(event.relatedTarget);
|
||||
var imgType = $link.data('imgType');
|
||||
$createForm.find('input[name="coo_img[img_type]"]').val(imgType);
|
||||
});
|
||||
|
||||
$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 $cooImgItem = $('.coo-img-item-' + data.source_id);
|
||||
$.post('/admins/cooperatives/'+ data.source_id + '/replace_image_url');
|
||||
$cooImgItem.find('.coo-img-item-img img').attr('src', data.url);
|
||||
})
|
||||
}
|
||||
})
|
@ -0,0 +1,70 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-ec-templates-index-page').length > 0) {
|
||||
var add_modal = $(".ec-templates-new-add");
|
||||
var template_file_name = add_modal.find(".template-file-upload");
|
||||
var attachment_id_input = add_modal.find(".template_attachment_id");
|
||||
var template_container = $(".ec-templates-list-container");
|
||||
|
||||
//编辑附件
|
||||
template_container.on("click", ".edit-template-content", function () {
|
||||
var t_id = $(this).attr("data-id");
|
||||
var t_name = $(this).attr("data-name");
|
||||
var template_name = $(this).attr("data-template-name");
|
||||
var t_msg = $(this).attr("data-msg");
|
||||
var template_id = $(this).attr("data-template-id");
|
||||
add_modal.modal("show");
|
||||
add_modal.find(".template_add_title").html(t_msg);
|
||||
attachment_id_input.val(template_id);
|
||||
add_modal.find(".template_show_id").val(t_id);
|
||||
add_modal.find("input[name='name']").val(t_name);
|
||||
add_modal.find("i.delete-template-icon").attr("data-id", template_id);
|
||||
if(template_id !== "-1"){
|
||||
template_file_name.find("span.template-file-input").hide();
|
||||
template_file_name.find("span.template_file_show").show();
|
||||
template_file_name.find("span.template_file_show_title").html(template_name);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//删除附件
|
||||
add_modal.on("click",".delete-template-icon",function () {
|
||||
var attachment_id = $(this).attr("data-id");
|
||||
$.ajax({
|
||||
url: "/api/attachments/" + attachment_id,
|
||||
type: "delete",
|
||||
contentType:"application/json",
|
||||
dataType:"json",
|
||||
success: function (data) {
|
||||
template_file_name.find("span.template-file-input").show();
|
||||
template_file_name.find("span.template_file_show").hide();
|
||||
attachment_id_input.attr("value","-1")
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
//上传附件
|
||||
add_modal.on("change", "#upload_template_file",function () {
|
||||
|
||||
var template = document.getElementById('upload_template_file').files[0];
|
||||
|
||||
var file_content = new FormData();
|
||||
|
||||
file_content.append("file", template);
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/api/attachments",
|
||||
data:file_content,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function (data) {
|
||||
template_file_name.find("span.template-file-input").hide();
|
||||
template_file_name.find("span.template_file_show").show();
|
||||
template_file_name.find("span.template_file_show_title").html(template.name);
|
||||
template_file_name.find("i.delete-template-icon").attr("data-id",data.id);
|
||||
attachment_id_input.val(data.id)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
@ -0,0 +1,13 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if($(".admins-graduation-standards-index-page").length > 0){
|
||||
$(".admin-body-container").on("click", ".standard-create-modal", function () {
|
||||
var content = $(this).attr("data-content");
|
||||
var g_id = $(this).attr("data-id");
|
||||
var g_msg = $(this).attr("data-msg");
|
||||
|
||||
$("#graduation-modal-type").html(g_msg);
|
||||
$("#graduation_standard_id").val(g_id);
|
||||
$("textarea[name='content']").val(content);
|
||||
})
|
||||
}
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-help-centers-edit-page, body.admins-help-centers-update-page').length > 0) {
|
||||
createMDEditor('help-center-editor', {});
|
||||
}
|
||||
})
|
@ -0,0 +1,13 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-major-informations-index-page').length > 0) {
|
||||
var box_contain = $(".major-informations-list-container");
|
||||
box_contain.on("click",".collapse-item",function () {
|
||||
var a_fa = $(this).find("i");
|
||||
if(a_fa.hasClass("fa-caret-right")){
|
||||
a_fa.removeClass("fa-caret-right").addClass("fa-caret-down");
|
||||
}else{
|
||||
a_fa.removeClass("fa-caret-down").addClass("fa-caret-right");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -1,14 +1,22 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
var $modal = $('.modal.admin-message-modal');
|
||||
var $submitBtn = $modal.find('.submit-btn');
|
||||
if ($modal.length > 0) {
|
||||
$modal.on('hide.bs.modal', function(){
|
||||
$modal.find('.modal-body').html('');
|
||||
$submitBtn.unbind();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function showMessageModal(html) {
|
||||
function showMessageModal(html, callback) {
|
||||
var $modal = $('.modal.admin-message-modal');
|
||||
var $submitBtn = $modal.find('.submit-btn');
|
||||
$submitBtn.unbind();
|
||||
if(callback !== undefined && typeof callback === 'function'){
|
||||
$submitBtn.on('click', callback);
|
||||
}
|
||||
|
||||
$modal.find('.modal-body').html(html);
|
||||
$modal.modal('show');
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
var $modal = $('.modal.admin-import-course-member-modal');
|
||||
if ($modal.length > 0) {
|
||||
var $form = $modal.find('form.admin-import-course-member-form');
|
||||
|
||||
var resetFileInputFunc = function(file){
|
||||
file.after(file.clone().val(""));
|
||||
file.remove();
|
||||
}
|
||||
|
||||
$modal.on('show.bs.modal', function(){
|
||||
$modal.find('.file-names').html('选择文件');
|
||||
$modal.find('.upload-file-input').trigger('click');
|
||||
});
|
||||
$modal.on('hide.bs.modal', function(){
|
||||
resetFileInputFunc($modal.find('.upload-file-input'));
|
||||
});
|
||||
$modal.on('change', '.upload-file-input', function(e){
|
||||
var file = $(this)[0].files[0];
|
||||
$modal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||
})
|
||||
|
||||
var importFormValid = function(){
|
||||
if($form.find('input[name="file"]').val() == undefined || $form.find('input[name="file"]').val().length == 0){
|
||||
$form.find('.error').html('请选择文件');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var buildResultMessage = function(data){
|
||||
var messageHtml = "<div>导入结果:成功" + data.success + "条,失败"+ data.fail.length + "条</div>";
|
||||
|
||||
if(data.fail.length > 0){
|
||||
messageHtml += '<table class="table"><thead class="thead-light"><tr><th>数据</th><th>失败原因</th></tr></thead><tbody>';
|
||||
|
||||
data.fail.forEach(function(item){
|
||||
messageHtml += '<tr><td>' + item.data + '</td><td>' + item.message + '</td></tr>';
|
||||
});
|
||||
|
||||
messageHtml += '</tbody></table>'
|
||||
}
|
||||
|
||||
return messageHtml;
|
||||
}
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
|
||||
if (importFormValid()) {
|
||||
$('body').mLoading({ text: '正在导入...' });
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/admins/import_course_members',
|
||||
data: new FormData($form[0]),
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(data){
|
||||
$('body').mLoading('destroy');
|
||||
$modal.modal('hide');
|
||||
|
||||
showMessageModal(buildResultMessage(data), function(){
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
error: function(res){
|
||||
$('body').mLoading('destroy');
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-schools-index-page').length > 0) {
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,66 @@
|
||||
.admins-auth-schools-index-page{
|
||||
.list-item-title{
|
||||
padding-bottom:5px;
|
||||
padding-left: 33px;
|
||||
color: #555;
|
||||
}
|
||||
.list-item-title-1{
|
||||
width: 100px;
|
||||
display: inline-block;
|
||||
}
|
||||
.list-item-title-2{
|
||||
width: 200px;
|
||||
display: inline-block;
|
||||
}
|
||||
.collegeManage{
|
||||
float: left;
|
||||
padding: 0px 8px;
|
||||
border-radius: 6px;
|
||||
background-color: #f5f5f5;
|
||||
margin: 3px 0px 3px 10px;
|
||||
height: 34px;
|
||||
line-height: 34px;
|
||||
a{
|
||||
color: #05101a;
|
||||
}
|
||||
a:hover{
|
||||
color: #007bff;
|
||||
}
|
||||
}
|
||||
i:hover{
|
||||
color: #333;
|
||||
}
|
||||
.add-manager-i{
|
||||
float: left;
|
||||
i{
|
||||
padding: 10px 5px;
|
||||
}
|
||||
}
|
||||
.auth-schools-new-add, .auth-schools-user-add{
|
||||
.flex-column{
|
||||
input{
|
||||
height: 38px;
|
||||
}
|
||||
}
|
||||
.search-school{
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
}
|
||||
.school-search-list{
|
||||
background: #F4FAFF;
|
||||
height: 280px;
|
||||
overflow-y: scroll;
|
||||
padding: 10px 0;
|
||||
}
|
||||
.school-list-item{
|
||||
padding: 2px 10px;
|
||||
input{
|
||||
font-size: 20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
.admins-cooperatives-index-page {
|
||||
.coo-img-card {
|
||||
.coo-img-item {
|
||||
& > .drag {
|
||||
cursor: move;
|
||||
background: #fff;
|
||||
box-shadow: 1px 2px 5px 3px #f0f0f0;
|
||||
}
|
||||
|
||||
&-img {
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
& > img {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
right: 20px;
|
||||
color: red;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.save-url-btn {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
.admins-ec-templates-index-page{
|
||||
.template-file-upload{
|
||||
padding: 10px;
|
||||
background: #fafafa;
|
||||
border: 1px dashed #ccc;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
input[name='file']{
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
display: inline-block;
|
||||
left: 0;
|
||||
height: 43px;
|
||||
top: 0;
|
||||
width:100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
.admins-major-informations-index-page{
|
||||
.fr{
|
||||
float:right;
|
||||
}
|
||||
.panel-default{
|
||||
margin-bottom: 10px;
|
||||
background-color: rgb(245, 245, 245);
|
||||
.panel-heading{
|
||||
i{
|
||||
margin-right:15px;
|
||||
font-size:16px;
|
||||
color:rgb(204, 204, 204);
|
||||
}
|
||||
a{
|
||||
padding: 8px 10px;
|
||||
display: inline-block;
|
||||
width:100%;
|
||||
color:rgb(102, 102, 102);
|
||||
}
|
||||
}
|
||||
.panel-collapse{
|
||||
padding-top: 10px;
|
||||
background: #fff;
|
||||
table{
|
||||
text-align:center;
|
||||
th,td{
|
||||
padding: 8px;
|
||||
}
|
||||
td{
|
||||
color:#888;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
.admins-schools-index-page {
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the course_stages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,18 @@
|
||||
class Admins::AboutsController < Admins::BaseController
|
||||
def edit
|
||||
current_doc
|
||||
end
|
||||
|
||||
def update
|
||||
current_doc.update!(about_us: params[:about_us])
|
||||
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_about_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_doc
|
||||
@doc ||= Help.first || Help.create
|
||||
end
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
class Admins::AgreementsController < Admins::BaseController
|
||||
def edit
|
||||
current_doc
|
||||
end
|
||||
|
||||
def update
|
||||
current_doc.update!(agreement: params[:agreement])
|
||||
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_agreement_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_doc
|
||||
@doc ||= Help.first || Help.create
|
||||
end
|
||||
end
|
@ -0,0 +1,58 @@
|
||||
class Admins::AuthSchoolsController < Admins::BaseController
|
||||
|
||||
def index
|
||||
schools = School.where(ec_auth: 1).includes(:users).order("updated_at desc")
|
||||
@params_page = params[:page] || 1
|
||||
@schools = paginate schools
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
school = School.where(id: params[:id]).first
|
||||
school.destroy
|
||||
render_success_js
|
||||
end
|
||||
end
|
||||
|
||||
# 工程认证单位列表搜索学校
|
||||
def search_school
|
||||
@schools = School.where("ec_auth != 1 and name like '%#{params[:name]}%'").limit(10)
|
||||
end
|
||||
|
||||
# 添加认证学校
|
||||
def add_school
|
||||
all_schools = School.all
|
||||
all_schools.where(id: params[:school_id]).update_all(ec_auth: 1)
|
||||
schools = all_schools.where(ec_auth: 1).order("updated_at desc")
|
||||
@params_page = params[:page] || 1
|
||||
@schools = paginate schools
|
||||
end
|
||||
|
||||
# 搜索用户
|
||||
def search_manager
|
||||
school = School.find_by(id: params[:school_id])
|
||||
user_ids = school&.ec_school_users&.pluck(:user_id)
|
||||
@users = User.where.not(id: user_ids).where("concat(lastname, firstname) like ?", "%#{params[:name].strip.to_s}%").limit(10)
|
||||
end
|
||||
|
||||
# 添加认证学校管理员
|
||||
def add_manager
|
||||
ActiveRecord::Base.transaction do
|
||||
user_ids = params[:user_id]
|
||||
@school_id = params[:school_id]
|
||||
user_ids.each do |id|
|
||||
EcSchoolUser.create(user_id: id, school_id: @school_id)
|
||||
end
|
||||
@school_users = User.where(id: user_ids)
|
||||
end
|
||||
end
|
||||
|
||||
# 删除学校管理员
|
||||
def remove_manager
|
||||
ActiveRecord::Base.transaction do
|
||||
manager = EcSchoolUser.where(school_id: params[:school_id], user_id: params[:user_id]).first
|
||||
manager&.destroy
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
class Admins::ContactUsController < Admins::BaseController
|
||||
def edit
|
||||
@cooperations = Cooperation.all.group(:user_type)
|
||||
@help = Help.first
|
||||
end
|
||||
|
||||
def update
|
||||
cooperation = Cooperation.find(params[:id])
|
||||
cooperation.update!(update_cooperation_params)
|
||||
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_contact_us_path
|
||||
end
|
||||
|
||||
def update_address
|
||||
help = Help.first || Help.create
|
||||
help.update!(status: params.dig('help', 'status'))
|
||||
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_contact_us_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_cooperation_params
|
||||
params.require(:cooperation).permit(:name, :qq, :mail)
|
||||
end
|
||||
end
|
@ -0,0 +1,84 @@
|
||||
class Admins::CooperativesController < Admins::BaseController
|
||||
before_action :convert_file!, only: [:create]
|
||||
|
||||
def index
|
||||
@data = { 'alliance_coop' => [], 'com_coop' => [], 'edu_coop' => [] }
|
||||
@data = @data.merge CooImg.all.group_by(&:img_type)
|
||||
end
|
||||
|
||||
def create
|
||||
position = CooImg.where(img_type: create_params[:img_type]).count + 1
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
coo = CooImg.create!(create_params.merge(position: position))
|
||||
|
||||
file_path = Util::FileManage.disk_filename('CooImg', coo.id)
|
||||
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||
Util.write_file(@file, file_path)
|
||||
|
||||
coo.update!(url_states: Util::FileManage.disk_file_url('CooImg', coo.id))
|
||||
end
|
||||
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to admins_cooperatives_path
|
||||
end
|
||||
|
||||
def update
|
||||
current_coo.update!(src_states: params[:url])
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
current_coo.destroy!
|
||||
# 前移
|
||||
CooImg.where(img_type: current_coo.img_type).where('position > ?', current_coo.position)
|
||||
.update_all('position = position - 1')
|
||||
|
||||
file_path = Util::FileManage.disk_filename('CooImg', current_coo.id)
|
||||
File.delete(file_path) if File.exist?(file_path)
|
||||
end
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
def drag
|
||||
move = CooImg.find_by(id: params[:move_id])
|
||||
after = CooImg.find_by(id: params[:after_id])
|
||||
|
||||
Admins::DragCooperativeService.call(move, after)
|
||||
render_ok
|
||||
rescue Admins::DragCooperativeService::Error => e
|
||||
render_error(e.message)
|
||||
end
|
||||
|
||||
def replace_image_url
|
||||
current_coo.update!(url_states: Util::FileManage.disk_file_url('CooImg', current_coo.id))
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_coo
|
||||
@_current_coo ||= CooImg.find(params[:id])
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.require(:coo_img).permit(:img_type, :src_states)
|
||||
end
|
||||
|
||||
def convert_file!
|
||||
max_size = 10 * 1024 * 1024 # 10M
|
||||
file = params.dig('coo_img', '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,106 @@
|
||||
class Admins::DepartmentAppliesController < Admins::BaseController
|
||||
|
||||
before_action :get_apply,only:[:agree,:destroy]
|
||||
|
||||
def index
|
||||
params[:status] ||= 0
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_at'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
applies = Admins::DepartmentApplyQuery.call(params)
|
||||
@depart_applies = paginate applies.preload(:school,user: :user_extension)
|
||||
end
|
||||
|
||||
def agree
|
||||
ActiveRecord::Base.transaction do
|
||||
@depart_apply.update_attribute("status",1)
|
||||
@depart_apply&.applied_messages&.update_all(status:1)
|
||||
@depart_apply&.department&.update_attribute("is_auth",1)
|
||||
@depart_apply&.user&.user_extension&.update_attribute("department_id",@depart_apply.department_id)
|
||||
render_success_js
|
||||
end
|
||||
end
|
||||
|
||||
def merge
|
||||
apply_id = params[:origin_department_id]
|
||||
apply_add =ApplyAddDepartment.find(apply_id)
|
||||
origin_id = apply_add&.department_id
|
||||
new_id = params[:department_id]
|
||||
|
||||
return render_error('请选择其它部门') if origin_id.to_s == new_id.to_s
|
||||
|
||||
origin_department = apply_add&.department
|
||||
to_department = Department.find(new_id)
|
||||
|
||||
return render_error('部门所属单位不相同') if origin_department&.school_id != to_department&.school_id
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
applied_message = AppliedMessage.where(applied_id: origin_id, applied_type: "ApplyAddDepartment")
|
||||
|
||||
applied_message.update_all(:status => 4)
|
||||
apply_add.update_attribute(:status, 2)
|
||||
apply_add.tidings.update_all(:status => 1)
|
||||
|
||||
extra = to_department&.name + "(#{apply_add&.department&.school&.try(:name)})"
|
||||
tiding_params = {
|
||||
user_id: apply_add.user_id,
|
||||
trigger_user_id: 0,
|
||||
container_id: apply_add.id,
|
||||
container_type: 'ApplyAddDepartment',
|
||||
belong_container_id: apply_add&.department&.school_id,
|
||||
belong_container_type: "School",
|
||||
tiding_type: "System",
|
||||
status: 3,
|
||||
extra: extra
|
||||
}
|
||||
Tiding.create(tiding_params)
|
||||
|
||||
origin_department.apply_add_departments.delete_all
|
||||
|
||||
origin_department.user_extensions.update_all(department_id: new_id)
|
||||
|
||||
if to_department.identifier.blank? && origin_department.identifier.present?
|
||||
to_department.update!(identifier: origin_department.identifier)
|
||||
end
|
||||
|
||||
origin_department.destroy!
|
||||
apply_add.destroy!
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
@depart_apply.update_attribute("status",3)
|
||||
@depart_apply&.applied_messages&.update_all(status:3)
|
||||
|
||||
if params[:tip] == 'unapplied' #未审批时候删除
|
||||
user_extens = UserExtension.where(department_id: @depart_apply.department_id)
|
||||
user_extens.update_all(department_id:nil)
|
||||
User.where(id: user_extens.pluck(:user_id)).update_all(profile_completed:false)
|
||||
|
||||
tiding_params = {
|
||||
user_id: @depart_apply.user_id,
|
||||
trigger_user_id: 0,
|
||||
container_id: @depart_apply.id,
|
||||
container_type: 'ApplyAddDepartment',
|
||||
belong_container_id: @depart_apply&.department&.school_id,
|
||||
belong_container_type: "School",
|
||||
tiding_type: "System",
|
||||
status: 2,
|
||||
extra: params[:reason]
|
||||
}
|
||||
Tiding.create(tiding_params)
|
||||
end
|
||||
|
||||
@depart_apply&.department&.destroy
|
||||
@depart_apply.destroy
|
||||
render_success_js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_apply
|
||||
@depart_apply = ApplyAddDepartment.find_by(id:params[:id])
|
||||
end
|
||||
end
|
@ -0,0 +1,41 @@
|
||||
class Admins::EcTemplatesController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@params_page = params[:page] || 1
|
||||
templates = EcTemplate.where(nil).includes(:attachments).order("updated_at desc")
|
||||
@templates = paginate templates
|
||||
end
|
||||
|
||||
def create_template
|
||||
ActiveRecord::Base.transaction do
|
||||
if params[:template_id] == "-1"
|
||||
ec_template = EcTemplate.new(name: params[:name])
|
||||
ec_template.save
|
||||
else
|
||||
ec_template = EcTemplate.find_by(id: params[:template_id])
|
||||
end
|
||||
|
||||
if params[:attachment_id] != "-1"
|
||||
attachment_id = params[:attachment_id]
|
||||
attachment_tem = Attachment.find_by(id: attachment_id)
|
||||
|
||||
unless attachment_tem.container_id.present? && attachment_tem.container_id == ec_template&.id
|
||||
attachment_tem.update_attributes(container_id: ec_template&.id, container_type: "EcTemplate")
|
||||
end
|
||||
end
|
||||
|
||||
@params_page = params[:page] || 1
|
||||
templates = EcTemplate.where(nil).includes(:attachments).order("updated_at desc")
|
||||
@templates = paginate templates
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
template = EcTemplate.find_by(id: params[:id])
|
||||
template.destroy
|
||||
render_success_js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,33 @@
|
||||
class Admins::GraduationStandardsController < Admins::BaseController
|
||||
|
||||
def index
|
||||
standards = EcGraduationStandard.all.order("updated_at desc")
|
||||
@params_page = params[:page] || 1
|
||||
@standards = paginate standards
|
||||
end
|
||||
|
||||
def create_standard
|
||||
ActiveRecord::Base.transaction do
|
||||
if params[:graduation_id] == "-1"
|
||||
content = params[:content]
|
||||
EcGraduationStandard.create(:content => content)
|
||||
else
|
||||
graduation = EcGraduationStandard.find_by(id: params[:graduation_id])
|
||||
graduation.update_attribute(:content, params[:content])
|
||||
end
|
||||
|
||||
standards = EcGraduationStandard.all.order("updated_at desc")
|
||||
@params_page = params[:page] || 1
|
||||
@standards = paginate standards
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
@graduation = EcGraduationStandard.find_by(id: params[:id])
|
||||
@graduation.destroy
|
||||
render_success_js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
class Admins::HelpCentersController < Admins::BaseController
|
||||
def edit
|
||||
current_doc
|
||||
end
|
||||
|
||||
def update
|
||||
current_doc.update!(help_center: params[:help_center])
|
||||
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_help_center_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_doc
|
||||
@doc ||= Help.first || Help.create
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
class Admins::MajorInformationsController < Admins::BaseController
|
||||
|
||||
def index
|
||||
disciplines = EcDiscipline.includes(ec_discipline_firsts: {ec_majors: :schools}).order("ec_disciplines.code asc")
|
||||
@disciplines = paginate disciplines
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,30 @@
|
||||
class Admins::SchoolsController < Admins::BaseController
|
||||
def index
|
||||
params[:sort_by] ||= 'created_at'
|
||||
params[:sort_direction] ||= 'desc'
|
||||
|
||||
schools = Admins::SchoolQuery.call(params)
|
||||
|
||||
@schools = paginate schools
|
||||
|
||||
school_ids = @schools.map(&:id)
|
||||
@department_count = Department.where(school_id: school_ids).group(:school_id).count
|
||||
end
|
||||
|
||||
def destroy
|
||||
users = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id })
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
users.update_all(profile_completed: false)
|
||||
current_school.destroy!
|
||||
end
|
||||
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_school
|
||||
@_current_school ||= School.find(params[:id])
|
||||
end
|
||||
end
|
@ -0,0 +1,122 @@
|
||||
class Admins::UnitAppliesController < Admins::BaseController
|
||||
before_action :get_apply,only: [:agree,:destroy,:edit,:update]
|
||||
|
||||
def index
|
||||
params[:sort_by] ||= 'created_at'
|
||||
params[:sort_direction] ||= 'desc'
|
||||
unit_applies = Admins::UnitApplyQuery.call(params)
|
||||
@unit_applies = paginate unit_applies.preload(:school, :user)
|
||||
end
|
||||
|
||||
def agree
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@unit_apply.update_attribute("status",1)
|
||||
@unit_apply&.applied_messages&.update_all(status:1)
|
||||
@unit_apply&.school&.update_attribute("province",@unit_apply.province)
|
||||
|
||||
# #申请信息的创建
|
||||
apply_message_params = {
|
||||
user_id: @unit_apply&.user_id,
|
||||
status: 1,
|
||||
viewed: 0,
|
||||
applied_id: @unit_apply.school_id,
|
||||
applied_type: "ApplyAddSchools",
|
||||
name: @unit_apply.name,
|
||||
}
|
||||
AppliedMessage.new(apply_message_params).save(validate: false)
|
||||
|
||||
Tiding.where(user_id: 1, trigger_user_id: @unit_apply.user_id, container_id: @unit_apply.id,
|
||||
container_type: 'ApplyAddSchools', status: 0, tiding_type: "Apply").update_all(status: 1)
|
||||
#消息的创建
|
||||
tiding_params = {
|
||||
user_id: @unit_apply.user_id,
|
||||
trigger_user_id: 0,
|
||||
container_id: @unit_apply.id,
|
||||
container_type: 'ApplyAddSchools',
|
||||
belong_container_id: @unit_apply.school_id,
|
||||
belong_container_type: "School",
|
||||
tiding_type: "System",
|
||||
status: 1
|
||||
}
|
||||
Tiding.create(tiding_params)
|
||||
render_success_js
|
||||
rescue Exception => e
|
||||
Rails.logger.info("############_________________#########{e}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
Admins::DeleteUnitApplyService.call(@unit_apply, params)
|
||||
render_success_js
|
||||
end
|
||||
|
||||
def edit
|
||||
@all_schools = School.where.not(id: @unit_apply.school_id).pluck("name","id")
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
school = School.find_by(id: params[:school_id])
|
||||
ActiveRecord::Base.transaction do
|
||||
@unit_apply&.applied_messages&.update_all(status:4)
|
||||
Tiding.where(user_id: 1, trigger_user_id: @unit_apply.user_id, container_id: @unit_apply.id,
|
||||
container_type: 'ApplyAddSchools', status: 0, tiding_type: "Apply").update_all(status: 1)
|
||||
|
||||
#消息的创建
|
||||
tiding_params = {
|
||||
user_id: @unit_apply.user_id,
|
||||
trigger_user_id: 0,
|
||||
container_id: @unit_apply.id,
|
||||
container_type: 'ApplyAddSchools',
|
||||
belong_container_id: params[:school_id],
|
||||
belong_container_type: "School",
|
||||
tiding_type: "System",
|
||||
status: 3,
|
||||
extra: school.try(:name).to_s
|
||||
}
|
||||
Tiding.create(tiding_params)
|
||||
|
||||
UserExtension.where(school_id: @unit_apply.school_id).update_all(school_id: params[:school_id].to_i)
|
||||
ApplyAddDepartment.where(:school_id => @unit_apply.school_id).update_all(school_id: params[:school_id].to_i)
|
||||
|
||||
# 判断重复
|
||||
before_apply_departments = Department.where(school_id: @unit_apply.school_id)
|
||||
before_apply_departments.each do |department|
|
||||
after_dep = Department.where(school_id: params[:school_id].to_i, name: department.name)&.first
|
||||
if after_dep.present?
|
||||
UserExtension.where(school_id: @unit_apply.school_id, department_id: department.id).update_all(department_id: after_dep.id)
|
||||
department.destroy
|
||||
department.apply_add_departments.destroy_all
|
||||
else
|
||||
department.apply_add_departments.update_all(school_id: school.id)
|
||||
department.update_attribute(:school_id, school.id)
|
||||
end
|
||||
end
|
||||
|
||||
@unit_apply&.school&.destroy
|
||||
apply_params = {
|
||||
status: 2,
|
||||
name: school&.name.to_s,
|
||||
school_id: params[:school_id],
|
||||
province: params[:province],
|
||||
city: params[:city],
|
||||
address: params[:address]
|
||||
}
|
||||
@unit_apply.update_attributes(apply_params)
|
||||
# render_success_js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_apply
|
||||
@unit_apply = ApplyAddSchool.find_by(id:params[:id])
|
||||
end
|
||||
|
||||
def disk_auth_filename(source_type, source_id, type)
|
||||
File.join(storage_path, "#{source_type}", "#{source_id}#{type}")
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,105 @@
|
||||
class CourseStagesController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :find_course, only: [:create]
|
||||
before_action :find_course_stage, only: [:update, :destroy, :edit, :up_position, :down_position]
|
||||
before_action :user_course_identity, :teacher_allowed
|
||||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@stage = CourseStage.new(stage_params)
|
||||
@stage.course_id = @course.id
|
||||
@stage.position = @course.course_stages.count + 1
|
||||
@stage.save!
|
||||
unless params[:shixun_id].blank?
|
||||
shixuns = Shixun.where(id: params[:shixun_id]).order("field(id, #{params[:shixun_id].join(",")})")
|
||||
shixuns.each do |shixun|
|
||||
CourseStageShixun.create!(course_stage_id: @stage.id, course_id: @course.id, shixun_id: shixun.id, position: @stage.course_stage_shixuns.count + 1)
|
||||
end
|
||||
end
|
||||
normal_status("创建成功")
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@stage.update_attributes!(stage_params)
|
||||
@stage.course_stage_shixuns.destroy_all
|
||||
unless params[:shixun_id].blank?
|
||||
params[:shixun_id].each do |shixun_id|
|
||||
shixun = Shixun.where(id: shixun_id).first
|
||||
@stage.course_stage_shixuns.create!(course_id: @course.id, shixun_id: shixun.id, position: @stage.course_stage_shixuns.count + 1) if shixun.present?
|
||||
end
|
||||
end
|
||||
normal_status("更新成功")
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
ActiveRecord::Base.transaction do
|
||||
@course.course_stages.where("position > ?", @stage.position).update_all("position = position - 1")
|
||||
@stage.destroy!
|
||||
normal_status("删除成功")
|
||||
end
|
||||
end
|
||||
|
||||
def up_position
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
position = @stage.position
|
||||
tip_exception("第一章不能向上移动") if @stage.position == 1
|
||||
pre_stage = @course.course_stages.where(position: position - 1).first
|
||||
pre_stage.update_attributes(position: position)
|
||||
@stage.update_attributes(position: position - 1)
|
||||
normal_status("更新成功")
|
||||
rescue Exception => e
|
||||
uid_logger("stage up failed: #{e.message}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down_position
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
position = @stage.position
|
||||
rails "最后一章不能向下移动" if @stage.position == @course.course_stages.count
|
||||
next_stage = @course.course_stages.where(position: position + 1).first
|
||||
next_stage.update_attributes(position: position)
|
||||
@stage.update_attributes(position: position + 1)
|
||||
normal_status("更新成功")
|
||||
rescue Exception => e
|
||||
uid_logger("stage up failed: #{e.message}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_course_stage
|
||||
@stage = CourseStage.find_by!(id: params[:id])
|
||||
@course = @stage.course
|
||||
end
|
||||
|
||||
def stage_params
|
||||
tip_exception("章节名称不能为空") if params[:name].blank?
|
||||
params.permit(:name, :description)
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class Ecs::GraduationSubitemsController < Ecs::BaseController
|
||||
def index
|
||||
subitems = current_year.ec_graduation_subitems.reorder('ec_graduation_requirements.position ASC, ec_graduation_subitems.position ASC')
|
||||
@graduation_subitems = subitems.includes(:ec_graduation_requirement)
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
class Ecs::UsersController < Ecs::BaseController
|
||||
skip_before_action :check_user_permission!
|
||||
before_action :check_manager_permission!
|
||||
|
||||
def index
|
||||
users = UserQuery.call(params)
|
||||
|
||||
@count = users.count
|
||||
@users = paginate users.includes(user_extension: [:school, :department])
|
||||
@manager_ids = current_major_school.ec_major_school_users.pluck(:user_id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_major_school
|
||||
@_ec_major_school ||= EcMajorSchool.find(params[:ec_major_school_id])
|
||||
end
|
||||
|
||||
def current_school
|
||||
@_current_school ||= current_major_school.school
|
||||
end
|
||||
end
|
@ -0,0 +1,44 @@
|
||||
class HelpsController < ApplicationController
|
||||
before_action :require_login, only: [:feedback]
|
||||
|
||||
helper_method :current_help
|
||||
|
||||
def about
|
||||
render_ok(content: current_help&.about_us)
|
||||
end
|
||||
|
||||
def contact
|
||||
@cooperations = Cooperation.all.group(:user_type)
|
||||
end
|
||||
|
||||
def cooperatives
|
||||
@data = { 'alliance_coop' => [], 'com_coop' => [], 'edu_coop' => [] }
|
||||
@data = @data.merge CooImg.all.group_by(&:img_type)
|
||||
end
|
||||
|
||||
def agreement
|
||||
render_ok(content: current_help&.agreement)
|
||||
end
|
||||
|
||||
def help_center
|
||||
render_ok(content: current_help&.help_center)
|
||||
end
|
||||
|
||||
def feedback
|
||||
content = "<p>[#{params[:question_kind]}]</p><p>问题页面网址:#{params[:url]}</p>#{params[:description]}"
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
attr = { sender_id: User.current.id, receiver_id: 1, content: content, send_time: Time.now }
|
||||
PrivateMessage.create!(attr.merge(user_id: User.current.id, target_id: 1, status: 1))
|
||||
PrivateMessage.create!(attr.merge(user_id: 1, target_id: User.current.id, status: 0))
|
||||
end
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_help
|
||||
@_current_help ||= Help.first
|
||||
end
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
class ShixunListsController < ApplicationController
|
||||
def index
|
||||
@results = ShixunSearchService.call(search_params)
|
||||
end
|
||||
|
||||
private
|
||||
def search_params
|
||||
params.permit(:keyword, :type, :page, :limit, :order, :type, :status, :diff)
|
||||
end
|
||||
end
|
@ -0,0 +1,11 @@
|
||||
class Wechats::JsSdkSignaturesController < ApplicationController
|
||||
def create
|
||||
timestamp = Time.now.to_i
|
||||
noncestr = ('A'..'z').to_a.sample(8).join
|
||||
signature = Util::Wechat.js_sdk_signature(params[:url], noncestr, timestamp)
|
||||
|
||||
render_ok(appid: Util::Wechat.appid, timestamp: timestamp, noncestr: noncestr, signature: signature)
|
||||
rescue Util::Wechat::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
module CourseStagesHelper
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
module Ecs::EcYearsHelper
|
||||
def achieved_graduation_course_count(ec_year)
|
||||
return 0 if ec_year.ec_courses.count.zero?
|
||||
|
||||
course_ids = ec_year.ec_courses.map(&:id)
|
||||
target_count_map = EcCourseTarget.where(ec_course_id: course_ids).group(:ec_course_id).count
|
||||
|
||||
ec_year.ec_courses.sum { |course| course.complete_target_count == target_count_map[course.id] ? 1 : 0 }
|
||||
end
|
||||
|
||||
def achieved_graduation_objective_count(ec_year)
|
||||
return 0 if ec_year.ec_graduation_subitems.count.zero?
|
||||
|
||||
subitem_ids = ec_year.ec_graduation_subitems.reorder(nil).pluck(:id)
|
||||
|
||||
relations = EcGraduationRequirementCalculation.joins(:ec_course_support).where(ec_course_supports: { ec_graduation_subitem_id: subitem_ids })
|
||||
|
||||
reached_map = relations.where(status: true).group('ec_graduation_subitem_id').count
|
||||
|
||||
reached_map.keys.size
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue