Add detect site mode.

This commit is contained in:
BoHung Chiu 2021-04-14 18:55:07 +08:00
parent fd8ee8bd0e
commit aa574f7808
9 changed files with 88 additions and 33 deletions

View File

@ -174,11 +174,21 @@ class Admin::SitePanelController < OrbitAdminController
def sites_list
@module_app = ModuleApp.where(:title=>@app_title).first
@categories = @module_app.categories
@filter_fields = filter_fields(@categories, [])
site_modes = ["development","production"]
@filter_fields["client_management.site_mode"] = site_modes.map{|mode| {:title=>I18n.t("client_management.#{mode}"), :id=>mode}}
@sites = SiteConstruct.any_in(:hidden=>[false,nil]).desc(:id)
@site_servers = SiteServer.all.with_categories(filters("category"))
@sites = (params[:server_name].blank? ? @sites : @sites.where(:server_type=>params[:server_name]))
@sites = @sites.any_in(:server_type => @site_servers.map{|s| s.server_name})
@sites = search_data(@sites,[:domain_name,:site_name,:school_name,:status]).page(params[:page].to_i).per(10)
if (params[:filters][:site_mode].present? rescue false)
site_modes = params[:filters][:site_mode]
if site_modes.include?("development")
site_modes << nil
end
@sites = @sites.where(:rails_env.in=>site_modes,:status=>"finish")
end
if request.xhr?
render :partial => "sites_list_table"
end

View File

@ -5,7 +5,7 @@ class SiteConstruct
SiteServer.all.map{|s| s.server_name}
end
SITE_TYPES = ["School","Gravity"]
field :rails_env, type: String, :default => "development"
field :server_type
field :site_name
field :domain_name

View File

@ -15,6 +15,8 @@
Active: <%=SiteConstruct.where(:server_type => site_server.server_name,:status=>"finish").count %><br>
Closed: <%=SiteConstruct.where(:server_type => site_server.server_name,:status=>"closed").count %><br>
Not yet installed: <%=SiteConstruct.where(:server_type => site_server.server_name,:status=>"").count %><br>
Production: <%=SiteConstruct.where(:server_type => site_server.server_name,:rails_env=>"production",:status=>"finish").count %><br>
Development: <%=SiteConstruct.where(:server_type => site_server.server_name,:rails_env.in=>["development",nil],:status=>"finish").count %><br>
</p>
</td>
<td><%=site_server.server_name%></td>
@ -51,6 +53,9 @@
maxHeight: 400,
modal: true,
width: '80%',
open: function(){
$(this).parent().css("top",$(document).height() - $(window).height() + "px");
},
close: function(){$( this ).dialog( "close" );},
buttons: {
"<%= t(:submit) %>": function(){$( this ).dialog( "close" );exec_commands()},
@ -113,6 +118,9 @@
maxHeight: 400,
width: '80%',
modal: true,
open: function(){
$(this).parent().css("top",$(document).height() - $(window).height() + "px");
},
close: function(){close_info = true;},
buttons: {
"<%= t('client_management.confirm') %>": function(){$( this ).dialog( "close" );close_info = true;},

View File

@ -1,46 +1,49 @@
<div id="filter" class="topnav clearfix open">
<ul class="breadcrumb text-info pull-left">
<li><a href="/zh_tw/admin/dashboards">網站內容</a><span class="divider">/</span></li><li><a href="/admin/site_panel"><span class="translation_missing" title="translation missing: zh_tw.module_name.client_management">Client Management</span></a><span class="divider">/</span></li><li class="active"><span class="translation_missing" title="translation missing: zh_tw.restful_actions.server_manager">Server Manager</span></li>
</ul>
<div class="searchClear pull-left" style="clear: left;">
<% content_for :right_nav do %>
<% if !search_dom_id.nil?%>
<% if quick_new %>
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), request.original_fullpath + '/new', class: "btn btn-primary pull-left", style: "clear: left;"%>
<% end %>
<div class="searchClear pull-left" <% if !quick_new %>style="clear: left;"<% end %>>
<form id="module-search-form">
<div class="sc-field"><i class="icon-search"></i><i class="icons-cross-3 search-clear" style="display: none;"></i><input type="text" id="filter-input" class="search-query input-medium" placeholder="搜尋" value=""></div>
<input type="text" id="filter-input" class="search-query input-medium" placeholder="<%= t(:search_) %>" value="<%=params[:keywords]%>">
</form>
<img id="search-preloader" src="/assets/preloader.gif" style="height: 40px; position: absolute; left: 220px; top: -5px; display:none;">
</div>
<% end %>
<ul class="nav nav-pills filter-nav pull-right">
<% fields.keys.each do |field| %>
<% org_field = field %>
<% field = field.to_s.split(".").last %>
<li class="accordion-group">
<div class="accordion-heading">
<a href="#collapse-category" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%=t(:category)%></a>
</div>
</li>
<li class="accordion-group">
<div class="accordion-heading">
<a href="#collapse-tags" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%=t(:tags)%></a>
<a href="#collapse-<%= field %>" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%= t(org_field) %></a>
</div>
</li>
<% end %>
</ul>
<div class="filter-group accordion-group">
<div class="accordion-body in collapse" id="collapse-category" style="height: auto;">
<div class="accordion-inner pagination-right">
<% @categories.each do |category|%>
<a class="btn btn-small " href="#" id="filter_<%=category.id%>" onclick="filter.addFilter('filters[category][]=<%=category.id%>');$(this).toggleClass('active');return false;"><%=category.title%></a>
<% fields.keys.each do |field| %>
<% org_field = field %>
<% field = field.to_s.split(".").last %>
<div class="accordion-body collapse" id="collapse-<%= field %>">
<div class="accordion-inner pagination-right" >
<% if fields[org_field].class == String %>
<%= fields[org_field].html_safe %>
<% else %>
<% fields[org_field].each do |val| %>
<%= link_to (val[:title].blank? ? "" : t(val[:title])), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}');$(this).toggleClass('active');return false;", :class => "btn btn-small #{is_filter_active?(field, val[:id])}", :id => "filter_#{val[:id]}" %>
<% end %>
<% end %>
</div>
<div class="filter-clear">
<a href="#" onclick="filter.clearFilter();" class="btn btn-link btn-small"><i class="icons-cycle"></i> 清除</a>
</div>
</div>
<div class="accordion-body collapse" id="collapse-tags">
<div class="accordion-inner pagination-right">
</div>
<div class="filter-clear">
<a href="#" onclick="filter.clearFilter();" class="btn btn-link btn-small"><i class="icons-cycle"></i> 清除</a>
<a href="#" onclick="filter.clearFilter();" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
<script type="text/javascript">
<% if !search_dom_id.nil?%>
var interval = 0;
var keyword;
var searchLock=false;
@ -99,7 +102,7 @@
history.pushState(null, null, url);
$.get(url,function(data){
searchLock = false;
$("#index_table").html(data);
$("#<%= search_dom_id %>").html(data);
bindPagination();
$("#search-preloader").fadeOut();
});
@ -108,6 +111,7 @@
setTimeout(moduleSearch,100);
}
}
<% end %>
var bindPagination = function(){
$(".pagination a").click(function(){
@ -186,7 +190,7 @@
var update = false;
var filter;
$(document).ready(function(){
filter = new Filter("#index_table");
filter = new Filter("#<%= search_dom_id %>");
bindPagination();
});
</script>

View File

@ -19,7 +19,7 @@
<div id='info_texts'></div>
</div>
<% end %>
<%= render :partial => "sites_list_filter" %>
<%= render :partial => "sites_list_filter", :locals =>{:fields => @filter_fields, :search_dom_id=>"index_table", :quick_new=>false} %>
<span id="index_table">
<%=render :partial=>'sites_list_table',:locals=>{:@sites=>@sites}%>
</span>

View File

@ -1,5 +1,13 @@
en:
module_name:
client_management: Client Management
restful_actions:
server_manager: Server Manager
site_list: Site List
client_management:
development: Development
production: Production
site_mode: Site mode
only_copy_installed_module: Only copy installed modules
copy_source: Copy Source
see_sites: See sites on the server

View File

@ -1,5 +1,13 @@
zh_tw:
module_name:
client_management: 網站管理系統
restful_actions:
server_manager: 伺服器管理
site_list: 網站列表
client_management:
development: 開發者模式
production: 產品模式
site_mode: 網站模式
only_copy_installed_module: 只複製安裝的模組
copy_source: 複製來源
see_sites: 查看主機上的網站

View File

@ -89,6 +89,20 @@ namespace :create_site do
else
site_construct.update(:server_type=>server_type,:site_name=>site_name,:domain_name=>server_name,:nginx_file=>nginx_file,:db_name=>db_name,:port=>port,:path=>path,:site_type=>site_type,:school_name=>school_name,:user_id=>User.first.id,:status=>status,:cert_ver_added_text=>cert_ver_added_text)
end
default_rails_env = 'development'
enable_rails_env = ['development','production']
rails_env = default_rails_env
cmd_output = exec_ssh_command_by_sudo_and_see_output(ssh,"ps -o args= -p `cat #{site_construct.path}/#{site_construct.site_name}/tmp/pids/unicorn.pid`",false) rescue []
enable_rails_env.each do |env|
if( cmd_output[0].include?(env) rescue false)
rails_env = env
break
elsif( cmd_output[0].include?("No such file or directory") rescue false)
site_construct.update(:status => "closed")
break
end
end
site_construct.update(:rails_env => rails_env)
end
end
end

View File

@ -47,10 +47,13 @@ namespace :exec_commands do
default_rails_env = 'development'
enable_rails_env = ['development','production']
rails_env = default_rails_env
log_files = exec_ssh_command_by_sudo_and_see_output(ssh,"ls -t '#{@site_construct.path}/#{@site_construct.site_name}/log'",false).flat_map{|output| output.split(/(\r\n|\t|\n|\s+)/)}.select{|output| output.present? && /(\r\n|\t|\n|\s+)/.match(output).nil?} rescue []
log_files.each do |log_file|
if( enable_rails_env.include?(log_file.sub('.log','')) rescue false)
rails_env = log_file.sub('.log','')
cmd_output = exec_ssh_command_by_sudo_and_see_output(ssh,"ps -o args= -p `cat #{@site_construct.path}/#{@site_construct.site_name}/tmp/pids/unicorn.pid`",false) rescue []
enable_rails_env.each do |env|
if( cmd_output[0].include?(env) rescue false)
rails_env = env
break
elsif( cmd_output[0].include?("No such file or directory") rescue false)
site_construct.update(:status => "closed")
break
end
end