diff --git a/app/assets/javascripts/apply_project_masters.js b/app/assets/javascripts/apply_project_masters.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/apply_project_masters.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/no_uses.js b/app/assets/javascripts/no_uses.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/no_uses.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/apply_project_masters.css b/app/assets/stylesheets/apply_project_masters.css new file mode 100644 index 000000000..afad32db0 --- /dev/null +++ b/app/assets/stylesheets/apply_project_masters.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/no_uses.css b/app/assets/stylesheets/no_uses.css new file mode 100644 index 000000000..afad32db0 --- /dev/null +++ b/app/assets/stylesheets/no_uses.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/apply_project_masters_controller.rb b/app/controllers/apply_project_masters_controller.rb new file mode 100644 index 000000000..7dadaf2ed --- /dev/null +++ b/app/controllers/apply_project_masters_controller.rb @@ -0,0 +1,83 @@ +class ApplyProjectMastersController < ApplicationController + # GET /apply_project_masters + # GET /apply_project_masters.json + def index + @apply_project_masters = ApplyProjectMaster.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @apply_project_masters } + end + end + + # GET /apply_project_masters/1 + # GET /apply_project_masters/1.json + def show + @apply_project_master = ApplyProjectMaster.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @apply_project_master } + end + end + + # GET /apply_project_masters/new + # GET /apply_project_masters/new.json + def new + @apply_project_master = ApplyProjectMaster.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @apply_project_master } + end + end + + # GET /apply_project_masters/1/edit + def edit + @apply_project_master = ApplyProjectMaster.find(params[:id]) + end + + # POST /apply_project_masters + # POST /apply_project_masters.json + def create + @apply_project_master = ApplyProjectMaster.new(params[:apply_project_master]) + + respond_to do |format| + if @apply_project_master.save + format.html { redirect_to @apply_project_master, notice: 'Apply project master was successfully created.' } + format.json { render json: @apply_project_master, status: :created, location: @apply_project_master } + else + format.html { render action: "new" } + format.json { render json: @apply_project_master.errors, status: :unprocessable_entity } + end + end + end + + # PUT /apply_project_masters/1 + # PUT /apply_project_masters/1.json + def update + @apply_project_master = ApplyProjectMaster.find(params[:id]) + + respond_to do |format| + if @apply_project_master.update_attributes(params[:apply_project_master]) + format.html { redirect_to @apply_project_master, notice: 'Apply project master was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @apply_project_master.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /apply_project_masters/1 + # DELETE /apply_project_masters/1.json + def destroy + @apply_project_master = ApplyProjectMaster.find(params[:id]) + @apply_project_master.destroy + + respond_to do |format| + format.html { redirect_to apply_project_masters_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/no_uses_controller.rb b/app/controllers/no_uses_controller.rb new file mode 100644 index 000000000..c18c6c3b6 --- /dev/null +++ b/app/controllers/no_uses_controller.rb @@ -0,0 +1,123 @@ +class NoUsesController < ApplicationController + # GET /no_uses + # GET /no_uses.json + def index + @no_uses = NoUse.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @no_uses } + end + end + + # GET /no_uses/1 + # GET /no_uses/1.json + def show + @no_use = NoUse.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @no_use } + end + end + + # GET /no_uses/new + # GET /no_uses/new.json + def new + @no_use = NoUse.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @no_use } + end + end + + # GET /no_uses/1/edit + def edit + @no_use = NoUse.find(params[:id]) + end + + # POST /no_uses + # POST /no_uses.json + def create + @no_use = NoUse.new(params[:no_use]) + + respond_to do |format| + if @no_use.save + format.html { redirect_to @no_use, notice: 'No use was successfully created.' } + format.json { render json: @no_use, status: :created, location: @no_use } + else + format.html { render action: "new" } + format.json { render json: @no_use.errors, status: :unprocessable_entity } + end + end + end + + # PUT /no_uses/1 + # PUT /no_uses/1.json + def update + @no_use = NoUse.find(params[:id]) + + respond_to do |format| + if @no_use.update_attributes(params[:no_use]) + format.html { redirect_to @no_use, notice: 'No use was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @no_use.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /no_uses/1 + # DELETE /no_uses/1.json + def destroy + @no_use = NoUse.find(params[:id]) + @no_use.destroy + + respond_to do |format| + format.html { redirect_to no_uses_url } + format.json { head :no_content } + end + end + private + + def find_no_use + klass = Object.const_get(params[:object_type].camelcase) rescue nil + if klass && klass.respond_to?('watched_by') + @no_use = klass.find_all_by_id(Array.wrap(params[:object_id])) + end + render_404 unless @no_use.present? + end + + def set_watcher(watchables, user, watching) + watchables.each do |watchable| + watchable.set_watcher(user, watching) + # @user = watchable # added by william + if watching + # 修改 user和project的状态 + if watchable.instance_of?(User) + #写user_statuses表 + UserStatus.find_by_user_id(watchable.id).update_watchers_count(1) + elsif watchable.instance_of?(Project) + #写project_statuese表 + ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(1) + end + else + # 修改 user和project的状态 + if watchable.instance_of?(User) + #写user_statuses表 + UserStatus.find_by_user_id(watchable.id).update_watchers_count(-1) + elsif watchable.instance_of?(Project) + #写project_statuese表 :project_status + ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(-1) + end + end + + end + respond_to do |format| + format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} + format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} } + end + end +end diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index f7f32a43b..55892d457 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -2,6 +2,10 @@ class OpenSourceProjectsController < ApplicationController helper :sort include SortHelper + helper :apply_project_masters + include ApplyProjectMastersHelper + helper :no_uses + include NoUsesHelper # GET /open_source_projects # GET /open_source_projects.json def index diff --git a/app/helpers/apply_project_masters_helper.rb b/app/helpers/apply_project_masters_helper.rb new file mode 100644 index 000000000..11724cde0 --- /dev/null +++ b/app/helpers/apply_project_masters_helper.rb @@ -0,0 +1,23 @@ +module ApplyProjectMastersHelper + def apply_super_user(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + applied = objects.any? {|object| object.applied_by?(user)} + allowed = objects.any? {|object| object.allowed?(user)} + # @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid))) + # css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + # ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = applied ? (allowed ? ("123") : ("123")) : ("231") + + url = apply_project_master_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = applied ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method + #, :class => css + end +end diff --git a/app/helpers/no_uses_helper.rb b/app/helpers/no_uses_helper.rb new file mode 100644 index 000000000..2c7c268fc --- /dev/null +++ b/app/helpers/no_uses_helper.rb @@ -0,0 +1,22 @@ +module NoUsesHelper + def no_use_link(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + clicked = objects.any? {|object| object.no_use_for?(user)} + # @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid))) + # css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + # ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = clicked ? ("123") : ("231") + + url = apply_project_master_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = clicked ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method + #, :class => css + end +end diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb index f6735688b..793e1458e 100644 --- a/app/helpers/open_source_projects_helper.rb +++ b/app/helpers/open_source_projects_helper.rb @@ -11,4 +11,5 @@ module OpenSourceProjectsHelper end s << "" end + end diff --git a/app/models/apply_project_master.rb b/app/models/apply_project_master.rb new file mode 100644 index 000000000..336c102df --- /dev/null +++ b/app/models/apply_project_master.rb @@ -0,0 +1,3 @@ +class ApplyProjectMaster < ActiveRecord::Base + # attr_accessible :title, :body +end diff --git a/app/models/no_use.rb b/app/models/no_use.rb new file mode 100644 index 000000000..333174a8d --- /dev/null +++ b/app/models/no_use.rb @@ -0,0 +1,3 @@ +class NoUse < ActiveRecord::Base + # attr_accessible :title, :body +end diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index f6ec5a8ce..57bcfeabc 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -11,6 +11,14 @@ class OpenSourceProject < ActiveRecord::Base description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end + def applied_by?(user) + false + end + + def allowed?(user) + false + end + def reset_counters! self.class.reset_counters!(id) end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index 060312f86..cd2d0e8a6 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -69,6 +69,16 @@ class RelativeMemo < ActiveRecord::Base # Forum.reset_counters!(forum_id) # end # end + + + scope :no_use_for, lambda { |user_id| + { :include => :no_uses, + :conditions => ["#{NoUse.table_name}.user_id = ?", user_id] } + } + + def no_use_for?(user) + false + end def reset_counters! if parent && parent.id diff --git a/app/views/apply_project_masters/_form.html.erb b/app/views/apply_project_masters/_form.html.erb new file mode 100644 index 000000000..f817c1bcf --- /dev/null +++ b/app/views/apply_project_masters/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@apply_project_master) do |f| %> + <% if @apply_project_master.errors.any? %> +
+ | + | + |
---|---|---|
<%= link_to 'Show', apply_project_master %> | +<%= link_to 'Edit', edit_apply_project_master_path(apply_project_master) %> | +<%= link_to 'Destroy', apply_project_master, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ + +<%= link_to 'Edit', edit_apply_project_master_path(@apply_project_master) %> | +<%= link_to 'Back', apply_project_masters_path %> diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index df05d4f75..b982a3a19 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -54,6 +54,7 @@+ | + | + |
---|---|---|
<%= link_to 'Show', no_use %> | +<%= link_to 'Edit', edit_no_use_path(no_use) %> | +<%= link_to 'Destroy', no_use, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ + +<%= link_to 'Edit', edit_no_use_path(@no_use) %> | +<%= link_to 'Back', no_uses_path %> diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb index 172949e92..f4400ed39 100644 --- a/app/views/open_source_projects/_show_topics.html.erb +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -33,18 +33,18 @@