From 1668d44c7cc75d8f0d40ecaf2d79a78a0e89a8ad Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 28 Jan 2021 11:10:41 +0800 Subject: [PATCH] add multiple domain feature for one server --- app/models/site_construct.rb | 5 +- app/models/site_server.rb | 13 +++++ app/views/admin/site_panel/_form.html.erb | 47 ++++++++++++++----- .../site_panel/edit_server_info.html.erb | 37 ++++++++++++++- 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/app/models/site_construct.rb b/app/models/site_construct.rb index d52f2bc..eddb422 100644 --- a/app/models/site_construct.rb +++ b/app/models/site_construct.rb @@ -1,8 +1,9 @@ class SiteConstruct include Mongoid::Document include Mongoid::Timestamps - - SERVER_TYPES = SiteServer.all.map{|s| s.server_name} + def self.server_types + SiteServer.all.map{|s| s.server_name} + end SITE_TYPES = ["School","Gravity"] field :server_type diff --git a/app/models/site_server.rb b/app/models/site_server.rb index bbb6c16..6e1afd7 100644 --- a/app/models/site_server.rb +++ b/app/models/site_server.rb @@ -6,8 +6,21 @@ class SiteServer include OrbitModel::Status field :server_name , type: String ,default: '' field :domain_name , type: String ,default: '' + field :domain_names, type: Array, default: [] field :ip , type: String ,default: '' field :account , type: String ,default: '' field :password , type: String ,default: '' field :active , type: Boolean ,default: true + def domain_names + if self.domain_name != '' + [self.domain_name] + else + super + end + end + before_save do + if self.domain_name != '' && self.domain_names.length !=0 + self.domain_name = '' + end + end end \ No newline at end of file diff --git a/app/views/admin/site_panel/_form.html.erb b/app/views/admin/site_panel/_form.html.erb index d05e293..2db14f3 100644 --- a/app/views/admin/site_panel/_form.html.erb +++ b/app/views/admin/site_panel/_form.html.erb @@ -23,7 +23,16 @@
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
- <%= f.select :server_type, SiteConstruct::SERVER_TYPES %> + <%= f.select :server_type, SiteConstruct.server_types %> +
+
+ +
+ <%= f.label :root_domain ,"Root Domain", :class => "control-label muted" %> +
+ <%= select_tag :root_domain, + options_for_select(SiteServer.first.domain_names.collect{ |u| [u, u] }), + :id => "root_domain" %>
@@ -53,8 +62,8 @@
<%= f.label :domain_name ,"Domain Name", :class => "control-label muted" %>
- <%= f.text_field :domain_name, :id => "domain_name" %> -
schoolname-deptname.pending.rulingcom.com eg: nctu-eed.pending.rulingcom.com
+ <%= f.text_field :domain_name, :id => "domain_name",:disabled => 'disabled' %> +
@@ -89,9 +98,12 @@ <%= form_for @site_server ,:url=>{:action=>"edit_server_info",:type=>'update'},:method=>:post, :html => {:class=>"form-horizontal main-forms"} do |f|%>
@@ -43,7 +63,20 @@
- <%= f.text_field :domain_name,{:id=>'domain_name'} %> +
+ <% + tp = @site_server.domain_names + tp << '' if tp.length == 0 + tp.each_with_index do |domain_name,i| %> + <%= '
'.html_safe if i !=0 %> + <%= text_field_tag "site_server[domain_names][]",domain_name,{:id=>nil,:class=>"domain_name"} %> + <% delete_domain_button if i !=0 %> + <% end %> +
+ <%= f.button "#{t('add')} domain", class: 'btn btn-info', + :onclick=> "add_domain(this)", + :type => 'button' + %>