CommentsContainerWidget::CommentsContainerWidget(string videoId, Session* session, WContainerWidget* parent)
  : WContainerWidget(parent), d(videoId, session)
{
  string querysql = "select content,last_updated,\
      auth_info.email as email,\
    auth_identity.identity as identity\
    from comment\
    inner join auth_info on comment.user_id = auth_info.user_id\
    inner join auth_identity on auth_info.id = auth_identity.auth_info_id\
  ";
  wApp->log("notice") << "comments query: " << querysql;
  auto query = d->session->query<CommentTuple>(querysql);
  query.where("media_id = ?").bind(videoId);
  query.where("auth_identity.provider = 'loginname'");
  query.orderBy("last_updated DESC");
  addWidget(WW<WText>(wtr("comments.label")).css("label").setInline(false));
  
  WTextArea* newCommentContent = new WTextArea();
  newCommentContent->setRows(3);
  newCommentContent->setInline(false);
  WPushButton* insertComment = WW<WPushButton>(wtr("comments.addcomment.button")).css("btn btn-primary btn-sm").onClick([=](WMouseEvent){
    if(newCommentContent->text().empty())
      return;
    Comment *comment = new Comment(videoId, d->session->user(), newCommentContent->text().toUTF8());
    Dbo::Transaction t(*d->session);
    Dbo::ptr< Comment > newComment = d->session->add(comment);
    t.commit();
    newCommentContent->setText("");
    commentViewers.commentAdded(videoId, newComment.id());
  });
  newCommentContent->keyWentUp().connect([=](WKeyEvent){
    insertComment->setEnabled(!newCommentContent->text().empty());
  });
  insertComment->setEnabled(false);
  
//     newCommentContent->setWidth(500);
  newCommentContent->addStyleClass("col-md-8");

  addWidget(WW<WContainerWidget>().css("add-comment-box row").add(newCommentContent).add(insertComment).setContentAlignment(AlignCenter));
  
  addWidget(d->commentsContainer = WW<WContainerWidget>().css("container") );

  Dbo::Transaction t(*d->session);
  for(CommentTuple comment : query.resultList())
    d->commentsContainer->addWidget(new CommentView(comment) );
  
  auto commentAdded = [=] (string commentVideoId, long commentId) {
    if(commentVideoId != videoId) return;
    Dbo::Transaction t(*d->session);
    auto query = d->session->query<CommentTuple>(querysql).where("comment.id = ?").bind(commentId);
    query.where("auth_identity.provider = 'loginname'");
    d->commentsContainer->insertWidget(0, new CommentView(query.resultValue()));
    d->commentsContainer->refresh();
    wApp->triggerUpdate();
  };
  
  commentViewers.addClient(wApp->sessionId(), commentAdded);
}
Esempio n. 2
0
void HelloApplication::completion_cb(std::string txt)
{
//	HelloApplication* inst = (HelloApplication*)WApplication::instance();

    output_->setText(txt);
    triggerUpdate();
    enableUpdates(false);

    ga_thread->join();
    ga_thread.reset();
}
Esempio n. 3
0
void HelloApplication::generation_cb(WStandardItemModel* obs_model, std::string txt)
{
    observations_table->setModel(obs_model);

    output_->setText(txt);

    dbo::QueryModel< dbo::ptr< evo_period > >* period_mod = (dbo::QueryModel< dbo::ptr< evo_period > >*)period_table->model();
    period_mod->reload();
    dbo::QueryModel< dbo::ptr< generation > >* generation_mod = (dbo::QueryModel< dbo::ptr< generation > >*)generation_table->model();
    generation_mod->reload();

    triggerUpdate();
}
Esempio n. 4
0
WWidget *FormWidgets::wTextArea()
{
  WContainerWidget *result = new WContainerWidget();

  topic("WTextArea", result);
  addText(tr("formwidgets-WTextArea"), result);

  WTextArea *ta = new WTextArea(result);
  ta->setColumns(80);
  ta->setRows(15);
  ta->setText(tr("formwidgets-WTextArea-contents"));
  ed_->showSignal(ta->changed(), "Text area changed");
 
  addText(tr("formwidgets-WTextArea-related"), result);

  return result;
}
Esempio n. 5
0
void WebGLDemo::resetShaders()
{
  fragmentShaderText_->setText(fragmentShaderSrc);
  vertexShaderText_->setText(vertexShaderSrc);
  updateShaders();
}