Refactor newly-added ClearDataView in settings_view.js

This commit is contained in:
Scott Nonnenberg 2018-03-08 10:00:20 -08:00 committed by Scott Nonnenberg
parent ef041b29d0
commit 256b87aa7a
No known key found for this signature in database
GPG key ID: 5F82280C35134661
2 changed files with 72 additions and 59 deletions

View file

@ -23,6 +23,7 @@ test/views/*.js
!js/views/debug_log_view.js
!js/views/file_input_view.js
!js/views/inbox_view.js
!js/views/settings_view.js
!js/database.js
!main.js
!prepare_build.js

View file

@ -1,10 +1,15 @@
/*
* vim: ts=4:sw=4:expandtab
*/
/* global storage: false */
/* global textsecure: false */
/* global i18n: false */
/* global Whisper: false */
/* eslint-disable */
(function () {
'use strict';
window.Whisper = window.Whisper || {};
const { OS } = window.Signal;
const { Database } = window.Whisper;
const { OS, Logs } = window.Signal;
const { Settings } = window.Signal.Types;
var CheckboxView = Whisper.View.extend({
@ -119,63 +124,70 @@
},
});
var CLEAR_DATA_STEPS = {
CHOICE: 1,
DELETING: 2,
};
var ClearDataView = Whisper.View.extend({
templateName: 'clear-data',
className: 'full-screen-flow overlay',
events: {
'click .cancel': 'onCancel',
'click .delete-all-data': 'onDeleteAllData',
},
initialize: function() {
this.step = CLEAR_DATA_STEPS.CHOICE;
},
onCancel: function() {
this.remove();
},
onDeleteAllData: function() {
console.log('Deleting everything!');
this.step = CLEAR_DATA_STEPS.DELETING;
this.render();
/* jshint ignore:start */
/* eslint-enable */
Whisper.Database.close().then(function() {
console.log('All database connections closed. Starting delete.');
this.clearAllData();
}.bind(this), function(error) {
console.log('Something went wrong closing all database connections.');
this.clearAllData();
}.bind(this));
},
clearAllData: function() {
Promise.all([
Signal.Logs.deleteAll(),
Whisper.Database.drop(),
]).then(function() {
window.restart();
}, function(error) {
console.log(
'Something went wrong deleting all data:',
error && error.stack ? error.stack : error
);
window.restart();
});
},
render_attributes: function() {
return {
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
header: i18n('deleteAllDataHeader'),
body: i18n('deleteAllDataBody'),
cancelButton: i18n('cancel'),
deleteButton: i18n('deleteAllDataButton'),
const CLEAR_DATA_STEPS = {
CHOICE: 1,
DELETING: 2,
};
const ClearDataView = Whisper.View.extend({
templateName: 'clear-data',
className: 'full-screen-flow overlay',
events: {
'click .cancel': 'onCancel',
'click .delete-all-data': 'onDeleteAllData',
},
initialize() {
this.step = CLEAR_DATA_STEPS.CHOICE;
},
onCancel() {
this.remove();
},
async onDeleteAllData() {
console.log('Deleting everything!');
this.step = CLEAR_DATA_STEPS.DELETING;
this.render();
isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
deleting: i18n('deleteAllDataProgress'),
};
}
});
try {
await Database.close();
console.log('All database connections closed. Starting delete.');
} catch (error) {
console.log('Something went wrong closing all database connections.');
}
this.clearAllData();
},
async clearAllData() {
try {
await Promise.all([
Logs.deleteAll(),
Database.drop(),
]);
} catch (error) {
console.log(
'Something went wrong deleting all data:',
error && error.stack ? error.stack : error
);
}
window.restart();
},
render_attributes() {
return {
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
header: i18n('deleteAllDataHeader'),
body: i18n('deleteAllDataBody'),
cancelButton: i18n('cancel'),
deleteButton: i18n('deleteAllDataButton'),
isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
deleting: i18n('deleteAllDataProgress'),
};
},
});
/* eslint-disable */
/* jshint ignore:end */
var SyncView = Whisper.View.extend({
templateName: 'syncSettings',