app/models/web.rb in Pimki-1.2.092 vs app/models/web.rb in Pimki-1.3.092

- old
+ new

@@ -5,10 +5,11 @@ require "zip/zip" class Web attr_accessor :pages, :name, :address, :password, :menu_type, :menu_content, :rendered_menu, :menu_limit, :menu_category attr_accessor :markup, :color, :safe_mode, :additional_style, :published, :brackets_only, :count_pages + attr_accessor :mind_map_size, :symbols_map, :links_map @@BLIKI_TEMPLATE = "Try a weekly worksheet:\n\n| / | *Morning* | *Afternoon* |\n" + "| *Mon* | - | - |\n| *Tue* | - | - |\n| *Wed* | - | - |\n" + "| *Thu* | - | - |\n| *Fri* | - | - |\n" @@ -85,87 +86,96 @@ # Default values def markup() @markup || :textile end def color() @color || "008B26" end def brackets_only() @brackets_only || false end def count_pages() @count_pages || false end - def menu_content() @menu_content || '' end - def menu_limit() @menu_limit || 20 end + def menu_content() @menu_content || '' end + def menu_limit() @menu_limit || 20 end def menu_type() (@menu_type.nil? || @menu_type.empty?) ? 'linkers' : @menu_type end + def mind_map_size() (@mind_map_size == '0,0' ? '6,5' : @mind_map_size) end + # create a Mind Map graph and return the PNG and HTML map files generated - def create_mind_map(prog, missing, show_authors) + def create_mind_map(prog, missing, show_authors, show_leaves, selected_categories) dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" - file.puts 'size="7,5";' - #file.puts 'ratio=fill;' + file.puts "size=\"#{mind_map_size}\";" + file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' - # Page Special nodes properties: - file.puts "HomePage [color=\"##{color}\",style=bold];" - # Links and node properties: - nodes = pages.values + nodes = filter_categories(pages.values, selected_categories) auths = authors # avoid repeated selects - unless show_authors == 'on' + unless show_authors nodes.delete_if { |entry| auths.include? entry.name } end + unless show_leaves + nodes.delete_if { |page| + (page.wiki_words - [missing].flatten).size == 0 + } + end + + # Page Special nodes properties: + file.puts "HomePage [color=\"##{color}\",style=bold];" if nodes.map{ |p| p.name }.include? "HomePage" + nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.references.each do |referer| - unless page.name == referer.name - unless show_authors != 'on' and auths.include? referer.name + unless page.name == referer.name or not nodes.include? referer + unless !show_authors and auths.include? referer.name file.puts "#{referer.name} -> #{page.name};" end end end end # find missing pages: if missing - missing.each do |wanted| - file.puts "#{wanted} [URL=\"/#{@address}/show/#{wanted}\", fontsize=10,style=filled,color=grey];" - end - pages.values.each do |page| + shown_missing = [] + nodes.each do |page| missing.each do |wanted| if page.content =~ /#{wanted}/ file.puts "#{page.name} -> #{wanted};" + shown_missing << wanted end end end + shown_missing.each do |wanted| + file.puts "#{wanted} [URL=\"/#{@address}/show/#{wanted}\", fontsize=10,style=filled,color=grey];" + end end file.puts "}" end - system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") - system("#{prog} -Tpng #{dotFile} -o #{pngFile}") + call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end - def create_author_graph(prog) + def create_author_graph(prog, selected_categories) dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" - file.puts 'size="7,5";' + file.puts "size=\"#{mind_map_size}\";" if mind_map_size #file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' @@ -173,52 +183,51 @@ auths = authors # avoid repeated selects auths.each do |auth| file.puts "#{auth} [style=filled,color=grey,URL=\"../show/#{auth}\"];" end - nodes = pages.values - nodes.delete_if { |entry| auths.include? entry.name } + nodes = pages.values.reject { |entry| auths.include? entry.name } + nodes = filter_categories(nodes, selected_categories) nodes.each do |page| file.puts "#{page.name} [URL=\"../show/#{page.name}\"];" page.authors.each do |auth| file.puts "#{auth} -> #{page.name};" end end file.puts "}" end - system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") - system("#{prog} -Tpng #{dotFile} -o #{pngFile}") + call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end - def create_category_graph(prog, show_authors) #{{{ + def create_category_graph(prog, show_authors, selected_categories) #{{{ dotFile = File.expand_path("#{WikiService.storage_path}/graph.dot") mapFile = File.expand_path("#{WikiService.storage_path}/graph.map") pngFile = File.expand_path("#{WikiService.storage_path}/map.png") File.open(dotFile, "w") do |file| # Graph properties: file.puts "digraph G {" - file.puts 'size="7,5";' + file.puts "size=\"#{mind_map_size}\";" if mind_map_size #file.puts 'ratio=fill;' file.puts 'concentrate=true;' file.puts 'node [fontsize=10,fontname="Tahoma"];' file.puts 'edge [len=1.5];' # Page Special nodes properties: - file.puts "HomePage [color=\"##{color}\",style=bold];" - categories.each do |category| - file.puts "#{category} [fontsize=20,style=filled,color=grey,comment=\"#{category}\"];" + categs = selected_categories.empty? ? categories : selected_categories + categs.each do |category| + file.puts "#{category} [fontsize=20,style=filled,color=grey,comment=\"#{category}\",URL=\"../list/?category=#{category}\"];" end # Links and node properties: - nodes = pages.values + nodes = filter_categories(pages.values, selected_categories) auths = authors # avoid repeated selects - unless show_authors == 'on' + unless show_authors nodes.delete_if { |entry| auths.include? entry.name } end nodes.each do |page| @@ -229,14 +238,29 @@ end file.puts "}" end - system("#{prog} -Tcmap #{dotFile} -o #{mapFile}") - system("#{prog} -Tpng #{dotFile} -o #{pngFile}") + call_graphviz(prog, dotFile, mapFile, pngFile) [pngFile, mapFile] end #}}} + + def filter_categories(pages, selected_categories) #{{{ + nodes = pages + unless selected_categories.empty? + nodes = pages.reject { |page| (page.categories & selected_categories).empty? } + if selected_categories.include? 'none' + nodes += pages.select { |page| page.categories.empty? } + end + end + nodes + end #}}} + + def call_graphviz(prog, dotFile, mapFile, pngFile) + system("#{prog} -Tcmap \"#{dotFile}\" -o \"#{mapFile}\"") + system("#{prog} -Tpng \"#{dotFile}\" -o \"#{pngFile}\"") + end ## Bliki methods def add_bliki_entry(page) bliki[page.name] = page \ No newline at end of file