From 81380ea879011eac6cbd36c38755d3f2156b8b3c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 2 Mar 2020 16:08:10 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attendances_controller.rb | 38 +++++++++++++++++++ app/models/course.rb | 4 ++ app/models/course_attendance.rb | 13 +++++++ app/models/course_attendance_group.rb | 5 +++ config/routes.rb | 2 + ...0200302034841_create_course_attendances.rb | 15 ++++++++ ...2035218_create_course_attendance_groups.rb | 13 +++++++ spec/models/course_attendance_group_spec.rb | 5 +++ spec/models/course_attendance_spec.rb | 5 +++ 9 files changed, 100 insertions(+) create mode 100644 app/controllers/attendances_controller.rb create mode 100644 app/models/course_attendance.rb create mode 100644 app/models/course_attendance_group.rb create mode 100644 db/migrate/20200302034841_create_course_attendances.rb create mode 100644 db/migrate/20200302035218_create_course_attendance_groups.rb create mode 100644 spec/models/course_attendance_group_spec.rb create mode 100644 spec/models/course_attendance_spec.rb diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb new file mode 100644 index 000000000..fc94eaf5b --- /dev/null +++ b/app/controllers/attendances_controller.rb @@ -0,0 +1,38 @@ +class AttendancesController < ApplicationController + before_action :require_login + before_action :find_course, only: [:create, :index] + + def create + ActiveRecord::Base.transaction do + attendance = @course.course_attendances.create!(create_params) + unless params[:group_ids].blank? + params[:group_ids].each do |group_id| + @course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance) + end + else + + end + end + end + + def index + + end + + def show + + end + + def update + + end + + def destroy + + end + + private + def create_params + params.permit(:name, :mode, :attendance_date, :start_time, :end_time) + end +end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 14c17cf39..74be99bb2 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -90,6 +90,10 @@ class Course < ApplicationRecord # 直播 has_many :live_links, dependent: :destroy + # 签到 + has_many :course_attendances, dependent: :destroy + has_many :course_attendance_groups, dependent: :destroy + validate :validate_sensitive_string scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } diff --git a/app/models/course_attendance.rb b/app/models/course_attendance.rb new file mode 100644 index 000000000..fcad77ec1 --- /dev/null +++ b/app/models/course_attendance.rb @@ -0,0 +1,13 @@ +class CourseAttendance < ApplicationRecord + belongs_to :course + belongs_to :user + + has_many :course_attendance_groups, dependent: :destroy + + validates :name, presence: true + validates :mode, presence: true + validates :attendance_date, presence: true + validates :start_time, presence: true + validates :end_time, presence: true + +end diff --git a/app/models/course_attendance_group.rb b/app/models/course_attendance_group.rb new file mode 100644 index 000000000..8de9ebe88 --- /dev/null +++ b/app/models/course_attendance_group.rb @@ -0,0 +1,5 @@ +class CourseAttendanceGroup < ApplicationRecord + belongs_to :course + belongs_to :course_attendance + belongs_to :course_group +end diff --git a/config/routes.rb b/config/routes.rb index ba0827676..6a25a076e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -554,6 +554,8 @@ Rails.application.routes.draw do end end + resources :attendances, only: [:index, :update, :create, :show, :destroy], shallow: true + resources :live_links, only: [:index, :update, :create, :edit, :destroy], shallow: true resources :homework_commons, shallow: true do diff --git a/db/migrate/20200302034841_create_course_attendances.rb b/db/migrate/20200302034841_create_course_attendances.rb new file mode 100644 index 000000000..25eaf0d8e --- /dev/null +++ b/db/migrate/20200302034841_create_course_attendances.rb @@ -0,0 +1,15 @@ +class CreateCourseAttendances < ActiveRecord::Migration[5.2] + def change + create_table :course_attendances do |t| + t.references :course, index: true + t.references :user, index: true + t.string :name + t.integer :mode, limit: 1, default: 0 + t.date :attendance_date + t.time :start_time + t.time :end_time + + t.timestamps + end + end +end diff --git a/db/migrate/20200302035218_create_course_attendance_groups.rb b/db/migrate/20200302035218_create_course_attendance_groups.rb new file mode 100644 index 000000000..0f76beea3 --- /dev/null +++ b/db/migrate/20200302035218_create_course_attendance_groups.rb @@ -0,0 +1,13 @@ +class CreateCourseAttendanceGroups < ActiveRecord::Migration[5.2] + def change + create_table :course_attendance_groups do |t| + t.references :course, index: true + t.references :course_attendance + t.references :course_group, index: true + + t.timestamps + + add_index :course_attendances, [:course_attendance_id, :course_group_id, :course_id], name: "course_group_attendance", unique: true + end + end +end diff --git a/spec/models/course_attendance_group_spec.rb b/spec/models/course_attendance_group_spec.rb new file mode 100644 index 000000000..2fc1a2a0a --- /dev/null +++ b/spec/models/course_attendance_group_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseAttendanceGroup, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/course_attendance_spec.rb b/spec/models/course_attendance_spec.rb new file mode 100644 index 000000000..a54f4be64 --- /dev/null +++ b/spec/models/course_attendance_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseAttendance, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From c3d98855cb854f04e0c5c95b11552c182aa8af0d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 2 Mar 2020 19:38:05 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attendances_controller.rb | 38 --------- .../weapps/attendances_controller.rb | 85 +++++++++++++++++++ app/models/course.rb | 3 +- app/models/course_attendance.rb | 20 +++++ app/models/course_member_attendance.rb | 9 ++ .../weapps/attendances/index.json.jbuilder | 0 .../student_attendances.json.jbuilder | 12 +++ config/locales/zh-CN.yml | 6 ++ config/routes.rb | 8 +- ...0200302034841_create_course_attendances.rb | 1 + ...2035218_create_course_attendance_groups.rb | 3 +- ...100750_create_course_member_attendances.rb | 17 ++++ spec/models/course_member_attendance_spec.rb | 5 ++ 13 files changed, 165 insertions(+), 42 deletions(-) delete mode 100644 app/controllers/attendances_controller.rb create mode 100644 app/controllers/weapps/attendances_controller.rb create mode 100644 app/models/course_member_attendance.rb create mode 100644 app/views/weapps/attendances/index.json.jbuilder create mode 100644 app/views/weapps/attendances/student_attendances.json.jbuilder create mode 100644 db/migrate/20200302100750_create_course_member_attendances.rb create mode 100644 spec/models/course_member_attendance_spec.rb diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb deleted file mode 100644 index fc94eaf5b..000000000 --- a/app/controllers/attendances_controller.rb +++ /dev/null @@ -1,38 +0,0 @@ -class AttendancesController < ApplicationController - before_action :require_login - before_action :find_course, only: [:create, :index] - - def create - ActiveRecord::Base.transaction do - attendance = @course.course_attendances.create!(create_params) - unless params[:group_ids].blank? - params[:group_ids].each do |group_id| - @course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance) - end - else - - end - end - end - - def index - - end - - def show - - end - - def update - - end - - def destroy - - end - - private - def create_params - params.permit(:name, :mode, :attendance_date, :start_time, :end_time) - end -end \ No newline at end of file diff --git a/app/controllers/weapps/attendances_controller.rb b/app/controllers/weapps/attendances_controller.rb new file mode 100644 index 000000000..69d2f658d --- /dev/null +++ b/app/controllers/weapps/attendances_controller.rb @@ -0,0 +1,85 @@ +class Weapps::AttendancesController < ApplicationController + before_action :require_login + before_action :find_course, only: [:create, :index] + before_action :find_attendance, except: [:create, :index] + before_action :user_course_identity + before_action :teacher_allowed, only: [:create] + + def create + ActiveRecord::Base.transaction do + attendance = @course.course_attendances.create!(create_params.merge(user_id: current_user.id)) + unless params[:group_ids].blank? + group_ids = @course.charge_group_ids(current_user) & params[:group_ids] + group_ids.each do |group_id| + @course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance) + end + else + @course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance) + end + render_ok({attendance_id: attendance.id}) + end + end + + def index + + end + + def student_attendances + if @user_course_identity == Course::STUDENT + current_date = Date.current + current_end_time = Time.current.strftime("%H:%M:%S") + member = @course.students.find_by(user_id: current_user.id) + + # 先算出该学生所在分班的签到id + # 分班id为0 表示签到不限制分班 + group_ids = [member&.course_group_id.to_i, 0] + all_attendance_ids = @course.course_attendance_groups.where(course_group_id: group_ids).pluck(:course_attendance_id) + + @history_attendances = @course.course_attendances.where(id: all_attendance_ids.uniq). + where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and end_time < #{current_end_time})").order("id desc") + @current_attendance = @course.course_attendances.where(id: all_attendance_ids.uniq). + where("attendance_date = '#{current_date}' and start_time <= #{current_end_time} and end_time > #{current_end_time}").take + @history_count = @history_attendances.size + + student_attendance_ids = @history_attendances.pluck(:id) + student_attendance_ids += @current_attendance.present? ? [@current_attendance.id] : [] + + if student_attendance_ids.uniq.blank? + @normal_count = 0 + @leave_count = 0 + @absence_count = 0 + else + @normal_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 1).size + @leave_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 2).size + @absence_count = student_attendance_ids.uniq.size - @normal_count - @leave_count + end + + @all_history_count = @history_attendances.size + @history_attendances = paginate @history_attendances.includes(:course_member_attendances) + end + end + + def show + + end + + def update + tip_exception(403, "") unless @user_course_identity < Course::PROFESSOR || @attendance.user_id == current_user.id + @attendance.update!(name: params[:name]) + render_ok + end + + def destroy + + end + + private + def create_params + params.permit(:name, :mode, :attendance_date, :start_time, :end_time) + end + + def find_attendance + @attendance = CourseAttendance.find params[:id] + @course = @attendance.course + end +end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 74be99bb2..5ae7f9484 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -92,7 +92,8 @@ class Course < ApplicationRecord # 签到 has_many :course_attendances, dependent: :destroy - has_many :course_attendance_groups, dependent: :destroy + has_many :course_attendance_groups + has_many :course_member_attendances validate :validate_sensitive_string diff --git a/app/models/course_attendance.rb b/app/models/course_attendance.rb index fcad77ec1..f3bcffc56 100644 --- a/app/models/course_attendance.rb +++ b/app/models/course_attendance.rb @@ -1,8 +1,10 @@ class CourseAttendance < ApplicationRecord + # mode: 0 两种签到,1 二维码签到,2 数字签到 belongs_to :course belongs_to :user has_many :course_attendance_groups, dependent: :destroy + has_many :course_member_attendances, dependent: :destroy validates :name, presence: true validates :mode, presence: true @@ -10,4 +12,22 @@ class CourseAttendance < ApplicationRecord validates :start_time, presence: true validates :end_time, presence: true + after_create :generate_attendance_code + + # 延迟生成邀请码 + def attendance_code + return generate_attendance_code + end + + # 生成邀请码 + CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + def generate_attendance_code + code = read_attribute(:attendance_code) + if !code || code.size < 4 + code = CODES.sample(4).join + return generate_attendance_code if CourseAttendance.where(attendance_code: code).present? + update_attribute(:attendance_code, code) + end + code + end end diff --git a/app/models/course_member_attendance.rb b/app/models/course_member_attendance.rb new file mode 100644 index 000000000..a03d016bb --- /dev/null +++ b/app/models/course_member_attendance.rb @@ -0,0 +1,9 @@ +class CourseMemberAttendance < ApplicationRecord + # attendance_mode :1 二维码签到,2 数字签到,3 老师签到 + # attendance_status :1 正常签到,2 请假 + belongs_to :course_member + belongs_to :user + belongs_to :course + belongs_to :course_attendance + belongs_to :course_group +end diff --git a/app/views/weapps/attendances/index.json.jbuilder b/app/views/weapps/attendances/index.json.jbuilder new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/weapps/attendances/student_attendances.json.jbuilder b/app/views/weapps/attendances/student_attendances.json.jbuilder new file mode 100644 index 000000000..2c9bad5ac --- /dev/null +++ b/app/views/weapps/attendances/student_attendances.json.jbuilder @@ -0,0 +1,12 @@ +json.current_attendance do + json.partial! 'student_attendance', locals: {attendance: @current_attendance} +end + +json.history_attendances @history_attendances do |attendance| + json.partial! 'student_attendance', locals: {attendance: attendance} +end + +json.all_history_count @all_history_count +json.normal_count @normal_count +json.leave_count @leave_count +json.absence_count @absence_count \ No newline at end of file diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 4f41df0c5..f9671eec1 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -177,6 +177,12 @@ zh-CN: platform: '直播平台' live_time: '开播时间' duration: '直播时长' + course_attendance: + name: '签到名称' + mode: '签到方式' + attendance_date: '签到日期' + start_time: '开始时间' + end_time: '结束时间' diff --git a/config/routes.rb b/config/routes.rb index 6a25a076e..ba06cb4c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -554,8 +554,6 @@ Rails.application.routes.draw do end end - resources :attendances, only: [:index, :update, :create, :show, :destroy], shallow: true - resources :live_links, only: [:index, :update, :create, :edit, :destroy], shallow: true resources :homework_commons, shallow: true do @@ -1054,6 +1052,12 @@ Rails.application.routes.draw do collection do get :check_invite_code end + + resources :attendances, only: [:index, :update, :create, :show, :destroy], shallow: true do + member do + get :student_attendances + end + end end resources :homework_commons do diff --git a/db/migrate/20200302034841_create_course_attendances.rb b/db/migrate/20200302034841_create_course_attendances.rb index 25eaf0d8e..e99668058 100644 --- a/db/migrate/20200302034841_create_course_attendances.rb +++ b/db/migrate/20200302034841_create_course_attendances.rb @@ -8,6 +8,7 @@ class CreateCourseAttendances < ActiveRecord::Migration[5.2] t.date :attendance_date t.time :start_time t.time :end_time + t.string :attendance_code t.timestamps end diff --git a/db/migrate/20200302035218_create_course_attendance_groups.rb b/db/migrate/20200302035218_create_course_attendance_groups.rb index 0f76beea3..048a33c06 100644 --- a/db/migrate/20200302035218_create_course_attendance_groups.rb +++ b/db/migrate/20200302035218_create_course_attendance_groups.rb @@ -7,7 +7,8 @@ class CreateCourseAttendanceGroups < ActiveRecord::Migration[5.2] t.timestamps - add_index :course_attendances, [:course_attendance_id, :course_group_id, :course_id], name: "course_group_attendance", unique: true end + + add_index :course_attendance_groups, [:course_attendance_id, :course_group_id, :course_id], name: "course_group_attendance", unique: true end end diff --git a/db/migrate/20200302100750_create_course_member_attendances.rb b/db/migrate/20200302100750_create_course_member_attendances.rb new file mode 100644 index 000000000..b9c39902f --- /dev/null +++ b/db/migrate/20200302100750_create_course_member_attendances.rb @@ -0,0 +1,17 @@ +class CreateCourseMemberAttendances < ActiveRecord::Migration[5.2] + def change + create_table :course_member_attendances do |t| + t.references :course_member, index: true + t.references :user + t.references :course, index: true + t.references :course_attendance + t.references :course_group, index: true + t.integer :attendance_mode, default: 0 + t.integer :attendance_status, default: 0 + + t.timestamps + end + + add_index :course_member_attendances, [:course_attendance_id, :user_id], unique: true, name: "index_on_user_attendance" + end +end diff --git a/spec/models/course_member_attendance_spec.rb b/spec/models/course_member_attendance_spec.rb new file mode 100644 index 000000000..5e66e8f1a --- /dev/null +++ b/spec/models/course_member_attendance_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseMemberAttendance, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From e7b8946bdae698cf277f00fcab4e20f42a748b05 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 3 Mar 2020 14:42:48 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weapps/attendances_controller.rb | 65 +++++++++---------- app/helpers/weapps/attendances_helper.rb | 7 ++ app/models/course_attendance_group.rb | 2 +- .../_student_attendance.json.jbuilder | 5 ++ .../student_attendances.json.jbuilder | 2 +- config/routes.rb | 2 +- 6 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 app/helpers/weapps/attendances_helper.rb create mode 100644 app/views/weapps/attendances/_student_attendance.json.jbuilder diff --git a/app/controllers/weapps/attendances_controller.rb b/app/controllers/weapps/attendances_controller.rb index 69d2f658d..f61cc95c2 100644 --- a/app/controllers/weapps/attendances_controller.rb +++ b/app/controllers/weapps/attendances_controller.rb @@ -1,7 +1,7 @@ class Weapps::AttendancesController < ApplicationController before_action :require_login - before_action :find_course, only: [:create, :index] - before_action :find_attendance, except: [:create, :index] + before_action :find_course, only: [:create, :index, :student_attendances] + before_action :find_attendance, except: [:create, :index, :student_attendances] before_action :user_course_identity before_action :teacher_allowed, only: [:create] @@ -25,38 +25,37 @@ class Weapps::AttendancesController < ApplicationController end def student_attendances - if @user_course_identity == Course::STUDENT - current_date = Date.current - current_end_time = Time.current.strftime("%H:%M:%S") - member = @course.students.find_by(user_id: current_user.id) - - # 先算出该学生所在分班的签到id - # 分班id为0 表示签到不限制分班 - group_ids = [member&.course_group_id.to_i, 0] - all_attendance_ids = @course.course_attendance_groups.where(course_group_id: group_ids).pluck(:course_attendance_id) - - @history_attendances = @course.course_attendances.where(id: all_attendance_ids.uniq). - where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and end_time < #{current_end_time})").order("id desc") - @current_attendance = @course.course_attendances.where(id: all_attendance_ids.uniq). - where("attendance_date = '#{current_date}' and start_time <= #{current_end_time} and end_time > #{current_end_time}").take - @history_count = @history_attendances.size - - student_attendance_ids = @history_attendances.pluck(:id) - student_attendance_ids += @current_attendance.present? ? [@current_attendance.id] : [] - - if student_attendance_ids.uniq.blank? - @normal_count = 0 - @leave_count = 0 - @absence_count = 0 - else - @normal_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 1).size - @leave_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 2).size - @absence_count = student_attendance_ids.uniq.size - @normal_count - @leave_count - end - - @all_history_count = @history_attendances.size - @history_attendances = paginate @history_attendances.includes(:course_member_attendances) + tip_exception(403, "") if @user_course_identity != Course::STUDENT + member = @course.students.find_by(user_id: current_user.id) + current_date = Date.current + current_end_time = Time.current.strftime("%H:%M:%S") + + # 先算出该学生所在分班的签到id + # 分班id为0 表示签到不限制分班 + group_ids = [member&.course_group_id.to_i, 0] + all_attendance_ids = @course.course_attendance_groups.where(course_group_id: group_ids).pluck(:course_attendance_id) + + @history_attendances = @course.course_attendances.where(id: all_attendance_ids.uniq). + where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and end_time < '#{current_end_time}')").order("id desc") + @current_attendance = @course.course_attendances.where(id: all_attendance_ids.uniq). + where("attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}'").take + @history_count = @history_attendances.size + + student_attendance_ids = @history_attendances.pluck(:id) + student_attendance_ids += @current_attendance.present? ? [@current_attendance.id] : [] + + if student_attendance_ids.uniq.blank? + @normal_count = 0 + @leave_count = 0 + @absence_count = 0 + else + @normal_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 1).size + @leave_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 2).size + @absence_count = student_attendance_ids.uniq.size - @normal_count - @leave_count end + + @all_history_count = @history_attendances.size + @history_attendances = paginate @history_attendances.includes(:course_member_attendances) end def show diff --git a/app/helpers/weapps/attendances_helper.rb b/app/helpers/weapps/attendances_helper.rb new file mode 100644 index 000000000..087084288 --- /dev/null +++ b/app/helpers/weapps/attendances_helper.rb @@ -0,0 +1,7 @@ +module Weapps::AttendancesHelper + + def student_attendance_status attendance, user + st_attendance = attendance.course_member_attendances.find_by(user_id: user.id) + st_attendance.present? ? st_attendance.attendance_status : 0 + end +end \ No newline at end of file diff --git a/app/models/course_attendance_group.rb b/app/models/course_attendance_group.rb index 8de9ebe88..02c2f6fb9 100644 --- a/app/models/course_attendance_group.rb +++ b/app/models/course_attendance_group.rb @@ -1,5 +1,5 @@ class CourseAttendanceGroup < ApplicationRecord belongs_to :course belongs_to :course_attendance - belongs_to :course_group + belongs_to :course_group, optional: true end diff --git a/app/views/weapps/attendances/_student_attendance.json.jbuilder b/app/views/weapps/attendances/_student_attendance.json.jbuilder new file mode 100644 index 000000000..9461c4976 --- /dev/null +++ b/app/views/weapps/attendances/_student_attendance.json.jbuilder @@ -0,0 +1,5 @@ +json.(attendance, :name, :mode) +json.attendance_date attendance.attendance_date.strftime("%Y/%m/%d") +json.start_time attendance.start_time.strftime("%H:%M") +json.end_time attendance.end_time.strftime("%H:%M") +json.attendance_status student_attendance_status(attendance, User.current) \ No newline at end of file diff --git a/app/views/weapps/attendances/student_attendances.json.jbuilder b/app/views/weapps/attendances/student_attendances.json.jbuilder index 2c9bad5ac..91c6fd457 100644 --- a/app/views/weapps/attendances/student_attendances.json.jbuilder +++ b/app/views/weapps/attendances/student_attendances.json.jbuilder @@ -1,5 +1,5 @@ json.current_attendance do - json.partial! 'student_attendance', locals: {attendance: @current_attendance} + json.partial! 'student_attendance', locals: {attendance: @current_attendance} if @current_attendance.present? end json.history_attendances @history_attendances do |attendance| diff --git a/config/routes.rb b/config/routes.rb index ba06cb4c7..f82dfec11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1054,7 +1054,7 @@ Rails.application.routes.draw do end resources :attendances, only: [:index, :update, :create, :show, :destroy], shallow: true do - member do + collection do get :student_attendances end end From 2491524975c1e9c57231167976c418dfd1dbfcb8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 3 Mar 2020 15:18:46 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_member_attendance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/course_member_attendance.rb b/app/models/course_member_attendance.rb index a03d016bb..3b8aafda0 100644 --- a/app/models/course_member_attendance.rb +++ b/app/models/course_member_attendance.rb @@ -1,6 +1,6 @@ class CourseMemberAttendance < ApplicationRecord # attendance_mode :1 二维码签到,2 数字签到,3 老师签到 - # attendance_status :1 正常签到,2 请假 + # attendance_status :1 正常签到,2 请假,0 旷课 belongs_to :course_member belongs_to :user belongs_to :course From 51c55bfada4d70429324b98d20b7d94c4039923e Mon Sep 17 00:00:00 2001 From: anke1460 Date: Tue, 3 Mar 2020 15:30:50 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=AE=9E?= =?UTF-8?q?=E8=AE=ADbannner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/admins/ajaxform.js | 1312 +++++++++++++++++ .../admins/webapp_banners/index.js | 25 + .../stylesheets/admins/laboratories.scss | 303 ++-- .../admins/weapp_banners_controller.rb | 82 +- app/controllers/weapps/banners_controller.rb | 12 + app/models/weapp_settings/course_banner.rb | 3 + app/models/weapp_settings/shixun_banner.rb | 3 + app/views/admins/weapp_banners/create.js.erb | 1 + app/views/admins/weapp_banners/index.html.erb | 34 + .../admins/weapp_banners/shixun_banner.js.erb | 1 + config/routes.rb | 8 +- 11 files changed, 1568 insertions(+), 216 deletions(-) create mode 100644 app/assets/javascripts/admins/ajaxform.js create mode 100644 app/assets/javascripts/admins/webapp_banners/index.js create mode 100644 app/controllers/weapps/banners_controller.rb create mode 100644 app/models/weapp_settings/course_banner.rb create mode 100644 app/models/weapp_settings/shixun_banner.rb create mode 100644 app/views/admins/weapp_banners/create.js.erb create mode 100644 app/views/admins/weapp_banners/shixun_banner.js.erb diff --git a/app/assets/javascripts/admins/ajaxform.js b/app/assets/javascripts/admins/ajaxform.js new file mode 100644 index 000000000..20a88247a --- /dev/null +++ b/app/assets/javascripts/admins/ajaxform.js @@ -0,0 +1,1312 @@ +/*! + * jQuery Form Plugin + * version: 3.51.0-2014.06.20 + * Requires jQuery v1.5 or later + * Copyright (c) 2014 M. Alsup + * Examples and documentation at: http://malsup.com/jquery/form/ + * Project repository: https://github.com/malsup/form + * Dual licensed under the MIT and GPL licenses. + * https://github.com/malsup/form#copyright-and-license + */ +/*global ActiveXObject */ + +// AMD support +(function(factory) { + "use strict"; + if (typeof define === 'function' && define.amd) { + // using AMD; register as anon module + define(['jquery'], factory); + } else { + // no AMD; invoke directly + factory((typeof(jQuery) != 'undefined') ? jQuery : window.Zepto); + } + } + + (function($) { + "use strict"; + + /* + Usage Note: + ----------- + Do not use both ajaxSubmit and ajaxForm on the same form. These + functions are mutually exclusive. Use ajaxSubmit if you want + to bind your own submit handler to the form. For example, + + $(document).ready(function() { + $('#myForm').on('submit', function(e) { + e.preventDefault(); // <-- important + $(this).ajaxSubmit({ + target: '#output' + }); + }); + }); + + Use ajaxForm when you want the plugin to manage all the event binding + for you. For example, + + $(document).ready(function() { + $('#myForm').ajaxForm({ + target: '#output' + }); + }); + + You can also use ajaxForm with delegation (requires jQuery v1.7+), so the + form does not have to exist when you invoke ajaxForm: + + $('#myForm').ajaxForm({ + delegation: true, + target: '#output' + }); + + When using ajaxForm, the ajaxSubmit function will be invoked for you + at the appropriate time. + */ + + /** + * Feature detection + */ + var feature = {}; + feature.fileapi = $("").get(0).files !== undefined; + feature.formdata = window.FormData !== undefined; + + var hasProp = !!$.fn.prop; + + // attr2 uses prop when it can but checks the return type for + // an expected string. this accounts for the case where a form + // contains inputs with names like "action" or "method"; in those + // cases "prop" returns the element + $.fn.attr2 = function() { + if (!hasProp) { + return this.attr.apply(this, arguments); + } + var val = this.prop.apply(this, arguments); + if ((val && val.jquery) || typeof val === 'string') { + return val; + } + return this.attr.apply(this, arguments); + }; + + /** + * ajaxSubmit() provides a mechanism for immediately submitting + * an HTML form using AJAX. + */ + $.fn.ajaxSubmit = function(options) { + /*jshint scripturl:true */ + + // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) + if (!this.length) { + log('ajaxSubmit: skipping submit process - no element selected'); + return this; + } + + var method, action, url, $form = this; + + if (typeof options == 'function') { + options = { + success: options + }; + } else if (options === undefined) { + options = {}; + } + + method = options.type || this.attr2('method'); + action = options.url || this.attr2('action'); + + url = (typeof action === 'string') ? $.trim(action) : ''; + url = url || window.location.href || ''; + if (url) { + // clean url (don't include hash vaue) + url = (url.match(/^([^#]+)/) || [])[1]; + } + + options = $.extend(true, { + url: url, + success: $.ajaxSettings.success, + type: method || $.ajaxSettings.type, + iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' + }, options); + + // hook for manipulating the form data before it is extracted; + // convenient for use with rich editors like tinyMCE or FCKEditor + var veto = {}; + this.trigger('form-pre-serialize', [this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); + return this; + } + + // provide opportunity to alter form data before it is serialized + if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSerialize callback'); + return this; + } + + var traditional = options.traditional; + if (traditional === undefined) { + traditional = $.ajaxSettings.traditional; + } + + var elements = []; + var qx, a = this.formToArray(options.semantic, elements); + if (options.data) { + options.extraData = options.data; + qx = $.param(options.data, traditional); + } + + // give pre-submit callback an opportunity to abort the submit + if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSubmit callback'); + return this; + } + + // fire vetoable 'validate' event + this.trigger('form-submit-validate', [a, this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); + return this; + } + + var q = $.param(a, traditional); + if (qx) { + q = (q ? (q + '&' + qx) : qx); + } + if (options.type.toUpperCase() == 'GET') { + options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; + options.data = null; // data is null for 'get' + } else { + options.data = q; // data is the query string for 'post' + } + + var callbacks = []; + if (options.resetForm) { + callbacks.push(function() { + $form.resetForm(); + }); + } + if (options.clearForm) { + callbacks.push(function() { + $form.clearForm(options.includeHidden); + }); + } + + // perform a load on the target only if dataType is not provided + if (!options.dataType && options.target) { + var oldSuccess = options.success || function() {}; + callbacks.push(function(data) { + var fn = options.replaceTarget ? 'replaceWith' : 'html'; + $(options.target)[fn](data).each(oldSuccess, arguments); + }); + } else if (options.success) { + callbacks.push(options.success); + } + + options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg + var context = options.context || this; // jQuery 1.4+ supports scope context + for (var i = 0, max = callbacks.length; i < max; i++) { + callbacks[i].apply(context, [data, status, xhr || $form, $form]); + } + }; + + if (options.error) { + var oldError = options.error; + options.error = function(xhr, status, error) { + var context = options.context || this; + oldError.apply(context, [xhr, status, error, $form]); + }; + } + + if (options.complete) { + var oldComplete = options.complete; + options.complete = function(xhr, status) { + var context = options.context || this; + oldComplete.apply(context, [xhr, status, $form]); + }; + } + + // are there files to upload? + + // [value] (issue #113), also see comment: + // https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219 + var fileInputs = $('input[type=file]:enabled', this).filter(function() { + return $(this).val() !== ''; + }); + + var hasFileInputs = fileInputs.length > 0; + var mp = 'multipart/form-data'; + var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); + + var fileAPI = feature.fileapi && feature.formdata; + log("fileAPI :" + fileAPI); + var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI; + + var jqxhr; + + // options.iframe allows user to force iframe mode + // 06-NOV-09: now defaulting to iframe mode if file input is detected + if (options.iframe !== false && (options.iframe || shouldUseFrame)) { + // hack to fix Safari hang (thanks to Tim Molendijk for this) + // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d + if (options.closeKeepAlive) { + $.get(options.closeKeepAlive, function() { + jqxhr = fileUploadIframe(a); + }); + } else { + jqxhr = fileUploadIframe(a); + } + } else if ((hasFileInputs || multipart) && fileAPI) { + jqxhr = fileUploadXhr(a); + } else { + jqxhr = $.ajax(options); + } + + $form.removeData('jqxhr').data('jqxhr', jqxhr); + + // clear element array + for (var k = 0; k < elements.length; k++) { + elements[k] = null; + } + + // fire 'notify' event + this.trigger('form-submit-notify', [this, options]); + return this; + + // utility fn for deep serialization + function deepSerialize(extraData) { + var serialized = $.param(extraData, options.traditional).split('&'); + var len = serialized.length; + var result = []; + var i, part; + for (i = 0; i < len; i++) { + // #252; undo param space replacement + serialized[i] = serialized[i].replace(/\+/g, ' '); + part = serialized[i].split('='); + // #278; use array instead of object storage, favoring array serializations + result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]); + } + return result; + } + + // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz) + function fileUploadXhr(a) { + var formdata = new FormData(); + + for (var i = 0; i < a.length; i++) { + formdata.append(a[i].name, a[i].value); + } + + if (options.extraData) { + var serializedData = deepSerialize(options.extraData); + for (i = 0; i < serializedData.length; i++) { + if (serializedData[i]) { + formdata.append(serializedData[i][0], serializedData[i][1]); + } + } + } + + options.data = null; + + var s = $.extend(true, {}, $.ajaxSettings, options, { + contentType: false, + processData: false, + cache: false, + type: method || 'POST' + }); + + if (options.uploadProgress) { + // workaround because jqXHR does not expose upload property + s.xhr = function() { + var xhr = $.ajaxSettings.xhr(); + if (xhr.upload) { + xhr.upload.addEventListener('progress', function(event) { + var percent = 0; + var position = event.loaded || event.position; /*event.position is deprecated*/ + var total = event.total; + if (event.lengthComputable) { + percent = Math.ceil(position / total * 100); + } + options.uploadProgress(event, position, total, percent); + }, false); + } + return xhr; + }; + } + + s.data = null; + var beforeSend = s.beforeSend; + s.beforeSend = function(xhr, o) { + //Send FormData() provided by user + if (options.formData) { + o.data = options.formData; + } else { + o.data = formdata; + } + if (beforeSend) { + beforeSend.call(this, xhr, o); + } + }; + return $.ajax(s); + } + + // private function for handling file uploads (hat tip to YAHOO!) + function fileUploadIframe(a) { + var form = $form[0], + el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle; + var deferred = $.Deferred(); + + // #341 + deferred.abort = function(status) { + xhr.abort(status); + }; + + if (a) { + // ensure that every serialized input is still enabled + for (i = 0; i < elements.length; i++) { + el = $(elements[i]); + if (hasProp) { + el.prop('disabled', false); + } else { + el.removeAttr('disabled'); + } + } + } + + s = $.extend(true, {}, $.ajaxSettings, options); + s.context = s.context || s; + id = 'jqFormIO' + (new Date().getTime()); + if (s.iframeTarget) { + $io = $(s.iframeTarget); + n = $io.attr2('name'); + if (!n) { + $io.attr2('name', id); + } else { + id = n; + } + } else { + $io = $('