Publish button in browser (replaces Unpublish button when unpublished saves are selected)
Works using the html page and isn't really the best way until @simtr implements Delete.json&Mode=Publish or something
This commit is contained in:
parent
1a50217acd
commit
b2954a7f0a
@ -1676,6 +1676,36 @@ failure:
|
|||||||
return RequestFailure;
|
return RequestFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestStatus Client::PublishSave(int saveID)
|
||||||
|
{
|
||||||
|
lastError = "";
|
||||||
|
std::stringstream urlStream;
|
||||||
|
int dataStatus;
|
||||||
|
urlStream << "http://" << SERVER << "/Browse/View.html?ID=" << saveID << "&Key=" << authUser.SessionKey;
|
||||||
|
if (authUser.ID)
|
||||||
|
{
|
||||||
|
std::stringstream userIDStream;
|
||||||
|
userIDStream << authUser.ID;
|
||||||
|
const char *const postNames[] = { "ActionPublish", NULL };
|
||||||
|
const char *const postDatas[] = { "" };
|
||||||
|
int postLengths[] = { 1 };
|
||||||
|
char *data = http_multipart_post(urlStream.str().c_str(), postNames, postDatas, postLengths, userIDStream.str().c_str(), NULL, authUser.SessionID.c_str(), &dataStatus, NULL);
|
||||||
|
if (data)
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastError = "Not authenticated";
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
if (dataStatus != 302)
|
||||||
|
{
|
||||||
|
lastError = http_ret_text(dataStatus);
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
return RequestOkay;
|
||||||
|
}
|
||||||
|
|
||||||
SaveInfo * Client::GetSave(int saveID, int saveDate)
|
SaveInfo * Client::GetSave(int saveID, int saveDate)
|
||||||
{
|
{
|
||||||
lastError = "";
|
lastError = "";
|
||||||
|
@ -157,6 +157,7 @@ public:
|
|||||||
RequestStatus DeleteSave(int saveID);
|
RequestStatus DeleteSave(int saveID);
|
||||||
RequestStatus ReportSave(int saveID, std::string message);
|
RequestStatus ReportSave(int saveID, std::string message);
|
||||||
RequestStatus UnpublishSave(int saveID);
|
RequestStatus UnpublishSave(int saveID);
|
||||||
|
RequestStatus PublishSave(int saveID);
|
||||||
RequestStatus FavouriteSave(int saveID, bool favourite);
|
RequestStatus FavouriteSave(int saveID, bool favourite);
|
||||||
void SetAuthUser(User user);
|
void SetAuthUser(User user);
|
||||||
User GetAuthUser();
|
User GetAuthUser();
|
||||||
|
@ -269,6 +269,8 @@ void SearchController::removeSelectedC()
|
|||||||
std::stringstream saveIDF;
|
std::stringstream saveIDF;
|
||||||
saveIDF << "\boFailed to delete [" << saves[i] << "] ...";
|
saveIDF << "\boFailed to delete [" << saves[i] << "] ...";
|
||||||
notifyStatus(saveIDF.str());
|
notifyStatus(saveIDF.str());
|
||||||
|
c->Refresh();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
notifyProgress((float(i+1)/float(saves.size())*100));
|
notifyProgress((float(i+1)/float(saves.size())*100));
|
||||||
}
|
}
|
||||||
@ -283,47 +285,73 @@ void SearchController::removeSelectedC()
|
|||||||
searchModel->UpdateSaveList(searchModel->GetPageNum(), searchModel->GetLastQuery());
|
searchModel->UpdateSaveList(searchModel->GetPageNum(), searchModel->GetLastQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::UnpublishSelected()
|
void SearchController::UnpublishSelected(bool publish)
|
||||||
{
|
{
|
||||||
class UnpublishSelectedConfirmation: public ConfirmDialogueCallback {
|
class UnpublishSelectedConfirmation: public ConfirmDialogueCallback {
|
||||||
public:
|
public:
|
||||||
SearchController * c;
|
SearchController * c;
|
||||||
UnpublishSelectedConfirmation(SearchController * c_) { c = c_; }
|
bool publish;
|
||||||
|
UnpublishSelectedConfirmation(SearchController * c_, bool publish_) { c = c_; publish = publish_; }
|
||||||
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
||||||
if (result == ConfirmPrompt::ResultOkay)
|
if (result == ConfirmPrompt::ResultOkay)
|
||||||
c->unpublishSelectedC();
|
c->unpublishSelectedC(publish);
|
||||||
}
|
}
|
||||||
virtual ~UnpublishSelectedConfirmation() { }
|
virtual ~UnpublishSelectedConfirmation() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::stringstream desc;
|
std::stringstream desc;
|
||||||
desc << "Are you sure you want to hide " << searchModel->GetSelected().size() << " save";
|
desc << "Are you sure you want to " << (publish ? "publish " : "unpublish ") << searchModel->GetSelected().size() << " save";
|
||||||
if(searchModel->GetSelected().size()>1)
|
if(searchModel->GetSelected().size()>1)
|
||||||
desc << "s";
|
desc << "s";
|
||||||
desc << "?";
|
desc << "?";
|
||||||
new ConfirmPrompt("Unpublish saves", desc.str(), new UnpublishSelectedConfirmation(this));
|
new ConfirmPrompt((publish ? "Publish Saves" : "Unpublish Saves"), desc.str(), new UnpublishSelectedConfirmation(this, publish));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::unpublishSelectedC()
|
void SearchController::unpublishSelectedC(bool publish)
|
||||||
{
|
{
|
||||||
class UnpublishSavesTask : public Task
|
class UnpublishSavesTask : public Task
|
||||||
{
|
{
|
||||||
std::vector<int> saves;
|
std::vector<int> saves;
|
||||||
SearchController *c;
|
SearchController *c;
|
||||||
|
bool publish;
|
||||||
public:
|
public:
|
||||||
UnpublishSavesTask(std::vector<int> saves_, SearchController *c_) { saves = saves_; c = c_; }
|
UnpublishSavesTask(std::vector<int> saves_, SearchController *c_, bool publish_) { saves = saves_; c = c_; publish = publish_; }
|
||||||
|
|
||||||
|
bool PublishSave(int saveID)
|
||||||
|
{
|
||||||
|
std::stringstream message;
|
||||||
|
message << "Publishing save [" << saveID << "]";
|
||||||
|
notifyStatus(message.str());
|
||||||
|
if (Client::Ref().PublishSave(saveID) != RequestOkay)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UnpublishSave(int saveID)
|
||||||
|
{
|
||||||
|
std::stringstream message;
|
||||||
|
message << "Unpublishing save [" << saveID << "]";
|
||||||
|
notifyStatus(message.str());
|
||||||
|
if (Client::Ref().UnpublishSave(saveID) != RequestOkay)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool doWork()
|
virtual bool doWork()
|
||||||
{
|
{
|
||||||
|
bool ret;
|
||||||
for(int i = 0; i < saves.size(); i++)
|
for(int i = 0; i < saves.size(); i++)
|
||||||
{
|
{
|
||||||
std::stringstream saveID;
|
if (publish)
|
||||||
saveID << "Hiding save [" << saves[i] << "]";
|
ret = PublishSave(saves[i]);
|
||||||
notifyStatus(saveID.str());
|
else
|
||||||
if(Client::Ref().UnpublishSave(saves[i])!=RequestOkay)
|
ret = UnpublishSave(saves[i]);
|
||||||
|
if (!ret)
|
||||||
{
|
{
|
||||||
std::stringstream saveIDF;
|
std::stringstream error;
|
||||||
saveIDF << "\boFailed to hide [" << saves[i] << "], is this save yours?";
|
error << "\boFailed to " << (publish ? "Publish" : "Unpublish") << " [" << saves[i] << "], is this save yours?";
|
||||||
notifyError(saveIDF.str());
|
notifyError(error.str());
|
||||||
|
c->Refresh();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
notifyProgress((float(i+1)/float(saves.size())*100));
|
notifyProgress((float(i+1)/float(saves.size())*100));
|
||||||
@ -334,7 +362,7 @@ void SearchController::unpublishSelectedC()
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<int> selected = searchModel->GetSelected();
|
std::vector<int> selected = searchModel->GetSelected();
|
||||||
new TaskWindow("Unpublishing saves", new UnpublishSavesTask(selected, this));
|
new TaskWindow((publish ? "Publishing Saves" : "Unpublishing Saves"), new UnpublishSavesTask(selected, this, publish));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::FavouriteSelected()
|
void SearchController::FavouriteSelected()
|
||||||
|
@ -24,7 +24,7 @@ private:
|
|||||||
bool instantOpen;
|
bool instantOpen;
|
||||||
bool doRefresh;
|
bool doRefresh;
|
||||||
void removeSelectedC();
|
void removeSelectedC();
|
||||||
void unpublishSelectedC();
|
void unpublishSelectedC(bool publish);
|
||||||
public:
|
public:
|
||||||
class OpenCallback;
|
class OpenCallback;
|
||||||
bool HasExited;
|
bool HasExited;
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
void Update();
|
void Update();
|
||||||
void ClearSelection();
|
void ClearSelection();
|
||||||
void RemoveSelected();
|
void RemoveSelected();
|
||||||
void UnpublishSelected();
|
void UnpublishSelected(bool publish);
|
||||||
void FavouriteSelected();
|
void FavouriteSelected();
|
||||||
void ReleaseLoadedSave();
|
void ReleaseLoadedSave();
|
||||||
SaveInfo * GetLoadedSave();
|
SaveInfo * GetLoadedSave();
|
||||||
|
@ -19,7 +19,8 @@ SearchView::SearchView():
|
|||||||
c(NULL),
|
c(NULL),
|
||||||
changed(true),
|
changed(true),
|
||||||
lastChanged(0),
|
lastChanged(0),
|
||||||
pageCount(0)
|
pageCount(0),
|
||||||
|
publishButtonShown(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
Client::Ref().AddListener(this);
|
Client::Ref().AddListener(this);
|
||||||
@ -202,7 +203,7 @@ SearchView::SearchView():
|
|||||||
UnpublishSelectedAction(SearchView * _v) { v = _v; }
|
UnpublishSelectedAction(SearchView * _v) { v = _v; }
|
||||||
void ActionCallback(ui::Button * sender)
|
void ActionCallback(ui::Button * sender)
|
||||||
{
|
{
|
||||||
v->c->UnpublishSelected();
|
v->c->UnpublishSelected(v->publishButtonShown);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -730,13 +731,18 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
|||||||
void SearchView::NotifySelectedChanged(SearchModel * sender)
|
void SearchView::NotifySelectedChanged(SearchModel * sender)
|
||||||
{
|
{
|
||||||
vector<int> selected = sender->GetSelected();
|
vector<int> selected = sender->GetSelected();
|
||||||
|
int published = 0;
|
||||||
for(int j = 0; j < saveButtons.size(); j++)
|
for(int j = 0; j < saveButtons.size(); j++)
|
||||||
{
|
{
|
||||||
saveButtons[j]->SetSelected(false);
|
saveButtons[j]->SetSelected(false);
|
||||||
for(int i = 0; i < selected.size(); i++)
|
for(int i = 0; i < selected.size(); i++)
|
||||||
{
|
{
|
||||||
if(saveButtons[j]->GetSave()->GetID() == selected[i])
|
if(saveButtons[j]->GetSave()->GetID() == selected[i])
|
||||||
|
{
|
||||||
saveButtons[j]->SetSelected(true);
|
saveButtons[j]->SetSelected(true);
|
||||||
|
if (saveButtons[j]->GetSave()->GetPublished())
|
||||||
|
published++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,13 +752,29 @@ void SearchView::NotifySelectedChanged(SearchModel * sender)
|
|||||||
unpublishSelected->Visible = true;
|
unpublishSelected->Visible = true;
|
||||||
favouriteSelected->Visible = true;
|
favouriteSelected->Visible = true;
|
||||||
clearSelection->Visible = true;
|
clearSelection->Visible = true;
|
||||||
|
pageTextbox->Visible = false;
|
||||||
|
pageLabel->Visible = false;
|
||||||
|
pageCountLabel->Visible = false;
|
||||||
|
if (published <= selected.size()/2)
|
||||||
|
{
|
||||||
|
unpublishSelected->SetText("Publish");
|
||||||
|
publishButtonShown = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
unpublishSelected->SetText("Unpublish");
|
||||||
|
publishButtonShown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (removeSelected->Visible)
|
||||||
{
|
{
|
||||||
removeSelected->Visible = false;
|
removeSelected->Visible = false;
|
||||||
unpublishSelected->Visible = false;
|
unpublishSelected->Visible = false;
|
||||||
favouriteSelected->Visible = false;
|
favouriteSelected->Visible = false;
|
||||||
clearSelection->Visible = false;
|
clearSelection->Visible = false;
|
||||||
|
pageTextbox->Visible = true;
|
||||||
|
pageLabel->Visible = true;
|
||||||
|
pageCountLabel->Visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ private:
|
|||||||
bool changed;
|
bool changed;
|
||||||
int lastChanged;
|
int lastChanged;
|
||||||
int pageCount;
|
int pageCount;
|
||||||
|
bool publishButtonShown;
|
||||||
public:
|
public:
|
||||||
void NotifyTagListChanged(SearchModel * sender);
|
void NotifyTagListChanged(SearchModel * sender);
|
||||||
void NotifySaveListChanged(SearchModel * sender);
|
void NotifySaveListChanged(SearchModel * sender);
|
||||||
|
Reference in New Issue
Block a user