1 | // $Id: first_page.cc 286 2007-05-07 16:07:23Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006, 2007 Peter Johansson |
---|
5 | |
---|
6 | This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest |
---|
7 | |
---|
8 | svndigest is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svndigest is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "first_page.h" |
---|
25 | |
---|
26 | #include "html_utility.h" |
---|
27 | |
---|
28 | #include "Commitment.h" |
---|
29 | #include "Configuration.h" |
---|
30 | #include "Date.h" |
---|
31 | #include "HtmlStream.h" |
---|
32 | #include "Stats.h" |
---|
33 | #include "SVNlog.h" |
---|
34 | #include "Trac.h" |
---|
35 | #include "utility.h" |
---|
36 | #include <config.h> // this header file is created by configure |
---|
37 | |
---|
38 | #include <algorithm> |
---|
39 | #include <cassert> |
---|
40 | #include <fstream> |
---|
41 | #include <iostream> |
---|
42 | #include <sstream> |
---|
43 | #include <stdexcept> |
---|
44 | #include <string> |
---|
45 | #include <sys/param.h> |
---|
46 | #include <unistd.h> |
---|
47 | #include <vector> |
---|
48 | |
---|
49 | namespace theplu{ |
---|
50 | namespace svndigest{ |
---|
51 | |
---|
52 | void print_main_page(const std::string& dir, const SVNlog& log, |
---|
53 | const Stats& stats) |
---|
54 | { |
---|
55 | std::string filename="index.html"; |
---|
56 | std::ofstream os(filename.c_str()); |
---|
57 | print_header(os, dir, 0, "all", "main", "index.html"); |
---|
58 | |
---|
59 | using namespace std; |
---|
60 | set<string> authors; |
---|
61 | authors.insert(log.author().begin(), log.author().end()); |
---|
62 | // erase invalid authors |
---|
63 | authors.erase(""); |
---|
64 | authors.erase("no author"); |
---|
65 | |
---|
66 | vector<Commitment> latest_commit; |
---|
67 | latest_commit.reserve(authors.size()); |
---|
68 | for (set<string>::const_iterator i(authors.begin()); i!=authors.end(); ++i) |
---|
69 | latest_commit.push_back(log.latest_commit(*i)); |
---|
70 | |
---|
71 | print_general_information(os, log, authors.size()); |
---|
72 | sort(latest_commit.begin(), latest_commit.end(), GreaterRevision()); |
---|
73 | print_authors(os, latest_commit, stats); |
---|
74 | print_recent_logs(os, log); |
---|
75 | os << "<hr width=100% />"; |
---|
76 | print_footer(os); |
---|
77 | os.close(); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | void print_general_information(std::ostream& os, const SVNlog& log, |
---|
82 | size_t nof_authors) |
---|
83 | { |
---|
84 | Date begin(log.date()[0]); |
---|
85 | if (log.date().size()>1) |
---|
86 | begin = std::min(begin, Date(log.date()[1])); |
---|
87 | Date end(log.date().back()); |
---|
88 | Date now; |
---|
89 | std::string timefmt("%a, %e %b %Y"); |
---|
90 | |
---|
91 | os << "<div class=\"main\">" |
---|
92 | << "<table class=\"main\"><thead><tr><th colspan=\"2\">" |
---|
93 | << "General Information" |
---|
94 | << "</th></tr></thead>\n" |
---|
95 | << "<tr><td>First Revision:</td><td>" |
---|
96 | << begin(timefmt) << "</td></tr>\n" |
---|
97 | << "<tr><td>Latest Revision:</td><td>" |
---|
98 | << end(timefmt) << "</td></tr>\n" |
---|
99 | << "<tr><td>Report Generated:</td><td>" |
---|
100 | << now(timefmt) << "</td></tr>\n" |
---|
101 | << "<tr><td>Repository Age:</td><td>"; |
---|
102 | os << now.difftime(begin); |
---|
103 | os << "</td></tr>\n" |
---|
104 | << "<tr><td>Number of Authors:</td><td>" << nof_authors |
---|
105 | << "</td></tr>\n" |
---|
106 | << "<tr><td>Revisions:</td><td>" << log.revision().size() |
---|
107 | << "</td></tr>\n" |
---|
108 | << "</table></div>\n"; |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | void print_authors(std::ostream& os, |
---|
113 | const std::vector<Commitment>& lc, |
---|
114 | const Stats& stats) |
---|
115 | { |
---|
116 | os << "<div class=\"main\">" |
---|
117 | << "<table class=\"main\"><thead><tr><th colspan=\"2\">" |
---|
118 | << "Authors" |
---|
119 | << "</th></tr></thead>\n"; |
---|
120 | |
---|
121 | os << "<tr><td>Author</td>" |
---|
122 | << "<td>Number of Lines</td>" |
---|
123 | << "<td>Code Lines</td>" |
---|
124 | << "<td>Comment Lines</td>" |
---|
125 | << "<td>Latest Commitment</td>" |
---|
126 | <<"</tr>"; |
---|
127 | |
---|
128 | std::string timefmt("%b %d %H:%M:%S %Y"); |
---|
129 | using namespace std; |
---|
130 | for (vector<Commitment>::const_iterator i=lc.begin(); i!=lc.end(); ++i) { |
---|
131 | os << "<tr><td>" |
---|
132 | << anchor(string(i->author()+"/total/index.html"),i->author()) |
---|
133 | << "</td><td>" << stats.lines(i->author()) << " (" |
---|
134 | << 100*stats.lines(i->author())/stats.lines() << "%)</td>" |
---|
135 | << "<td>" << stats.code(i->author()) << " (" |
---|
136 | << 100*stats.code(i->author())/stats.code() << "%)</td>" |
---|
137 | << "<td>" << stats.comments(i->author()) << " (" |
---|
138 | << 100*stats.comments(i->author())/stats.comments() << "%)</td>" |
---|
139 | << "<td>" << i->date()(timefmt) << "</td>" |
---|
140 | <<"</tr>"; |
---|
141 | } |
---|
142 | |
---|
143 | os << "</table></div>\n"; |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | void print_recent_logs(std::ostream& os, const SVNlog& log) |
---|
149 | { |
---|
150 | os << "<div class=\"main\">\n" |
---|
151 | << "<table class=\"main\"><thead><tr><th colspan=\"2\">" |
---|
152 | << "Recent Log" |
---|
153 | << "</th></tr></thead>\n"; |
---|
154 | |
---|
155 | std::vector<std::string>::const_reverse_iterator a=log.author().rbegin(); |
---|
156 | std::vector<std::string>::const_reverse_iterator d=log.date().rbegin(); |
---|
157 | std::vector<std::string>::const_reverse_iterator m=log.message().rbegin(); |
---|
158 | std::vector<size_t>::const_reverse_iterator r=log.revision().rbegin(); |
---|
159 | assert(log.author().size()==log.date().size()); |
---|
160 | assert(log.author().size()==log.message().size()); |
---|
161 | assert(log.author().size()==log.revision().size()); |
---|
162 | os << "<tr><td>Author</td><td>Date</td><td>Rev</td><td>Message</td></tr>\n"; |
---|
163 | HtmlStream hs(os); |
---|
164 | std::string timefmt("%b %d %H:%M:%S %Y"); |
---|
165 | const size_t maxlength = 80; |
---|
166 | const Configuration* conf = Configuration::instance(); |
---|
167 | for (size_t i=0; i<10 && a!=log.author().rend(); ++i) { |
---|
168 | os << "<tr><td>" << anchor(*a+"/total/index.html",*a) << "</td>"; |
---|
169 | Date date(*d); |
---|
170 | os << "<td>" << date(timefmt) << "</td>"; |
---|
171 | os << "<td>"; |
---|
172 | os << trac_revision(*r); |
---|
173 | os << "</td>"; |
---|
174 | os << "<td>"; |
---|
175 | std::string mess = *m; |
---|
176 | // replace newlines with space |
---|
177 | std::replace(mess.begin(), mess.end(), '\n', ' '); |
---|
178 | mess = htrim(mess); |
---|
179 | // truncate message if too long |
---|
180 | if (mess.size()>maxlength) |
---|
181 | mess = mess.substr(0,maxlength-3) + "..."; |
---|
182 | |
---|
183 | if (conf->trac_ticket().empty()) |
---|
184 | hs << mess; |
---|
185 | else {// make anchors to trac |
---|
186 | Trac trac(hs); |
---|
187 | trac.print(mess); |
---|
188 | } |
---|
189 | |
---|
190 | os << "</td></tr>"; |
---|
191 | ++a; |
---|
192 | ++d; |
---|
193 | ++m; |
---|
194 | ++r; |
---|
195 | } |
---|
196 | os << "</table></div>\n"; |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | }} // end of namespace svndigest and namespace theplu |
---|