1 #ifndef __BIAWEBDOCITEMLIST__
2 #define __BIAWEBDOCITEMLIST__
9 #include <fmt/format.h>
10 #include <fmt/chrono.h>
11 #include "biawebstrings.hpp"
12 #include "biawebdocument.hpp"
13 #include "biawebtemplate.hpp"
15 // to implement a list of items (documents) with creation/modified date/time display
17 // to implement a single document item
20 // Just the required fields to build the item
26 DocListItem (std::string title, std::string url,
27 std::time_t ctime, std::time_t mtime ) {
28 this->title = escape_html (title);
34 std::time_t get_mtime() {
37 void set_mtime(std::time_t mtime) {
40 std::time_t get_ctime() {
43 void set_ctime(std::time_t ctime) {
47 std::string get_url() {
51 void set_url(std::string url) {
55 std::string get_title() {
58 void set_title(std::string title) {
59 this->title = escape_html (title);
62 // output to HTML vide the template
63 std::string to_html (Template *t);
66 // output to HTML vide the template
67 std::string DocListItem::to_html (Template *t) {
68 std::string templstr = t->get_doclistitem_tpl ();
70 c = *std::localtime (&this->ctime);
71 m = *std::localtime (&this->mtime);
73 std::string outputhtml = fmt::format (templstr, fmt::arg("url", this->url),
74 fmt::arg("doctitle", this->title),
76 fmt::arg("mdate", m));
81 // to implement a document list (or table)
85 std::list<DocListItem> items;
87 void set_title (std::string title) {
88 this->title = escape_html (title);
90 // add a document item
91 void add_document_item (DocListItem docitem) {
92 this->items.insert (this->items.cend(), docitem);
94 // render to HTML from a template
95 std::string to_html (Template *t);
98 std::string DocList::to_html (Template *t) {
99 std::string templstr = t->get_doclist_tpl ();
101 std::string outputhtml = "";
102 // if the number of elements is non zero
103 if (this->items.size () != 0) {
104 std::string docitems = "";
105 for (DocListItem item : this->items)
106 docitems += item.to_html (t);
108 outputhtml = fmt::format (templstr,
109 fmt::arg ("title", this->title),
110 fmt::arg ("docitems", docitems));