source: trunk/lib/Node.cc @ 285

Last change on this file since 285 was 285, checked in by Peter Johansson, 14 years ago

moving first page generation to separate file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1// $Id: Node.cc 285 2007-05-06 19:03:28Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Peter Johansson
6
7  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "Node.h"
26#include "html_utility.h"
27#include "SVNlog.h"
28#include "SVNproperty.h"
29#include "utility.h"
30
31#include <cassert>
32#include <ctime>
33#include <fstream>
34#include <iostream>
35#include <sstream>
36
37namespace theplu{
38namespace svndigest{
39
40  std::string Node::project_=std::string();
41
42  Node::Node(const u_int level, const std::string& path, 
43             const std::string& local_path)
44    : level_(level), path_(path), stats_(path), 
45      svninfo_(path)
46  { 
47    SVNproperty property(path);
48    binary_=property.binary();
49    svndigest_ignore_=property.svndigest_ignore();
50    if (Node::project_==std::string()) // no root directory in local path
51      Node::project_ = file_name(path);
52    else if (local_path.empty())
53      local_path_ = file_name(path);
54    else
55      local_path_ = local_path + "/" + file_name(path);
56  }
57
58
59  bool Node::dir(void) const
60  {
61    return false;
62  }
63
64
65  void Node::path_anchor(std::ostream& os) const
66  {
67
68    os << "<h2 class=\"path\">\n";
69    std::vector<std::string> words;
70    words.reserve(level_+1);
71    std::string word;
72    words.push_back(Node::project_);
73    std::stringstream ss(local_path());
74    while(getline(ss,word,'/'))
75      if (!word.empty()) // ignore double slash in path
76        words.push_back(word);
77    if (words.size()==1)
78      os << anchor("index.html", Node::project_,0, "View " + Node::project_);
79    else {
80      for (size_t i=0; i<words.size()-1; ++i){
81        os << anchor("index.html", words[i], level_-i, "View " + words[i]);
82        os << "<span class=\"sep\">/</span>\n";
83      }
84      os << anchor(href(), words.back(), level_+2-words.size(), 
85             "View " + words.back()); 
86    }
87    os << "\n</h2>\n";
88  }
89
90
91  void Node::html_tablerow(std::ostream& os, 
92                           const std::string& css_class,
93                           const std::string& user) const
94  {
95    os << "<tr class=\"" << css_class << "\">\n"
96       << "<td class=\"" << node_type() << "\">";
97    if (svndigest_ignore())
98      os << name() << " (<i>svndigest:ignore</i>)";
99    else if (binary())
100      os << name() << " (<i>binary</i>)";
101    // there is no output for nodes when user has zero contribution
102    else if (user!="all" && !stats_.lines(user))
103      os << name();
104    else
105      os << anchor(href(), name()); 
106    os << "</td>\n"; 
107    if (user=="all") {
108      os << "<td>" << stats_.lines() << "</td>\n"
109         << "<td>" << stats_.code() << "</td>\n"
110         << "<td>" << stats_.comments() << "</td>\n"
111         << "<td>" << stats_.empty() << "</td>\n";
112    }
113    else {
114      os << "<td>" << stats_.lines(user) << "</td>\n"
115         << "<td>" << stats_.code(user) << "</td>\n"
116         << "<td>" << stats_.comments(user) << "</td>\n"
117         << "<td>" << stats_.empty(user) << "</td>\n";
118    }
119    os << "<td>" << trac_revision(stats_.last_changed_rev()) << "</td>\n"
120       << "<td>" << author() << "</td>\n"
121       << "</tr>\n";
122  }
123
124
125  void Node::print(const bool verbose) const
126  {
127    if (ignore())
128      return;
129    if (verbose)
130      std::cout << "Printing output for " << path_ << std::endl;
131    SVNlog log(path_);
132    print_core("all", "total", log);
133    print_core("all", "code", log);
134    print_core("all", "comments", log);
135    print_core("all", "empty", log);
136
137    for (std::set<std::string>::const_iterator i = stats_.authors().begin();
138         i!=stats_.authors().end(); ++i) {
139      print_core(*i, "total", log);
140      print_core(*i, "code", log);
141      print_core(*i, "comments", log);
142      print_core(*i, "empty", log);
143    }
144   
145    print_core(verbose);
146  }
147
148
149  void Node::print_author_summary(std::ostream& os, std::string line_type,
150                                  const SVNlog& log) const
151  { 
152    os << "<h4>Author Summary</h4>";
153    os << "<table class=\"listings\">\n";
154    os << "<thead>";
155    os << "<tr>\n";
156    os << "<th>Author</th>\n";
157    os << "<th>Lines</th>\n";
158    os << "<th>Code</th>\n";
159    os << "<th>Comments</th>\n";
160    os << "<th>Other</th>\n";
161    os << "<th>Revision</th>\n";
162    os << "<th>Date</th>\n";
163    os << "</tr>\n</thead>\n";
164    os << "<tbody>";
165
166    std::string color("light");
167    if (!dir()) {
168      os << "<tr class=\"" << color << "\">\n";
169      os << "<td class=\"directory\" colspan=\"5\">";
170      os << anchor("index.html", "../");
171      os << "</td>\n</tr>\n";
172    }
173
174    // print authors
175    const std::string timefmt("%e/%m/%y %H:%M:%S");
176    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
177         i!=stats_.authors().end(); ++i){
178      if (color=="dark")
179        color="light";
180      else
181        color="dark";
182      os << "<tr class=\"" << color << "\"><td>"; 
183      if (dir())
184        if (local_path().empty())
185          os << anchor(*i+"/"+line_type+"/index.html"
186                       ,*i, level_+2, "View statistics for "+*i); 
187        else
188          os << anchor(*i+"/"+line_type+"/"+local_path()+"/index.html"
189                       ,*i, level_+2, "View statistics for "+*i); 
190      else
191        os << anchor(*i+"/"+line_type+"/"+local_path()+".html"
192                     ,*i, level_+2, "View statistics for "+*i); 
193      os << "</td><td>" << stats_.lines(*i)
194         << "</td><td>" << stats_.code(*i)
195         << "</td><td>" << stats_.comments(*i)
196         << "</td><td>" << stats_.empty(*i);
197      if (log.exist(*i)) {
198        Commitment lc(log.latest_commit(*i));
199        os << "</td>" << "<td>" << trac_revision(lc.revision()) 
200           << "</td>" << "<td>" << lc.date()(timefmt);
201      }
202      else {
203        os << "</td>" << "<td>N/A"
204           << "</td>" << "<td>N/A";
205      }
206      os << "</td></tr>\n";
207    }
208
209    os << "<tr class=\"" << color << "\">\n";
210    os << "<td>"; 
211    if (dir())
212      os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
213                   ,"Total", level_+2, "View statistics for all"); 
214    else
215      os << anchor("all/"+line_type+"/"+local_path()+".html"
216                   ,"Total", level_+2, "View statistics for all"); 
217    os << "</td>\n";
218    os << "<td>" << stats_.lines() << "</td>\n";
219    os << "<td>" << stats_.code() << "</td>\n";
220    os << "<td>" << stats_.comments() << "</td>\n";
221    os << "<td>" << stats_.empty() << "</td>\n";
222    Commitment lc(log.latest_commit());
223    os << "<td>" << trac_revision(lc.revision()) << "</td>\n";
224    os << "<td>" << lc.date()(timefmt)<< "</td>\n";
225    os << "</tr>\n";
226    os << "</table>\n";
227
228  }
229
230}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.