-
Notifications
You must be signed in to change notification settings - Fork 187
Purge button #592
Purge button #592
Changes from 6 commits
68126dd
ed80b70
2358e6a
6fb3649
466d729
279db7a
7b20f3d
2917583
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ export default class extends baseVw { | |
constructor(options = {}) { | ||
super({ | ||
className: 'settingsAdvanced', | ||
initialState: { | ||
isPurging: false, | ||
isComplete: false, | ||
isSaving: false, | ||
...options.initialState, | ||
}, | ||
...options, | ||
}); | ||
|
||
|
@@ -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', | ||
}; | ||
} | ||
|
||
|
@@ -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'); | ||
}); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might not be a bad idea to pass 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 }); | ||
|
@@ -71,6 +110,7 @@ export default class extends baseVw { | |
attrs: serverFormData, | ||
type: 'PATCH', | ||
}); | ||
this.setState({ isSaving: true }); | ||
|
||
$.when(localSave, serverSave) | ||
.done(() => { | ||
|
@@ -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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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.