aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/service/pages/mon_page.cpp
blob: 4d53beff0638ca15e3cf93d24e1a5baaf118505e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "mon_page.h"

using namespace NMonitoring;

IMonPage::IMonPage(const TString& path, const TString& title)
    : Path(path)
    , Title(title)
{
    Y_VERIFY(!Path.StartsWith('/')); 
    Y_VERIFY(!Path.EndsWith('/')); 
}

void IMonPage::OutputNavBar(IOutputStream& out) {
    TVector<const IMonPage*> parents;
    for (const IMonPage* p = this; p; p = p->Parent) {
        parents.push_back(p);
    }
    std::reverse(parents.begin(), parents.end());

    out << "<ol class='breadcrumb'>\n";

    TString absolutePath;
    for (size_t i = 0; i < parents.size(); ++i) {
        const TString& title = parents[i]->GetTitle();
        if (i == parents.size() - 1) {
            out << "<li>" << title << "</li>\n";
        } else {
            if (!absolutePath.EndsWith('/')) {
                absolutePath += '/';
            }
            absolutePath += parents[i]->GetPath();
            out << "<li class='active'><a href='" << absolutePath << "'>" << title << "</a></li>\n";
        }
    }
    out << "</ol>\n";
}