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
b14dd974
Commit
b14dd974
authored
Nov 16, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#34 client cmd command parse and redirect with data to controller
route updates [regex before static urls]
parent
58f7c699
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
259 additions
and
310 deletions
+259
-310
app_routes.js
app/app_routes.js
+35
-24
crud_controller.js
app/components/crud/crud_controller.js
+62
-64
list.html
app/components/crud/templates/list.html
+11
-11
debug_controller.js
app/components/debug/debug_controller.js
+0
-96
devSettings_controller.js
app/components/devSettings/devSettings_controller.js
+0
-8
directives.js
app/shared/directives.js
+10
-3
sidebar.html
app/shared/templates/directives/sidebar.html
+2
-16
form_service.js
app/zetalib/forms/form_service.js
+135
-71
form_service_test.js
app/zetalib/forms/form_service_test.js
+2
-14
bower.json
bower.json
+2
-3
No files found.
app/app_routes.js
View file @
b14dd974
...
...
@@ -10,45 +10,56 @@ app.config(['$routeProvider', function ($routeProvider, $route) {
templateUrl
:
'components/dashboard/dashboard.html'
,
controller
:
'DashCtrl'
})
//.when('/crud/:model/:param/:id/add', {
// templateUrl: 'components/crud/templates/add.html',
// controller: 'CRUDAddEditCtrl'
//})
//.when('/crud/:model/:param/:id/edit/:key', {
// templateUrl: 'components/crud/templates/add.html',
// controller: 'CRUDAddEditCtrl'
//})
//.when('/crud/:model/:param/:id/list', {
// templateUrl: 'components/crud/templates/list.html',
// controller: 'CRUDListCtrl'
//})
//.when('/crud/:model/:param/:id/detail/:key', {
// templateUrl: 'components/crud/templates/show.html',
// controller: 'CRUDShowCtrl'
//})
.
when
(
'/dev/settings'
,
{
templateUrl
:
'components/devSettings/devSettings.html'
,
controller
:
'DevSettingsCtrl'
})
.
when
(
'/debug/list'
,
{
templateUrl
:
'components/debug/debug.html'
,
controller
:
'DebugCtrl'
})
// use crud without selected user
.
when
(
'/crud/:model/list'
,
{
// important: regex urls must be defined later than static ones
.
when
(
'/:wf/'
,
{
templateUrl
:
'components/wf/templates/add.html'
,
controller
:
'CRUDCtrl'
})
.
when
(
'/:wf/list'
,
{
templateUrl
:
'components/crud/templates/list.html'
,
controller
:
'CRUDListCtrl'
})
.
when
(
'/
crud/:model
/add'
,
{
.
when
(
'/
:wf
/add'
,
{
templateUrl
:
'components/crud/templates/add.html'
,
controller
:
'CRUDAddEditCtrl'
})
.
when
(
'/
crud/:model
/edit/:key'
,
{
.
when
(
'/
:wf
/edit/:key'
,
{
templateUrl
:
'components/crud/templates/add.html'
,
controller
:
'CRUDAddEditCtrl'
})
.
when
(
'/
crud/:model
/detail/:key'
,
{
.
when
(
'/
:wf
/detail/:key'
,
{
templateUrl
:
'components/crud/templates/show.html'
,
controller
:
'CRUDShowCtrl'
})
// wf links just need model
.
when
(
'/:model/'
,
{
.
when
(
'/:wf/:model'
,
{
templateUrl
:
'components/wf/templates/add.html'
,
controller
:
'WFAddEditCtrl'
controller
:
'CRUDCtrl'
})
.
when
(
'/:wf/:model/list'
,
{
templateUrl
:
'components/crud/templates/list.html'
,
controller
:
'CRUDListCtrl'
})
.
when
(
'/:wf/:model/add'
,
{
templateUrl
:
'components/crud/templates/add.html'
,
controller
:
'CRUDAddEditCtrl'
})
.
when
(
'/:wf/:model/edit/:key'
,
{
templateUrl
:
'components/crud/templates/add.html'
,
controller
:
'CRUDAddEditCtrl'
})
.
when
(
'/:wf/:model/detail/:key'
,
{
templateUrl
:
'components/crud/templates/show.html'
,
controller
:
'CRUDShowCtrl'
})
.
otherwise
({
redirectTo
:
'/dashboard'
});
}])
...
...
app/components/crud/crud_controller.js
View file @
b14dd974
...
...
@@ -9,48 +9,68 @@
var
crud
=
angular
.
module
(
'ulakbus.crud'
,
[
'ui.bootstrap'
,
'schemaForm'
,
'formService'
]);
/**
*
*/
crud
.
service
(
'CrudUtility'
,
function
()
{
return
{
generateParam
:
function
(
scope
,
routeParams
)
{
// define api request url path
scope
.
url
=
routeParams
.
wf
;
angular
.
forEach
(
routeParams
,
function
(
value
,
key
)
{
if
(
key
.
indexOf
(
'_id'
)
>
-
1
)
{
scope
.
param
=
key
;
scope
.
param_id
=
value
;
}
});
scope
.
form_params
=
{
model
:
routeParams
.
model
,
param
:
scope
.
param
,
id
:
scope
.
param_id
,
wf
:
routeParams
.
wf
,
object_id
:
routeParams
.
key
};
return
scope
;
},
listPageItems
:
function
(
scope
,
pageData
)
{
angular
.
forEach
([
'objects'
,
'model'
,
'addLink'
],
function
(
value
,
key
)
{
scope
[
value
]
=
pageData
[
value
];
});
}
}
});
/**
*
*/
crud
.
controller
(
'CRUDCtrl'
,
function
(
$scope
,
$routeParams
,
Generator
,
CrudUtility
)
{
CrudUtility
.
generateParam
(
$scope
,
$routeParams
);
Generator
.
get_wf
(
$scope
);
});
/**
* CRUDAddEditCtrl is a controller
* which provide a form with form generator.
*/
crud
.
controller
(
'CRUDAddEditCtrl'
,
function
(
$scope
,
$rootScope
,
$location
,
$http
,
$log
,
$modal
,
$timeout
,
Generator
,
$routeParams
)
{
$scope
.
url
=
'crud/'
;
crud
.
controller
(
'CRUDAddEditCtrl'
,
function
(
$scope
,
$rootScope
,
$location
,
$http
,
$log
,
$modal
,
$timeout
,
Generator
,
$routeParams
,
CrudUtility
)
{
CrudUtility
.
generateParam
(
$scope
,
$routeParams
)
;
angular
.
forEach
(
$routeParams
,
function
(
value
,
key
)
{
if
(
key
.
indexOf
(
'_id'
)
>
-
1
)
{
$scope
.
param
=
key
;
$scope
.
param_id
=
value
;
}
});
$scope
.
form_params
=
{
'model'
:
$routeParams
.
model
,
param
:
$scope
.
param
,
id
:
$scope
.
param_id
};
if
(
$routeParams
.
key
)
{
$scope
.
form_params
[
'object_id'
]
=
$routeParams
.
key
;
$scope
.
form_params
[
'cmd'
]
=
'edit'
;
}
else
{
$scope
.
form_params
[
'cmd'
]
=
'add'
;
}
$scope
.
form_params
[
'cmd'
]
=
'form'
;
// get form with generator
if
(
$routeParams
.
model
)
{
if
(
$routeParams
.
pageData
)
{
console
.
log
(
Generator
.
getPageData
());
Generator
.
generate
(
$scope
,
Generator
.
getPageData
());
}
else
{
Generator
.
get_form
(
$scope
);
}
$scope
.
onSubmit
=
function
(
form
)
{
//$scope.$broadcast('schemaFormValidate');
debugger
;
//if (form.$valid) {
Generator
.
submit
(
$scope
)
.
success
(
function
(
data
)
{
})
.
error
(
function
(
data
)
{
$scope
.
message
=
data
.
title
;
});
//}
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
Generator
.
submit
(
$scope
);
}
};
});
...
...
@@ -59,27 +79,19 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
* CRUD List Controller
*/
crud
.
controller
(
'CRUDListCtrl'
,
function
(
$scope
,
$rootScope
,
Generator
,
$routeParams
)
{
$scope
.
url
=
'crud/'
;
angular
.
forEach
(
$routeParams
,
function
(
value
,
key
)
{
if
(
key
.
indexOf
(
'_id'
)
>
-
1
)
{
$scope
.
param
=
key
;
$scope
.
param_id
=
value
;
}
});
$scope
.
form_params
=
{
'model'
:
$routeParams
.
model
,
param
:
$scope
.
param
,
id
:
$scope
.
param_id
};
crud
.
controller
(
'CRUDListCtrl'
,
function
(
$scope
,
$rootScope
,
Generator
,
$routeParams
,
CrudUtility
)
{
CrudUtility
.
generateParam
(
$scope
,
$routeParams
);
$scope
.
form_params
[
'cmd'
]
=
'list'
;
if
(
$routeParams
.
nobjects
)
{
$scope
.
nobjects
=
$routeParams
.
nobjects
;
$scope
.
model
=
$routeParams
.
model
;
$scope
.
addLink
=
$routeParams
.
addLink
;
}
else
{
if
(
$routeParams
.
pageData
)
{
var
pageData
=
Generator
.
getPageData
()
;
CrudUtility
.
listPageItems
(
$scope
,
pageData
)
;
}
else
{
// call generator's get_list func
Generator
.
get_list
(
$scope
)
.
then
(
function
(
res
)
{
$scope
.
nobjects
=
res
.
data
.
nobjects
;
$scope
.
model
=
$routeParams
.
model
;
$scope
.
addLink
=
res
.
data
.
addLink
;
CrudUtility
.
listPageItems
(
$scope
,
res
.
Data
);
});
}
});
...
...
@@ -87,23 +99,9 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
/**
* CRUD Show Controller
*/
crud
.
controller
(
'CRUDShowCtrl'
,
function
(
$scope
,
$rootScope
,
$location
,
Generator
,
$routeParams
)
{
$scope
.
url
=
'crud/'
;
angular
.
forEach
(
$routeParams
,
function
(
value
,
key
)
{
if
(
key
.
indexOf
(
'_id'
)
>
-
1
)
{
$scope
.
param
=
key
;
$scope
.
param_id
=
value
;
}
});
$scope
.
form_params
=
{
"id"
:
$scope
.
param_id
,
"object_id"
:
$routeParams
.
key
,
"cmd"
:
"show"
,
param
:
$scope
.
param
,
"model"
:
$routeParams
.
model
};
crud
.
controller
(
'CRUDShowCtrl'
,
function
(
$scope
,
$rootScope
,
$location
,
Generator
,
$routeParams
,
CrudUtility
)
{
CrudUtility
.
generateParam
(
$scope
,
$routeParams
);
$scope
.
form_params
[
'cmd'
]
=
'show'
;
// call generator's get_single_item func
Generator
.
get_single_item
(
$scope
).
then
(
function
(
res
)
{
$scope
.
listobjects
=
{};
...
...
app/components/crud/templates/list.html
View file @
b14dd974
...
...
@@ -4,12 +4,12 @@
<button
type=
"button"
class=
"btn btn-primary"
>
Ekle
</button>
</a>
</h1>
<div
class=
"row"
ng-if=
"!
n
objects[1]"
>
<div
class=
"row"
ng-if=
"!objects[1]"
>
<div
class=
"col-md-12"
>
<p
class=
"no-content"
>
Listelenecek içerik yok.
</p>
</div>
</div>
<div
class=
"tablescroll"
ng-if=
"
n
objects[1]"
>
<div
class=
"tablescroll"
ng-if=
"objects[1]"
>
<table
class=
"table table-bordered"
style=
"background-color:#fff;"
>
<thead>
<tr>
...
...
@@ -19,13 +19,13 @@
Hepsini Seç
</label>
</td>
<td
ng-repeat=
"value in
nobjects[0]"
ng-if=
"n
objects[0]!='-1' && !$last"
>
{{ value }}
</td>
<td
ng-if=
"
n
objects[0]=='-1'"
>
{{ model }}
</td>
<td
ng-repeat=
"value in
objects[0]"
ng-if=
"
objects[0]!='-1' && !$last"
>
{{ value }}
</td>
<td
ng-if=
"objects[0]=='-1'"
>
{{ model }}
</td>
<td>
action
</td>
</tr>
</thead>
<tbody>
<tr
ng-repeat=
"object in
n
objects"
ng-if=
"$index>0"
>
<tr
ng-repeat=
"object in objects"
ng-if=
"$index>0"
>
<td
width=
"60"
>
<label>
<input
type=
"checkbox"
style=
"zoom:1.5; margin:5px 0 0 8px;"
>
...
...
@@ -33,16 +33,16 @@
</td>
<td
scope=
"row"
style=
"text-align:center"
>
{{$index}}
</td>
<!-- below 2 of object will not be listed there for ng repeat loops 2 less -->
<td
ng-repeat=
"
k in object track by $index"
ng-if=
"nobjects[0]=='-1' && $index>0 && !$last
"
>
<a
ng-href=
"{{object
[object.length-1].detailLink}}"
>
{{object[1]
}}
</a>
<td
ng-repeat=
"
field in object.fields track by $index"
ng-if=
"objects[0]=='-1'
"
>
<a
ng-href=
"{{object
.detailLink}}"
>
{{field
}}
</a>
</td>
<td
ng-repeat=
"(key,value) in object
track by $index"
ng-if=
"nobjects[0]!='-1' && $index>0 && !$last
"
>
<a
ng-href=
"{{object
[object.length-1].detailLink}}"
ng-if=
"$index==1"
>
{{object[key]
}}
</a>
<td
ng-repeat=
"(key,value) in object
.fieldset track by $index"
ng-if=
"objects[0]!='-1'
"
>
<a
ng-href=
"{{object
.detailLink}}"
ng-if=
"$index==1"
>
{{object.fields
}}
</a>
<span
ng-if=
"$index!=1"
>
{{object[key]}}
</span>
</td>
<td>
<a
ng-href=
"{{object
[object.length-1]
.editLink}}"
>
Edit
</a>
<a
ng-href=
"{{object.editLink}}"
>
Edit
</a>
<br>
</td>
</tr>
...
...
@@ -52,7 +52,7 @@
<br/>
<hr/>
<div
class=
"btn-group"
ng-if=
"
n
objects[1]"
>
<div
class=
"btn-group"
ng-if=
"objects[1]"
>
<button
type=
"button"
class=
"btn btn-default dropdown-toggle"
data-toggle=
"dropdown"
aria-haspopup=
"true"
aria-expanded=
"false"
>
İşlemler
<span
class=
"caret"
></span>
...
...
app/components/debug/debug_controller.js
View file @
b14dd974
...
...
@@ -7,105 +7,9 @@
'use strict'
;
app
.
config
([
'$routeProvider'
,
function
(
$routeProvider
)
{
$routeProvider
.
when
(
'/debug/list'
,
{
templateUrl
:
'components/debug/debug.html'
,
controller
:
'DebugCtrl'
});
}]);
angular
.
module
(
'ulakbus.debug'
,
[
'ngRoute'
])
.
controller
(
'DebugCtrl'
,
function
(
$scope
,
$rootScope
,
$location
)
{
// todo: define breadcrumb
//$scope.$on("debug_queries", function (event, data) {
// $scope.debug_queries.push(data);
//});
$scope
.
debug_queries
=
$rootScope
.
debug_queries
;
//$scope.debug_queries = [{
// "url": "http://ulakbus-remote-dev.zetaops.io:18188/notify",
// "queries": [
// {
// "TIMESTAMP": 1446666305.753408,
// "TIME": 0.0362,
// "BUCKET": "models_personel",
// "QUERY_PARAMS": {
// "sort": "timestamp desc",
// "rows": 1000
// },
// "QUERY": "tckn:123* AND -deleted:True"
// },
// {
// "TIMESTAMP": 1446666492.017113,
// "BUCKET": "models_kurum_disi_gorevlendirme_bilgileri",
// "SERIALIZATION": 0.00078,
// "SAVE_IS_NEW": true,
// "KEY": "ZZjOPrcdfW1w8EASYRastvEWKaA",
// "TIME": 0.01684
// },
// {
// "TIMESTAMP": 1446666305.789678,
// "BUCKET": "models_personel",
// "KEY": "TILjcZZpBzbVXdFMCWkYjNMnDSi",
// "TIME": 0.00425
// },
// {
// "TIMESTAMP": 1446666305.798089,
// "BUCKET": "models_personel",
// "KEY": "2yBUSlyr2WQp4l6xL79ehPCDR35",
// "TIME": 0.00335
// },
// {
// "TIMESTAMP": 1446666305.810038,
// "BUCKET": "models_personel",
// "KEY": "WTbiwac9tjtEQ2TZxmJh7eSb3CF",
// "TIME": 0.00548
// },
// {
// "TIMESTAMP": 1446666305.819372,
// "BUCKET": "models_personel",
// "KEY": "FmV5il0bAIwCBE1Zuk63WXfC9Vd",
// "TIME": 0.00305
// },
// {
// "TIMESTAMP": 1446666305.82646,
// "BUCKET": "models_personel",
// "KEY": "6SZXvENlJKuDtD8e9b1mHxDqc4Y",
// "TIME": 0.00305
// },
// {
// "TIMESTAMP": 1446666305.832966,
// "BUCKET": "models_personel",
// "KEY": "YPjWATvtR54JdY5BxVWYUh5AbeB",
// "TIME": 0.04506
// },
// {
// "TIMESTAMP": 1446666305.882205,
// "BUCKET": "models_personel",
// "KEY": "UGYo52etHUacK5uP1v91oGX8JDU",
// "TIME": 0.01335
// },
// {
// "TIMESTAMP": 1446666305.899335,
// "BUCKET": "models_personel",
// "KEY": "doZJrm6phbFwyuWZk9LYf05u4z",
// "TIME": 0.00291
// },
// {
// "TIMESTAMP": 1446666305.906138,
// "BUCKET": "models_personel",
// "KEY": "CZDKGx57MKufxrZNgNb2j9EQ9Mz",
// "TIME": 0.0098
// },
// {
// "TIMESTAMP": 1446666305.919088,
// "BUCKET": "models_personel",
// "KEY": "BW6nTAnpBQAIuj8LL98wOV1DJMC",
// "TIME": 0.00257
// }
// ]}]
});
\ No newline at end of file
app/components/devSettings/devSettings_controller.js
View file @
b14dd974
...
...
@@ -7,14 +7,6 @@
'use strict'
;
app
.
config
([
'$routeProvider'
,
function
(
$routeProvider
)
{
$routeProvider
.
when
(
'/dev/settings'
,
{
templateUrl
:
'components/devSettings/devSettings.html'
,
controller
:
'DevSettingsCtrl'
});
}]);
angular
.
module
(
'ulakbus.devSettings'
,
[
'ngRoute'
])
.
controller
(
'DevSettingsCtrl'
,
function
(
$scope
,
$cookies
,
$rootScope
,
RESTURL
)
{
...
...
app/shared/directives.js
View file @
b14dd974
...
...
@@ -54,7 +54,6 @@ app.directive('headerNotification', function ($http, $rootScope, $cookies, $inte
// check notifications every 5 seconds
$interval
(
function
()
{
if
(
$cookies
.
get
(
"notificate"
)
==
"on"
)
{
console
.
log
(
'get notification call - interval'
);
$scope
.
getNotifications
();
}
},
5000
);
...
...
@@ -130,7 +129,6 @@ app.directive('headerSubMenu', function ($location) {
replace
:
true
,
link
:
function
(
$scope
)
{
$scope
.
$on
(
'$routeChangeStart'
,
function
()
{
console
.
log
(
$location
.
path
());
//
$scope
.
style
=
$location
.
path
()
===
'/dashboard'
?
'width:calc(100% - 300px);'
:
'width:%100 !important;'
;
});
}
...
...
@@ -201,6 +199,14 @@ app.directive('sidebar', ['$location', function () {
angular
.
forEach
(
items
,
function
(
value
,
key
)
{
newItems
[
value
.
kategori
]
=
newItems
[
value
.
kategori
]
||
[];
value
[
'baseCategory'
]
=
baseCategory
;
// todo: generate urls here
//value['url'] = '#/wf' + value.wf;
//if (value.model) {
// value['url'] += '/model/' + value.model;
//}
value
[
'wf'
]
=
value
.
url
.
split
(
'/'
)[
0
];
value
[
'model'
]
=
value
.
url
.
split
(
'/'
)[
1
];
newItems
[
value
.
kategori
].
push
(
value
);
});
return
newItems
;
...
...
@@ -210,7 +216,8 @@ app.directive('sidebar', ['$location', function () {
$scope
.
allMenuItems
[
key
]
=
reGroupMenuItems
(
value
,
key
);
});
// broadcast for authorized menu items, consume in dashboard
// broadcast for authorized menu items, consume in dashboard to show search inputs and/or
// related items
$rootScope
.
$broadcast
(
"authz"
,
data
);
$scope
.
menuItems
=
$scope
.
prepareMenu
({
other
:
$scope
.
allMenuItems
.
other
});
...
...
app/shared/templates/directives/sidebar.html
View file @
b14dd974
...
...
@@ -24,26 +24,12 @@
</a>
<ul
class=
"nav nav-second-level"
ng-class=
"{hidden: $root.collapsed}"
>
<li
ng-repeat=
"(k, v) in item"
>
<a
ng-if=
"v['baseCategory'] == 'other'"
ng-href=
"#{{v.url}}"
<a
ng-if=
"v['baseCategory'] == 'other'"
ng-href=
"#{{v.url}}"
ng-
ng-click=
"breadcrumb([key, v.text], $event)"
>
{{v.text}}
</a>
<a
ng-if=
"v['baseCategory'] == 'ogrenci' || v['baseCategory'] == 'personel'"
ng-href=
"#
{{v.url}}/list
?{{v.param}}={{$root.selectedUser.key}}"
ng-href=
"#
/{{v.wf}}/{{v.model}}
?{{v.param}}={{$root.selectedUser.key}}"
ng-click=
"breadcrumb([key, v.text], $event)"
>
{{v.text}}
</a>
</li>
<!--<li ng-repeat="(key2, item2) in item">-->
<!--<a href="#">{{key2}} <span class="fa arrow"></span></a>-->
<!--<ul class="nav nav-third-level collapse in" aria-expanded="true">-->
<!--<li ng-repeat="(k,v) in item2">-->
<!--<a ng-if="key == 'other'" ng-href="#{{v.url}}"-->
<!--ng-click="breadcrumb([key, v.text], $event)">{{v.text}}</a>-->
<!--<a ng-if="key == 'ogrenci' || key == 'personel'"-->
<!--ng-href="#{{v.url}}/list?{{v.param}}={{$root.selectedUser.key}}"-->
<!--ng-click="breadcrumb([key, v.text], $event)">{{v.text}}</a>-->
<!--</li>-->
<!--</ul>-->
<!--<!– /.nav-third-level –>-->
<!--</li>-->
</ul>
<!-- /.nav-second-level -->
</li>
...
...
app/zetalib/forms/form_service.js
View file @
b14dd974
...
...
@@ -11,7 +11,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
var
generator
=
{};
generator
.
makeUrl
=
function
(
scope
)
{
var
getparams
=
scope
.
form_params
.
param
?
"?"
+
scope
.
form_params
.
param
+
"="
+
scope
.
form_params
.
id
:
""
;
return
RESTURL
.
url
+
scope
.
url
+
(
scope
.
form_params
.
model
||
''
)
+
getparams
;
return
RESTURL
.
url
+
scope
.
url
+
'/'
+
(
scope
.
form_params
.
model
||
''
)
+
getparams
;
};
generator
.
generate
=
function
(
scope
,
data
)
{
...
...
@@ -25,6 +25,8 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
scope
[
key
]
=
data
.
forms
[
key
];
});
scope
.
client_cmd
=
data
.
client_cmd
;
scope
.
token
=
data
.
token
;
// initialModel will be used in formDiff when submiting the form to submit only
...
...
@@ -100,7 +102,11 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
scope
.
form_params
[
"flow"
]
=
v
.
flow
;
}
scope
.
model
[
k
]
=
1
;
generator
.
submit
(
scope
);
// todo: test it
scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
scope
.
formgenerated
.
$valid
)
{
generator
.
submit
(
scope
);
}
}
};
$timeout
(
function
()
{
...
...
@@ -123,7 +129,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
dateFormat
:
"dd.mm.yy"
,
onSelect
:
function
(
date
,
inst
)
{
scope
.
model
[
k
]
=
date
;
scope
.
$broadcast
(
'schemaForm.error.'
+
k
,
'tv4-302'
,
true
);
scope
.
$broadcast
(
'schemaForm.error.'
+
k
,
'tv4-302'
,
true
);
}
});
});
...
...
@@ -157,8 +163,8 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
model_name
:
v
.
model_name
,
titleMap
:
generator
.
get_list
(
modelscope
).
then
(
function
(
res
)
{
formitem
.
titleMap
=
[];
angular
.
forEach
(
res
.
data
.
n
objects
,
function
(
item
)
{
if
(
item
!==
res
.
data
.
n
objects
[
0
])
{
angular
.
forEach
(
res
.
data
.
objects
,
function
(
item
)
{
if
(
item
!==
res
.
data
.
objects
[
0
])
{
formitem
.
titleMap
.
push
({
"value"
:
item
[
0
],
"name"
:
item
[
1
]
+
' '
+
(
item
[
2
]
?
item
[
2
]
:
''
)
+
'...'
...
...
@@ -240,27 +246,34 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
if
(
ndate
==
'Invalid Date'
)
{
return
''
;
}
else
{
var
newdatearray
=
[
ndate
.
getDate
(),
ndate
.
getMonth
(),
ndate
.
getFullYear
()];
var
newdatearray
=
[
ndate
.
getDate
(),
ndate
.
getMonth
()
+
1
,
ndate
.
getFullYear
()];
return
newdatearray
.
join
(
'.'
);
}
};
generator
.
itemLinksGenerator
=
function
(
scope
,
itemlist
)
{
angular
.
forEach
(
itemlist
.
n
objects
,
function
(
value
,
key
)
{
angular
.
forEach
(
itemlist
.
objects
,
function
(
value
,
key
)
{
function
makelink
(
page
)
{
if
(
value
===
'-1'
&&
page
!==
'add/'
)
{
return
;
}
var
link
=
"#"
+
scope
.
url
+
scope
.
form_params
.
model
;
var
link
=
"#"
+
scope
.
url
;
if
(
scope
.
form_params
)
{
if
(
scope
.
form_params
.
model
)
{
link
+=
'/'
+
scope
.
form_params
.
model
;
}
}
link
+=
"/"
+
page
;
if
(
page
===
'edit/'
||
page
===
'detail/'
)
{
link
+=
"/"
+
page
+
value
[
0
];
}
if
(
page
===
'add/'
)
{
link
+=
"/add"
;
link
+=
value
.
key
;
}
if
(
scope
.
form_params
.
param
)
{
link
+=
"?"
+
scope
.
form_params
.
param
+
"="
+
scope
.
form_params
.
id
;
if
(
scope
.
form_params
)
{
if
(
scope
.
form_params
.
param
)
{
link
+=
"?"
+
scope
.
form_params
.
param
+
"="
+
scope
.
form_params
.
id
;
}
}
return
link
;
}
...
...
@@ -271,7 +284,8 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
}
if
(
value
!==
'-1'
)
{
value
.
push
({
detailLink
:
makelink
(
"detail/"
),
editLink
:
makelink
(
"edit/"
)});
value
.
detailLink
=
makelink
(
"detail/"
);
value
.
editLink
=
makelink
(
"edit/"
);
}
});
};
...
...
@@ -299,6 +313,14 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
return
res
;
});
};
generator
.
get_wf
=
function
(
scope
)
{
return
$http
.
post
(
generator
.
makeUrl
(
scope
),
scope
.
form_params
)
.
then
(
function
(
res
)
{
//generator.generate(scope, res.data);
generator
.
pathDecider
(
res
.
data
.
client_cmd
,
scope
,
res
.
data
);
});
};
generator
.
isValidEmail
=
function
(
email
)
{
var
re
=
/^
([\w
-
]
+
(?:\.[\w
-
]
+
)
*
)
@
((?:[\w
-
]
+
\.)
*
\w[\w
-
]{0,66})\.([
a-z
]{2,6}(?:\.[
a-z
]{2})?)
$/i
;
return
re
.
test
(
email
);
...
...
@@ -331,67 +353,112 @@ form_generator.factory('Generator', function ($http, $q, $timeout, $location, $c
return
deferred
.
promise
;
}
};
// custom form submit for custom submit buttons
generator
.
genericSubmit
=
function
(
$scope
,
data
)
{
return
$http
.
post
(
generator
.
makePostUrl
(
$scope
),
data
);
};
generator
.
submit
=
function
(
$scope
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
$scope
.
formgenerated
.
$valid
)
{
/**
* pageData object is moving object from response to controller
* with this object controller will not need to call the api for response object to work on to
* @type {{}}
*/
generator
.
pageData
=
{};
generator
.
getPageData
=
function
()
{
return
generator
.
pageData
;
};
generator
.
setPageData
=
function
(
value
)
{
generator
.
pageData
=
value
;
};
// todo: diff for all submits to recognize form change. if no change returns to view with no submit
angular
.
forEach
(
$scope
.
ListNode
,
function
(
value
,
key
)
{
$scope
.
model
[
key
]
=
value
.
model
;
});
angular
.
forEach
(
$scope
.
Node
,
function
(
value
,
key
)
{
$scope
.
model
[
key
]
=
value
.
model
;
});
var
data
=
{
"form"
:
$scope
.
model
,
//"subcmd": "do_list",
"model"
:
$scope
.
form_params
.
model
,
"token"
:
$scope
.
token
};
if
(
$scope
.
form_params
.
cmd
)
{
data
[
"cmd"
]
=
$scope
.
form_params
.
cmd
;
}
if
(
$scope
.
form_params
.
flow
)
{
data
[
"flow"
]
=
$scope
.
form_params
.
flow
;
}
if
(
$scope
.
object_id
)
{
//var get_diff = FormDiff.get_diff($scope.model, $scope.initialModel);
data
.
object_id
=
$scope
.
object_id
;
//data.form = get_diff;
/**
* pathDecider is used to redirect related path by looking up the data in response
* @param $scope
* @param data
*/
generator
.
pathDecider
=
function
(
client_cmd
,
$scope
,
data
)
{
/**
* 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
* @param page
*/
function
redirectTo
(
scope
,
page
){
var
pathUrl
=
scope
.
form_params
.
wf
;
if
(
scope
.
form_params
.
model
)
{
pathUrl
+=
'/'
+
scope
.
form_params
.
model
+
'/'
+
page
;
}
else
{
pathUrl
+=
'/'
+
page
;
}
$location
.
path
(
pathUrl
).
search
(
angular
.
fromJson
({
pageData
:
true
}));
}
if
(
client_cmd
.
indexOf
(
'form'
)
>
-
1
&&
client_cmd
.
indexOf
(
'list'
)
<
0
)
{
generator
.
setPageData
(
data
);
redirectTo
(
$scope
,
'add'
);
}
return
$http
.
post
(
generator
.
makeUrl
(
$scope
),
data
)
.
success
(
function
(
data
)
{
// if return data consists forms key then trigger redraw the form with updated data
if
(
data
.
forms
)
{
delete
$scope
.
form
,
$scope
.
model
,
$scope
.
schema
,
$scope
.
form_params
.
cmd
;
generator
.
generate
(
$scope
,
data
);
$scope
.
$broadcast
(
'schemaFormRedraw'
)
}
if
(
client_cmd
.
indexOf
(
'list'
)
>
-
1
&&
client_cmd
.
indexOf
(
'form'
)
<
0
)
{
data
[
$scope
.
form_params
.
param
]
=
$scope
.
form_params
.
id
;
data
[
'model'
]
=
$scope
.
form_params
.
model
;
data
[
'wf'
]
=
$scope
.
form_params
.
wf
;
// if submit returns nobjects after save
if
(
data
.
nobjects
)
{
generator
.
itemLinksGenerator
(
$scope
,
data
);
data
[
$scope
.
form_params
.
param
]
=
$scope
.
form_params
.
id
;
$location
.
path
(
'/crud/'
+
$scope
.
form_params
.
model
+
'/list'
).
search
(
angular
.
fromJson
(
data
));
}
generator
.
setPageData
(
data
);
generator
.
itemLinksGenerator
(
$scope
,
data
);
// if submit returns msgbox after save
if
(
data
.
msgbox
)
{
$scope
.
msgbox
=
data
.
msgbox
;
var
newElement
=
$compile
(
"<msgbox ></msgbox>"
)(
$scope
);
angular
.
element
(
document
.
querySelector
(
'.main.ng-scope'
)).
children
().
remove
();
angular
.
element
(
document
.
querySelector
(
'.main.ng-scope'
)).
append
(
newElement
);
}
redirectTo
(
$scope
,
'list'
);
}
});
if
(
client_cmd
.
indexOf
(
'form'
)
>
-
1
&&
client_cmd
.
indexOf
(
'list'
)
>
-
1
)
{
// todo: will be tested
generator
.
generate
(
$scope
,
data
);
generator
.
itemLinksGenerator
(
$scope
,
data
);
data
[
$scope
.
form_params
.
param
]
=
$scope
.
form_params
.
id
;
redirectTo
(
$scope
,
'formwithlist'
);
}
//todo: msgbox make it work
// if submit returns msgbox after save
//if (data.msgbox) {
// $scope.msgbox = data.msgbox;
// var newElement = $compile("<msgbox ></msgbox>")($scope);
// angular.element(document.querySelector('.main.ng-scope')).children().remove();
// angular.element(document.querySelector('.main.ng-scope')).append(newElement);
//}
};
generator
.
submit
=
function
(
$scope
)
{
// todo: diff for all submits to recognize form change. if no change returns to view with no submit
angular
.
forEach
(
$scope
.
ListNode
,
function
(
value
,
key
)
{
$scope
.
model
[
key
]
=
value
.
model
;
});
angular
.
forEach
(
$scope
.
Node
,
function
(
value
,
key
)
{
$scope
.
model
[
key
]
=
value
.
model
;
});
var
data
=
{
"form"
:
$scope
.
model
,
"token"
:
$scope
.
token
};
if
(
$scope
.
form_params
.
model
)
{
data
[
"model"
]
=
$scope
.
form_params
.
model
;
}
if
(
$scope
.
form_params
.
cmd
)
{
data
[
"cmd"
]
=
$scope
.
form_params
.
cmd
;
}
if
(
$scope
.
form_params
.
flow
)
{
data
[
"flow"
]
=
$scope
.
form_params
.
flow
;
}
// todo: remove object_id ?? why?
if
(
$scope
.
object_id
)
{
//var get_diff = FormDiff.get_diff($scope.model, $scope.initialModel);
data
.
object_id
=
$scope
.
object_id
;
//data.form = get_diff;
}
return
$http
.
post
(
generator
.
makeUrl
(
$scope
),
data
)
.
success
(
function
(
data
)
{
generator
.
pathDecider
(
data
.
client_cmd
,
$scope
,
data
);
});
};
return
generator
;
});
...
...
@@ -412,10 +479,7 @@ form_generator.controller('ModalCtrl', function ($scope, $modalInstance, Generat
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
console
.
log
(
form
.
$valid
);
//if(form.$valid){
// todo: change to if form valid
if
(
1
===
1
)
{
if
(
form
.
$valid
)
{
// send form to modalinstance result function
$modalInstance
.
close
(
$scope
);
...
...
app/zetalib/forms/form_service_test.js
View file @
b14dd974
...
...
@@ -173,21 +173,9 @@ describe('form service module', function () {
$httpBackend
.
expectGET
(
RESTURL
.
url
+
'test/personel'
)
.
respond
(
200
,
{
items
:
{
"client_cmd"
:
"list_objects"
,
"objects"
:
[
{
"data"
:
{
"ad"
:
"firstname"
,
"tckn"
:
"12345678910"
,
"timestamp"
:
1444133895215881
,
"soyad"
:
"lastname"
,
"deleted"
:
false
,
"cep_telefonu"
:
"05552223333"
},
"key"
:
"4MsKRH9435cdKOzKCITNPml5bhB"
}],
"client_cmd"
:
"list_objects"
,
"is_login"
:
true
,
"
n
objects"
:[
"objects"
:[
[
"Ad
\
u0131"
,
"Soyad
\
u0131"
,
"TC No"
,
"Durum"
],
[
"4MsKRH9435cdKOzKCITNPml5bhB"
,
"firstname"
,
"lastname"
,
"dksoap"
,
false
]
],
...
...
bower.json
View file @
b14dd974
{
"name"
:
"ulakbus-ui"
,
"description"
:
"UI
project for u
lakbüs"
,
"version"
:
"0.
0.1
"
,
"description"
:
"UI
for U
lakbüs"
,
"version"
:
"0.
4.0
"
,
"homepage"
:
"https://github.com/zetaops/ulakbus-ui"
,
"license"
:
"GPL"
,
"private"
:
false
,
...
...
@@ -18,7 +18,6 @@
"font-awesome"
:
"4.3.0"
,
"angular-schema-form"
:
"0.8.3"
,
"angular-loading-bar"
:
"~0.8.0"
,
"angular-ui-router"
:
"~0.2.15"
,
"angular-toggle-switch"
:
"~1.2.1"
,
"metisMenu"
:
"~1.1.3"
,
"angular-chart.js"
:
"~0.5.2"
,
...
...
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