Make filters really work
This commit is contained in:
@@ -43,6 +43,10 @@ Artist::Artist(Filters* filters, Wt::WContainerWidget* parent)
|
||||
}));
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(std::bind([=] {
|
||||
refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -54,8 +54,11 @@ Artists::Artists(Filters* filters, Wt::WContainerWidget* parent)
|
||||
artists->bindWidget("artists", _artistsContainer);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
filters->updated().connect(std::bind([=] {
|
||||
refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
void
|
||||
Artists::refresh(std::vector<std::string> searchKeywords)
|
||||
|
||||
+109
-2
@@ -17,13 +17,116 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Wt/WTemplate>
|
||||
#include <Wt/WComboBox>
|
||||
#include <Wt/WDialog>
|
||||
#include <Wt/WPushButton>
|
||||
#include <Wt/WTemplate>
|
||||
|
||||
#include "Filters.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
void
|
||||
Filters::showDialog()
|
||||
{
|
||||
auto dialog = new Wt::WDialog("Go to cell");
|
||||
|
||||
auto container = new Wt::WTemplate(Wt::WString::tr("template-filter-add"));
|
||||
container->addFunction("tr", &Wt::WTemplate::Functions::tr);
|
||||
|
||||
dialog->contents()->addWidget(container);
|
||||
|
||||
auto typeCombo = new Wt::WComboBox();
|
||||
container->bindWidget("type", typeCombo);
|
||||
|
||||
auto valueCombo = new Wt::WComboBox();
|
||||
container->bindWidget("value", valueCombo);
|
||||
|
||||
auto addBtn = new Wt::WPushButton(Wt::WString::tr("msg-add"));
|
||||
container->bindWidget("add", addBtn);
|
||||
addBtn->clicked().connect(dialog, &Wt::WDialog::accept);
|
||||
|
||||
auto cancelBtn = new Wt::WPushButton(Wt::WString::tr("msg-cancel"));
|
||||
container->bindWidget("cancel", cancelBtn);
|
||||
cancelBtn->clicked().connect(dialog, &Wt::WDialog::reject);
|
||||
|
||||
// Populate data
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto types = Database::Cluster::getAllTypes(DboSession());
|
||||
|
||||
for (auto type : types)
|
||||
typeCombo->addItem(Wt::WString::fromUTF8(type));
|
||||
|
||||
if (!types.empty())
|
||||
{
|
||||
auto values = Database::Cluster::getByType(DboSession(), types.front());
|
||||
|
||||
for (auto value : values)
|
||||
{
|
||||
if (_filterIds.find(value.id()) == _filterIds.end())
|
||||
valueCombo->addItem(Wt::WString::fromUTF8(value->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
typeCombo->changed().connect(std::bind([=]
|
||||
{
|
||||
auto type = typeCombo->valueText().toUTF8();
|
||||
|
||||
valueCombo->clear();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto values = Database::Cluster::getByType(DboSession(), type);
|
||||
for (auto value : values)
|
||||
{
|
||||
if (_filterIds.find(value.id()) == _filterIds.end())
|
||||
valueCombo->addItem(Wt::WString::fromUTF8(value->getName()));
|
||||
}
|
||||
}));
|
||||
|
||||
dialog->setModal(true);
|
||||
dialog->setMovable(false);
|
||||
dialog->setResizable(false);
|
||||
dialog->setClosable(false);
|
||||
|
||||
dialog->finished().connect(std::bind([=]
|
||||
{
|
||||
if (dialog->result() != Wt::WDialog::Accepted)
|
||||
return;
|
||||
|
||||
auto type = typeCombo->valueText().toUTF8();
|
||||
auto value = valueCombo->valueText().toUTF8();
|
||||
|
||||
Wt::Dbo::Transaction transaction(DboSession());
|
||||
|
||||
auto cluster = Database::Cluster::get(DboSession(), type, value);
|
||||
if (!cluster)
|
||||
return;
|
||||
|
||||
auto clusterId = cluster.id();
|
||||
_filterIds.insert(clusterId);
|
||||
_sigUpdated.emit();
|
||||
|
||||
auto filterBtn = new Wt::WPushButton(Wt::WString::fromUTF8(value));
|
||||
_filters->addWidget(filterBtn);
|
||||
|
||||
filterBtn->clicked().connect(std::bind([=]
|
||||
{
|
||||
_filters->removeWidget(filterBtn);
|
||||
_filterIds.erase(clusterId);
|
||||
_sigUpdated.emit();
|
||||
}));
|
||||
}));
|
||||
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
Filters::Filters(Wt::WContainerWidget *parent)
|
||||
: Wt::WContainerWidget(parent)
|
||||
{
|
||||
@@ -36,7 +139,11 @@ Filters::Filters(Wt::WContainerWidget *parent)
|
||||
_filters = new Wt::WContainerWidget();
|
||||
container->bindWidget("filters", _filters);
|
||||
|
||||
// _filterIds = {108, 419};
|
||||
addFilterBtn->clicked().connect(std::bind([this]
|
||||
{
|
||||
showDialog();
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+8
-2
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WSignal>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
|
||||
@@ -32,12 +33,17 @@ class Filters : public Wt::WContainerWidget
|
||||
public:
|
||||
Filters(Wt::WContainerWidget *parent = 0);
|
||||
|
||||
std::vector<Database::Cluster::id_type> getClusterIds() const { return _filterIds; }
|
||||
std::set<Database::Cluster::id_type> getClusterIds() const { return _filterIds; }
|
||||
|
||||
Wt::Signal<void>& updated() { return _sigUpdated; }
|
||||
|
||||
private:
|
||||
|
||||
void showDialog();
|
||||
|
||||
Wt::WContainerWidget *_filters;
|
||||
std::vector<Database::Cluster::id_type> _filterIds;
|
||||
Wt::Signal<void> _sigUpdated;
|
||||
std::set<Database::Cluster::id_type> _filterIds;
|
||||
};
|
||||
|
||||
} // namespace UserInterface
|
||||
|
||||
@@ -56,6 +56,10 @@ Releases::Releases(Filters* filters, Wt::WContainerWidget* parent)
|
||||
releases->bindWidget("releases", _releasesContainer);
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(std::bind([=] {
|
||||
refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ Tracks::Tracks(Filters* filters, Wt::WContainerWidget* parent)
|
||||
tracks->bindWidget("tracks", _tracksContainer);
|
||||
|
||||
refresh();
|
||||
|
||||
filters->updated().connect(std::bind([=] {
|
||||
refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user