First version of the Users view (read only)
This commit is contained in:
+2
-1
@@ -22,7 +22,8 @@ lms_js_DATA = \
|
|||||||
|
|
||||||
lms_approot_DATA = \
|
lms_approot_DATA = \
|
||||||
approot/admin-database.xml \
|
approot/admin-database.xml \
|
||||||
approot/admin-wizard.xml \
|
approot/admin-users.xml \
|
||||||
|
approot/admin-initwizard.xml \
|
||||||
approot/artist.xml \
|
approot/artist.xml \
|
||||||
approot/artists.xml \
|
approot/artists.xml \
|
||||||
approot/explore.xml \
|
approot/explore.xml \
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<messages xmlns:if="Wt.WTemplate.conditions">
|
<messages xmlns:if="Wt.WTemplate.conditions">
|
||||||
<!--FORMS message blocks-->
|
<!--FORMS message blocks-->
|
||||||
|
|
||||||
<message id="Lms.AdminWizard.template">
|
<message id="Lms.Admin.InitWizard.template">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h2>${tr:Lms.AdminWizard.header}</h2>
|
<h2>${tr:Lms.AdminWizard.header}</h2>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<messages xmlns:if="Wt.WTemplate.conditions">
|
||||||
|
|
||||||
|
<message id="Lms.Admin.Users.template">
|
||||||
|
<div class="page-header">
|
||||||
|
<h2>${tr:Lms.Admin.Users.users}</h2>
|
||||||
|
</div>
|
||||||
|
${users class="list-group"}
|
||||||
|
${add-btn class="btn-primary"}
|
||||||
|
</message>
|
||||||
|
|
||||||
|
<message id="Lms.Admin.Users.template.entry">
|
||||||
|
<div class="list-group-item">
|
||||||
|
${name} ${<if-edit>}${edit-btn} ${del-btn class="btn-danger"}${</if-edit>}
|
||||||
|
</div>
|
||||||
|
</message>
|
||||||
|
|
||||||
|
</messages>
|
||||||
@@ -30,10 +30,15 @@
|
|||||||
<message id="Lms.Admin.Database.update-start-time">Update start time</message>
|
<message id="Lms.Admin.Database.update-start-time">Update start time</message>
|
||||||
<message id="Lms.Admin.Database.weekly">Weekly</message>
|
<message id="Lms.Admin.Database.weekly">Weekly</message>
|
||||||
|
|
||||||
|
<!--Users-->
|
||||||
|
<message id="Lms.Admin.Users.add">New user</message>
|
||||||
|
<message id="Lms.Admin.Users.del">Delete</message>
|
||||||
|
<message id="Lms.Admin.Users.edit">Edit</message>
|
||||||
|
<message id="Lms.Admin.Users.users">Users</message>
|
||||||
|
|
||||||
<!--Admin Wizard-->
|
<!--Wizard-->
|
||||||
<message id="Lms.AdminWizard.done">Administration account created. Please refresh to continue!</message>
|
<message id="Lms.Admin.InitWizard.done">Administration account created. Please refresh to continue!</message>
|
||||||
<message id="Lms.AdminWizard.header">Create administrator account</message>
|
<message id="Lms.Admin.InitWizard.header">Create administrator account</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
<message id="Lms.Auth.remember-me">Remember me</message>
|
<message id="Lms.Auth.remember-me">Remember me</message>
|
||||||
|
|||||||
+2
-1
@@ -28,7 +28,8 @@ lms_SOURCES = \
|
|||||||
$(srcdir)/ui/PlayQueueView.cpp \
|
$(srcdir)/ui/PlayQueueView.cpp \
|
||||||
$(srcdir)/ui/SettingsView.cpp \
|
$(srcdir)/ui/SettingsView.cpp \
|
||||||
$(srcdir)/ui/admin/DatabaseSettingsView.cpp \
|
$(srcdir)/ui/admin/DatabaseSettingsView.cpp \
|
||||||
$(srcdir)/ui/admin/AdminWizardView.cpp \
|
$(srcdir)/ui/admin/InitWizardView.cpp \
|
||||||
|
$(srcdir)/ui/admin/UsersView.cpp \
|
||||||
$(srcdir)/ui/common/InputRange.cpp \
|
$(srcdir)/ui/common/InputRange.cpp \
|
||||||
$(srcdir)/ui/common/LineEdit.cpp \
|
$(srcdir)/ui/common/LineEdit.cpp \
|
||||||
$(srcdir)/ui/common/Validators.cpp \
|
$(srcdir)/ui/common/Validators.cpp \
|
||||||
|
|||||||
@@ -60,13 +60,6 @@ User::getById(Wt::Dbo::Session& session, id_type id)
|
|||||||
return session.find<User>().where("id = ?").bind( id );
|
return session.find<User>().where("id = ?").bind( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
|
||||||
User::getId( pointer user)
|
|
||||||
{
|
|
||||||
std::ostringstream oss; oss << user.id();
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
User::setAudioBitrate(std::size_t bitrate)
|
User::setAudioBitrate(std::size_t bitrate)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ class User
|
|||||||
// accessors
|
// accessors
|
||||||
static pointer getById(Wt::Dbo::Session& session, id_type id);
|
static pointer getById(Wt::Dbo::Session& session, id_type id);
|
||||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
||||||
static std::string getId(pointer user);
|
|
||||||
|
|
||||||
// write
|
// write
|
||||||
void setAdmin(bool admin) { _isAdmin = admin; }
|
void setAdmin(bool admin) { _isAdmin = admin; }
|
||||||
|
|||||||
+55
-32
@@ -37,8 +37,9 @@
|
|||||||
#include "PlayQueueView.hpp"
|
#include "PlayQueueView.hpp"
|
||||||
#include "SettingsView.hpp"
|
#include "SettingsView.hpp"
|
||||||
|
|
||||||
|
#include "admin/InitWizardView.hpp"
|
||||||
#include "admin/DatabaseSettingsView.hpp"
|
#include "admin/DatabaseSettingsView.hpp"
|
||||||
#include "admin/AdminWizardView.hpp"
|
#include "admin/UsersView.hpp"
|
||||||
|
|
||||||
#include "resource/ImageResource.hpp"
|
#include "resource/ImageResource.hpp"
|
||||||
#include "resource/TranscodeResource.hpp"
|
#include "resource/TranscodeResource.hpp"
|
||||||
@@ -86,6 +87,7 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
|
|||||||
|
|
||||||
// Add a resource bundle
|
// Add a resource bundle
|
||||||
messageResourceBundle().use(appRoot() + "admin-database");
|
messageResourceBundle().use(appRoot() + "admin-database");
|
||||||
|
messageResourceBundle().use(appRoot() + "admin-users");
|
||||||
messageResourceBundle().use(appRoot() + "admin-wizard");
|
messageResourceBundle().use(appRoot() + "admin-wizard");
|
||||||
messageResourceBundle().use(appRoot() + "artist");
|
messageResourceBundle().use(appRoot() + "artist");
|
||||||
messageResourceBundle().use(appRoot() + "artists");
|
messageResourceBundle().use(appRoot() + "artists");
|
||||||
@@ -115,7 +117,7 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
|
|||||||
|
|
||||||
if (firstConnection)
|
if (firstConnection)
|
||||||
{
|
{
|
||||||
root()->addWidget(new AdminWizardView());
|
root()->addWidget(new InitWizardView());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -208,31 +210,41 @@ enum IdxRoot
|
|||||||
IdxPlayQueue,
|
IdxPlayQueue,
|
||||||
IdxSettings,
|
IdxSettings,
|
||||||
IdxAdminDatabase,
|
IdxAdminDatabase,
|
||||||
|
IdxAdminUsers,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handlePathChange(Wt::WStackedWidget* stack)
|
handlePathChange(Wt::WStackedWidget* stack, bool isAdmin)
|
||||||
{
|
{
|
||||||
static const std::map<std::string, int> indexes =
|
static const struct
|
||||||
{
|
{
|
||||||
{ "/home", IdxHome },
|
std::string path;
|
||||||
{ "/artists", IdxExplore },
|
int index;
|
||||||
{ "/artist", IdxExplore },
|
bool admin;
|
||||||
{ "/releases", IdxExplore },
|
} views[] =
|
||||||
{ "/release", IdxExplore },
|
{
|
||||||
{ "/tracks", IdxExplore },
|
{ "/home", IdxHome, false },
|
||||||
{ "/playqueue", IdxPlayQueue },
|
{ "/artists", IdxExplore, false },
|
||||||
{ "/settings", IdxSettings },
|
{ "/artist", IdxExplore, false },
|
||||||
{ "/admin/database", IdxAdminDatabase },
|
{ "/releases", IdxExplore, false },
|
||||||
|
{ "/release", IdxExplore, false },
|
||||||
|
{ "/tracks", IdxExplore, false },
|
||||||
|
{ "/playqueue", IdxPlayQueue, false },
|
||||||
|
{ "/settings", IdxSettings, false },
|
||||||
|
{ "/admin/database", IdxAdminDatabase, true },
|
||||||
|
{ "/admin/users", IdxAdminUsers, true },
|
||||||
};
|
};
|
||||||
|
|
||||||
LMS_LOG(UI, DEBUG) << "Internal path changed to '" << wApp->internalPath() << "'";
|
LMS_LOG(UI, DEBUG) << "Internal path changed to '" << wApp->internalPath() << "'";
|
||||||
|
|
||||||
for (auto index : indexes)
|
for (auto& view : views)
|
||||||
{
|
{
|
||||||
if (wApp->internalPathMatches(index.first))
|
if (wApp->internalPathMatches(view.path))
|
||||||
{
|
{
|
||||||
stack->setCurrentIndex(index.second);
|
if (view.admin && !isAdmin)
|
||||||
|
break;
|
||||||
|
|
||||||
|
stack->setCurrentIndex(view.index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,6 +265,11 @@ LmsApplication::handleAuthEvent(void)
|
|||||||
|
|
||||||
LMS_LOG(UI, INFO) << "User '" << CurrentAuthUser().identity(Wt::Auth::Identity::LoginName) << "' logged in from '" << Wt::WApplication::instance()->environment().clientAddress() << "', user agent = " << Wt::WApplication::instance()->environment().agent() << ", session = " << Wt::WApplication::instance()->sessionId();
|
LMS_LOG(UI, INFO) << "User '" << CurrentAuthUser().identity(Wt::Auth::Identity::LoginName) << "' logged in from '" << Wt::WApplication::instance()->environment().clientAddress() << "', user agent = " << Wt::WApplication::instance()->environment().agent() << ", session = " << Wt::WApplication::instance()->sessionId();
|
||||||
|
|
||||||
|
{
|
||||||
|
Wt::Dbo::Transaction transaction (DboSession());
|
||||||
|
_isAdmin = CurrentUser()->isAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
require("/js/mediaplayer.js");
|
require("/js/mediaplayer.js");
|
||||||
|
|
||||||
_imageResource = new ImageResource(_db, root());
|
_imageResource = new ImageResource(_db, root());
|
||||||
@@ -295,21 +312,21 @@ LmsApplication::handleAuthEvent(void)
|
|||||||
auto rightMenu = new Wt::WMenu();
|
auto rightMenu = new Wt::WMenu();
|
||||||
std::size_t itemCounter = 0;
|
std::size_t itemCounter = 0;
|
||||||
|
|
||||||
|
if (_isAdmin)
|
||||||
{
|
{
|
||||||
Wt::Dbo::Transaction transaction (DboSession());
|
auto menuItem = rightMenu->insertItem(itemCounter++, Wt::WString::tr("Lms.administration"));
|
||||||
|
menuItem->setSelectable(false);
|
||||||
|
|
||||||
if (CurrentUser()->isAdmin())
|
Wt::WPopupMenu *admin = new Wt::WPopupMenu();
|
||||||
{
|
auto dbSettings = admin->insertItem(0, Wt::WString::tr("Lms.Admin.Database.database"));
|
||||||
auto menuItem = rightMenu->insertItem(itemCounter++, Wt::WString::tr("Lms.administration"));
|
dbSettings->setLink(Wt::WLink(Wt::WLink::InternalPath, "/admin/database"));
|
||||||
menuItem->setSelectable(false);
|
dbSettings->setSelectable(false);
|
||||||
|
|
||||||
Wt::WPopupMenu *admin = new Wt::WPopupMenu();
|
auto usersSettings = admin->insertItem(1, Wt::WString::tr("Lms.Admin.Users.users"));
|
||||||
auto dbSettings = admin->insertItem(0, Wt::WString::tr("Lms.Admin.Database.database"));
|
usersSettings->setLink(Wt::WLink(Wt::WLink::InternalPath, "/admin/users"));
|
||||||
dbSettings->setLink(Wt::WLink(Wt::WLink::InternalPath, "/admin/database"));
|
usersSettings->setSelectable(false);
|
||||||
dbSettings->setSelectable(false);
|
|
||||||
|
|
||||||
menuItem->setMenu(admin);
|
menuItem->setMenu(admin);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -344,8 +361,14 @@ LmsApplication::handleAuthEvent(void)
|
|||||||
mainStack->addWidget(settings);
|
mainStack->addWidget(settings);
|
||||||
|
|
||||||
// Admin stuff
|
// Admin stuff
|
||||||
auto databaseSettings = new DatabaseSettingsView();
|
if (_isAdmin)
|
||||||
mainStack->addWidget(databaseSettings);
|
{
|
||||||
|
auto databaseSettings = new DatabaseSettingsView();
|
||||||
|
mainStack->addWidget(databaseSettings);
|
||||||
|
|
||||||
|
auto users = new UsersView();
|
||||||
|
mainStack->addWidget(users);
|
||||||
|
}
|
||||||
|
|
||||||
explore->tracksAdd.connect(std::bind([=] (std::vector<Database::Track::pointer> tracks)
|
explore->tracksAdd.connect(std::bind([=] (std::vector<Database::Track::pointer> tracks)
|
||||||
{
|
{
|
||||||
@@ -380,7 +403,7 @@ LmsApplication::handleAuthEvent(void)
|
|||||||
playqueue->playbackStop.connect(player, &MediaPlayer::stop);
|
playqueue->playbackStop.connect(player, &MediaPlayer::stop);
|
||||||
|
|
||||||
// Events from MediaScanner
|
// Events from MediaScanner
|
||||||
if (CurrentUser()->isAdmin())
|
if (_isAdmin)
|
||||||
{
|
{
|
||||||
enableUpdates(true);
|
enableUpdates(true);
|
||||||
std::string sessionId = this->sessionId();
|
std::string sessionId = this->sessionId();
|
||||||
@@ -401,10 +424,10 @@ LmsApplication::handleAuthEvent(void)
|
|||||||
|
|
||||||
internalPathChanged().connect(std::bind([=]
|
internalPathChanged().connect(std::bind([=]
|
||||||
{
|
{
|
||||||
handlePathChange(mainStack);
|
handlePathChange(mainStack, _isAdmin);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
handlePathChange(mainStack);
|
handlePathChange(mainStack, _isAdmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class LmsApplication : public Wt::WApplication
|
|||||||
Scanner::MediaScanner& _scanner;
|
Scanner::MediaScanner& _scanner;
|
||||||
ImageResource* _imageResource;
|
ImageResource* _imageResource;
|
||||||
TranscodeResource* _transcodeResource;
|
TranscodeResource* _transcodeResource;
|
||||||
|
bool _isAdmin = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helpers to get session data
|
// Helpers to get session data
|
||||||
|
|||||||
@@ -27,11 +27,11 @@
|
|||||||
#include "common/Validators.hpp"
|
#include "common/Validators.hpp"
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
#include "AdminWizardView.hpp"
|
#include "InitWizardView.hpp"
|
||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|
||||||
class AdminWizardModel : public Wt::WFormModel
|
class InitWizardModel : public Wt::WFormModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class AdminWizardModel : public Wt::WFormModel
|
|||||||
static const Field PasswordField;
|
static const Field PasswordField;
|
||||||
static const Field PasswordConfirmField;
|
static const Field PasswordConfirmField;
|
||||||
|
|
||||||
AdminWizardModel(Wt::WObject *parent = 0)
|
InitWizardModel(Wt::WObject *parent = 0)
|
||||||
: Wt::WFormModel(parent)
|
: Wt::WFormModel(parent)
|
||||||
{
|
{
|
||||||
addField(AdminLoginField);
|
addField(AdminLoginField);
|
||||||
@@ -112,31 +112,31 @@ class AdminWizardModel : public Wt::WFormModel
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Wt::WFormModel::Field AdminWizardModel::AdminLoginField = "admin-login";
|
const Wt::WFormModel::Field InitWizardModel::AdminLoginField = "admin-login";
|
||||||
const Wt::WFormModel::Field AdminWizardModel::PasswordField = "password";
|
const Wt::WFormModel::Field InitWizardModel::PasswordField = "password";
|
||||||
const Wt::WFormModel::Field AdminWizardModel::PasswordConfirmField = "password-confirm";
|
const Wt::WFormModel::Field InitWizardModel::PasswordConfirmField = "password-confirm";
|
||||||
|
|
||||||
AdminWizardView::AdminWizardView(Wt::WContainerWidget *parent)
|
InitWizardView::InitWizardView(Wt::WContainerWidget *parent)
|
||||||
: Wt::WTemplateFormView(parent)
|
: Wt::WTemplateFormView(parent)
|
||||||
{
|
{
|
||||||
auto model = new AdminWizardModel(this);
|
auto model = new InitWizardModel(this);
|
||||||
|
|
||||||
setTemplateText(Wt::WString::tr("Lms.AdminWizard.template"));
|
setTemplateText(Wt::WString::tr("Lms.Admin.InitWizard.template"));
|
||||||
addFunction("tr", &WTemplate::Functions::tr);
|
addFunction("tr", &WTemplate::Functions::tr);
|
||||||
addFunction("id", &WTemplate::Functions::id);
|
addFunction("id", &WTemplate::Functions::id);
|
||||||
|
|
||||||
// AdminLogin
|
// AdminLogin
|
||||||
Wt::WLineEdit* accountEdit = new Wt::WLineEdit();
|
Wt::WLineEdit* accountEdit = new Wt::WLineEdit();
|
||||||
setFormWidget(AdminWizardModel::AdminLoginField, accountEdit);
|
setFormWidget(InitWizardModel::AdminLoginField, accountEdit);
|
||||||
|
|
||||||
// Password
|
// Password
|
||||||
Wt::WLineEdit* passwordEdit = new Wt::WLineEdit();
|
Wt::WLineEdit* passwordEdit = new Wt::WLineEdit();
|
||||||
setFormWidget(AdminWizardModel::PasswordField, passwordEdit );
|
setFormWidget(InitWizardModel::PasswordField, passwordEdit );
|
||||||
passwordEdit->setEchoMode(Wt::WLineEdit::Password);
|
passwordEdit->setEchoMode(Wt::WLineEdit::Password);
|
||||||
|
|
||||||
// Password confirmation
|
// Password confirmation
|
||||||
Wt::WLineEdit* passwordConfirmEdit = new Wt::WLineEdit();
|
Wt::WLineEdit* passwordConfirmEdit = new Wt::WLineEdit();
|
||||||
setFormWidget(AdminWizardModel::PasswordConfirmField, passwordConfirmEdit);
|
setFormWidget(InitWizardModel::PasswordConfirmField, passwordConfirmEdit);
|
||||||
passwordConfirmEdit->setEchoMode(Wt::WLineEdit::Password);
|
passwordConfirmEdit->setEchoMode(Wt::WLineEdit::Password);
|
||||||
|
|
||||||
auto saveButton = new Wt::WPushButton(Wt::WString::tr("Lms.create"));
|
auto saveButton = new Wt::WPushButton(Wt::WString::tr("Lms.create"));
|
||||||
@@ -148,7 +148,7 @@ AdminWizardView::AdminWizardView(Wt::WContainerWidget *parent)
|
|||||||
if (model->validate())
|
if (model->validate())
|
||||||
{
|
{
|
||||||
model->saveData();
|
model->saveData();
|
||||||
LmsApp->notify(Wt::WString::tr("Lms.AdminWizard.done"));
|
LmsApp->notify(Wt::WString::tr("Lms.Admin.InitWizard.done"));
|
||||||
saveButton->setEnabled(false);
|
saveButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,10 +24,10 @@
|
|||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|
||||||
class AdminWizardView : public Wt::WTemplateFormView
|
class InitWizardView : public Wt::WTemplateFormView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AdminWizardView(Wt::WContainerWidget *parent = 0);
|
InitWizardView(Wt::WContainerWidget *parent = 0);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Emeric Poupon
|
||||||
|
*
|
||||||
|
* This file is part of LMS.
|
||||||
|
*
|
||||||
|
* LMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Wt/WTemplate>
|
||||||
|
#include <Wt/WPushButton>
|
||||||
|
|
||||||
|
#include "database/Types.hpp"
|
||||||
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
|
#include "LmsApplication.hpp"
|
||||||
|
#include "UsersView.hpp"
|
||||||
|
|
||||||
|
namespace UserInterface {
|
||||||
|
|
||||||
|
UsersView::UsersView(Wt::WContainerWidget *parent)
|
||||||
|
: Wt::WContainerWidget(parent)
|
||||||
|
{
|
||||||
|
LMS_LOG(UI, DEBUG) << "TEST";
|
||||||
|
auto t = new Wt::WTemplate(Wt::WString::tr("Lms.Admin.Users.template"), this);
|
||||||
|
t->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||||
|
|
||||||
|
_container = new Wt::WContainerWidget();
|
||||||
|
t->bindWidget("users", _container);
|
||||||
|
|
||||||
|
auto addBtn = new Wt::WPushButton(Wt::WString::tr("Lms.Admin.Users.add"));
|
||||||
|
t->bindWidget("add-btn", addBtn);
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UsersView::refresh()
|
||||||
|
{
|
||||||
|
_container->clear();
|
||||||
|
|
||||||
|
Wt::Dbo::Transaction transaction(DboSession());
|
||||||
|
|
||||||
|
auto users = Database::User::getAll(DboSession());
|
||||||
|
for (auto user : users)
|
||||||
|
{
|
||||||
|
auto entry = new Wt::WTemplate(Wt::WString::tr("Lms.Admin.Users.template.entry"), _container);
|
||||||
|
|
||||||
|
Wt::Auth::User authUser = DbHandler().getUserDatabase().findWithId(std::to_string(user.id()));
|
||||||
|
|
||||||
|
if (!authUser.isValid()) {
|
||||||
|
LMS_LOG(UI, ERROR) << "Skipping invalid userId = " << user.id();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->bindString("name", authUser.identity(Wt::Auth::Identity::LoginName), Wt::PlainText);
|
||||||
|
|
||||||
|
// Don't edit ourself this way
|
||||||
|
if (CurrentUser() != user)
|
||||||
|
{
|
||||||
|
entry->setCondition("if-edit", true);
|
||||||
|
auto editBtn = new Wt::WPushButton(Wt::WString::tr("Lms.Admin.Users.edit"));
|
||||||
|
entry->bindWidget("edit-btn", editBtn);
|
||||||
|
|
||||||
|
auto delBtn = new Wt::WPushButton(Wt::WString::tr("Lms.Admin.Users.del"));
|
||||||
|
entry->bindWidget("del-btn", delBtn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace UserInterface
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Emeric Poupon
|
||||||
|
*
|
||||||
|
* This file is part of LMS.
|
||||||
|
*
|
||||||
|
* LMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Wt/WContainerWidget>
|
||||||
|
|
||||||
|
namespace UserInterface {
|
||||||
|
|
||||||
|
class UsersView : public Wt::WContainerWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UsersView(Wt::WContainerWidget *parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void refresh();
|
||||||
|
|
||||||
|
Wt::WContainerWidget* _container;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace UserInterface
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ Artists::addSome()
|
|||||||
|
|
||||||
for (auto artist : artists)
|
for (auto artist : artists)
|
||||||
{
|
{
|
||||||
Wt::WTemplate* entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artists.template.entry"), _artistsContainer);
|
auto entry = new Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artists.template.entry"), _artistsContainer);
|
||||||
|
|
||||||
entry->bindInt("nb-release", artist->getReleases(clusterIds).size());
|
entry->bindInt("nb-release", artist->getReleases(clusterIds).size());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user