From 383483de269bdf40c739c9b911a257f6101bc39a Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 28 Jun 2016 15:13:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=A4=A7=E7=BA=B2=E7=9A=84?= =?UTF-8?q?=E5=B7=A6=E4=BE=A7=E6=A0=8Fbase=EF=BC=8C=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=A4=A7=E7=BA=B2=E3=80=81=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 1 + app/controllers/syllabuses_controller.rb | 37 +++- app/controllers/tags_controller.rb | 8 + app/helpers/courses_helper.rb | 16 ++ app/helpers/syllabuses_helper.rb | 3 + app/helpers/tags_helper.rb | 2 + app/models/syllabus.rb | 4 +- app/services/courses_service.rb | 1 + app/views/courses/new.html.erb | 20 ++- app/views/layouts/_syllabus_info.html.erb | 25 +++ app/views/layouts/_user_courses.html.erb | 4 +- app/views/layouts/base_syllabus.html.erb | 158 ++++++++++++++++++ app/views/layouts/new_base.html.erb | 2 +- app/views/layouts/new_base_user.html.erb | 5 +- app/views/syllabuses/new.html.erb | 27 +++ app/views/syllabuses/show.html.erb | 0 app/views/tags/_syllabus_tag.html.erb | 5 + .../tags/_tag_syllabus_new_name.html.erb | 28 ++++ app/views/tags/remove_tag.js.erb | 3 + app/views/tags/tag_save.js.erb | 4 + config/locales/zh.yml | 8 +- config/routes.rb | 12 ++ .../20160627074232_add_column_to_syllabus.rb | 12 ++ db/schema.rb | 26 ++- public/images/syllabus.jpg | Bin 0 -> 16760 bytes public/javascripts/course.js | 40 ++++- public/javascripts/syllabus.js | 9 + public/stylesheets/courses.css | 4 +- public/stylesheets/syllabus.css | 155 +++++++++++++++++ 29 files changed, 599 insertions(+), 20 deletions(-) create mode 100644 app/views/layouts/_syllabus_info.html.erb create mode 100644 app/views/layouts/base_syllabus.html.erb create mode 100644 app/views/syllabuses/new.html.erb create mode 100644 app/views/syllabuses/show.html.erb create mode 100644 app/views/tags/_syllabus_tag.html.erb create mode 100644 app/views/tags/_tag_syllabus_new_name.html.erb create mode 100644 db/migrate/20160627074232_add_column_to_syllabus.rb create mode 100644 public/images/syllabus.jpg create mode 100644 public/javascripts/syllabus.js create mode 100644 public/stylesheets/syllabus.css diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7dea90e4b..e81251f63 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -715,6 +715,7 @@ class CoursesController < ApplicationController @trackers = Tracker.sorted.all @course = Course.new @course.safe_attributes = params[:course] + @syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first if params[:syllabus_id] # month = Time.now.month render :layout => 'new_base' else diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 69982b99a..5ee3224bd 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -8,8 +8,43 @@ class SyllabusesController < ApplicationController end def show - @courses = @syllabus.courses + #@courses = @syllabus.courses + respond_to do |format| + format.js + format.html{render :layout => 'base_syllabus'} + format.api + end + end + def new + if User.current.login? + @syllabus = Syllabus.new + render :layout => 'new_base' + else + redirect_to signin_url + end + end + + def create + if User.current.user_extensions.identity + @syllabus = Syllabus.new + @syllabus.title = params[:title] + @syllabus.eng_name = params[:eng_name] + @syllabus.user_id = User.current.id + if @syllabus && @syllabus.save + respond_to do |format| + flash[:notice] = l(:notice_successful_create) + format.html {redirect_to syllabus_path(@syllabus)} + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'syllabuses', :action => 'show', :id => @syllabus.id) } + end + else + respond_to do |format| + flash[:notice] = l(:notice_create_failed) + format.html { redirect_to new_syllabus_path } #Added by young + format.api { render_validation_errors(@syllabus) } + end + end + end end private diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 2c390025e..e66f88848 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -13,6 +13,7 @@ class TagsController < ApplicationController include ForumsHelper include AttachmentsHelper include ContestsHelper + include SyllabusesHelper include ActsAsTaggableOn::TagsHelper include TagsHelper include FilesHelper @@ -529,6 +530,8 @@ class TagsController < ApplicationController @obj = Course.find_by_id(@obj_id) when '10' @obj = Attachment.find_by_id(@obj_id) + when '11' + @obj = Syllabus.find_by_id(@obj_id) else @obj = nil end @@ -619,6 +622,9 @@ class TagsController < ApplicationController when '9' then @obj = Course.find_by_id(obj_id) @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) + when '11' then + @obj = Syllabus.find_by_id(obj_id) + @obj_pages, @syllabuses_results, @results_count = for_pagination(get_syllabuses_by_tag(selected_tags)) else @obj = nil end @@ -684,6 +690,8 @@ class TagsController < ApplicationController return 'Course' when '10' return 'Attachment' + when '11' + return 'Syllabus' else render_error :message => e.message return diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 47d343e8f..fd3be1369 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -667,6 +667,22 @@ module CoursesHelper is_current_term || is_next_term end + #课程大纲下拉框 + def syllabus_option + type = [] + option1 = [] + option1 << "请选择课程" + option1 << 0 + type << option1 + Syllabus.all.each do |syllabus| + option = [] + option << syllabus.title + option << syllabus.id + type << option + end + type + end + #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index dac84937b..d5284586e 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -1,2 +1,5 @@ module SyllabusesHelper + def get_syllabuses_by_tag(tag_name) + Syllabus.tagged_with(tag_name).order('updated_at desc') + end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 8847f4163..54753807d 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -23,6 +23,8 @@ module TagsHelper @obj= Course.find_by_id(obj_id) when '10' @obj = Attachment.find_by_id(obj_id) + when '11' + @obj = Syllabus.find_by_id(obj_id) else raise Exception, '[TagsHelper] ===> tag type unknow.' end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 7d6319955..b1bdfd5aa 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -1,5 +1,7 @@ class Syllabus < ActiveRecord::Base + acts_as_taggable + belongs_to :user has_many :courses - attr_accessible :description, :title + attr_accessible :description, :title, :eng_name, :type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 60c053997..b7b5e73ac 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -201,6 +201,7 @@ class CoursesService #@course.safe_attributes(current_user,params[:course]) #@course.password = params[:course][:password] @course.tea_id = current_user.id + @course.syllabus_id = params[:syllabus_id].to_i @course.term = params[:term] @course.time = params[:time] @course.end_term = params[:end_term] diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index ddaf17ae8..d3326480f 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -4,12 +4,22 @@
+ +
+
+ 班级 +
+
    +
  • +
      +
    • + <%= link_to "新建班级", new_course_path(:host=> Setting.host_course, :syllabus_id => @syllabus.id), :class => "menuGrey"%> +
    • + +
    • + <%= link_to "加入班级",join_private_courses_courses_path,:remote => true,:class => "menuGrey",:method => "post"%> +
    • +
    +
  • +
+
+
+ + <% courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %> +
+
+
    + <%= render :partial => 'layouts/user_courses', :locals => {:courses => courses,:user => User.current, :page => 0} %> + +
+
+ <% if !courses.empty? %> +
+ +
+ <% end %> +
+
+ +
+

标签:

+
+ <%= render :partial => 'tags/syllabus_tag', :locals => {:obj => @syllabus,:object_flag => "11"}%> +
+
+
+
访问计数 343 (自2016年5月)
+ + +
+ <%= yield %> +
+ + <%= render :partial => 'layouts/new_feedback' %> + +
+<%= render :partial => 'layouts/footer' %> +
+ + + + + + diff --git a/app/views/layouts/new_base.html.erb b/app/views/layouts/new_base.html.erb index e7695f0e7..4922882b9 100644 --- a/app/views/layouts/new_base.html.erb +++ b/app/views/layouts/new_base.html.erb @@ -13,7 +13,7 @@ <%= javascript_heads %> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> - <%= stylesheet_link_tag 'public', 'leftside', 'courses','header','prettify', 'org'%> + <%= stylesheet_link_tag 'public', 'leftside', 'courses','header','prettify', 'org', 'syllabus'%> <%= javascript_include_tag "course","header",'prettify' %> <%= yield :header_tags -%> diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 8455d5693..9c816af7f 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -198,7 +198,10 @@