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
15b9af5a
Commit
15b9af5a
authored
Dec 28, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refs #320
fixes #321
parent
75dae973
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
48 deletions
+106
-48
form_service.js
app/zetalib/form_service.js
+39
-31
form_service_test.js
app/zetalib/form_service_test.js
+62
-13
app.js
dist/app.js
+3
-3
components.js
dist/bower_components/components.js
+1
-1
karma.conf.js
karma.conf.js
+1
-0
No files found.
app/zetalib/form_service.js
View file @
15b9af5a
...
...
@@ -14,13 +14,16 @@
*
*/
angular
.
module
(
'formService'
,
[
'ui.bootstrap'
])
.
service
(
'Moment'
,
function
(){
return
window
.
moment
;
})
/**
* @name Generator
* @description
* form service's Generator factory service handles all generic form operations
*/
.
factory
(
'Generator'
,
function
(
$http
,
$q
,
$timeout
,
$sce
,
$location
,
$route
,
$compile
,
$log
,
RESTURL
,
$rootScope
)
{
.
factory
(
'Generator'
,
function
(
$http
,
$q
,
$timeout
,
$sce
,
$location
,
$route
,
$compile
,
$log
,
RESTURL
,
$rootScope
,
Moment
)
{
var
generator
=
{};
/**
* @name makeUrl
...
...
@@ -647,7 +650,8 @@ angular.module('formService', ['ui.bootstrap'])
if
(
isNaN
(
ndate
))
{
return
''
;
}
else
{
var
newdatearray
=
moment
(
ndate
).
format
(
'DD.MM.YYYY'
);
var
newdatearray
=
Moment
(
ndate
).
format
(
'DD.MM.YYYY'
);
$log
.
debug
(
'date formatted: '
,
newdatearray
);
return
newdatearray
;
}
};
...
...
@@ -739,30 +743,30 @@ angular.module('formService', ['ui.bootstrap'])
generator
.
isValidDate
=
function
(
dateValue
)
{
return
!
isNaN
(
Date
.
parse
(
dateValue
));
};
generator
.
asyncValidators
=
{
emailNotValid
:
function
(
value
)
{
var
deferred
=
$q
.
defer
();
$timeout
(
function
()
{
if
(
generator
.
isValidEmail
(
value
))
{
deferred
.
resolve
();
}
else
{
deferred
.
reject
();
}
},
500
);
return
deferred
.
promise
;
},
tcNoNotValid
:
function
(
value
)
{
var
deferred
=
$q
.
defer
();
$timeout
(
function
()
{
if
(
generator
.
isValidTCNo
(
value
))
{
deferred
.
resolve
();
}
else
{
deferred
.
reject
();
}
},
500
);
return
deferred
.
promise
;
}
};
//
generator.asyncValidators = {
//
emailNotValid: function (value) {
//
var deferred = $q.defer();
//
$timeout(function () {
//
if (generator.isValidEmail(value)) {
//
deferred.resolve();
//
} else {
//
deferred.reject();
//
}
//
}, 500);
//
return deferred.promise;
//
},
//
tcNoNotValid: function (value) {
//
var deferred = $q.defer();
//
$timeout(function () {
//
if (generator.isValidTCNo(value)) {
//
deferred.resolve();
//
} else {
//
deferred.reject();
//
}
//
}, 500);
//
return deferred.promise;
//
}
//
};
/**
...
...
@@ -838,13 +842,17 @@ angular.module('formService', ['ui.bootstrap'])
generator
.
get_diff
=
function
(
obj1
,
obj2
)
{
var
result
=
{};
for
(
key
in
obj1
)
{
if
(
obj2
[
key
]
!=
obj1
[
key
])
result
[
key
]
=
obj1
[
key
];
if
(
typeof
obj2
[
key
]
==
'array'
&&
typeof
obj1
[
key
]
==
'array'
)
angular
.
forEach
(
obj1
,
function
(
value
,
key
)
{
if
(
obj2
[
key
]
!=
obj1
[
key
])
{
result
[
key
]
=
angular
.
copy
(
obj1
[
key
])
}
if
(
obj2
[
key
].
constructor
===
Array
&&
obj1
[
key
].
constructor
===
Array
)
{
result
[
key
]
=
arguments
.
callee
(
obj1
[
key
],
obj2
[
key
]);
if
(
typeof
obj2
[
key
]
==
'object'
&&
typeof
obj1
[
key
]
==
'object'
)
}
if
(
obj2
[
key
].
constructor
===
Object
&&
obj1
[
key
].
constructor
===
Object
)
{
result
[
key
]
=
arguments
.
callee
(
obj1
[
key
],
obj2
[
key
]);
}
}
});
return
result
;
};
...
...
app/zetalib/form_service_test.js
View file @
15b9af5a
...
...
@@ -11,6 +11,7 @@ describe('form service module', function () {
beforeEach
(
module
(
'ulakbus'
));
beforeEach
(
module
(
'formService'
));
var
location
;
beforeEach
(
inject
(
function
(
$location
,
$injector
)
{
location
=
$location
;
...
...
@@ -153,7 +154,7 @@ describe('form service module', function () {
function
(
Generator
)
{
expect
(
Generator
.
dateformatter
).
not
.
toBe
(
null
);
var
generated_date
=
Generator
.
dateformatter
(
'2001-01-01T01:00:00Z'
);
expect
(
generated_date
).
toEqual
(
'01.1.2001'
);
expect
(
generated_date
).
toEqual
(
'01.
0
1.2001'
);
}])
);
...
...
@@ -161,14 +162,34 @@ describe('form service module', function () {
function
(
Generator
)
{
expect
(
Generator
.
group
).
not
.
toBe
(
null
);
var
group_json
=
{
group_objects
:
{
1
:
[
'email'
,
'name'
],
2
:
[
'password'
]
}
var
scope
=
{
form
:
[
'email'
,
'id'
,
'name'
,
'save'
],
schema
:
{
properties
:
{
email
:
{
title
:
'email'
,
type
:
'email'
},
id
:
{
title
:
'id'
,
type
:
'int'
},
name
:
{
title
:
'name'
,
type
:
'string'
},
save
:
{
title
:
'save'
,
type
:
'submit'
}
},
required
:
[],
type
:
'object'
,
title
:
'servicetest'
},
grouping
:
[
{
"group_title"
:
"title-1"
,
"items"
:
[
"email"
,
"id"
],
"layout"
:
"4"
,
"collapse"
:
false
},
{
"group_title"
:
"title-2"
,
"items"
:
[
"name"
,
"save"
],
"layout"
:
"2"
,
"collapse"
:
false
}
]
};
var
grouped_form
=
Generator
.
group
(
group_json
);
expect
(
grouped_form
).
toEqual
(
group_json
);
var
grouped_scope
=
Generator
.
group
(
scope
);
expect
(
grouped_scope
.
form
[
0
].
type
).
toEqual
(
'fieldset'
);
}])
);
...
...
@@ -345,7 +366,6 @@ describe('form service module', function () {
it
(
'should get wf and redirect according to client_cmd'
,
inject
(
function
(
Generator
,
$httpBackend
,
RESTURL
)
{
$httpBackend
.
expectPOST
(
RESTURL
.
url
+
'test?test=xyz123'
)
.
respond
(
200
,
{
"client_cmd"
:
"form"
,
...
...
@@ -389,7 +409,6 @@ describe('form service module', function () {
};
scope
.
url
=
'test'
;
Generator
.
get_wf
(
scope
);
$httpBackend
.
flush
();
...
...
@@ -397,6 +416,24 @@ describe('form service module', function () {
})
);
it
(
'should get wf and put msgbox to scope'
,
inject
(
function
(
Generator
,
$httpBackend
,
RESTURL
)
{
scope
.
form_params
=
{};
$httpBackend
.
expectPOST
(
RESTURL
.
url
+
'testmsgbox'
)
.
respond
(
200
,
{
"msgbox"
:
"test message"
});
scope
.
url
=
'testmsgbox'
;
Generator
.
get_wf
(
scope
);
$httpBackend
.
flush
();
expect
(
scope
.
msgbox
).
toEqual
(
"test message"
);
})
);
it
(
'doItemAction should do given action'
,
inject
(
function
(
Generator
,
$httpBackend
,
RESTURL
)
{
$httpBackend
.
expectPOST
(
RESTURL
.
url
+
'otherwf'
)
...
...
@@ -430,10 +467,13 @@ describe('form service module', function () {
scope
.
url
=
'test'
;
Generator
.
doItemAction
(
scope
,
'testkey123'
,
'list'
,
'otherwf'
,
'normal'
);
Generator
.
doItemAction
(
scope
,
'testkey123'
,
{
cmd
:
'list'
,
wf
:
'otherwf'
,
object_key
:
'4321'
}
,
'normal'
);
$httpBackend
.
flush
();
expect
(
location
.
path
()).
toEqual
(
'/otherwf/do/f'
);
Generator
.
doItemAction
(
scope
,
'testkey123'
,
{
cmd
:
'list'
,
wf
:
'otherwf'
,
object_key
:
'4321'
},
'modal'
);
Generator
.
doItemAction
(
scope
,
'testkey123'
,
{
cmd
:
'list'
,
wf
:
'otherwf'
,
object_key
:
'4321'
},
'new'
);
})
);
...
...
@@ -443,8 +483,8 @@ describe('form service module', function () {
// test cases - testing for success
var
same_json
=
[
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
},
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
}
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
,
foo
:
{
'a'
:
1
},
foo2
:
[
1
,
2
,
3
]
},
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
,
foo
:
{
'a'
:
1
},
foo2
:
[
1
,
2
,
3
]
}
];
// test cases - testing for failure
...
...
@@ -462,10 +502,16 @@ describe('form service module', function () {
var
different_json
=
[
{},
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
}
];
var
notEqual
=
[
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'Travolta'
,
foo
:
{
'a'
:
1
,
'b'
:
2
},
foo2
:
[
1
,
2
,
3
]},
{
email
:
'test@test.com'
,
id
:
2
,
name
:
'travolta'
,
foo
:
{
'a'
:
1
},
foo2
:
[
1
,
2
,
3
]}
]
var
diff
=
{
email
:
'test1@test.com'
,
name
:
'john'
};
var
diff2
=
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
};
var
noequal
=
{
email
:
'test1@test.com'
,
id
:
2
,
name
:
'john'
};
var
nodiff
=
{};
var
same
=
Generator
.
get_diff
(
same_json
[
0
],
same_json
[
1
]);
...
...
@@ -478,6 +524,9 @@ describe('form service module', function () {
var
different2
=
Generator
.
get_diff
(
different_json
[
1
],
different_json
[
0
]);
expect
(
different2
).
toEqual
(
diff2
);
var
not_equal
=
Generator
.
get_diff
(
notEqual
[
1
],
notEqual
[
0
]);
expect
(
not_equal
).
toEqual
(
noequal
);
})
);
...
...
dist/app.js
View file @
15b9af5a
This diff is collapsed.
Click to expand it.
dist/bower_components/components.js
View file @
15b9af5a
This diff is collapsed.
Click to expand it.
karma.conf.js
View file @
15b9af5a
...
...
@@ -26,6 +26,7 @@ module.exports = function (config) {
'app/bower_components/angular-schema-form/dist/schema-form.js'
,
'app/bower_components/angular-schema-form/dist/bootstrap-decorator.min.js'
,
'app/bower_components/angular-mocks/angular-mocks.js'
,
'app/bower_components/moment/min/moment.min.js'
,
'app/app.js'
,
'app/app_routes.js'
,
'app/zetalib/**/*.js'
,
...
...
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