示例#1
0
void Tester::LoadGrammar()
{
    string h = internalPathNextPart("/share/");
    fs::path input = fs::path(appRoot()) / "share" / (h + ".data");
    mInput->setText("");
    mGrammar->setText("");
    mResult->clear();

    ifstream data_fs(input.string().c_str());
    if (data_fs) {
        data_fs.unsetf(std::ios::skipws);
        string data((istream_iterator<char>(data_fs)), istream_iterator<char>());
        mInput->setText(data);
        data_fs.close();
    } else {
        stringstream ss;
        ss << "share not found: " << h;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    fs::path grammar = fs::path(appRoot()) / "share" / (h + ".lua");
    ifstream grammar_fs(grammar.string().c_str());
    if (grammar_fs) {
        grammar_fs.unsetf(std::ios::skipws);
        string data((istream_iterator<char>(grammar_fs)), istream_iterator<char>());
        mGrammar->setText(data);
        grammar_fs.close();
    }
}
示例#2
0
Wt::WWidget* Tester::Input()
{

    Wt::WContainerWidget* container = new Wt::WContainerWidget();
    container->setStyleClass("input_container");

    Wt::WText* t = new Wt::WText("Input", container);
    t->setStyleClass("area_title");
    new Wt::WBreak(container);
    mInput = new Wt::WTextArea(container);
    mInput->setText("20131220T094700");

    new Wt::WBreak(container);

    t = new Wt::WText("Grammar", container);
    t->setStyleClass("area_title");
    new Wt::WBreak(container);
    mGrammar = new Wt::WTextArea(container);
    mGrammar->setRows(15);
    mGrammar->setText("local l = require 'lpeg'\nl.locale(l)\ngrammar = l.C(l.digit^-4)");

    Wt::WPushButton* button = new Wt::WPushButton("Test Grammar", container);
    button->clicked().connect(this, &Tester::GrammarButton);

    button = new Wt::WPushButton("Benchmark Grammar", container);
    button->clicked().connect(this, &Tester::BenchmarkButton);

    button = new Wt::WPushButton("Share Grammar", container);
    button->clicked().connect(this, &Tester::ShareGrammar);

    return container;
}
示例#3
0
HeightLines::HeightLines()
{
  museums.set("mapbox://mapbox.2opop9hr");
  contours.set("mapbox://mapbox.mapbox-terrain-v2");

  museumLayer.set(&museums);
  museumLayer.sourceLayer("museum-cusco");
  museumLayer.radius(8);
  museumLayer.color(Wt::WColor(55, 148, 179));

  contourLayer.set(&contours);
  contourLayer.sourceLayer("contour");
  contourLayer.join(MapBox::JOIN::Round);
  contourLayer.cap(MapBox::CAP::Round);
  contourLayer.color(Wt::WColor("#877b59"));
  contourLayer.width(1);

  resize(250, 100);

  Wt::WVBoxLayout * vbox = new Wt::WVBoxLayout();
  setLayout(vbox);

  Wt::WHBoxLayout * hbox = new Wt::WHBoxLayout();
  vbox->addLayout(hbox);

  Wt::WText * t = new Wt::WText("Width: ", this);
  t->setMargin(10);
  hbox->addWidget(t);

  Wt::WSlider * slider = new Wt::WSlider(this);
  slider->resize(200, 12);
  slider->setMinimum(1);
  slider->setMaximum(10);
  slider->setValue(1);
  hbox->addWidget(slider);

  slider->valueChanged().connect(std::bind([=]() {
    contourLayer.width(slider->value());
  }));

  hbox = new Wt::WHBoxLayout();
  vbox->addLayout(hbox);

  t = new Wt::WText("Blur: ", this);
  t->setMargin(10);
  hbox->addWidget(t);

  slider = new Wt::WSlider(this);
  slider->resize(200, 12);
  slider->setMinimum(0);
  slider->setMaximum(10);
  slider->setValue(0);
  hbox->addWidget(slider);

  slider->valueChanged().connect(std::bind([=]() {
    contourLayer.blur(slider->value());
  }));

}
示例#4
0
文件: View.cpp 项目: hpepper/wt-test
/**
  Constructor for View

  /usr/lib/Wt/examples/widgetgallery/examples/ComboBoxModel.cpp
  https://www.webtoolkit.eu/widgets/forms/combo-box
  https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WComboBox.html

 */
View::View(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
{
  setTitle("DropDown Demo");


  log("info") << "Test";

  // This is the container for the full screen.
  Wt::WContainerWidget *pScreenContainer = new Wt::WContainerWidget();
  pScreenContainer->resize(Wt::WLength::Auto, Wt::WLength::Auto);
  // Add the primary container to the root widget?
  root()->addWidget(pScreenContainer);

  // Choose the grid layout.
  Wt::WGridLayout *pScreenLayout = new Wt::WGridLayout();
  pScreenContainer->setLayout(pScreenLayout);

  int nRow = 0;
  int nColoumn = 0;

 
  // Create the label
  Wt::WText *lblSeriesChoice = new Wt::WText("Series:");
  // set right align the label
  lblSeriesChoice->setTextAlignment(Wt::AlignRight);
  pScreenLayout->addWidget(lblSeriesChoice, nRow, nColoumn+0);

  // Create the dropdown
  Wt::WComboBox *cbSeries = new Wt::WComboBox();
  cbSeries->addItem("");
  cbSeries->addItem("New");
  cbSeries->addItem("Krakken awoke");
  cbSeries->addItem("Appocalypse survival");
  cbSeries->setCurrentIndex(0); // Empty string
  pScreenLayout->addWidget(cbSeries, nRow, nColoumn+1);


  // Create the connection
  cbSeries->activated().connect(this, &View::DropDownSelectionChangeOtherDropDown);
  cbSeries->activated().connect(this, &View::DropDownSelectionChangeTab);
  /* Signals connect to Slots.
  * You may specify up to 6 arguments which may be of arbitrary types that are Copyable, that may be passed through the signal to connected slots.
  *   https://www.webtoolkit.eu/wt/doc/reference/html/group__signalslot.html
  * I think the 
  *   first parm - is a pointer to the target class.
  *   second parm - is the name of the method?
  * 
  * See: Wt::Signal.
  */


  /*
  * Let row 1 and column 1 take the excess space.?
  */
  pScreenLayout->setRowStretch(0, 0);
  pScreenLayout->setColumnStretch(0, 0);
} // end
示例#5
0
void Tester::TestGrammar(bool benchmark)
{
    mResult->clear();

    fs::path grammar = fs::path("/tmp") / (sessionId() + ".lua");
    ofstream ofs(grammar.string().c_str());
    if (ofs) {
        ofs << mGrammar->text();
        ofs.close();
    } else {
        stringstream ss;
        ss << "failed to open: " << grammar;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("error") << ss.str();
        return;
    }
    lua_sandbox* sb = lsb_create(NULL, grammar.string().c_str(), "modules",
                                 8*1024*1024, 1e6, 1024*63);
    if (!sb) {
        stringstream ss;
        ss << "lsb_create() failed";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("error") << ss.str();
        return;
    }
    if (lsb_init(sb, nullptr)) {
        stringstream ss;
        string error = lsb_get_error(sb);
        size_t pos = error.find_first_of(':');
        if (pos != string::npos) {
            ss << "line " << error.substr(pos + 1);
        } else {
            ss << error;
        }
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;

    }
    if (benchmark) {
        Benchmark(sb, mInput->text().narrow());
    } else {
        Match(sb, mInput->text().narrow());
    }
    char* e = lsb_destroy(sb, nullptr);
    if (e) {
        stringstream ss;
        ss << "lsb_destroy() failed: " << e;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        free(e);
    }
}
示例#6
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void LocationTable::createHeaderRow()
{
    static const std::string captions[7] = {"Gebiet", "Name", "Höhe", "Position", "SP", "LP", "WP"};
    for(size_t i=0; i<sizeof(captions) / sizeof(std::string); ++i)
    {
        Wt::WText *labelText = new Wt::WText(captions[i]);
        labelText->setStyleClass("tableHeader");
        elementAt(0, i + 1)->addWidget(labelText);
    }
    rowAt(0)->setStyleClass("title");
}
示例#7
0
void
WFunctionSummary::init() {
    Wt::WVBoxLayout *vbox = new Wt::WVBoxLayout;
    this->setLayout(vbox);

    analyzers().push_back(FunctionEntryAddress::instance());
    analyzers().push_back(FunctionName::instance());
    analyzers().push_back(FunctionSizeBytes::instance());
    analyzers().push_back(FunctionSizeInsns::instance());
    analyzers().push_back(FunctionSizeBBlocks::instance());
    analyzers().push_back(FunctionSizeDBlocks::instance());
    analyzers().push_back(FunctionNDiscontiguousBlocks::instance());
    analyzers().push_back(FunctionNIntervals::instance());
    analyzers().push_back(FunctionImported::instance());
    analyzers().push_back(FunctionExported::instance());
    analyzers().push_back(FunctionNCallers::instance());
    analyzers().push_back(FunctionNReturns::instance());
    analyzers().push_back(FunctionMayReturn::instance());
    analyzers().push_back(FunctionStackDelta::instance());

    // Build a table to hold analysis results. The results will be organized into NCOLS each occupying two table columns (one
    // for the name and one for the value).
    const size_t NROWS = (analyzers_.size() + NCOLS - 1) / NCOLS;
    wAnalysisResultTable_ = new Wt::WTable();
    vbox->addWidget(wAnalysisResultTable_);

    Wt::WCssDecorationStyle labelDecor;
    labelDecor.setBackgroundColor(toWt(Color::HSV(0, 0, 0.95)));
    for (size_t col=0, i=0; col<NCOLS && i<analyzers_.size(); ++col) {
        for (size_t row=0; row<NROWS && i<analyzers_.size(); ++row) {
            Wt::WText *wLabel = new Wt::WText("<b>" + analyzers_[i]->name() + "</b>");
            wLabel->setToolTip(analyzers_[i]->toolTip());
            wAnalysisResultTable_->elementAt(row, 2*col+0)->addWidget(wLabel);
            wAnalysisResultTable_->elementAt(row, 2*col+0)->setContentAlignment(Wt::AlignRight);
            wAnalysisResultTable_->elementAt(row, 2*col+0)->setDecorationStyle(labelDecor);

            Wt::WText *wValue = new Wt::WText;
            wValue->setTextFormat(Wt::PlainText);
            analyzerResults_.push_back(wValue);
            analyzerResults_.back()->setToolTip(analyzers_[i]->toolTip());
            wAnalysisResultTable_->elementAt(row, 2*col+1)->addWidget(analyzerResults_.back());
            wAnalysisResultTable_->elementAt(row, 2*col+1)->setPadding(Wt::WLength(1, Wt::WLength::FontEm), Wt::Left);
            wAnalysisResultTable_->elementAt(row, 2*col+1)->setPadding(Wt::WLength(10, Wt::WLength::FontEm), Wt::Right);
            ++i;
        }
    }

    // Text area to hold function comments
    wFunctionComments_ = new Wt::WTextArea;
    vbox->addWidget(wFunctionComments_, 1 /*stretch*/);

    // FIXME[Robb P. Matzke 2015-05-06]: We don't provide a way to save results yet, so don't allow comment editing
    wFunctionComments_->setEnabled(false);
}
      WebApp::WebApp(const Wt::WEnvironment & env) : WApplication(env) {
        if (string(org::esb::config::Config::getProperty("hive.mode")) == "setup") {
          WApplication::instance()->redirect("/setup");
          WApplication::instance()->quit();
        }
        setTitle("Hive Webadmin");
        _isAuthenticated = false;
        Wt::Ext::Container *viewPort = new Wt::Ext::Container(root());
        Wt::WBorderLayout *layout = new Wt::WBorderLayout(viewPort);


        Wt::Ext::Panel *north = new Wt::Ext::Panel();
        north->setBorder(false);
        std::string h = "MediaEncodingCluster V-";
        h += MHIVE_VERSION;
        h += "($Rev$-"__DATE__ "-" __TIME__")";
        Wt::WText *head = new Wt::WText(h);
        head->setStyleClass("north");
        north->setLayout(new Wt::WFitLayout());
        north->layout()->addWidget(head);
        north->resize(Wt::WLength(), 35);
        layout->addWidget(north, Wt::WBorderLayout::North);

        /* West */
        west = new Wt::Ext::Panel();

        west->setTitle("Menu");
        west->resize(200, Wt::WLength());
        west->setResizable(true);
        west->collapse();
        west->setAnimate(true);
        west->setAutoScrollBars(true);
        layout->addWidget(west, Wt::WBorderLayout::West);


        /* Center */
        Wt::Ext::Panel *center = new Wt::Ext::Panel();
        center->setTitle("MediaEncodingCluster");
        center->layout()->addWidget(exampleContainer_ = new Wt::WContainerWidget());
        center->setAutoScrollBars(true);
        layout->addWidget(center, Wt::WBorderLayout::Center);

        exampleContainer_->setPadding(5);

        currentExample_ = login = new Login(exampleContainer_);
        login->authenticated.connect(SLOT(this, WebApp::authenticated));
        //        useStyleSheet("ext/resources/css/xtheme-gray.css");
        useStyleSheet("filetree.css");
        useStyleSheet("main.css");
        std::string res = std::string(Config::getProperty("hive.path"));
        res.append("/../res/messages");
        messageResourceBundle().use(res.c_str(), false);

      }
示例#9
0
Wt::WWidget* Tester::Result()
{
    Wt::WContainerWidget* c = new Wt::WContainerWidget();
    c->setStyleClass("result_container");

    Wt::WText* t = new Wt::WText("Results", c);
    t->setStyleClass("area_title");

    mResult = new Wt::WContainerWidget(c);
    mResult->setStyleClass("result_output");

    return c;
}
FeaturesBelowMouse::FeaturesBelowMouse()
{
  resize(290, 400);

  Wt::WText * text = new Wt::WText(this);

  mouseMove.trigger(MapBox::EVENT::MouseMove);
  mouseMove.code("function(e) {"
    "var features = " + APP->getMap()->jsRef() + ".map.queryRenderedFeatures(e.point);"
    "document.getElementById('" + text->id() + "').innerHTML = '<pre>' + JSON.stringify(features, null, 2) + '</pre>';"
    "}"
  );
}
示例#11
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
LocationPanel::LocationPanel(boost::shared_ptr<FlightDatabase>  flightDb, Wt::WContainerWidget *parent)
 : Wt::WCompositeWidget(parent), flightDb_(flightDb), impl_(new Wt::WContainerWidget())
{
    setImplementation(impl_);
    setStyleClass("flb_detail_panel");
    impl_->setStyleClass("flb_detail_panel");

    cbArea_ = new Wt::Ext::ComboBox(impl_);
    cbTakeoff_ = new Wt::Ext::CheckBox(impl_);
	cbLanding_ = new Wt::Ext::CheckBox(impl_);
	cbWayPnt_  = new Wt::Ext::CheckBox(impl_);
    table_  = new LocationTable(flightDb, impl_);
    pglist_ = new PagesList(table_);
    // signals
    cbArea_->activated().connect(SLOT(this, LocationPanel::filter));
    cbTakeoff_->checked().connect(SLOT(this, LocationPanel::filter));
    cbLanding_->checked().connect(SLOT(this, LocationPanel::filter));
    cbWayPnt_->checked().connect(SLOT(this, LocationPanel::filter));
    cbTakeoff_->unChecked().connect(SLOT(this, LocationPanel::filter));
    cbLanding_->unChecked().connect(SLOT(this, LocationPanel::filter));
    cbWayPnt_->unChecked().connect(SLOT(this, LocationPanel::filter));

    // header
    Wt::WTable *topBar = new Wt::WTable();
    topBar->setStyleClass("FilterBar");
    Wt::WText *wtFilt = new Wt::WText("Filter : ");
    wtFilt->setStyleClass("FilterTitle");
    Wt::WText *wtArea = new Wt::WText("Fluggebiet");
    wtArea->setStyleClass("FilterSubTitle");
    cbTakeoff_->setText("Startplaetze");
    cbLanding_->setText("Landeplaetze");
    cbWayPnt_->setText("Wegpunkte");
    topBar->elementAt(0, 0)->addWidget(wtFilt);
    topBar->elementAt(0, 1)->addWidget(wtArea);
    topBar->elementAt(0, 2)->addWidget(cbArea_);
    topBar->elementAt(0, 3)->addWidget(cbTakeoff_);
    topBar->elementAt(0, 4)->addWidget(cbLanding_);
    topBar->elementAt(0, 5)->addWidget(cbWayPnt_);
    topBar->elementAt(0, 6)->addWidget(pglist_);

    Wt::WContainerWidget *botBar = new Wt::WContainerWidget();

    Wt::WBorderLayout *borderLayout = new Wt::WBorderLayout();
    impl_->setLayout(borderLayout);
    borderLayout->addWidget(topBar, Wt::WBorderLayout::North);
    borderLayout->addWidget(table_, Wt::WBorderLayout::Center);
    borderLayout->addWidget(botBar, Wt::WBorderLayout::South);

    load();
    filter();
}
示例#12
0
Wt::WText *TopicWidget::addText(const Wt::WString& s,
				Wt::WContainerWidget *parent)
{
  Wt::WText *text = new Wt::WText(s, parent);
  bool literal;
#ifndef WT_TARGET_JAVA
  literal = s.literal();
#else
  literal = Wt::WString(s).literal();
#endif
  if (!literal)
    text->setInternalPathEncoding(true);
  return text;
}
示例#13
0
Upload::Upload( Wt::WContainerWidget* pcw ) {
  
  //Wt::WContainerWidget *container = new Wt::WContainerWidget();

  Wt::WFileUpload *fu = new Wt::WFileUpload( pcw );
  fu->setFileTextSize( 10000 ); // Set the maximum file size (in KB )
  fu->setProgressBar(new Wt::WProgressBar());
  fu->setMargin(10, Wt::Right);

  // Provide a button to start uploading.
  Wt::WPushButton *uploadButton = new Wt::WPushButton("Send", pcw );
  uploadButton->setMargin(10, Wt::Left | Wt::Right);

  Wt::WText *out = new Wt::WText( pcw );

  // Upload when the button is clicked.
  uploadButton->clicked().connect(std::bind([=] () {
      fu->upload();
      uploadButton->disable();
  }));

  // Upload automatically when the user entered a file.
  fu->changed().connect(std::bind([=] () {
      fu->upload();
      uploadButton->disable();
      std::string s( "File upload is changed." );
      out->setText( s );
  }));

  // React to a succesfull upload.
  fu->uploaded().connect(std::bind([=] () {
    std::string s( "File upload is finished: " );
    s += fu->clientFileName().toUTF8();
    s += ",";
    //s += fu->fileTextSize()
    s += fu->spoolFileName();
    //fu->stealSpooledFile()
    out->setText( s );
  }));

  // React to a file upload problem.
  fu->fileTooLarge().connect(std::bind([=] () {
      out->setText("File is too large.");
  }));
}
示例#14
0
Wt::WContainerWidget *PopupChatWidget::createBar() 
{
  Wt::WContainerWidget *bar = new Wt::WContainerWidget();
  bar->setStyleClass("chat-bar");

  Wt::WText *toggleButton = new Wt::WText();
  toggleButton->setInline(false);
  toggleButton->setStyleClass("chat-minmax");
  bar->clicked().connect(this, &PopupChatWidget::toggleSize);
  bar->clicked().connect(this, &PopupChatWidget::goOnline);

  bar->addWidget(toggleButton);

  title_ = new Wt::WText(bar);

  bar_ = bar;

  return bar;
}
示例#15
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void PagesList::select(Wt::WMouseEvent mev)
{
    // first, we have to find out which text was clicked
    Wt::WObject *wobj = sender();
    Wt::WText *wtxt = dynamic_cast<Wt::WText*>(wobj);
    if(!wtxt)
        return;

    const string txt = wtxt->text().narrow();
    if(txt == "<" || txt == "&lt;")
        table_->loadPage(table_->pageNr() - 1);
    else if(txt == ">" || txt == "&gt;")
        table_->loadPage(table_->pageNr() + 1);
    else
        table_->loadPage(lexical_cast<unsigned int>(txt));

    // reflect the change on the pagelist itself
    load();
}
示例#16
0
ForumCommentWidget::ForumCommentWidget(const CommentPtr& comment) {
    dbo::Transaction t(tApp->session());
    if (comment->type() != Comment::FORUM_COMMENT) {
        return;
    }
    new Header(tr("tc.forum.Comment"), this);
    Wt::WText* text = new Wt::WText(forum_comment_text(comment), this);
    text->addStyleClass("thechess-forum-comments");
    UserPtr user = comment->init();
    if (user) {
        new Wt::WBreak(this);
        user_anchor(user, this);
    }
    CommentPtr post_text = comment->root();
    CommentPtr post = post_text->parent();
    new Wt::WBreak(this);
    Wt::WAnchor* a = new Wt::WAnchor(this);
    a->setLink(tApp->path().post()->get_link(post.id()));
    a->setText(tr("tc.forum.post_header")
               .arg(post.id()).arg(post->text_or_removed(tApp->user())));
    CommentPtr parent = comment->parent();
    if (parent->type() == Comment::FORUM_COMMENT) {
        new Wt::WBreak(this);
        Wt::WAnchor* g = new Wt::WAnchor(this);
        g->setLink(tApp->path().post_comment()->get_link(parent.id()));
        g->setText(tr("tc.forum.Goto_parent").arg(parent.id()));
    }
    if (comment->can_edit(tApp->user())) {
        new Wt::WBreak(this);
        Wt::WAnchor* e = new Wt::WAnchor(this);
        e->setLink(tApp->path().forum_edit()->get_link(comment.id()));
        e->setText(tr("tc.forum.Edit"));
    }
    Wt::WTextEdit* edit = new Wt::WTextEdit(this);
    patch_text_edit(edit);
    new Wt::WBreak(this);
    if (Comment::can_create(tApp->user(), Comment::FORUM_COMMENT, comment)) {
        Wt::WPushButton* add = new Wt::WPushButton(tr("tc.comment.Add"), this);
        add->clicked().connect(boost::bind(add_comment, comment, edit, this));
    }
    add_remover_buttons(comment, this);
}
示例#17
0
void Tester::ShareGrammar()
{
    boost::hash<std::string> string_hash;
    string data(mInput->text().narrow() + mGrammar->text().narrow());
    string h = boost::lexical_cast<string>(string_hash(data));
    fs::path input = fs::path(appRoot()) / "share" / (h + ".data");
    if (!exists(input)) {
        ofstream data_fs(input.string().c_str());
        if (data_fs) {
            data_fs << mInput->text();
            data_fs.close();
        } else {
            stringstream ss;
            ss << "failed to open: " << input;
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("error") << ss.str();
            return;
        }

        fs::path grammar = fs::path(appRoot()) / "share" / (h + ".lua");
        ofstream lua_fs(grammar.string().c_str());
        if (lua_fs) {
            lua_fs << mGrammar->text();
            lua_fs.close();
        } else {
            stringstream ss;
            ss << "failed to open: " << grammar;
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("error") << ss.str();
            return;
        }
    }

    setInternalPath("/share/" + h);
    Wt::WMessageBox* messageBox = new Wt::WMessageBox("Share", makeAbsoluteUrl(bookmarkUrl()), Wt::Information, Wt::Ok);
    messageBox->buttonClicked().connect(std::bind([=]() {
        delete messageBox;
    }));
    messageBox->show();
}
示例#18
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void LocationTableRow::show()
{
	clearRow();

    // the edit image
	Wt::WImage *wiEdit = new Wt::WImage("img/edit.png");
	wiEdit->setToolTip("Ort bearbeiten");
	wiEdit->setStyleClass("operationImg");
	table_->elementAt(rowNr_, colOp)->addWidget(wiEdit);
	wiEdit->clicked().connect(SLOT(this, LocationTableRow::edit));
    // the delete image
	Wt::WImage *wiDelete = new Wt::WImage("img/delete.png");
	wiDelete->setToolTip("Ort löschen");
	wiDelete->setStyleClass("operationImg");
	table_->elementAt(rowNr_, colOp)->addWidget(wiDelete);
	wiDelete->clicked().connect(SLOT(this, LocationTableRow::remove));
	// the map image
//	WImage *wiMap = new WImage("img/map.png");
//	wiMap->setToolTip("position anschauen");
//    wiMap->setStyleClass("operationImg");
//	table_->elementAt(rowNr_, colOp)->addWidget(wiMap);
//	wiMap->clicked.connect(SLOT(this, LocationTableRow::map));

	// prepare the text
	std::vector<std::string> vsText;
	vsText.push_back(location_->area()->name());
	vsText.push_back(location_->name());
	vsText.push_back(boost::lexical_cast<std::string>(location_->height()));
	vsText.push_back(Wt::WGeoPosEdit::format(std::make_pair(location_->pos().first, location_->pos().second), Wt::WGeoPosEdit::WGS84_SEC));
	vsText.push_back(location_->usage() & Location::UA_TAKEOFF ? "x" : "_");
	vsText.push_back(location_->usage() & Location::UA_LANDING ? "x" : "_");
	vsText.push_back(location_->usage() & Location::UA_WAYPNT  ? "x" : "_");
	// add the text widgets
	for(size_t i=0; i<vsText.size(); ++i)
	{
		Wt::WText *wtxt = new Wt::WText(vsText[i]);
		wtxt->setStyleClass("tableContent");
		table_->elementAt(rowNr_, i + 1)->addWidget(wtxt);
	}
}
示例#19
0
/* ****************************************************************************
 * Limit List
 */
void EditUsers::LimitList()
{
    Wt::WContainerWidget* list = new Wt::WContainerWidget;
    bindWidget("user-list",list);

    typedef Wt::Dbo::collection<Wt::Dbo::ptr<User> > UserList;
    Wt::Dbo::Transaction t(session_);
    UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name");

    Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >* userLinkMap = new Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >(this);
    userLinkMap->mapped().connect(this,&EditUsers::OnUserClicked);
    for (UserList::const_iterator i = users.begin(); i != users.end(); ++i)
    {
        Wt::WText* t = new Wt::WText((*i)->name, list);
        t->setStyleClass("link");
        new Wt::WBreak(list);
        userLinkMap->mapConnect(t->clicked(), (*i).id());
    }
    if (!users.size())
    {
        new Wt::WText(tr("no-users-found"),list);
    }
} // end void EditUsers::LimitList
示例#20
0
 void add_handler_() {
     Wt::WValidator::State V = Wt::WValidator::Valid;
     if (username_->validate() != V) {
         error_->setText(tr("facts.comment.Incorrect_username"));
         return;
     }
     if (email_->validate() != V) {
         error_->setText(tr("facts.comment.Incorrect_email"));
         return;
     }
     int input_length = text_->text().value().size();
     if (input_length < MIN_INPUT_SIZE || input_length > MAX_TEXT_SIZE) {
         error_->setText(tr("facts.comment.Incorrect_text"));
         return;
     }
     dbo::Transaction t(fApp->session());
     if (fApp->is_banned()) {
         error_->setText(tr("facts.common.BannedIp"));
         return;
     }
     int index;
     if (comments_->fact()->comments().size()) {
         index = 1 + fApp->session()
                 .query<int>("select max(comment_index) from facts_comment where fact_id=?")
                 .bind(comments_->fact().id());
     } else {
         index = 1;
     }
     CommentPtr c = fApp->session().add(new Comment(CommentId(comments_->fact(), index)));
     c.modify()->set_username(username_->text());
     c.modify()->set_email(email_->text().toUTF8());
     c.modify()->set_text(text_->text());
     c.modify()->set_ip(fApp->environment().clientAddress());
     comments_->comment_added_handler_(); // delete this
     t.commit();
 }
示例#21
0
void Tester::Match(lua_sandbox* lsb, const string& input)
{
    lua_State* lua = lsb_get_lua(lsb);
    if (!lua) return;

    if (!CreateGlobalMatch(lua)) {
        stringstream ss;
        ss << "lpeg.match is not available";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    if (lsb_pcall_setup(lsb, kMatchFunction)) {
        stringstream ss;
        ss << "lsb_pcall_setup() failed";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    lua_getglobal(lua, "grammar");
    if (!lua_isuserdata(lua, -1)) {
        stringstream ss;
        ss << "no global grammar variable was found";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    lua_pushstring(lua, input.c_str());
    if (lua_pcall(lua, 2, LUA_MULTRET, 0) != 0) {
        char err[LSB_ERROR_SIZE];
        int len = snprintf(err, LSB_ERROR_SIZE, "%s() %s", kMatchFunction,
                           lua_tostring(lua, -1));
        if (len >= LSB_ERROR_SIZE || len < 0) {
            err[LSB_ERROR_SIZE - 1] = 0;
        }
        stringstream ss;
        ss << err;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        lsb_terminate(lsb, err);
        return;
    }
    // iterater over the results
    int results = lua_gettop(lua);
    if (LUA_TNIL == lua_type(lua, 1)) {
        stringstream ss;
        ss << "no match";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
    } else {
        Wt::WTree* tree = new Wt::WTree(mResult);
        tree->setSelectionMode(Wt::SingleSelection);
        Wt::WTreeNode* root = new Wt::WTreeNode("Returned Values");
        root->setStyleClass("tree_results");
        tree->setTreeRoot(root);
        root->label()->setTextFormat(Wt::PlainText);
        root->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
        for (int i = 1; i <= results; ++i) {
            stringstream ss;
            OutputItem(lua, i, root, ss);
        }
        root->expand();
    }
    lua_pop(lua, lua_gettop(lua)); // clear the stack
    lsb_pcall_teardown(lsb);
}
示例#22
0
void ChamadaForm::_initialize(){
	Wt::Dbo::Transaction transaction(_dbSession);

	Wt::WText* title = new Wt::WText("<h3>Diario de Classe: " + Wt::WDate::currentDate().toString("dd/MM/yyyy").toUTF8() + "</h3> <br></br><br></br>");

		addWidget(title);
		Wt::WPushButton* fazerChamada = new Wt::WPushButton("Percorrer turma", this);

		fazerChamada->setStyleClass("btn btn-primary");

		fazerChamada->clicked().connect(std::bind([=](){
			new AutoChamada(_dbSession, sortList);
		}));

		fazerChamada->setMargin(20, Wt::Bottom);
		_list =  new Wt::WTable(this);


		Wt::WPushButton* save = new Wt::WPushButton("Salvar", this);
		save->setStyleClass("btn btn-success");
		save->setMargin(10, Wt::Right);
		save->clicked().connect(std::bind([=](){
			_save();
			delete this;
		}));

		Wt::WPushButton* cancel = new Wt::WPushButton("Cancelar", this);
		cancel->setStyleClass("btn btn-primary");
		cancel->clicked().connect(std::bind([=](){
			delete this;
		}));

	_list->setWidth(Wt::WLength("100%"));
	_list->addStyleClass("table-striped table-hover");
	_list->setMargin(50, Wt::Bottom);
	new Wt::WText("Aluno", _list->elementAt(0,0));
	new Wt::WText("Presente", _list->elementAt(0,1));
	_list->setHeaderCount(1);


	for(auto i : _disciplina->turma()->alunos()){
		Wt::WCheckBox* checkbox = new Wt::WCheckBox();
		sortList.push_back(std::make_pair(checkbox, i));
	}

	auto sortAlg = [](std::pair<Wt::WCheckBox*, Wt::Dbo::ptr<SiconfModel::Aluno>> par1, std::pair<Wt::WCheckBox*, Wt::Dbo::ptr<SiconfModel::Aluno>>par2){
		return par1.second->usuario()->nome() < par2.second->usuario()->nome();
	};

	std::sort(std::begin(sortList), std::end(sortList), sortAlg);

	for(auto i : sortList){
		int row = _list->rowCount();
		Wt::WText* name = new Wt::WText(i.second->usuario()->nome() + " " + i.second->usuario()->sobrenome(), _list->elementAt(row, 0));
		name->setMargin(10, Wt::Right);
		_list->elementAt(row, 1)->addWidget(i.first);
		_list->elementAt(row, 1)->setHeight(40);
		_list->elementAt(row, 1)->setWidth(100);

	}
}
示例#23
0
void AlunoList::setTable(){

	Wt::Dbo::Transaction transaction(_dbSession);
	_table->clear();
	_table->setHeaderCount(1);
	_table->setStyleClass("table table-striped table-hover");
	_table->setWidth(500);

		Wt::Dbo::ptr<SiconfModel::Turma> turma = _disciplina->turma();

		Wt::Dbo::collection<Wt::Dbo::ptr<SiconfModel::Aluno>> alunos = turma->alunos();

		new Wt::WText("Nome", _table->elementAt(0,0));
		new Wt::WText("Frequencia", _table->elementAt(0,1));

		Wt::Dbo::collection<Wt::Dbo::ptr<SiconfModel::Avaliacao>> avaliacoes = _disciplina->avaliacoes();

		for(unsigned i = 1; i < (avaliacoes.size() + 1) ; i++){
			new Wt::WText("Av. " + std::to_string(i), _table->elementAt(0, _table->columnCount()));
		}

		new Wt::WText("Media", _table->elementAt(0, _table->columnCount()));

		for(auto aluno : alunos){
			int row = _table->rowCount();
			new Wt::WText(aluno->usuario()->nome(), _table->elementAt(row, 0));
			float presencas = 0.0;
			float total = 0.0;

			try{

				std::vector<Wt::Dbo::ptr<SiconfModel::Frequencia>> frequencias;

				total = _disciplina->aulas().size();

				Wt::Dbo::collection<Wt::Dbo::ptr<SiconfModel::Frequencia>> collFrequ = _dbSession.find<SiconfModel::Frequencia>("where frequencias_aluno_id = ?").bind(aluno.id());

				for(auto i : collFrequ){

					if(i->aula()->disciplina().id() == _disciplina.id()){
						if(i->presenca()){
							presencas +=1;
						}
					}
				}

				if(total > 0){
					for(auto i : frequencias){
						if(i->presenca()) presencas +=1;
					}
					presencas = ((presencas/total)* 100);
				}

			}catch(Wt::Dbo::Exception& e){
				std::cout << "AlunoList::setTable: " << e.what() << std::endl;
			}

			std::stringstream strPresencas;
			strPresencas << std::fixed << std::setprecision(1) << presencas;

			new Wt::WText(strPresencas.str() + " %", _table->elementAt(row, 1));
			unsigned col = 2;

			int qtdAvaliacoes = avaliacoes.size();
			float media = 0;

			for(auto avaliacao : avaliacoes){
				Wt::Dbo::ptr<SiconfModel::Nota> nota = _dbSession.find<SiconfModel::Nota>("where notas_avaliacao_id = ? and notas_aluno_id = ?").bind(avaliacao.id()).bind(aluno.id());
				if(nota){
					media+=nota->nota();
					std::stringstream strNotas;
					strNotas << std::fixed << std::setprecision(1) << nota->nota();
					Wt::WText* text = new Wt::WText(strNotas.str(), _table->elementAt(row, col));
					if(nota->nota() < 5){
						text->addStyleClass("text-red");
					}
				}
				col++;
			}


			if(qtdAvaliacoes == 0){
				media = 0;
			}else{
				media /= qtdAvaliacoes;
			}


			std::stringstream strMedia;
			strMedia << std::fixed << std::setprecision(1) << media;
			Wt::WText* text = new Wt::WText(strMedia.str(), _table->elementAt(row, _table->columnCount() -1));
			if(media < 5){
				text->addStyleClass("text-red");
			}
		}
}
// Updates all ranks
void RecentMatchesContainer::update()
{
    this->clear();
    
    std::vector<RecentMatch> recent_matches = Spartan_->getRecentMatches();
    
    // Create halo api with an api key (get api key from 343i api site)
    //HaloAPI halo_api("05cdc66c52ca4465b0b6e3c56bb87b71");
    
    for (int i = 0; i < recent_matches.size() && i < 10; i++)
    {
        // CUSTOM CONTAINERS
        Wt::WContainerWidget *myContainer = new Wt::WContainerWidget();
        myContainer->decorationStyle().setBorder(Wt::WBorder(Wt::WBorder::Style::Solid, Wt::WBorder::Width::Thin, Wt::WColor(0, 0, 0)));
        myContainer->decorationStyle().setBackgroundColor(Wt::WColor(240, 240, 240));
        myContainer->setPadding(3);
        myContainer->setMargin(3, Wt::Bottom);
        
        std::string title_string = "<b>" + getNameFromHopper(recent_matches[i].hopper_id_) + " / </b>" + getNameFromBaseVariant(recent_matches[i].base_variant_) + "<b> / </b>" + getNameFromMap(recent_matches[i].map_id_) + "";
        Wt::WText *someText = new Wt::WText(title_string, myContainer);
        
        Wt::WPushButton *myButton = new Wt::WPushButton(" + ", myContainer);
        myButton->setFloatSide(Wt::Right);
        
        std::string game_time = time_from_double(recent_matches[i].match_length_);
        Wt::WText *someMoreText = new Wt::WText(game_time, myContainer);
        someMoreText->setFloatSide(Wt::Right);
        
        Wt::WStackedWidget *myStack = new Wt::WStackedWidget(myContainer);
        Wt::WText *text1 = new Wt::WText("text1", myStack);

        
        myButton->clicked().connect(std::bind([=]()
        {
            if (myStack->currentIndex() == 0)
            {
                myButton->setText(" - ");
                Wt::WContainerWidget *stats_table = new Wt::WContainerWidget(myStack);
                Wt::WTable *table = new Wt::WTable(stats_table);
                table->setHeaderCount(1);
                table->elementAt(0, 0)->addWidget(new Wt::WText("Gamertag"));
                HaloAPI halo_api("05cdc66c52ca4465b0b6e3c56bb87b71");
                std::vector<std::string> gamertags;
                
                std::string json_data = halo_api.getPostGameCarnageArena(recent_matches[i].match_id_);
                Json::Value root;   // will contains the root value after parsing.
                Json::Reader reader;
                bool parsingSuccessful = reader.parse( json_data, root );
                if ( !parsingSuccessful )
                {
                    // report to the user the failure and their locations in the document.
                    std::cout  << "Failed to parse configuration\n"
                    << reader.getFormattedErrorMessages();
                }
                const Json::Value plugins = root;
                
                for (int j = 0; j < plugins["PlayerStats"].size(); j++)
                {
                    std::string tag(
                                    plugins["PlayerStats"][j]["Player"]["Gamertag"].asString()
                                    );
                    gamertags.push_back(tag);
                    table->elementAt(j+1, 0)->addWidget(new Wt::WText(tag));
                }
                table->addStyleClass("table table-condensed");
                myStack->setCurrentIndex(1);
            } else
            {
                delete myStack->currentWidget();
                myStack->setCurrentIndex(0);
                myButton->setText(" + ");
            }
        }));
        this->addWidget(myContainer);
    }
}
示例#25
0
void Tester::Benchmark(lua_sandbox* lsb, const string& input)
{
    lua_State* lua = lsb_get_lua(lsb);
    if (!lua) return;
    bool nomatch = false;

    if (!CreateGlobalMatch(lua)) {
        stringstream ss;
        ss << "lpeg.match is not available";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    clock_t t = clock();
    int x, iter = 10000;
    for (x = 0; x < iter; ++x) {
        if (lsb_pcall_setup(lsb, kMatchFunction)) {
            stringstream ss;
            ss << "lsb_pcall_setup() failed";
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("info") << ss.str();
            return;
        }

        lua_getglobal(lua, "grammar");
        if (!lua_isuserdata(lua, -1)) {
            stringstream ss;
            ss << "no global grammar variable was found";
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("info") << ss.str();
            return;
        }

        lua_pushstring(lua, input.c_str());
        if (lua_pcall(lua, 2, LUA_MULTRET, 0) != 0) {
            char err[LSB_ERROR_SIZE];
            int len = snprintf(err, LSB_ERROR_SIZE, "%s() %s", kMatchFunction,
                               lua_tostring(lua, -1));
            if (len >= LSB_ERROR_SIZE || len < 0) {
                err[LSB_ERROR_SIZE - 1] = 0;
            }
            stringstream ss;
            ss << err;
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("info") << ss.str();
            lsb_terminate(lsb, err);
            return;
        } else {
            if (LUA_TNIL == lua_type(lua, 1)) {
                nomatch = true;
            }
        }
        lua_pop(lua, lua_gettop(lua)); // clear the stack
    }
    t = clock() - t;
    stringstream ss;
    Wt::WText* txt = new Wt::WText(mResult);
    if (nomatch) {
        txt->setStyleClass("result_error");
        ss << " *** MATCH FAILED ***<br/>";
    }
    ss << "Benchmark"
       << "<br/>samples: " << x
       << "<br/>seconds per match: " << (((float)t) / CLOCKS_PER_SEC / x)
       << "<br/>max memory (bytes): " << lsb_usage(lsb, LSB_UT_MEMORY, LSB_US_MAXIMUM)
       << "<br/>max Lua instructions: " << lsb_usage(lsb, LSB_UT_INSTRUCTION, LSB_US_MAXIMUM);
    txt->setText(ss.str());
    lsb_pcall_teardown(lsb);
}