Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 098 - Hide Create New button on Download page #101

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 31 additions & 11 deletions src/fileshelter/ui/FileShelterApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <Wt/WMenu.h>
#include <Wt/WTemplate.h>
#include <Wt/WText.h>
#include <Wt/WAnchor.h>
#include <Wt/WHBoxLayout.h>
andymarden marked this conversation as resolved.
Show resolved Hide resolved

#include "utils/IConfig.hpp"
#include "utils/Logger.hpp"
Expand Down Expand Up @@ -139,19 +141,19 @@ 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);
}
{
auto menuItem = menu->addItem(Wt::WString::tr("msg-tos"));
menuItem->setLink(Wt::WLink {Wt::LinkType::InternalPath, "/tos"});
menuItem->setSelectable(true);
}

menuItemShareCreate = menu->addItem(Wt::WString::tr("msg-share-create"));
menuItemShareCreate->setLink(Wt::WLink {Wt::LinkType::InternalPath, "/share-create"});
menuItemShareCreate->setSelectable(true);

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 @@ -168,6 +170,24 @@ FileShelterApplication::initialize()
});

handlePathChange(mainStack);

FS_LOG(UI, INFO) << "end init";
}

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
Expand Down
8 changes: 6 additions & 2 deletions src/fileshelter/ui/FileShelterApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace UserInterface
{
public:
FileShelterApplication(const Wt::WEnvironment& env);

void updateMenuVisibility();
andymarden marked this conversation as resolved.
Show resolved Hide resolved

static std::filesystem::path prepareUploadDirectory();
static FileShelterApplication* instance();
const std::filesystem::path& getWorkingDirectory() const { return _workingDirectory; }
Expand All @@ -46,7 +47,10 @@ namespace UserInterface
void notify(const Wt::WEvent& event) override;

void displayError(std::string_view error);


Wt::WMenuItem* menuItemShareCreate;
andymarden marked this conversation as resolved.
Show resolved Hide resolved
Wt::WMenuItem* menuItemTos;
andymarden marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
4 changes: 4 additions & 0 deletions src/fileshelter/ui/ShareCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ProgressBar.hpp"
#include "ShareCreateFormView.hpp"
#include "ShareCreatePassword.hpp"
#include "FileShelterApplication.hpp"
andymarden marked this conversation as resolved.
Show resolved Hide resolved

namespace UserInterface
{
Expand Down Expand Up @@ -71,6 +72,9 @@ namespace UserInterface

if (!wApp->internalPathMatches("/share-create"))
return;

auto app = dynamic_cast<FileShelterApplication*>(Wt::WApplication::instance());
app->updateMenuVisibility();

if (!_isPasswordVerified && PasswordUtils::isUploadPassordRequired())
displayPassword();
Expand Down
7 changes: 5 additions & 2 deletions src/fileshelter/ui/ShareCreated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "share/Types.hpp"

#include "ShareUtils.hpp"

#include "FileShelterApplication.hpp"
andymarden marked this conversation as resolved.
Show resolved Hide resolved

namespace UserInterface {

Expand All @@ -49,7 +49,10 @@ ShareCreated::handlePathChanged()

if (!wApp->internalPathMatches("/share-created"))
return;


auto app = dynamic_cast<FileShelterApplication*>(Wt::WApplication::instance());
app->updateMenuVisibility();

try
{
const Share::ShareEditUUID shareEditUUID {wApp->internalPathNextPart("/share-created/")};
Expand Down
8 changes: 6 additions & 2 deletions src/fileshelter/ui/ShareDownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Exception.hpp"
#include "ShareDownloadPassword.hpp"
#include "ShareUtils.hpp"
#include "FileShelterApplication.hpp"
andymarden marked this conversation as resolved.
Show resolved Hide resolved

namespace UserInterface {

Expand All @@ -53,8 +54,11 @@ ShareDownload::handlePathChanged()

if (!wApp->internalPathMatches("/share-download"))
return;

try

auto app = dynamic_cast<FileShelterApplication*>(Wt::WApplication::instance());
app->updateMenuVisibility();

andymarden marked this conversation as resolved.
Show resolved Hide resolved
try
{
const Share::ShareUUID shareUUID {wApp->internalPathNextPart("/share-download/")};

Expand Down
4 changes: 4 additions & 0 deletions src/fileshelter/ui/ShareEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "share/Types.hpp"

#include "ShareUtils.hpp"
#include "FileShelterApplication.hpp"
andymarden marked this conversation as resolved.
Show resolved Hide resolved

namespace UserInterface
{
Expand All @@ -53,6 +54,9 @@ namespace UserInterface

if (!wApp->internalPathMatches("/share-edit"))
return;

auto app = dynamic_cast<FileShelterApplication*>(Wt::WApplication::instance());
app->updateMenuVisibility();

try
{
Expand Down