Use bootstrap notify to notify messages

This commit is contained in:
emeric
2018-08-29 15:10:00 +02:00
parent dbe0b81e43
commit 512ae5a0d6
11 changed files with 473 additions and 14 deletions
+29 -5
View File
@@ -110,7 +110,9 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
messageResourceBundle().use(appRoot() + "templates");
// Require js here to avoid async problems
requireJQuery("/js/jquery-1.10.2.min.js");
require("/js/mediaplayer.js");
require("/js/bootstrap-notify.js");
setTitle("LMS");
@@ -459,7 +461,7 @@ LmsApplication::createHome()
if (_isAdmin)
{
notifyMsg(Wt::WString::tr("Lms.Admin.Database.scan-complete")
notifyMsg(MsgType::Info, Wt::WString::tr("Lms.Admin.Database.scan-complete")
.arg(static_cast<unsigned>(stats.nbFiles()))
.arg(static_cast<unsigned>(stats.additions))
.arg(static_cast<unsigned>(stats.updates))
@@ -518,11 +520,33 @@ LmsApplication::notify(const Wt::WEvent& event)
}
}
void
LmsApplication::notifyMsg(const Wt::WString& message)
static std::string msgTypeToString(MsgType type)
{
LMS_LOG(UI, INFO) << "Notifying message '" << message.toUTF8() << "'";
root()->addNew<Wt::WText>(message);
switch(type)
{
case MsgType::Success: return "success";
case MsgType::Info: return "info";
case MsgType::Warning: return "warning";
case MsgType::Danger: return "danger";
}
return "";
}
void
LmsApplication::notifyMsg(MsgType type, const Wt::WString& message)
{
LMS_LOG(UI, INFO) << "Notifying message '" << message.toUTF8() << "' of type '" << msgTypeToString(type);
std::ostringstream oss;
oss << "$.notify({"
"message: '" << message.toUTF8() << "'"
"},{"
"type: '" << msgTypeToString(type) << "',"
"placement: {from: 'top', align: 'center'}"
"});";
LmsApp->doJavaScript(oss.str());
}
+10 -1
View File
@@ -44,6 +44,14 @@ struct GroupEvents
Wt::Signal<LmsApplicationInfo> appClosed;
};
enum class MsgType
{
Success,
Info,
Warning,
Danger,
};
class LmsApplication : public Wt::WApplication
{
public:
@@ -70,7 +78,8 @@ class LmsApplication : public Wt::WApplication
// Utils
void goHome();
void goHomeAndQuit();
void notifyMsg(const Wt::WString& message);
void notifyMsg(MsgType type, const Wt::WString& message);
static Wt::WLink createArtistLink(Database::Artist::pointer artist);
static std::unique_ptr<Wt::WAnchor> createArtistAnchor(Database::Artist::pointer artist, bool addText = true);
+2 -2
View File
@@ -236,7 +236,7 @@ void
PlayQueue::addTracks(const std::vector<Database::Track::pointer>& tracks)
{
enqueueTracks(tracks);
LmsApp->notifyMsg(Wt::WString::tr("Lms.PlayQueue.nb-tracks-added").arg(tracks.size()));
LmsApp->notifyMsg(MsgType::Info, Wt::WString::tr("Lms.PlayQueue.nb-tracks-added").arg(tracks.size()));
}
void
@@ -248,7 +248,7 @@ PlayQueue::playTracks(const std::vector<Database::Track::pointer>& tracks)
enqueueTracks(tracks);
play(0);
LmsApp->notifyMsg(Wt::WString::tr("Lms.PlayQueue.nb-tracks-playing").arg(tracks.size()));
LmsApp->notifyMsg(MsgType::Info, Wt::WString::tr("Lms.PlayQueue.nb-tracks-playing").arg(tracks.size()));
}
+2 -2
View File
@@ -301,7 +301,7 @@ SettingsView::refreshView()
if (LmsApp->getUser()->isDemo())
{
LmsApp->notifyMsg(Wt::WString::tr("Lms.Settings.demo-cannot-save"));
LmsApp->notifyMsg(MsgType::Warning, Wt::WString::tr("Lms.Settings.demo-cannot-save"));
return;
}
}
@@ -311,7 +311,7 @@ SettingsView::refreshView()
if (model->validate())
{
model->saveData();
LmsApp->notifyMsg(Wt::WString::tr("Lms.Settings.settings-saved"));
LmsApp->notifyMsg(MsgType::Success, Wt::WString::tr("Lms.Settings.settings-saved"));
}
// Udate the view: Delete any validation message in the view, etc.
+2 -2
View File
@@ -288,7 +288,7 @@ DatabaseSettingsView::refreshView()
model->saveData();
LmsApp->getMediaScanner().reschedule();
LmsApp->notifyMsg(Wt::WString::tr("Lms.Admin.Database.settings-saved"));
LmsApp->notifyMsg(MsgType::Success, Wt::WString::tr("Lms.Admin.Database.settings-saved"));
}
// Udate the view: Delete any validation message in the view, etc.
@@ -305,7 +305,7 @@ DatabaseSettingsView::refreshView()
immScanBtn->clicked().connect(std::bind([=] ()
{
LmsApp->getMediaScanner().scheduleImmediateScan();
LmsApp->notifyMsg(Wt::WString::tr("Lms.Admin.Database.scan-launched"));
LmsApp->notifyMsg(MsgType::Info, Wt::WString::tr("Lms.Admin.Database.scan-launched"));
}));
t->updateView(model.get());
+1 -1
View File
@@ -140,7 +140,7 @@ InitWizardView::InitWizardView()
if (model->validate())
{
model->saveData();
LmsApp->notifyMsg(Wt::WString::tr("Lms.Admin.InitWizard.done"));
LmsApp->notifyMsg(MsgType::Success, Wt::WString::tr("Lms.Admin.InitWizard.done"));
saveButton->setEnabled(false);
}
+1 -1
View File
@@ -306,7 +306,7 @@ UserView::refreshView()
if (model->validate())
{
model->saveData();
LmsApp->notifyMsg(Wt::WString::tr(userId ? "Lms.Admin.User.user-updated" : "Lms.Admin.User.user-created"));
LmsApp->notifyMsg(MsgType::Success, Wt::WString::tr(userId ? "Lms.Admin.User.user-updated" : "Lms.Admin.User.user-created"));
LmsApp->setInternalPath("/admin/users", true);
}
else