diff --git a/app/controllers/missions_controller.rb b/app/controllers/missions_controller.rb index f31ad62..8642172 100644 --- a/app/controllers/missions_controller.rb +++ b/app/controllers/missions_controller.rb @@ -57,8 +57,30 @@ class MissionsController < ApplicationController def update #Todo + id = params[:id] body = request.body.read - + mission = Mission.find(id) + mission.name = body[:name] + mission.content = body[:content] + mission.priority = body[:priority] + mission.status = body[:status] + mission.deadline = body[:deadline] + mission.save! + pid = mission.project_id + Mission_user.destory_all(:mission_id => id) + body[:users].each do |i| + uid = User.where(:email => i).id + mu = Mission_user.new + mu.mission_id = id + mu.user_id = uid + mu.save! + note = Note.new + note.project_id = pid + note.user_id = uid + note.type = 3 + note.content = "任务信息发生了变化" + note.save! + end render :json => {:code => 0} end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 5d67830..9219c3b 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -6,7 +6,31 @@ class NotesController < ApplicationController def getNotesList #Todo - + pid = params[:project_id] + uid = session[:user_id] + note = {} + Note.where(:user_id => uid).where(:project_id => pid).each do |i| + date = i.created_at.to_date.to_s + if not note[date] then + note[date] = [] + end + note[:date] += [{ + :content => i.content, + :time => i.created_at.to_time, + :type => i.type + }] + end + data = [] + note.each do |date, list| + data += [{ + :time => date, + :notes => list + }] + end + render :json => { + :code => 0, + :data => data + } end end \ No newline at end of file diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e9c5fdd..b359864 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -8,9 +8,9 @@ class ProjectsController < ApplicationController def index #Todo uid = session[:user_id] - pid = Project_user.find(uid) + pid = Projects_user.find_by(project_id: uid) mc = Mission.where(:project_id => pid).size - uc = Project_user.where(:project_id => pid).size + uc = Projects_user.where(:project_id => pid).size sc = Share.where(:project_id => pid).size data = [] Project.find(pid) do |i| @@ -46,10 +46,19 @@ class ProjectsController < ApplicationController def addUsers #Todo body = request.body.read + uid = body[:user_id].to_i + pid = body[:project_id].to_i pu = Project_user.new() - pu.project_id = body[:project_id] - #pu.user_id = body[:user_id] + pu.project_id = pid + pu.user_id = uid pu.save! + note = Note.new + note.user_id = uid + note.project_id = pid + note.type = 2 + note.content = User.find(uid).name + "邀请您进入项目" + + Project.find(pid).name + note.save! render :json => {:code => 0} end @@ -58,8 +67,8 @@ class ProjectsController < ApplicationController def detail #Todo pid = params[:id] - project = Project.find(pid) - uid = Project_user.where(:project_id => pid) + project = Project.find_by(id: pid) + uid = Projects_user.where(:project_id => pid) users = [] Users.find(uid).each do |i| users += [{ diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb index 644719e..046bcae 100644 --- a/app/controllers/shares_controller.rb +++ b/app/controllers/shares_controller.rb @@ -7,11 +7,22 @@ class SharesController < ApplicationController def create #Todo body = request.body.read + uid = session[:user_id].to_i + pid = body[:project_id].to_i put = Share.new() put.content = body[:content] - put.project_id = body[:project_id] - put.user_id = session[:user_id] + put.project_id = pid + put.user_id = uid put.save! + content = User.find(uid).name + "分享了一些事" + Project_user.where(:project_id => pid).each do |tuid| + note = Note.new + note.user_id = tuid + note.project_id = pid + note.type = 1 + note.content = content + note.save! + end render :json => {:code => 0} end diff --git a/app/models/note.rb b/app/models/note.rb index d6abe22..bd35493 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -4,11 +4,14 @@ class Note < ActiveRecord:: Base validates :content, presence: true validates :user_id, presence: true + validates :project_id, presence: true validates :category, presence: true validate :note_has_atleast_one_character validate :note_category_should_among_valid_values validate :user_exist, on: :create + validate :project_exist, on: :create + private def note_has_atleast_one_character @@ -34,6 +37,14 @@ class Note < ActiveRecord:: Base end end - + + def project_exist + + project = Project.find_by(id: project_id) + if project == nil + errors[:project] = "project should be exist" + end + + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index aceb849..0c11c60 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,4 +62,17 @@ Rails.application.routes.draw do post 'sessions' => 'sessions#create' delete 'session' => 'sessions#destroy' get 'session' => 'sessions#show' + + post 'shares' => 'shares#create' + get 'shares' => 'share#getShareList' + + get 'projects' => 'projects#index' + post 'projects' => 'projects#create' + post 'projects/users' => 'projects#addUsers' + get 'projects/detail' => 'projects#detail' + + get 'missions/project/status' => 'missions#getlist' + get 'missions/detail' => 'missions#detail' + patch 'missions/detail' => 'missions#update' + post 'missions/comments' => 'missions#commentPublish' end diff --git a/db/migrate/20161229080053_add_project_id_to_notes.rb b/db/migrate/20161229080053_add_project_id_to_notes.rb new file mode 100644 index 0000000..c8d5525 --- /dev/null +++ b/db/migrate/20161229080053_add_project_id_to_notes.rb @@ -0,0 +1,5 @@ +class AddProjectIdToNotes < ActiveRecord::Migration + def change + add_column :notes, :project_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 05d6229..42d373a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -45,6 +45,7 @@ ActiveRecord::Schema.define(version: 20161229084919) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "category" + t.integer "project_id" end add_index "notes", ["user_id"], name: "index_notes_on_user_id" diff --git a/db/seeds.rb b/db/seeds.rb index 3f8f98d..c849e66 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,7 +6,8 @@ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) users = [ - {:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"} + {:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"}, + {:name => '陈翊', :password => '123456', :email => '1085730215@qq.com', :phone => '18269771988', :created_at => "2016/12/28", :updated_at => "2016/12/27"} ] users.each do |user| diff --git a/public/index.html b/public/index.html index dc51d5a..031d1e4 100644 --- a/public/index.html +++ b/public/index.html @@ -57,7 +57,7 @@