You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

org_subfields_controller.rb 7.8 kB

10 years ago
10 years ago
​
​
10 years ago
​
10 years ago
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. class OrgSubfieldsController < ApplicationController
  2. helper :attachments
  3. include FilesHelper
  4. layout 'base_org'
  5. def create
  6. if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0
  7. @res = true
  8. @organization = Organization.find(params[:organization_id])
  9. @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id], :priority => @organization.org_subfields.order("priority").last.priority + 1)
  10. if !params[:sub_dir].blank?
  11. sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
  12. "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'"
  13. if SubfieldSubdomainDir.find_by_sql(sql).count == 0
  14. SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase)
  15. end
  16. end
  17. #默认类型为帖子
  18. @subfield.update_attributes(:field_type => params[:field_type]||"Post")
  19. # admin配置的类型
  20. update_status_by_type(@subfield, params[:field_type]||"Post")
  21. else
  22. @res = false
  23. end
  24. end
  25. # status类型说明,详见SubField
  26. def update_status_by_type subfield, type
  27. case type
  28. when "Resource"
  29. subfield.update_attribute(:status, 6)
  30. when "Comptec"
  31. subfield.update_attribute(:status, 6)
  32. when "Compstu"
  33. subfield.update_attribute(:status, 7)
  34. when "Comppro"
  35. subfield.update_attribute(:status, 5)
  36. when "Compcou"
  37. subfield.update_attribute(:status, 2)
  38. when "Compact"
  39. subfield.update_attribute(:status, 4)
  40. end
  41. end
  42. def show
  43. @flag = params[:flag] || false
  44. sort = ""
  45. @sort = ""
  46. @order = ""
  47. @is_remote = false
  48. if params[:id]
  49. @organization = Organization.find(params[:id])
  50. else
  51. domain = Secdomain.where("subname=?", request.subdomain).first
  52. begin
  53. @organization = Organization.find(domain.pid)
  54. rescue
  55. render_404
  56. return
  57. end
  58. end
  59. if @organization.is_public? or User.current.admin? or User.current.member_of_org?(@organization)
  60. @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+
  61. "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+
  62. " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first
  63. if @org_subfield.nil?
  64. render_404
  65. return
  66. end
  67. if @org_subfield.field_type == 'Post'
  68. @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
  69. @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
  70. #redirect_to organization_path(@organization, :org_subfield_id => @org_subfield.id)
  71. else
  72. if params[:sort]
  73. params[:sort].split(",").each do |sort_type|
  74. order_by = sort_type.split(":")
  75. case order_by[0]
  76. when "filename"
  77. attribute = "filename"
  78. when "size"
  79. attribute = "filesize"
  80. when "attach_type"
  81. attribute = "attachtype"
  82. when "content_type"
  83. attribute = "created_on"
  84. when "field_file_dense"
  85. attribute = "is_public"
  86. when "downloads"
  87. attribute = "downloads"
  88. when "created_on"
  89. attribute = "created_on"
  90. when "quotes"
  91. attribute = "quotes"
  92. else
  93. attribute = "created_on"
  94. end
  95. @sort = order_by[0]
  96. @order = order_by[1]
  97. if order_by.count == 1 && attribute
  98. sort += "#{Attachment.table_name}.#{attribute} asc "
  99. if sort_type != params[:sort].split(",").last
  100. sort += ","
  101. end
  102. elsif order_by.count == 2 && order_by[1]
  103. sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
  104. if sort_type != params[:sort].split(",").last
  105. sort += ","
  106. end
  107. end
  108. end
  109. else
  110. sort = "#{Attachment.table_name}.created_on desc"
  111. end
  112. @container_type = 2
  113. @containers = [OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
  114. @organization = Organization.find(@containers.first.organization_id)
  115. show_attachments @containers
  116. @tag_list = attachment_tag_list @all_attachments
  117. end
  118. @page = params[:page] || 1
  119. else
  120. render_403
  121. end
  122. #render :layout => 'base_org'
  123. end
  124. def destroy
  125. @subfield = OrgSubfield.find(params[:id])
  126. @organization = Organization.find(@subfield.organization_id)
  127. @subfield.destroy
  128. end
  129. def update
  130. @subfield = OrgSubfield.find(params[:id])
  131. @organization = Organization.find(@subfield.organization_id)
  132. @subfield.update_attributes(:name => params[:name])
  133. end
  134. def update_sub_dir
  135. @org_subfield = OrgSubfield.find(params[:id])
  136. sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
  137. "and org_subfields.organization_id=#{@org_subfield.organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'"
  138. if SubfieldSubdomainDir.find_by_sql(sql).count == 0
  139. if @org_subfield.subfield_subdomain_dir
  140. @sub_dir = @org_subfield.subfield_subdomain_dir
  141. @sub_dir = SubfieldSubdomainDir.update(@sub_dir.id, :name => params[:sub_dir_name])
  142. #@sub_dir.update_attribute(:name, params[:sub_dir_name])
  143. else
  144. @sub_dir = SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name])
  145. end
  146. @exist = false
  147. else
  148. @exist = true
  149. end
  150. end
  151. def update_priority
  152. @org_subfield = OrgSubfield.find(params[:id])
  153. @org_subfield.update_attribute(:priority, params[:priority].to_i)
  154. @organization = @org_subfield.organization
  155. end
  156. def update_status
  157. @subfield = OrgSubfield.find(params[:id])
  158. @organization = Organization.find(@subfield.organization_id)
  159. @subfield.update_attributes(:status => params[:status])
  160. end
  161. def show_attachments obj
  162. @attachments = []
  163. obj.each do |container|
  164. @attachments += container.attachments
  165. end
  166. @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments)
  167. @limit = 10
  168. @feedback_count = @all_attachments.count
  169. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  170. @offset ||= @feedback_pages.offset
  171. #@curse_attachments_all = @all_attachments[@offset, @limit]
  172. @obj_attachments = paginateHelper @all_attachments,10
  173. end
  174. #获取指定资源列表的TAG的集合以及每个TAG的数量,降序排序
  175. def attachment_tag_list attachments
  176. tag_list = Hash.new
  177. attachments.each do |attachment|
  178. attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1}
  179. end
  180. tag_list.sort {|a,b| b[1]<=>a[1]}
  181. end
  182. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...