Skip to content

Commit

Permalink
Issue 098 - Hide Create New button on Download page (#101)
Browse files Browse the repository at this point in the history
Remove create links from download page optionally, fixes #98
  • Loading branch information
andymarden authored Feb 5, 2024
1 parent a5a88ab commit 069fbc5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
3 changes: 3 additions & 0 deletions conf/fileshelter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ tos-org = "**[ORG]**";
tos-url = "**[DEPLOY URL]**/tos";
tos-support-email = "**[SUPPORT EMAIL ADDRESS]**";

# Set to false if you want to hide links to other Create application pages on the download page
show-create-links-on-download = true;

# Location for deployment
deploy-path = "/";

Expand Down
36 changes: 28 additions & 8 deletions src/fileshelter/ui/FileShelterApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ handlePathChange(Wt::WStackedWidget* stack)
{
if (wApp->internalPathMatches(index.first))
{
FsApp->updateMenuVisibility();

stack->setCurrentIndex(index.second);

return;
}
}
Expand Down Expand Up @@ -139,19 +142,20 @@ FileShelterApplication::initialize()
Wt::WTemplate* main {root()->addNew<Wt::WTemplate>(Wt::WString::tr("template-main"))};

Wt::WNavigationBar* navbar {main->bindNew<Wt::WNavigationBar>("navbar-top")};
navbar->setTitle("<i class=\"fa fa-external-link\"></i> " + Wt::WString::tr("msg-app-name"), Wt::WLink {Wt::LinkType::InternalPath, defaultPath});

navbar->setTitle(Wt::WString::tr("msg-app-name"));

Wt::WMenu* menu {navbar->addMenu(std::make_unique<Wt::WMenu>())};
{
auto menuItem = menu->addItem(Wt::WString::tr("msg-share-create"));
menuItem->setLink(Wt::WLink {Wt::LinkType::InternalPath, "/share-create"});
menuItem->setSelectable(true);
_menuItemShareCreate = menu->addItem(Wt::WString::tr("msg-share-create"));
_menuItemShareCreate->setLink(Wt::WLink {Wt::LinkType::InternalPath, "/share-create"});
_menuItemShareCreate->setSelectable(true);
}
{
auto menuItem = menu->addItem(Wt::WString::tr("msg-tos"));
menuItem->setLink(Wt::WLink {Wt::LinkType::InternalPath, "/tos"});
menuItem->setSelectable(true);
}
Wt::WMenuItem* menuItemTos = menu->addItem(Wt::WString::tr("msg-tos"));
menuItemTos->setLink(Wt::WLink {Wt::LinkType::InternalPath, "/tos"});
menuItemTos->setSelectable(true);
}
Wt::WContainerWidget* container {main->bindNew<Wt::WContainerWidget>("contents")};

// Same order as Idx enum
Expand All @@ -170,6 +174,22 @@ FileShelterApplication::initialize()
handlePathChange(mainStack);
}

void
FileShelterApplication::updateMenuVisibility()
{
if (!Service<IConfig>::get()->getBool("show-create-links-on-download", true))
{
if (wApp->internalPathMatches("/share-download"))
{
_menuItemShareCreate->hide();
}
else
{
_menuItemShareCreate->show();
}
}
}

void
FileShelterApplication::displayError(std::string_view error)
{
Expand Down
4 changes: 3 additions & 1 deletion src/fileshelter/ui/FileShelterApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace UserInterface
{
public:
FileShelterApplication(const Wt::WEnvironment& env);

void updateMenuVisibility();
static std::filesystem::path prepareUploadDirectory();
static FileShelterApplication* instance();
const std::filesystem::path& getWorkingDirectory() const { return _workingDirectory; }
Expand All @@ -47,6 +47,8 @@ namespace UserInterface

void displayError(std::string_view error);

Wt::WMenuItem* _menuItemShareCreate;

static inline std::filesystem::path _workingDirectory;
};

Expand Down
1 change: 0 additions & 1 deletion src/fileshelter/ui/ShareCreated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "ShareUtils.hpp"


namespace UserInterface {

ShareCreated::ShareCreated()
Expand Down

0 comments on commit 069fbc5

Please sign in to comment.