单位批准及消息框架搭建

This commit is contained in:
daiao 2016-07-27 10:46:48 +08:00
parent f35b33b09e
commit 9e788c9b6f
11 changed files with 90 additions and 9 deletions

View File

@ -630,10 +630,14 @@ class AdminController < ApplicationController
end
# 批准未审批的高校
# 消息发送,发送对象为申请人
# status: 0表示未批准 status1表示已批准 status 2表示已拒绝
def approve_applied_schools
@applied_schools = ApplyAddSchools.find params[:id]
unless @applied_schools_schools.nil?
@applied_schools.update_column('status', 1)
applied_school = ApplyAddSchools.find params[:id]
applied_school.update_column('status', 1) unless applied_school.nil?
applied_school.applied_messages << AppliedMessage.new(:user_id => applied_school.user_id, :viewed => false, :status => true)
respond_to do |format|
format.html{ redirect_to unapplied_schools_url }
end
end

View File

@ -0,0 +1,21 @@
class AppliedMessage < ActiveRecord::Base
# status: 0表示未批准 status1表示已批准 status 2表示已拒绝
attr_accessible :applied_id, :applied_type, :status, :user_id, :viewed
belongs_to :applied_message ,:polymorphic => true
belongs_to :apply_add_schools
belongs_to :user
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
validates :user_id,presence: true
validates :applied_id,presence: true
validates :applied_type, presence: true
after_create :add_user_message
# 因为要排序所以需要写入总表
def add_user_message
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id, :viewed => false)
end
end
end

View File

@ -1,5 +1,16 @@
class ApplyAddSchools < ActiveRecord::Base
# status0 未审批 1 已批阅
attr_accessible :address, :city, :name, :province, :remarks, :school_id, :status
has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied_message, :dependent => :destroy
belongs_to :school
after_create :send_massage
#给系统所有管理发送消息
def send_massage
users = User.where(:admin => 1)
users.each do |user|
self.applied_messages << AppliedMessage.new(:user_id => user.id, :viewed => false, :status => false)
end
end
end

View File

@ -45,6 +45,7 @@
</thead>
<tbody>
<% @apply_status.each do |apply| %>
<% if apply.status == 0 %>
<tr class="odd">
<td style="text-align: center;">
<%= apply.id %>
@ -65,12 +66,13 @@
<%= format_date(apply.created_at) %>
</td>
<td class="center">
<%= link_to( "批准", { :controller => 'admin', :action => 'approve_applied_schools', :id => apply.id }, :class => 'icon-del') %>
<%= link_to( "删除", { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id }, :class => 'icon-del') %>
<%= link_to( "更改", { :controller => 'admin', :action => 'edit_applied_schools', :id => apply.id, :name => apply.name }, :class => 'icon-del') %>
<%= link_to( l(:label_approve), { :controller => 'admin', :action => 'approve_applied_schools', :id => apply.id }, :class => 'icon-del') %>
<%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id }, :class => 'icon-del') %>
<%= link_to( l(:button_change), { :controller => 'admin', :action => 'edit_applied_schools', :id => apply.id, :name => apply.name }, :class => 'icon-del') %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>

View File

@ -45,6 +45,7 @@
</thead>
<tbody>
<% @has_apply_status.each do |apply| %>
<% if apply.status == 1 %>
<tr class="odd">
<td style="text-align: center;">
<%= apply.id %>
@ -65,11 +66,12 @@
<%= format_date(apply.created_at) %>
</td>
<td class="center">
<%= link_to( "删除", { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id }, :class => 'icon-del') %>
<%= link_to( "更改", { :controller => 'admin', :action => 'edit_applied_schools', :id => apply.id, :name => apply.name }, :class => 'icon-del') %>
<%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id }, :class => 'icon-del') %>
<%= link_to( l(:button_change), { :controller => 'admin', :action => 'edit_applied_schools', :id => apply.id, :name => apply.name }, :class => 'icon-del') %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>

View File

@ -910,6 +910,7 @@ zh:
button_test: 测试
button_edit: 编辑
button_delete: 删除
button_approve: 批准
button_set_homepage: 设为首页
button_cancel_homepage: 取消首页
button_edit_homepage: 编辑首页

View File

@ -1071,6 +1071,8 @@ RedmineApp::Application.routes.draw do
get 'admin/schools'
get 'admin/applied_schools', as: :unapplied_schools
get 'admin/has_applied_schools', as: :applied_schools
get 'admin/approve_applied_schools'
get 'admin/leave_messages'
match 'admin/messages_list', as: :messages_list
match 'admin/project_messages', as: :project_messages

View File

@ -0,0 +1,13 @@
class CreateAppliedMessages < ActiveRecord::Migration
def change
create_table :applied_messages do |t|
t.integer :user_id
t.integer :applied_id
t.string :applied_type
t.integer :viewed, :default => false
t.integer :status, :default => false
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160725091759) do
ActiveRecord::Schema.define(:version => 20160727020247) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -52,6 +52,16 @@ ActiveRecord::Schema.define(:version => 20160725091759) do
add_index "api_keys", ["access_token"], :name => "index_api_keys_on_access_token"
add_index "api_keys", ["user_id"], :name => "index_api_keys_on_user_id"
create_table "applied_messages", :force => true do |t|
t.integer "user_id"
t.integer "applied_id"
t.string "applied_type"
t.integer "viewed"
t.integer "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "applied_projects", :force => true do |t|
t.integer "project_id", :null => false
t.integer "user_id", :null => false

View File

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :applied_message do
user_id 1
applied_id 1
applied_type "MyString"
viewed 1
status 1
end
end

View File

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