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
5f28dc2d
Commit
5f28dc2d
authored
Sep 19, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form service test cases fixed
parent
5529d3a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
28 deletions
+80
-28
form_service.js
app/zetalib/forms/form_service.js
+36
-22
form_service_test.js
app/zetalib/forms/form_service_test.js
+44
-6
No files found.
app/zetalib/forms/form_service.js
View file @
5f28dc2d
...
...
@@ -15,7 +15,9 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
generator
.
generate
=
function
(
scope
,
data
)
{
// if no form in response (in case of list and single item request) return scope
if
(
!
data
.
forms
)
{
return
scope
;
}
if
(
!
data
.
forms
)
{
return
scope
;
}
// prepare scope form, schema and model from response object
angular
.
forEach
(
data
.
forms
,
function
(
value
,
key
)
{
...
...
@@ -40,7 +42,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
generator
.
group
=
function
(
formObject
)
{
return
formObject
;
};
generator
.
prepareFormItems
=
function
(
scope
)
{
generator
.
prepareFormItems
=
function
(
scope
)
{
/**
* prepareforms checks input types and convert if necessary
*/
...
...
@@ -52,11 +54,11 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
scope
.
model
[
v
]
=
generator
.
dateformatter
(
scope
.
model
[
v
]);
// seek for datepicker field and initialize datepicker
scope
.
$watch
(
$
(
'#'
+
v
),
function
()
{
scope
.
$watch
(
$
(
'#'
+
v
),
function
()
{
$timeout
(
function
()
{
jQuery
(
'#'
+
v
).
datepicker
({
dateFormat
:
"dd.mm.yy"
,
onSelect
:
function
(
date
)
{
onSelect
:
function
(
date
)
{
scope
.
model
[
v
]
=
date
;
}
});
...
...
@@ -89,7 +91,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
});
});
}),
onChange
:
function
(
modelValue
,
form
)
{
onChange
:
function
(
modelValue
,
form
)
{
scope
.
model
[
v
]
=
modelValue
;
}
};
...
...
@@ -114,13 +116,20 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
scope
[
k
.
type
][
k
.
title
]
=
{
title
:
k
.
title
,
form
:
[],
schema
:
{
properties
:
{},
required
:
[],
title
:
k
.
title
,
type
:
"object"
,
formType
:
k
.
type
,
model_name
:
v
},
schema
:
{
properties
:
{},
required
:
[],
title
:
k
.
title
,
type
:
"object"
,
formType
:
k
.
type
,
model_name
:
v
},
url
:
scope
.
url
};
scope
[
k
.
type
][
k
.
title
].
model
=
scope
.
model
[
v
]
!=
null
?
scope
.
model
[
v
]
:
{};
angular
.
forEach
(
k
.
schema
,
function
(
item
)
{
angular
.
forEach
(
k
.
schema
,
function
(
item
)
{
scope
[
k
.
type
][
k
.
title
].
schema
.
properties
[
item
.
name
]
=
item
;
// if model is empty object then fill it with scope model item
...
...
@@ -153,7 +162,9 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
};
generator
.
dateformatter
=
function
(
formObject
)
{
var
ndate
=
new
Date
(
formObject
);
if
(
ndate
==
'Invalid Date'
)
{
return
''
}
if
(
ndate
==
'Invalid Date'
)
{
return
''
}
var
newdatearray
=
[
ndate
.
getDate
(),
ndate
.
getMonth
(),
ndate
.
getFullYear
()];
return
newdatearray
.
join
(
'.'
);
};
...
...
@@ -214,14 +225,17 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
data
.
object_id
=
$scope
.
object_id
;
//data.form = get_diff;
}
$http
.
post
(
generator
.
makeUrl
(
$scope
.
url
),
data
)
.
success
()
.
then
(
function
(
res
){
if
(
res
.
data
.
client_cmd
){
console
.
log
(
"record fin"
);
$location
.
path
(
$scope
.
form_params
.
model
);
}
});
return
$http
.
post
(
generator
.
makeUrl
(
$scope
.
url
),
data
);
//.success(function () {
//
//})
//.then(function (res) {
// if (res.data.client_cmd) {
// console.log("record fin");
// $location.path($scope.form_params.model);
// }
//});
};
return
generator
;
});
...
...
@@ -244,9 +258,9 @@ form_generator.controller('ModalCtrl', function ($scope, $modalInstance, Generat
$scope
.
$broadcast
(
'schemaFormValidate'
);
console
.
log
(
form
.
$valid
);
//if(form.$valid){
if
(
1
==
1
)
{
// send form to modalinstance result function
$modalInstance
.
close
(
$scope
);
if
(
1
==
1
)
{
// send form to modalinstance result function
$modalInstance
.
close
(
$scope
);
}
};
...
...
@@ -284,12 +298,12 @@ form_generator.directive('modalForNodes', function ($modal) {
// subfix will be removed
//var subfix = scope.schema.title.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
if
(
childmodel
.
schema
.
formType
==
'Node'
){
if
(
childmodel
.
schema
.
formType
==
'Node'
)
{
scope
.
$parent
.
model
[
childmodel
.
schema
.
model_name
]
=
childmodel
.
model
;
}
if
(
childmodel
.
schema
.
formType
==
'ListNode'
){
if
(
childmodel
.
schema
.
formType
==
'ListNode'
)
{
debugger
;
if
(
scope
.
$parent
.
model
[
childmodel
.
schema
.
model_name
]
==
null
){
if
(
scope
.
$parent
.
model
[
childmodel
.
schema
.
model_name
]
==
null
)
{
scope
.
$parent
.
model
[
childmodel
.
schema
.
model_name
]
=
[];
}
scope
.
$parent
.
model
[
childmodel
.
schema
.
model_name
].
push
(
childmodel
.
model
);
...
...
app/zetalib/forms/form_service_test.js
View file @
5f28dc2d
...
...
@@ -18,13 +18,43 @@ describe('form service module', function () {
function
(
Generator
)
{
expect
(
Generator
.
generate
).
not
.
toBe
(
null
);
var
scope
=
{
form_params
:
{
object_id
:
'123456'
}};
var
data
=
{
forms
:
{
form
:
[
'email'
,
'id'
,
'name'
],
schema
:
{
properties
:
{
email
:
{
title
:
'email'
,
type
:
'email'
},
id
:
{
title
:
'id'
,
type
:
'int'
},
name
:
{
title
:
'name'
,
type
:
'string'
}
},
required
:
[],
type
:
'object'
,
title
:
'servicetest'
},
model
:
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
}
},
token
:
"b1d8fa68ae3d47bdb580a89f76192447"
};
var
form_json
=
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
form_params
:
{
object_id
:
'123456'
},
form
:
[
'email'
,
'id'
,
'name'
],
schema
:
{
properties
:
{
email
:
{
title
:
'email'
,
type
:
'email'
},
id
:
{
title
:
'id'
,
type
:
'number'
},
name
:
{
title
:
'name'
,
type
:
'string'
}
},
required
:
[],
type
:
'object'
,
title
:
'servicetest'
},
model
:
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
},
token
:
"b1d8fa68ae3d47bdb580a89f76192447"
,
initialModel
:
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
},
object_id
:
'123456'
};
var
form_generated
=
Generator
.
generate
(
form_json
);
var
form_generated
=
Generator
.
generate
(
scope
,
data
);
expect
(
form_generated
).
toEqual
(
form_json
);
}])
);
...
...
@@ -88,8 +118,16 @@ describe('form service module', function () {
$httpBackend
.
expectPOST
(
RESTURL
.
url
+
'student/add'
)
.
respond
(
200
,
{
data
:
'OK'
});
var
cred
=
{
email
:
'test@test.com'
};
Generator
.
submit
({
url
:
'student/add'
,
form_params
:
cred
})
var
scope
=
{
model
:
{
email
:
'test@test.com'
},
form_params
:
{
cmd
:
'add'
,
model
:
'testmodel'
},
token
:
'123456'
,
url
:
'student/add'
};
Generator
.
submit
(
scope
)
.
success
(
function
(){
})
.
then
(
function
(
data
)
{
expect
(
data
.
data
).
toEqual
({
data
:
'OK'
});
});
...
...
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