forked from SpectaTechnologies/med-stock
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e8b038
commit 39f3a10
Showing
11 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
|
||
|
||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.