competitions
cxt 5 years ago
parent c337d36794
commit acd5c28bb1

@ -11,6 +11,7 @@ class Admins::CompetitionsController < Admins::BaseController
ids = @competitions.map(&:id)
@member_count_map = TeamMember.where(competition_id: ids).group(:competition_id).count
@competition_hot = ModuleSetting.exists?(module_type: "Competition", property: "hot")
respond_to do |format|
format.js
format.html

@ -142,6 +142,14 @@ module ApplicationHelper
end
end
# 主页banner图
def banner_img(source_type)
if File.exist?(disk_filename(source_type, "banner"))
ctime = File.ctime(disk_filename(source_type, "banner")).to_i
File.join("images/avatars", ["#{source_type}", "banner"]) + "?t=#{ctime}"
end
end
def disk_filename(source_type,source_id,image_file=nil)
File.join(storage_path, "#{source_type}", "#{source_id}")
end

@ -0,0 +1,2 @@
class ModuleSetting < ApplicationRecord
end

@ -5,5 +5,12 @@
end
%>
<div class="card mb-5">
<div class="card-header d-flex justify-content-between align-items-center">
<span class="flex-1">基础设置</span>
</div>
<div class="card-body row">
</div>
</div>

@ -2,6 +2,25 @@
<% add_admin_breadcrumb('竞赛列表', admins_competitions_path) %>
<% end %>
<div class="box mb-5">
<div class="d-flex flex-column w-100">
<div class="d-flex">
<% imageExists = File.exist?(disk_filename("Competition", "banner")) %>
<% imageUrl = imageExists ? '/' + banner_img("Competition") + "?#{Time.now.to_i}" : '' %>
<span class="mr-3">竞赛主页banner</span>
<%= image_tag(imageUrl, width: 150, height: 50, class: "preview-image competition-image-banner mr-1", data: { toggle: 'tooltip', title: '点击预览' }) %>
<%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-competition-image-action', data: { source_id: "banner", source_type: 'Competition', toggle: 'modal', target: '.admin-upload-file-modal' } %>
</div>
<div class="d-flex">
<label for="hot">
<%= check_box_tag :hot, (@competition_hot ? "1" : "0"), @competition_hot, class:"shixun-settings-select" %>
<span class="only_view">只看可ssh</span>
</label>
</div>
</div>
</div>
<div class="box competitions-list-container">
<%= render partial: 'admins/competitions/shared/list', locals: { competitions: @competitions } %>
</div>

@ -7,7 +7,7 @@
<td><%= @member_count_map&.fetch(competition.id, 0) || competition.team_members.count %></td>
<td><%= competition.teacher_staff_num %></td>
<td><%= competition.member_staff_num %></td>
<td class="shixun-setting-image">
<td class="competition-setting-image">
<% imageExists = File.exist?(disk_filename("Competition", competition.id)) %>
<% imageUrl = imageExists ? '/' + url_to_avatar(competition) + "?#{Time.now.to_i}" : '' %>
<%= image_tag(imageUrl, width: 60, height: 40, class: "preview-image competition-image-#{competition.id}", data: { toggle: 'tooltip', title: '点击预览' }, style: imageExists ? '' : 'display:none') %>

@ -0,0 +1,12 @@
class CreateModuleSettings < ActiveRecord::Migration[5.2]
def change
create_table :module_settings do |t|
t.string :module_type
t.string :property
t.timestamps
end
add_index :module_settings, :module_type
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ModuleSetting, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save