app/controllers/wiki.rb in Pimki-1.4.092 vs app/controllers/wiki.rb in Pimki-1.5.092

- old
+ new

@@ -3,11 +3,11 @@ RenderedTodo = Struct.new( :text, :context, :due_date ) class WikiController < ActionControllerServlet EXPORT_DIRECTORY = WikiService.storage_path unless const_defined?("EXPORT_DIRECTORY") - + def index if web_address redirect_show "HomePage" elsif !wiki.setup? redirect_path "/new_system/" @@ -74,16 +74,84 @@ end def search set_menu_pages @query = @params["query"] - rex = /#{@query}/i - @results = web.select { |page| rex.match(page.name) or rex.match(page.content) } - @bliki_results = web.bliki.values.select do |entry| - rex.match(entry.name) or rex.match(entry.content) + search_content = [nil, 'both', 'contents'].include? @params['fields'] + search_names = [nil, 'both', 'names'].include? @params['fields'] + + case @params['expression'] + when 'regex', nil + rex = Regexp.new @query, (Regexp::IGNORECASE unless @params['case']) + @results = if [nil, 'all', 'pages', nil].include? @params['where'] + web.select do |page| + (search_names and rex.match(page.name)) or (search_content and rex.match(page.content)) + end + else + [] + end + @bliki_results = if [nil, 'all', 'bliki'].include? @params['where'] + web.bliki.values.select do |entry| + (search_names and rex.match(entry.name)) or (search_content and rex.match(entry.content)) + end + else + [] + end + + when 'all' + words = @query.split(/\s/).reject { |w| w.empty? } + @results = if [nil, 'all', 'pages'].include? @params['where'] + web.select do |page| + words.all? do |word| + (search_names and page.name.index(word)) or (search_content and page.content.index(word)) + end + end + else + [] + end + @bliki_results = if [nil, 'all', 'bliki'].include? @params['where'] + web.bliki.values.select do |entry| + words.all? do |word| + (search_names and entry.name.index(word)) or (search_content and entry.content.index(word)) + end + end + else + [] + end + + when 'exact' + @results = if [nil, 'all', 'pages'].include? @params['where'] + web.select do |page| + (search_names and page.name.index(@query)) or (search_content and page.content.index(@query)) + end + else + [] + end + @bliki_results = if [nil, 'all', 'bliki'].include? @params['where'] + web.bliki.values.select do |entry| + (search_names and entry.name.index(@query)) or (search_content and entry.content.index(@query)) + end + else + [] + end end - @results.length == 1 ? redirect_show(@results.first.name) : render + + if !@params['category'].nil? and @params['category'] != 'noselect' + @selected_categories = parse_multi_select 'category' + @results.reject! { |page| (page.categories & @selected_categories).empty? } + @bliki_results.reject! { |page| (page.categories & @selected_categories).empty? } + end + + if !@params['author'].nil? and @params['author'] != 'noselect' + @selected_authors = parse_multi_select 'author' + @results.reject! { |page| (page.authors & @selected_authors).empty? } + @bliki_results.reject! { |page| (page.authors & @selected_authors).empty? } + end + + redirect_show(@results.first.name) if @results.length == 1 && @bliki_results.length == 0 + redirect_path("/#{web_address}/bliki_revision/#{@bliki_results.first.name}?rev=#{@bliki_results.first.revisions.size-1}") if @results.length == 0 && @bliki_results.length == 1 + render_action "search" end def authors @authors = web.select.authors end @@ -149,62 +217,79 @@ export_markup_to_zip_file(file_path) unless FileTest.exists?(file_path) send_export(file_name, file_path) end def export_pdf - file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}" + file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}" file_path = EXPORT_DIRECTORY + file_name export_web_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex") convert_tex_to_pdf(file_path + ".tex") send_export(file_name + ".pdf", file_path + ".pdf") end def export_tex - file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.tex" + file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}.tex" file_path = EXPORT_DIRECTORY + file_name export_web_to_tex(file_path) unless FileTest.exists?(file_path) send_export(file_name, file_path) end def edit_web #{{{ parse_category set_mm_options + @snapshot_interval = MadeleineService.snapshot_interval_hours end #}}} def update_web redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) set_mm_options wiki.update_web( - web.address, @params["address"], @params["name"], - @params["markup"].intern, + web.address, @params["address"], @params["name"], + @params["markup"].intern, @params["color"], @params["additional_style"], @params["safe_mode"] ? true : false, @params["password"].empty? ? nil : @params["password"], @params["published"] ? true : false, @params["brackets_only"] ? true : false, @params["count_pages"] ? true : false, @params['mind_map_size'], @params['symbols_map'], @params['links_map'], + @params['snapshots_interval'], @params['enable_dclick_edit'], @params['check_pass_on_edit'] == 'each_edit', @prog, @graph_type, @missing, @show_authors, @show_leaves, @selected_categories ) redirect_show("HomePage", @params["address"]) end - def remove_orphaned_pages - if wiki.authenticate(@params["system_password"]) - wiki.remove_orphaned_pages(web_address) - redirect_action "list/" + def administrate + @logger.info "Taking administrative action: #{@params['action']}" + if wiki.authenticate(@params['system_password']) + case @params['action'] + when 'Delete Orphan Pages' + wiki.remove_orphaned_pages(web_address) + + when 'Clear Render Cache' + clear_render_cache true + + when 'Force Data Snapshot' + MadeleineService.take_snapshot + + when 'Clean Storage' + MadeleineService.clean_old_snapshots + + end + @message = 'Operation succeeded' + redirect_action 'edit_web/' else - redirect_show "HomePage" + redirect_show 'HomePage' end end FAR_FUTURE = Date.new(4000,1,1).freeze TODO_RE = %r{<todo-tag context='(.*?)' due_date='(.*?)'><span class="todo"><strong>TODO(?:.*)?:</strong> (.*?)</span></todo-tag>} @@ -214,11 +299,12 @@ set_menu_pages @context = @params['context'] @sort_order = @params['sort_order'] - clear_render_cache # hack to make sure we don't have old-style rendered todos. + # the clear_render_cache hack to make sure we don't have old-style rendered + # todos is no longer needed - can go thru the edit web to explicitely clear the cache. @todo_items = analyse_rendered_todo_items @pages_in_category.by_name @bliki_todo_items = analyse_rendered_todo_items web.bliki.values @context_links = @todo_items.clone.update(@bliki_todo_items).map { |page, items| # 'items' contain the full 'todo' info @@ -279,25 +365,31 @@ # default is the muted 'darkred', to prevent to many bright red # items on one page: (See also chunks/todo.rb) (due_date <=> Date.today) > -1 ? "todoFuture" : "todo" end - def clear_render_cache do_redirect=false + def clear_render_cache dont_redirect=false web.refresh_revisions - redirect_show 'HomePage' if do_redirect + redirect_path "/#{web_address}/edit_web/" unless dont_redirect end def set_menu_pages #{{{ parse_category @all_pages = web.select { true } @menu_pages = case web.menu_type when 'all' then @all_pages.by_name when 'recent' then @all_pages.by_last_visited when 'viewed' then @all_pages.by_most_viewed when 'revised' then @all_pages.by_revision - when 'user' then @menu_content = web.menu_content.revisions.last.display_content; nil when 'category' then web.select { |page| page.in_category?(web.menu_category) } + when 'user' + @menu_content = if Page === web.menu_content + web.menu_content.revisions.last.display_content + else + web.menu_content + end + nil when 'linkers' web.select { |page| page.wiki_words.size > 0 }.sort_by { |page| page.name } end @@ -356,17 +448,24 @@ @graph_type = @req.query['graph_type'] || 'normal' @missing = @pages_in_category.wanted_pages if @req.query['missing'] @show_authors = @req.query['show_authors'] == 'on' @show_leaves = @req.query.empty? || @req.query['show_leaves'] == 'on' - # TODO: fix handling of multiple-select for whole application - @selected_categories = @req.body.split('&').map { |pair| - pair.split('=') }.select { |k,v| - k == 'selected_categs' }.map { |k,v| v } if @req.body - @selected_categories ||= [] + @selected_categories = parse_multi_select 'selected_categs' @selected_categories = [] if @selected_categories.include? 'all' end end #}}} + + def parse_multi_select field #{{{ + if @req.body + @req.body.split('&').map { |pair| + pair.split('=') }.select { |k,v| + k == field }.map { |k,v| v } + else + [] + end + end #}}} + def edit_menu #{{{ @menu_type = web.menu_type @menu_content = web.menu_content @list_limit = web.menu_limit \ No newline at end of file