Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Purge button #592

Merged
merged 8 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
16 changes: 11 additions & 5 deletions js/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@
"helperWindowControls": "Maximize, Minimize & Close controls",
"helperSaveMetaData": "Store additional transaction information",
"helperDefaultFee": "Priority is recommended for the fastest transactions",
"helperServerManagement": "Switch and manage server connections",
"helperServerPeers": "Peers you're connected to",
"smtp": {
"sectionName": "Email Integration (SMTP)",
"testAction": "Test Integration",
Expand Down Expand Up @@ -365,9 +363,17 @@
"server": {
"sectionName": "Server",
"management": "Management",
"managementHelper": "Switch and manage server connections",
"managementBtn": "Connection Management",
"peers": "Peers",
"btnShowManagementAction": "Connection Management",
"btnShowPeersAction": "Show Connected Peers"
"peersHelper": "Peers you're connected to",
"peersBtn": "Show Connected Peers",
"purge": "Purge Shared Files",
"purgeHelper": "Delete cached files you are sharing with others",
"purgeBtn": "Purge Files",
"purgeToolTip": "OpenBazaar shares cached content you have viewed with other users. If you have viewed text or images you don't want to share this button will delete them. This will not affect any files that belong to you.",
"purgeError": "There was an error, your cached files may not have been deleted.",
"purgeComplete": "Your cached files have been deleted."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to check with @cpacia to know if 'ob/purgecache' returns after the purge is complete or if it just kicks off a purge, returns immediately, and the purge finished at some time. That's how the publish api works. If the purge API works the same way, I think we'd want to tweak the messaging since Your cached files have been deleted. wouldn't be completely accurate.

},
"transaction": {
"sectionName": "Transactions",
Expand Down Expand Up @@ -708,7 +714,7 @@
"body": "Once it's deleted, it's gone forever.",
"btnCancel": "Cancel",
"btnConfirm": "Yes, Delete"
}
}
},
"listingDelete": {
"deletingListing": "Deleting listing %{listing}…",
Expand Down
36 changes: 30 additions & 6 deletions js/templates/modals/settings/advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="flexHCent">
<h2 class="h3 clrT"><%= ob.polyT('settings.advancedTab.sectionName') %></h2>
<%= ob.processingButton({
className: 'btn clrP clrBr clrSh2 modalContentCornerBtn js-save',
className: `btn clrP clrBr clrSh2 modalContentCornerBtn js-save ${ob.isSaving ? 'processing' : ''}`,
btnText: ob.polyT('settings.btnSave')
}) %>
</div>
Expand Down Expand Up @@ -159,26 +159,50 @@ <h2 class="h4 clrT"><%= ob.polyT('settings.advancedTab.server.sectionName') %></
<label>
<%= ob.polyT('settings.advancedTab.server.management') %>
</label>
<div class="clrT2 txSm"><%= ob.polyT('settings.advancedTab.helperServerManagement') %></div>
<div class="clrT2 txSm"><%= ob.polyT('settings.advancedTab.server.managementHelper') %></div>
</div>
<div class="col9">
<a class="btn clrP clrBr clrSh2 js-showConnectionManagement flexNoShrink"><%= ob.polyT('settings.advancedTab.server.btnShowManagementAction') %></a>
<a class="btn clrP clrBr clrSh2 js-showConnectionManagement flexNoShrink"><%= ob.polyT('settings.advancedTab.server.managementBtn') %></a>
</div>
</div>
<div class="flexRow gutterH">
<div class="col3">
<label>
<%= ob.polyT('settings.advancedTab.server.peers') %>
</label>
<div class="clrT2 txSm"><%= ob.polyT('settings.advancedTab.helperServerPeers') %></div>
<div class="clrT2 txSm"><%= ob.polyT('settings.advancedTab.server.peersHelper') %></div>
</div>
<div class="col9">
<a href="#connected-peers"
class="btn clrP clrBr clrSh2 js-showConnectedPeers flexNoShrink">
<%= ob.polyT('settings.advancedTab.server.btnShowPeersAction') %>
<%= ob.polyT('settings.advancedTab.server.peersBtn') %>
</a>
</div>
</div>
<div class="flexRow gutterH">
<div class="col3">
<label>
<%= ob.polyT('settings.advancedTab.server.purge') %>
</label>
<div class="clrT2 txSm">
<%= ob.polyT('settings.advancedTab.server.purgeHelper') %>
<span class="toolTip toolTipTop" data-tip="<%= ob.polyT('settings.advancedTab.server.purgeToolTip') %>">
<i class="ion-help-circled"></i>
</span>
</div>
</div>
<div class="col9">
<div class="flexVCent gutterH">
<%= ob.processingButton({
className: `btn clrP clrBr clrSh2 js-purge ${ob.isPurging ? 'processing' : ''}`,
btnText: ob.polyT('settings.advancedTab.server.purgeBtn'),
}) %>
<div class="js-purgeComplete <% if (!ob.isComplete) print('hide') %>">
<i class="tx5 clrTEmph1"><%= ob.polyT('settings.advancedTab.server.purgeComplete') %></i>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
Expand Down Expand Up @@ -325,7 +349,7 @@ <h2 class="h4 clrT"><%= ob.polyT('settings.advancedTab.smtp.sectionName') %></h2
<div class="contentBox padMd clrP clrBr clrSh3">
<div class="flexHRight">
<%= ob.processingButton({
className: 'btn clrP clrBr clrSh2 js-save',
className: `btn clrP clrBr clrSh2 js-save ${ob.isSaving ? 'processing' : ''}`,
btnText: ob.polyT('settings.btnSave')
}) %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion js/templates/modals/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ <h1 class="h4 txUp clrT"><%= ob.polyT('settings.settingsLabel') %></h1>
<a class="js-tab tab row" data-tab="Page"><%= ob.polyT('settings.pageTab.sectionPage') %></a>
<a class="js-tab tab row" data-tab="Store"><%= ob.polyT('settings.storeTab.sectionName') %></a>
<a class="js-tab tab row" data-tab="Addresses"><%= ob.polyT('settings.addressesTab.sectionName') %></a>
<a class="js-tab tab row" data-tab="Advanced"><%= ob.polyT('settings.advancedTab.sectionName') %></a>
<a class="js-tab tab row" data-tab="Moderation"><%= ob.polyT('settings.moderationTab.sectionName') %></a>
<a class="js-tab tab row" data-tab="Advanced"><%= ob.polyT('settings.advancedTab.sectionName') %></a>
</div>
</div>
<div class="flexExpand posR">
Expand Down
52 changes: 44 additions & 8 deletions js/views/modals/Settings/Advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export default class extends baseVw {
constructor(options = {}) {
super({
className: 'settingsAdvanced',
initialState: {
isPurging: false,
isComplete: false,
isSaving: false,
...options.initialState,
},
...options,
});

Expand All @@ -30,6 +36,7 @@ export default class extends baseVw {
'click .js-smtpContainer input[type="reset"]': 'resetSMTPFields',
'click .js-save': 'save',
'click .js-showConnectionManagement': 'showConnectionManagement',
'click .js-purge': 'clickPurge',
};
}

Expand All @@ -47,6 +54,38 @@ export default class extends baseVw {
return super.getFormData(subset);
}

clickPurge() {
this.purgeCache();
}

/**
* Call to the server to remove cached files that are being shared on IPFS.
* This call should not be aborted when the view is removed, it's critical the user is informed if
* the call fails, even if they have navigated away from the view.
*/
purgeCache() {
this.getCachedEl('.js-purge').addClass('processing');
this.getCachedEl('.js-purgeComplete').addClass('hide');
this.setState({ isPurging: true, isComplete: false });

this.purge = $.post(app.getServerUrl('ob/purgecache'))
.always(() => {
this.getCachedEl('.js-purge').removeClass('processing');
this.setState({ isPurging: false });
})
.fail((xhr) => {
const failReason = xhr.responseJSON && xhr.responseJSON.reason || '';
openSimpleMessage(
app.polyglot.t('settings.advancedTab.server.purgeError'),
failReason);
})
.done(() => {
this.setState({ isComplete: true });
this.getCachedEl('.js-purgeComplete').removeClass('hide');
});
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the super.render().

At some point, I think I'll try and write a test that would check all views and ensure that if they are using getCachedEl, that they are calling super.render(). It's really easy to forget.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be a bad idea to pass isPurging: this.purge && this.purge.state() === 'pending' into the template and then use that in the template to decide whether the processing class should be applied to the button.

Otherwise, if you re-render during a purge (e.g. user clicks Save), then the spinner state is lost and the user might just kick off another purge.

save() {
this.localSettings.set(this.getFormData(this.$localFields));
this.localSettings.set({}, { validate: true });
Expand All @@ -71,6 +110,7 @@ export default class extends baseVw {
attrs: serverFormData,
type: 'PATCH',
});
this.setState({ isSaving: true });

$.when(localSave, serverSave)
.done(() => {
Expand All @@ -95,40 +135,36 @@ export default class extends baseVw {
});
})
.always(() => {
this.$btnSave.removeClass('processing');
this.getCachedEl('.js-save').removeClass('processing');
this.setState({ isSaving: false });
setTimeout(() => statusMessage.remove(), 3000);
});
}

this.render();
if (!this.localSettings.validationError && !this.settings.validationError) {
this.$btnSave.addClass('processing');
this.getCachedEl('.js-save').addClass('processing');
}

const $firstErr = this.$('.errorList:first');
if ($firstErr.length) $firstErr[0].scrollIntoViewIfNeeded();
}

get $btnSave() {
return this._$btnSave ||
(this._$btnSave = this.$('.js-save'));
}

render() {
loadTemplate('modals/settings/advanced.html', (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the super.render() if using getCachedEl.

this.$el.html(t({
errors: {
...(this.settings.validationError || {}),
...(this.localSettings.validationError || {}),
},
...this.getState(),
...this.settings.toJSON(),
...this.localSettings.toJSON(),
}));

this.$formFields = this.$('select[name], input[name], textarea[name]').
not('[data-persistence-location="local"]');
this.$localFields = this.$('[data-persistence-location="local"]');
this._$btnSave = null;
});

return this;
Expand Down