From 9599283586a0c8de75c4e65d308569c6aef6f37e Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 4 Dec 2014 21:59:49 +0800 Subject: [PATCH] added customization logs for registered site --- .../admin/customization_logs_controller.rb | 62 ++++++++++ app/models/registered_site.rb | 2 + app/models/site_log.rb | 14 +++ app/models/site_log_file.rb | 15 +++ .../admin/customization_logs/_form.html.erb | 114 ++++++++++++++++++ .../customization_logs/_form_file.html.erb | 38 ++++++ .../admin/customization_logs/_index.html.erb | 38 ++++++ .../customization_logs/_log_modal.html.erb | 13 ++ .../admin/customization_logs/edit.html.erb | 5 + .../admin/customization_logs/get_log.html.erb | 46 +++++++ .../admin/customization_logs/index.html.erb | 23 ++++ .../admin/customization_logs/new.html.erb | 5 + config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + config/routes.rb | 5 + lib/registered_sites/engine.rb | 8 +- 16 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/customization_logs_controller.rb create mode 100644 app/models/site_log.rb create mode 100644 app/models/site_log_file.rb create mode 100644 app/views/admin/customization_logs/_form.html.erb create mode 100644 app/views/admin/customization_logs/_form_file.html.erb create mode 100644 app/views/admin/customization_logs/_index.html.erb create mode 100644 app/views/admin/customization_logs/_log_modal.html.erb create mode 100644 app/views/admin/customization_logs/edit.html.erb create mode 100644 app/views/admin/customization_logs/get_log.html.erb create mode 100644 app/views/admin/customization_logs/index.html.erb create mode 100644 app/views/admin/customization_logs/new.html.erb diff --git a/app/controllers/admin/customization_logs_controller.rb b/app/controllers/admin/customization_logs_controller.rb new file mode 100644 index 0000000..4a0bff2 --- /dev/null +++ b/app/controllers/admin/customization_logs_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/registered_site.rb b/app/models/registered_site.rb index 06a7ee9..5f2cd8e 100644 --- a/app/models/registered_site.rb +++ b/app/models/registered_site.rb @@ -13,6 +13,8 @@ class RegisteredSite field :site_confirmed, type: Boolean, :default => false field :confirmation_token + has_many :site_logs + index({ confirmation_token: 1}, { unique: true }) def site_token diff --git a/app/models/site_log.rb b/app/models/site_log.rb new file mode 100644 index 0000000..cfe40c4 --- /dev/null +++ b/app/models/site_log.rb @@ -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 \ No newline at end of file diff --git a/app/models/site_log_file.rb b/app/models/site_log_file.rb new file mode 100644 index 0000000..36786f5 --- /dev/null +++ b/app/models/site_log_file.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/customization_logs/_form.html.erb b/app/views/admin/customization_logs/_form.html.erb new file mode 100644 index 0000000..cdbc05c --- /dev/null +++ b/app/views/admin/customization_logs/_form.html.erb @@ -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 %> + + +
+ + +
+ + + + + +
+ +
+ <%= f.text_field :title, class: "input-block-level", placeholder: t(:title) %> +
+
+ + +
+ +
+
+ <%= f.cktext_area :content, rows: 5, class: "input-block-level" %> +
+
+
+ +
+ + +
+ +
+ + + <% if @log && !@log.site_log_files.blank? %> +
+ <% @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 %> +
+
+ <% end %> + + +
+
+

+ <%= hidden_field_tag 'plugin_file_field_count', @log.site_log_files.count %> + <%= t(:add) %> +

+ +
+
+
+ + + +
+ <%= get_referer_url[:action] rescue "" %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + + <% if params[:action] == "new" %> + + <% else %> + + <% end %> + <%= link_to t('cancel'), admin_customization_logs_path, :class=>"btn" %> +
+ + + + + + diff --git a/app/views/admin/customization_logs/_form_file.html.erb b/app/views/admin/customization_logs/_form_file.html.erb new file mode 100644 index 0000000..d296b60 --- /dev/null +++ b/app/views/admin/customization_logs/_form_file.html.erb @@ -0,0 +1,38 @@ +<% if form_file.new_record? %> +
+<% else %> +
+ <% 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 %> +
+ + + + <%= f.text_field :title, :class => "input-medium", placeholder: t(:alternative) %> + + <% if form_file.new_record? %> + + + + <% else %> + + <%= f.hidden_field :id %> + + <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %> + + <% end %> +
+
\ No newline at end of file diff --git a/app/views/admin/customization_logs/_index.html.erb b/app/views/admin/customization_logs/_index.html.erb new file mode 100644 index 0000000..1b9666d --- /dev/null +++ b/app/views/admin/customization_logs/_index.html.erb @@ -0,0 +1,38 @@ + + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @registeredsites.each do |site| %> + + + + + + + + + + <% end %> + +
+ <%= site.title.nil? ? site.site_domain : site.title %> + <%= site.category.nil? ? "Category not assigned." : "#{site.category.title}".html_safe %> + <% site.tags.each do |tag| %> + + <%= tag.name %> + + <% end %> + + <% if !site.site_logs.blank? %> + View Log + <% end %> + Add Log +
+
;">
+
\ No newline at end of file diff --git a/app/views/admin/customization_logs/_log_modal.html.erb b/app/views/admin/customization_logs/_log_modal.html.erb new file mode 100644 index 0000000..57a6be1 --- /dev/null +++ b/app/views/admin/customization_logs/_log_modal.html.erb @@ -0,0 +1,13 @@ + + \ No newline at end of file diff --git a/app/views/admin/customization_logs/edit.html.erb b/app/views/admin/customization_logs/edit.html.erb new file mode 100644 index 0000000..9fcd99a --- /dev/null +++ b/app/views/admin/customization_logs/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @log, url: admin_customization_log_path(@log), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/customization_logs/get_log.html.erb b/app/views/admin/customization_logs/get_log.html.erb new file mode 100644 index 0000000..9899886 --- /dev/null +++ b/app/views/admin/customization_logs/get_log.html.erb @@ -0,0 +1,46 @@ +<% @logs.each_with_index do |log, i| %> +
+
+
+
Author :
+ <% user = User.find(log.create_user_id) %> +
<%= user.member_profile.nil? ? user.user_name : user.member_profile.name %>
+
+
+
Date :
+
<%= log.created_at %>
+
+ <% if !log.update_user_id.nil? %> +
+
Updated by :
+ <% user = User.find(log.update_user_id) %> +
<%= user.member_profile.nil? ? user.user_name : user.member_profile.name %>
+
+ <% end %> +
+
Title :
+
<%= log.title %>
+
+ <% if !log.site_log_files.blank? %> +
+ <% log.site_log_files.each_with_index do |file,index| %> +
<%= index == 0 ? "Files" : "" %>
+
+ <%= 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} %> +
+ <% end %> +
+ <% end %> +
+
Content :
+
<%= log.content.html_safe %>
+
+
+
+
+ +
+ <% if i != (@logs.length - 1) %> +
+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/customization_logs/index.html.erb b/app/views/admin/customization_logs/index.html.erb new file mode 100644 index 0000000..e138f19 --- /dev/null +++ b/app/views/admin/customization_logs/index.html.erb @@ -0,0 +1,23 @@ +<%= render_filter @filter_fields, "index_table" %> + + <%= render 'index'%> + + +<%= render "log_modal" %> + \ No newline at end of file diff --git a/app/views/admin/customization_logs/new.html.erb b/app/views/admin/customization_logs/new.html.erb new file mode 100644 index 0000000..3540dc1 --- /dev/null +++ b/app/views/admin/customization_logs/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @log, url: admin_customization_logs_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 31e239a..e410ef7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,6 +4,7 @@ en: status: Status permission: Access registered_sites: + customization_log: Customization Log registered_sites: Registered Sites all: All email_not_confirmed: Email not confirmed. diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 72f733f..7e07b54 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -4,6 +4,7 @@ zh_tw: status: Status permission: Access registered_sites: + customization_log: Customization Log registered_sites: Registered Sites all: All email_not_confirmed: Email not confirmed. diff --git a/config/routes.rb b/config/routes.rb index 991fcf1..d752ce4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,11 @@ Rails.application.routes.draw do namespace :admin do get "/registered_site/change_access/:uid" => "registered_sites#change_access_status" resources :registered_sites + resources :customization_logs do + member do + get "get_log" => "customization_logs#get_log" + end + end end end diff --git a/lib/registered_sites/engine.rb b/lib/registered_sites/engine.rb index 97ef65a..83bc4d2 100644 --- a/lib/registered_sites/engine.rb +++ b/lib/registered_sites/engine.rb @@ -20,10 +20,16 @@ module RegisteredSites :active_for_action=>{'admin/registered_sites'=>"index"}, :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', :link_path=>"admin_module_app_categories_path" , :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_category => 'RegisteredSite', :available_for => 'managers'