Commit 2970444f authored by Evren Kutar's avatar Evren Kutar

Merge branch 'backend_implementation'

parents 7ae6ea4d ee23a6e8
...@@ -31,7 +31,7 @@ var app = angular.module( ...@@ -31,7 +31,7 @@ var app = angular.module(
config(['$ocLazyLoadProvider', function ($ocLazyLoadProvider) { config(['$ocLazyLoadProvider', function ($ocLazyLoadProvider) {
$ocLazyLoadProvider.config({ $ocLazyLoadProvider.config({
// todo: turn debug false on prod // todo: turn debug false on prod
debug: true debug: false
}); });
}]). }]).
/** /**
...@@ -66,16 +66,16 @@ var app = angular.module( ...@@ -66,16 +66,16 @@ var app = angular.module(
// todo: not working properly, get it done! // todo: not working properly, get it done!
directive('activeLink', ['$location', function($location) { directive('activeLink', ['$location', function ($location) {
return { return {
restrict: 'A', restrict: 'A',
link: function($scope, $element, $attrs) { link: function ($scope, $element, $attrs) {
var clazz = $attrs.activeLink; var clazz = $attrs.activeLink;
var path = $location.path(); var path = $location.path();
path = path //hack because path does not path = path //hack because path does not
// return including hashbang // return including hashbang
$scope.location = $location; $scope.location = $location;
$scope.$watch('location.path()', function(newPath) { $scope.$watch('location.path()', function (newPath) {
if (path === newPath) { if (path === newPath) {
console.log(path, newPath); console.log(path, newPath);
$element.addClass(clazz); $element.addClass(clazz);
...@@ -86,7 +86,23 @@ var app = angular.module( ...@@ -86,7 +86,23 @@ var app = angular.module(
}); });
} }
}; };
}]); }]).
/**
* logout directive
*/
directive('logout', function($http, $location){
return {
link: function($scope, $element, $rootScope){
$element.on('click', function(){
$http.post('http://127.0.0.1:9001/logout', {}).then(function () {
$rootScope.loggedInUser = false;
$location.path("/login");
});
});
}
}
});
// test the code with strict di mode to see if it works when minified // test the code with strict di mode to see if it works when minified
//angular.bootstrap(document, ['zaerp'], { //angular.bootstrap(document, ['zaerp'], {
......
...@@ -180,4 +180,7 @@ app.config(['$routeProvider', function ($routeProvider) { ...@@ -180,4 +180,7 @@ app.config(['$routeProvider', function ($routeProvider) {
} }
} }
}); });
}); }).config(['$httpProvider', function($httpProvider) {
\ No newline at end of file // to send cookies CORS
$httpProvider.defaults.withCredentials = true;
}]);
\ No newline at end of file
...@@ -17,13 +17,13 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook ...@@ -17,13 +17,13 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
return $http return $http
.post(RESTURL.url + url, credentials) .post(RESTURL.url + url, credentials)
.success(function (data, status, headers, config) { .success(function (data, status, headers, config) {
$window.sessionStorage.token = data.token; //$window.sessionStorage.token = data.token;
$rootScope.loggedInUser = true; $rootScope.loggedInUser = true;
$location.path("/dashboard"); $location.path("/dashboard");
}) })
.error(function (data, status, headers, config) { .error(function (data, status, headers, config) {
// Erase the token if the user fails to log in // Erase the token if the user fails to log in
delete $window.sessionStorage.token; //delete $window.sessionStorage.token;
// Handle login errors here // Handle login errors here
$scope.message = 'Error: Invalid user or password'; $scope.message = 'Error: Invalid user or password';
...@@ -44,6 +44,16 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook ...@@ -44,6 +44,16 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
//}); //});
}; };
loginService.logout = function() {
console.log("logout");
$http.post(RESTURL.url + 'logout', {}).then(function(){
$rootScope.loggedInUser = false;
$location.path("/login");
});
console.log("loggedout");
};
loginService.isAuthenticated = function () { loginService.isAuthenticated = function () {
return !!Session.userId; return !!Session.userId;
}; };
......
<div ng-app="zaerp.login"> <div ng-app="zaerp.auth">
<div class="col-md-6" ng-controller="LoginCtrl"> <div class="col-md-6">
<h1>Zaerp Login Form</h1> <h1>Ulakbüs Login Form</h1>
<form name="loginForm" sf-schema="schema" sf-form="form" sf-model="model" ng-submit="onSubmit(loginForm)"></form> <form name="loginForm" sf-schema="schema" sf-form="form" sf-model="model" ng-submit="onSubmit(loginForm)"></form>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -12,7 +12,7 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService ...@@ -12,7 +12,7 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
/** /**
* StaffCtrl is a controller * StaffAddEditCtrl is a controller
* which provide a form with form generator. * which provide a form with form generator.
*/ */
...@@ -40,6 +40,7 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService ...@@ -40,6 +40,7 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
//}); //});
staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $routeParams) { staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $routeParams) {
$scope.url = 'personel_duzenle_basitlestirilmis';
var form_params = {}; var form_params = {};
if ($routeParams.id){ if ($routeParams.id){
form_params['id'] = $routeParams.id; form_params['id'] = $routeParams.id;
...@@ -48,11 +49,11 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $ ...@@ -48,11 +49,11 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
else { else {
form_params['cmd'] = 'add_object'; form_params['cmd'] = 'add_object';
} }
Generator.get_form('personel_duzenle_basitlestirilmis', form_params).then(function (data) { Generator.get_form($scope.url, form_params).then(function (data) {
var d = data.data.forms; var d = data.data.forms;
$scope.schema = d.schema; $scope.schema = d.schema;
$scope.form = d.form; $scope.form = d.form;
$scope.form.push({"key": "birth_date", "format": "yyyy-mm-dd"}); //$scope.form.push({"key": "birth_date", "format": "yyyy-mm-dd"});
$scope.model = d.model ? d.model : {}; $scope.model = d.model ? d.model : {};
$scope.initialModel = angular.copy(d.model); $scope.initialModel = angular.copy(d.model);
//$scope.form.push($asyncValidators: Generator.asyncValidators); //$scope.form.push($asyncValidators: Generator.asyncValidators);
...@@ -68,17 +69,20 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $ ...@@ -68,17 +69,20 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
$scope.onSubmit = function (form) { $scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
if (form.$valid) { if (form.$valid) {
Generator.submit('edit_staff', $scope); Generator.submit($scope);
} }
} }
}); });
// todo: for single point of failure code a "get item" service and use it to
// retrieve list and single item
/** /**
* Staff List Controller * Staff List Controller
*/ */
staff.controller('StaffListCtrl', function($scope, $http){ staff.controller('StaffListCtrl', function($scope, $http){
$http.get('personel_duzenle_basitlestirilmis').then(function(res){ $http.post('personel_duzenle_basitlestirilmis').then(function(res){
$scope.staffs = res.data; $scope.staffs = res.data;
}) })
}); });
...@@ -87,7 +91,7 @@ staff.controller('StaffListCtrl', function($scope, $http){ ...@@ -87,7 +91,7 @@ staff.controller('StaffListCtrl', function($scope, $http){
* Staff Show Controller * Staff Show Controller
*/ */
staff.controller('StaffShowCtrl', function($scope, $http, $routeParams){ staff.controller('StaffShowCtrl', function($scope, $http, $routeParams){
$http.get('http://127.0.0.1:3000/api/list_staff/').then(function(res){ $http.post('personel_duzenle_basitlestirilmis').then(function(res){
$scope.staff = res.data[0]; $scope.staff = res.data[0];
}) })
}); });
\ No newline at end of file
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><a href="#/dashboard">Dashboard</a></li> <li><a href="#/dashboard">Dashboard</a></li>
<li><a href="#/login">Login</a></li> <li><a href="#/login">Login</a></li>
<li><a href="javascript:void(0);" logout>Logout
</a></li>
</ul> </ul>
<form class="navbar-form navbar-right"> <form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search..."> <input type="text" class="form-control" placeholder="Search...">
......
...@@ -42,10 +42,10 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL ...@@ -42,10 +42,10 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
return deferred.promise; return deferred.promise;
} }
}; };
generator.submit = function (url, $scope) { generator.submit = function ($scope) {
var get_diff = FormDiff.get_diff($scope.model,$scope.initialModel); var get_diff = FormDiff.get_diff($scope.model,$scope.initialModel);
$log.info(get_diff); $log.info(get_diff);
$http.post(RESTURL.url + url, get_diff).then(function (res) { $http.post(RESTURL.url + $scope.url, get_diff).then(function (res) {
// todo: for now fake rest api returns 'ok' no data to // todo: for now fake rest api returns 'ok' no data to
// manipulate on ui. therefor used just a log // manipulate on ui. therefor used just a log
$log.info(res); $log.info(res);
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
* (GPLv3). See LICENSE.txt for details. * (GPLv3). See LICENSE.txt for details.
*/ */
app.config(['$httpProvider', function ($httpProvider, $rootScope) { app.config(['$httpProvider', function ($httpProvider) {
/** /**
* the interceptor for all requests to check response * the interceptor for all requests to check response
* 4xx - 5xx errors will be handled here * 4xx - 5xx errors will be handled here
*/ */
$httpProvider.interceptors.push(function ($q) { $httpProvider.interceptors.push(function ($q, $rootScope, $location) {
return { return {
'request': function(config){ 'request': function(config){
// todo: delete console logs // todo: delete console logs
...@@ -23,23 +23,26 @@ app.config(['$httpProvider', function ($httpProvider, $rootScope) { ...@@ -23,23 +23,26 @@ app.config(['$httpProvider', function ($httpProvider, $rootScope) {
}, },
'response': function (response) { 'response': function (response) {
//Will only be called for HTTP up to 300 //Will only be called for HTTP up to 300
if(response.is_login){ if(response.data.is_login){
$rootScope.loggedInUser = response.is_login; $rootScope.loggedInUser = response.data.is_login;
console.log("login", response.is_login); //$location.path("/dashboard");
} }
if(response.screen) { if(response.data.screen) {
location.path(response.screen); $location.path(response.data.screen);
} }
console.log(response);
return response; return response;
}, },
'responseError': function (rejection) { 'responseError': function (rejection) {
// if unauthorized then redirect to login page // if unauthorized then redirect to login page
if(rejection.status === 400) { if(rejection.status === 400) {
location.reload(); $location.reload();
} }
if(rejection.status === 401) { if(rejection.status === 401) {
location.path('#/login'); if($location.path()==="/login"){
console.log("show errors on login form");
} else{
$location.path('/login');
}
} }
return $q.reject(rejection); return $q.reject(rejection);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"license": "GPL", "license": "GPL",
"private": false, "private": false,
"dependencies": { "dependencies": {
"angular": "1.4.x", "angular": "1.4.1",
"angular-mocks": "1.4.x", "angular-mocks": "1.4.x",
"angular-route": "1.4.x", "angular-route": "1.4.x",
"angular-resource": "1.4.x", "angular-resource": "1.4.x",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment