app/controllers/wiki.rb in Pimki-1.2.092 vs app/controllers/wiki.rb in Pimki-1.3.092

- old
+ new

@@ -59,21 +59,28 @@ def parse_category @categories = web.categories @category = @params["category"] @pages_in_category = web.select { |page| page.in_category?(@category) } + @pages_without_category = web.select { |page| page.categories.length == 0 } + if @category == 'none' + @pages_in_category = @pages_without_category + end @set_name = ( @categories.include?(@category) ? "category '#{@category}'" : "the web" ) @category_links = @categories.map do |c| - (@category == c ? "<span class=\"selected\">#{c}</span>" : "<a href=\"?category=#{c}\">#{c}</a>") + (@category == c ? "<span class=\"selected\">[#{c}]</span>" : "<a href=\"?category=#{c}\">#{c}</a>") end end def search set_menu_pages - @query = @params["query"] + @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) + end @results.length == 1 ? redirect_show(@results.first.name) : render end def authors @authors = web.select.authors @@ -162,11 +169,14 @@ @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["count_pages"] ? true : false, + @params['mind_map_size'], + @params['symbols_map'], + @params['links_map'] ) redirect_show("HomePage", @params["address"]) end @@ -238,23 +248,36 @@ end @color = web.color @authors = web.authors end #}}} +require 'pp' def mind #{{{ parse_category set_menu_pages @prog = @req.query['draw_type'] || 'neato' @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_authors = !@req.query.empty? && @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 = [] if @selected_categories.include? 'all' + @pngFile = @mapFile = nil case @graph_type - when 'normal' then @pngFile, @mapFile = web.create_mind_map(@prog, missing, show_authors) - when 'author' then @pngFile, @mapFile = web.create_author_graph(@prog) - when 'category' then @pngFile, @mapFile = web.create_category_graph(@prog, show_authors) + when 'normal' then @pngFile, @mapFile = web.create_mind_map(@prog, missing, + show_authors, show_leaves, @selected_categories) + when 'author' then @pngFile, @mapFile = web.create_author_graph(@prog, + @selected_categories) + when 'category' then @pngFile, @mapFile = web.create_category_graph(@prog, + show_authors, @selected_categories) end end #}}} def edit_menu #{{{ @menu_type = web.menu_type @@ -262,10 +285,12 @@ @list_limit = web.menu_limit @list_limit += 1 if @list_limit >= -1 end #}}} def save_menu #{{{ + redirect_show("HomePage") unless wiki.authenticate(@params["system_password"]) + unless @req.query['action'] == 'Cancel Update' type = @req.query['type'] content = @req.query['content'] category = @req.query['category'] @@ -314,11 +339,15 @@ rescue => e $stderr << e.backtrace.join("\n") redirect_action "edit/#{CGI.escape(page_name)}?msg=#{CGI.escape(e.message)}" end else - redirect_action "new/#{CGI.escape(page_name)}" + if page_name + redirect_action "new/#{CGI.escape(page_name)}" + else + redirect_show "HomePage" + end end end def published if web.published then @page = wiki.read_page(web_address, page_name || "HomePage") else redirect_show("HomePage") end @@ -398,11 +427,11 @@ # Bliki ---------------------------------------------------------------------- def bliki_delete wiki.delete_bliki_entry(web_address, page_name) - redirect_bliki("") + redirect_bliki end def bliki_edit @page = wiki.read_bliki_entry(web_address, page_name) @@ -416,11 +445,11 @@ end def cancel_bliki_edit @page = wiki.read_bliki_entry(web_address, page_name) @page.unlock if @page - redirect_bliki(@page? @page.name : "") + redirect_bliki end def bliki_save pname = page_name || @params["pagename"] if web.bliki[pname] @@ -429,11 +458,11 @@ else page = wiki.write_bliki_entry(web_address, pname, @params["content"], Time.now, @params["author"]) end write_cookie("author", @params["author"]) - redirect_bliki('') + redirect_bliki end def bliki_revision @page = wiki.read_bliki_entry(web_address, page_name || @params['pagename']) @revision = @page.revisions[@params["rev"].to_i] || @page.revisions.last @@ -469,11 +498,11 @@ def redirect_show(page = @page.name, web = web_address) redirect_path "/#{web}/show/#{CGI.escape(page)}" end - def redirect_bliki(page = @page.name, web = web_address) - redirect_path "/#{web}/bliki/#{page}" + def redirect_bliki + redirect_path "/#{web_address}/bliki/" end def redirect_action(action, web = web_address) redirect_path "/#{web}/#{action}" end \ No newline at end of file