This commit is contained in:
commit
70630df038
|
@ -61,6 +61,8 @@ simple_intruduce(requires): String, 新闻简介
|
|||
|
||||
remote_url(requires): String, 新闻访问地址
|
||||
|
||||
platform(requires): String, 该条数据的来源{educoder | trusite | ihub | gcc | openi |toschina | military | jiaotong_university}; 如educoder说明是来源educoder平台
|
||||
|
||||
|
||||
返回值
|
||||
```
|
||||
|
|
|
@ -41,6 +41,7 @@ module Mobile
|
|||
requires :title, type: String
|
||||
requires :simple_intruduce, type: String
|
||||
requires :remote_url, type: String, regexp: Home::REG_URL_FORMAT
|
||||
requires :platform, type: String, desc: "platform requires." , values: DynamicNew::PLATFORMS
|
||||
end
|
||||
put 'sync_news' do
|
||||
authenticate_token!
|
||||
|
@ -50,7 +51,8 @@ module Mobile
|
|||
remote_url: params[:remote_url],
|
||||
category_id: params[:category_id],
|
||||
content: params[:content],
|
||||
cover_remote_url: params[:cover_remote_url]
|
||||
cover_remote_url: params[:cover_remote_url],
|
||||
platform: params[:platform]
|
||||
}
|
||||
begin
|
||||
DynamicNewsService.new.sync(news_params)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
class DynamicNewsController < ApplicationController
|
||||
layout 'admin', only: [:new, :index, :destroy]
|
||||
layout 'admin', only: [:new, :destroy, :edit]
|
||||
|
||||
before_filter :require_admin, :only => [:new, :create, :destroy]
|
||||
before_filter :find_dynamic_new, :only => [:show, :destroy]
|
||||
before_filter :require_admin, :except => [:index, :show]
|
||||
before_filter :find_dynamic_new, :only => [:destroy, :edit, :update]
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@category_id = params[:category_id] || 0
|
||||
@dynamic_new = DynamicNew.new
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,6 @@ class DynamicNewsController < ApplicationController
|
|||
tmp_file = params[:cover]
|
||||
@dynamic_new = DynamicNew.new(params[:dynamic_new])
|
||||
begin
|
||||
ActiveRecord::Base.transaction do
|
||||
identity = SecureRandom.uuid
|
||||
unless tmp_file.nil?
|
||||
File.open(Rails.root.join('public', 'images', 'dynamic_new', identity.to_s+'.png'), 'wb') do |file|
|
||||
|
@ -27,9 +26,12 @@ class DynamicNewsController < ApplicationController
|
|||
# TODO: 如下警告信息导致值写不进库
|
||||
# WARNING: Can't mass-assign protected attributes: simple_intruduce,
|
||||
@dynamic_new.simple_intruduce = params[:dynamic_new][:simple_intruduce]
|
||||
@dynamic_new.save
|
||||
end
|
||||
if @dynamic_new.save!
|
||||
redirect_to admin_dynamic_news_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
|
||||
rescue => e
|
||||
logger.info e
|
||||
render 'new'
|
||||
|
@ -41,6 +43,14 @@ class DynamicNewsController < ApplicationController
|
|||
redirect_to admin_dynamic_news_path
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@dynamic_new.update_attributes!(params[:dynamic_new])
|
||||
redirect_to admin_dynamic_news_path
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class DynamicNew < ActiveRecord::Base
|
||||
PLATFORMS = %w(educoder trusite ihub gcc openi toschina military jiaotong_university)
|
||||
belongs_to :category
|
||||
|
||||
validates_presence_of :title, :simple_intruduce, :category_id
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
<%= format_time(dynamic_new.created_at) %>
|
||||
</td>
|
||||
<td class="buttons" style="vertical-align: middle;text-align:center">
|
||||
<%= link_to("修改", upload_logo_school_path(dynamic_new.id,:school_name => @school_name), :class => 'icon icon-copy') %>
|
||||
<%= link_to("修改", edit_dynamic_news_path(dynamic_new), :class => 'icon icon-copy') %>
|
||||
<%= link_to(l(:button_delete), dynamic_news_path(dynamic_new), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -64,12 +64,3 @@
|
|||
<div class="pagination">
|
||||
<%= pagination_links_full @obj_pages, @obj_count ,:per_page_links => true, :remote => true, :flag => true, :is_new => true %>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
function delcfm() {
|
||||
if (!confirm("删除项目会一并删除项目的关联信息,确认要删除吗?")) {
|
||||
window.event.returnValue = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<%= form_for(@dynamic_new, :url=> { :action => params[:action] == 'new'? :create : :update }, :html => {:id =>'system_messages-form',:multipart => true }) do |f| %>
|
||||
<li>
|
||||
<%= image_tag(params[:action] == 'new' ? '' : @dynamic_new.cover_url, id: "avatar_image", :class=>"school_avatar dynamic_new_image" )%>
|
||||
<a type="button" onclick="$('#file').click();" style="margin: 86px 0 0 15px;float: left;padding: 2px 5px;border: 1px solid #eaeaea;cursor: pointer;text-decoration: none;width: 55px;">上传封面</a>
|
||||
<%= file_field_tag 'cover',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
|
||||
<div style="clear: both;"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_category) %> :</label>
|
||||
<%= f.select :category_id, options_for_select(Category.all.collect{|item| [item.name, item.id]}, @category_id), :class => "small" %>
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_title) %> :</label>
|
||||
<input type="text" name="dynamic_new[title]" class="hwork_input_news" id="dynamic_new_title" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="<%= @dynamic_new.title %>">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_summary) %> :</label>
|
||||
<input type="textarea" name="dynamic_new[simple_intruduce]" class="hwork_input_news" id="dynamic_new_simple_introduce" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="<%= @dynamic_new.simple_intruduce %>">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label class="fl" > <span class="c_red"></span> <%= l(:field_content) %> :</label>
|
||||
<%= f.kindeditor :content,:width=>'87.5%',:editor_id=>'dynamic_new_editor' %>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<div>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="actions">
|
||||
<%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "dynamic_new_editor.sync();submit_message($(this));" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<script>
|
||||
function system_message_length() {
|
||||
var obj = dynamic_new_editor.html();
|
||||
if (obj.length > 10000) {
|
||||
$("#content_notice_span").text("内容过长,超过10000个字符");
|
||||
$("#content_notice_span").css('color', '#ff0000');
|
||||
$("#content_notice_span").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#content_notice_span").text("填写正确");
|
||||
$("#content_notice_span").css('color', '#008000');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function regexTitle(obj) {
|
||||
var title = obj.val();
|
||||
if (title.length == 0) {
|
||||
$("#title_notice_span").text("标题不能为空").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else if (title.length > 255) {
|
||||
$("#title_notice_span").text("标题长度过长,不能超过255个字符").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#title_notice_span").text("填写正确").css("color", "#008000");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function submit_message(dom) {
|
||||
if (system_message_length() && regexTitle($("#dynamic_new_title")) && regexTitle($("#dynamic_new_simple_introduce"))) {
|
||||
$("#system_messages-form").submit();
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<script>
|
||||
function showPreview(source) {
|
||||
var file = source.files[0];
|
||||
if (window.FileReader) {
|
||||
var fr = new FileReader();
|
||||
fr.onloadend = function (e) {
|
||||
document.getElementById("avatar_image").src = e.target.result;
|
||||
};
|
||||
fr.readAsDataURL(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<%= content_for(:header_tags) do %>
|
||||
<%= import_ke(enable_at: false) %>
|
||||
<% end %>
|
||||
<h3 style="float: left">
|
||||
<%=l(:label_new_dynamic_new)%>
|
||||
</h3><br/>
|
||||
<div style="padding-top: 20px; padding-left: 5px;">
|
||||
<%= error_messages_for 'dynamic_new' %>
|
||||
<%= render 'form' %>
|
||||
</div>
|
|
@ -18,70 +18,5 @@
|
|||
<%=l(:label_new_dynamic_new)%>
|
||||
</h3><br/>
|
||||
<div style="padding-top: 20px; padding-left: 5px;">
|
||||
<%= form_for(@dynamic_new, :url=> { :action => :create }, :html => {:id =>'system_messages-form',:multipart => true }) do |f| %>
|
||||
<li>
|
||||
<input type="hidden" value="<%= @school_name%>" name="school_name">
|
||||
<%= image_tag('', id: "avatar_image", :class=>"school_avatar dynamic_new_image" )%>
|
||||
<a type="button" onclick="$('#file').click();" style="margin: 86px 0 0 15px;float: left;padding: 2px 5px;border: 1px solid #eaeaea;cursor: pointer;text-decoration: none;width: 55px;">上传图片</a>
|
||||
<%= file_field_tag 'cover',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
|
||||
<div style="clear: both;"></div>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_title) %> :</label>
|
||||
<input type="text" name="dynamic_new[title]" class="hwork_input_news" id="system_message_subject" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_summary) %> :</label>
|
||||
<input type="textarea" name="dynamic_new[simple_intruduce]" class="hwork_input_news" id="system_message_subject" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label class="fl" > <span class="c_red"></span> <%= l(:field_content) %> :</label>
|
||||
<%= f.kindeditor :content,:width=>'87.5%',:editor_id=>'system_message_editor' %>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<div>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
<%= render 'form' %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="actions">
|
||||
<%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "system_message_editor.sync();submit_message($(this));" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<script>
|
||||
function system_message_length() {
|
||||
var obj = system_message_editor.html();
|
||||
if (obj.length > 10000) {
|
||||
$("#content_notice_span").text("内容过长,超过10000个字符");
|
||||
$("#content_notice_span").css('color', '#ff0000');
|
||||
$("#content_notice_span").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#content_notice_span").text("填写正确");
|
||||
$("#content_notice_span").css('color', '#008000');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function regexTitle(obj) {
|
||||
var title = obj.val();
|
||||
if (title.length == 0) {
|
||||
$("#title_notice_span").text("标题不能为空").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else if (title.length > 255) {
|
||||
$("#title_notice_span").text("标题长度过长,不能超过255个字符").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#title_notice_span").text("填写正确").css("color", "#008000");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function submit_message(dom) {
|
||||
|
||||
if (system_message_length() && regexTitle($("#system_message_subject"))) {
|
||||
$("#system_messages-form").submit();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddPlatformToDynamicNews < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :dynamic_news, :platform, :string
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20191021063319) do
|
||||
ActiveRecord::Schema.define(:version => 20191022031808) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -958,6 +958,7 @@ ActiveRecord::Schema.define(:version => 20191021063319) do
|
|||
t.datetime "updated_at", :null => false
|
||||
t.string "simple_intruduce"
|
||||
t.integer "category_id", :null => false
|
||||
t.string "platform"
|
||||
end
|
||||
|
||||
add_index "dynamic_news", ["title"], :name => "index_dynamic_news_on_title"
|
||||
|
|
Loading…
Reference in New Issue