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
27 DocListItem (std::string title, std::string url,
28 std::time_t ctime, std::time_t mtime, std::string desc ) {
29 this->title = escape_html (title);
36 std::string get_desc () {
40 void set_desc (std::string desc) {
41 this->desc = escape_html (desc);
44 std::time_t get_mtime() {
47 void set_mtime(std::time_t mtime) {
50 std::time_t get_ctime() {
53 void set_ctime(std::time_t ctime) {
57 std::string get_url() {
61 void set_url(std::string url) {
65 std::string get_title() {
68 void set_title(std::string title) {
69 this->title = escape_html (title);
72 // output to HTML vide the template
73 std::string to_html (Template *t);
76 // output to HTML vide the template
77 std::string DocListItem::to_html (Template *t) {
78 std::string templstr = t->get_doclistitem_tpl ();
80 c = *std::localtime (&this->ctime);
81 m = *std::localtime (&this->mtime);
83 std::string outputhtml = fmt::format (templstr, fmt::arg("url", this->url),
84 fmt::arg("doctitle", this->title),
85 fmt::arg("desc", this->desc),
87 fmt::arg("mdate", m));
92 // to implement a document list (or table)
96 std::list<DocListItem> items;
98 void set_title (std::string title) {
99 this->title = escape_html (title);
101 // add a document item
102 void add_document_item (DocListItem docitem) {
103 this->items.insert (this->items.cend(), docitem);
105 // render to HTML from a template
106 std::string to_html (Template *t);
109 std::string DocList::to_html (Template *t) {
110 std::string templstr = t->get_doclist_tpl ();
112 std::string outputhtml = "";
113 // if the number of elements is non zero
114 if (this->items.size () != 0) {
115 std::string docitems = "";
116 for (DocListItem item : this->items)
117 docitems += item.to_html (t);
119 outputhtml = fmt::format (templstr,
120 fmt::arg ("title", this->title),
121 fmt::arg ("docitems", docitems));