From 66251c8d30b70f2cff928a19ed2420271f531053 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 9 Sep 2015 17:05:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E7=95=8C=E9=9D=A2=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/system_messages.js.coffee | 3 + .../stylesheets/system_messages.css.scss | 3 + app/controllers/admin_controller.rb | 5 ++ app/controllers/system_messages_controller.rb | 83 +++++++++++++++++++ app/helpers/system_messages_helper.rb | 2 + app/models/system_message.rb | 4 + app/models/user.rb | 1 + app/views/admin/messages.html.erb | 14 ++++ app/views/system_messages/index.html.erb | 3 + config/locales/admins/en.yml | 2 + config/locales/admins/zh.yml | 2 + config/locales/zh.yml | 2 + config/routes.rb | 11 +++ .../20150909062619_create_system_messages.rb | 11 +++ db/schema.rb | 9 +- lib/redmine.rb | 1 + .../system_messages_controller_spec.rb | 5 ++ spec/factories/system_messages.rb | 8 ++ spec/models/system_message_spec.rb | 5 ++ 19 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/system_messages.js.coffee create mode 100644 app/assets/stylesheets/system_messages.css.scss create mode 100644 app/controllers/system_messages_controller.rb create mode 100644 app/helpers/system_messages_helper.rb create mode 100644 app/models/system_message.rb create mode 100644 app/views/admin/messages.html.erb create mode 100644 app/views/system_messages/index.html.erb create mode 100644 db/migrate/20150909062619_create_system_messages.rb create mode 100644 spec/controllers/system_messages_controller_spec.rb create mode 100644 spec/factories/system_messages.rb create mode 100644 spec/models/system_message_spec.rb diff --git a/app/assets/javascripts/system_messages.js.coffee b/app/assets/javascripts/system_messages.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/system_messages.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/system_messages.css.scss b/app/assets/stylesheets/system_messages.css.scss new file mode 100644 index 000000000..a9947d45a --- /dev/null +++ b/app/assets/stylesheets/system_messages.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the SystemMessages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 1624008f2..5666934b6 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -79,6 +79,11 @@ class AdminController < ApplicationController end end + # 系统消息 + def messages + @admin_messages = SystemMessage.new + end + def plugins @plugins = Redmine::Plugin.all end diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb new file mode 100644 index 000000000..21b9ae9b8 --- /dev/null +++ b/app/controllers/system_messages_controller.rb @@ -0,0 +1,83 @@ +class SystemMessagesController < ApplicationController + # before_filter :message_author, :only => [:show] + # + # def message_author + # if(!User.current.logged? && !token.nil?) + # + # User.current =try_to_autologin1 + # end + # if @system_messages + # render_403 :message => :notice_not_authorized_message + # else + # deny_access + # end + # end + + def index + @system_messages = SystemMessage.all + end + + # def show + # @system_messages = SystemMessage.find(params[:id]) + # end + + # GET /products/new + # def new + # @product = Product.new + # end + + # GET /products/1/edit + # def edit + # end + + # POST /products + # POST /products.json + def create + @system_messages = SystemMessage.new + @system_messages.content = params[:system_message][:content] + @system_messages.user_id = User.current.id + respond_to do |format| + if @system_messages.save + format.html {redirect_to system_messages_url(@project)} + flash[:notice] = l(:notice_successful_message) + end + end + end + + # PATCH/PUT /products/1 + # PATCH/PUT /products/1.json + # def update + # respond_to do |format| + # if @product.update(product_params) + # format.html { redirect_to @product, notice: 'Product was successfully updated.' } + # format.json { render :show, status: :ok, location: @product } + # else + # format.html { render :edit } + # format.json { render json: @product.errors, status: :unprocessable_entity } + # end + # end + # end + + # DELETE /products/1 + # DELETE /products/1.json + # def destroy + # @system_messages.destroy + # respond_to do |format| + # format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' } + # format.json { head :no_content } + # end + # end + + # private + # # Use callbacks to share common setup or constraints between actions. + # def set_product + # @product = Product.find(params[:id]) + # end + # + # # Never trust parameters from the scary internet, only allow the white list through. + # def message_params + # params.require(:admin_system_messages).permit(:content) + # end + + +end diff --git a/app/helpers/system_messages_helper.rb b/app/helpers/system_messages_helper.rb new file mode 100644 index 000000000..fef238676 --- /dev/null +++ b/app/helpers/system_messages_helper.rb @@ -0,0 +1,2 @@ +module SystemMessagesHelper +end diff --git a/app/models/system_message.rb b/app/models/system_message.rb new file mode 100644 index 000000000..4802ba252 --- /dev/null +++ b/app/models/system_message.rb @@ -0,0 +1,4 @@ +class SystemMessage < ActiveRecord::Base + attr_accessible :content, :id, :user_id + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 2ccc41783..8b5951687 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,6 +133,7 @@ class User < Principal has_many :memo_messages has_many :user_feedback_messages has_one :onclick_time + has_many :system_messages # 虚拟转换 has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb new file mode 100644 index 000000000..9d312c7e7 --- /dev/null +++ b/app/views/admin/messages.html.erb @@ -0,0 +1,14 @@ +

+ <%=l(:label_system_message)%> +


+
+ <%= form_for(@admin_messages) do |f| %> +
+ <%= f.text_area :content %> +
+
+ <%= f.submit l(:label_submit),:class => "small" %> +
+ <% end %> +
+ diff --git a/app/views/system_messages/index.html.erb b/app/views/system_messages/index.html.erb new file mode 100644 index 000000000..4ed40757b --- /dev/null +++ b/app/views/system_messages/index.html.erb @@ -0,0 +1,3 @@ +<% @system_messages.each do |sm| %> + +<% end %> diff --git a/config/locales/admins/en.yml b/config/locales/admins/en.yml index 479d2f0f0..ed23107cb 100644 --- a/config/locales/admins/en.yml +++ b/config/locales/admins/en.yml @@ -11,3 +11,5 @@ en: label_registration_activation_by_email: account activation by email label_registration_manual_activation: manual account activation label_registration_automatic_activation: automatic account activation + + label_system_message: system messages diff --git a/config/locales/admins/zh.yml b/config/locales/admins/zh.yml index 936b3109f..49abcfc8d 100644 --- a/config/locales/admins/zh.yml +++ b/config/locales/admins/zh.yml @@ -14,3 +14,5 @@ zh: label_registration_manual_activation: 手动激活帐号 label_registration_automatic_activation: 自动激活帐号 + label_system_message: 系统消息 + diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 4a6ddce4e..d2fa502b9 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -36,6 +36,7 @@ zh: notice_create_failed: 创建失败,请先完善个人信息 notice_failed_create: 创建失败 notice_successful_update: 更新成功 + notice_successful_message: 消息创建成功! notice_successful_edit: 修改成功 notice_failed_edit: 修改失败 notice_successful_delete: 删除成功 @@ -49,6 +50,7 @@ zh: notice_not_contest_setting_authorized: 对不起,您无权配置此竞赛。 notice_not_contest_delete_authorized: 对不起,您无权删除此竞赛。 notice_not_authorized_archived_project: 要访问的项目已经归档。 + notice_not_authorized_message: 您访问的消息不存在! notice_email_sent: "邮件已发送至 %{value}" notice_email_error: "发送邮件时发生错误 (%{value})" notice_feeds_access_key_reseted: 您的RSS存取键已被重置。 diff --git a/config/routes.rb b/config/routes.rb index 8454a1c47..2a0e1a492 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -260,6 +260,16 @@ RedmineApp::Application.routes.draw do match '/users/search', :via => [:get, :post] #end + # 消息相关路由 + resources :system_messages do + collection do + post 'create', :as => 'system_messages' + get 'index', :as => 'index' + get 'show', :as => 'show' + end + end + # match 'system_messages/index', to: 'system_messages#index', :via => :get, :as => 'system_messages' + match 'account/heartbeat', to: 'account#heartbeat', :via => :get match 'login', :to => 'account#login', :as => 'signin', :via => [:get, :post] match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post] @@ -702,6 +712,7 @@ RedmineApp::Application.routes.draw do match 'admin/projects', :via => :get get 'admin/courses' match 'admin/users', :via => :get + match 'admin/messages', :via => :get match 'admin/first_page_made', as: :first_page_made match 'admin/course_page_made', as: :course_page_made match 'admin/contest_page_made', as: :contest_page_made diff --git a/db/migrate/20150909062619_create_system_messages.rb b/db/migrate/20150909062619_create_system_messages.rb new file mode 100644 index 000000000..a51715ead --- /dev/null +++ b/db/migrate/20150909062619_create_system_messages.rb @@ -0,0 +1,11 @@ +class CreateSystemMessages < ActiveRecord::Migration + def change + create_table :system_messages do |t| + t.integer :id + t.integer :user_id + t.string :content + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e44bdd1d9..71d521453 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150906083453) do +ActiveRecord::Schema.define(:version => 20150909062619) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1357,6 +1357,13 @@ ActiveRecord::Schema.define(:version => 20150906083453) do add_index "students_for_courses", ["course_id"], :name => "index_students_for_courses_on_course_id" add_index "students_for_courses", ["student_id"], :name => "index_students_for_courses_on_student_id" + create_table "system_messages", :force => true do |t| + t.integer "user_id" + t.string "content" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "taggings", :force => true do |t| t.integer "tag_id" t.integer "taggable_id" diff --git a/lib/redmine.rb b/lib/redmine.rb index 99b7ea22f..8ebdacfa6 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -369,6 +369,7 @@ Redmine::MenuManager.map :admin_menu do |menu| menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural menu.push :courses, {:controller => 'admin', :action => 'courses'}, :caption => :label_course_all menu.push :users, {:controller => 'admin', :action => 'users'}, :caption => :label_user_plural + menu.push :messages, {:controller => 'admin', :action => 'messages'}, :caption => :label_system_message menu.push :schools, {:controller => 'admin', :action => 'schools'}, :caption => :label_school_plural menu.push :first_page_made, {:controller => 'admin',:action => 'first_page_made'},:caption => :label_first_page_made menu.push :mobile_version, {:controller => 'admin',:action => 'mobile_version'},:caption => :label_mobile_version diff --git a/spec/controllers/system_messages_controller_spec.rb b/spec/controllers/system_messages_controller_spec.rb new file mode 100644 index 000000000..c65f5b5e0 --- /dev/null +++ b/spec/controllers/system_messages_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SystemMessagesController, :type => :controller do + +end diff --git a/spec/factories/system_messages.rb b/spec/factories/system_messages.rb new file mode 100644 index 000000000..7bcc27422 --- /dev/null +++ b/spec/factories/system_messages.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :system_message do + id 1 +user_id 1 +content "MyString" + end + +end diff --git a/spec/models/system_message_spec.rb b/spec/models/system_message_spec.rb new file mode 100644 index 000000000..fd8df4e92 --- /dev/null +++ b/spec/models/system_message_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SystemMessage, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end