diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index e645d1b..cbc022d 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -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 diff --git a/app/models/site_construct.rb b/app/models/site_construct.rb index 82f5d50..ccb1ec3 100644 --- a/app/models/site_construct.rb +++ b/app/models/site_construct.rb @@ -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 diff --git a/app/views/admin/site_panel/_server_manager_index.html.erb b/app/views/admin/site_panel/_server_manager_index.html.erb index 736a045..794775b 100644 --- a/app/views/admin/site_panel/_server_manager_index.html.erb +++ b/app/views/admin/site_panel/_server_manager_index.html.erb @@ -15,6 +15,8 @@ Active: <%=SiteConstruct.where(:server_type => site_server.server_name,:status=>"finish").count %>
Closed: <%=SiteConstruct.where(:server_type => site_server.server_name,:status=>"closed").count %>
Not yet installed: <%=SiteConstruct.where(:server_type => site_server.server_name,:status=>"").count %>
+ Production: <%=SiteConstruct.where(:server_type => site_server.server_name,:rails_env=>"production",:status=>"finish").count %>
+ Development: <%=SiteConstruct.where(:server_type => site_server.server_name,:rails_env.in=>["development",nil],:status=>"finish").count %>

<%=site_server.server_name%> @@ -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;}, diff --git a/app/views/admin/site_panel/_sites_list_filter.html.erb b/app/views/admin/site_panel/_sites_list_filter.html.erb index dd9d4f0..9703c78 100644 --- a/app/views/admin/site_panel/_sites_list_filter.html.erb +++ b/app/views/admin/site_panel/_sites_list_filter.html.erb @@ -1,46 +1,49 @@ -
- -
+<% 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 %> +
style="clear: left;"<% end %>>
-
+
+ <% end %>
-
-
- <% @categories.each do |category|%> - <%=category.title%> + <% fields.keys.each do |field| %> + <% org_field = field %> + <% field = field.to_s.split(".").last %> +
+
+ <% 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 %>
- 清除 -
-
- + <% end %>
-
+<% end %> \ No newline at end of file diff --git a/app/views/admin/site_panel/sites_list.html.erb b/app/views/admin/site_panel/sites_list.html.erb index 2afd32a..46112c2 100644 --- a/app/views/admin/site_panel/sites_list.html.erb +++ b/app/views/admin/site_panel/sites_list.html.erb @@ -19,7 +19,7 @@
<% end %> -<%= render :partial => "sites_list_filter" %> +<%= render :partial => "sites_list_filter", :locals =>{:fields => @filter_fields, :search_dom_id=>"index_table", :quick_new=>false} %> <%=render :partial=>'sites_list_table',:locals=>{:@sites=>@sites}%> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 6af4856..1eed249 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 7ac4b6f..5059ea1 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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: 查看主機上的網站 diff --git a/lib/tasks/detect_sites.rake b/lib/tasks/detect_sites.rake index 89da80e..c694d5e 100644 --- a/lib/tasks/detect_sites.rake +++ b/lib/tasks/detect_sites.rake @@ -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 diff --git a/lib/tasks/exec_command.rake b/lib/tasks/exec_command.rake index 482cad5..a086845 100644 --- a/lib/tasks/exec_command.rake +++ b/lib/tasks/exec_command.rake @@ -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