Skip to content

Commit

Permalink
new feature: finish teaching progress system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiyuan-Yang committed May 15, 2020
1 parent d8bd67b commit d767430
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 7 deletions.
86 changes: 84 additions & 2 deletions app/controllers/classrooms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'date'

class ClassroomsController < ApplicationController
@@dup_class = false
Expand Down Expand Up @@ -111,7 +112,7 @@ def edit
@classroom = Classroom.new
@classroom_id = params[:id]
end

def update
@classroom = params[:classroom]
@classroom_id = params[:id]
Expand Down Expand Up @@ -302,6 +303,59 @@ def exit
def teaching_progress_index
@role = User.find_by(:gitlab_id => current_user.id).role
@classroom_id = params[:id]

@all_task_infos = []

current_time = DateTime.now

TaskPeriod.where(:classroom_id => @classroom_id).each do |item|
task_steps_dict = []
sub_judge = true
sub_use_minus_one = "false"
sub_use_max_plus_one = "false"
TaskStep.order(step_date: :asc).where(:task_period_id => item.id).each do |sub_item|
if sub_judge && sub_item.step_date > current_time
sub_judge = false
if task_steps_dict.length > 0
task_steps_dict[-1][:selected] = "true"
else
sub_use_minus_one = "true"
end
end
task_steps_dict.append(
{
:id => sub_item.id,
:step_date => sub_item.step_date,
:title => sub_item.title,
:description => sub_item.description,
:selected => "false"
}
)
end
if sub_judge
sub_use_max_plus_one = "true"
end
is_selected = "false"
if item.from_date <= current_time && item.to_date >= current_time
is_selected = "true"
end
@all_task_infos.append(
{
:id => item.id,
:title => item.title,
:description => item.description,
:from_date => item.from_date,
:to_date => item.to_date,
:tasksteps => task_steps_dict,
:selected => is_selected,
:sub_use_minus_one => sub_use_minus_one,
:sub_use_max_plus_one => sub_use_max_plus_one
}
)
end
@all_task_infos = @all_task_infos.to_json
# puts '>>>>>>>>'
# puts @all_task_infos
render 'classrooms/teaching_progress_index'
end

Expand All @@ -323,13 +377,41 @@ def create_task_period
task_period.description = period_info["description"]
task_period.classroom_id = period_info["classroom_id"]
task_period.save

# add two end points for each period
task_step_0 = TaskStep.new
task_step_0.step_date = from_date
task_step_0.title = '开始'
task_step_0.description = 'Start of a Period'
task_step_0.task_period_id = task_period.id
task_step_0.save

task_step_1 = TaskStep.new
task_step_1.step_date = to_date
task_step_1.title = '结束'
task_step_1.description = 'End of a Period'
task_step_1.task_period_id = task_period.id
task_step_1.save

@role = User.find_by(:gitlab_id => current_user.id).role
@classroom_id = params[:id]
render 'classrooms/teaching_progress_index'
redirect_to teaching_progress_index_classroom_path
end

def create_task_step
step_info = params["step"]
step_date = params["f"]

task_step_0 = TaskStep.new
task_step_0.step_date = step_date
task_step_0.title = step_info["title"]
task_step_0.description = step_info["description"]
task_step_0.task_period_id = step_info["task_period_id"]
task_step_0.save

@role = User.find_by(:gitlab_id => current_user.id).role
@classroom_id = params[:id]
redirect_to teaching_progress_index_classroom_path
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

<el-form-item label="时间点" prop="step">
<el-date-picker
v-model="stepForm.period"
v-model="stepForm.step"
type="datetime"
placeholder="选择日期时间"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="pickerOptions"
name="step[step]">
name="f">
</el-date-picker>
</el-form-item>

Expand Down Expand Up @@ -92,7 +93,7 @@
{min: 1, max: 10, message: '标题长度在1到10个字符', trigger: 'blur'}
],
description: [
{max: 10, message: '描述长度不得超过50个字符', trigger: 'blur'}
{max: 50, message: '描述长度不得超过50个字符', trigger: 'blur'}
],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<el-collapse v-model="activeNames">
<el-collapse-item v-for="item in taskInfoParsed" :title="item.title" :name="item.id">
<p>{{item.description}}</p>
<el-steps :active="1" finish-status="success">
<el-steps :active="stepActivateIndex[taskInfoParsed.indexOf(item)]" finish-status="success">
<el-step
v-for="subItem in item.tasksteps"
:title="subItem.title"
Expand Down Expand Up @@ -59,6 +59,7 @@
return {
taskInfoParsed: [],
activeNames: [],
stepActivateIndex: []
}
},
components: {
Expand All @@ -67,6 +68,22 @@
},
mounted() {
this.taskInfoParsed = JSON.parse(this.taskinfo);
for (let i = 0; i < this.taskInfoParsed.length; ++i) {
if (this.taskInfoParsed[i]["selected"] === "true") {
this.activeNames.push(this.taskInfoParsed[i]["id"])
}
if (this.taskInfoParsed[i]["sub_use_minus_one"] === true) {
this.stepActivateIndex.push(-1);
} else if (this.taskInfoParsed[i]["sub_use_max_plus_one"] === true) {
this.stepActivateIndex.push(this.taskInfoParsed[i]["tasksteps"].length);
} else {
for (let j = 0; j < this.taskInfoParsed[i]["tasksteps"].length; ++j) {
if (this.taskInfoParsed[i]["tasksteps"][j]["selected"] === "true") {
this.stepActivateIndex.push(j);
}
}
}
}
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/classrooms/teaching_progress_index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
#teaching-progress-index.small-container
.page-title-holder
.page-title 教学进度
%teaching_progress_index_main{:taskinfo => [],
%teaching_progress_index_main{:taskinfo => @all_task_infos,
:role => @role, :classroomid => @classroom_id}

0 comments on commit d767430

Please sign in to comment.