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
c7aeefcf
Commit
c7aeefcf
authored
Nov 25, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolves #50
resolves #51
parent
06e1a5d4
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
126 additions
and
71 deletions
+126
-71
app.js
app/app.js
+2
-2
crud_controller.js
app/components/crud/crud_controller.js
+50
-35
crud.html
app/components/crud/templates/crud.html
+0
-1
list.html
app/components/crud/templates/list.html
+4
-3
main.js
app/main.js
+2
-2
form_service.js
app/zetalib/form_service.js
+45
-14
form_service_test.js
app/zetalib/form_service_test.js
+13
-7
app.js
dist/app.js
+1
-1
app.css
dist/css/app.css
+1
-1
templates.js
dist/templates.js
+8
-5
No files found.
app/app.js
View file @
c7aeefcf
...
...
@@ -25,7 +25,7 @@ var app = angular.module(
'ulakbus.version'
,
//'schemaForm',
'gettext'
,
'ulakbus.uitemplates'
,
'ulakbus.uitemplates'
]).
/**
* RESTURL is the url of rest api to talk
...
...
@@ -33,7 +33,7 @@ var app = angular.module(
*/
constant
(
"RESTURL"
,
(
function
()
{
// todo: below backendurl definition is for development purpose and will be deleted
var
backendurl
=
location
.
href
.
indexOf
(
'nightly'
)
?
"//nightly.api.ulakbus.net/"
:
"//api.ulakbus.net/"
;
var
backendurl
=
location
.
href
.
indexOf
(
'nightly'
)
>
-
1
?
"//nightly.api.ulakbus.net/"
:
"//api.ulakbus.net/"
;
if
(
document
.
cookie
.
indexOf
(
"backendurl"
)
>
-
1
)
{
var
cookiearray
=
document
.
cookie
.
split
(
';'
);
angular
.
forEach
(
cookiearray
,
function
(
item
)
{
...
...
app/components/crud/crud_controller.js
View file @
c7aeefcf
...
...
@@ -72,8 +72,14 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
});
angular
.
forEach
(
value
.
fields
,
function
(
v
,
k
)
{
if
(
value
.
actions
.
length
>
0
&&
linkIndexes
.
fields
){
scope
.
objects
[
key
].
fields
[
k
]
=
{
type
:
linkIndexes
.
fields
.
indexOf
(
k
)
>
-
1
?
'link'
:
'str'
,
content
:
v
,
cmd
:
linkIndexes
.
cmd
};
}
else
{
scope
.
objects
[
key
].
fields
[
k
]
=
{
type
:
linkIndexes
.
fields
.
indexOf
(
k
)
>
-
1
?
'link'
:
'str'
,
content
:
v
,
cmd
:
linkIndexes
.
cmd
,
mode
:
linkIndexes
.
mode
};
}
else
{
scope
.
objects
[
key
].
fields
[
k
]
=
{
type
:
'str'
,
content
:
v
};
}
});
...
...
@@ -128,7 +134,31 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
$scope
.
reload_cmd
=
data
;
$scope
.
reload
({});
});
if
(
$routeParams
.
cmd
===
'show'
)
{
// we use form generator for generic forms. this makes form's scope to confuse on the path to generate form
// object by its name. to manage to locate the form to controllers scope we use a directive called form locator
// a bit dirty way to find form working on but solves our problem
$scope
.
$on
(
'formLocator'
,
function
(
event
)
{
$scope
.
formgenerated
=
event
.
targetScope
.
formgenerated
;
});
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
Generator
.
submit
(
$scope
);
}
};
$scope
.
do_action
=
function
(
key
,
cmd
,
mode
)
{
Generator
.
doItemAction
(
$scope
,
key
,
cmd
,
mode
||
'normal'
);
};
$scope
.
getNumber
=
function
(
num
)
{
return
new
Array
(
num
);
};
//
$scope
.
showCmd
=
function
()
{
CrudUtility
.
generateParam
(
$scope
,
$routeParams
,
$routeParams
.
cmd
);
// todo: refactor createListObjects func
var
createListObjects
=
function
()
{
...
...
@@ -155,9 +185,8 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
});
}
createListObjects
();
}
if
(
$routeParams
.
cmd
===
'form'
||
$routeParams
.
cmd
===
'list'
)
{
};
$scope
.
listFormCmd
=
function
()
{
// function to set scope objects
var
setpageobjects
=
function
(
data
)
{
CrudUtility
.
listPageItems
(
$scope
,
data
);
...
...
@@ -179,39 +208,25 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
CrudUtility
.
generateParam
(
$scope
,
$routeParams
,
$routeParams
.
cmd
);
Generator
.
get_wf
(
$scope
);
}
// we use form generator for generic forms. this makes form's scope to confuse on the path to generate form
// object by its name. to manage to locate the form to controllers scope we use a directive called form locator
// a bit dirty way to find form working on but solves our problem
$scope
.
$on
(
'formLocator'
,
function
(
event
)
{
$scope
.
formgenerated
=
event
.
targetScope
.
formgenerated
;
});
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
Generator
.
submit
(
$scope
);
}
};
$scope
.
do_action
=
function
(
key
,
cmd
)
{
Generator
.
doItemAction
(
$scope
,
key
,
cmd
);
};
$scope
.
getNumber
=
function
(
num
)
{
return
new
Array
(
num
);
};
}
if
(
$routeParams
.
cmd
===
'reload'
)
{
};
$scope
.
reloadCmd
=
function
()
{
$scope
.
reload
({});
}
if
(
$routeParams
.
cmd
===
'reset'
)
{
};
$scope
.
resetCmd
=
function
()
{
delete
$scope
.
token
;
$scope
.
cmd
=
'reset'
;
Generator
.
get_wf
(
$scope
);
}
};
var
executeCmd
=
{
show
:
$scope
.
showCmd
,
list
:
$scope
.
listFormCmd
,
form
:
$scope
.
listFormCmd
,
reload
:
$scope
.
reloadCmd
,
reset
:
$scope
.
resetCmd
};
return
executeCmd
[
$routeParams
.
cmd
]();
})
...
...
app/components/crud/templates/crud.html
View file @
c7aeefcf
<crud-show-directive
ng-if=
"object"
></crud-show-directive>
<crud-form-directive
ng-if=
"forms"
></crud-form-directive>
<hr
class=
"col-md-12"
>
<crud-list-directive
ng-if=
"objects"
></crud-list-directive>
\ No newline at end of file
app/components/crud/templates/list.html
View file @
c7aeefcf
<div
class=
"starter-template container"
>
<search-directive
ng-if=
"meta['allow_search']===true"
></search-directive>
<div
class=
"clearfix"
></div>
<
h1>
{{form_params.model || form_params.wf}}
</h1
>
<
!--<h1>{{form_params.model || form_params.wf}}</h1>--
>
<div
class=
"row"
ng-if=
"!objects[1]"
>
<div
class=
"col-md-12"
>
<p
class=
"no-content"
>
Listelenecek içerik yok.
</p>
...
...
@@ -34,13 +34,14 @@
<td
ng-repeat=
"field in object.fields track by $index"
>
<a
ng-href=
"javascript:void(0)"
ng-if=
"field.type==='link'"
ng-click=
"do_action(object.key, field.cmd)"
>
{{field.content}}
</a>
ng-click=
"do_action(object.key, field.cmd
, field.mode
)"
>
{{field.content}}
</a>
<span
ng-if=
"field.type==='str'"
>
{{field.content}}
</span>
</td>
<td>
<button
class=
"btn btn-primary"
style=
"margin-right: 5px;"
ng-repeat=
"action in object.actions"
ng-if=
"action.show_as==='button'"
ng-click=
"do_action(object.key, action.cmd)"
>
{{action
ng-if=
"action.show_as==='button'"
ng-click=
"do_action(object.key, action.cmd, action.mode)"
>
{{action
.name}}
</button>
<br>
...
...
app/main.js
View file @
c7aeefcf
...
...
@@ -29,7 +29,7 @@ var app = angular.module(
'templates-prod'
,
// @endif
// @if NODE_ENV='DEVELOPMENT'
'ulakbus.uitemplates'
,
'ulakbus.uitemplates'
// @endif
]).
/**
...
...
@@ -38,7 +38,7 @@ var app = angular.module(
*/
constant
(
"RESTURL"
,
(
function
()
{
// todo: below backendurl definition is for development purpose and will be deleted
var
backendurl
=
location
.
href
.
indexOf
(
'nightly'
)
?
"//nightly.api.ulakbus.net/"
:
"//api.ulakbus.net/"
;
var
backendurl
=
location
.
href
.
indexOf
(
'nightly'
)
>
-
1
?
"//nightly.api.ulakbus.net/"
:
"//api.ulakbus.net/"
;
if
(
document
.
cookie
.
indexOf
(
"backendurl"
)
>
-
1
)
{
var
cookiearray
=
document
.
cookie
.
split
(
';'
);
angular
.
forEach
(
cookiearray
,
function
(
item
)
{
...
...
app/zetalib/form_service.js
View file @
c7aeefcf
...
...
@@ -13,7 +13,7 @@
* The `formService` module provides generic services for auto generated forms.
*
*/
angular
.
module
(
'formService'
,
[])
angular
.
module
(
'formService'
,
[
'ui.bootstrap'
])
/**
* @name Generator
...
...
@@ -98,6 +98,16 @@ angular.module('formService', [])
* @returns {*}
*/
generator
.
prepareFormItems
=
function
(
scope
)
{
// todo: remove after backend fix
angular
.
forEach
(
scope
.
form
,
function
(
value
,
key
)
{
if
(
value
.
type
===
'select'
)
{
scope
.
schema
.
properties
[
value
.
key
].
type
=
'select'
;
scope
.
schema
.
properties
[
value
.
key
].
titleMap
=
value
.
titleMap
;
scope
.
form
[
key
]
=
value
.
key
;
}
});
angular
.
forEach
(
scope
.
schema
.
properties
,
function
(
v
,
k
)
{
// generically change _id fields model value
...
...
@@ -126,7 +136,7 @@ angular.module('formService', [])
scope
.
form
[
scope
.
form
.
indexOf
(
k
)]
=
{
type
:
v
.
type
,
title
:
v
.
title
,
style
:
"btn-primary hide"
+
(
buttonPositions
[
v
.
position
]
||
"move-to-bottom"
),
style
:
"btn-primary hide
"
+
(
buttonPositions
[
v
.
position
]
||
"move-to-bottom"
),
onClick
:
function
()
{
delete
scope
.
form_params
.
cmd
;
delete
scope
.
form_params
.
flow
;
...
...
@@ -144,17 +154,18 @@ angular.module('formService', [])
}
}
};
// replace buttons according to their position values
$timeout
(
function
()
{
var
buttonsToBottom
=
angular
.
element
(
document
.
querySelector
(
'.move-to-bottom'
));
angular
.
element
(
document
.
querySelector
(
'.buttons-on-bottom'
)).
append
(
buttonsToBottom
);
var
buttonsToTop
=
angular
.
element
(
document
.
querySelector
(
'.move-to-top'
));
angular
.
element
(
document
.
querySelector
(
'.buttons-on-bottom'
)).
append
(
buttonsToTop
);
buttons
.
removeClass
(
'hide'
);
buttonsToBottom
.
removeClass
(
'hide'
);
buttonsToTop
.
removeClass
(
'hide'
);
});
}
// check if type is date and if type date found change it to string
if
(
v
.
type
===
'date'
)
{
v
.
type
=
'string'
;
scope
.
model
[
k
]
=
generator
.
dateformatter
(
scope
.
model
[
k
]);
...
...
@@ -180,13 +191,12 @@ angular.module('formService', [])
if
(
v
.
type
===
'text_general'
)
{
v
.
type
=
'string'
;
v
[
"x-schema-form"
]
=
{
"type"
:
"textarea"
,
"type"
:
"textarea"
//"placeholder": ""
}
}
// if type is model use foreignKey.html template to show them
if
(
v
.
type
===
'model'
)
{
var
formitem
=
scope
.
form
[
scope
.
form
.
indexOf
(
k
)];
...
...
@@ -209,7 +219,15 @@ angular.module('formService', [])
"name"
:
item
.
value
});
}
// get selected item from titleMap using model value
if
(
item
.
key
===
scope
.
model
[
k
])
{
formitem
.
selected_item
=
{
value
:
item
.
key
,
name
:
item
.
value
};}
});
// after rendering change input value to model value
scope
.
$watch
(
document
.
querySelector
(
'input[name='
+
v
.
model_name
+
']'
),
function
(){
angular
.
element
(
document
.
querySelector
(
'input[name='
+
v
.
model_name
+
']'
)).
val
(
formitem
.
selected_item
.
name
);
}
);
}),
onSelect
:
function
(
item
)
{
scope
.
model
[
k
]
=
item
.
value
;
...
...
@@ -289,13 +307,24 @@ angular.module('formService', [])
return
newdatearray
.
join
(
'.'
);
}
};
generator
.
doItemAction
=
function
(
$scope
,
key
,
cmd
)
{
$scope
.
form_params
.
cmd
=
cmd
;
$scope
.
form_params
.
object_id
=
key
;
$scope
.
form_params
.
param
=
$scope
.
param
;
$scope
.
form_params
.
id
=
$scope
.
param_id
;
$scope
.
form_params
.
token
=
$scope
.
token
;
generator
.
get_wf
(
$scope
);
generator
.
doItemAction
=
function
(
$scope
,
key
,
cmd
,
mode
)
{
// mode could be in ['normal', 'modal', 'new'] . the default mode is 'normal' and it loads data on same
// tab without modal. 'modal' will use modal to manipulate data and do all actions in that modal. 'new'
// will be open new page with response data
var
_do
=
{
normal
:
function
(){
$log
.
debug
(
'normal mode starts'
);
$scope
.
form_params
.
cmd
=
cmd
;
$scope
.
form_params
.
object_id
=
key
;
$scope
.
form_params
.
param
=
$scope
.
param
;
$scope
.
form_params
.
id
=
$scope
.
param_id
;
$scope
.
form_params
.
token
=
$scope
.
token
;
return
generator
.
get_wf
(
$scope
);
},
modal
:
function
(){
$log
.
debug
(
'modal mode is not not ready'
);},
new
:
function
(){
$log
.
debug
(
'new mode is not not ready'
);}
};
return
_do
[
mode
]();
};
generator
.
get_form
=
function
(
scope
)
{
...
...
@@ -380,6 +409,7 @@ angular.module('formService', [])
/**
* pathDecider is used to redirect related path by looking up the data in response
* @param client_cmd
* @param $scope
* @param data
*/
...
...
@@ -391,7 +421,8 @@ angular.module('formService', [])
* redirectTo function redirects to related controller and path with given data
* before redirect setPageData must be called and pageData need to be defined
* otherwise redirected path will call api for its data
* @param scope, page
* @param scope
* @param page
*/
function
redirectTo
(
scope
,
page
)
{
var
pathUrl
=
'/'
+
scope
.
form_params
.
wf
;
...
...
app/zetalib/form_service_test.js
View file @
c7aeefcf
...
...
@@ -6,15 +6,19 @@
* (GPLv3). See LICENSE.txt for details.
*/
'use strict'
;
describe
(
'form service module'
,
function
()
{
beforeEach
(
module
(
'ulakbus'
));
beforeEach
(
module
(
'formService'
));
var
location
;
beforeEach
(
inject
(
function
(
$location
)
{
beforeEach
(
inject
(
function
(
$location
,
$injector
)
{
location
=
$location
;
// Set up the mock http service responses
$httpBackend
=
$injector
.
get
(
'$httpBackend'
);
// backend definition common for all tests
authRequestHandler
=
$httpBackend
.
when
(
'GET'
,
/
\.[
0-9a-z
]
+$/i
)
.
respond
({
userId
:
'userX'
},
{
'A-Token'
:
'xxx'
});
}));
describe
(
'form service'
,
function
()
{
...
...
@@ -23,7 +27,7 @@ describe('form service module', function () {
function
(
Generator
)
{
expect
(
Generator
.
group
).
not
.
toBe
(
null
);
var
generated_url
=
Generator
.
makeUrl
({
url
:
'test'
,
form_params
:
{}});
expect
(
generated_url
).
toEqual
(
"//
nightly.
api.ulakbus.net/test/"
);
expect
(
generated_url
).
toEqual
(
"//api.ulakbus.net/test/"
);
}])
);
...
...
@@ -175,15 +179,15 @@ describe('form service module', function () {
it
(
'should get list'
,
inject
(
function
(
Generator
,
$httpBackend
,
RESTURL
)
{
$httpBackend
.
expect
GET
(
RESTURL
.
url
+
'test/personel'
)
$httpBackend
.
expect
POST
(
RESTURL
.
url
+
'test/personel'
,
{
cmd
:
'list'
,
model
:
"personel"
,
object_id
:
"5821bc25a90aa1"
}
)
.
respond
(
200
,
{
items
:
{
"client_cmd"
:
"list_objects"
,
"is_login"
:
true
,
"objects"
:[
[
"Ad
\
u0131"
,
"Soyad
\
u0131"
,
"TC No"
,
"Durum"
],
[
"Ad
\
u0131"
,
"Soyad
\
u0131"
,
"TC No"
,
"Durum"
],
[
"4MsKRH9435cdKOzKCITNPml5bhB"
,
"firstname"
,
"lastname"
,
"dksoap"
,
false
]
],
],
"token"
:
"0122b2843f504c15821bc25a90aa1370"
}
});
...
...
@@ -317,10 +321,12 @@ describe('form service module', function () {
object_id
:
'xxx11'
,
wf
:
'testModel'
};
scope
.
url
=
'test'
;
Generator
.
get_wf
(
scope
);
$httpBackend
.
flush
();
expect
(
location
.
path
()).
toEqual
(
'/testModel/testModel/
add
'
);
expect
(
location
.
path
()).
toEqual
(
'/testModel/testModel/
do/f
'
);
})
);
...
...
dist/app.js
View file @
c7aeefcf
This diff is collapsed.
Click to expand it.
dist/css/app.css
View file @
c7aeefcf
...
...
@@ -1649,7 +1649,7 @@ table.dataTable thead .sorting:after {
}
/* end page transitions */
.move
tobottom
{
.move
-to-bottom
,
.move-to-top
{
margin-right
:
10px
!important
;
}
...
...
dist/templates.js
View file @
c7aeefcf
...
...
@@ -24,7 +24,6 @@ angular.module("components/crud/templates/crud.html", []).run(["$templateCache",
$templateCache
.
put
(
"components/crud/templates/crud.html"
,
"<crud-show-directive ng-if=
\"
object
\"
></crud-show-directive>
\n
"
+
"<crud-form-directive ng-if=
\"
forms
\"
></crud-form-directive>
\n
"
+
"<hr class=
\"
col-md-12
\"
>
\n
"
+
"<crud-list-directive ng-if=
\"
objects
\"
></crud-list-directive>"
);
}]);
...
...
@@ -33,6 +32,8 @@ angular.module("components/crud/templates/form.html", []).run(["$templateCache",
"<div class=
\"
container
\"
>
\n
"
+
" <h1>{{ schema.title }}</h1>
\n
"
+
"
\n
"
+
" <div class=
\"
buttons-on-top
\"
></div>
\n
"
+
"
\n
"
+
" <form id=
\"
formgenerated
\"
name=
\"
formgenerated
\"
sf-schema=
\"
schema
\"
sf-form=
\"
form
\"
sf-model=
\"
model
\"\n
"
+
" ng-submit=
\"
onSubmit(formgenerated)
\"
form-locator></form>
\n
"
+
"
\n
"
+
...
...
@@ -66,6 +67,7 @@ angular.module("components/crud/templates/form.html", []).run(["$templateCache",
" </div>
\n
"
+
"
\n
"
+
" <div class=
\"
buttons-on-bottom
\"
></div>
\n
"
+
"
\n
"
+
"</div>"
);
}]);
...
...
@@ -74,7 +76,7 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
"<div class=
\"
starter-template container
\"
>
\n
"
+
" <search-directive ng-if=
\"
meta['allow_search']===true
\"
></search-directive>
\n
"
+
" <div class=
\"
clearfix
\"
></div>
\n
"
+
" <
h1>{{form_params.model || form_params.wf}}</h1
>
\n
"
+
" <
!--<h1>{{form_params.model || form_params.wf}}</h1>--
>
\n
"
+
" <div class=
\"
row
\"
ng-if=
\"
!objects[1]
\"
>
\n
"
+
" <div class=
\"
col-md-12
\"
>
\n
"
+
" <p class=
\"
no-content
\"
>Listelenecek içerik yok.</p>
\n
"
+
...
...
@@ -107,13 +109,14 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
" <td ng-repeat=
\"
field in object.fields track by $index
\"
>
\n
"
+
" <a ng-href=
\"
javascript:void(0)
\"\n
"
+
" ng-if=
\"
field.type==='link'
\"\n
"
+
" ng-click=
\"
do_action(object.key, field.cmd)
\"
>{{field.content}}</a>
\n
"
+
" ng-click=
\"
do_action(object.key, field.cmd
, field.mode
)
\"
>{{field.content}}</a>
\n
"
+
" <span ng-if=
\"
field.type==='str'
\"
>{{field.content}}</span>
\n
"
+
" </td>
\n
"
+
"
\n
"
+
" <td>
\n
"
+
" <button class=
\"
btn btn-primary
\"
style=
\"
margin-right: 5px;
\"
ng-repeat=
\"
action in object.actions
\"\n
"
+
" ng-if=
\"
action.show_as==='button'
\"
ng-click=
\"
do_action(object.key, action.cmd)
\"
>{{action
\n
"
+
" ng-if=
\"
action.show_as==='button'
\"\n
"
+
" ng-click=
\"
do_action(object.key, action.cmd, action.mode)
\"
>{{action
\n
"
+
" .name}}
\n
"
+
" </button>
\n
"
+
" <br>
\n
"
+
...
...
@@ -1455,7 +1458,7 @@ angular.module("shared/templates/foreignKey.html", []).run(["$templateCache", fu
" sf-changed=
\"
form
\"\n
"
+
" class=
\"
form-control {{form.fieldHtmlClass}}
\"\n
"
+
" schema-validate=
\"
form
\"\n
"
+
" name=
\"
{{form.model_name}}
\"
/>
\n
"
+
" name=
\"
{{form.model_name}}
\"
value=
\"
{{form.selected_item}}
\"
/>
\n
"
+
" </div>
\n
"
+
"
\n
"
+
" <!--<select ng-model=
\"
$$value$$
\"
-->
\n
"
+
...
...
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