From e8f55523ace887045a6cea34878b9fac492c3d2b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 28 Jun 2019 16:03:56 +0800 Subject: [PATCH 1/2] competition --- app/controllers/competitions_controller.rb | 4 ++-- app/models/competition.rb | 2 +- app/views/managements/_competionList.html.erb | 24 +++++++++++++++---- ...628074837_add_sub_title_to_competitions.rb | 5 ++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190628074837_add_sub_title_to_competitions.rb diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index b43bb5c8..c1d918f6 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -447,7 +447,7 @@ class CompetitionsController < ApplicationController def new_competition if params[:com_name] && params[:com_name].strip != "" visits = rand(400..1000) - Competition.create(:name => params[:com_name], :start_time => params[:start_time], :end_time => params[:end_time], :visits => visits) + Competition.create(:name => params[:com_name], sub_title: params[:sub_title].to_s.strip, :start_time => params[:start_time], :end_time => params[:end_time], :visits => visits) end redirect_to competition_managements_path end @@ -455,7 +455,7 @@ class CompetitionsController < ApplicationController def edit_competition competition = Competition.find params[:id] if params[:com_name] && params[:com_name].strip != "" - competition.update_attributes(:name => params[:com_name], :start_time => params[:start_time], :end_time => params[:end_time]) + competition.update_attributes(:name => params[:com_name], sub_title: params[:sub_title].to_s.strip, :start_time => params[:start_time], :end_time => params[:end_time]) end redirect_to competition_managements_path end diff --git a/app/models/competition.rb b/app/models/competition.rb index 9506b724..2fe1887c 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -2,7 +2,7 @@ class Competition < ActiveRecord::Base # status 0:下架, 1:上架 attr_accessible :end_time, :identifier, :name, :online_time, :start_time, :status, :visits, :competition_lists_count, - :min_num, :max_num, :enroll_end_time + :min_num, :max_num, :enroll_end_time, :sub_title has_many :competition_modules, :dependent => :destroy has_many :competition_stages, :dependent => :destroy diff --git a/app/views/managements/_competionList.html.erb b/app/views/managements/_competionList.html.erb index b37502d1..5a9d8812 100644 --- a/app/views/managements/_competionList.html.erb +++ b/app/views/managements/_competionList.html.erb @@ -3,11 +3,12 @@ - + + - @@ -19,6 +20,10 @@

<%= competition.name %>

+ @@ -101,7 +106,8 @@ function setCompetition() { if($("#addLine").length == 0){ var html = '' + + '' + '' + ' - - + + @@ -25,10 +25,10 @@ ' + '' + - '' + + '' + + '' + '
序号竞赛名称竞赛名称副标题 开始时间 截止时间 竞赛活动图创建时间 + 创建时间 操作
+

<%= competition.sub_title %>

+ +
' + - '' + + '' + '' + @@ -136,7 +142,8 @@ return; } else{ $.post("<%= new_competition_competitions_path %>", - {"com_name": $("#inputTitlevalue").val().trim(), "start_time": $("input[name='start_time']").val().trim(), + {"com_name": $("#inputTitlevalue").val().trim(), "sub_title": $("#inputSubTitlevalue").val().trim() + , "start_time": $("input[name='start_time']").val().trim(), "end_time": $("input[name='end_time']").val().trim()}); } } @@ -158,6 +165,8 @@ var trIndex = $(item).parents("tr"); $(trIndex).find(".editTitlevalue").removeClass("none").focus(); $(trIndex).find(".showTitlevalue").addClass("none"); + $(trIndex).find(".editSubTitlevalue").removeClass("none"); + $(trIndex).find(".showSubTitlevalue").addClass("none"); $(item).hide(); $(item).next().show(); $(item).next().next().show(); @@ -166,6 +175,7 @@ // 保存 function update_competition(id){ var $competition = $("#edit_competition_name_"+id); + var $competitionSubTitle = $("#edit_competition_sub_title_"+id); if($competition.val().trim() == ""){ $competition.focus(); } else { @@ -175,7 +185,11 @@ url: "/competitions/"+id+"/edit_competition", type: "POST", datatype: "script", - data:{com_name: $competition.val().trim(), start_time: start_time, end_time: end_time} + data:{ + com_name: $competition.val().trim(), + sub_title: $competitionSubTitle.val().trim(), + start_time: start_time, end_time: end_time + } }); } } diff --git a/db/migrate/20190628074837_add_sub_title_to_competitions.rb b/db/migrate/20190628074837_add_sub_title_to_competitions.rb new file mode 100644 index 00000000..e3d4bedd --- /dev/null +++ b/db/migrate/20190628074837_add_sub_title_to_competitions.rb @@ -0,0 +1,5 @@ +class AddSubTitleToCompetitions < ActiveRecord::Migration + def change + add_column :competitions, :sub_title, :string + end +end From 0e5ff1cc24e5b80d3ca3315ebd240482aae60200 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 28 Jun 2019 16:20:42 +0800 Subject: [PATCH 2/2] modify competition list style --- app/views/managements/_competionList.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/managements/_competionList.html.erb b/app/views/managements/_competionList.html.erb index 5a9d8812..f2c4921f 100644 --- a/app/views/managements/_competionList.html.erb +++ b/app/views/managements/_competionList.html.erb @@ -5,8 +5,8 @@ 序号 竞赛名称 副标题开始时间截止时间开始时间截止时间 竞赛活动图 创建时间 - + - + <%= file_field_tag 'avatar[image]', @@ -108,8 +108,8 @@ var html = '
' + '' + - '' + '取消' + '保存' +