added hidden and show
This commit is contained in:
parent
e6c7b932aa
commit
5af9cfe9e2
|
@ -230,7 +230,7 @@ end
|
|||
|
||||
def add_entry
|
||||
entry = TableEntry.new(table_entry_params)
|
||||
create_get_table_tags(@entry)
|
||||
create_get_table_tags(entry)
|
||||
entry.save
|
||||
entry.fix_have_data
|
||||
table = UTable.find(params[:table_entry][:u_table_id])
|
||||
|
@ -263,6 +263,13 @@ end
|
|||
redirect_to admin_universal_table_path(:id=> table.to_param, :page => params[:page])
|
||||
end
|
||||
|
||||
def toggle_entries
|
||||
ids = params[:ids]
|
||||
hidden = params[:status] == "hide"
|
||||
TableEntry.where(:id.in => ids).update_all(is_hidden: hidden)
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
def new
|
||||
@table = UTable.new
|
||||
end
|
||||
|
@ -338,7 +345,7 @@ end
|
|||
columns_count = columns.count
|
||||
columns_count = 1 if columns_count==0
|
||||
columns = Kaminari.paginate_array(columns,limit: columns_count)
|
||||
entries = TableEntry.where(:u_table_id=>table.id).sorting(params: params,table: table,column_entries: columns,page_num: params[:page],per: per)
|
||||
entries = TableEntry.where(:u_table_id=>table.id).can_display.sorting(params: params,table: table,column_entries: columns,page_num: params[:page],per: per)
|
||||
end
|
||||
|
||||
def table_params
|
||||
|
|
|
@ -127,15 +127,15 @@ class UniversalTablesController < ApplicationController
|
|||
end
|
||||
if paginated
|
||||
if tag.nil?
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).can_display.sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
||||
else
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}, :table_tag_ids => tag.id).sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}, :table_tag_ids => tag.id).can_display.sorting(params: params,table: table,page_num: params["page_no"],per: OrbitHelper.page_data_count)
|
||||
end
|
||||
else
|
||||
if tag.nil?
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).sorting(params: params,table: table,paginated: false)
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}).can_display.sorting(params: params,table: table,paginated: false)
|
||||
else
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}, :table_tag_ids => tag.id).sorting(params: params,table: table,paginated: false)
|
||||
entries = TableEntry.where(:u_table_id=>table.id, "have_data.#{I18n.locale}" => {"$in" => [nil, true]}, :table_tag_ids => tag.id).can_display.sorting(params: params,table: table,paginated: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class TableEntry
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include OrbitModel::Status
|
||||
include Slug
|
||||
|
||||
attr_accessor :sort_value
|
||||
|
@ -14,6 +15,7 @@ class TableEntry
|
|||
has_and_belongs_to_many :table_tags, inverse_of: :table_entries
|
||||
|
||||
accepts_nested_attributes_for :column_entries, :allow_destroy => true
|
||||
scope :can_display, ->{where(:is_hidden.ne=>true)}
|
||||
|
||||
I18n.available_locales.each do |locale|
|
||||
index({"have_data.#{locale}" => 1}, { unique: false, background: true })
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "universal_table/universal-table" %>
|
||||
<% end %>
|
||||
<style>
|
||||
.hidden_entry{
|
||||
background-color: grey;
|
||||
}
|
||||
</style>
|
||||
<form class="form-search" action="<%= admin_universal_table_path(@table) %>" method="get">
|
||||
<input type="text" name="q" class="input-large search-query" placeholder="Search from text or editor columns">
|
||||
<button type="submit" class="btn btn-primary">Search</button>
|
||||
|
@ -13,6 +18,13 @@
|
|||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<th width="15">
|
||||
<%= t(:status) %>
|
||||
<div class="status hide" id="entry-status">
|
||||
<a href="" class="toggle_entries" data-status="hide"><%= t(:hide) %></a>
|
||||
<a href="" class="toggle_entries" data-status="show"><%= t(:show) %></a>
|
||||
</div>
|
||||
</th>
|
||||
<% @table_fields.each do |field| %>
|
||||
<%
|
||||
sort = field.to_s.include?('.') ? field.to_s.split('.')[1] : field.to_s
|
||||
|
@ -29,7 +41,8 @@
|
|||
<tbody>
|
||||
<% can_edit = can_edit_or_delete?(@table) %>
|
||||
<% @entries.each do |entry| %>
|
||||
<tr>
|
||||
<tr id="tr_entry_<%= entry.id.to_s %>" class="<%= entry.is_hidden? ? 'hidden_entry' : '' %>">
|
||||
<td><input class="hide-toggle" type="checkbox" value="<%= entry.id.to_s %>" /></td>
|
||||
<% @columns.each_with_index do |column, index| %>
|
||||
<% ce = entry.column_entries.where(:table_column_id => column.id).first rescue nil %>
|
||||
<td>
|
||||
|
@ -123,4 +136,31 @@ $(".voice-player").on("click", function(){
|
|||
}
|
||||
return false;
|
||||
})
|
||||
$(".hide-toggle").on("click", function(){
|
||||
var count = $(".hide-toggle:checked").length;
|
||||
if(count > 0){
|
||||
$("#entry-status").removeClass("hide")
|
||||
}else{
|
||||
$("#entry-status").addClass("hide")
|
||||
}
|
||||
})
|
||||
$(".toggle_entries").on("click", function(){
|
||||
let checkedValues = $('.hide-toggle:checked').map(function() {
|
||||
return $(this).val();
|
||||
}).get();
|
||||
let status = $(this).data("status");
|
||||
$.ajax({
|
||||
url: "/admin/universal_tables/toggle_entries",
|
||||
method: "post",
|
||||
data: {"ids": checkedValues, "status": status},
|
||||
type: "json"
|
||||
}).done(function(){
|
||||
if(status == "hide"){
|
||||
$('.hide-toggle:checked').parents("tr").addClass("hidden_entry");
|
||||
}else{
|
||||
$('.hide-toggle:checked').parents("tr").removeClass("hidden_entry");
|
||||
}
|
||||
})
|
||||
return false;
|
||||
})
|
||||
</script>
|
|
@ -32,4 +32,5 @@ en:
|
|||
save_mind_map: Save mind map
|
||||
hashtags: Hashtags
|
||||
related_entries: Related entries
|
||||
search_entries: Search entries
|
||||
search_entries: Search entries
|
||||
status: Status
|
|
@ -32,4 +32,5 @@ zh_tw:
|
|||
save_mind_map: Save mind map
|
||||
hashtags: Hashtags
|
||||
related_entries: Related entries
|
||||
search_entries: Search entries
|
||||
search_entries: Search entries
|
||||
status: Status
|
|
@ -18,6 +18,7 @@ Rails.application.routes.draw do
|
|||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
namespace :admin do
|
||||
post "/universal_tables/add_entry", to: 'universal_tables#add_entry'
|
||||
post "/universal_tables/toggle_entries", to: 'universal_tables#toggle_entries'
|
||||
get "/universal_tables/get_entries", to: 'universal_tables#get_entries'
|
||||
get "/universal_tables/get_mindmaps", to: 'universal_tables#get_mindmaps'
|
||||
patch "/universal_tables/update_entry", to: 'universal_tables#update_entry'
|
||||
|
|
Loading…
Reference in New Issue