Update Manager
This commit is contained in:
parent
bba0e436d9
commit
a154d16a7e
|
@ -3,6 +3,7 @@ class Admin::SitesController < OrbitBackendController
|
|||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
before_filter :get_site
|
||||
before_filter :git_branch
|
||||
|
||||
# def index
|
||||
# @site = Site.first
|
||||
|
@ -107,6 +108,43 @@ class Admin::SitesController < OrbitBackendController
|
|||
render :nothing => true
|
||||
end
|
||||
|
||||
def update_manager
|
||||
end
|
||||
|
||||
def get_update_history
|
||||
@update_log = %x{git log --pretty=format:"%ad','%s" --date=short}.split("\n").map{|log| log.gsub("'","").split(",")}.to_json
|
||||
render :json => @update_log
|
||||
end
|
||||
|
||||
def check_updates
|
||||
%x(git fetch origin)
|
||||
@new_updates = %x(git log #{@branch}..origin/#{@branch} --pretty=format:"%ad','%s" --date=short).split("\n").map{|log| log.gsub("'","").split(",")}.to_json
|
||||
render :json => @new_updates
|
||||
end
|
||||
|
||||
def update_orbit
|
||||
result = ""
|
||||
need_stash = %x(git diff).blank?
|
||||
%x(git stash) unless need_stash
|
||||
%x(git fetch origin)
|
||||
pull_result = %x(git pull -r --ff-only 2>&1 origin #{@branch})
|
||||
|
||||
if pull_result.include? "fatal: Not possible to fast-forward, aborting."
|
||||
result = "failed"
|
||||
else
|
||||
result = "success"
|
||||
%x{bundle install}
|
||||
%x{touch tmp/restart.txt}
|
||||
end
|
||||
%x(git stash pop) unless need_stash
|
||||
|
||||
render :text => result
|
||||
end
|
||||
|
||||
def restart_server
|
||||
render :text => "success"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def update_design(design)
|
||||
|
@ -124,5 +162,9 @@ class Admin::SitesController < OrbitBackendController
|
|||
def get_site
|
||||
@site ||= Site.first
|
||||
end
|
||||
|
||||
def git_branch
|
||||
@branch = %x(git rev-parse --abbrev-ref HEAD).gsub("\n","")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
<li title="<%= t('preference') %>"><%= link_to admin_site_preference_path(@site), :class => active_for_action('sites', 'preference') do %><span><i class="icons-cog"></i></span><%end%></li>
|
||||
|
||||
<li title="<%= t('update_manager') %>"><%= link_to admin_site_update_manager_path(@site), :class => active_for_action('sites', 'update_manager') do %><span><i class="icon-refresh"></i></span><%end%></li>
|
||||
|
||||
<!-- <li title="System Info"><a href="/orbit_4.0.1/admin/system_info/index.shtml?sidebarNavList=8&subNavBlockList=0"><span><i class="icons-info-2"></i></span></a></li>
|
||||
--> </ul>
|
||||
</div>
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
<li title="<%= t('preference') %>"><%= link_to admin_site_preference_path(@site), :class => active_for_action('sites', 'preference') do %><span><i class="icons-cog"></i></span><%end%></li>
|
||||
|
||||
<li title="<%= t('update_manager') %>"><%= link_to admin_site_update_manager_path(@site), :class => active_for_action('sites', 'update_manager') do %><span><i class="icon-refresh"></i></span><%end%></li>
|
||||
|
||||
<!-- <li title="System Info"><a href="/orbit_4.0.1/admin/system_info/index.shtml?sidebarNavList=8&subNavBlockList=0"><span><i class="icons-info-2"></i></span></a></li>
|
||||
--> </ul>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,245 @@
|
|||
<% content_for :side_bar do %>
|
||||
<%= render :partial => 'layouts/side_bar', :locals => {:link_name => t('site.settings'), :link_url => admin_site_site_info_path(@site), :icon => 'icons-cog', :side_bar_content => 'admin/sites/side_bar'} %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.container{
|
||||
}
|
||||
|
||||
#new_update_container{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#update_progress{
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#update_status{
|
||||
/*display: none;*/
|
||||
}
|
||||
|
||||
#update_done{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#update_failed{
|
||||
display: none;
|
||||
}
|
||||
|
||||
.panel{
|
||||
/*max-height: 400px;*/
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #DFDFDF;
|
||||
background: #FFF;
|
||||
box-shadow: 0px 0px 10px #CCC;
|
||||
}
|
||||
|
||||
.panel-heading{
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
padding: 10px 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;
|
||||
}
|
||||
|
||||
.pannel-body{
|
||||
max-height: 400px;
|
||||
overflow: scroll;
|
||||
overflow-x: hidden;
|
||||
overflow-y: hidden;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.pannel-body:hover{
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
background-color: #AAA;
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background-color: #666;
|
||||
}
|
||||
|
||||
.break{
|
||||
border-left: 1px solid #FCFCFC;
|
||||
border-right: 1px solid #DDD;
|
||||
padding: 10px 0;
|
||||
margin: 0 15px;
|
||||
}
|
||||
</style>
|
||||
<div class="container">
|
||||
<div class="row-fluid">
|
||||
<div class="span6">
|
||||
<div id="new_update_container">
|
||||
<div class="panel">
|
||||
<div class="panel-heading">
|
||||
<i class="icon-exclamation-sign"></i>
|
||||
<span class="break"></span>
|
||||
<span class="panel-title"><%= t("update_manager_.available_updates") %></span>
|
||||
<span id="num_new_updates" class="badge badge-important pull-right"></span>
|
||||
</div>
|
||||
<div class="pannel-body">
|
||||
<table class="table table-striped">
|
||||
<tbody id="new_update_table">
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div style="height: 55px;">
|
||||
<button id="update_btn" class="btn btn-primary pull-right" style="margin: 10px;"><i class="icon-inbox icon-white"></i> <%= t("update_manager_.system_update") %></button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="update_status">
|
||||
<div class="panel">
|
||||
<div class="panel-heading">
|
||||
<i class="icon-info-sign"></i>
|
||||
<span class="break"></span>
|
||||
<span class="panel-title"><%= t("update_manager_.update_status") %></span>
|
||||
</div>
|
||||
<div class="pannel-body">
|
||||
<div id="update_done" class="alert alert-success" style="font-size: 16px; text-align: center; margin: 0px;">
|
||||
<i class="icon-ok-sign"> <%= t("update_manager_.update_done") %></i>
|
||||
</div>
|
||||
<div id="update_failed" class="alert alert-error" style="font-size: 16px; text-align: center; margin: 0px;">
|
||||
<i class="icon-remove"> <%= t("update_manager_.update_faild") %></i>
|
||||
</div>
|
||||
<div id="update_progress">
|
||||
<img src="http://ridepal.com/images/homeimg/preloader_transparent.gif" width="50"><br/>
|
||||
<span id="progress_msg"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="padding: 10px 0; height: 65px;">
|
||||
<button id="chech_update_btn" class="btn btn-small btn-inverse pull-right"><i class="icon-refresh icon-white"></i> <%= t("update_manager_.check_update") %></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<div class="panel">
|
||||
<div class="panel-heading">
|
||||
<i class="icon-th-list"></i>
|
||||
<span class="break"></span>
|
||||
<span class="panel-title"><%= t("update_manager_.update_history") %></span>
|
||||
<span id="num_updates" class="badge badge-success pull-right"></span>
|
||||
</div>
|
||||
<div class="pannel-body" id="update-history-body">
|
||||
<table class="table table-striped">
|
||||
<tbody id="update_history_table">
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var update_logs;
|
||||
var update_log_display;
|
||||
var new_updates;
|
||||
|
||||
function get_update_history(){
|
||||
$.getJSON("<%= admin_site_get_update_history_path %>",function(data){
|
||||
update_logs = data;
|
||||
update_log_display = 0;
|
||||
$("#num_updates").text(update_logs.length);
|
||||
$("#update_history_table").html("");
|
||||
|
||||
show_update_history();
|
||||
});
|
||||
}
|
||||
|
||||
function show_update_history(){
|
||||
for(var i = 0; i<30; i++){
|
||||
var log = update_logs[update_log_display];
|
||||
update_log_display++;
|
||||
$("#update_history_table").append("<tr><td width=30%'>"+log[0]+"</td><td>"+log[1]+"</td></tr>");
|
||||
if((update_log_display+1)>update_logs.length) break;
|
||||
}
|
||||
}
|
||||
|
||||
function check_updates(){
|
||||
$("#progress_msg").html("<strong><%= t("update_manager_.checking_update") %></strong>");
|
||||
$("#new_update_container").fadeOut(function(){
|
||||
$("#update_done").fadeOut(function(){
|
||||
$("#update_status").fadeIn(function(){
|
||||
$("#update_progress").fadeIn();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$.getJSON("<%= admin_site_check_updates_path %>",function(data){
|
||||
new_updates = data;
|
||||
show_new_updates();
|
||||
});
|
||||
}
|
||||
|
||||
function show_new_updates(){
|
||||
if(new_updates.length){
|
||||
$("#num_new_updates").text(new_updates.length);
|
||||
$.each(new_updates,function(){
|
||||
$("#new_update_table").append("<tr><td>"+$(this)[0]+"</td><td>"+$(this)[1]+"</td></tr>");
|
||||
});
|
||||
$("#update_status").fadeOut(function(){$("#new_update_container").fadeIn();});
|
||||
}else{
|
||||
$("#update_progress").fadeOut(function(){$("#update_done").fadeIn();});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
check_updates();
|
||||
get_update_history();
|
||||
|
||||
$("#chech_update_btn").click(check_updates);
|
||||
|
||||
$("#update_btn").click(function(){
|
||||
$("#progress_msg").html("<strong><%= t("update_manager_.updating_orbit") %></strong>");
|
||||
$("#new_update_container").fadeOut(function(){
|
||||
$("#update_status").fadeIn();
|
||||
});
|
||||
$.get("<%= admin_site_update_orbit_path %>",function(result){
|
||||
if(result=="failed"){
|
||||
$("#chech_update_btn").hide();
|
||||
$("#update_progress").fadeOut(function(){$("#update_failed").fadeIn();});
|
||||
}else{
|
||||
$("#progress_msg").html("<strong><%= t("update_manager_.restart_server") %></strong>");
|
||||
$.get("<%= admin_site_restart_server_path %>",function(result){
|
||||
$("#update_progress").fadeOut(function(){$("#update_done").fadeIn();});
|
||||
$("#update_status").fadeIn();
|
||||
get_update_history();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#update-history-body").scroll(function () {
|
||||
if((update_log_display+1)<update_logs.length){
|
||||
var scroll_pos = ($("#update-history-body").scrollTop()+$("#update-history-body").height())/$("#update_history_table").height()*100;
|
||||
if(scroll_pos>90){
|
||||
show_update_history();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -532,6 +532,18 @@ en:
|
|||
success_: Successfully updated
|
||||
update_: Update
|
||||
update_at: Update at
|
||||
update_manager: Update Manager
|
||||
update_manager_:
|
||||
available_updates: Available Updates
|
||||
check_update: Check Update
|
||||
checking_update: Checking for Updates
|
||||
system_update: Install Updates
|
||||
update_done: System is update to date
|
||||
update_faild: Update failed. Merge is require in the update. Please login to server and update manually.
|
||||
update_history: Update Histroy
|
||||
update_status: Update Status
|
||||
updating_orbit: Updating Orbit. Please wait.
|
||||
restart_server: Restarting Server. Please wait.
|
||||
upload: Upload
|
||||
url: URL
|
||||
use_status: Use Statue
|
||||
|
|
|
@ -535,6 +535,18 @@ zh_tw:
|
|||
success_: 使用者已更新成功
|
||||
update_: 更新
|
||||
update_at: 最後更新時間
|
||||
update_manager: 更新管理員
|
||||
update_manager_:
|
||||
available_updates: 有可用更新
|
||||
check_update: 檢查更新
|
||||
checking_update: 檢查更新中
|
||||
system_update: 安裝更新
|
||||
update_done: 系統已是最新版本
|
||||
update_faild: 更新失敗. 更新需要合併程式碼. 請登入伺服器手動進行更新.
|
||||
update_history: 更新紀錄
|
||||
update_status: 更新狀態
|
||||
updating_orbit: 安裝更新中,請稍候.
|
||||
restart_server: 重啟伺服器中,請稍候.
|
||||
upload: 上傳
|
||||
url: 網址
|
||||
use_status: 使用狀態
|
||||
|
|
|
@ -212,6 +212,11 @@ Orbit::Application.routes.draw do
|
|||
get 'change_design'
|
||||
get 'reset_default_locale'
|
||||
get 'preference'
|
||||
get 'update_manager'
|
||||
get 'get_update_history'
|
||||
get 'check_updates'
|
||||
get 'update_orbit'
|
||||
get 'restart_server'
|
||||
end
|
||||
|
||||
resources :tags do
|
||||
|
|
Reference in New Issue