added customization logs for registered site

This commit is contained in:
Harry Bomrah 2014-12-04 21:59:49 +08:00
parent 2967ee8c9f
commit 9599283586
16 changed files with 389 additions and 1 deletions

View File

@ -0,0 +1,62 @@
class Admin::CustomizationLogsController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
def initialize
super
@app_title = "registered_site"
end
def index
@registeredsites = RegisteredSite.all.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
@table_fields = table_fields
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@filter_fields = filter_fields_without_status(@categories, @tags)
@registeredsites = search_data(@registeredsites,[:title]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def get_log
@site = RegisteredSite.find(params[:id])
@logs = @site.site_logs.desc(:created_at)
render :layout => false
end
def new
@log = SiteLog.new
@site = RegisteredSite.find(params[:id])
end
def update
log = SiteLog.find(params[:id])
log.update_attributes(site_log_params)
log.save
redirect_to params['referer_url']
end
def edit
@log = SiteLog.find(params[:id])
@site = @log.registered_site
end
def create
log = SiteLog.new
log.update_attributes(site_log_params)
log.save
redirect_to params['referer_url']
end
private
def table_fields
[:domain, :category, :tags, :actions]
end
def site_log_params
params.require(:site_log).permit!
end
end

View File

@ -13,6 +13,8 @@ class RegisteredSite
field :site_confirmed, type: Boolean, :default => false field :site_confirmed, type: Boolean, :default => false
field :confirmation_token field :confirmation_token
has_many :site_logs
index({ confirmation_token: 1}, { unique: true }) index({ confirmation_token: 1}, { unique: true })
def site_token def site_token

14
app/models/site_log.rb Normal file
View File

@ -0,0 +1,14 @@
class SiteLog
include Mongoid::Document
include Mongoid::Timestamps
field :title
field :content
field :create_user_id, type: BSON::ObjectId
field :update_user_id, type: BSON::ObjectId
belongs_to :registered_site
has_many :site_log_files, autosave: true, dependent: :destroy
accepts_nested_attributes_for :site_log_files, :allow_destroy => true
end

View File

@ -0,0 +1,15 @@
# encoding: utf-8
class SiteLogFile
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Attributes::Dynamic
mount_uploader :file, AssetUploader
field :title, localize: true
field :should_destroy, type: Boolean
belongs_to :site_log
end

View File

@ -0,0 +1,114 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<!-- Input Area -->
<div class="input-area">
<!-- Language -->
<div class="tab-content language-area">
<!-- site domain and title -->
<div class="control-group input-title">
<label class="control-label muted"><%= t(:domain) %></label>
<div class="controls">
<a href="http://<%= @site.site_domain %>/" target="_blank"><%= @site.title.nil? ? @site.site_domain : @site.title %></a>
</div>
</div>
<!-- Title-->
<div class="control-group input-title">
<label class="control-label muted"><%= t(:title) %></label>
<div class="controls">
<%= f.text_field :title, class: "input-block-level", placeholder: t(:title) %>
</div>
</div>
<!-- Content -->
<div class="control-group input-content">
<label class="control-label muted"><%= t(:content) %></label>
<div class="controls">
<div class="textarea">
<%= f.cktext_area :content, rows: 5, class: "input-block-level" %>
</div>
</div>
</div>
</div>
<!-- File -->
<div class="control-group">
<label class="control-label muted"><%= t(:file_) %></label>
<div class="controls">
<!-- Exist -->
<% if @log && !@log.site_log_files.blank? %>
<div class="exist">
<% @log.site_log_files.each_with_index do |file, i| %>
<%= f.fields_for :site_log_files, file do |f| %>
<%= render :partial => 'form_file', :object => file, :locals => {:f => f, :i => i} %>
<% end %>
<% end %>
<hr>
</div>
<% end %>
<!-- Add -->
<div class="add-target">
</div>
<p class="add-btn">
<%= hidden_field_tag 'plugin_file_field_count', @log.site_log_files.count %>
<a id="add_file" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
</div>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= get_referer_url[:action] rescue "" %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
<input type="hidden" name="site_log[registered_site_id]" value="<%= @site.id.to_s %>">
<% if params[:action] == "new" %>
<input type="hidden" name="site_log[create_user_id]" value="<%= current_user.id.to_s %>">
<% else %>
<input type="hidden" name="site_log[update_user_id]" value="<%= current_user.id.to_s %>">
<% end %>
<%= link_to t('cancel'), admin_customization_logs_path, :class=>"btn" %>
</div>
<script>
$('.main-forms').find('.add-on').tooltip().end().on('click', '.trigger, .delete_file, .remove_existing_record', function() {
if($(this).hasClass('trigger')) {
var new_id = $(this).prev().attr('value');
console.log(new_id);
var old_id = new RegExp("new_site_log_files", "g");
var on = $('.language-nav li.active').index();
var le = $(this).parent('.add-btn').prev('.add-target').children('.start-line').length;
$(this).prev().attr('value', parseInt(new_id) + 1);
$(this).parent().siblings('.add-target').append(("<%= escape_javascript(add_attribute 'form_file', f, :site_log_files) %>").replace(old_id, new_id));
} else if($(this).hasClass('delete_file')) {
$(this).parents('.input-prepend').remove();
} else if($(this).hasClass('remove_existing_record')) {
if(confirm("<%= I18n.t(:sure?)%>")){
$(this).children('.should_destroy').attr('value', 1);
$(this).parents('.start-line').hide();
}
}
});
</script>

View File

@ -0,0 +1,38 @@
<% if form_file.new_record? %>
<div class="fileupload fileupload-new start-line" data-provides="fileupload">
<% else %>
<div class="fileupload fileupload-exist start-line" data-provides="fileupload">
<% if form_file.file.blank? %>
<%= t(:no_file) %>
<% else %>
<%= link_to content_tag(:i) + form_file.file_identifier, form_file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => form_file.file_identifier} %>
<% end %>
<% end %>
<div class="input-prepend input-append">
<label>
<span class="add-on btn btn-file" title='<%= t(:file_) %>'>
<i class="icons-paperclip"></i>
<%= f.file_field :file %>
</span>
<div class="uneditable-input input-medium">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"><%= (form_file.new_record? || form_file.file.blank?) ? t(:select_file) : t(:change_file) %></span>
</div>
</label>
<span class="add-on icons-pencil" title='<%= t(:alternative) %>'></span>
<span class="tab-content">
<%= f.text_field :title, :class => "input-medium", placeholder: t(:alternative) %>
</span>
<% if form_file.new_record? %>
<span class="delete_file add-on btn" title="<%= t(:delete_) %>">
<a class="icon-trash"></a>
</span>
<% else %>
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
<%= f.hidden_field :id %>
<a class="icon-remove"></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
</span>
<% end %>
</div>
</div>

View File

@ -0,0 +1,38 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @registeredsites.each do |site| %>
<tr>
<td class="domain_title_block">
<a href="http://<%= site.site_domain %>/" target="_blank"><%= site.title.nil? ? site.site_domain : site.title %></a>
</td>
<td><%= site.category.nil? ? "Category not assigned." : "<span class='label label-info'>#{site.category.title}</span>".html_safe %></td>
<td>
<% site.tags.each do |tag| %>
<span class="label">
<%= tag.name %>
</span>
<% end %>
</td>
<td>
<% if !site.site_logs.blank? %>
<a data-toggle="modal" href="/admin/customization_logs/<%= site.id.to_s %>/get_log" data-target="#logModal" class="btn view_log_btn">View Log</a>
<% end %>
<a href="<%= new_admin_customization_log_path(:id => site.id) %>" class="btn btn-primary">Add Log</a>
</td>
</tr>
<tr>
<td colspan="<%= @table_fields.length %>" style="padding:0; border:0;">
<div class="line" style="width:auto; height:2px; background-color:<%= site.active? ? "green" : "red" %>;"></div>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -0,0 +1,13 @@
<!-- Modal -->
<div id="logModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="logModal" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4>Customization log for</h4>
<h3 id="domain_title"></h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>

View File

@ -0,0 +1,5 @@
<%= form_for @log, url: admin_customization_log_path(@log), html: {class: "form-horizontal main-forms previewable"} do |f| %>
<fieldset>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -0,0 +1,46 @@
<% @logs.each_with_index do |log, i| %>
<div class="row">
<div class="span9">
<div class="row">
<div class="span2 muted">Author :</div>
<% user = User.find(log.create_user_id) %>
<div class="span7"><%= user.member_profile.nil? ? user.user_name : user.member_profile.name %></div>
</div>
<div class="row">
<div class="span2 muted">Date :</div>
<div class="span7"><%= log.created_at %></div>
</div>
<% if !log.update_user_id.nil? %>
<div class="row">
<div class="span2 muted">Updated by :</div>
<% user = User.find(log.update_user_id) %>
<div class="span7"><%= user.member_profile.nil? ? user.user_name : user.member_profile.name %></div>
</div>
<% end %>
<div class="row">
<div class="span2 muted">Title :</div>
<div class="span7"><%= log.title %></div>
</div>
<% if !log.site_log_files.blank? %>
<div class="row">
<% log.site_log_files.each_with_index do |file,index| %>
<div class="span2 muted"><%= index == 0 ? "Files" : "" %></div>
<div class="span7">
<%= link_to (file.title.nil? || file.title == "" ? file.file_identifier : file.title), file.file.url, {:class => 'file-link file-type', :target => '_blank', :title => file.file_identifier} %>
</div>
<% end %>
</div>
<% end %>
<div class="row">
<div class="span2 muted">Content :</div>
<div class="span7"><%= log.content.html_safe %></div>
</div>
</div>
</div>
<div class="row">
<div class="span9" style="text-align:center;font-size:15px;"><a href="<%= edit_admin_customization_log_path(log) %>">Edit</a></div>
</div>
<% if i != (@logs.length - 1) %>
<hr />
<% end %>
<% end %>

View File

@ -0,0 +1,23 @@
<%= render_filter @filter_fields, "index_table" %>
<span id="index_table">
<%= render 'index'%>
</span>
<style type="text/css">
#logModal{
width: 80%;
margin-left: -40%;
}
#logModal .modal-body{
max-height: 600px;
}
</style>
<%= render "log_modal" %>
<script type="text/javascript">
var clicked_button = null;
$(".view_log_btn").on("click",function(){
clicked_button = $(this);
})
$("#logModal").on("shown",function(){
$("#domain_title").html(clicked_button.parent().parent().find("td.domain_title_block").html());
})
</script>

View File

@ -0,0 +1,5 @@
<%= form_for @log, url: admin_customization_logs_path, html: {class: "form-horizontal main-forms previewable"} do |f| %>
<fieldset>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -4,6 +4,7 @@ en:
status: Status status: Status
permission: Access permission: Access
registered_sites: registered_sites:
customization_log: Customization Log
registered_sites: Registered Sites registered_sites: Registered Sites
all: All all: All
email_not_confirmed: Email not confirmed. email_not_confirmed: Email not confirmed.

View File

@ -4,6 +4,7 @@ zh_tw:
status: Status status: Status
permission: Access permission: Access
registered_sites: registered_sites:
customization_log: Customization Log
registered_sites: Registered Sites registered_sites: Registered Sites
all: All all: All
email_not_confirmed: Email not confirmed. email_not_confirmed: Email not confirmed.

View File

@ -6,6 +6,11 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
get "/registered_site/change_access/:uid" => "registered_sites#change_access_status" get "/registered_site/change_access/:uid" => "registered_sites#change_access_status"
resources :registered_sites resources :registered_sites
resources :customization_logs do
member do
get "get_log" => "customization_logs#get_log"
end
end
end end
end end

View File

@ -20,10 +20,16 @@ module RegisteredSites
:active_for_action=>{'admin/registered_sites'=>"index"}, :active_for_action=>{'admin/registered_sites'=>"index"},
:available_for => 'users' :available_for => 'users'
context_link 'registered_sites.customization_log',
:link_path=>"admin_customization_logs_path",
:priority=>2,
:active_for_action=>{'admin/customization_logs'=>'index'},
:available_for => 'sub_managers'
context_link 'categories', context_link 'categories',
:link_path=>"admin_module_app_categories_path" , :link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'registered_site').id}", :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'registered_site').id}",
:priority=>2, :priority=>3,
:active_for_action=>{'admin/registered_sites'=>'categories'}, :active_for_action=>{'admin/registered_sites'=>'categories'},
:active_for_category => 'RegisteredSite', :active_for_category => 'RegisteredSite',
:available_for => 'managers' :available_for => 'managers'