New UI changes(tags, categories, authorisations, module index…)
To run: - ruby lib/remove_old_tags.rb DB_NAME - rake new_ui:migrate_tags - rake new_ui:migrate_categories['APP_KEY,''MODEL_NAME'] (check new_ui.rake for more details)
This commit is contained in:
1 parent
07b3857465
commit
856898016b
1495 files changed
+52132
-9876
No files matched your search
@@ -0,0 +1,15 @@
|
||||
module Admin::CategoriesHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
|
||||
|
||||
def show_permission_link(category)
|
||||
type = 'submit'
|
||||
oa = category.get_object_auth_by_title(type)
|
||||
if oa.nil?
|
||||
category.object_auths.new(title: type ).save
|
||||
oa = category.get_object_auth_by_title(type)
|
||||
end
|
||||
link_to t(:category_auth), admin_object_auth_ob_auth_path(oa)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -40,5 +40,14 @@ module Admin::ItemsHelper
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def get_item_module_infos(item)
|
||||
if module_app = item.module_app
|
||||
app = OrbitApp::Module::Registration.find_by_key(module_app.key)
|
||||
[t(app.get_label_i18n), (app.get_icon_class rescue 'icons-daniel-bruce-2')]
|
||||
else
|
||||
[t(:no_app), 'icons-daniel-bruce-2']
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
module Admin::TagsHelper
|
||||
|
||||
def get_module_app_icon(module_app)
|
||||
app = OrbitApp::Module::Registration.find_by_key(module_app.key)
|
||||
app.get_icon_class rescue 'icons-daniel-bruce-2'
|
||||
end
|
||||
|
||||
def show_names_slash(tag)
|
||||
span_names = @site_valid_locales.inject([]) do |names, locale|
|
||||
names << content_tag(:span, tag.name_translations[locale], class: "tag")
|
||||
end
|
||||
span_names.join(" / ").html_safe
|
||||
end
|
||||
|
||||
def get_tagging_count(module_tag)
|
||||
if module_tag.is_default && module_tag.parent.blank?
|
||||
count = module_tag.children.inject(0) do |count, child|
|
||||
count += child.tag.taggings.count
|
||||
count
|
||||
end
|
||||
else
|
||||
count = module_tag.tag.taggings.count
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -39,7 +39,7 @@ module ApplicationHelper
|
||||
def current_or_guest_user
|
||||
if current_user
|
||||
if session[:guest_user_id]
|
||||
guest_user.destroy
|
||||
User.find(session[:guest_user_id]).destroy rescue nil
|
||||
session[:guest_user_id] = nil
|
||||
end
|
||||
current_user
|
||||
@@ -190,18 +190,10 @@ module ApplicationHelper
|
||||
|
||||
def page_stylesheets(page, edit=nil)
|
||||
stylesheets = ''
|
||||
unless edit
|
||||
stylesheets << "<link href='/assets/bootstrap-orbit.css' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='/assets/style.css' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='/assets/icons.css' rel='stylesheet' type='text/css' />\n"
|
||||
end
|
||||
stylesheets << "<link href='#{asset_path 'orbit_bar_bootstrap'}' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='#{page.design.css_reset.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.css_reset
|
||||
stylesheets << "<link href='/assets/bootstrap.css' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='/assets/font-awesome.css' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='/assets/orbit-bar.css' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='/assets/social-share-button.css' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='#{asset_path 'banner_nav.css'}' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='#{asset_path 'default_widget.css'}' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='#{asset_path 'banner_nav.css'}' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='#{asset_path 'default_widget.css'}' rel='stylesheet' type='text/css' />\n"
|
||||
stylesheets << "<link href='#{page.design.css_default.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.css_default
|
||||
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
|
||||
stylesheets << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />\n" if theme
|
||||
@@ -210,20 +202,8 @@ module ApplicationHelper
|
||||
|
||||
def page_javascripts(page, edit=nil)
|
||||
javascripts = ''
|
||||
unless edit
|
||||
javascripts << "<script type='text/javascript' src='/static/jquery.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/bootstrap.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/jquery.tinyscrollbar.min.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/orbit-bar-member.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/orbit_bar.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/orbit-bar-search.js'></script>\n"
|
||||
end
|
||||
javascripts << "<script type='text/javascript' src='/assets/lib/jquery.preload-min.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/static/kernel.js'></script>\n"
|
||||
# javascripts << "<script type='text/javascript' src='/assets/social-share-button.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/lib/social-share-button.js'></script>\n"
|
||||
javascripts << "<script type='text/javascript' src='/assets/event.js'></script>\n"
|
||||
# javascripts << "<script type='text/javascript' src='/assets/lib/jquery.preload-min.js'></script>\n"
|
||||
# javascripts << "<script type='text/javascript' src='/assets/jquery.cycle.all.latest.js'></script>\n"
|
||||
page.design.javascripts.each do |js|
|
||||
javascripts << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
end
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
module DefaultIndexHelper
|
||||
|
||||
def show_title_at_index(object)
|
||||
if object.class.instance_methods.include?(:is_checked?) && object.bulletin.is_checked?
|
||||
link_to bulletin.title, panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.category.id) rescue ''
|
||||
else
|
||||
bulletin.title
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,51 +1,302 @@
|
||||
module OrbitBackendHelper
|
||||
|
||||
def sortable(column)
|
||||
direction = (column == params[:sort] && params[:direction] == "asc") ? "desc" : "asc"
|
||||
{:sort => column, :direction => direction}
|
||||
#========================================================================================================================
|
||||
# from bulletin_helper.rb
|
||||
#========================================================================================================================
|
||||
|
||||
def show_reject_reason(object)
|
||||
by_object = object.is_rejected
|
||||
by_user = (((object.create_user_id == current_user.id) rescue nil) or is_manager? or is_admin?)
|
||||
by_object && by_user
|
||||
end
|
||||
|
||||
def is_sort_active?(name)
|
||||
res = ''
|
||||
res << ' select' if params[:sort].eql?(name)
|
||||
res << ' active' if params[:sort].eql?(name) && params[:direction].eql?('asc')
|
||||
res
|
||||
def show_form_status_field(object)
|
||||
#by_object = (!object.is_expired? and object.is_pending?)
|
||||
by_user = ((object.category.authed_users("fact_check_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?)
|
||||
by_user
|
||||
end
|
||||
|
||||
def is_sort?(name)
|
||||
' web-symbol' if params[:sort].eql?(name)
|
||||
def show_approval_link(object)
|
||||
by_object = (!object.is_expired? and object.is_pending?)
|
||||
by_user = ((object.category.authed_users("fact_check_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin?)
|
||||
by_object and by_user
|
||||
end
|
||||
|
||||
def show_delete_link(object)
|
||||
if !current_user.nil?
|
||||
by_object = (object.create_user_id == current_user.id )
|
||||
by_user = (is_manager? or is_admin?)
|
||||
by_object or by_user
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# def show_bulletin_title_at_index (bulletin)
|
||||
# if bulletin.is_checked?
|
||||
# link_to bulletin.title, panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''
|
||||
# else
|
||||
# bulletin.title
|
||||
# end
|
||||
# end
|
||||
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
#========================================================================================================================
|
||||
|
||||
def is_filter_active?(type, id)
|
||||
' active' if (@filter[type].include?(id.to_s) rescue nil)
|
||||
end
|
||||
|
||||
def render_sort_bar(delete_all, url, *titles)
|
||||
content_tag :table, :class => "table main-list" do
|
||||
content_tag :thead do
|
||||
content_tag :tr, :class => "sort-header" do
|
||||
concat (content_tag :th, :class => "span1 strong" do
|
||||
concat check_box_tag :check_all
|
||||
concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove", :rel => url
|
||||
end) if (delete_all && (is_admin? || (is_manager? rescue nil)))
|
||||
titles.each do |title|
|
||||
concat render_title(title[0], title[1], title[2], title[3])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def render_title(title, fields, span, translation)
|
||||
content_tag :th, :class => "sort #{span} #{is_sort_active?(title)}" do
|
||||
content_tag :span do
|
||||
link_to (t(translation) + content_tag(:b, nil, :class => is_sort?(title))).html_safe, url_for({:filter => @filter}.merge(sortable(title).merge(:sort_options => fields))), :class => 'js_history'
|
||||
end
|
||||
def is_sort_active?(field)
|
||||
res = t(field[:translation])
|
||||
if params[:sort].eql?(field[:sort])
|
||||
res << " " + content_tag(:b, nil, class: (params[:direction].eql?('asc') ? "icons-arrow-up-3" : "icons-arrow-down-4 "))
|
||||
end
|
||||
res.html_safe
|
||||
end
|
||||
|
||||
def show_toggle_archive_btn(object)
|
||||
object.disable ? t(:disable) : t(:enable)
|
||||
object.disable ? t(:disable) : t(:enable)
|
||||
end
|
||||
|
||||
def sortable_options(column)
|
||||
direction = (column == params[:sort] && params[:direction] == "asc") ? "desc" : "asc"
|
||||
{:sort => column, :direction => direction}
|
||||
end
|
||||
|
||||
|
||||
# ===============================================================
|
||||
# associated:
|
||||
#
|
||||
# TODO: link for other types
|
||||
# ===============================================================
|
||||
def get_value(object, field)
|
||||
authorization = !@authorization || (@authorization && is_authorized(object))
|
||||
approvable = !@approvable || (@approvable && is_approvable(object))
|
||||
res = ''
|
||||
case field[:type]
|
||||
when 'associated'
|
||||
res << object.send(field[:db_field]).send(field[:associated_value]) rescue ''
|
||||
when 'date'
|
||||
res << (object.send(field[:db_field]) ? display_date_time(object.send(field[:db_field])) : t(:no_date))
|
||||
when 'field'
|
||||
res << with_link?(field, object, object.send(field[:db_field]))
|
||||
if field[:quick_edit]
|
||||
res << (content_tag :div, class: "quick-edit" do
|
||||
content_tag :ul, class: "nav nav-pills" do
|
||||
@quick_edit.each do |quick|
|
||||
concat get_quick_link(quick, object, authorization, approvable)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
when 'status'
|
||||
if object.is_top?
|
||||
res << content_tag(:span, t(:top), class: "label label-success") + ' '
|
||||
end
|
||||
if object.is_hot?
|
||||
res << content_tag(:span, t(:hot), class: "label label-important") + ' '
|
||||
end
|
||||
if object.is_hidden?
|
||||
res << content_tag(:span, t(:hidden), class: "label") + ' '
|
||||
end
|
||||
if object.is_pending?
|
||||
res << content_tag(:span, t(:pending), class: "label") + ' '
|
||||
end
|
||||
if object.is_checked?
|
||||
res << content_tag(:span, t(:passed), class: "label") + ' '
|
||||
end
|
||||
if object.is_rejected?
|
||||
res << content_tag(:span, t(:rejected), class: "label") + ' '
|
||||
end
|
||||
when 'tags'
|
||||
object.sorted_tags.each do |tag|
|
||||
res << content_tag(:span, tag.name, class: "label label-warning")
|
||||
end if object.tags
|
||||
res.html_safe
|
||||
when 'id'
|
||||
res << field[:id_model].constantize.find(object.send(field[:db_field])).name rescue ''
|
||||
end
|
||||
res.html_safe
|
||||
end
|
||||
|
||||
def index_table
|
||||
content_tag :table, class: "table main-list" do
|
||||
concat (content_tag :thead do
|
||||
(content_tag :tr, class: "sort-header" do
|
||||
@fields.each do |field|
|
||||
concat (content_tag :th, "data-hide" => field[:hide], class: "#{field[:header_class]} #{'active' if params[:sort].eql?(field[:sort])}" do
|
||||
if @sortable && field[:sort]
|
||||
link_to is_sort_active?(field), url_for({:filter => @filter}.merge(sortable_options(field[:sort]).merge(:sort_options => field[:db_field])))
|
||||
else
|
||||
t(field[:translation])
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
concat (content_tag :tbody do
|
||||
(@objects.each do |object|
|
||||
concat (content_tag :tr do
|
||||
(@fields.each do |field|
|
||||
concat(content_tag :td, get_value(object, field))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def set_default_index(&block)
|
||||
@approvable = false
|
||||
@authorization = false
|
||||
@fields = []
|
||||
@filter_fields =[]
|
||||
@filterable = false
|
||||
@index_footer = nil
|
||||
@quick_edit = []
|
||||
@sortable = false
|
||||
block.call
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def approvable
|
||||
@approvable = true
|
||||
end
|
||||
|
||||
def authorization
|
||||
@authorization = true
|
||||
end
|
||||
|
||||
# ===============================================================
|
||||
# type:
|
||||
# check "get_value"
|
||||
# associated_value:
|
||||
# check "get_value"
|
||||
# db_field:
|
||||
# name of the field(s) in the database
|
||||
# translation:
|
||||
# key in the yml translation files
|
||||
# hide:
|
||||
# - no value: always shown
|
||||
# - all: alway hidden
|
||||
# - phone: hidden for phone
|
||||
# sort:
|
||||
# unique value used for keeping the sorted column
|
||||
# link:
|
||||
# if provided, the values will be shown as link
|
||||
# (only available for type 'field' for now)
|
||||
# ===============================================================
|
||||
def field(args={})
|
||||
if !args.blank? && args[:type] && args[:translation] && args[:db_field]
|
||||
case args[:type]
|
||||
when 'status', 'field', 'date', 'tags'
|
||||
@fields << args
|
||||
when 'associated'
|
||||
@fields << args if args[:associated_value]
|
||||
when 'id'
|
||||
@fields << args if args[:id_model]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def filter_field(args={})
|
||||
if !args.blank? && args[:type] && args[:values] && args[:translation]
|
||||
case args[:type]
|
||||
when 'array'
|
||||
@filter_fields << args
|
||||
when 'objects'
|
||||
@filter_fields << args if args[:object_field]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def filterable
|
||||
@filterable = true
|
||||
end
|
||||
|
||||
# ===============================================================
|
||||
# args:
|
||||
# - paginate: default true, there'es no need to specify it
|
||||
# - link: path to the new action
|
||||
# TODO: links to other actions
|
||||
# ===============================================================
|
||||
def footer(args={})
|
||||
paginate = args.has_key?(:paginate) ? args[:paginate] : true
|
||||
link = (is_manager? || is_sub_manager? rescue nil) && args.has_key?(:link) ? true : false
|
||||
if paginate || link
|
||||
@index_footer = content_tag :div, class: "bottomnav clearfix" do
|
||||
concat content_tag :div, link_to(content_tag(:i, nil, :class => 'icon-plus') + ' ' + t(:add), send(args[:link]), :class => 'btn btn-primary' ), class: "action pull-right" if link
|
||||
concat content_tag :div, paginate(@objects, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]}), class: "pagination pagination-centered" if paginate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_quick_link(quick, object, authorization, approvable)
|
||||
case quick[:type]
|
||||
when 'approval'
|
||||
if show_approval_link(object)
|
||||
content_tag :li, link_to(t(quick[:translation] || :approval_), eval("#{quick[:link]}('#{object.id}')"), class: "preview_trigger #{quick[:class]}")
|
||||
end
|
||||
when 'edit'
|
||||
if authorization || approvable
|
||||
content_tag :li, link_to(t(quick[:translation] || :edit), eval("#{quick[:link]}('#{object.id}')"), class: quick[:class])
|
||||
end
|
||||
when 'delete'
|
||||
if show_delete_link(object)
|
||||
content_tag :li, link_to(t(quick[:translation] || :delete_), '#', rel: eval("#{quick[:link]}('#{object.id}')"), class: "delete_link #{quick[:class] || 'text-error'}")
|
||||
end
|
||||
when 'detail'
|
||||
content_tag :li, link_to(t(quick[:translation] || :detail), '#', class: (quick[:class] || "detail-row"))
|
||||
when 'reject_reason'
|
||||
if show_reject_reason(object)
|
||||
content_tag :li, link_to(t(quick[:translation] || :rejected_reason) + ' ' + truncate(object.not_checked_reason, :length => 10), '#', rel: "tooltip", 'data-original-title' => (wrap_string_with(object.not_checked_reason, :line_width => 24)), class: "reject_info #{quick[:class]}")
|
||||
end
|
||||
else
|
||||
content_tag :li, link_to(t(quick[:translation]), eval("#{quick[:link]}('#{object.id}')"), class: quick[:class])
|
||||
end
|
||||
end
|
||||
|
||||
def is_approvable(object)
|
||||
current_or_guest_user.admin? || (!object.is_rejected? && !object.is_checked?)
|
||||
end
|
||||
|
||||
def is_authorized(object)
|
||||
at_least_module_manager || object.category.cur_user_is_sub_manager_of("submit_#{@module_app.key}")
|
||||
end
|
||||
|
||||
def quick_edit_link(args)
|
||||
@quick_edit << args
|
||||
end
|
||||
|
||||
def objects(objects)
|
||||
@objects = objects
|
||||
end
|
||||
|
||||
def sortable
|
||||
@sortable = true
|
||||
end
|
||||
|
||||
def with_link?(field, object, value)
|
||||
if field[:link] && @approvable
|
||||
if object.class.instance_methods.include?(:is_checked?) && object.is_checked?
|
||||
link_to(value, eval("#{field[:link]}('#{object.id}')"))
|
||||
# link_to bulletin.title, panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''
|
||||
else
|
||||
value
|
||||
end
|
||||
elsif field[:link]
|
||||
link_to(value, eval("#{field[:link]}('#{object.id}')"))
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user