Skip to content

Commit

Permalink
edit for stockist and employees
Browse files Browse the repository at this point in the history
  • Loading branch information
vishivish18 committed Mar 12, 2016
1 parent 3e8b038 commit 39f3a10
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 0 deletions.
Binary file added favicon.ico
Binary file not shown.
8 changes: 8 additions & 0 deletions public/app/controllers/errorCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
angular.module('app')
.controller('errorCtrl', function($scope, $rootScope) {
$scope.hello = "this is from the controller hello"
console.log($scope.hello)



})
30 changes: 30 additions & 0 deletions public/app/controllers/loginCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
angular.module('app')
.controller('loginCtrl', function($scope, auth, $location, $timeout) {
$scope.authFail = false;
$scope.login = function(username, password) {
auth.login(username, password)
.then(function(res) {
auth.storeToken(res.data, function() {
auth.getUser()
.then(function(res) {
auth.postLoginOps(res.data, function() {
auth.postLoginRouteHandler();
});
})
});

})
.catch(function(response) {
console.error('Gists error', response.status, response.data);
if (response.status == 401) {
$scope.authFail = true
$timeout(function() { $scope.authFail = false; }, 3000);
}
})
.finally(function() {
console.log("finally finished gists");
});


}
})
7 changes: 7 additions & 0 deletions public/app/controllers/navCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
angular.module('app')
.controller('navCtrl', function($scope, auth, $location) {
$scope.logout = function() {
auth.logout()

}
})
14 changes: 14 additions & 0 deletions public/app/controllers/registerCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
angular.module('app')
.controller('registerCtrl',function($scope,UserSvc ,$location){
$scope.register = function(name,username,password){
UserSvc.register(name,username,password)
.then(function(response){
$scope.$emit('login',response.data)
$location.path('/home')
})
.catch(function (err){
console.log(err)
})
}

})
43 changes: 43 additions & 0 deletions public/app/controllers/resources/editEmployeeCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
angular.module('app')
.controller('editEmployeesCtrl', function($scope, $http, $location, $stateParams) {


$scope.setup = function() {
console.log($stateParams)
$http.get('/api/employees/' + $stateParams.id)
.then(function(response) {
$scope.model = response.data;
console.log($scope.model)

}, function(response) {
console.log(response)
});

}

$scope.updateEmployeeDetails = function() {
$http.put('/api/employees/' + $stateParams.id, {
employee_code: $scope.model.employee_code,
employee_name: $scope.model.employee_name,
employee_areacode: $scope.model.employee_areacode,
employee_address: $scope.model.employee_address,
employee_openingbalance: $scope.model.employee_openingbalance,
employee_bstcode: $scope.model.employee_bstcode,

})
.then(function(response) {
console.log(response)

}, function(response) {
console.log(response)
});

}



$scope.setup();



})
43 changes: 43 additions & 0 deletions public/app/controllers/resources/editStockistCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
angular.module('app')
.controller('editCompanyCtrl', function($scope, $http, $location, $stateParams) {


$scope.setup = function() {
console.log($stateParams)
$http.get('/api/companies/' + $stateParams.id)
.then(function(response) {
$scope.model = response.data;
console.log($scope.model)

}, function(response) {
console.log(response)
});

}

$scope.updateCompanyDetails = function() {
$http.put('/api/companies/' + $stateParams.id, {
company_code: $scope.model.company_code,
company_name: $scope.model.company_name,
company_areacode: $scope.model.company_areacode,
company_address: $scope.model.company_address,
company_openingbalance: $scope.model.company_openingbalance,
company_bstcode: $scope.model.company_bstcode,

})
.then(function(response) {
console.log(response)

}, function(response) {
console.log(response)
});

}



$scope.setup();



})
75 changes: 75 additions & 0 deletions public/app/services/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
angular.module('app')
.service('auth', function($http, $window, $location, $rootScope) {


return {
getUser: getUser,
login: login,
logout: logout,
storeToken: storeToken,
isLogged: isLogged,
postLoginOps: postLoginOps,
postLoginRouteHandler: postLoginRouteHandler

}

function getUser() {
return $http.get('api/users')
}

function login(username, password) {

return $http.post('api/sessions', {
username: username,
password: password
})
}


function logout() {
localStorage.removeItem('user_token');
localStorage.removeItem('logged_user');
delete $http.defaults.headers.common['x-auth']
$rootScope.isLogged = false;
$rootScope.currentUser = null;
$location.path("/login")



}

function storeToken(res, cb) {
$window.sessionStorage["user_token"] = res
localStorage.setItem('user_token', res);
$http.defaults.headers.common['x-auth'] = $window.sessionStorage.user_token
if (cb && (typeof cb === 'function')) {
cb();
}
}

function isLogged() {

}

function postLoginOps(res, cb) {


$rootScope.currentUser = res.name
localStorage.setItem('logged_user', $rootScope.currentUser)
$rootScope.isLogged = true;
if (cb && (typeof cb === 'function')) {
cb();
}

}

function postLoginRouteHandler() {
if ($rootScope.intendedRoute) {
$location.path($rootScope.intendedRoute);
} else {
$location.path('/home');
}
}


})
36 changes: 36 additions & 0 deletions public/app/views/resources/editEmployee.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="container">
<div class="top-buffer row">
<div class="col-md-4">
<input type="text" ng-model="model.employee_code" placeholder="employee Code" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.employee_name" placeholder="employee Name" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.employee_areacode" placeholder="Area Code" class="form-control">
</div>
</div>
<div class="top-buffer row">
<div class="col-md-4">
<input type="text" ng-model="model.employee_address" placeholder="Address" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.employee_openingbalance" placeholder="Opening Balance" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.employee_bstcode" placeholder="BST Code" class="form-control">
</div>
</div>
<div class="top-buffer row">
<div class="col-md-offset-8 col-md-4">
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-primary btn-block">Reset</button>
</div>
<div class="col-md-6">
<button ng-click="updateEmployeeDetails()" type="button" class="btn btn-success btn-block"><span class="glyphicon glyphicon-floppy-disk"></span> Update</button>
</div>
</div>
</div>
</div>
</div>
36 changes: 36 additions & 0 deletions public/app/views/resources/editStockist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="container">
<div class="top-buffer row">
<div class="col-md-4">
<input type="text" ng-model="model.stockist_code" placeholder="Stockist Code" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.stockist_name" placeholder="Stockist Name" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.stockist_areacode" placeholder="Area Code" class="form-control">
</div>
</div>
<div class="top-buffer row">
<div class="col-md-4">
<input type="text" ng-model="model.stockist_address" placeholder="Address" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.stockist_openingbalance" placeholder="Opening Balance" class="form-control">
</div>
<div class="col-md-4">
<input type="text" ng-model="model.stockist_bstcode" placeholder="BST Code" class="form-control">
</div>
</div>
<div class="top-buffer row">
<div class="col-md-offset-8 col-md-4">
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-primary btn-block">Reset</button>
</div>
<div class="col-md-6">
<button ng-click="updateStockistDetails()" type="button" class="btn btn-success btn-block"><span class="glyphicon glyphicon-floppy-disk"></span> Update</button>
</div>
</div>
</div>
</div>
</div>
Binary file added public/assets/images/favicon.ico
Binary file not shown.

0 comments on commit 39f3a10

Please sign in to comment.