WIP. Added the user table view
This commit is contained in:
+3
-2
@@ -65,8 +65,9 @@ lms_SOURCES = \
|
||||
$(top_srcdir)/ui/video/VideoDatabaseWidget.cpp \
|
||||
$(top_srcdir)/ui/video/VideoMediaPlayerWidget.cpp \
|
||||
$(top_srcdir)/ui/video/VideoParametersDialog.cpp \
|
||||
$(top_srcdir)/ui/settings/Settings.cpp \
|
||||
$(top_srcdir)/ui/settings/SettingsDatabaseFormView.cpp
|
||||
$(top_srcdir)/ui/settings/Settings.cpp \
|
||||
$(top_srcdir)/ui/settings/SettingsDatabaseFormView.cpp \
|
||||
$(top_srcdir)/ui/settings/SettingsUsers.cpp
|
||||
|
||||
|
||||
lms_CXXFLAGS=-std=c++11 -Wall -I$(top_srcdir)/boost/ -I$(top_srcdir)/ui -I$(top_srcdir)/remote
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
- Add path to Audio/Video files
|
||||
- Do not make the update start time active when update perdiod is "Never"
|
||||
- Do not restart the db update service if user applied no changes
|
||||
- Uncheck the "Request immediate scan" once setins are applied
|
||||
- [user/transcoding]
|
||||
- Prefered bitrate and codecs for audio/video
|
||||
- [user/Personal]
|
||||
|
||||
@@ -14,6 +14,12 @@ _videoBitrate(defaultVideoBitrate)
|
||||
|
||||
}
|
||||
|
||||
std::vector<User::pointer>
|
||||
User::getAll(Wt::Dbo::Session& session)
|
||||
{
|
||||
Wt::Dbo::collection<pointer> res = session.find<User>();
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ class User {
|
||||
|
||||
typedef Wt::Dbo::ptr<User> pointer;
|
||||
|
||||
// accessors
|
||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
||||
|
||||
bool isAdmin() const {return _isAdmin;}
|
||||
|
||||
template<class Action>
|
||||
|
||||
@@ -57,7 +57,6 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, boost::filesystem::p
|
||||
void
|
||||
LmsApplication::handleAuthEvent(void)
|
||||
{
|
||||
_sessionData.getDatabaseHandler().getLogin().changed().connect(this, &LmsApplication::handleAuthEvent);
|
||||
if (_sessionData.getDatabaseHandler().getLogin().loggedIn())
|
||||
{
|
||||
if (_home == nullptr) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <Wt/WTextArea>
|
||||
|
||||
#include "SettingsDatabaseFormView.hpp"
|
||||
#include "SettingsUsers.hpp"
|
||||
|
||||
#include "Settings.hpp"
|
||||
|
||||
@@ -31,7 +32,7 @@ _sessionData(sessionData)
|
||||
{
|
||||
// TODO Special admin settings
|
||||
menu->addItem("Database", new DatabaseFormView(sessionData));
|
||||
menu->addItem("Users", new Wt::WTextArea("Users here!"));
|
||||
menu->addItem("Users", new Users(sessionData));
|
||||
}
|
||||
|
||||
// User specifics settings
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
|
||||
#include <Wt/WGroupBox>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WPushButton>
|
||||
#include <Wt/WMessageBox>
|
||||
|
||||
#include <Wt/Auth/Identity>
|
||||
|
||||
#include "SettingsUsers.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
Users::Users(SessionData& sessionData, Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent),
|
||||
_sessionData(sessionData)
|
||||
{
|
||||
|
||||
Wt::WGroupBox *container = new Wt::WGroupBox("Users", this);
|
||||
|
||||
_table = new Wt::WTable(container);
|
||||
|
||||
_table->addStyleClass("table form-inline");
|
||||
|
||||
_table->toggleStyleClass("table-hover", true);
|
||||
_table->toggleStyleClass("table-striped", true);
|
||||
|
||||
_table->setHeaderCount(1);
|
||||
|
||||
_table->elementAt(0, 0)->addWidget(new Wt::WText("#"));
|
||||
_table->elementAt(0, 1)->addWidget(new Wt::WText("Name"));
|
||||
_table->elementAt(0, 2)->addWidget(new Wt::WText("e-Mail"));
|
||||
_table->elementAt(0, 3)->addWidget(new Wt::WText("Admin"));
|
||||
|
||||
Database::Handler& db = sessionData.getDatabaseHandler();
|
||||
|
||||
Wt::Dbo::Transaction transaction(db.getSession());
|
||||
|
||||
std::vector<Database::User::pointer> users = Database::User::getAll(db.getSession());
|
||||
|
||||
for (std::size_t i = 0; i < users.size(); ++i)
|
||||
{
|
||||
|
||||
std::string userId;
|
||||
{
|
||||
std::ostringstream oss; oss << users[i].id();
|
||||
userId = oss.str();
|
||||
}
|
||||
|
||||
Wt::Auth::User authUser = db.getUserDatabase().findWithId( userId );
|
||||
|
||||
_table->elementAt(i + 1, 0)->addWidget(new Wt::WText( Wt::WString::fromUTF8("{1}").arg(i+1)));
|
||||
_table->elementAt(i + 1, 1)->addWidget(new Wt::WText( authUser.identity(Wt::Auth::Identity::LoginName)) );
|
||||
|
||||
Wt::WText* email = new Wt::WText();
|
||||
if (!authUser.email().empty()) {
|
||||
email->setText(authUser.email());
|
||||
}
|
||||
else {
|
||||
email->setStyleClass("alert-danger");
|
||||
email->setText(authUser.unverifiedEmail());
|
||||
}
|
||||
|
||||
_table->elementAt(i + 1, 2)->addWidget( email ) ;
|
||||
|
||||
_table->elementAt(i + 1, 3)->addWidget(new Wt::WText( users[i]->isAdmin() ? "Yes" : "No" ));
|
||||
|
||||
Wt::WPushButton* editBtn = new Wt::WPushButton("Edit");
|
||||
_table->elementAt(i + 1, 4)->addWidget(editBtn);
|
||||
|
||||
Wt::WPushButton* delBtn = new Wt::WPushButton("Delete");
|
||||
delBtn->setStyleClass("btn-danger");
|
||||
delBtn->setMargin(5, Wt::Left);
|
||||
|
||||
delBtn->clicked().connect(boost::bind( &Users::handleDelUser, this, authUser.identity(Wt::Auth::Identity::LoginName), userId));
|
||||
|
||||
_table->elementAt(i + 1, 4)->addWidget(delBtn);
|
||||
}
|
||||
|
||||
Wt::WPushButton* addBtn = new Wt::WPushButton("Add User");
|
||||
addBtn->setStyleClass("btn-success");
|
||||
|
||||
addWidget( addBtn );
|
||||
}
|
||||
|
||||
void
|
||||
Users::handleDelUser(Wt::WString loginNameIdentity, std::string id)
|
||||
{
|
||||
Wt::WMessageBox *messageBox = new Wt::WMessageBox
|
||||
("Delete User",
|
||||
Wt::WString( "Deleting user '{1}'?").arg(loginNameIdentity),
|
||||
Wt::Question, Wt::Yes | Wt::No);
|
||||
|
||||
messageBox->setModal(false);
|
||||
|
||||
messageBox->buttonClicked().connect(std::bind([=] () {
|
||||
if (messageBox->buttonResult() == Wt::Yes)
|
||||
{
|
||||
Database::Handler& db = _sessionData.getDatabaseHandler();
|
||||
|
||||
// Delete the user
|
||||
Wt::Auth::User authUser = db.getUserDatabase().findWithId( id );
|
||||
|
||||
db.getUserDatabase().deleteUser( authUser );
|
||||
|
||||
// TODO remove Database::User too?
|
||||
|
||||
// TODO Update the view
|
||||
}
|
||||
|
||||
delete messageBox;
|
||||
}));
|
||||
|
||||
messageBox->show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace UserInterface
|
||||
} // namespace Settings
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef UI_SETTINGS_USERS_HPP
|
||||
#define UI_SETTINGS_USERS_HPP
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WTable>
|
||||
|
||||
#include "common/SessionData.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
namespace Settings {
|
||||
|
||||
class Users : public Wt::WContainerWidget
|
||||
{
|
||||
public:
|
||||
Users(SessionData& sessioNData, Wt::WContainerWidget *parent = 0);
|
||||
|
||||
private:
|
||||
|
||||
void handleDelUser(Wt::WString loginNameIdentity, std::string id);
|
||||
|
||||
SessionData& _sessionData;
|
||||
|
||||
Wt::WTable* _table;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
} // namespace Settings
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user