1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 18:32:20 -05:00

Restructure architecture into angular modules and services

This commit is contained in:
Tankred Hase 2014-11-19 15:23:10 +01:00
parent 95ad15b0dd
commit c221372ed4
14 changed files with 59 additions and 16 deletions

View File

@ -78,9 +78,6 @@ ctrl.start = function(options, callback) {
ctrl.buildModules = function() {
var lawnchairDao, restDao, pubkeyDao, privkeyDao, crypto, emailDao, keychain, pgp, userStorage, pgpbuilder, oauth, appConfigStore, auth;
// start the mailreader's worker thread
mailreader.startWorker(config.workerPath + '/mailreader-parser-worker.min.js');
// init objects and inject dependencies
restDao = new RestDAO();
lawnchairDao = new LawnchairDAO();
@ -91,6 +88,8 @@ ctrl.buildModules = function() {
crypto = new Crypto();
ctrl._pgp = pgp = new PGP();
ctrl._keychain = keychain = new KeychainDAO(lawnchairDao, pubkeyDao, privkeyDao, crypto, pgp);
// TODO: inject dialog service directly into keychain service
keychain.requestPermissionForKeyUpdate = function(params, callback) {
var message = params.newKey ? str.updatePublicKeyMsgNewKey : str.updatePublicKeyMsgRemovedKey;
message = message.replace('{0}', params.userId);

6
src/js/email/index.js Normal file
View File

@ -0,0 +1,6 @@
'use strict';
angular.module('woEmail', []);
require('./email');
require('./account');

View File

@ -0,0 +1,10 @@
'use strict';
var mailreader = require('mailreader');
var config = require('../app-config').config;
mailreader.startWorker(config.workerPath + '/mailreader-parser-worker.min.js');
var ngModule = angular.module('woServices');
ngModule.factory('mailreader', function() {
return mailreader;
});

View File

@ -0,0 +1,4 @@
'use strict';
var ngModule = angular.module('woServices');
ngModule.service('pgpbuilder', require('pgpbuilder'));

View File

@ -25,8 +25,8 @@ var SMTP_DB_KEY = 'smtp';
* auth.getCredentials(...); // called to gather all the information to connect to IMAP/SMTP,
* username, password / oauth token, IMAP/SMTP server host names, ...
*/
function Auth(appConfigStore, oauth, pgp) {
this._appConfigStore = appConfigStore;
function Auth(deviceStorage, oauth, pgp) {
this._appConfigStore = deviceStorage;
this._oauth = oauth;
this._pgp = pgp;
}

View File

@ -1,9 +1,11 @@
'use strict';
var ngModule = angular.module('woServices');
ngModule.factory('deviceStorage', ['lawnchairDAO', function(lawnchairDAO) {
return new DeviceStorage(lawnchairDAO);
}]);
ngModule.factory('deviceStorage', ['lawnchairDAO',
function(lawnchairDAO) {
return new DeviceStorage(lawnchairDAO);
}
]);
module.exports = DeviceStorage;
/**
@ -13,8 +15,8 @@ function DeviceStorage(lawnchairDAO) {
this._localDbDao = lawnchairDAO;
}
DeviceStorage.prototype.init = function(emailAddress, callback) {
this._localDbDao.init(emailAddress, callback);
DeviceStorage.prototype.init = function(dbName, callback) {
this._localDbDao.init(dbName, callback);
};
/**

View File

@ -4,4 +4,5 @@ angular.module('woServices', []);
require('./newsletter');
require('./mail-config');
require('./account');
require('./account');
require('.pgpbuilder');

12
src/js/util/dialog.js Normal file
View File

@ -0,0 +1,12 @@
'use strict';
var ngModule = angular.module('woUtil');
ngModule.service('dialog', Dialog);
function Dialog() {}
Dialog.prototype.error = function() {};
Dialog.prototype.info = function() {};
Dialog.prototype.confirm = function() {};

6
src/js/util/index.js Normal file
View File

@ -0,0 +1,6 @@
'use strict';
angular.module('woUtil', []);
require('./dialog');
require('./update/update-handler');

View File

@ -1,5 +1,10 @@
'use strict';
var ngModule = angular.module('woUtil');
ngModule.service('updateHandler', ['deviceStorage', 'deviceStorage', 'auth', UpdateHandler]);
module.exports = UpdateHandler;
var axe = require('axe-logger'),
cfg = require('../../app-config').config,
updateV1 = require('./update-v1'),
@ -11,12 +16,12 @@ var axe = require('axe-logger'),
/**
* Handles database migration
*/
var UpdateHandler = function(appConfigStorage, userStorage, auth) {
function UpdateHandler(appConfigStorage, userStorage, auth) {
this._appConfigStorage = appConfigStorage;
this._userStorage = userStorage;
this._updateScripts = [updateV1, updateV2, updateV3, updateV4, updateV5];
this._auth = auth;
};
}
/**
* Executes all the necessary updates
@ -125,6 +130,4 @@ UpdateHandler.prototype.checkForUpdate = function(dialog) {
}
});
}
};
module.exports = UpdateHandler;
};