First version of the Users view (read only)
This commit is contained in:
@@ -27,11 +27,11 @@
|
||||
#include "common/Validators.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "AdminWizardView.hpp"
|
||||
#include "InitWizardView.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class AdminWizardModel : public Wt::WFormModel
|
||||
class InitWizardModel : public Wt::WFormModel
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -40,7 +40,7 @@ class AdminWizardModel : public Wt::WFormModel
|
||||
static const Field PasswordField;
|
||||
static const Field PasswordConfirmField;
|
||||
|
||||
AdminWizardModel(Wt::WObject *parent = 0)
|
||||
InitWizardModel(Wt::WObject *parent = 0)
|
||||
: Wt::WFormModel(parent)
|
||||
{
|
||||
addField(AdminLoginField);
|
||||
@@ -112,31 +112,31 @@ class AdminWizardModel : public Wt::WFormModel
|
||||
|
||||
};
|
||||
|
||||
const Wt::WFormModel::Field AdminWizardModel::AdminLoginField = "admin-login";
|
||||
const Wt::WFormModel::Field AdminWizardModel::PasswordField = "password";
|
||||
const Wt::WFormModel::Field AdminWizardModel::PasswordConfirmField = "password-confirm";
|
||||
const Wt::WFormModel::Field InitWizardModel::AdminLoginField = "admin-login";
|
||||
const Wt::WFormModel::Field InitWizardModel::PasswordField = "password";
|
||||
const Wt::WFormModel::Field InitWizardModel::PasswordConfirmField = "password-confirm";
|
||||
|
||||
AdminWizardView::AdminWizardView(Wt::WContainerWidget *parent)
|
||||
InitWizardView::InitWizardView(Wt::WContainerWidget *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("id", &WTemplate::Functions::id);
|
||||
|
||||
// AdminLogin
|
||||
Wt::WLineEdit* accountEdit = new Wt::WLineEdit();
|
||||
setFormWidget(AdminWizardModel::AdminLoginField, accountEdit);
|
||||
setFormWidget(InitWizardModel::AdminLoginField, accountEdit);
|
||||
|
||||
// Password
|
||||
Wt::WLineEdit* passwordEdit = new Wt::WLineEdit();
|
||||
setFormWidget(AdminWizardModel::PasswordField, passwordEdit );
|
||||
setFormWidget(InitWizardModel::PasswordField, passwordEdit );
|
||||
passwordEdit->setEchoMode(Wt::WLineEdit::Password);
|
||||
|
||||
// Password confirmation
|
||||
Wt::WLineEdit* passwordConfirmEdit = new Wt::WLineEdit();
|
||||
setFormWidget(AdminWizardModel::PasswordConfirmField, passwordConfirmEdit);
|
||||
setFormWidget(InitWizardModel::PasswordConfirmField, passwordConfirmEdit);
|
||||
passwordConfirmEdit->setEchoMode(Wt::WLineEdit::Password);
|
||||
|
||||
auto saveButton = new Wt::WPushButton(Wt::WString::tr("Lms.create"));
|
||||
@@ -148,7 +148,7 @@ AdminWizardView::AdminWizardView(Wt::WContainerWidget *parent)
|
||||
if (model->validate())
|
||||
{
|
||||
model->saveData();
|
||||
LmsApp->notify(Wt::WString::tr("Lms.AdminWizard.done"));
|
||||
LmsApp->notify(Wt::WString::tr("Lms.Admin.InitWizard.done"));
|
||||
saveButton->setEnabled(false);
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class AdminWizardView : public Wt::WTemplateFormView
|
||||
class InitWizardView : public Wt::WTemplateFormView
|
||||
{
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user