parent
2f8d4a0fdd
commit
99eaa92635
@ -0,0 +1,57 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-courses-index-page').length > 0) {
|
||||
let searchContainer = $(".course-list-form");
|
||||
let searchForm = $("form.search-form",searchContainer);
|
||||
|
||||
searchContainer.on('change', '.course-homepage-show', function(){
|
||||
searchForm.find('input[type="submit"]').trigger('click');
|
||||
});
|
||||
|
||||
//导出
|
||||
searchContainer.on('click', "#course-export", function () {
|
||||
window.location.href = "/admins/courses.xlsx?" + searchForm.serialize();
|
||||
});
|
||||
|
||||
$(".course-list-container").on("change", '.course-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/courses/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
|
||||
// ************** 学校选择 *************
|
||||
searchForm.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;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,45 @@
|
||||
class Admins::ProjectsController < Admins::BaseController
|
||||
|
||||
def index
|
||||
default_sort('created_at', 'desc')
|
||||
|
||||
search = params[:search].to_s.strip
|
||||
projects = Project.where("name like ?", "%#{search}%")
|
||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @course.is_delete == 0
|
||||
@course.delete!
|
||||
Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id,
|
||||
container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @course.update_attributes(setting_params)
|
||||
render_ok
|
||||
else
|
||||
redirect_to admins_courses_path
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
def homepage_show
|
||||
|
||||
end
|
||||
|
||||
def email_notify
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_course
|
||||
@course = Course.find_by!(id: params[:id])
|
||||
end
|
||||
|
||||
def setting_params
|
||||
params.permit(:homepage_show, :email_notify)
|
||||
end
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class Version < ApplicationRecord
|
||||
belongs_to :project
|
||||
end
|
@ -0,0 +1,29 @@
|
||||
wb = xlsx_package.workbook
|
||||
|
||||
wb.styles do |s|
|
||||
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center}
|
||||
wb.add_worksheet(name: "课堂列表") do |sheet|
|
||||
sheet.add_row %w(ID 课堂名称 成员 资源 普通作业 分组作业 实训作业 试卷 评测次数 私有 状态 单位 创建者 创建时间 动态时间), :height => 25,:style => blue_cell
|
||||
|
||||
@courses.each do |course|
|
||||
data = [
|
||||
course.id,
|
||||
course.name,
|
||||
course.course_members_count,
|
||||
get_attachment_count(course, 0),
|
||||
course.course_homework_count(1),
|
||||
course.course_homework_count(3),
|
||||
course.course_homework_count(4),
|
||||
course.exercises_count,
|
||||
course.evaluate_count,
|
||||
course.is_public == 1 ? "--" : "√",
|
||||
course.is_end ? "已结束" : "正在进行",
|
||||
course.school&.name,
|
||||
course.teacher&.real_name,
|
||||
course.created_at&.strftime('%Y-%m-%d %H:%M'),
|
||||
course.max_activity_time ? course.max_activity_time&.strftime('%Y-%m-%d %H:%M') : "--"
|
||||
]
|
||||
sheet.add_row(data)
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
alert("删除成功");
|
||||
$(".course-item-<%= @course.id %>").find(".delete-course-action").remove();
|
@ -0,0 +1,15 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('项目列表') %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container project-list-form">
|
||||
<%= form_tag(admins_projects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '项目名称检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container project-list-container">
|
||||
<%= render partial: 'admins/projects/shared/list', locals: { projects: @projects } %>
|
||||
</div>
|
@ -0,0 +1 @@
|
||||
$('.project-list-container').html("<%= j( render partial: 'admins/projects/shared/list', locals: { projects: @projects } ) %>");
|
@ -0,0 +1,48 @@
|
||||
<table class="table table-hover text-center subject-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="4%">ID</th>
|
||||
<th width="15%" class="text-left">项目名称</th>
|
||||
<th width="6%">公开</th>
|
||||
<th width="5%">issue</th>
|
||||
<th width="5%">资源</th>
|
||||
<th width="5%">版本库</th>
|
||||
<th width="5%">PullRequest</th>
|
||||
<th width="5%">里程碑</th>
|
||||
<th width="10%">成员</th>
|
||||
<th width="10%">管理员</th>
|
||||
<th width="20%"><%= sort_tag('创建时间', name: 'created_at', path: admins_projects_path) %></th>
|
||||
<th width="10%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if projects.present? %>
|
||||
<% projects.each do |project| %>
|
||||
<tr class="project-item-<%= project.id %>">
|
||||
<td><%= project.id %></td>
|
||||
<td class="text-left">
|
||||
<%= link_to(project.name, "/projects/#{project.id}", target: '_blank') %>
|
||||
</td>
|
||||
<td><%= project.is_public ? '√' : '' %></td>
|
||||
<td><%= project.issues.size %></td>
|
||||
<td><%= project.attachments.size %></td>
|
||||
<td><%= project.project_score.try(:changeset_num).to_i %></td>
|
||||
<td><%= project.project_score.try(:pull_request_num).to_i %></td>
|
||||
<td><%= project.versions.size %></td>
|
||||
<td><%= project.members.size %></td>
|
||||
<td>
|
||||
<%= project.owner ? link_to(project.owner&.real_name, "/users/#{project.owner&.login}", target: '_blank') : "" %>
|
||||
</td>
|
||||
<td><%= project.created_on&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td class="action-container">
|
||||
<%= delete_link '删除', admins_project_path(project, element: ".project-item-#{project.id}"), class: 'delete-project-action' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= render partial: 'admins/shared/paginate', locals: { objects: projects } %>
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Version, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue