Skip to content

Commit

Permalink
debug commit (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
docelic committed Aug 17, 2018
1 parent 30610b0 commit fca0a08
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 333 deletions.
136 changes: 0 additions & 136 deletions src/fluence/controllers/media_controller.cr

This file was deleted.

46 changes: 23 additions & 23 deletions src/fluence/controllers/pages_controller.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ class PagesController < ApplicationController
page = Fluence::Page.new(query)
# TODO: a real search
title = "Search Results - #{title()}"
redirect_to query.empty? ? "/pages/home" : page.real_url
redirect_to query.empty? ? "/pages/home" : page.url
end

# get /pages/*path
def show
acl_permit! :read
flash["danger"] = params.query["flash.danger"] if params.query["flash.danger"]?
pp params.url
page = Fluence::Page.new url: params.url["path"], read_title: true
# if (params.query["edit"]?) || !page.exists?
# show_edit(page)
# else
show_show(page)
# end
#pp params.url
page = Fluence::Pages[params.url["path"]]?
if (params.query["edit"]?) || !page
show_edit(page)
else
show_show(page)
end
end

private def show_show(page)
Expand All @@ -36,13 +36,13 @@ class PagesController < ApplicationController
Fluence::ACL.load!

if !page.exists?
flash["info"] = "The page #{page.url} does not exist yet."
flash["info"] = "The page #{page.name} does not exist yet."
flash["info"] += " You could create it by typing in and saving new content." if
Fluence::ACL.permitted?(current_user, request.path, Acl::Perm::Write)
end

groups_read = Fluence::ACL.groups_having_any_access_to page.real_url, Acl::Perm::Read, true
groups_write = Fluence::ACL.groups_having_any_access_to page.real_url, Acl::Perm::Write, true
groups_read = Fluence::ACL.groups_having_any_access_to page.url, Acl::Perm::Read, true
groups_write = Fluence::ACL.groups_having_any_access_to page.url, Acl::Perm::Write, true
title = "#{page.title} - #{title()}"
# For menu on the left
pages = Fluence::FileTree.build Fluence::Page.subdirectory
Expand All @@ -52,7 +52,7 @@ class PagesController < ApplicationController
# post /pages/*path
def update
acl_permit! :write
page = Fluence::Page.new url: params.url["path"], read_title: true
page = Fluence::Pages[params.url["path"]]
if params.body["rename"]?
update_rename(page)
elsif params.body["delete"]?
Expand All @@ -71,16 +71,16 @@ class PagesController < ApplicationController
# TODO: if input-page-name do not begin with /, relative rename to the current path
begin
new_page = page.rename current_user, params.body["input-page-name"], !!params.body["input-page-overwrite"]?
flash["success"] = "The page #{page.url} has been renamed to #{new_page.url}."
flash["success"] = "The page #{page.name} has been renamed to #{new_page.name}."
Fluence::PAGES.transaction! { |index| index.rename page, new_page }
Fluence::Page.remove_empty_directories page.path
redirect_to new_page.real_url
redirect_to new_page.url
rescue e : Fluence::Page::AlreadyExist
flash["danger"] = e.to_s
redirect_to page.real_url
redirect_to page.url
end
else
redirect_to page.real_url
redirect_to page.url
end
end

Expand All @@ -92,26 +92,26 @@ class PagesController < ApplicationController
pages.each do |p|
Fluence::PAGES.transaction! { |index| index.delete page }
page.delete current_user
flash["success"] += "The page #{page.url} has been deleted. "
flash["success"] += "The page #{page.name} has been deleted. "
Fluence::Page.remove_empty_directories page.path
end
redirect_to "/pages/home"
rescue err
# TODO: what if the page is not deleted but not indexed anymore ?
# Fluence::PAGES.transaction! { |index| index.add page }
flash["danger"] = "Error: cannot remove #{page.url}, #{err.message}"
redirect_to page.real_url
flash["danger"] = "Error: cannot remove #{page.name}, #{err.message}"
redirect_to page.url
end

private def update_edit(page)
is_new = page.is_new?
page.write current_user, params.body["body"]
page.read_title!
Fluence::PAGES.transaction! { |index| index.add! page }
flash["success"] = %Q(The page #{page.url} has been #{is_new ? "created" : "updated"}.)
redirect_to page.real_url
flash["success"] = %Q(The page #{page.name} has been #{is_new ? "created" : "updated"}.)
redirect_to page.url
rescue err
flash["danger"] = "Error: cannot update #{page.url}, #{err.message}"
redirect_to page.real_url
flash["danger"] = "Error: cannot update #{page.name}, #{err.message}"
redirect_to page.url
end
end
32 changes: 16 additions & 16 deletions src/fluence/lib/_init.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ module Fluence
Fluence::Page::Index.build("pages")
end

# The list of media with a lot of meta-data. Same behavior like
# `USERS` and `ACL`.
MEDIA = if File.exists? "meta/media"
Fluence::Page::Index.new("meta/media").load!
else
Fluence::Page::Index.build("media")
end
# # The list of media with a lot of meta-data. Same behavior like
# # `USERS` and `ACL`.
# MEDIA = if File.exists? "meta/media"
# Fluence::Page::Index.new("meta/media").load!
# else
# Fluence::Page::Index.build("media")
# end

# Install file watcher on data files.
# Exact use of the triggers is to be determined later.
# (It could be used to catch file modifications which happen
# outside of the wiki, and to automatically update the wiki
# index. This could be made to work live and report live stream
# of page and media changes to some admin page)
watch "data/**/*" do |e|
"Detected #{e.status} for file #{e.name}"
end
# # Install file watcher on data files.
# # Exact use of the triggers is to be determined later.
# # (It could be used to catch file modifications which happen
# # outside of the wiki, and to automatically update the wiki
# # index. This could be made to work live and report live stream
# # of page and media changes to some admin page)
# watch "data/**/*" do |e|
# "Detected #{e.status} for file #{e.name}"
# end
end

0 comments on commit fca0a08

Please sign in to comment.