Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
ulakbus-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ulakbus
ulakbus-ui
Commits
2970444f
Commit
2970444f
authored
Jul 08, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'backend_implementation'
parents
7ae6ea4d
ee23a6e8
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
68 additions
and
30 deletions
+68
-30
app.js
app/app.js
+21
-5
app_routes.js
app/app_routes.js
+4
-1
auth_service.js
app/components/auth/auth_service.js
+12
-2
login.html
app/components/auth/login.html
+3
-3
staff_controller.js
app/components/staff/staff_controller.js
+10
-6
index.html
app/index.html
+2
-0
form_service.js
app/zetalib/forms/form_service.js
+2
-2
interceptors.js
app/zetalib/interceptors.js
+13
-10
bower.json
bower.json
+1
-1
No files found.
app/app.js
View file @
2970444f
...
@@ -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
:
tru
e
debug
:
fals
e
});
});
}]).
}]).
/**
/**
...
@@ -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'], {
...
...
app/app_routes.js
View file @
2970444f
...
@@ -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
app/components/auth/auth_service.js
View file @
2970444f
...
@@ -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
;
};
};
...
...
app/components/auth/login.html
View file @
2970444f
<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
app/components/staff/staff_controller.js
View file @
2970444f
...
@@ -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
* Staff
AddEdit
Ctrl 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
.
ge
t
(
'personel_duzenle_basitlestirilmis'
).
then
(
function
(
res
){
$http
.
pos
t
(
'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
app/index.html
View file @
2970444f
...
@@ -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..."
>
...
...
app/zetalib/forms/form_service.js
View file @
2970444f
...
@@ -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
);
...
...
app/zetalib/interceptors.js
View file @
2970444f
...
@@ -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
);
}
}
...
...
bower.json
View file @
2970444f
...
@@ -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"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment