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
d1e16543
Commit
d1e16543
authored
Jul 06, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Feature/#101/ImplementFormDiff'
parents
61f021ef
6cd28cc7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
26 deletions
+51
-26
staff_controller.js
app/components/staff/staff_controller.js
+5
-5
student_controller.js
app/components/student/student_controller.js
+6
-8
form_service.js
app/zetalib/forms/form_service.js
+8
-8
general.js
app/zetalib/general.js
+3
-1
general_test.js
app/zetalib/general_test.js
+21
-4
interceptors.js
app/zetalib/interceptors.js
+8
-0
No files found.
app/components/staff/staff_controller.js
View file @
d1e16543
...
...
@@ -16,11 +16,12 @@ var staff = angular.module('zaerp.staff', ['ngRoute', 'schemaForm', 'formService
* which provide a form with form generator.
*/
staff
.
controller
(
'StaffAddCtrl'
,
function
(
$scope
,
$http
,
$log
,
Generator
,
$routeParams
)
{
staff
.
controller
(
'StaffAddCtrl'
,
function
(
$scope
,
$http
,
$log
,
Generator
)
{
Generator
.
get_form
(
'add_staff'
,
''
).
then
(
function
(
d
)
{
$scope
.
schema
=
d
.
schema
;
$scope
.
form
=
d
.
form
;
$scope
.
model
=
d
.
model
?
d
.
model
:
{};
$scope
.
initialModel
=
angular
.
copy
(
d
.
model
);
$scope
.
form
[
0
].
$asyncValidators
=
Generator
.
asyncValidators
;
$scope
.
form
.
push
(
{
...
...
@@ -33,8 +34,7 @@ staff.controller('StaffAddCtrl', function ($scope, $http, $log, Generator, $rout
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
// todo: implement form diff here
$log
.
info
(
$scope
);
Generator
.
submit
(
'add_staff'
,
$scope
);
}
}
});
...
...
@@ -44,6 +44,7 @@ staff.controller('StaffEditCtrl', function ($scope, $http, $log, Generator, $rou
$scope
.
schema
=
d
.
schema
;
$scope
.
form
=
d
.
form
;
$scope
.
model
=
d
.
model
?
d
.
model
:
{};
$scope
.
initialModel
=
angular
.
copy
(
d
.
model
);
$scope
.
form
[
0
].
$asyncValidators
=
Generator
.
asyncValidators
;
$scope
.
form
.
push
(
{
...
...
@@ -56,8 +57,7 @@ staff.controller('StaffEditCtrl', function ($scope, $http, $log, Generator, $rou
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
// todo: implement form diff here
$log
.
info
(
$scope
);
Generator
.
submit
(
'edit_staff'
,
$scope
);
}
}
});
...
...
app/components/student/student_controller.js
View file @
d1e16543
...
...
@@ -35,14 +35,12 @@ student.controller('StudentAddEditCtrl', function($scope, $http, $log, Generator
}
);
});
$scope
.
onSubmit
=
Generator
.
submit
(
$scope
);
//$scope.$broadcast('schemaFormValidate');
//if (form.$valid) {
// todo: implement form diff here
//Generator.submit($scope);
//$log.info($scope.initialModel, $scope.model);
//}
//}
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
Generator
.
submit
(
'add_staff'
,
$scope
);
}
}
});
/**
...
...
app/zetalib/forms/form_service.js
View file @
d1e16543
...
...
@@ -5,9 +5,9 @@
* (GPLv3). See LICENSE.txt for details.
*/
var
form_generator
=
angular
.
module
(
'formService'
,
[]);
var
form_generator
=
angular
.
module
(
'formService'
,
[
'general'
]);
form_generator
.
factory
(
'Generator'
,
function
(
$http
,
$q
,
$log
,
$timeout
,
RESTURL
)
{
form_generator
.
factory
(
'Generator'
,
function
(
$http
,
$q
,
$log
,
$timeout
,
RESTURL
,
FormDiff
)
{
var
generator
=
{};
generator
.
generate
=
function
(
modelObject
)
{
return
generator
.
group
(
modelObject
);
...
...
@@ -54,14 +54,14 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
return
deferred
.
promise
;
}
};
generator
.
submit
=
function
(
$scope
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
//if ($scope.form.$valid) {
// todo: change post url, this is not correct!
$http
.
post
(
'http://127.0.0.1:3000/api/add_student'
,
$scope
.
model
).
then
(
function
(
res
)
{
generator
.
submit
=
function
(
url
,
$scope
)
{
var
get_diff
=
FormDiff
.
get_diff
(
$scope
.
model
,
$scope
.
initialModel
);
$log
.
info
(
get_diff
);
$http
.
post
(
RESTURL
.
url
+
url
,
get_diff
).
then
(
function
(
res
)
{
// todo: for now fake rest api returns 'ok' no data to
// manipulate on ui. therefor used just a log
$log
.
info
(
res
);
});
//}
};
return
generator
;
});
\ No newline at end of file
app/zetalib/general.js
View file @
d1e16543
...
...
@@ -18,12 +18,14 @@ general.factory('FormDiff', function () {
* function to return diff of models of submitted form
* @type {{}}
* @params obj1, obj2
* @attention: obj1 must be initialModel, obj2 must be model after inputs
* filled
*/
var
formDiff
=
{};
formDiff
.
get_diff
=
function
(
obj1
,
obj2
)
{
var
result
=
{};
for
(
key
in
obj1
)
{
if
(
obj2
[
key
]
!=
obj1
[
key
])
result
[
key
]
=
obj
2
[
key
];
if
(
obj2
[
key
]
!=
obj1
[
key
])
result
[
key
]
=
obj
1
[
key
];
if
(
typeof
obj2
[
key
]
==
'array'
&&
typeof
obj1
[
key
]
==
'array'
)
result
[
key
]
=
arguments
.
callee
(
obj1
[
key
],
obj2
[
key
]);
if
(
typeof
obj2
[
key
]
==
'object'
&&
typeof
obj1
[
key
]
==
'object'
)
...
...
app/zetalib/general_test.js
View file @
d1e16543
...
...
@@ -24,19 +24,36 @@ describe('general module', function () {
];
// test cases - testing for failure
var
different_jsons
=
[
[
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
},
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
}
],
[
{
id
:
2
,
name
:
'travolta'
},
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
}
]
];
var
different_json
=
[
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
},
{},
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
}
]
;
]
var
diff
=
{
email
:
'test1@test.com'
,
name
:
'john'
};
var
diff2
=
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
};
var
nodiff
=
{};
var
same
=
FormDiff
.
get_diff
(
same_json
[
0
],
same_json
[
1
]);
expect
(
same
).
toEqual
(
nodiff
);
var
different
=
FormDiff
.
get_diff
(
different_json
[
0
],
different_json
[
1
]);
expect
(
different
).
toEqual
(
diff
);
for
(
var
json_obj
in
different_jsons
)
{
var
different
=
FormDiff
.
get_diff
(
different_jsons
[
json_obj
][
1
],
different_jsons
[
json_obj
][
0
]);
expect
(
different
).
toEqual
(
diff
);
}
var
different2
=
FormDiff
.
get_diff
(
different_json
[
1
],
different_json
[
0
]);
expect
(
different2
).
toEqual
(
diff2
);
}])
);
...
...
app/zetalib/interceptors.js
View file @
d1e16543
...
...
@@ -12,6 +12,14 @@ app.config(['$httpProvider', function ($httpProvider) {
*/
$httpProvider
.
interceptors
.
push
(
function
(
$q
)
{
return
{
'request'
:
function
(
config
){
if
(
config
.
method
==
"POST"
){
console
.
log
(
"post request"
)
}
else
{
console
.
log
(
"get request"
)
}
return
config
;
},
'response'
:
function
(
response
)
{
//Will only be called for HTTP up to 300
return
response
;
...
...
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