Merge branch 'master' into 'master'

Master

let user can choose whether to show the description and fix the problem of category and tag not showing on sitemap

See merge request !2
This commit is contained in:
wmcheng 2019-09-30 23:23:07 +08:00
commit 7df10fc320
19 changed files with 314 additions and 20 deletions

View File

@ -143,6 +143,9 @@
/* Gallery Body */
div.rgbody{
margin-bottom:50px;
}
.rgbody .gallery-info {
padding: 0 5px;
}

View File

@ -4,6 +4,24 @@ class Admin::GalleriesController < OrbitAdminController
before_filter :setup_vars
before_action :authenticate_user, :except => "imgs"
before_action :log_user_action
find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')}
if find_tag.length==0
module_app_id = ModuleApp.where(:key=>"gallery").first[:_id]
tags = ModuleApp.where(:key=>"gallery").first.tags
tag0 = Tag.new(is_default: false,module_app_ids: [module_app_id])
tag1 = Tag.new(is_default: false,module_app_ids: [module_app_id])
nowlocale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
tag0.name = I18n.t('gallery.show_desc')
tag1.name = I18n.t('gallery.not_show_desc')
end
I18n.locale = nowlocale
tag0.save
tag1.save
tags << tag0
tags << tag1
end
def save_crop
begin
images = AlbumImage.all.select{|value| params[:id].include? value.id.to_s}

View File

@ -1,16 +1,35 @@
class GalleriesController < ApplicationController
find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')}
if find_tag.length==0
module_app_id = ModuleApp.where(:key=>"gallery").first[:_id]
tags = ModuleApp.where(:key=>"gallery").first.tags
tag0 = Tag.new(is_default: false,module_app_ids: [module_app_id])
tag1 = Tag.new(is_default: false,module_app_ids: [module_app_id])
nowlocale = I18n.locale
I18n.available_locales.each do |locale|
I18n.locale = locale
tag0.name = I18n.t('gallery.show_desc')
tag1.name = I18n.t('gallery.not_show_desc')
end
I18n.locale = nowlocale
tag0.save
tag1.save
tags << tag0
tags << tag1
end
def index
albums = Album.filter_by_categories.filter_by_tags.asc(:order)
galleries = albums.collect do |a|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{
"album-name" => a.name,
"album-description" => a.description,
"alt_title" => alt_text,
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
}
end
doc = Nokogiri::HTML(a.description.to_s)
alt_text = doc.text.empty? ? 'gallery image' : doc.text
{
"album-name" => a.name,
"album-description" => a.description,
"alt_title" => alt_text,
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
"thumb-src" => a.cover_path || "/assets/gallery/default.jpg"
}
end
{
"albums" => galleries,
"extras" => {"widget-title"=>"Gallery"},
@ -22,18 +41,20 @@ class GalleriesController < ApplicationController
def show
params = OrbitHelper.params
album = Album.find_by_param(params[:uid])
flag = show_desc?
images = album.album_images.asc(:order).collect do |a|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{
"image-description" => a.description,
"alt_title" => alt_text,
"link_to_show" => "/xhr/galleries/theater/" + a.id.to_s,
"thumb-src" => a.file.thumb.url
"link_to_show" => "/xhr/galleries/theater/" + a.id.to_s,
"thumb-src" => a.file.thumb.url
}
end
{
"images" => images,
"data" => {"album-title"=>album.name}
"data" => {"album-title"=>album.name,
"album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")}
}
end
@ -112,6 +133,21 @@ class GalleriesController < ApplicationController
}
render :json => {"data" => data}.to_json
end
end
private
def show_desc?
tags = OrbitHelper.page_tags if tags.blank?
tags = [tags].flatten.uniq
flag = true
tag_temp = Tag.all.select{|value| tags.include? value.id.to_s}
tag_temp_length = 0
tag_temp.each do |value|
if value.name==I18n.t('gallery.show_desc')
flag = true
elsif value.name==I18n.t('gallery.not_show_desc')
flag = false
end
end
flag
end
end

View File

@ -24,5 +24,29 @@ class Album
def self.find_by_param(input)
self.find_by(uid: input)
end
def self.filter_by_tags(tags=[])
tags = OrbitHelper.page_tags if tags.blank?
tags = [tags].flatten.uniq
if !(tags.include?("all"))
tag_temp = Tag.all.select{|value| tags.include? value.id.to_s}
tag_temp_length = 0
tag_temp.each do |value|
if value.name==I18n.t('gallery.show_desc') || value.name==I18n.t('gallery.not_show_desc')
tag_temp_length+=1
end
end
if tag_temp_length!=0
if (tags.length - tag_temp_length) == 0
tags = ['all']
end
end
end
if tags.blank? || (tags.include?("all") rescue false)
self.all
else
tags
taggings = Tagging.where(:tag_id.in=>tags).map{|item| item.taggable_id}
self.where(:id.in=>taggings)
end
end
end

View File

@ -16,7 +16,7 @@
<% if can_edit_or_delete?(album) %>
<li><%= link_to (content_tag(:i,"",:class=>"icon-trash danger")), admin_gallery_path(album.id), "data-confirm" => "Are you sure?", :method=>:delete %></li>
<% end %>
<li class="albumcateg"><%= Category.find(album.category_id).title %></li>
<li class="albumcateg"><%= (Category.find(album.category_id).title rescue album.category_id) %></li>
</ul>
<ul class="albumtag">
<% album.tags.each do |tag| %>

View File

@ -1,6 +1,8 @@
en:
gallery:
show_desc: Show the album description
not_show_desc: Don't show the album description
show_original_image: Show the original picture
width: Width
height: Height

View File

@ -1,6 +1,8 @@
zh_tw:
gallery:
show_desc: 顯示相簿描述
not_show_desc: 不顯示相簿描述
show_original_image: 顯示原始圖片
width:
height:

View File

@ -2,7 +2,20 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "gallery/version"
app_path = File.expand_path(__dir__)
template_path = ENV['PWD'] + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
puts 'copying module'
all_template.each do |folder|
if folder.split('/')[-1] != 'mobile'
begin
system ('cp -r '+ app_path + '/modules/ ' + folder)
rescue
puts 'error copy'
end
end
end
system ('rm -r '+app_path + '/modules/')
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "gallery"

View File

@ -1,4 +1,4 @@
require "gallery/engine"
module Gallery
end

View File

@ -8,8 +8,9 @@ module Gallery
# widget_settings []
widget_settings [{"data_count"=>10}]
models_to_cache [:album,:album_image]
categorizable
authorizable
taggable "Album"
categorizable
authorizable
frontend_enabled
data_count 1..30
side_bar do

View File

@ -0,0 +1,25 @@
<div class="widget-gallery widget1 no-print">
<h3 class="widget-title">
<span>{{widget-title}}</span>
</h3>
<div class="cycle-slideshow widget-content"
data-level="0"
data-list="images"
data-cycle-slides="> a"
data-cycle-fx="carousel"
data-cycle-timeout="3000"
data-cycle-carousel-visible="3"
data-cycle-pause-on-hover="true"
data-cycle-log="false"
data-cycle-carousel-fluid="true">
<a class="widget-pic" href="{{link_to_show}}">
<img
srcset="
{{thumb-large-src}} 1024w,
{{thumb-src}} 768w"
src="{{thumb-src}}"
alt="{{alt_title}}"
>
</a>
</div>
</div>

View File

@ -0,0 +1,16 @@
<div class="widget-gallery widget2 no-print">
<h3 class="widget-title">
<span>{{widget-title}}</span>
</h3>
<div class="row widget-content" data-level="0" data-list="images">
<a class="widget-pic col-xs-4" href="{{link_to_show}}">
<img
srcset="
{{thumb-large-src}} 1024w,
{{thumb-src}} 768w"
src="{{thumb-src}}"
alt="{{alt_title}}"
>
</a>
</div>
</div>

View File

@ -0,0 +1,21 @@
<div class="index-gallery index1">
<h1 class="index-title">
<span>{{page-title}}</span>
</h1>
<div class="row" data-level="0" data-list="albums">
<div class="index-content col-xs-4 col-sm-3">
<div class="index-content-inner">
<div class="index-pic">
<img class="img-thumbnail" src="{{thumb-src}}" alt="{{alt_title}}">
</div>
<section class="index-part">
<h4 class="index-content-title">
<a href="{{link_to_show}}">{{album-name}}</a>
</h4>
<div class="index-img-description">{{album-description}}</div>
</section>
</div>
</div>
</div>
</div>
{{pagination_goes_here}}

View File

@ -0,0 +1,21 @@
<div class="index-gallery index2">
<h1 class="index-title">
<span>{{page-title}}</span>
</h1>
<div class="row" data-level="0" data-list="albums">
<div class="index-content">
<div class="index-content-inner clearfix row">
<div class="index-pic col-xs-5 col-sm-2">
<img class="index-img" src="{{thumb-src}}" alt="{{alt_title}}">
</div>
<section class="index-part col-xs-7 col-sm-10">
<h4 class="index-content-title">
<a href="{{link_to_show}}">{{album-name}}</a>
</h4>
<div class="index-img-description">{{album-description}}</div>
</section>
</div>
</div>
</div>
</div>
{{pagination_goes_here}}

View File

@ -0,0 +1,20 @@
<div class="index-gallery index1">
<h1 class="index-title">
<span>{{page-title}}</span>
</h1>
<div class="row" data-level="0" data-list="albums">
<div class="index-content col-xs-4 col-sm-3">
<div class="index-content-inner">
<div class="index-pic">
<img class="img-thumbnail" src="{{thumb-src}}" alt="{{alt_title}}">
</div>
<section class="index-part">
<h4 class="index-content-title">
<a href="{{link_to_show}}">{{album-name}}</a>
</h4>
</section>
</div>
</div>
</div>
</div>
{{pagination_goes_here}}

View File

@ -0,0 +1,20 @@
<div class="index-gallery index2">
<h1 class="index-title">
<span>{{page-title}}</span>
</h1>
<div class="row" data-level="0" data-list="albums">
<div class="index-content">
<div class="index-content-inner clearfix row">
<div class="index-pic col-xs-5 col-sm-2">
<img class="index-img" src="{{thumb-src}}" alt="{{alt_title}}">
</div>
<section class="index-part col-xs-7 col-sm-10">
<h4 class="index-content-title">
<a href="{{link_to_show}}">{{album-name}}</a>
</h4>
</section>
</div>
</div>
</div>
</div>
{{pagination_goes_here}}

54
modules/gallery/info.json Normal file
View File

@ -0,0 +1,54 @@
{
"frontend": [
{
"filename" : "gallery_index1",
"name" : {
"zh_tw" : "1. 縮圖 ( 相本圖片, 相本說明, 分頁導覽 )",
"en" : "1. Thumbnail ( gallery thumbnail, gallery description, page navigation )"
},
"thumbnail" : "thumb.png"
},
{
"filename" : "gallery_index2",
"name" : {
"zh_tw" : "2. 條列 ( 相本圖片, 相本說明, 分頁導覽 )",
"en" : "2. Thumbnail ( gallery thumbnail, gallery description, page navigation )"
},
"thumbnail" : "thumb.png"
},
{
"filename" : "gallery_index3",
"name" : {
"zh_tw" : "3. 縮圖 ( 相本圖片, 分頁導覽 )",
"en" : "3. Thumbnail ( gallery thumbnail, page navigation )"
},
"thumbnail" : "thumb.png"
},
{
"filename" : "gallery_index4",
"name" : {
"zh_tw" : "4. 條列 ( 相本圖片, 分頁導覽 )",
"en" : "4. Thumbnail ( gallery thumbnail, page navigation )"
},
"thumbnail" : "thumb.png"
}
],
"widgets" : [
{
"filename" : "gallery_widget1",
"name" : {
"zh_tw" : "1. 跑馬燈 ( 模組標題, 圖片 )",
"en" : "1. Carousel Effect (widget-title, image)"
},
"thumbnail" : "thumb.png"
},
{
"filename" : "gallery_widget2",
"name" : {
"zh_tw" : "2. 相本排版",
"en" : "2. Thumbnail"
},
"thumbnail" : "thumb.png"
}
]
}

View File

@ -0,0 +1,18 @@
<div class="show-gallery">
<h1 class="show-title">
<span>{{album-title}}</span>
</h1>
{{album-description}}
<div data-level="0" data-list="images">
<div class="show-content col-xs-6 col-sm-2">
<div class="show-content-inner">
<div class="show-pic">
<a href="{{link_to_show}}">
<img class="img" src="{{thumb-src}}" alt="{{alt_title}}">
</a>
<p class="show-description">{{image-description}}</p>
</div>
</div>
</div>
</div>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB