added few modules

This commit is contained in:
Harry Bomrah 2016-02-19 17:13:10 +08:00
parent fa2736b6f6
commit da1271a111
1 changed files with 107 additions and 0 deletions

View File

@ -4,6 +4,12 @@ class UpgradeController < ApplicationController
case params[:module]
when "announcement"
data = get_announcements
when "archive"
data = get_archives
when "link"
data = get_links
when "page"
data = get_pages
else
data = {"success" => false, "msg" => "Module not found."}
end
@ -77,6 +83,107 @@ class UpgradeController < ApplicationController
return {"announcements" => bulletins, "categories" => categories, "tags" => tags, "success" => true}
end
def get_archives
ma = ModuleApp.find_by_key("archive")
categories = ma.categories.collect do |c|
{
"title" => c.title_translations,
"disable" => c.disable
}
end
tags = ma.tags.collect do |t|
{
"name" => t.name_translations,
"is_default" => t.is_default
}
end
archives = ArchiveFile.all.collect do |a|
files = a.archive_file_multiples.collect do |af|
file = request.protocol + request.host_with_port + af.file.url rescue nil
{
"file_title" => af.file_title_translations,
"file" => file
}
end
ts = a.tags.collect do |t|
{
"name" => t.name_translations
}
end
{
"id" => a.id.to_s,
"title" => a.title_translations,
"category" => a.category.title_translations,
"tags" => ts,
"files" => files
}
end
return {"archives" => archives, "categories" => categories, "tags" => tags, "success" => true}
end
def get_links
ma = ModuleApp.find_by_key("web_resource")
categories = ma.categories.collect do |c|
{
"title" => c.title_translations,
"disable" => c.disable
}
end
tags = ma.tags.collect do |t|
{
"name" => t.name_translations,
"is_default" => t.is_default
}
end
links = WebLink.all.collect do |b|
ts = b.tags.collect do |t|
{
"name" => t.name_translations
}
end
{
"id" => b.id.to_s,
"title" => b.title_translations,
"category" => b.category.title_translations,
"tags" => ts,
"context" => b.context_translations,
"url" => b.url_translations
}
end
return {"links" => links, "categories" => categories, "tags" => tags, "success" => true}
end
def get_pages
ma = ModuleApp.find_by_key("page_content")
pages = PageContext.all.collect do |p|
# context = {"en" => "", "zh_tw" => ""}
# context["en"] = (p.context_translations["en"].nil? ? "" : smart_convertor(p.context_translations["en"]))
# context["zh_tw"] = (p.context_translations["zh_tw"].nil? ? "" : smart_convertor(p.context_translations["zh_tw"]))
{
"id" => p.id.to_s,
"context" => p.context,
"page_id" => p.page_id
}
end
return {"pages" => pages, "success" => true}
end
def smart_convertor(text)
html_string = text
links = html_string.scan(/img.*?src="(.*?)"/i)