Module store with basic module manager

This commit is contained in:
Manson Wang 2014-01-24 19:21:37 +08:00
parent 5a9e60174d
commit 94eeb1c52e
6 changed files with 389 additions and 102 deletions

View File

@ -4,6 +4,7 @@ class Admin::ModuleStoreController < OrbitBackendController
def index def index
@extensions = get_extensions @extensions = get_extensions
@downloaded_extensions = get_downloaded_extension
end end
def show def show
@ -24,18 +25,124 @@ class Admin::ModuleStoreController < OrbitBackendController
file.puts @download_link file.puts @download_link
end end
end end
%w(bundle install) # %w(bundle install)
site_restart # site_restart
Bundler.with_clean_env { `cd #{Rails.root} && bundle install && touch tmp/restart.txt` }
redirect_to admin_module_store_path redirect_to admin_module_store_path
end end
def toggle_module
temp_extensions=File.open("#{Rails.root}/extensions.tmp.rb", 'w')
extensions = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
while (extension = extensions.gets)
if params[:module].any? { |mod| extension.include?(mod)}
@mod = ModuleApp.where(:key=>extension.split("'")[1]).first
if extension.start_with?("# ")
temp_extensions << extension.gsub("# ","")
toggle_item(@mod , true)
else
temp_extensions << "# "+extension
toggle_item(@mod , false)
end
else
temp_extensions << extension
end
end
extensions.close
temp_extensions.close
FileUtils.mv("#{Rails.root}/extensions.tmp.rb","#{Rails.root}/downloaded_extensions.rb")
render :text => "true"
end
def remove_module
temp_extensions=File.open("#{Rails.root}/extensions.tmp.rb", 'w')
extensions = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
while (extension = extensions.gets)
if extension.include?(params[:module])
@mod = ModuleApp.where(:key=>extension.split("'")[1]).first
toggle_item(@mod , false)
temp_extensions << ""
else
temp_extensions << extension
end
end
extensions.close
temp_extensions.close
FileUtils.mv("#{Rails.root}/extensions.tmp.rb","#{Rails.root}/downloaded_extensions.rb")
render :text => "true"
end
def restart_server
Bundler.with_clean_env { `cd #{Rails.root} && bundle install && touch tmp/restart.txt` }
render :text => "true"
end
protected protected
def get_extensions def get_extensions
JSON.parse(open("#{@@store}/api/extensions").read) extensions = JSON.parse(open("#{@@store}/api/extensions").read)
exist_exts = []
ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
while (exist_ext = ext_file.gets)
status = !exist_ext.start_with?("# ")
exist_ext = exist_ext.split(',')
if !extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}.blank?
extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}[0]['installed']=true
extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}[0]['enabled']=status
extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}[0]['installed_version']=exist_ext[1].split(/[\'\"]/)[1]
if extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}[0]['version'] != exist_ext[1].split(/[\'\"]/)[1]
extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}[0]['updated'] = false
else
extensions.select{|ext| ext['key']==exist_ext[0].split(/[\'\"]/)[1]}[0]['updated'] = true
end
end
end
ext_file.close
extensions
end end
def get_extension(id) def get_extension(id)
JSON.parse(open("#{@@store}/api/extensions/#{id}").read) JSON.parse(open("#{@@store}/api/extensions/#{id}").read)
end end
def get_downloaded_extension
downloaded_extensions = []
extensions = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
while (extension = extensions.gets)
status = !extension.start_with?("# ")
extension = extension.split(',')
downloaded_extensions << {'name' => extension[0].split(/[\'\"]/)[1], 'version' => extension[1].split(/[\'\"]/)[1], 'repo' => extension[2].split(/[\'\"]/)[1], 'status' => status}
end
extensions.close
downloaded_extensions.to_json
end
def toggle_item(module_key, active)
if !module_key.nil?
Item.where(:module_app_id=>module_key._id).each do |item|
item.is_published = active
item.menu_enabled_for = {"zh_tw" => active.to_s, "en" => active.to_s}
item.save
end
end
end
end end

View File

@ -3,7 +3,11 @@ module Admin::ItemsHelper
def get_item_module_infos(item) def get_item_module_infos(item)
if module_app = item.module_app if module_app = item.module_app
app = OrbitApp::Module::Registration.find_by_key(module_app.key) app = OrbitApp::Module::Registration.find_by_key(module_app.key)
if !app.nil?
[t(app.get_label_i18n), (app.get_icon_class rescue 'icons-daniel-bruce-2')] [t(app.get_label_i18n), (app.get_icon_class rescue 'icons-daniel-bruce-2')]
else
["","icon-minus-sign"]
end
else else
[t(:no_app), 'icons-daniel-bruce-2'] [t(:no_app), 'icons-daniel-bruce-2']
end end

View File

@ -12,14 +12,147 @@
<%= javascript_include_tag 'lib/footable-0.1' %> <%= javascript_include_tag 'lib/footable-0.1' %>
<%= javascript_include_tag 'lib/all-list' %> <%= javascript_include_tag 'lib/all-list' %>
<%= javascript_include_tag 'lib/retina' %> <%= javascript_include_tag 'lib/retina' %>
<%= javascript_include_tag 'lib/mudole_templates_status' %> <style type="text/css">
.container{
/*max-width: 600px;*/
}
.panel{
border-radius: 5px;
overflow: hidden;
border: 1px solid #DFDFDF;
background: #FFF;
box-shadow: 0px 0px 10px #CCC;
}
.break{
border-left: 1px solid #FCFCFC;
border-right: 1px solid #DDD;
padding: 10px 0;
margin: 0 15px;
}
.panel-heading{
font-size: 16px;
color: #666;
padding: 10px 20px;
height: 20px;
background-color: #fafafa;
background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f2f2f2));
background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2);
background-image: -o-linear-gradient(top, #ffffff, #f2f2f2);
background-image: linear-gradient(to bottom, #ffffff, #f2f2f2);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff2f2f2', GradientType=0);
*zoom: 1;
border-bottom: 1px solid #DDD;
}
.table{
margin: 0;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.table td{
vertical-align: middle;
text-align: center;
}
.table td img{
background: #666;
border: 3px solid #AAA;
padding: 2px;
border-radius: 5px;
box-shadow: 0px 0px 10px #000 inset;
}
.pannel-body{
min-height: 400px;
overflow: scroll;
overflow-x: hidden;
overflow-y: hidden;
padding: 15px;
}
.pannel-footer{
background: #f2f2f2; /* Old browsers */
background: -moz-linear-gradient(top, #f2f2f2 0%, #ffffff 76%, #ededed 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f2f2f2), color-stop(76%,#ffffff), color-stop(100%,#ededed)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f2f2f2 0%,#ffffff 76%,#ededed 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f2f2f2 0%,#ffffff 76%,#ededed 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f2f2f2 0%,#ffffff 76%,#ededed 100%); /* IE10+ */
background: linear-gradient(to bottom, #f2f2f2 0%,#ffffff 76%,#ededed 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2f2f2', endColorstr='#ededed',GradientType=0 ); /* IE6-9 */
border: 1px solid #EEE;
border-top: 1px solid #CCC;
padding: 10px;
height: 30px;
}
#apply_change_btn{
display: none;
}
#alert_wrap{
display: none;
position: absolute;
width: 93%;
top: 30%;
z-index: 1045;
}
.alert{
width: 400px;
text-align: center;
z-index: 1050;
margin: 0 auto;
padding: 10px 0;
}
.modal-backdrop{
display: none;
}
.icons-faq:before{ content: "\e086"; }
.icons-ask:before { content: "\e062"; }
</style>
</head> </head>
<!--
<% @extensions.each do |extension|%>
<%=link_to extension["title"], admin_module_store_show_path(extension["_slugs"][0])%>
<%end%> -->
<%= flash[:notice] rescue nil%> <%= flash[:notice] rescue nil%>
<div id="alert_wrap">
<div class="alert alert-success">
<h4><span id="module_msg_title"></span></h4><br/>
<span id="module_msg_content"></span><br/>
<img src="http://ridepal.com/images/homeimg/preloader_transparent.gif" width="50">
</div>
</div>
<div class="container row-fluid">
<div class="span4">
<div class="panel">
<div class="panel-heading"><i class="icons-download"></i><span class="break"></span><%= t(:installed_modules) %></div>
<div class="pannel-body">
<table class="table table-striped">
<tbody id="extensions_table">
</tbody>
</table>
</div>
<div class="pannel-footer">
<button id="apply_change_btn" onclick="apply_change();" class="btn btn-primary btn-small pull-right">Appy Change</button>
</div>
</div>
</div>
<div class="span8 pull-right">
<div class="panel">
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:module_store) %></div>
<div class="pannel-body">
<table id="mt-list" class="table main-list"> <table id="mt-list" class="table main-list">
<thead> <thead>
@ -35,7 +168,7 @@
<tr> <tr>
<td class="detail-row"> <td class="detail-row">
<div class="module_icon pull-left"> <div class="module_icon pull-left">
<%= image_tag "module_icon.png"%> <i class='icons-<%= extension["key"] %> icon-3x'></i>
</div> </div>
<h5 class="mt_title"><span><%=link_to extension["title"], admin_module_store_show_path(extension["_slugs"][0])%></span></h5> <h5 class="mt_title"><span><%=link_to extension["title"], admin_module_store_show_path(extension["_slugs"][0])%></span></h5>
<p class="mt_dev muted"><%=extension["author"]%></p> <p class="mt_dev muted"><%=extension["author"]%></p>
@ -55,62 +188,94 @@
</tbody> </tbody>
</table> </table>
</div>
<div class="pannel-footer">
</div>
</div>
</div>
</div>
<div class="modal-backdrop"></div>
<!-- <script type="text/javascript">
<tr> var toggle_modules = new Array();
<td class="detail-row"> // var downloaded_extensions = <%= @downloaded_extensions.to_s.html_safe %>;
<div class="module_icon pull-left"> var extensions = <%= @extensions.to_json.to_s.html_safe %>;
<%= image_tag "module_icon.png"%>
</div>
<h5 class="mt_title"><span>Module Title</span><span class="muted">2.0.1</span></h5>
<p class="mt_dev muted">Rulingcom</p>
</td>
<td class="detail-row">2013/07/12</td>
<td>
@detail
</td>
<td class="active"><button class="act btn btn-mini" type="button">Uninstall</button></td>
</tr>
<tr class="download">
<td class="detail-row">
<div class="module_icon pull-left">
<%= image_tag "module_icon.png"%>
</div>
<h5 class="mt_title"><span>Module Title Module Title Module Title</span><span class="muted">2.0.1</span></h5>
<p class="mt_dev muted">Rulingcom</p>
</td>
<td class="detail-row">2013/07/12</td>
<td>
@detail
</td>
<td class="active"><button class="act btn btn-mini btn-success" type="button">Download</button></td>
</tr>
<tr class="install">
<td class="detail-row">
<div class="module_icon pull-left">
<%= image_tag "module_icon.png"%>
</div>
<h5 class="mt_title"><span>Module Title</span><span class="muted">2.0.1</span></h5>
<p class="mt_dev muted">Rulingcom</p>
</td>
<td class="detail-row">2013/07/12</td>
<td>
@detail
</td>
<td class="active"><button class="act btn btn-mini btn-primary" type="button">Install</button></td>
</tr>
<tr class="update">
<td class="detail-row">
<div class="module_icon pull-left">
<%= image_tag "module_icon.png"%>
</div>
<h5 class="mt_title"><span>Module Title</span><span class="muted">2.0.1</span></h5>
<p class="mt_dev muted">Rulingcom</p>
</td>
<td class="detail-row">2013/07/12</td>
<td>
@detail
</td>
<td class="active"><button class="act btn btn-mini btn-info" type="button">Update</button></td>
</tr> -->
$.each(extensions,function(){
if(typeof this['installed']=='undefined') return;
if(this['updated']==false) console.log(this['key']);
var checked = "";
if(this['enabled']==true) checked="checked='checked'";
$("#extensions_table").append("<tr><td width='15%'><i class='icons-"+this['key']+" icon-3x'></i><br/>"+this['title']+"</td><td width='40%'>Version<br/>v"+this['installed_version']+"</td><td><%= t(:active) %><br/><input type='checkbox' class='toggle-check set-sidebar-state' data-disabled='true' "+checked+" onclick='toggle_module(\""+this['key']+"\");'></td><td><button onclick='remove_module(\""+this['key']+"\");' class='btn btn-small btn-danger'><i class='icon-trash'></i> <%= t(:delete_) %></button></td></tr>");
});
function toggle_module(module){
if((idx = $.inArray(module, toggle_modules))>=0){
toggle_modules.splice(idx, 1);
}else{
toggle_modules.push(module);
}
if(toggle_modules.length>0){
$("#apply_change_btn").show();
}else{
$("#apply_change_btn").hide();
}
}
function apply_change(){
$(document).scrollTop(0);
$("#module_msg_title").html("Applying Change");
$("#module_msg_content").html("Please wait");
$(".modal-backdrop").fadeIn(300,function(){
$("#alert_wrap").fadeIn(300);
$.get("<%= admin_module_store_toggle_module_path%>?"+$.param({'module':toggle_modules}),function(data){
toggle_modules = new Array();
$("#apply_change_btn").hide();
$("#module_msg_title").html("Change Applied");
$("#module_msg_content").html("Restarting Server");
$.get("<%= admin_module_store_restart_server_path%>",function(){
$("#module_msg_title").html("Change Applied");
$("#module_msg_content").html("Restarting Server");
$("#alert_wrap").delay(2000).fadeOut(300,function(){
$(".modal-backdrop").fadeOut();
});
});
});
});
}
function remove_module(mod_key){
$(document).scrollTop(0);
$("#module_msg_title").html("Applying Change");
$("#module_msg_content").html("Please wait");
$(".modal-backdrop").fadeIn(300,function(){
$("#alert_wrap").fadeIn(300);
$.get("<%= admin_module_store_remove_module_path%>?module="+mod_key,function(data){
toggle_modules = new Array();
$("#apply_change_btn").hide();
$("#module_msg_title").html("Change Applied");
$("#module_msg_content").html("Restarting Server");
$.get("<%= admin_module_store_restart_server_path%>",function(){
$("#module_msg_title").html("Change Applied");
$("#module_msg_content").html("Restarting Server");
$("#alert_wrap").delay(2000).fadeOut(300,function(){
$(".modal-backdrop").fadeOut();
});
});
});
});
}
</script>

View File

@ -13,6 +13,7 @@ en:
object: Access Denied for you don't have permission for this object object: Access Denied for you don't have permission for this object
academic_info: Academic Info. academic_info: Academic Info.
action: Action action: Action
active: Active
ad: ad:
chinese_1: Enter 1, if it shows once in a series chinese_1: Enter 1, if it shows once in a series
chinese_2: Type Link chinese_2: Type Link
@ -232,6 +233,8 @@ en:
images: Images images: Images
info: Information info: Information
initial: Default Value initial: Default Value
install: Install
installed_modules: Installed Modules
intro: Introduction intro: Introduction
is_published: Is published is_published: Is published
item: Item item: Item
@ -302,6 +305,7 @@ en:
module: Module module: Module
modules: Modules modules: Modules
module_authorization: Module Authorization module_authorization: Module Authorization
module_store: Module Store
monthly_traffic: Monthly Traffic monthly_traffic: Monthly Traffic
more_plus: more+ more_plus: more+
most_visited_page: Most Visited Page most_visited_page: Most Visited Page

View File

@ -13,6 +13,7 @@ zh_tw:
object: 拒絕存取,因你沒有權限 object: 拒絕存取,因你沒有權限
academic_info: 學術資訊 academic_info: 學術資訊
action: 操作 action: 操作
active: 啟用
ad: ad:
chinese_1: 在套圖中出現次數 1次請輸入1 chinese_1: 在套圖中出現次數 1次請輸入1
chinese_2: 輸入連結 chinese_2: 輸入連結
@ -234,6 +235,8 @@ zh_tw:
images: images images: images
info: 基本資料 info: 基本資料
initial: 預設值 initial: 預設值
install: 安裝
installed_modules: 已安裝模組
intro: 簡介 intro: 簡介
is_published: 已發佈 is_published: 已發佈
item: 項目 item: 項目
@ -305,6 +308,7 @@ zh_tw:
module: 模組 module: 模組
modules: 網站模組 modules: 網站模組
module_authorization: 模組授權 module_authorization: 模組授權
module_store: 模組商店
monthly_traffic: 本月流量 monthly_traffic: 本月流量
more_plus: 更多+ more_plus: 更多+
most_visited_page: 最多瀏覽頁面 most_visited_page: 最多瀏覽頁面

View File

@ -263,6 +263,9 @@ Orbit::Application.routes.draw do
match 'module_store' => 'module_store#index' match 'module_store' => 'module_store#index'
match 'module_store/show' => 'module_store#show' match 'module_store/show' => 'module_store#show'
match 'module_store/download' => 'module_store#download' match 'module_store/download' => 'module_store#download'
match 'module_store/remove_module' => 'module_store#remove_module'
match 'module_store/toggle_module' => 'module_store#toggle_module'
match 'module_store/restart_server' => 'module_store#restart_server'
match 'template_store' => 'template_store#index' match 'template_store' => 'template_store#index'
match 'template_store/download_theme' => "template_store#download_theme" match 'template_store/download_theme' => "template_store#download_theme"
match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template