add multiple domain feature for one server

This commit is contained in:
chiu 2021-01-28 11:10:41 +08:00
parent 2322db910c
commit 1668d44c7c
4 changed files with 87 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -23,7 +23,16 @@
<div class="control-group">
<%= f.label :server_type ,"Server", :class => "control-label muted" %>
<div class="controls">
<%= f.select :server_type, SiteConstruct::SERVER_TYPES %>
<%= f.select :server_type, SiteConstruct.server_types %>
</div>
</div>
<div class="control-group">
<%= f.label :root_domain ,"Root Domain", :class => "control-label muted" %>
<div class="controls">
<%= select_tag :root_domain,
options_for_select(SiteServer.first.domain_names.collect{ |u| [u, u] }),
:id => "root_domain" %>
</div>
</div>
@ -53,8 +62,8 @@
<div class="control-group">
<%= f.label :domain_name ,"Domain Name", :class => "control-label muted" %>
<div class="controls">
<%= f.text_field :domain_name, :id => "domain_name" %>
<div class="hint">schoolname-deptname.pending.rulingcom.com eg: nctu-eed.pending.rulingcom.com</div>
<%= f.text_field :domain_name, :id => "domain_name",:disabled => 'disabled' %>
<!--<div class="hint">schoolname-deptname.pending.rulingcom.com eg: nctu-eed.pending.rulingcom.com</div>-->
</div>
</div>
@ -89,9 +98,12 @@
<script type="text/javascript">
var domain_name_relations = {};
<% SiteServer.all.each do |server_server| %>
domain_name_relations['<%= server_server.server_name %>'] = '<%= server_server.domain_name %>';
domain_name_relations['<%= server_server.server_name %>'] = <%= server_server.domain_names.inspect.html_safe %>;
<% end %>
console.log(domain_name_relations);
function change_domain_name(domain_name){
$("#domain_name").val($("#site_name").val().replace("_","-") + "."+domain_name);
}
$("#school_name").on("blur",function(){
var school = $(this).val().toLowerCase();
if($("#site_name").val() == ""){
@ -114,18 +126,31 @@
$("#path").val("/home/rulingcom/" + type);
}
})
$('#site_construct_server_type').click(function(){
var domain_name = domain_name_relations[$(this).val()];
$("#domain_name").val($("#site_name").val().replace("_","-") + "."+domain_name);
$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
$("#root_domain").change(function(){
change_domain_name($(this).val());
})
$('#site_construct_server_type').change(function(){
var domain_name = domain_name_relations[$(this).val()][0];
var domain_names = domain_name_relations[$(this).val()];
$("#root_domain").find('option').remove()
$.each(domain_names,function(i,v){
var o = new Option(v, v);
/// jquerify the DOM object 'o' so we can use the html method
$(o).html(v);
$("#root_domain").append(o);
})
if ($("#site_name").val()!=''){
change_domain_name(domain_name);
}
//$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
})
$("#site_name").on("blur",function(){
var val = $(this).val(),
type = $("#site_construct_site_type").val(),
school = $("#school_name").val(),
domain_name = domain_name_relations[$('#site_construct_server_type').val()];
$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
$("#domain_name").val(val.replace("_","-") + "."+domain_name);
domain_name = $("#root_domain").val();
//$('#domain_name').siblings('.hint').html('schoolname-deptname.'+domain_name+' eg: nctu-eed.'+domain_name);
change_domain_name(domain_name);
$("#db_name").val(val);
type = (type == "School" ? "school_sites" : "orbit_sites" );
if(school != ""){

View File

@ -1,6 +1,26 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<% end %>
<% end
delete_domain_button = button_tag("#{t('delete_')} domain", class: 'btn btn-danger',
:onclick=> "delete_domain(this)",
:type => 'button')
%>
<script type="text/javascript">
function add_domain(ele){
var tp=$(ele);
var tp2=tp.parents('.controls').eq(0).find('.group');
var tp3=tp2.find('.domain_name').eq(0).clone();
tp3.val('');
tp2.append('<br>');
tp2.append(tp3);
tp2.append('<%= delete_domain_button %>')
}
function delete_domain(ele){
$(ele).prev('input').remove()
$(ele).prev('br').remove()
$(ele).remove()
}
</script>
<%= form_for @site_server ,:url=>{:action=>"edit_server_info",:type=>'update'},:method=>:post, :html => {:class=>"form-horizontal main-forms"} do |f|%>
<fieldset>
<input type='hidden' name='id' value='<%=@site_server.id.to_s%>'/>
@ -43,7 +63,20 @@
<div class="control-group">
<label class="control-label muted" for="domain_name">Domain name:</label>
<div class="controls">
<%= f.text_field :domain_name,{:id=>'domain_name'} %>
<div class="group">
<%
tp = @site_server.domain_names
tp << '' if tp.length == 0
tp.each_with_index do |domain_name,i| %>
<%= '<br>'.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 %>
</div>
<%= f.button "#{t('add')} domain", class: 'btn btn-info',
:onclick=> "add_domain(this)",
:type => 'button'
%>
</div>
</div>
<div class="control-group">