diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 5db82436b..df81ccaff 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -3,6 +3,13 @@ class OrgSubfieldsController < ApplicationController @subfield = OrgSubfield.create(:name => params[:name]) @organization = Organization.find(params[:organization_id]) @organization.org_subfields << @subfield + if !params[:sub_dir].blank? + sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ + "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" + if SubfieldSubdomainDir.find_by_sql(sql).count == 0 + SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir]) + end + end @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) end @@ -11,9 +18,58 @@ class OrgSubfieldsController < ApplicationController @subfield = @organization.org_subfields.first if @subfield.field_type == 'Post' redirect_to organization_path(@organization, :org_subfield_id => @subfield.id) - else - end + @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ + "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ + " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name=#{params[:name]}").first + if params[:sort] + params[:sort].split(",").each do |sort_type| + order_by = sort_type.split(":") + + case order_by[0] + when "filename" + attribute = "filename" + when "size" + attribute = "filesize" + when "attach_type" + attribute = "attachtype" + when "content_type" + attribute = "created_on" + when "field_file_dense" + attribute = "is_public" + when "downloads" + attribute = "downloads" + when "created_on" + attribute = "created_on" + when "quotes" + attribute = "quotes" + else + attribute = "created_on" + end + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end + end + end + else + sort = "#{Attachment.table_name}.created_on desc" + end + @container_type = 2 + @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] + @organization = Organization.find(@containers.first.organization_id) + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @page = params[:page] || 1 + render :layout => 'base_org' # @org_subfield = OrgSubfield.find(params[:id]) # @organization = @org_subfield.organization.id # @messages = [] diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index 0747114ca..146323a32 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -1,5 +1,6 @@ class OrgSubfield < ActiveRecord::Base belongs_to :organization, :foreign_key => :organization_id + has_one :subfield_subdomain_dir has_many :org_document_comments, :dependent => :destroy has_many :files has_many :org_subfield_messages, :dependent => :destroy diff --git a/app/models/subfield_subdomain_dir.rb b/app/models/subfield_subdomain_dir.rb new file mode 100644 index 000000000..9897e19ac --- /dev/null +++ b/app/models/subfield_subdomain_dir.rb @@ -0,0 +1,4 @@ +class SubfieldSubdomainDir < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :org_subfield +end diff --git a/app/views/org_subfields/show.html.erb b/app/views/org_subfields/show.html.erb index e69de29bb..660322c29 100644 --- a/app/views/org_subfields/show.html.erb +++ b/app/views/org_subfields/show.html.erb @@ -0,0 +1,581 @@ + +
+ <%= render :partial => 'files/subfield_files', locals: {org_subfield: @org_subfield} %> +
+ + + + + diff --git a/app/views/organizations/reject_apply_subdomain.js.erb b/app/views/organizations/reject_apply_subdomain.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/organizations/setting.html.erb b/app/views/organizations/setting.html.erb index 40cc295d9..59e2f2ad9 100644 --- a/app/views/organizations/setting.html.erb +++ b/app/views/organizations/setting.html.erb @@ -114,26 +114,30 @@

新增栏目

<%= form_tag url_for(:controller => 'org_subfields', :action => 'create', :organization_id => @organization.id), :id=> 'add_subfield_form',:remote => true do %> - -
-

域名目录(用户自定义url,可选)

- micros.trustie.net/ -
-
- -
- 确定 + +
+

域名目录(用户自定义url,可选)

+ <% if @organization.domain %> + <%= @organization.domain %>.trustie.net/ + <% else %> + 您还没有子域名,请先在左侧信息栏申请子域名 + <% end %> +
+
+ +
+ 确定 <% end %>
diff --git a/db/migrate/20160108093752_add_status_to_org_messages.rb b/db/migrate/20160108093752_add_status_to_org_messages.rb new file mode 100644 index 000000000..4fbe41fe1 --- /dev/null +++ b/db/migrate/20160108093752_add_status_to_org_messages.rb @@ -0,0 +1,5 @@ +class AddStatusToOrgMessages < ActiveRecord::Migration + def change + add_column :org_messages, :status, :integer, :default => 0 + end +end diff --git a/db/migrate/20160112085834_create_subfield_subdomain_dirs.rb b/db/migrate/20160112085834_create_subfield_subdomain_dirs.rb new file mode 100644 index 000000000..0ef66a94c --- /dev/null +++ b/db/migrate/20160112085834_create_subfield_subdomain_dirs.rb @@ -0,0 +1,9 @@ +class CreateSubfieldSubdomainDirs < ActiveRecord::Migration + def change + create_table :subfield_subdomain_dirs do |t| + t.integer :org_subfield_id + t.string :name + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b21b5057d..85eec4d85 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 => 20160108093752) do +ActiveRecord::Schema.define(:version => 20160112085834) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1656,6 +1656,13 @@ ActiveRecord::Schema.define(:version => 20160108093752) do add_index "students_for_courses", ["course_id"], :name => "index_students_for_courses_on_course_id" add_index "students_for_courses", ["student_id"], :name => "index_students_for_courses_on_student_id" + create_table "subfield_subdomain_dirs", :force => true do |t| + t.integer "org_subfield_id" + t.string "name" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "system_messages", :force => true do |t| t.integer "user_id" t.string "content" diff --git a/spec/factories/subfield_subdomain_dirs.rb b/spec/factories/subfield_subdomain_dirs.rb new file mode 100644 index 000000000..3a9878a82 --- /dev/null +++ b/spec/factories/subfield_subdomain_dirs.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :subfield_subdomain_dir do + + end + +end diff --git a/spec/models/subfield_subdomain_dir_spec.rb b/spec/models/subfield_subdomain_dir_spec.rb new file mode 100644 index 000000000..330a35c54 --- /dev/null +++ b/spec/models/subfield_subdomain_dir_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SubfieldSubdomainDir, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end