diff --git a/app/controllers/admin/official_module_controller.rb b/app/controllers/admin/official_module_controller.rb index e5f8ab6..554743c 100644 --- a/app/controllers/admin/official_module_controller.rb +++ b/app/controllers/admin/official_module_controller.rb @@ -1,11 +1,11 @@ class Admin::OfficialModuleController < OrbitAdminController - layout "structure" def set_master_key @master_password = MasterPassword.first rescue nil if @master_password.nil? @master_password = MasterPassword.new end + render :layout => "structure" end def update_master_password @@ -26,7 +26,43 @@ class Admin::OfficialModuleController < OrbitAdminController redirect_to admin_site_set_master_key_path(current_site) end - + def index + @managers = ServerAbilityManager.all.order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")).desc(:created_at) + @table_fields = ["site_name_layout", "max_site_ability", "site_num","site_ip"] + @tags = @module_app.tags + @categories = @module_app.categories.enabled + @filter_fields = filter_fields_without_status(@categories, @tags) + @managers = search_data(@managers,[:title,:site_domain]).page(params[:page]).per(10) + + if request.xhr? + render :partial => "index" + end + end + + def set_server_ability + store_token = params[:official_module_id] + @manager = ServerAbilityManager.where(store_token: store_token).first || ServerAbilityManager.new(id: nil) + end + + def update_server_ability + manager_params = params.require(:server_ability_manager).permit! + store_token = manager_params[:store_token] + manager = ServerAbilityManager.where(store_token: store_token).first + if manager.nil? + r_site = RegisteredSite.where(uid: store_token).first + manager = ServerAbilityManager.create(store_token: store_token, site_name: r_site.title,site_url: r_site.site_domain,site_ip: r_site.real_ip || r_site.ip[0]) + end + manager.update_attributes(manager_params) + redirect_to :action => "index" + end + + def delete + store_token = params[:official_module_id] + ServerAbilityManager.where(store_token: store_token).first.destroy + redirect_to :action => "index" + end private def password_params diff --git a/app/controllers/client_sites_controller.rb b/app/controllers/client_sites_controller.rb index 8fbdedf..dc59b5d 100644 --- a/app/controllers/client_sites_controller.rb +++ b/app/controllers/client_sites_controller.rb @@ -100,4 +100,26 @@ class ClientSitesController < ApplicationController end end + def check_server_ability + site_num = params[:site_num] + store_token = params[:store_token] + site_name = params[:site_name] + site_url = params[:site_url] + manager = ServerAbilityManager.where(store_token: store_token).first + ability = manager.max_site_ability rescue 0 + site_ip = request.remote_ip + update_params = { + site_ip: site_ip, + site_num: site_num, + site_url: site_url + } + if manager.nil? + update_params = update_params.merge({store_token: store_token, + site_name: site_name}) + ServerAbilityManager.create(update_params) + else + manager.update_attributes(update_params) + end + render :json => {ability: ability} + end end \ No newline at end of file diff --git a/app/models/server_ability_manager.rb b/app/models/server_ability_manager.rb new file mode 100644 index 0000000..99f124a --- /dev/null +++ b/app/models/server_ability_manager.rb @@ -0,0 +1,35 @@ +class ServerAbilityManager + include Mongoid::Document + include Mongoid::Timestamps + include OrbitCategory::Categorizable + include OrbitTag::Taggable + field :store_token + field :site_name + field :site_url + field :site_ip + field :site_num, type: Integer, default: 0 + field :max_site_ability, type: Integer, default: 0 + def site_name_layout(url=nil,site_name=nil) + url = self.site_url if url.nil? + site_name = self.site_name if site_name.nil? + "#{site_name} +
+ +
" + end + def site_name + tmp = super + tmp = tmp.blank? ? self.site_url : tmp + end +end \ No newline at end of file diff --git a/app/views/admin/official_module/_index.html.erb b/app/views/admin/official_module/_index.html.erb new file mode 100644 index 0000000..eb5de4c --- /dev/null +++ b/app/views/admin/official_module/_index.html.erb @@ -0,0 +1,26 @@ + + + + <% @table_fields.each do |f| %> + <%= thead("official_module.#{f}") %> + <% end %> + + + + <% @managers.each do |manager| %> + + <% @table_fields.each do |f| %> + + <% end %> + + <% end %> + +
+ <%= manager.send(f).to_s.html_safe %> +
+
+ <%= content_tag :div, paginate(@managers), class: "pagination pagination-centered" %> + + <%= t('new_') %> + +
\ No newline at end of file diff --git a/app/views/admin/official_module/index.html.erb b/app/views/admin/official_module/index.html.erb new file mode 100644 index 0000000..cf6b8c0 --- /dev/null +++ b/app/views/admin/official_module/index.html.erb @@ -0,0 +1,4 @@ +<%= render_filter @filter_fields, "index_table" %> +
+<%= render :partial => "index" %> +
\ No newline at end of file diff --git a/app/views/admin/official_module/set_server_ability.erb b/app/views/admin/official_module/set_server_ability.erb new file mode 100644 index 0000000..275995e --- /dev/null +++ b/app/views/admin/official_module/set_server_ability.erb @@ -0,0 +1,40 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/wrap-nav"%> + <%= stylesheet_link_tag "lib/main-forms"%> + <%= stylesheet_link_tag "lib/fileupload"%> + <%= stylesheet_link_tag "lib/togglebox"%> +<% end %> +<%= form_for @manager, :url => {:action => "update_server_ability"}, :method => "patch", :html => {:class => "form-horizontal main-forms"} do |f| %> +
+ +
+
+ +
+ <% if @manager.new_record? %> + <%= f.select :store_token, RegisteredSite.all.collect{|v| [v.show_name,v.site_token]} %> + <% else %> + <%= f.hidden_field :store_token %> + + <% end %> +
+
+
+ +
+ <%= f.number_field :max_site_ability, :class=>"input-large", :autocomplete=>"off" %> +
+
+
+ +
+ <% if @manager.new_record? %> + <%= f.submit t('new_'), :class => "btn btn-primary" %> + <% else %> + <%= f.submit t('edit'), :class => "btn btn-primary" %> + <% end %> +
+
+<% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 82557d8..e51c500 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,2 +1,11 @@ en: - master_key: Master Key \ No newline at end of file + master_key: Master Key + official_module: + all: All + official_module: Official Module + site_name_layout: Site Name + max_site_ability: Max Site Ability + site_num: Site Number + site_ip: Site IP + module_name: + official_module: Official Module \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index f3cb9ac..866678a 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,2 +1,11 @@ zh_tw: - master_key: 網站密碼 \ No newline at end of file + master_key: 網站密碼 + official_module: + all: 全部 + official_module: 官網模組 + site_name_layout: 網站名稱 + max_site_ability: 最大容許網站數量 + site_num: 網站數量 + site_ip: 網站IP + module_name: + official_module: 官網模組 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 73d5205..0f54961 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,13 +6,23 @@ Rails.application.routes.draw do get "/desktop/widget_download_url" => "client_sites#widget_download_url" get "/store/form_token" => 'client_sites#get_csrf_token' - + post "/xhr/check_server_ability" => 'client_sites#check_server_ability' locales = Site.first.in_use_locales rescue I18n.available_locales scope "(:locale)", locale: Regexp.new(locales.join("|")) do namespace :admin do - scope "sites/:id", :controller => 'official_module' do - get "set_master_key" => 'official_module#set_master_key', as: :site_set_master_key - patch "update_master_password" => 'official_module#update_master_password' + scope "sites/:id", :controller => 'official_module',as: :site do + get "set_master_key" + patch "update_master_password" + end + resources :official_module, :controller => 'official_module',:only=>[:index] do + get "set_server_ability" + get "delete" + patch "update_server_ability" + end + scope :official_module, :controller => 'official_module',:only=>[],as: :official_module_new do + get "set_server_ability" + get "delete" + patch "update_server_ability" end end end diff --git a/lib/official_module/engine.rb b/lib/official_module/engine.rb index 9f36694..82fce1b 100644 --- a/lib/official_module/engine.rb +++ b/lib/official_module/engine.rb @@ -3,13 +3,45 @@ module OfficialModule initializer "official_module" do OrbitApp.registration "OfficialModule", :type => "ModuleApp" do base_url File.expand_path File.dirname(__FILE__) + taggable "ServerAbilityManager" + categorizable + authorizable + module_label "official_module.official_module" set_keyword_contstraints ['/store/check_module_permissions', '/store/register_old_sites_modules', '/store/check_for_rulingcom', '/store/desktop/widgets', '/desktop/widget_download_url', '/store/form_token'] + side_bar do + head_label_i18n 'official_module.official_module', icon_class: "fa fa-puzzle-piece" + available_for "managers" + active_for_controllers (['admin/official_module']) + head_link_path "admin_official_module_index_path" + context_link 'official_module.all', + :link_path=>"admin_official_module_index_path" , + :priority=>1, + :active_for_action=>{'admin/official_module'=>"index"}, + :available_for => 'users' + + context_link 'categories', + :link_path=>"admin_module_app_categories_path" , + :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'official_module').id}", + :priority=>2, + :active_for_action=>{'admin/official_module'=>'categories'}, + :active_for_category => 'OfficialModule', + :available_for => 'managers' + + context_link 'tags', + :link_path=>"admin_module_app_tags_path" , + :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'official_module').id}", + :priority=>3, + :active_for_action=>{'admin/official_module'=>'tags'}, + :active_for_tag => 'OfficialModule', + :available_for => 'managers' + + end end end end