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.7 kB

10 years ago
10 years ago
​
​
10 years ago
​
10 years ago
10 years ago
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. @organization = Organization.find(domain.pid)
  53. end
  54. if @organization.is_public? or User.current.admin? or User.current.member_of_org?(@organization)
  55. @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+
  56. "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+
  57. " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first
  58. if @org_subfield.nil?
  59. render_404
  60. return
  61. end
  62. if @org_subfield.field_type == 'Post'
  63. @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
  64. @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)
  65. #redirect_to organization_path(@organization, :org_subfield_id => @org_subfield.id)
  66. else
  67. if params[:sort]
  68. params[:sort].split(",").each do |sort_type|
  69. order_by = sort_type.split(":")
  70. case order_by[0]
  71. when "filename"
  72. attribute = "filename"
  73. when "size"
  74. attribute = "filesize"
  75. when "attach_type"
  76. attribute = "attachtype"
  77. when "content_type"
  78. attribute = "created_on"
  79. when "field_file_dense"
  80. attribute = "is_public"
  81. when "downloads"
  82. attribute = "downloads"
  83. when "created_on"
  84. attribute = "created_on"
  85. when "quotes"
  86. attribute = "quotes"
  87. else
  88. attribute = "created_on"
  89. end
  90. @sort = order_by[0]
  91. @order = order_by[1]
  92. if order_by.count == 1 && attribute
  93. sort += "#{Attachment.table_name}.#{attribute} asc "
  94. if sort_type != params[:sort].split(",").last
  95. sort += ","
  96. end
  97. elsif order_by.count == 2 && order_by[1]
  98. sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} "
  99. if sort_type != params[:sort].split(",").last
  100. sort += ","
  101. end
  102. end
  103. end
  104. else
  105. sort = "#{Attachment.table_name}.created_on desc"
  106. end
  107. @container_type = 2
  108. @containers = [OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
  109. @organization = Organization.find(@containers.first.organization_id)
  110. show_attachments @containers
  111. @tag_list = attachment_tag_list @all_attachments
  112. end
  113. @page = params[:page] || 1
  114. else
  115. render_403
  116. end
  117. #render :layout => 'base_org'
  118. end
  119. def destroy
  120. @subfield = OrgSubfield.find(params[:id])
  121. @organization = Organization.find(@subfield.organization_id)
  122. @subfield.destroy
  123. end
  124. def update
  125. @subfield = OrgSubfield.find(params[:id])
  126. @organization = Organization.find(@subfield.organization_id)
  127. @subfield.update_attributes(:name => params[:name])
  128. end
  129. def update_sub_dir
  130. @org_subfield = OrgSubfield.find(params[:id])
  131. sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
  132. "and org_subfields.organization_id=#{@org_subfield.organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'"
  133. if SubfieldSubdomainDir.find_by_sql(sql).count == 0
  134. if @org_subfield.subfield_subdomain_dir
  135. @sub_dir = @org_subfield.subfield_subdomain_dir
  136. @sub_dir = SubfieldSubdomainDir.update(@sub_dir.id, :name => params[:sub_dir_name])
  137. #@sub_dir.update_attribute(:name, params[:sub_dir_name])
  138. else
  139. @sub_dir = SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name])
  140. end
  141. @exist = false
  142. else
  143. @exist = true
  144. end
  145. end
  146. def update_priority
  147. @org_subfield = OrgSubfield.find(params[:id])
  148. @org_subfield.update_attribute(:priority, params[:priority].to_i)
  149. @organization = @org_subfield.organization
  150. end
  151. def update_status
  152. @subfield = OrgSubfield.find(params[:id])
  153. @organization = Organization.find(@subfield.organization_id)
  154. @subfield.update_attributes(:status => params[:status])
  155. end
  156. def show_attachments obj
  157. @attachments = []
  158. obj.each do |container|
  159. @attachments += container.attachments
  160. end
  161. @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments)
  162. @limit = 10
  163. @feedback_count = @all_attachments.count
  164. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  165. @offset ||= @feedback_pages.offset
  166. #@curse_attachments_all = @all_attachments[@offset, @limit]
  167. @obj_attachments = paginateHelper @all_attachments,10
  168. end
  169. #获取指定资源列表的TAG的集合以及每个TAG的数量,降序排序
  170. def attachment_tag_list attachments
  171. tag_list = Hash.new
  172. attachments.each do |attachment|
  173. attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1}
  174. end
  175. tag_list.sort {|a,b| b[1]<=>a[1]}
  176. end
  177. end

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