summaryrefslogtreecommitdiff
path: root/server/src/journal_commit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/journal_commit.cc')
-rw-r--r--server/src/journal_commit.cc38
1 files changed, 32 insertions, 6 deletions
diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc
index accf839..f74e54e 100644
--- a/server/src/journal_commit.cc
+++ b/server/src/journal_commit.cc
@@ -200,6 +200,28 @@ JournalWriter::JournalWriter(std::string host, unsigned short int port)
void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
std::string resume, std::string course)
{
+ TemplateParser tp(course);
+ tp.parse();
+ Template *templ = tp.getTemplate();
+
+ size_t index = 0;
+ std::vector< Macro >::iterator i = templ->course.macros.begin();
+ while(i != templ->course.macros.end()) {
+ Macro &m = *i;
+ if(commit.macro == m.attributes["name"]) break;
+ index++;
+ i++;
+ }
+
+ if(index >= templ->course.macros.size()) {
+ PRACRO_ERR(journal, "Could not find macro %s in course %s\n",
+ commit.macro.c_str(), course.c_str());
+ // return;
+ } else {
+ PRACRO_DEBUG(journal, "Found macro %s as index %u in course %s\n",
+ commit.macro.c_str(), index, course.c_str());
+ }
+
// First run - initialize username and cpr.
if(currentuser == "" && entrylist.size() == 0) currentuser = transaction.user;
if(currentcpr == "" && entrylist.size() == 0) currentcpr = transaction.cpr;
@@ -208,9 +230,6 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
// Add the course resume as the header (ie. first entry) of the journal entry.
if(entrylist.size() == 0 && course != "") {
- TemplateParser tp(course);
- tp.parse();
- Template *templ = tp.getTemplate();
std::string course_resume = templ->course.attributes["resume"];
PRACRO_DEBUG(journal, "CourseResume: %s\n", course_resume.c_str());
@@ -219,7 +238,7 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
ResumeEntry re;
re.resume = course_resume;
re.macro = "course_header";
- entrylist.push_back(re);
+ entrylist[-1] = re; // Make sure it comes first.
}
}
@@ -233,6 +252,7 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
std::string r = stripTrailingWhitepace(addNewlines(resume, 60));
std::string m = commit.macro;
+ /*
// If macro already exists, overwrite with this entry, otherwise, just add it
int idx = -1;
std::vector< ResumeEntry >::iterator i = entrylist.begin();
@@ -252,6 +272,12 @@ void JournalWriter::addEntry(Transaction &transaction, Commit &commit,
re.macro = m;
entrylist.push_back(re);
}
+ */
+
+ ResumeEntry re;
+ re.resume = r;
+ re.macro = m;
+ entrylist[index] = re;
}
void JournalWriter::commit()
@@ -259,11 +285,11 @@ void JournalWriter::commit()
std::string resume;
// Iterate through all resumes, and create a string containing them all.
- std::vector< ResumeEntry >::iterator i = entrylist.begin();
+ std::map< int, ResumeEntry >::iterator i = entrylist.begin();
while(i != entrylist.end()) {
if(resume != "") resume += "\n\n";
// resume += i->macro + "\n";
- resume += i->resume;
+ resume += i->second.resume;
i++;
}