From d935152ed735ee531e060fd45d697cb237855aeb Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Sat, 29 Mar 2014 10:57:36 +0800 Subject: [PATCH 01/24] initial crawl --- .../javascripts/open_source_projects.js | 2 + .../stylesheets/open_source_projects.css | 4 + .../open_source_projects_controller.rb | 96 +++++++++++++ app/helpers/open_source_projects_helper.rb | 14 ++ app/models/open_source_project.rb | 6 + app/views/layouts/base_opensource_p.html.erb | 130 ++++++++++++++++++ app/views/open_source_projects/_form.html.erb | 21 +++ .../open_source_projects/_os_project.html.erb | 56 ++++++++ app/views/open_source_projects/edit.html.erb | 6 + app/views/open_source_projects/index.html.erb | 45 ++++++ app/views/open_source_projects/new.html.erb | 5 + app/views/open_source_projects/show.html.erb | 10 ++ config/routes.rb | 7 + ...40324015819_create_open_source_projects.rb | 15 ++ db/schema.rb | 15 +- test/fixtures/activities.yml | 11 ++ test/fixtures/forums.yml | 11 ++ test/fixtures/journal_replies.yml | 11 ++ test/fixtures/open_source_projects.yml | 7 + test/functional/forums_controller_test.rb | 49 +++++++ .../open_source_projects_controller_test.rb | 49 +++++++ test/unit/activity_test.rb | 7 + test/unit/forum_test.rb | 7 + test/unit/helpers/forums_helper_test.rb | 4 + .../open_source_projects_helper_test.rb | 4 + test/unit/journal_reply_test.rb | 7 + test/unit/open_source_project_test.rb | 7 + 27 files changed, 605 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/open_source_projects.js create mode 100644 app/assets/stylesheets/open_source_projects.css create mode 100644 app/controllers/open_source_projects_controller.rb create mode 100644 app/helpers/open_source_projects_helper.rb create mode 100644 app/models/open_source_project.rb create mode 100644 app/views/layouts/base_opensource_p.html.erb create mode 100644 app/views/open_source_projects/_form.html.erb create mode 100644 app/views/open_source_projects/_os_project.html.erb create mode 100644 app/views/open_source_projects/edit.html.erb create mode 100644 app/views/open_source_projects/index.html.erb create mode 100644 app/views/open_source_projects/new.html.erb create mode 100644 app/views/open_source_projects/show.html.erb create mode 100644 db/migrate/20140324015819_create_open_source_projects.rb create mode 100644 test/fixtures/activities.yml create mode 100644 test/fixtures/forums.yml create mode 100644 test/fixtures/journal_replies.yml create mode 100644 test/fixtures/open_source_projects.yml create mode 100644 test/functional/forums_controller_test.rb create mode 100644 test/functional/open_source_projects_controller_test.rb create mode 100644 test/unit/activity_test.rb create mode 100644 test/unit/forum_test.rb create mode 100644 test/unit/helpers/forums_helper_test.rb create mode 100644 test/unit/helpers/open_source_projects_helper_test.rb create mode 100644 test/unit/journal_reply_test.rb create mode 100644 test/unit/open_source_project_test.rb diff --git a/app/assets/javascripts/open_source_projects.js b/app/assets/javascripts/open_source_projects.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/open_source_projects.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/open_source_projects.css b/app/assets/stylesheets/open_source_projects.css new file mode 100644 index 000000000..afad32db0 --- /dev/null +++ b/app/assets/stylesheets/open_source_projects.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/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb new file mode 100644 index 000000000..41df7c409 --- /dev/null +++ b/app/controllers/open_source_projects_controller.rb @@ -0,0 +1,96 @@ +class OpenSourceProjectsController < ApplicationController + # GET /open_source_projects + # GET /open_source_projects.json + def index + per_page_option = 10 + + @open_source_projects = OpenSourceProject.all + + @os_project_count = @open_source_projects.count + @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] + + @open_source_projects = OpenSourceProject.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @open_source_projects } + end + end + + # GET /open_source_projects/1 + # GET /open_source_projects/1.json + def show + @open_source_project = OpenSourceProject.find(params[:id]) + + respond_to do |format| + format.html { + render :layout => "base_opensource_p" + } + format.json { render json: @open_source_project } + end + end + + def search + + end + + # GET /open_source_projects/new + # GET /open_source_projects/new.json + def new + @open_source_project = OpenSourceProject.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @open_source_project } + end + end + + # GET /open_source_projects/1/edit + def edit + @open_source_project = OpenSourceProject.find(params[:id]) + end + + # POST /open_source_projects + # POST /open_source_projects.json + def create + @open_source_project = OpenSourceProject.new(params[:open_source_project]) + + respond_to do |format| + if @open_source_project.save + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.' } + format.json { render json: @open_source_project, status: :created, location: @open_source_project } + else + format.html { render action: "new" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # PUT /open_source_projects/1 + # PUT /open_source_projects/1.json + def update + @open_source_project = OpenSourceProject.find(params[:id]) + + respond_to do |format| + if @open_source_project.update_attributes(params[:open_source_project]) + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /open_source_projects/1 + # DELETE /open_source_projects/1.json + def destroy + @open_source_project = OpenSourceProject.find(params[:id]) + @open_source_project.destroy + + respond_to do |format| + format.html { redirect_to open_source_projects_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb new file mode 100644 index 000000000..f6735688b --- /dev/null +++ b/app/helpers/open_source_projects_helper.rb @@ -0,0 +1,14 @@ +module OpenSourceProjectsHelper + def render_opensource_project(os_projects) + s='' + s << "" + end +end diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb new file mode 100644 index 000000000..61b734f25 --- /dev/null +++ b/app/models/open_source_project.rb @@ -0,0 +1,6 @@ +class OpenSourceProject < ActiveRecord::Base + attr_accessible :String + def short_description(length = 255) + description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + end +end diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb new file mode 100644 index 000000000..64232ff9c --- /dev/null +++ b/app/views/layouts/base_opensource_p.html.erb @@ -0,0 +1,130 @@ +<% @nav_dispaly_project_label = 1 %> + + + + + <%= h html_title %> + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %> + <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> + <%= javascript_heads %> + <%= heads_for_theme %> + <%= call_hook :view_layouts_base_html_head %> + + <%= yield :header_tags -%> + + + +
+
+
+ <%= render :partial => 'layouts/base_header'%> +
+
+ + + + + + + +
软件项目托管社区<%= l(:label_user_location) %> : +
+
+ + +
+
+ +
+ <%= render_flash_messages %> + <%= yield %> + <%= call_hook :view_layouts_base_content %> +
+
+ <%= render :partial => 'layouts/base_footer'%> +
+ + + +
+
+ <%= call_hook :view_layouts_base_body_bottom %> +
+ + + diff --git a/app/views/open_source_projects/_form.html.erb b/app/views/open_source_projects/_form.html.erb new file mode 100644 index 000000000..3949754ac --- /dev/null +++ b/app/views/open_source_projects/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@open_source_project) do |f| %> + <% if @open_source_project.errors.any? %> +
+

<%= pluralize(@open_source_project.errors.count, "error") %> prohibited this open_source_project from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :String %>
+ <%= f.text_field :String %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb new file mode 100644 index 000000000..ab52b0e3c --- /dev/null +++ b/app/views/open_source_projects/_os_project.html.erb @@ -0,0 +1,56 @@ + +
+
+ 图片 +
+
+

+ <%= textilizable(project.short_description, :project => project) %> +

+
+ +
+

+ + <%= 1%> + <%= content_tag('span', l(:label_x_follow_people,:count =>0)) %> +

+

+ + <%= 1%> + <%= content_tag('span', l(:label_x_current_contributors, :count => 0)) %> +

+

+ + <%= 1 %> + <%= content_tag('span', l(:label_since_last_commits)) %> +

+

+ + <%= 1 %> + <%= content_tag('span', l(:label_commit_on)) %> +

+
+ + +
+
+
+ + <%= content_tag('span', "#{l(:default_role_manager)}: ") %> + +
+
+ <%= content_tag('span', "#{l(:label_create_time)}: ") %><%= content_tag('span', format_time(project.created_at)) %> +
+ +
+
+ +
+ + <%= image_tag( "/images/sidebar/tags.png") %> + + +
+
diff --git a/app/views/open_source_projects/edit.html.erb b/app/views/open_source_projects/edit.html.erb new file mode 100644 index 000000000..bbe64cba8 --- /dev/null +++ b/app/views/open_source_projects/edit.html.erb @@ -0,0 +1,6 @@ +

Editing open_source_project

+ +<%= render 'form' %> + +<%= link_to 'Show', @open_source_project %> | +<%= link_to 'Back', open_source_projects_path %> diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb new file mode 100644 index 000000000..67c6f48c5 --- /dev/null +++ b/app/views/open_source_projects/index.html.erb @@ -0,0 +1,45 @@ +
+ <%= form_tag(:controller => 'open_source_projects', :action => "search", :method => :get) do %> + + + + + + + + + + + +
<%= l(:label_project_deposit) %><%= l(:label_user_location) %> : +
<%= link_to request.host()+"/projects", :controller => 'projects', :action => 'index', :project_type => 0 %> <%= link_to l(:field_homepage), home_path %> > <%= link_to l(:label_project_deposit), :controller => 'projects', :action => 'index', :project_type => 0 %>
+ <% end %> +
+ +
+ + +
+ + + +<% html_title(l(:label_project_plural)) -%> + diff --git a/app/views/open_source_projects/new.html.erb b/app/views/open_source_projects/new.html.erb new file mode 100644 index 000000000..66de0a3f9 --- /dev/null +++ b/app/views/open_source_projects/new.html.erb @@ -0,0 +1,5 @@ +

New open_source_project

+ +<%= render 'form' %> + +<%= link_to 'Back', open_source_projects_path %> diff --git a/app/views/open_source_projects/show.html.erb b/app/views/open_source_projects/show.html.erb new file mode 100644 index 000000000..f0657fc89 --- /dev/null +++ b/app/views/open_source_projects/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +

+ String: + <%= @open_source_project.name %> +

+ + +<%= link_to 'Edit', edit_open_source_project_path(@open_source_project) %> | +<%= link_to 'Back', open_source_projects_path %> diff --git a/config/routes.rb b/config/routes.rb index 41106c0a7..67634b422 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do + resources :open_source_projects do + collection do + match 'search', via: [:get, :post] + end + end + + match 'course', :to => 'welcome#course', :via => :get resources :stores do collection do diff --git a/db/migrate/20140324015819_create_open_source_projects.rb b/db/migrate/20140324015819_create_open_source_projects.rb new file mode 100644 index 000000000..22034c3bb --- /dev/null +++ b/db/migrate/20140324015819_create_open_source_projects.rb @@ -0,0 +1,15 @@ +class CreateOpenSourceProjects < ActiveRecord::Migration + def change + create_table :open_source_projects do |t| + t.column "name", :string, :default => nil, :null => true + t.column "description", :string, :default => '', :null => true + t.column "commit_count", :integer, :default => 0 + t.column "code_line", :integer, :default => 0 + t.column "users_count",:integer, :default => 0 + t.column "last_commit_time", :date, :null => true + t.column "url", :string, :default => nil, :null => true + t.column "date_collected", :date, :null => true + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index effd13d81..22a574604 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 => 20140319092720) do +ActiveRecord::Schema.define(:version => 20140324015819) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -493,6 +493,19 @@ ActiveRecord::Schema.define(:version => 20140319092720) do t.string "salt", :null => false end + create_table "open_source_projects", :force => true do |t| + t.string "name" + t.string "description", :default => "" + t.integer "commit_count", :default => 0 + t.integer "code_line", :default => 0 + t.integer "users_count", :default => 0 + t.date "last_commit_time" + t.string "url" + t.date "date_collected" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "praise_tread_caches", :force => true do |t| t.integer "object_id", :null => false t.string "object_type" diff --git a/test/fixtures/activities.yml b/test/fixtures/activities.yml new file mode 100644 index 000000000..585b0e66f --- /dev/null +++ b/test/fixtures/activities.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + act_id: + act_type: MyString + user_id: + +two: + act_id: + act_type: MyString + user_id: diff --git a/test/fixtures/forums.yml b/test/fixtures/forums.yml new file mode 100644 index 000000000..c63aac0b6 --- /dev/null +++ b/test/fixtures/forums.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/journal_replies.yml b/test/fixtures/journal_replies.yml new file mode 100644 index 000000000..1a8bb39c1 --- /dev/null +++ b/test/fixtures/journal_replies.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + journal_id: 1 + user_id: 1 + reply_id: 1 + +two: + journal_id: 1 + user_id: 1 + reply_id: 1 diff --git a/test/fixtures/open_source_projects.yml b/test/fixtures/open_source_projects.yml new file mode 100644 index 000000000..a95f1d28f --- /dev/null +++ b/test/fixtures/open_source_projects.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + String: + +two: + String: diff --git a/test/functional/forums_controller_test.rb b/test/functional/forums_controller_test.rb new file mode 100644 index 000000000..9b0438bd2 --- /dev/null +++ b/test/functional/forums_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class ForumsControllerTest < ActionController::TestCase + setup do + @forum = forums(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:forums) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create forum" do + assert_difference('Forum.count') do + post :create, forum: { } + end + + assert_redirected_to forum_path(assigns(:forum)) + end + + test "should show forum" do + get :show, id: @forum + assert_response :success + end + + test "should get edit" do + get :edit, id: @forum + assert_response :success + end + + test "should update forum" do + put :update, id: @forum, forum: { } + assert_redirected_to forum_path(assigns(:forum)) + end + + test "should destroy forum" do + assert_difference('Forum.count', -1) do + delete :destroy, id: @forum + end + + assert_redirected_to forums_path + end +end diff --git a/test/functional/open_source_projects_controller_test.rb b/test/functional/open_source_projects_controller_test.rb new file mode 100644 index 000000000..9b33a8b1f --- /dev/null +++ b/test/functional/open_source_projects_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class OpenSourceProjectsControllerTest < ActionController::TestCase + setup do + @open_source_project = open_source_projects(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:open_source_projects) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create open_source_project" do + assert_difference('OpenSourceProject.count') do + post :create, open_source_project: { String: @open_source_project.String } + end + + assert_redirected_to open_source_project_path(assigns(:open_source_project)) + end + + test "should show open_source_project" do + get :show, id: @open_source_project + assert_response :success + end + + test "should get edit" do + get :edit, id: @open_source_project + assert_response :success + end + + test "should update open_source_project" do + put :update, id: @open_source_project, open_source_project: { String: @open_source_project.String } + assert_redirected_to open_source_project_path(assigns(:open_source_project)) + end + + test "should destroy open_source_project" do + assert_difference('OpenSourceProject.count', -1) do + delete :destroy, id: @open_source_project + end + + assert_redirected_to open_source_projects_path + end +end diff --git a/test/unit/activity_test.rb b/test/unit/activity_test.rb new file mode 100644 index 000000000..eddcccdf7 --- /dev/null +++ b/test/unit/activity_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ActivityTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/forum_test.rb b/test/unit/forum_test.rb new file mode 100644 index 000000000..a6f90e493 --- /dev/null +++ b/test/unit/forum_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ForumTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/forums_helper_test.rb b/test/unit/helpers/forums_helper_test.rb new file mode 100644 index 000000000..deebfb03b --- /dev/null +++ b/test/unit/helpers/forums_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ForumsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/open_source_projects_helper_test.rb b/test/unit/helpers/open_source_projects_helper_test.rb new file mode 100644 index 000000000..8ecd58615 --- /dev/null +++ b/test/unit/helpers/open_source_projects_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class OpenSourceProjectsHelperTest < ActionView::TestCase +end diff --git a/test/unit/journal_reply_test.rb b/test/unit/journal_reply_test.rb new file mode 100644 index 000000000..500f11a6f --- /dev/null +++ b/test/unit/journal_reply_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class JournalReplyTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/open_source_project_test.rb b/test/unit/open_source_project_test.rb new file mode 100644 index 000000000..db44aad6e --- /dev/null +++ b/test/unit/open_source_project_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OpenSourceProjectTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From cfa553259813461ab5502eb90da11679a75eadf3 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Tue, 1 Apr 2014 08:51:43 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E4=BA=86open=20source?= =?UTF-8?q?=20project=E9=83=A8=E5=88=86=E7=9A=84=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=BB=BA=E7=AB=8B=E4=BA=86=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E5=B8=96=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/open_source_project.rb | 4 + app/models/relative_memo.rb | 3 + app/views/layouts/base_opensource_p.html.erb | 15 +- .../open_source_projects/_os_project.html.erb | 16 +- app/views/open_source_projects/index.html.erb | 2 +- .../20140401004102_create_relative_memos.rb | 18 ++ db/schema.rb | 199 +++++++++++++++++- test/fixtures/relative_memos.yml | 11 + test/unit/relative_memo_test.rb | 7 + 9 files changed, 264 insertions(+), 11 deletions(-) create mode 100644 app/models/relative_memo.rb create mode 100644 db/migrate/20140401004102_create_relative_memos.rb create mode 100644 test/fixtures/relative_memos.yml create mode 100644 test/unit/relative_memo_test.rb diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 61b734f25..39ab5fc46 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -1,5 +1,9 @@ class OpenSourceProject < ActiveRecord::Base attr_accessible :String + + has_many :tags, :through => :project_tags, :class_name => 'Tag' + has_many :project_tags, :class_name => 'ProjectTags' + acts_as_taggable def short_description(length = 255) description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb new file mode 100644 index 000000000..a8b745f66 --- /dev/null +++ b/app/models/relative_memo.rb @@ -0,0 +1,3 @@ +class RelativeMemo < ActiveRecord::Base + # attr_accessible :title, :body +end diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index 64232ff9c..dc5efe05c 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -26,7 +26,7 @@
- + - - + + @@ -90,6 +90,10 @@
<%= l(:label_create_time) %>:<%= format_time(@open_source_project.created_at) %>
+
+ 项目来源:<%= link_to @open_source_project.url, @open_source_project.url %> + +
@@ -97,6 +101,11 @@
+
+
+ <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "2"}%> +
+
diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb index ab52b0e3c..010b4fb54 100644 --- a/app/views/open_source_projects/_os_project.html.erb +++ b/app/views/open_source_projects/_os_project.html.erb @@ -1,4 +1,3 @@ -
图片 @@ -28,7 +27,7 @@

<%= 1 %> - <%= content_tag('span', l(:label_commit_on)) %> + <%= content_tag('span', "行代码") %>

@@ -45,12 +44,17 @@
+
+
+ <%= content_tag('span', "项目来源:")%><%= link_to project.url, project.url %> +
+
+ <%= content_tag('span', "数据更新时间") %><%= content_tag('span', format_time(project.created_at)) %> +
+
-
- <%= image_tag( "/images/sidebar/tags.png") %> - - + <%= render :partial => 'tags/tag_name', :locals => {:obj => project,:object_flag => "2",:non_list_all => true }%>
diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index 67c6f48c5..5cb93ea63 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -26,7 +26,7 @@ <% @open_source_projects.each do |project| %>
  • - <%= link_to project.name, open_source_projects_path(project), :class=>"project root leaf"%> + <%= link_to project.name, open_source_project_path(project), :class=>"project root leaf"%> <%= render :partial => 'open_source_projects/os_project', :locals => {:project => project}%>
    diff --git a/db/migrate/20140401004102_create_relative_memos.rb b/db/migrate/20140401004102_create_relative_memos.rb new file mode 100644 index 000000000..6654b8fe5 --- /dev/null +++ b/db/migrate/20140401004102_create_relative_memos.rb @@ -0,0 +1,18 @@ +class CreateRelativeMemos < ActiveRecord::Migration + def change + create_table :relative_memos do |t| + t.integer :osp_id, :null => false + t.integer :parent_id, null: true + t.string :subject, null: false + t.text :content, null: false + t.integer :author_id + t.integer :replies_count, default: 0 + t.integer :last_reply_id + t.boolean :lock, default: false + t.boolean :sticky, default: false + t.boolean :is_quote, default: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 22a574604..6544ba9d4 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 => 20140324015819) do +ActiveRecord::Schema.define(:version => 20140401004102) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -62,6 +62,20 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "auth_sources", ["id", "type"], :name => "index_auth_sources_on_id_and_type" + create_table "bak_mentioned", :primary_key => "Id", :force => true do |t| + t.string "this_real_name", :limit => 1000 + t.integer "is_mentioned_in" + t.string "context", :limit => 2000 + end + + add_index "bak_mentioned", ["this_real_name", "is_mentioned_in"], :name => "name_mention", :length => {"this_real_name"=>900, "is_mentioned_in"=>nil} + add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name" + add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_2" + add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_3", :length => {"this_real_name"=>900} + add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_4" + add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_5" + add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_6" + create_table "biding_projects", :force => true do |t| t.integer "project_id" t.integer "bid_id" @@ -101,6 +115,11 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id" add_index "boards", ["project_id"], :name => "boards_project_id" + create_table "categories", :primary_key => "Id", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "proj_categories" + end + create_table "changes", :force => true do |t| t.integer "changeset_id", :null => false t.string "action", :limit => 1, :default => "", :null => false @@ -232,6 +251,14 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "documents", ["created_on"], :name => "index_documents_on_created_on" add_index "documents", ["project_id"], :name => "documents_project_id" + create_table "eco_projects", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.integer "eco_proj_id" + t.datetime "date_collected" + end + + add_index "eco_projects", ["proj_id"], :name => "proj_id" + create_table "enabled_modules", :force => true do |t| t.integer "project_id" t.string "name", :null => false @@ -253,6 +280,137 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "enumerations", ["id", "type"], :name => "index_enumerations_on_id_and_type" add_index "enumerations", ["project_id"], :name => "index_enumerations_on_project_id" + create_table "events", :primary_key => "event_id", :force => true do |t| + t.string "job_name" + t.datetime "event_time" + t.string "event_type", :limit => 20 + end + + create_table "fm_article", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "article_title", :limit => 16777215 + t.text "article_link", :limit => 16777215 + t.text "article_time", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_article", ["proj_id"], :name => "proj_id" + + create_table "fm_bugtracker_link", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_bugtracker_link", ["proj_id"], :name => "proj_id" + + create_table "fm_datametric_link", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_datametric_link", ["proj_id"], :name => "proj_id" + + create_table "fm_dependency_link", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_dependency_link", ["proj_id"], :name => "proj_id" + + create_table "fm_download_link", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "download_link", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_download_link", ["proj_id"], :name => "proj_id" + + create_table "fm_heartbeat", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.float "popularity_score", :limit => 12 + t.float "vitality_score", :limit => 12 + t.integer "subscription" + t.integer "voting_score" + t.integer "voting_count" + t.datetime "date_collected" + end + + add_index "fm_heartbeat", ["proj_id"], :name => "proj_id" + + create_table "fm_license", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_license", ["proj_id"], :name => "proj_id" + + create_table "fm_mailinglist_link", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_mailinglist_link", ["proj_id"], :name => "proj_id" + + create_table "fm_operating_system", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_operating_system", ["proj_id"], :name => "proj_id" + + create_table "fm_programming_language", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_programming_language", ["proj_id"], :name => "proj_id" + + create_table "fm_project_spotlight", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.text "project_name", :limit => 16777215 + t.text "project_spotlight_link", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_project_spotlight", ["proj_id"], :name => "proj_id" + + create_table "fm_release", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.text "release_version", :limit => 16777215 + t.text "release_time", :limit => 16777215 + t.text "release_tag", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_release", ["proj_id"], :name => "proj_id" + + create_table "fm_submit", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "submitter", :limit => 16777215 + t.text "submitter_link", :limit => 16777215 + t.text "submit_time", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_submit", ["proj_id"], :name => "proj_id" + + create_table "fm_summary", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.text "description", :limit => 16777215 + t.datetime "date_collected" + end + + add_index "fm_summary", ["proj_id"], :name => "proj_id" + create_table "forums", :force => true do |t| t.string "name", :null => false t.string "description", :default => "" @@ -478,6 +636,14 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "news", ["created_on"], :name => "index_news_on_created_on" add_index "news", ["project_id"], :name => "news_project_id" + create_table "ohloh_tagged", :force => true do |t| + t.integer "proj_id", :default => 0, :null => false + t.string "description", :limit => 100, :null => false + t.datetime "date_collected" + end + + add_index "ohloh_tagged", ["proj_id"], :name => "proj_id" + create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime" @@ -585,6 +751,21 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "queries", ["project_id"], :name => "index_queries_on_project_id" add_index "queries", ["user_id"], :name => "index_queries_on_user_id" + create_table "relative_memos", :force => true do |t| + t.integer "osp_id", :null => false + t.integer "parent_id" + t.string "subject", :null => false + t.text "content", :null => false + t.integer "author_id" + t.integer "replies_count", :default => 0 + t.integer "last_reply_id" + t.boolean "lock", :default => false + t.boolean "sticky", :default => false + t.boolean "is_quote", :default => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "repositories", :force => true do |t| t.integer "project_id", :default => 0, :null => false t.string "url", :default => "", :null => false @@ -720,6 +901,22 @@ ActiveRecord::Schema.define(:version => 20140324015819) do add_index "tokens", ["user_id"], :name => "index_tokens_on_user_id" add_index "tokens", ["value"], :name => "tokens_value", :unique => true + create_table "tprojects", :force => true do |t| + t.string "name", :limit => 1000, :default => "0" + t.text "description", :limit => 16777215 + t.string "commit_count", :limit => 100, :default => "0" + t.string "code_line", :limit => 100 + t.string "last_commit_time", :limit => 100 + t.string "url", :limit => 1000 + t.datetime "date_collected" + t.string "created_at", :limit => 100 + t.string "updated_at", :limit => 100 + t.integer "proj_id", :null => false + t.string "user_count", :limit => 100 + end + + add_index "tprojects", ["proj_id"], :name => "proj_id" + create_table "trackers", :force => true do |t| t.string "name", :limit => 30, :default => "", :null => false t.boolean "is_in_chlog", :default => false, :null => false diff --git a/test/fixtures/relative_memos.yml b/test/fixtures/relative_memos.yml new file mode 100644 index 000000000..c63aac0b6 --- /dev/null +++ b/test/fixtures/relative_memos.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/unit/relative_memo_test.rb b/test/unit/relative_memo_test.rb new file mode 100644 index 000000000..5f835a2a8 --- /dev/null +++ b/test/unit/relative_memo_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RelativeMemoTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From e8de48dd24279de671b199ce974a77ea313d5264 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Thu, 3 Apr 2014 14:41:04 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9osp=E7=9A=84show?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=EF=BC=8C=E5=BB=BA=E7=AB=8B=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open_source_projects_controller.rb | 30 ++++ app/controllers/relative_memos_controller.rb | 123 +++++++++++++++ app/models/open_source_project.rb | 15 ++ app/models/relative_memo.rb | 149 ++++++++++++++++++ app/views/forums/_show_topics.html.erb | 2 +- app/views/layouts/base_opensource_p.html.erb | 6 +- .../open_source_projects/_os_project.html.erb | 2 +- .../_show_topics.html.erb | 57 +++++++ app/views/open_source_projects/show.html.erb | 60 ++++++- app/views/relative_memos/show.html.erb | 0 app/views/tags/_tag.html.erb | 2 + config/routes.rb | 64 ++++---- 12 files changed, 463 insertions(+), 47 deletions(-) create mode 100644 app/controllers/relative_memos_controller.rb create mode 100644 app/views/open_source_projects/_show_topics.html.erb create mode 100644 app/views/relative_memos/show.html.erb diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index 41df7c409..f7f32a43b 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -1,4 +1,7 @@ class OpenSourceProjectsController < ApplicationController + + helper :sort + include SortHelper # GET /open_source_projects # GET /open_source_projects.json def index @@ -21,6 +24,33 @@ class OpenSourceProjectsController < ApplicationController # GET /open_source_projects/1.json def show @open_source_project = OpenSourceProject.find(params[:id]) + + sort_init 'updated_at', 'desc' + sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at", + 'replies' => "#{RelativeMemo.table_name}.replies_count", + 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)" + + @memo = RelativeMemo.new(:open_source_project => @open_source_project) + @topic_count = @open_source_project.topics.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = @open_source_project.topics. + reorder("#{RelativeMemo.table_name}.sticky DESC"). + includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + order(sort_clause). + all + + + + # @offset, @limit = api_offset_and_limit({:limit => 10}) + # @forum = Forum.find(params[:id]) + # @memos_all = @forum.topics + # @topic_count = @memos_all.count + # @topic_pages = Paginator.new @topic_count, @limit, params['page'] + + # @offset ||= @topic_pages.offset + # @memos = @memos_all.offset(@offset).limit(@limit).all respond_to do |format| format.html { diff --git a/app/controllers/relative_memos_controller.rb b/app/controllers/relative_memos_controller.rb new file mode 100644 index 000000000..98ca8cd52 --- /dev/null +++ b/app/controllers/relative_memos_controller.rb @@ -0,0 +1,123 @@ +class RelativeMemosController < ApplicationController + + helper :sort + include SortHelper + # GET /open_source_projects + # GET /open_source_projects.json + def index + # per_page_option = 10 +# + # @open_source_projects = OpenSourceProject.all +# + # @os_project_count = @open_source_projects.count + # @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] +# + # @open_source_projects = OpenSourceProject.all +# + # respond_to do |format| + # format.html # index.html.erb + # format.json { render json: @open_source_projects } + # end + end + + # GET /open_source_projects/1 + # GET /open_source_projects/1.json + def show + # @open_source_project = OpenSourceProject.find(params[:id]) +# + # sort_init 'updated_at', 'desc' + # sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at", + # 'replies' => "#{RelativeMemo.table_name}.replies_count", + # 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)" +# + # @memo = RelativeMemo.new(:open_source_project => @open_source_project) + # @topic_count = @open_source_project.topics.count + # @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + # @memos = @open_source_project.topics. + # reorder("#{RelativeMemo.table_name}.sticky DESC"). + # includes(:last_reply). + # limit(@topic_pages.per_page). + # offset(@topic_pages.offset). + # order(sort_clause). + # all + + + + # @offset, @limit = api_offset_and_limit({:limit => 10}) + # @forum = Forum.find(params[:id]) + # @memos_all = @forum.topics + # @topic_count = @memos_all.count + # @topic_pages = Paginator.new @topic_count, @limit, params['page'] + + # @offset ||= @topic_pages.offset + # @memos = @memos_all.offset(@offset).limit(@limit).all + + # respond_to do |format| + # format.html { + # render :layout => "base_opensource_p" + # } + # format.json { render json: @open_source_project } + # end + end + + + # GET /open_source_projects/new + # GET /open_source_projects/new.json + def new + @open_source_project = OpenSourceProject.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @open_source_project } + end + end + + # GET /open_source_projects/1/edit + def edit + @open_source_project = OpenSourceProject.find(params[:id]) + end + + # POST /open_source_projects + # POST /open_source_projects.json + def create + @open_source_project = OpenSourceProject.new(params[:open_source_project]) + + respond_to do |format| + if @open_source_project.save + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.'} + format.json { render json: @open_source_project, status: :created, location: @open_source_project } + else + format.html { render action: "new" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # PUT /open_source_projects/1 + # PUT /open_source_projects/1.json + def update + @open_source_project = OpenSourceProject.find(params[:id]) + + respond_to do |format| + if @open_source_project.update_attributes(params[:open_source_project]) + format.html { redirect_to @open_source_project, notice: 'Open source project was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /open_source_projects/1 + # DELETE /open_source_projects/1.json + def destroy + @open_source_project = OpenSourceProject.find(params[:id]) + @open_source_project.destroy + + respond_to do |format| + format.html { redirect_to open_source_projects_url } + format.json { head :no_content } + end + end +end diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 39ab5fc46..f6ec5a8ce 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -1,10 +1,25 @@ class OpenSourceProject < ActiveRecord::Base attr_accessible :String + include Redmine::SafeAttributes + has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy + has_many :relative_memos, :dependent => :destroy has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' acts_as_taggable def short_description(length = 255) description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end + + def reset_counters! + self.class.reset_counters!(id) + end + + def self.reset_counters!(id) + osp_id = id.to_i + update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," + + " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," + + " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})", + ["id = ?", osp_id]) + end end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index a8b745f66..060312f86 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -1,3 +1,152 @@ class RelativeMemo < ActiveRecord::Base # attr_accessible :title, :body + include Redmine::SafeAttributes + belongs_to :open_source_project, :class_name => "OpenSourceProject", :foreign_key => 'osp_id' + belongs_to :author, :class_name => "User", :foreign_key => 'author_id' + + has_many :tags, :through => :project_tags, :class_name => 'Tag' + has_many :project_tags, :class_name => 'ProjectTags' + acts_as_taggable + + validates_presence_of :osp_id, :subject + #validates :content, presence: true + # validates_length_of :subject, maximum: 50 + #validates_length_of :content, maximum: 3072 + validate :cannot_reply_to_locked_topic, :on => :create + + acts_as_tree :counter_cache => :replies_count, :order => "#{RelativeMemo.table_name}.created_at ASC" + acts_as_attachable + belongs_to :last_reply, :class_name => 'RelativeMemo', :foreign_key => 'last_reply_id' + # acts_as_searchable :column => ['subject', 'content'], + # #:include => { :forum => :p} + # #:project_key => "#{Forum.table_name}.project_id" + # :date_column => "#{table_name}.created_at" + + # acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"}, + # :datetime => :updated_at, + # # :datetime => :created_at, + # :description => :content, + # :author => :author, + # :type => Proc.new {|o| o.parent_id.nil? ? 'Memo' : 'Reply'}, + # :url => Proc.new {|o| {:controller => 'memos', :action => 'show', :forum_id => o.forum_id}.merge(o.parent_id.nil? ? {:id => o.id} : {:id => o.parent_id, :r => o.id, :anchor => "reply-#{o.id}"})} + # acts_as_activity_provider :author_key => :author_id, + # :func => 'memos', + # :timestamp => 'created_at' + + # :find_options => {:type => 'memos'} + # acts_as_watchable + + safe_attributes "author_id", + "subject", + "content", + "osp_id", + "last_memo_id", + "lock", + "sticky", + "parent_id", + "replies_count", + "is_quote" + + after_create :add_author_as_watcher, :reset_counters! + # after_update :update_memos_forum + after_destroy :reset_counters! + # after_create :send_notification + # after_save :plusParentAndForum + # after_destroy :minusParentAndForum + + # scope :visible, lambda { |*args| + # includes(:forum => ).where() + # } + + def cannot_reply_to_locked_topic + errors.add :base, l(:label_memo_locked) if root.locked? && self != root + end + + # def update_memos_forum + # if forum_id_changed? + # Message.update_all({:board_id => board_id}, ["id = ? OR parent_id = ?", root.id, root.id ]) + # Forum.reset_counters!(forum_id_was) + # Forum.reset_counters!(forum_id) + # end + # end + + def reset_counters! + if parent && parent.id + RelativeMemo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) + parent.update_attribute(:updated_at, Time.now) + end + forum.reset_counters! + end + + def sticky? + sticky == 1 + end + + def replies + RelativeMemo.where("parent_id = ?", id) + end + + def locked? + self.lock + end + + def editable_by? user + # user && user.logged? || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)) + user.admin? + end + + # def destroyable_by? user + # (user && user.logged? && (Forum.find(self.forum_id).creator_id == user.id) ) || user.admin? + # #self.author == user || user.admin? + # end + + def deleted_attach_able_by? user + (user && user.logged? && (self.author == user) ) || user.admin? + end + + private + + def add_author_as_watcher + Watcher.create(:watchable => self.root, :user => author) + end + + def send_notification + if Setting.notified_events.include?('message_posted') + Mailer.message_posted(self).deliver + end + end + + # def plusParentAndForum + # @forum = Forum.find(self.forum_id) + # @forum.memo_count = @forum.memo_count.to_int + 1 + # @forum.last_memo_id = self.id + # if self.parent_id + # @parent_memo = Memo.find_by_id(self.parent_id) + # @parent_memo.last_reply_id = self + # @parent_memo.replies_count = @parent_memo.replies_count.to_int + 1 + # @parent_memo.save + # else + # @forum.topic_count = @forum.topic_count.to_int + 1 + # end + # @forum.save + # end + + # def minusParentAndForum + # @forum = Forum.find(self.forum_id) + # @forum.memo_count = @forum.memo_count.to_int - 1 + # @forum.memo_count = 0 if @forum.memo_count.to_int < 0 + # # @forum.last_memo_id = Memo.reorder('created_at ASC').find_all_by_forum_id(self.forum_id).last.id + # if self.parent_id + # @parent_memo = Memo.find_by_id(self.parent_id) + # # @parent_memo.last_reply_id = Memo.reorder('created_at ASC').find_all_by_parent_id(self.parent_id).last.id + # @parent_memo.replies_count = @parent_memo.replies_count.to_int - 1 + # @parent_memo.replies_count = 0 if @parent_memo.replies_count.to_int < 0 + # @parent_memo.save + # else + # @forum.topic_count = @forum.topic_count.to_int - 1 + # @forum.topic_count = 0 if @forum.topic_count.to_int < 0 + # end + # @forum.save + # end end + diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index 3e7d4947b..0531f9625 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -5,7 +5,7 @@ <% if memos.any? %> <% memos.each do |topic| %>
  • 软件项目托管社区开源项目社区 <%= l(:label_user_location) %> :
    <%= l(:label_member) %><%= l(:label_user_watchered) %> 贡献者讨论 <%= l(:label_project_issues) %>
    - + diff --git a/app/views/no_uses/_form.html.erb b/app/views/no_uses/_form.html.erb new file mode 100644 index 000000000..0bcedb031 --- /dev/null +++ b/app/views/no_uses/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@no_use) do |f| %> + <% if @no_use.errors.any? %> +
    +

    <%= pluralize(@no_use.errors.count, "error") %> prohibited this no_use from being saved:

    + + +
    + <% end %> + +
    + <%= f.submit %> +
    +<% end %> diff --git a/app/views/no_uses/edit.html.erb b/app/views/no_uses/edit.html.erb new file mode 100644 index 000000000..d7a0ea439 --- /dev/null +++ b/app/views/no_uses/edit.html.erb @@ -0,0 +1,6 @@ +

    Editing no_use

    + +<%= render 'form' %> + +<%= link_to 'Show', @no_use %> | +<%= link_to 'Back', no_uses_path %> diff --git a/app/views/no_uses/index.html.erb b/app/views/no_uses/index.html.erb new file mode 100644 index 000000000..5535d74c1 --- /dev/null +++ b/app/views/no_uses/index.html.erb @@ -0,0 +1,21 @@ +

    Listing no_uses

    + +
    <%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) %>
    <%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index dc5efe05c..df05d4f75 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -103,7 +103,7 @@
    - <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "2"}%> + <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "7"}%>
    @@ -114,10 +114,10 @@ -
    +
    <%#=
    -
    +
    %> <%= render_flash_messages %> <%= yield %> <%= call_hook :view_layouts_base_content %> diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb index 010b4fb54..133f6c4cc 100644 --- a/app/views/open_source_projects/_os_project.html.erb +++ b/app/views/open_source_projects/_os_project.html.erb @@ -51,7 +51,7 @@
    <%= content_tag('span', "数据更新时间") %><%= content_tag('span', format_time(project.created_at)) %>
    -
    +
    <%= image_tag( "/images/sidebar/tags.png") %> diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb new file mode 100644 index 000000000..172949e92 --- /dev/null +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -0,0 +1,57 @@ + + +
    + 共有 <%= link_to memos.count %> 个贴子 +
    +
    + <% if memos.any? %> + <% memos.each do |topic| %> +
    + + + + + +
    <%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> + + + + + + + + + + + + + + + + +
    <%= link_to h(topic.subject), open_source_project_relative_memo_path(topic.open_source_project, topic) %> + + + + + + + +
    <%= link_to (topic.replies_count), forum_memo_path(topic.open_source_project, topic) %>
    回答
    <%#= authoring topic.created_at, topic.author %> +
    +
    <%= @open_source_project.url%>
    + <%= image_tag( "/images/sidebar/tags.png") %> + <%= render :partial => 'tags/tag_name', :locals => {:obj => topic,:object_flag => "9",:non_list_all => true }%> + +
    + + <% end %> + + <% else %> +

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

    + <% end %> + \ No newline at end of file diff --git a/app/views/open_source_projects/show.html.erb b/app/views/open_source_projects/show.html.erb index f0657fc89..eb8e1b49f 100644 --- a/app/views/open_source_projects/show.html.erb +++ b/app/views/open_source_projects/show.html.erb @@ -1,10 +1,54 @@ -

    <%= notice %>

    + + + +<% #= link_to '发布帖子', new_forum_memo_path(@forum), :class => 'icon icon-add' %> + + <%= link_to l(:label_memo_new_from_forum), new_forum_memo_path(@forum), :class => 'icon icon-add', + :onclick => 'showAndScrollTo("add-memo", "memo_subject"); return false;' if User.current.logged? %> + - -<%= link_to 'Edit', edit_open_source_project_path(@open_source_project) %> | -<%= link_to 'Back', open_source_projects_path %> +
    + <%#= link_to( + image_tag('edit.png')+l(:label_forum_edit), + {:action => 'edit', :id => @forum}, + :method => 'get', + :title => l(:button_edit) + ) if @forum.editable_by?(User.current) %> + <%#= link_to( + image_tag('delete.png')+'删除讨论区', + {:action => 'destroy', :id => @forum}, + :method => :delete, + :data => {:confirm => l(:text_are_you_sure)}, + :title => l(:button_delete) + ) if @forum.destroyable_by?(User.current) %> +
    +<%= render :partial => 'open_source_projects/show_topics', :locals => {:memos => @memos} %> diff --git a/app/views/relative_memos/show.html.erb b/app/views/relative_memos/show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 7eb360d53..b674e5152 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -6,6 +6,8 @@ 4 代表是bid类型 5 代表是forum类型 6 代表是Attachment类型 + 7 代表是OpenSourceProject类型 + 8 代表是RelativeMemo类型 #end%> <% if object_flag == '3' %> diff --git a/config/routes.rb b/config/routes.rb index 67634b422..fac469985 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,14 +20,16 @@ RedmineApp::Application.routes.draw do collection do match 'search', via: [:get, :post] end + resources :relative_memos do + + end end - match 'course', :to => 'welcome#course', :via => :get resources :stores do collection do match 'search', via: [:get, :post] - end + end end resources :forums do @@ -44,21 +46,20 @@ RedmineApp::Application.routes.draw do end end - resources :shares - + #added by william get "tags/index" - + get "tags/show" - + get "praise_tread/praise_plus" get "praise_tread/tread_plus" #end root :to => 'welcome#index', :as => 'home' - + #added by baiyu match 'git_usage/ch_usage', :controller => 'git_usage', :action => 'ch_usage', :via => :get, :as => 'ch_usage' match 'git_usage/en_usage', :controller => 'git_usage', :action => 'en_usage', :via => :get, :as => 'en_usage' @@ -103,7 +104,6 @@ RedmineApp::Application.routes.draw do match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post] match '/journals/destroy/:id', :to => 'journals#destroy', :id => /\d+/, :via => [:get, :post] - get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt' get '/issues/gantt', :to => 'gantts#show' @@ -113,21 +113,21 @@ RedmineApp::Application.routes.draw do get 'projects/:id/issues/report', :to => 'reports#issue_report', :as => 'project_issues_report' get 'projects/:id/issues/report/:detail', :to => 'reports#issue_report_details', :as => 'project_issues_report_details' post '/users/:id/user_activities', :to => 'users#show', :as => "user_activities" - + #added by young - resources :users do + resources :users do member do match 'user_projects', :to => 'users#user_projects', :via => :get match 'user_activities', :to => 'users#show', :via => :get, :as => "user_activities" - match 'user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "user_newfeedback" - match 'watch_calls', :controller => 'users', :action => 'watch_bids', :via => [:get , :post] + match 'user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "user_newfeedback" + match 'watch_calls', :controller => 'users', :action => 'watch_bids', :via => [:get , :post] match 'info', :to => 'users#info', :via => [:get , :post], :as => 'user_info' match 'user_watchlist', :to => 'users#user_watchlist', :via => :get, :as => "user_watchlist" #add by huang match 'user_fanslist', :to => 'users#user_fanslist', :via => :get, :as => "user_fanslist" #add by huang match 'user_courses', :to => 'users#user_courses', :via => :get match 'user_homeworks', :to => 'users#user_homeworks', :via => :get - match 'watch_projects', :to => 'users#watch_projects', :via => :get - # added by bai + match 'watch_projects', :to => 'users#watch_projects', :via => :get + # added by bai match 'show_score', :to => 'users#show_score', :via => :get match 'topic_score_index', :controller => 'users', :action => 'topic_score_index', :via => [:get, :post] match 'project_score_index', :to => 'users#project_score_index', :via => :get @@ -141,13 +141,13 @@ RedmineApp::Application.routes.draw do match 'file_score_index', :to => 'projects#file_score_index', :via => [:get, :post] match 'code_submit_score_index', :to => 'projects#code_submit_score_index', :via => [:get, :post] match 'projects_topic_score_index', :to => 'projects#projects_topic_score_index', :via => [:get, :post] - # end + # end end end match 'users/:id/user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "feedback" match 'users/:id/user_projects', :controller => 'users', :action => 'user_projects', :via => :get - #match 'user/:id/watch_calls', :controller => 'users', :action => 'watch_bids', :via => [:get , :post] - + #match 'user/:id/watch_calls', :controller => 'users', :action => 'watch_bids', :via => [:get , :post] + #end match 'my/account', :controller => 'my', :action => 'account', :via => [:get, :post] match 'my/account/destroy', :controller => 'my', :action => 'destroy', :via => [:get, :post] @@ -203,7 +203,6 @@ RedmineApp::Application.routes.draw do post 'reopen' match 'copy', :via => [:get, :post] end - #by young match '/member', :controller => 'projects', :action => 'member', :as => 'member', :via => :get @@ -212,7 +211,6 @@ RedmineApp::Application.routes.draw do # match '/investor', :controller => 'projects', :action => 'investor', :as => 'investor', :via => :get match '/homework', :controller => 'projects', :action => 'homework', :as => 'homework', :via => :get - # match '/activity', :controller => 'activities', :action => 'index', :as => 'activity', :via => :get # match '/repository', :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil, :as => 'repository', :via => :get # match '/', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get @@ -220,7 +218,7 @@ RedmineApp::Application.routes.draw do # get 'projects/:project_id/repository', :to => 'repositories#show', :as => 'project_repository' # match '/show', :controller => 'projects', :action => 'show', :as => 'project_show', :via => :get - match '/watcherlist', :controller=>'projects', :action=> 'watcherlist', :as => 'watcherlist', :via => :get #add by huang + match '/watcherlist', :controller=>'projects', :action=> 'watcherlist', :as => 'watcherlist', :via => :get #add by huang # matche '/news', :controller => 'news', :action => 'index', :as => 'news', :via => :get #end @@ -270,7 +268,7 @@ RedmineApp::Application.routes.draw do resources :repositories, :except => [:index, :show] do member do get 'newrepo', :via => [:get, :post] - # get 'create', :via=>[:get, :post] + # get 'create', :via=>[:get, :post] end end match 'wiki/index', :controller => 'wiki', :action => 'index', :via => :get @@ -447,8 +445,6 @@ RedmineApp::Application.routes.draw do get 'autocomplete_for_new_user' end end - - match 'workflows', :controller => 'workflows', :action => 'index', :via => :get match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post] @@ -464,7 +460,7 @@ RedmineApp::Application.routes.draw do match 'uploads', :to => 'attachments#upload', :via => :post # Added by Tao - match 'upload_avatar', :to => 'avatar#upload', :via => :post + match 'upload_avatar', :to => 'avatar#upload', :via => :post # Endof Tao's code get 'robots.txt', :to => 'welcome#robots' @@ -479,7 +475,7 @@ RedmineApp::Application.routes.draw do end end end - + ##############测试留言功能 fq post 'words/new', :to => 'words#new' post 'words/create', :to => 'words#create' @@ -503,7 +499,7 @@ RedmineApp::Application.routes.draw do match 'calls/:id/new_submit_homework', to: 'bids#new_submit_homework', via: :get, as: 'new_submit_homework' match 'words/add_project_respond', :controller => 'words', :action => 'add_project_respond' match 'words/:id/leave_project_message', :controller => 'words', :action => 'leave_project_message' - + match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback' match 'calls/create_bid', :to => 'bids#create_bid' match 'contest/create_contest', :to => 'bids#create_contest' #huang @@ -517,24 +513,24 @@ RedmineApp::Application.routes.draw do match 'calls/:id/show_course', :to => 'bids#show_course', :as => 'show_course' match 'calls/:id/show_bid_project', :to => 'bids#show_bid_project', :as => 'show_bid_project' match 'calls/:id/show_bid_user', :to => 'bids#show_bid_user', :as => 'show_bid_user' - + match 'project/:id/share', :to => 'projects#share', :as => 'share_show' #share - - post 'join_in/join', :to => 'courses#join', :as => 'join' + + post 'join_in/join', :to => 'courses#join', :as => 'join' delete 'join_in/join', :to => 'courses#unjoin' post 'calls/:id/join_in_contest', :to => 'bids#join_in_contest', :as => 'join_in_contest' delete 'calls/:id/join_in_contest', :to => 'bids#unjoin_in_contest' match 'calls/:id/show_participator', :to => 'bids#show_participator' #bai match 'calls/:id/update_contest', :to => 'bids#update_contest' #bai match 'calls/:id/settings', :to => 'bids#settings' #bai - + delete 'attachment/:id', :to => 'attachments#delete_homework' match 'new_join', :to => 'projects#new_join', :as => 'try_join' match 'new_join_in_contest', :to => 'bids#new_join', :as => 'try_join_in_contest' match 'projects/:id/respond', :to => 'projects#project_respond', :via => :post match 'calls/:id/manage',:to => 'bids#manage',:via => [:get,:post] match 'project/course', :to => 'projects#course', :as => 'course' - + #added by william # match 'calls/:id/set_results',:controller => 'bids', :action => 'set_results',:via => [:get,:post],:as => 'set_results' # match 'calls/:id/set_prizes',:controller => 'bids',:action => 'set_prizes',:as => 'set_prizes' @@ -544,10 +540,10 @@ RedmineApp::Application.routes.draw do match 'test/index', :controller => 'test', :action => 'index' # added by young match 'calls', :controller => 'bids', :action => 'index' - + match 'calls/:id', :controller => 'bids', :action => 'show', :as => 'respond' match 'contest', :controller => 'bids', :action => 'contest', :as => 'contest' - + ######added by nie match 'tags/show_projects_tags',:to => 'tags#show_projects_tags' ########### added by liuping @@ -558,6 +554,6 @@ RedmineApp::Application.routes.draw do match 'parise_tread/tread_plus',:to => 'parise_tread#tread_plus',:as=>"tread" match 'tags/delete',:to=>'tags#delete' match 'tags/remove_tag',:to=>'tags#remove_tag',:as=>"remove_tag" - + match 'words/add_brief_introdution', :controller => 'words', :action => 'add_brief_introdution' end From 9af808821dbb64c5b6f206186e459b30fe06538f Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Thu, 3 Apr 2014 20:47:09 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0"=E6=B2=A1=E6=9C=89=E5=B8=AE?= =?UTF-8?q?=E5=8A=A9"=E5=92=8C"=E7=94=B3=E8=AF=B7=E6=88=90=E4=B8=BA?= =?UTF-8?q?=E7=89=88=E4=B8=BB"=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/apply_project_masters.js | 2 + app/assets/javascripts/no_uses.js | 2 + .../stylesheets/apply_project_masters.css | 4 + app/assets/stylesheets/no_uses.css | 4 + .../apply_project_masters_controller.rb | 83 ++++++++++++ app/controllers/no_uses_controller.rb | 123 ++++++++++++++++++ .../open_source_projects_controller.rb | 4 + app/helpers/apply_project_masters_helper.rb | 23 ++++ app/helpers/no_uses_helper.rb | 22 ++++ app/helpers/open_source_projects_helper.rb | 1 + app/models/apply_project_master.rb | 3 + app/models/no_use.rb | 3 + app/models/open_source_project.rb | 8 ++ app/models/relative_memo.rb | 10 ++ .../apply_project_masters/_form.html.erb | 17 +++ app/views/apply_project_masters/edit.html.erb | 6 + .../apply_project_masters/index.html.erb | 21 +++ app/views/apply_project_masters/new.html.erb | 5 + app/views/apply_project_masters/show.html.erb | 5 + app/views/layouts/base_opensource_p.html.erb | 1 + app/views/no_uses/_form.html.erb | 17 +++ app/views/no_uses/edit.html.erb | 6 + app/views/no_uses/index.html.erb | 21 +++ app/views/no_uses/new.html.erb | 5 + app/views/no_uses/show.html.erb | 5 + .../_show_topics.html.erb | 16 +-- app/views/open_source_projects/show.html.erb | 8 +- config/routes.rb | 6 + ...0403075029_create_apply_project_masters.rb | 12 ++ db/migrate/20140403113341_create_no_uses.rb | 11 ++ db/schema.rb | 19 ++- test/fixtures/apply_project_masters.yml | 11 ++ test/fixtures/no_uses.yml | 11 ++ .../apply_project_masters_controller_test.rb | 49 +++++++ test/functional/no_uses_controller_test.rb | 49 +++++++ test/unit/apply_project_master_test.rb | 7 + .../apply_project_masters_helper_test.rb | 4 + test/unit/helpers/no_uses_helper_test.rb | 4 + test/unit/no_use_test.rb | 7 + 39 files changed, 602 insertions(+), 13 deletions(-) create mode 100644 app/assets/javascripts/apply_project_masters.js create mode 100644 app/assets/javascripts/no_uses.js create mode 100644 app/assets/stylesheets/apply_project_masters.css create mode 100644 app/assets/stylesheets/no_uses.css create mode 100644 app/controllers/apply_project_masters_controller.rb create mode 100644 app/controllers/no_uses_controller.rb create mode 100644 app/helpers/apply_project_masters_helper.rb create mode 100644 app/helpers/no_uses_helper.rb create mode 100644 app/models/apply_project_master.rb create mode 100644 app/models/no_use.rb create mode 100644 app/views/apply_project_masters/_form.html.erb create mode 100644 app/views/apply_project_masters/edit.html.erb create mode 100644 app/views/apply_project_masters/index.html.erb create mode 100644 app/views/apply_project_masters/new.html.erb create mode 100644 app/views/apply_project_masters/show.html.erb create mode 100644 app/views/no_uses/_form.html.erb create mode 100644 app/views/no_uses/edit.html.erb create mode 100644 app/views/no_uses/index.html.erb create mode 100644 app/views/no_uses/new.html.erb create mode 100644 app/views/no_uses/show.html.erb create mode 100644 db/migrate/20140403075029_create_apply_project_masters.rb create mode 100644 db/migrate/20140403113341_create_no_uses.rb create mode 100644 test/fixtures/apply_project_masters.yml create mode 100644 test/fixtures/no_uses.yml create mode 100644 test/functional/apply_project_masters_controller_test.rb create mode 100644 test/functional/no_uses_controller_test.rb create mode 100644 test/unit/apply_project_master_test.rb create mode 100644 test/unit/helpers/apply_project_masters_helper_test.rb create mode 100644 test/unit/helpers/no_uses_helper_test.rb create mode 100644 test/unit/no_use_test.rb 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? %> +
    +

    <%= pluralize(@apply_project_master.errors.count, "error") %> prohibited this apply_project_master from being saved:

    + +
      + <% @apply_project_master.errors.full_messages.each do |msg| %> +
    • <%= msg %>
    • + <% end %> +
    +
    + <% end %> + +
    + <%= f.submit %> +
    +<% end %> diff --git a/app/views/apply_project_masters/edit.html.erb b/app/views/apply_project_masters/edit.html.erb new file mode 100644 index 000000000..47d85b99c --- /dev/null +++ b/app/views/apply_project_masters/edit.html.erb @@ -0,0 +1,6 @@ +

    Editing apply_project_master

    + +<%= render 'form' %> + +<%= link_to 'Show', @apply_project_master %> | +<%= link_to 'Back', apply_project_masters_path %> diff --git a/app/views/apply_project_masters/index.html.erb b/app/views/apply_project_masters/index.html.erb new file mode 100644 index 000000000..16023cd83 --- /dev/null +++ b/app/views/apply_project_masters/index.html.erb @@ -0,0 +1,21 @@ +

    Listing apply_project_masters

    + + + + + + + + +<% @apply_project_masters.each do |apply_project_master| %> + + + + + +<% end %> +
    <%= 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?' } %>
    + +
    + +<%= link_to 'New Apply project master', new_apply_project_master_path %> diff --git a/app/views/apply_project_masters/new.html.erb b/app/views/apply_project_masters/new.html.erb new file mode 100644 index 000000000..7cdcac28b --- /dev/null +++ b/app/views/apply_project_masters/new.html.erb @@ -0,0 +1,5 @@ +

    New apply_project_master

    + +<%= render 'form' %> + +<%= link_to 'Back', apply_project_masters_path %> diff --git a/app/views/apply_project_masters/show.html.erb b/app/views/apply_project_masters/show.html.erb new file mode 100644 index 000000000..a7edc11ff --- /dev/null +++ b/app/views/apply_project_masters/show.html.erb @@ -0,0 +1,5 @@ +

    <%= 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 @@
    + <%= apply_super_user(@open_source_project, User.current) %>
    + + + + + + +<% @no_uses.each do |no_use| %> + + + + + +<% end %> +
    <%= 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?' } %>
    + +
    + +<%= link_to 'New No use', new_no_use_path %> diff --git a/app/views/no_uses/new.html.erb b/app/views/no_uses/new.html.erb new file mode 100644 index 000000000..fb295879c --- /dev/null +++ b/app/views/no_uses/new.html.erb @@ -0,0 +1,5 @@ +

    New no_use

    + +<%= render 'form' %> + +<%= link_to 'Back', no_uses_path %> diff --git a/app/views/no_uses/show.html.erb b/app/views/no_uses/show.html.erb new file mode 100644 index 000000000..1e580700c --- /dev/null +++ b/app/views/no_uses/show.html.erb @@ -0,0 +1,5 @@ +

    <%= 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 @@ <%= @open_source_project.url%> + <%= no_use_link(topic, User.current) %> - - <%= image_tag( "/images/sidebar/tags.png") %> - <%= render :partial => 'tags/tag_name', :locals => {:obj => topic,:object_flag => "9",:non_list_all => true }%> - - - + + <%= image_tag( "/images/sidebar/tags.png") %> + <%= render :partial => 'tags/tag_name', :locals => {:obj => topic,:object_flag => "9",:non_list_all => true }%> + + - + - + <% end %>
    + diff --git a/app/views/relative_memos/show.html.erb b/app/views/relative_memos/show.html.erb index e69de29bb..69ea0de41 100644 --- a/app/views/relative_memos/show.html.erb +++ b/app/views/relative_memos/show.html.erb @@ -0,0 +1,142 @@ +
    +
    +
    <%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) if @memo.author %>
    +

    <%=link_to @memo.author.name, user_path(@memo.author) if @memo.author%>

    +
    +
    +
    + + <%#= link_to( + l(:button_quote), + {:action => 'quote', :id => @memo}, + :remote => true, + :method => 'get', + :title => l(:button_quote) + )if !@memo.locked? && User.current.logged? %> + + <%#= link_to( + image_tag('edit.png'), + {:action => 'edit', :id => @memo}, + :method => 'get', + :title => l(:button_edit) + ) if @memo.editable_by?(User.current) %> + + <%#= link_to( + l(:button_delete), + {:action => 'destroy', :id => @memo}, + :method => :delete, + :data => {:confirm => l(:text_are_you_sure)}, + :title => l(:button_delete) + ) if @memo.destroyable_by?(User.current) %> + + +
    + +
    <%= label_tag l(:field_subject) %>: <%=h @memo.subject %>
    +
    + + <%= raw @memo.content %> +

    + <% if @memo.attachments.any?%> + <% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %> + <%= render :partial => 'attachments/links', :locals => {:attachments => @memo.attachments, :options => options} %> + <% end %> +

    +
    +
    <%= authoring @memo.created_at, @memo.author.name if @memo.author %>
    + +
    +
    +
    +
    +

    <%= l(:label_reply_plural) %> (<%= @replies.nil? ? 0 : @replies.size %>)

    + <% pages_count = @reply_pages.offset %> + <% @replies.each do |reply| %> +
    "> +

    <%= pages_count += 1 %>楼 :

    +
    + + <%#= link_to( + l(:button_quote), + {:action => 'quote', :id => reply}, + :remote => true, + :method => 'get', + :title => l(:button_quote) + )if !@memo.locked? && User.current.logged? %> + + <%#= link_to( + image_tag('edit.png'), + {:action => 'edit', :id => reply}, + :title => l(:button_edit) + ) if reply.editable_by?(User.current) %> + + <%#= link_to( + l(:button_delete), + {:action => 'destroy', :id => reply}, + :method => :delete, + :data => {:confirm => l(:text_are_you_sure)}, + :title => l(:button_delete) + ) if reply.destroyable_by?(User.current) %> + +
    + + + + + + + + + +
    + <%= link_to image_tag(url_to_avatar(reply.author), :class => "avatar"), user_path(reply.author) if reply.author %> + +
    <%=h reply.content.html_safe %>
    + +

    + <% if reply.attachments.any?%> + <% options = {:author => true, :deletable => reply.deleted_attach_able_by?(User.current) } %> + <%= render :partial => 'attachments/links', :locals => {:attachments => reply.attachments, :options => options} %> + <% end %> +

    +
    <%= authoring reply.created_at, reply.author.name if reply.author %>
    +
    + <% end %> + +
    + +<% if User.current.login? %> +
    + <%#= render :partial => 'memos/reply_box' %> +
    +<% else %> +
    + <%= l(:label_user_login_tips) %> + <%= link_to l(:label_user_login_new), signin_path %> +
    +
    +<% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 4aac82bf2..1877e1d33 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1806,3 +1806,5 @@ zh: label_contest_reason: 参赛宣言: label_notification: 通知 label_sumbit_empty: 搜索内容不能为空 + no_use: 没有帮助 + cancel_no_use: 撤销没有帮助 diff --git a/config/routes.rb b/config/routes.rb index 0b17651c5..d357eff01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,9 +17,12 @@ RedmineApp::Application.routes.draw do resources :no_uses + delete 'no_uses', :to => 'no_uses#delete' + resources :apply_project_masters + delete 'apply_project_masters', :to => 'apply_project_masters#delete' resources :open_source_projects do diff --git a/db/migrate/20140404031622_add_view_count_to_relative_memos.rb b/db/migrate/20140404031622_add_view_count_to_relative_memos.rb new file mode 100644 index 000000000..17eb95b70 --- /dev/null +++ b/db/migrate/20140404031622_add_view_count_to_relative_memos.rb @@ -0,0 +1,6 @@ +class AddViewCountToRelativeMemos < ActiveRecord::Migration + def change + add_column :relative_memos, :viewed_count_crawl, :int, default: 0 + add_column :relative_memos, :viewed_count_local, :int, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 40523093c..f0969c398 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 => 20140403113341) do +ActiveRecord::Schema.define(:version => 20140404031622) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -201,6 +201,7 @@ ActiveRecord::Schema.define(:version => 20140403113341) do t.string "setup_time" t.string "endup_time" t.string "class_period" + t.integer "school_id" end create_table "custom_fields", :force => true do |t| @@ -769,18 +770,20 @@ ActiveRecord::Schema.define(:version => 20140403113341) do add_index "queries", ["user_id"], :name => "index_queries_on_user_id" create_table "relative_memos", :force => true do |t| - t.integer "osp_id", :null => false + t.integer "osp_id", :null => false t.integer "parent_id" - t.string "subject", :null => false - t.text "content", :null => false + t.string "subject", :null => false + t.text "content", :null => false t.integer "author_id" - t.integer "replies_count", :default => 0 + t.integer "replies_count", :default => 0 t.integer "last_reply_id" - t.boolean "lock", :default => false - t.boolean "sticky", :default => false - t.boolean "is_quote", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.boolean "lock", :default => false + t.boolean "sticky", :default => false + t.boolean "is_quote", :default => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "viewed_count_crawl", :default => 0 + t.integer "viewed_count_local", :default => 0 end create_table "repositories", :force => true do |t| From d381423c0e63626562306c5a2654ac7e234988f0 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Sun, 6 Apr 2014 22:12:16 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=89=88?= =?UTF-8?q?=E4=B8=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open_source_projects_controller.rb | 29 +++++++ app/helpers/apply_project_masters_helper.rb | 2 +- app/models/apply_project_master.rb | 1 + app/models/open_source_project.rb | 22 +++++ app/views/layouts/base_opensource_p.html.erb | 27 ++++-- .../open_source_projects/_os_project.html.erb | 6 +- app/views/open_source_projects/index.html.erb | 43 ++++++++-- .../master_apply.html.erb | 83 +++++++++++++++++++ config/locales/zh.yml | 4 + config/routes.rb | 5 +- 10 files changed, 202 insertions(+), 20 deletions(-) create mode 100644 app/views/open_source_projects/master_apply.html.erb diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index 55892d457..2c1e1e049 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -1,5 +1,8 @@ class OpenSourceProjectsController < ApplicationController + before_filter :find_osp, :only => [:master_apply] + before_filter :require_master, :only => [:master_apply] + helper :sort include SortHelper helper :apply_project_masters @@ -9,6 +12,9 @@ class OpenSourceProjectsController < ApplicationController # GET /open_source_projects # GET /open_source_projects.json def index + @app_dir = params[:app_dir] + @language = params[:language] + @created_at = params[:created_at] per_page_option = 10 @open_source_projects = OpenSourceProject.all @@ -23,6 +29,18 @@ class OpenSourceProjectsController < ApplicationController format.json { render json: @open_source_projects } end end + + def master_apply + @apply = @open_source_project.apply_tips + @applicants = @open_source_project.applicants + + respond_to do |format| + format.html { + render :layout => "base_opensource_p" + } + format.json { render json: @open_source_project } + end + end # GET /open_source_projects/1 # GET /open_source_projects/1.json @@ -127,4 +145,15 @@ class OpenSourceProjectsController < ApplicationController format.json { head :no_content } end end + + private + + def require_master + render_403 unless @open_source_project.admin?(User.current) + end + + def find_osp + @open_source_project = OpenSourceProject.find(params[:id]) + render_404 unless @open_source_project.present? + end end diff --git a/app/helpers/apply_project_masters_helper.rb b/app/helpers/apply_project_masters_helper.rb index a2dccba35..565f8ea04 100644 --- a/app/helpers/apply_project_masters_helper.rb +++ b/app/helpers/apply_project_masters_helper.rb @@ -11,7 +11,7 @@ module ApplyProjectMastersHelper css = apply_css(objects) << options[0].to_s - text = applied ? (allowed ? ("123") : ("123")) : ("231") + text = applied ? (allowed ? l(:you_are_master) : l(:cancel_apply)) : l(:apply_master) url = apply_project_masters_path( :object_type => objects.first.class.to_s.underscore, diff --git a/app/models/apply_project_master.rb b/app/models/apply_project_master.rb index f4d21b2bb..13bd2f372 100644 --- a/app/models/apply_project_master.rb +++ b/app/models/apply_project_master.rb @@ -1,5 +1,6 @@ class ApplyProjectMaster < ActiveRecord::Base # attr_accessible :title, :body + # status 1是申请者,2是版主 belongs_to :apply, :polymorphic => true belongs_to :user diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 320b79f7e..ca2d0be18 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -7,6 +7,10 @@ class OpenSourceProject < ActiveRecord::Base has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy has_many :tags, :through => :project_tags, :class_name => 'Tag' has_many :project_tags, :class_name => 'ProjectTags' + has_many :masters, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 2" + has_many :admin, :through => :masters, :class_name => 'User' + has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1" + has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user acts_as_taggable @@ -22,10 +26,20 @@ class OpenSourceProject < ActiveRecord::Base end def applied_by?(user) + self.applies.each do |apply| + if apply.user_id == user.id + return true + end + end false end def allowed?(user) + self.applies.each do |apply| + if apply.user_id == user.id and apply.status == 2 + return true + end + end false end @@ -42,6 +56,14 @@ class OpenSourceProject < ActiveRecord::Base ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}" end + def admin?(user) + if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present? + return true + else + return false + end + end + def reset_counters! self.class.reset_counters!(id) end diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index b982a3a19..3f64996c7 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -47,13 +47,14 @@ <% @open_source_project = OpenSourceProject.find(params[:id])%> - + @@ -104,19 +105,35 @@
    - <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project,:object_flag => "7"}%> + <%= render :partial => 'tags/tag', :locals => {:obj => @open_source_project, :object_flag => "7"}%>
    + + <% if @open_source_project.admin?(User.current) %> +
    +
    + 管理 +
    + +
    + +
    + <% end %> +
    -
    <%#= -
    +
    + <%#=
    %> <%= render_flash_messages %> diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb index 133f6c4cc..c609110de 100644 --- a/app/views/open_source_projects/_os_project.html.erb +++ b/app/views/open_source_projects/_os_project.html.erb @@ -11,7 +11,7 @@

    - <%= 1%> + <%= project.users_count %> <%= content_tag('span', l(:label_x_follow_people,:count =>0)) %>

    @@ -21,12 +21,12 @@

    - <%= 1 %> + <%= project.commit_count %> <%= content_tag('span', l(:label_since_last_commits)) %>

    - <%= 1 %> + <%= project.code_line %> <%= content_tag('span', "行代码") %>

    diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index 032e0a82b..0df5a69d0 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -141,16 +141,17 @@ li {
    图片<%= image_tag(url_to_avatar(Project.find(2)), :class => 'avatar2') %>
    <%= @open_source_project.name %>
    -
    +
    +
    <%= apply_super_user(@open_source_project, User.current) %>
    - + + @@ -33,7 +42,7 @@ - + From a611ed4848579d9ab51a4ac0d46efa6cfd0620cf Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Sat, 19 Apr 2014 11:03:54 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=8C=89?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=90=9C=E7=B4=A2=EF=BC=8C=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=BA=9B=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/open_source_project.rb | 5 +++-- app/views/open_source_projects/_os_project.html.erb | 4 ++-- app/views/open_source_projects/index.html.erb | 9 +++++---- ...700_change_description_type_to_open_source_project.rb | 9 +++++++++ db/schema.rb | 8 ++++---- 5 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20140411011700_change_description_type_to_open_source_project.rb diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 114a95cc4..95b4444e1 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -1,5 +1,5 @@ class OpenSourceProject < ActiveRecord::Base - attr_accessible :String + attr_accessible :name include Redmine::SafeAttributes has_many :applies, :class_name => "ApplyProjectMaster", :as => :apply, :dependent => :delete_all @@ -12,6 +12,7 @@ class OpenSourceProject < ActiveRecord::Base has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1" has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user + validates_uniqueness_of :name acts_as_taggable @@ -41,7 +42,7 @@ class OpenSourceProject < ActiveRecord::Base } scope :filter_time, lambda {|args| - nil + where("YEAR(#{OpenSourceProject.table_name}.created_at) = ?", args) unless args.nil? } # def filter_app_dir(app_dir) diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb index 937fd3b1b..cae5b963b 100644 --- a/app/views/open_source_projects/_os_project.html.erb +++ b/app/views/open_source_projects/_os_project.html.erb @@ -57,12 +57,12 @@ <%= content_tag('span', "项目来源:")%><%= link_to project.url, project.url %>
    - <%= content_tag('span', "数据更新时间") %><%= content_tag('span', format_time(project.created_at)) %> + <%= content_tag('span', "数据更新时间:") %><%= content_tag('span', project.date_collected) %>
    <%= image_tag( "/images/sidebar/tags.png") %> - <%= render :partial => 'tags/tag_name', :locals => {:obj => project,:object_flag => "2",:non_list_all => true }%> + <%= render :partial => 'tags/tag_name', :locals => {:obj => project,:object_flag => "7",:non_list_all => true }%>
    diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index 61d4aa60c..e83417dbb 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -2,7 +2,7 @@ <%= form_tag(:controller => 'open_source_projects', :action => "search", :method => :get) do %>
    <%= image_tag(url_to_avatar(Project.find(2)), :class => 'avatar2') %><%= image_tag('../images/avatars/Project/0', :class => 'avatar2') %>
    <%= @open_source_project.name %> diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb index c609110de..e484ad714 100644 --- a/app/views/open_source_projects/_os_project.html.erb +++ b/app/views/open_source_projects/_os_project.html.erb @@ -1,6 +1,6 @@
    - 图片 + <%= image_tag('../images/avatars/Project/0', :class => 'avatar2') %>

    diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb index f4400ed39..9cb6c46af 100644 --- a/app/views/open_source_projects/_show_topics.html.erb +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -8,7 +8,8 @@ <% memos.each do |topic| %> - +
    <%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%><%= link_to image_tag(url_to_avatar(topic.author), :class => "avatar"), user_path(topic.author) if topic.author%> + <%= image_tag('../images/avatars/User/0', :class => "avatar") unless topic.author%> diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index 0df5a69d0..61d4aa60c 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -174,10 +174,10 @@ li { - +
    贡献者 讨论 <%= l(:label_project_issues) %> 代码提交
    diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb index 9cb6c46af..3f51b06c7 100644 --- a/app/views/open_source_projects/_show_topics.html.erb +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -23,6 +23,15 @@
    回答

    + + + + + + + +
    <%= link_to (topic.viewed_count_crawl+topic.viewed_count_local), forum_memo_path(topic.open_source_project, topic) %>
    浏览
    <%= @open_source_project.url%> 帖子来源:<%= link_to @open_source_project.url, @open_source_project.url%> <%= no_use_link(topic, User.current) %>
    - + - - + +
    <%= l(:label_project_deposit) %>开源项目社区 <%= l(:label_user_location) %> : @@ -13,8 +13,8 @@
    <%= link_to request.host()+"/projects", :controller => 'projects', :action => 'index', :project_type => 0 %> <%= link_to l(:field_homepage), home_path %> > <%= link_to l(:label_project_deposit), :controller => 'projects', :action => 'index', :project_type => 0 %><%= link_to request.host()+"/open_source_projects", :controller => 'open_source_projects', :action => 'index' %> <%= link_to l(:field_homepage), home_path %> > <%= link_to "开源项目社区", :controller => 'open_source_projects', :action => 'index' %>
    <% end %> @@ -179,13 +179,14 @@ li { <%= link_to "C", open_source_projects_path(:language => "c", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %> <%= link_to "C#", open_source_projects_path(:language => "c#", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %> <%= link_to "ruby", open_source_projects_path(:language => "ruby", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %> - <%= link_to "其他", open_source_projects_path(:language => "其他", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %> + <%#= link_to "其他", open_source_projects_path(:language => "其他", :app_dir => @app_dir, :created_at => @created_at), :class => "nav-more J_More show" %> - + + <%= link_to request.host()+"/open_source_projects", :controller => 'open_source_projects', :action => 'index' %> + <%= link_to l(:field_homepage), home_path %> > <%= link_to "开源项目社区", :controller => 'open_source_projects', :action => 'index' %> > <%=link_to @open_source_project.name, open_source_project_path(@open_source_project) %> + @@ -119,10 +122,10 @@
    -
    <% end %> diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index e83417dbb..6aca9d2d4 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -144,10 +144,9 @@ li {
  • 查找条件>
  • + - <%= @app_dir%> - <%= @language%> - <%= @created_at%> + <%= show_condition(@app_dir, @language, @created_at) %>
  • <%= @os_project_count %> 个开源项目
  • From 28b10ed3fd0200d89d0499946898d8be86fd2705 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Tue, 22 Apr 2014 08:21:35 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6=E8=83=BD=E5=AF=B9?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=BF=9B=E8=A1=8C=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open_source_projects_controller.rb | 34 ++++--- app/helpers/open_source_projects_helper.rb | 22 +---- app/models/open_source_project.rb | 91 ++++++++++--------- app/views/open_source_projects/index.html.erb | 42 ++++----- config/routes.rb | 1 + 5 files changed, 97 insertions(+), 93 deletions(-) diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index a77ac858e..fa1f19058 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -18,6 +18,7 @@ class OpenSourceProjectsController < ApplicationController per_page_option = 10 @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at) + @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present? @os_project_count = @open_source_projects.count @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] @@ -65,17 +66,6 @@ class OpenSourceProjectsController < ApplicationController order(sort_clause). all - - - # @offset, @limit = api_offset_and_limit({:limit => 10}) - # @forum = Forum.find(params[:id]) - # @memos_all = @forum.topics - # @topic_count = @memos_all.count - # @topic_pages = Paginator.new @topic_count, @limit, params['page'] - - # @offset ||= @topic_pages.offset - # @memos = @memos_all.offset(@offset).limit(@limit).all - respond_to do |format| format.html { render :layout => "base_opensource_p" @@ -148,6 +138,28 @@ class OpenSourceProjectsController < ApplicationController end end + def remove_condition + @app_dir = params[:app_dir] + @language = params[:language] + @created_at = params[:created_at] + redirect_to open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => @created_at, :name => params[:name]) + end + + def search + per_page_option = 10 + + @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at) + @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present? + + @os_project_count = @open_source_projects.count + @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] + + @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page) + + redirect_to open_source_projects_path(:name => params[:name]) + + end + private def require_master diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb index 1ae851569..6c9060c18 100644 --- a/app/helpers/open_source_projects_helper.rb +++ b/app/helpers/open_source_projects_helper.rb @@ -1,22 +1,9 @@ module OpenSourceProjectsHelper - def render_opensource_project(os_projects) - s=''.html_safe - s << "" - end - - def show_condition(app_dir, language, created_at) + def show_condition(app_dir, language, created_at, name) s=''.html_safe unless app_dir.nil? s_temp = content_tag('a', app_dir) - temp = link_to 'x', {:controller => "tags", :action => "remove_tag"}, :remote => true + temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :language => language, :created_at => created_at, :name => name} temp = content_tag('span', temp, :class => 'del') s_temp << temp s_temp = content_tag('span', s_temp, :class => 'tag_show') @@ -25,7 +12,7 @@ module OpenSourceProjectsHelper end unless language.nil? s_temp = content_tag('a', language) - temp = link_to 'x', {:controller => "tags", :action => "remove_tag"}, :remote => true + temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :created_at => created_at, :name => name} temp = content_tag('span', temp, :class => 'del') s_temp << temp s_temp = content_tag('span', s_temp, :class => 'tag_show') @@ -33,7 +20,7 @@ module OpenSourceProjectsHelper end unless created_at.nil? s_temp = content_tag('a', created_at) - temp = link_to 'x', {:controller => "tags", :action => "remove_tag"}, :remote => true + temp = link_to 'x', {:controller => "open_source_projects", :action => "remove_condition", :app_dir => app_dir, :language => language, :name => name} temp = content_tag('span', temp, :class => 'del') s_temp << temp s_temp = content_tag('span', s_temp, :class => 'tag_show') @@ -42,5 +29,4 @@ module OpenSourceProjectsHelper s = content_tag('div', s, :id => 'tags') # s = content_tag('div', s, :class => 'tags') end - end diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 95b4444e1..e526dc921 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -1,6 +1,6 @@ class OpenSourceProject < ActiveRecord::Base attr_accessible :name - + include Redmine::SafeAttributes has_many :applies, :class_name => "ApplyProjectMaster", :as => :apply, :dependent => :delete_all has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy @@ -11,28 +11,36 @@ class OpenSourceProject < ActiveRecord::Base has_many :admin, :through => :masters, :class_name => 'User' has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1" has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user - + validates_uniqueness_of :name - - acts_as_taggable - + + acts_as_taggable + scope :applied_by, lambda { |user_id| { :include => :apply_project_master, - :conditions => ["#{ApplyProjectMaster.table_name}.user_id = ?", user_id] } - } - + :conditions => ["#{ApplyProjectMaster.table_name}.user_id = ?", user_id] + } + } + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where("LOWER(name) LIKE :p OR LOWER(description) LIKE :p ", :p => pattern) + end + } def filter(app_dir, language, created_at) filter_app_dir(app_dir).filter_language(language).filter_time(created_at) end - + def self.filter(app_dir, language, created_at) self.filter_app_dir(app_dir).filter_language(language).filter_time(created_at) end - + scope :filter_app_dir, lambda {|args| nil } - + scope :filter_language, lambda {|*arg| if arg[0].nil? where(nil) @@ -40,88 +48,87 @@ class OpenSourceProject < ActiveRecord::Base tagged_with(arg).order('updated_at desc') end } - + scope :filter_time, lambda {|args| where("YEAR(#{OpenSourceProject.table_name}.created_at) = ?", args) unless args.nil? } - + # def filter_app_dir(app_dir) - # nil + # nil # end -# + # # def self.filter_app_dir(app_dir) - # nil + # nil # end -# + # # def filter_language(language) - # nil + # nil # end -# + # # def self.filter_language(language) - # nil + # nil # end -# + # # def filter_time(created_at) - # nil + # nil # end -# + # # def self.filter_time(created_at) - # nil + # nil # end - - + def short_description(length = 255) description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end - + def applied_by?(user) self.applies.each do |apply| if apply.user_id == user.id - return true - end + return true + end end false end - + def allowed?(user) self.applies.each do |apply| if apply.user_id == user.id and apply.status == 2 - return true - end + return true + end end false end - + def set_apply(user, flag=true) flag ? set_filter(user) : remove_filter(user) end - + def set_filter(user) self.applies << ApplyProjectMaster.new(:user => user, :status => 1) end - + def remove_filter(user) return nil unless user && user.is_a?(User) ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}" end - + def admin?(user) if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present? - return true - else - return false + return true + else + return false end end - + def reset_counters! self.class.reset_counters!(id) end - + def self.reset_counters!(id) osp_id = id.to_i update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," + " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," + " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})", ["id = ?", osp_id]) - end + end end diff --git a/app/views/open_source_projects/index.html.erb b/app/views/open_source_projects/index.html.erb index 6aca9d2d4..0e9f1008a 100644 --- a/app/views/open_source_projects/index.html.erb +++ b/app/views/open_source_projects/index.html.erb @@ -8,7 +8,6 @@ @@ -144,9 +143,8 @@ li {
  • 查找条件>
  • - - <%= show_condition(@app_dir, @language, @created_at) %> + <%= show_condition(@app_dir, @language, @created_at, params[:name]) %>
  • <%= @os_project_count %> 个开源项目
  • @@ -160,24 +158,24 @@ li { @@ -107,7 +120,11 @@ - +
    - <%= link_to image_tag(url_to_avatar(reply.author), :class => "avatar"), user_path(reply.author) if reply.author %> + <% if reply.author%> + <%= link_to image_tag(url_to_avatar(reply.author), :class => "avatar"), user_path(reply.author) %> + <% else %> + <%= image_tag('../images/avatars/User/0', :class => "avatar") %> + <% end %>
    <%=h reply.content.html_safe %>
    @@ -121,7 +138,12 @@
    <%= authoring reply.created_at, reply.author.name if reply.author %> + <% if reply.author %> + <%= authoring reply.created_at, reply.author.name %> + <% else %> + <%= added_time reply.created_at %> + <% end %>
    diff --git a/app/views/tags/_show_open_source_projects.html.erb b/app/views/tags/_show_open_source_projects.html.erb new file mode 100644 index 000000000..2c8bc6374 --- /dev/null +++ b/app/views/tags/_show_open_source_projects.html.erb @@ -0,0 +1,15 @@ +
    +<% if projects_results.size > 0 %> +
    +<% projects_results.each do |prj| %> +
    +

    + <%= l(:label_tags_project_name) %><%= link_to "#{prj.name}",:controller => "open_source_projects",:action => "show",:id => prj.id %> +
    + <%= l(:label_tags_project_description) %><%= prj.short_description %> +

    +
    +
    +<% end %> +<% end %> +
    diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index c67ece520..0dfabd7fe 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -19,6 +19,10 @@ <% when show_flag == '6'%> <%= l(:label_attachment)%>(<%= @results_count %>) <%= render :partial => "show_attachments",:locals => {:attachments_results => attachments_results}%> + <% when show_flag == '7'%> + <%#= l(:label_attachment)%> + 开源项目:(<%= @results_count %>) + <%= render :partial => "show_open_source_projects",:locals => {:projects_results => open_source_projects_results}%> <% else %> <%= l(:label_tags_all_objects)%> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 17ac58184..068017c46 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -22,13 +22,15 @@ <%= l(:label_project_plural) %>(<%= @projects_tags_num %>) | <%= l(:label_user_plural) %>(<%= @users_tags_num %>) | <%= l(:label_tags_call)%>(<%= @bids_tags_num %>) | - <%= l(:field_filename)%>(<%= @attachments_tags_num %>) + <%= l(:field_filename)%>(<%= @attachments_tags_num %>) | + 开源项目(<%= @open_source_projects_num %>)
    <%# 求工厂模式重构 %> <%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_results, :projects_results => @projects_results,:users_results => @users_results , - :bids_results=>@bids_results,:forums_results => @forums_results, :attachments_results => @attachments_results, :show_flag => @obj_flag}%> + :bids_results=>@bids_results,:forums_results => @forums_results, :attachments_results => @attachments_results, + :open_source_projects_results => @open_source_projects_results, :show_flag => @obj_flag}%>
    diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 77db00aa8..e6ebbfeb5 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -828,6 +828,7 @@ zh: label_feeds_access_key_created_on: "RSS存取键是在 %{value} 之前建立的" label_module_plural: 模块 label_added_time_by: "由 %{author} 在 %{age} 之前添加" + label_added_time: "在 %{age} 之前添加" label_updated_time: " 更新于 %{value} 之前" label_updated_time_by: "由 %{author} 更新于 %{age} 之前" label_jump_to_a_project: 选择一个项目... From 87c70909beac2dc8cea45f3b296ef752b7a2fbca Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Mon, 28 Apr 2014 09:13:57 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=9C=A8=E5=BC=80?= =?UTF-8?q?=E6=BA=90=E7=A4=BE=E5=8C=BA=E6=B7=BB=E5=8A=A0=E5=B8=96=E5=AD=90?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=B8=96?= =?UTF-8?q?=E5=AD=90=E7=9A=84URL,=E5=8D=B3=E5=B8=96=E5=AD=90=E6=9D=A5?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/relative_memos_controller.rb | 25 ++++-- app/models/relative_memo.rb | 3 +- app/views/layouts/base_opensource_p.html.erb | 1 + .../_show_topics.html.erb | 2 +- app/views/open_source_projects/show.html.erb | 12 +-- ...0140428005537_add_url_to_relative_memos.rb | 5 ++ db/schema.rb | 77 ++++++++++++++++++- 7 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20140428005537_add_url_to_relative_memos.rb diff --git a/app/controllers/relative_memos_controller.rb b/app/controllers/relative_memos_controller.rb index 70d2f00c2..4c891e0a6 100644 --- a/app/controllers/relative_memos_controller.rb +++ b/app/controllers/relative_memos_controller.rb @@ -8,6 +8,8 @@ class RelativeMemosController < ApplicationController include NoUsesHelper before_filter :find_memo, :except => [:new, :create] + before_filter :find_osp, :only => [:create] + before_filter :require_login, :only => [:new, :create] layout 'base_opensource_p' @@ -88,15 +90,22 @@ class RelativeMemosController < ApplicationController # POST /open_source_projects # POST /open_source_projects.json def create - @open_source_project = OpenSourceProject.new(params[:open_source_project]) + @memo = RelativeMemo.new(params[:relative_memo]) + # @memo.url = "http://forge.trustie.net/open_source_projects" + @memo.osp_id = params[:open_source_project_id] + @memo.author_id = User.current.id + + @memo.save_attachments(params[:attachments] || (params[:relative_memo] && params[:relative_memo][:uploads])) respond_to do |format| - if @open_source_project.save - format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.'} - format.json { render json: @open_source_project, status: :created, location: @open_source_project } + if @memo.save + format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } + format.json { render json: @memo, status: :created, location: @memo } else - format.html { render action: "new" } - format.json { render json: @open_source_project.errors, status: :unprocessable_entity } + flash[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" + # back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id) + format.html { redirect_to back_memo_or_forum_url}#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" } + format.json { render json: @memo.errors, status: :unprocessable_entity } end end end @@ -145,4 +154,8 @@ class RelativeMemosController < ApplicationController render_404 nil end + + def back_memo_url + open_source_project_relative_memo_path(@open_source_project, (@memo.parent_id.nil? ? @memo : @memo.parent_id)) + end end diff --git a/app/models/relative_memo.rb b/app/models/relative_memo.rb index a1532dcb2..eeef0eb9c 100644 --- a/app/models/relative_memo.rb +++ b/app/models/relative_memo.rb @@ -10,6 +10,7 @@ class RelativeMemo < ActiveRecord::Base has_many :no_uses, :as => :no_use, :dependent => :delete_all acts_as_taggable + acts_as_attachable validates_presence_of :osp_id, :subject #validates :content, presence: true @@ -106,7 +107,7 @@ class RelativeMemo < ActiveRecord::Base RelativeMemo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) parent.update_attribute(:updated_at, Time.now) end - forum.reset_counters! + # forum.reset_counters! end def sticky? diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index ce6b7cb22..c6127f832 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -13,6 +13,7 @@ <%= javascript_heads %> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> + <%= javascript_include_tag "ckeditor/ckeditor.js" %> <%= yield :header_tags -%> diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb index 3f51b06c7..47903d5c4 100644 --- a/app/views/open_source_projects/_show_topics.html.erb +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -42,7 +42,7 @@ - 帖子来源:<%= link_to @open_source_project.url, @open_source_project.url%> + 帖子来源:<%= link_to topic.url, topic.url%> <%= no_use_link(topic, User.current) %> diff --git a/app/views/open_source_projects/show.html.erb b/app/views/open_source_projects/show.html.erb index 8b04183b1..0459e2399 100644 --- a/app/views/open_source_projects/show.html.erb +++ b/app/views/open_source_projects/show.html.erb @@ -2,7 +2,7 @@