WIP: start new service architecture

This commit is contained in:
Tankred Hase 2014-11-17 18:58:03 +01:00
parent f11d4e8df3
commit 628beb02e8
5 changed files with 64 additions and 4 deletions

View File

@ -41,7 +41,7 @@ ctrl.start = function(options, callback) {
}
ctrl.started = true;
ctrl.onError = options.onError;
ctrl.onError = options.onError; // TODO: replace by errorService
// are we running in a cordova app or in a browser environment?
if (window.cordova) {
@ -57,16 +57,21 @@ ctrl.start = function(options, callback) {
function onDeviceReady() {
axe.debug('Starting app.');
// TODO: will be replaced by angular dependency management
ctrl.buildModules();
// TODO: move self-contained connection management in emailDao
// Handle offline and online gracefully
window.addEventListener('online', ctrl.onConnect.bind(ctrl, ctrl.onError));
window.addEventListener('offline', ctrl.onDisconnect.bind(ctrl));
// TODO: move appConfigService shared singleton
ctrl._appConfigStore.init('app-config', callback);
}
};
// TODO: will be replaced by angular dependency management
/**
* Initialize the dependency tree.
*/
@ -121,6 +126,8 @@ ctrl.checkForUpdate = function() {
ctrl._updateHandler.checkForUpdate(ctrl.onError);
};
// TODO: move to AccountService
/**
* Fire up the database, retrieve the available keys for the user and initialize the email data access object
*/
@ -207,6 +214,8 @@ ctrl.isOnline = function() {
return navigator.onLine;
};
// TODO: move to AccountService
/**
* Event handler that is called when the user agent goes offline.
*/
@ -214,6 +223,8 @@ ctrl.onDisconnect = function() {
ctrl._emailDao.onDisconnect();
};
// TODO: move to AccountService
/**
* Log the current user out by clear the app config store and deleting instances of imap-client and pgp-mailer.
*/
@ -243,6 +254,8 @@ ctrl.logout = function() {
});
};
// TODO: move onConnect to emailDao
/**
* Event that is called when the user agent goes online. This create new instances of the imap-client and pgp-mailer and connects to the mail server.
*/

View File

@ -37,8 +37,7 @@ var DialogCtrl = require('./controller/dialog'),
errorUtil = require('./util/error'),
backButtonUtil = require('./util/backbutton-handler');
require('./directive/common'),
require('./service/newsletter'),
require('./service/mail-config');
require('./service');
// init main angular module including dependencies
var app = angular.module('mail', [

41
src/js/service/account.js Normal file
View File

@ -0,0 +1,41 @@
'use strict';
var ngModule = angular.module('woServices');
ngModule.service('account', Account);
var EmailDAO = require('../dao/email-dao');
function Account() {
this._emailDAOs = [];
}
/**
* Lists all of the current accounts connected to the app
* @return {Array<Object>} The account objects containing folder and message objects
*/
Account.prototype.all = function() {
return this._emailDAOs.map(function(emailDao) {
return emailDao._account;
});
};
/**
* Login to an existing email account. This creates a new email data access object instance for that account and logs in via IMAP.
* @param {String} options.emailAddress The account's email address
*/
Account.prototype.login = function(options) {
var emailDao = new EmailDAO();
this._emailDAOs.push(emailDao);
};
/**
* Create a new whiteout account. This creates a new email data access object instance for that account and logs in via IMAP.
* @param {String} options.emailAddress The account's email address
*/
Account.prototype.create = function(options) {};
/**
* Logout of an email account. This creates a new email data access object instance for that account and logs in via IMAP.
* @param {String} options.emailAddress The account's email address
*/
Account.prototype.logout = function(options) {};

7
src/js/service/index.js Normal file
View File

@ -0,0 +1,7 @@
'use strict';
angular.module('woServices', []);
require('./newsletter'),
require('./mail-config'),
require('./account');

View File

@ -1,6 +1,6 @@
'use strict';
var ngModule = angular.module('woServices', []);
var ngModule = angular.module('woServices');
ngModule.service('newsletter', Newsletter);
function Newsletter($q) {