api controller refactor

This commit is contained in:
Mo Bitar
2017-01-25 17:14:11 -06:00
parent a76f725f7f
commit 51012d7d54
14 changed files with 471 additions and 501 deletions

View File

@@ -1,9 +1,9 @@
class BaseCtrl {
constructor($rootScope, modelManager, apiController, dbManager) {
constructor(syncManager, dbManager) {
dbManager.openDatabase(null, function(){
// new database, delete syncToken so that items can be refetched entirely from server
apiController.clearSyncToken();
apiController.sync();
syncManager.clearSyncToken();
syncManager.sync();
})
}
}

View File

@@ -16,7 +16,7 @@ angular.module('app.frontend')
}
}
})
.controller('HeaderCtrl', function (apiController, modelManager, $timeout, dbManager) {
.controller('HeaderCtrl', function (apiController, modelManager, $timeout, dbManager, syncManager) {
this.user = apiController.user;
@@ -43,7 +43,7 @@ angular.module('app.frontend')
this.refreshData = function() {
this.isRefreshing = true;
apiController.sync(function(response){
syncManager.sync(function(response){
$timeout(function(){
this.isRefreshing = false;
}.bind(this), 200)

View File

@@ -1,14 +1,14 @@
angular.module('app.frontend')
.controller('HomeCtrl', function ($scope, $rootScope, $timeout, apiController, modelManager) {
.controller('HomeCtrl', function ($scope, $rootScope, $timeout, modelManager, syncManager) {
$rootScope.bodyClass = "app-body-class";
apiController.loadLocalItems(function(items){
syncManager.loadLocalItems(function(items){
$scope.$apply();
apiController.sync(null);
syncManager.sync(null);
// refresh every 30s
setInterval(function () {
apiController.sync(null);
syncManager.sync(null);
}, 30000);
});
@@ -31,7 +31,7 @@ angular.module('app.frontend')
modelManager.createRelationshipBetweenItems(note, tag);
}
apiController.sync();
syncManager.sync();
}
/*
@@ -57,7 +57,7 @@ angular.module('app.frontend')
$scope.tagsSave = function(tag, callback) {
tag.setDirty(true);
apiController.sync(callback);
syncManager.sync(callback);
}
/*
@@ -69,7 +69,7 @@ angular.module('app.frontend')
if(validNotes == 0) {
modelManager.setItemToBeDeleted(tag);
// if no more notes, delete tag
apiController.sync(function(){
syncManager.sync(function(){
// force scope tags to update on sub directives
$scope.tags = [];
$timeout(function(){
@@ -100,7 +100,7 @@ angular.module('app.frontend')
$scope.saveNote = function(note, callback) {
note.setDirty(true);
apiController.sync(function(response){
syncManager.sync(function(response){
if(response && response.error) {
if(!$scope.didShowErrorAlert) {
$scope.didShowErrorAlert = true;
@@ -137,8 +137,8 @@ angular.module('app.frontend')
return;
}
apiController.sync(function(){
if(!apiController.user) {
syncManager.sync(function(){
if(syncManager.offline) {
// when deleting items while ofline, we need to explictly tell angular to refresh UI
setTimeout(function () {
$scope.safeApply();