Commits

Boris Nagaev committed 82c5617

add draft of team widgets

  • Participants
  • Parent commits 08eabb8

Comments (0)

Files changed (7)

File src/widgets/global.hpp

 class RightsEdit;
 class SettingsWidget;
 class StagedCompetitionGraph;
+class TeamListWidget;
+class TeamEdit;
+class TeamWidget;
 class UserListWidget;
 class UserWidget;
 class VirtualsWidget;

File src/widgets/team/TeamEdit.cpp

+/*
+ * thechess, chess game web application written in C++ and based on Wt
+ * Copyright (C) 2010 Boris Nagaev
+ *
+ * See the LICENSE file for terms of use.
+ */
+
+#include <Wt/WText>
+#include <Wt/WPushButton>
+
+#include "widgets/team/TeamEdit.hpp"
+#include "Application.hpp"
+#include "log.hpp"
+
+namespace thechess {
+
+TeamEdit::TeamEdit(const TeamPtr& team) {
+    dbo::Transaction t(tApp->session());
+    // TODO check that this user can edit
+    add_record_inputs(team.get(), this);
+    Wt::WPushButton* save = new Wt::WPushButton(tr("tc.common.Save"));
+    item("", "", save);
+    save->clicked().connect(this, &TeamEdit::save);
+}
+
+void TeamEdit::save() {
+    dbo::Transaction t(tApp->session());
+    write_record(team_.modify());
+    t.commit();
+    // TODO open team page
+    // TODO emit team event
+}
+
+}
+

File src/widgets/team/TeamEdit.hpp

+/*
+ * thechess, chess game web application written in C++ and based on Wt
+ * Copyright (C) 2010 Boris Nagaev
+ *
+ * See the LICENSE file for terms of use.
+ */
+
+#ifndef THECHESS_WIDGETS_TEAM_EDIT_HPP_
+#define THECHESS_WIDGETS_TEAM_EDIT_HPP_
+
+#include <Wt/WGlobal>
+#include <Wt/Wc/global.hpp>
+#include <Wt/Wc/TableForm.hpp>
+
+#include "widgets/RecordWidgetBase.hpp"
+#include "model/all.hpp"
+
+namespace thechess {
+
+/** Widget editing team instance.
+Current user must be team leader or moderator.
+*/
+class TeamEdit : public Wt::Wc::TableForm, RecordWidgetBase {
+public:
+    /** Constructor */
+    TeamEdit(const TeamPtr& team);
+
+private:
+    TeamPtr team_;
+
+    void save();
+};
+
+}
+
+#endif
+

File src/widgets/team/TeamList.cpp

+/*
+ * thechess, chess game web application written in C++ and based on Wt
+ * Copyright (C) 2010 Boris Nagaev
+ *
+ * See the LICENSE file for terms of use.
+ */
+
+#include <boost/bind.hpp>
+
+#include <Wt/WTableView>
+#include <Wt/Dbo/QueryModel>
+#include <Wt/Wc/Pager.hpp>
+
+#include "widgets/team/TeamList.hpp"
+#include "model/all.hpp"
+
+namespace thechess {
+
+namespace TLP {
+typedef TeamPtr Result;
+typedef dbo::Query<Result> Q;
+typedef dbo::QueryModel<Result> BaseQM;
+}
+
+class TeamListModel : public TLP::BaseQM {
+public:
+    enum {
+        ID_COL,
+        NAME_COL,
+        DESCRIPTION_COL
+    };
+
+    TeamListModel(Wt::WObject* parent = 0) :
+        TLP::BaseQM(parent) {
+        set_query();
+        addColumn("id", tr("tc.common.number"));
+        addColumn("name", tr("tc.common.Name"));
+        addColumn("description", tr("tc.common.Description"));
+    }
+
+private:
+    void set_query() {
+        dbo::Transaction t(tApp->session());
+        TLP::Q q;
+        q = tApp->session().query<TeamPtr>("select * from thechess_team");
+        setQuery(q, /* keep_columns */ true);
+    }
+
+    boost::any data(const Wt::WModelIndex& index,
+                    int role = Wt::DisplayRole) const {
+        dbo::Transaction t(tApp->session());
+        const TeamPtr& o = resultRow(index.row());
+        if (role == Wt::LinkRole) {
+            if (index.column() == ID_COL) {
+                // TODO
+            }
+        }
+        t.commit();
+        return TLP::BaseQM::data(index, role);
+    }
+
+    static Wt::WString tr(const char* key) {
+        return Wt::WString::tr(key);
+    }
+};
+
+class TeamListView : public Wt::WTableView {
+public:
+    TeamListView(TeamListModel* model, Wt::WContainerWidget* p = 0):
+        Wt::WTableView(p) {
+        setModel(model);
+        resize(770, 450);
+        setColumnWidth(TeamListModel::ID_COL, 40);
+        setColumnWidth(TeamListModel::NAME_COL, 170);
+        setColumnWidth(TeamListModel::DESCRIPTION_COL, 770 - 40 - 170);
+        setSelectable(true);
+    }
+
+protected:
+    WWidget* createPageNavigationBar() {
+        return new Wt::Wc::Pager(this);
+    }
+};
+
+TeamList::TeamList() {
+    TeamListModel* m = new TeamListModel(this);
+    TeamListView* view = new TeamListView(m, this);
+    // TODO team creation button
+}
+
+}
+

File src/widgets/team/TeamList.hpp

+/*
+ * thechess, chess game web application written in C++ and based on Wt
+ * Copyright (C) 2010 Boris Nagaev
+ *
+ * See the LICENSE file for terms of use.
+ */
+
+#ifndef THECHESS_WIDGETS_TEAM_LIST_WIDGET_HPP_
+#define THECHESS_WIDGETS_TEAM_LIST_WIDGET_HPP_
+
+#include <Wt/WGlobal>
+#include <Wt/WContainerWidget>
+
+namespace thechess {
+
+/** List of teams */
+class TeamList : public Wt::WContainerWidget {
+public:
+    /** Constructor */
+    TeamList();
+};
+
+}
+
+#endif
+

File src/widgets/team/TeamWidget.cpp

+/*
+ * thechess, chess game web application written in C++ and based on Wt
+ * Copyright (C) 2010 Boris Nagaev
+ *
+ * See the LICENSE file for terms of use.
+ */
+
+#include "widgets/team/TeamWidget.hpp"
+
+namespace thechess {
+
+TeamWidget::TeamWidget(const TeamPtr& team):
+    Notifiable(Object(TEAM_OBJECT, team.id())),
+    team_(team) {
+    dbo::Transaction t(tApp->session());
+    reprint();
+}
+
+void TeamWidget::notify(EventPtr) {
+    dbo::Transaction t(tApp->session());
+    team_.reread();
+    reprint();
+}
+
+void TeamWidget::reprint() {
+    // TODO
+}
+
+}
+

File src/widgets/team/TeamWidget.hpp

+/*
+ * thechess, chess game web application written in C++ and based on Wt
+ * Copyright (C) 2010 Boris Nagaev
+ *
+ * See the LICENSE file for terms of use.
+ */
+
+#ifndef THECHESS_WIDGETS_TEAM_WIDGET_HPP_
+#define THECHESS_WIDGETS_TEAM_WIDGET_HPP_
+
+#include <Wt/WContainerWidget>
+
+#include "model/all.hpp"
+
+namespace thechess {
+
+class TeamWidget : public Wt::WContainerWidget, public Notifiable {
+public:
+    TeamWidget(const TeamPtr& team);
+
+    void notify(EventPtr);
+
+private:
+    TeamPtr team_;
+
+    void reprint();
+};
+
+}
+
+#endif
+