Skip to content

Commit

Permalink
Revert "Refactor angular"
Browse files Browse the repository at this point in the history
  • Loading branch information
sahat committed Sep 20, 2016
1 parent 7c0291c commit f118648
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 306 deletions.
2 changes: 0 additions & 2 deletions generators/js-framework/modules/angularjs/app.js
@@ -1,4 +1,3 @@
(function() {
angular.module('MyApp', ['ngRoute'<%= satellizer %>])
.config(function($routeProvider, $locationProvider, $authProvider) {
$locationProvider.html5Mode(true);
Expand Down Expand Up @@ -64,4 +63,3 @@ angular.module('MyApp', ['ngRoute'<%= satellizer %>])
$rootScope.currentUser = JSON.parse($window.localStorage.user);
}
});
})();
39 changes: 15 additions & 24 deletions generators/js-framework/modules/angularjs/controllers/contact.js
@@ -1,25 +1,16 @@
(function() {
angular.module('MyApp')
.controller('ContactCtrl', ContactCtrl);

ContactCtrl.$inject = ['$scope', 'Contact'];

function ContactCtrl($scope, Contact) {
var ctrl = this;
ctrl.sendContactForm = sendContactForm;

function sendContactForm() {
Contact.send($scope.contact)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}
}
})();
.controller('ContactCtrl', function($scope, Contact) {
$scope.sendContactForm = function() {
Contact.send($scope.contact)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
};
});
39 changes: 15 additions & 24 deletions generators/js-framework/modules/angularjs/controllers/forgot.js
@@ -1,25 +1,16 @@
(function() {
angular.module('MyApp')
.controller('ForgotCtrl', ForgotCtrl);

ForgotCtrl.$inject = ['$scope', 'Account'];

function ForgotCtrl($scope, Account) {
var ctrl = this;
ctrl.forgotPassword = forgotPassword;

function forgotPassword() {
Account.forgotPassword($scope.user)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}
}
})();
.controller('ForgotCtrl', function($scope, Account) {
$scope.forgotPassword = function() {
Account.forgotPassword($scope.user)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
};
});
43 changes: 16 additions & 27 deletions generators/js-framework/modules/angularjs/controllers/header.js
@@ -1,28 +1,17 @@
(function() {
angular.module('MyApp')
.controller('HeaderCtrl', HeaderCtrl);

HeaderCtrl.$inject = ['$scope', '$location', '$window', '$auth'];

function HeaderCtrl($scope, $location, $window, $auth) {
var ctrl = this;
ctrl.isActive = isActive;
ctrl.isAuthenticated = isAuthenticated;
ctrl.logout = logout;

function isActive(viewLocation) {
return viewLocation === $location.path();
}

function isAuthenticated() {
return $auth.isAuthenticated();
}

function logout() {
$auth.logout();
delete $window.localStorage.user;
$location.path('/');
}

}
})();
.controller('HeaderCtrl', function($scope, $location, $window, $auth) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};

$scope.isAuthenticated = function() {
return $auth.isAuthenticated();
};

$scope.logout = function() {
$auth.logout();
delete $window.localStorage.user;
$location.path('/');
};
//= FOUNDATION_INIT_INDENT2
});
74 changes: 32 additions & 42 deletions generators/js-framework/modules/angularjs/controllers/login.js
@@ -1,46 +1,36 @@
(function() {
angular.module('MyApp')
.controller('LoginCtrl', LoginCtrl);
.controller('LoginCtrl', function($scope, $rootScope, $location, $window, $auth) {
$scope.login = function() {
$auth.login($scope.user)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/account');
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
};

LoginCtrl.$inject = ['$scope', '$rootScope', '$location', '$window', '$auth'];

function LoginCtrl($scope, $rootScope, $location, $window, $auth) {
var ctrl = this;
ctrl.login = login;
ctrl.authenticate = authenticate;

function login() {
$auth.login($scope.user)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/account');
})
.catch(function(response) {
$scope.authenticate = function(provider) {
$auth.authenticate(provider)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
if (response.error) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
error: [{ msg: response.error }]
};
});
}

function authenticate(provider) {
$auth.authenticate(provider)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
if (response.error) {
$scope.messages = {
error: [{ msg: response.error }]
};
} else if (response.data) {
$scope.messages = {
error: [response.data]
};
}
});
}
}
})();
} else if (response.data) {
$scope.messages = {
error: [response.data]
};
}
});
};
});
156 changes: 70 additions & 86 deletions generators/js-framework/modules/angularjs/controllers/profile.js
@@ -1,92 +1,76 @@
(function() {
angular.module('MyApp')
.controller('ContactCtrl', ContactCtrl);

ContactCtrl.$inject = ['$scope', '$rootScope', '$location', '$window', '$auth', 'Account'];

function ContactCtrl($scope, $rootScope, $location, $window, $auth, Account) {
var ctrl = this;
ctrl.updateProfile = updateProfile;
ctrl.changePassword = changePassword;
ctrl.link = link;
ctrl.unlink = unlink;
ctrl.deleteAccount = deleteAccount;
ctrl.unlink = unlink;
.controller('ProfileCtrl', function($scope, $rootScope, $location, $window, $auth, Account) {
$scope.profile = $rootScope.currentUser;

function updateProfile() {
Account.updateProfile($scope.profile)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}

function changePassword() {
Account.changePassword($scope.profile)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}
$scope.updateProfile = function() {
Account.updateProfile($scope.profile)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
};

function link(provider) {
$auth.link(provider)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$window.scrollTo(0, 0);
$scope.messages = {
error: [response.data]
};
});
}
$scope.changePassword = function() {
Account.changePassword($scope.profile)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
};

function unlink(provider) {
$auth.unlink(provider)
.then(function() {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: [response.data]
};
});
}
$scope.link = function(provider) {
$auth.link(provider)
.then(function(response) {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$window.scrollTo(0, 0);
$scope.messages = {
error: [response.data]
};
});
};
$scope.unlink = function(provider) {
$auth.unlink(provider)
.then(function() {
$scope.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
error: [response.data]
};
});
};

function deleteAccount() {
$scope.deleteAccount = function() {
Account.deleteAccount()
.then(function() {
$auth.logout();
delete $window.localStorage.user;
$location.path('/');
})
.catch(function(response) {
$scope.messages = {
error: [response.data]
};
});
};
}
}
})();
$scope.deleteAccount = function() {
Account.deleteAccount()
.then(function() {
$auth.logout();
delete $window.localStorage.user;
$location.path('/');
})
.catch(function(response) {
$scope.messages = {
error: [response.data]
};
});
};
});

0 comments on commit f118648

Please sign in to comment.