diff --git a/app/controllers/admin/page_contents_controller.rb b/app/controllers/admin/page_contents_controller.rb index ea2fde2..f444fba 100644 --- a/app/controllers/admin/page_contents_controller.rb +++ b/app/controllers/admin/page_contents_controller.rb @@ -23,6 +23,10 @@ class Admin::PageContentsController < OrbitAdminController @page = Page.find(params[:page_id]) if can_edit_or_delete?(@page) @page_content = PageContext.new + @options = {} + @site_in_use_locales.each do |l| + @options[l.to_s] = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid]} + end else render_401 end diff --git a/app/controllers/admin/wiki_pages_controller.rb b/app/controllers/admin/wiki_pages_controller.rb new file mode 100644 index 0000000..cf4d6da --- /dev/null +++ b/app/controllers/admin/wiki_pages_controller.rb @@ -0,0 +1,64 @@ +class Admin::WikiPagesController < OrbitAdminController + before_action ->(module_app = @app_title) { set_variables module_app } + + def initialize + super + @app_title = "page_content" + end + + def index + @table_fields = [:title, :created_at, "page_content.parent_page", :last_modified] + @filter_fields = {} + @page = Page.find(params[:page_id]) rescue nil + if !@page.nil? + @wikis = @page.wiki_pages.order_by(sort) + @wikis = search_data(@wikis,[:name, :page_id]).page(params[:page]).per(10) + else + @wikis = WikiPage.all.order_by(sort) + @wikis = search_data(@wikis,[:title]).page(params[:page]).per(10) + end + render :partial => "index" if request.xhr? + end + + def create_on_the_go + wiki = WikiPage.create(wiki_page_params) + render :json => {"title" => wiki.title_translations, "id" => wiki.id.to_s}.to_json + end + + def new + @page = Page.find(params[:page_id]) rescue nil + @wiki = WikiPage.new + @options = {} + @site_in_use_locales.each do |l| + @options[l.to_s] = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid]} + end + end + + def edit + @page = Page.find(params[:page_id]) rescue nil + @wiki = WikiPage.find(params[:id]) + @options = {} + @site_in_use_locales.each do |l| + t = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid] if wp.id != @wiki.id} + t.delete(nil) + @options[l.to_s] = t + end + end + + def create + wiki = WikiPage.create(wiki_page_params) + redirect_to admin_wiki_pages_path(:page_id => wiki.page.id) + end + + def update + wiki = WikiPage.find(params[:id]) + wiki.update_attributes(wiki_page_params) + redirect_to admin_wiki_pages_path(:page_id => wiki.page.id) + end + + private + + def wiki_page_params + params.require(:wiki_page).permit! + end +end \ No newline at end of file diff --git a/app/controllers/page_contents_controller.rb b/app/controllers/page_contents_controller.rb index 20b64f7..06a9eb6 100644 --- a/app/controllers/page_contents_controller.rb +++ b/app/controllers/page_contents_controller.rb @@ -1,11 +1,21 @@ class PageContentsController < OrbitAdminController def index params = OrbitHelper.params - page = Page.where(:page_id => params[:page_id]).first - url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : "" + if params["wiki"].present? + page = WikiPage.where(:uid => params["wiki"]).first + name = page.title rescue "" + html = page.content rescue "" + url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/wiki_pages/#{page.id}/edit?page_id=#{page.page.id.to_s}" : "" + else + page = Page.where(:page_id => params[:page_id]).first + name = page.name rescue "" + html = page.page_contexts.last.content rescue "" + url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : "" + end + { - "html" => (page.page_contexts.last.content rescue ""), - "title" => (page.name rescue ""), + "html" => html, + "title" => name, "view_count" => (page.view_count rescue ""), "view-count-head" =>t('page_content.view_count'), "url_to_edit" => url_to_edit diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb new file mode 100644 index 0000000..2a34b0e --- /dev/null +++ b/app/models/wiki_page.rb @@ -0,0 +1,13 @@ +class WikiPage + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Impression + include Slug + + field :update_user_id + field :view_count, :type => Integer, :default => 0 + field :content, localize: true + field :title, localize: true + + belongs_to :page +end \ No newline at end of file diff --git a/app/views/admin/page_contents/_index.html.erb b/app/views/admin/page_contents/_index.html.erb index 3c3db4f..516139c 100644 --- a/app/views/admin/page_contents/_index.html.erb +++ b/app/views/admin/page_contents/_index.html.erb @@ -16,6 +16,7 @@
diff --git a/app/views/admin/page_contents/new.html.erb b/app/views/admin/page_contents/new.html.erb index d9ad743..1fecb02 100644 --- a/app/views/admin/page_contents/new.html.erb +++ b/app/views/admin/page_contents/new.html.erb @@ -15,7 +15,16 @@
+ <%= page.title %>
+
+
+
+ |
+ <%= format_value page.created_at rescue nil %> | +<%= page.page.page_id rescue "" %> | +<%= User.find(page.update_user_id).user_name rescue nil %> | +