Commit b14dd974 authored by Evren Kutar's avatar Evren Kutar

#34 client cmd command parse and redirect with data to controller

route updates [regex before static urls]
parent 58f7c699
...@@ -10,45 +10,56 @@ app.config(['$routeProvider', function ($routeProvider, $route) { ...@@ -10,45 +10,56 @@ app.config(['$routeProvider', function ($routeProvider, $route) {
templateUrl: 'components/dashboard/dashboard.html', templateUrl: 'components/dashboard/dashboard.html',
controller: 'DashCtrl' controller: 'DashCtrl'
}) })
//.when('/crud/:model/:param/:id/add', { .when('/dev/settings', {
// templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/devSettings/devSettings.html',
// controller: 'CRUDAddEditCtrl' controller: 'DevSettingsCtrl'
//}) })
//.when('/crud/:model/:param/:id/edit/:key', { .when('/debug/list', {
// templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/debug/debug.html',
// controller: 'CRUDAddEditCtrl' controller: 'DebugCtrl'
//}) })
//.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'
//})
// use crud without selected user // 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', templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl' controller: 'CRUDListCtrl'
}) })
.when('/crud/:model/add', { .when('/:wf/add', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/add.html',
controller: 'CRUDAddEditCtrl' controller: 'CRUDAddEditCtrl'
}) })
.when('/crud/:model/edit/:key', { .when('/:wf/edit/:key', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/add.html',
controller: 'CRUDAddEditCtrl' controller: 'CRUDAddEditCtrl'
}) })
.when('/crud/:model/detail/:key', { .when('/:wf/detail/:key', {
templateUrl: 'components/crud/templates/show.html', templateUrl: 'components/crud/templates/show.html',
controller: 'CRUDShowCtrl' controller: 'CRUDShowCtrl'
}) })
.when('/:wf/:model', {
// wf links just need model
.when('/:model/', {
templateUrl: 'components/wf/templates/add.html', 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'}); .otherwise({redirectTo: '/dashboard'});
}]) }])
......
...@@ -9,48 +9,68 @@ ...@@ -9,48 +9,68 @@
var crud = angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService']); 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 * CRUDAddEditCtrl is a controller
* which provide a form with form generator. * which provide a form with form generator.
*/ */
crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $http, $log, $modal, $timeout, Generator, $routeParams) { crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $http, $log, $modal, $timeout, Generator, $routeParams, CrudUtility) {
$scope.url = 'crud/'; CrudUtility.generateParam($scope, $routeParams);
angular.forEach($routeParams, function (value, key) { $scope.form_params['cmd'] = 'form';
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';
}
// get form with generator // get form with generator
if ($routeParams.model) { if ($routeParams.pageData) {
console.log(Generator.getPageData());
Generator.generate($scope, Generator.getPageData());
} else {
Generator.get_form($scope); Generator.get_form($scope);
} }
$scope.onSubmit = function (form) { $scope.onSubmit = function (form) {
//$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
if (form.$valid) {
debugger; Generator.submit($scope);
//if (form.$valid) { }
Generator.submit($scope)
.success(function (data) {
})
.error(function (data) {
$scope.message = data.title;
});
//}
}; };
}); });
...@@ -59,27 +79,19 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt ...@@ -59,27 +79,19 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
* CRUD List Controller * CRUD List Controller
*/ */
crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeParams) { crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeParams, CrudUtility) {
$scope.url = 'crud/'; CrudUtility.generateParam($scope, $routeParams);
angular.forEach($routeParams, function (value, key) { $scope.form_params['cmd'] = 'list';
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.nobjects) { if ($routeParams.pageData) {
$scope.nobjects = $routeParams.nobjects; var pageData = Generator.getPageData();
$scope.model = $routeParams.model; CrudUtility.listPageItems($scope, pageData);
$scope.addLink = $routeParams.addLink; }
} else { else {
// call generator's get_list func // call generator's get_list func
Generator.get_list($scope) Generator.get_list($scope)
.then(function (res) { .then(function (res) {
$scope.nobjects = res.data.nobjects; CrudUtility.listPageItems($scope, res.Data);
$scope.model = $routeParams.model;
$scope.addLink = res.data.addLink;
}); });
} }
}); });
...@@ -87,23 +99,9 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP ...@@ -87,23 +99,9 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
/** /**
* CRUD Show Controller * CRUD Show Controller
*/ */
crud.controller('CRUDShowCtrl', function ($scope, $rootScope, $location, Generator, $routeParams) { crud.controller('CRUDShowCtrl', function ($scope, $rootScope, $location, Generator, $routeParams, CrudUtility) {
$scope.url = 'crud/'; CrudUtility.generateParam($scope, $routeParams);
$scope.form_params['cmd'] = 'show';
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
};
// call generator's get_single_item func // call generator's get_single_item func
Generator.get_single_item($scope).then(function (res) { Generator.get_single_item($scope).then(function (res) {
$scope.listobjects = {}; $scope.listobjects = {};
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
<button type="button" class="btn btn-primary">Ekle</button> <button type="button" class="btn btn-primary">Ekle</button>
</a> </a>
</h1> </h1>
<div class="row" ng-if="!nobjects[1]"> <div class="row" ng-if="!objects[1]">
<div class="col-md-12"> <div class="col-md-12">
<p class="no-content">Listelenecek içerik yok.</p> <p class="no-content">Listelenecek içerik yok.</p>
</div> </div>
</div> </div>
<div class="tablescroll" ng-if="nobjects[1]"> <div class="tablescroll" ng-if="objects[1]">
<table class="table table-bordered" style="background-color:#fff;"> <table class="table table-bordered" style="background-color:#fff;">
<thead> <thead>
<tr> <tr>
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
Hepsini Seç Hepsini Seç
</label> </label>
</td> </td>
<td ng-repeat="value in nobjects[0]" ng-if="nobjects[0]!='-1' && !$last">{{ value }}</td> <td ng-repeat="value in objects[0]" ng-if="objects[0]!='-1' && !$last">{{ value }}</td>
<td ng-if="nobjects[0]=='-1'">{{ model }}</td> <td ng-if="objects[0]=='-1'">{{ model }}</td>
<td>action</td> <td>action</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="object in nobjects" ng-if="$index>0"> <tr ng-repeat="object in objects" ng-if="$index>0">
<td width="60"> <td width="60">
<label> <label>
<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;"> <input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">
...@@ -33,16 +33,16 @@ ...@@ -33,16 +33,16 @@
</td> </td>
<td scope="row" style="text-align:center">{{$index}}</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 --> <!-- 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"> <td ng-repeat="field in object.fields track by $index" ng-if="objects[0]=='-1'">
<a ng-href="{{object[object.length-1].detailLink}}">{{object[1]}}</a> <a ng-href="{{object.detailLink}}">{{field}}</a>
</td> </td>
<td ng-repeat="(key,value) in object track by $index" ng-if="nobjects[0]!='-1' && $index>0 && !$last"> <td ng-repeat="(key,value) in object.fieldset track by $index" ng-if="objects[0]!='-1'">
<a ng-href="{{object[object.length-1].detailLink}}" ng-if="$index==1">{{object[key]}}</a> <a ng-href="{{object.detailLink}}" ng-if="$index==1">{{object.fields}}</a>
<span ng-if="$index!=1">{{object[key]}}</span> <span ng-if="$index!=1">{{object[key]}}</span>
</td> </td>
<td> <td>
<a ng-href="{{object[object.length-1].editLink}}">Edit</a> <a ng-href="{{object.editLink}}">Edit</a>
<br> <br>
</td> </td>
</tr> </tr>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<br/> <br/>
<hr/> <hr/>
<div class="btn-group" ng-if="nobjects[1]"> <div class="btn-group" ng-if="objects[1]">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false"> aria-expanded="false">
İşlemler <span class="caret"></span> İşlemler <span class="caret"></span>
......
...@@ -7,105 +7,9 @@ ...@@ -7,105 +7,9 @@
'use strict'; 'use strict';
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/debug/list', {
templateUrl: 'components/debug/debug.html',
controller: 'DebugCtrl'
});
}]);
angular.module('ulakbus.debug', ['ngRoute']) angular.module('ulakbus.debug', ['ngRoute'])
.controller('DebugCtrl', function ($scope, $rootScope, $location) { .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 = $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
...@@ -7,14 +7,6 @@ ...@@ -7,14 +7,6 @@
'use strict'; 'use strict';
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/dev/settings', {
templateUrl: 'components/devSettings/devSettings.html',
controller: 'DevSettingsCtrl'
});
}]);
angular.module('ulakbus.devSettings', ['ngRoute']) angular.module('ulakbus.devSettings', ['ngRoute'])
.controller('DevSettingsCtrl', function ($scope, $cookies, $rootScope, RESTURL) { .controller('DevSettingsCtrl', function ($scope, $cookies, $rootScope, RESTURL) {
......
...@@ -54,7 +54,6 @@ app.directive('headerNotification', function ($http, $rootScope, $cookies, $inte ...@@ -54,7 +54,6 @@ app.directive('headerNotification', function ($http, $rootScope, $cookies, $inte
// check notifications every 5 seconds // check notifications every 5 seconds
$interval(function () { $interval(function () {
if ($cookies.get("notificate") == "on") { if ($cookies.get("notificate") == "on") {
console.log('get notification call - interval');
$scope.getNotifications(); $scope.getNotifications();
} }
}, 5000); }, 5000);
...@@ -130,7 +129,6 @@ app.directive('headerSubMenu', function ($location) { ...@@ -130,7 +129,6 @@ app.directive('headerSubMenu', function ($location) {
replace: true, replace: true,
link: function ($scope) { link: function ($scope) {
$scope.$on('$routeChangeStart', function () { $scope.$on('$routeChangeStart', function () {
console.log($location.path()); //
$scope.style = $location.path() === '/dashboard' ? 'width:calc(100% - 300px);' : 'width:%100 !important;'; $scope.style = $location.path() === '/dashboard' ? 'width:calc(100% - 300px);' : 'width:%100 !important;';
}); });
} }
...@@ -201,6 +199,14 @@ app.directive('sidebar', ['$location', function () { ...@@ -201,6 +199,14 @@ app.directive('sidebar', ['$location', function () {
angular.forEach(items, function (value, key) { angular.forEach(items, function (value, key) {
newItems[value.kategori] = newItems[value.kategori] || []; newItems[value.kategori] = newItems[value.kategori] || [];
value['baseCategory'] = baseCategory; 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); newItems[value.kategori].push(value);
}); });
return newItems; return newItems;
...@@ -210,7 +216,8 @@ app.directive('sidebar', ['$location', function () { ...@@ -210,7 +216,8 @@ app.directive('sidebar', ['$location', function () {
$scope.allMenuItems[key] = reGroupMenuItems(value, key); $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); $rootScope.$broadcast("authz", data);
$scope.menuItems = $scope.prepareMenu({other: $scope.allMenuItems.other}); $scope.menuItems = $scope.prepareMenu({other: $scope.allMenuItems.other});
......
...@@ -24,26 +24,12 @@ ...@@ -24,26 +24,12 @@
</a> </a>
<ul class="nav nav-second-level" ng-class="{hidden: $root.collapsed}"> <ul class="nav nav-second-level" ng-class="{hidden: $root.collapsed}">
<li ng-repeat="(k, v) in item"> <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> ng-click="breadcrumb([key, v.text], $event)">{{v.text}}</a>
<a ng-if="v['baseCategory'] == 'ogrenci' || v['baseCategory'] == 'personel'" <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> ng-click="breadcrumb([key, v.text], $event)">{{v.text}}</a>
</li> </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>-->
<!--&lt;!&ndash; /.nav-third-level &ndash;&gt;-->
<!--</li>-->
</ul> </ul>
<!-- /.nav-second-level --> <!-- /.nav-second-level -->
</li> </li>
......
This diff is collapsed.
...@@ -173,21 +173,9 @@ describe('form service module', function () { ...@@ -173,21 +173,9 @@ describe('form service module', function () {
$httpBackend.expectGET(RESTURL.url + 'test/personel') $httpBackend.expectGET(RESTURL.url + 'test/personel')
.respond(200, { .respond(200, {
items: { items: {
"client_cmd": "list_objects", "client_cmd": "list_objects",
"objects": [
{
"data": {
"ad": "firstname",
"tckn": "12345678910",
"timestamp": 1444133895215881,
"soyad": "lastname",
"deleted": false,
"cep_telefonu": "05552223333"
},
"key": "4MsKRH9435cdKOzKCITNPml5bhB"
}],
"is_login": true, "is_login": true,
"nobjects":[ "objects":[
["Ad\u0131", "Soyad\u0131", "TC No", "Durum"], ["Ad\u0131", "Soyad\u0131", "TC No", "Durum"],
["4MsKRH9435cdKOzKCITNPml5bhB", "firstname", "lastname", "dksoap", false] ["4MsKRH9435cdKOzKCITNPml5bhB", "firstname", "lastname", "dksoap", false]
], ],
......
{ {
"name": "ulakbus-ui", "name": "ulakbus-ui",
"description": "UI project for ulakbüs", "description": "UI for Ulakbüs",
"version": "0.0.1", "version": "0.4.0",
"homepage": "https://github.com/zetaops/ulakbus-ui", "homepage": "https://github.com/zetaops/ulakbus-ui",
"license": "GPL", "license": "GPL",
"private": false, "private": false,
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
"font-awesome": "4.3.0", "font-awesome": "4.3.0",
"angular-schema-form": "0.8.3", "angular-schema-form": "0.8.3",
"angular-loading-bar": "~0.8.0", "angular-loading-bar": "~0.8.0",
"angular-ui-router": "~0.2.15",
"angular-toggle-switch": "~1.2.1", "angular-toggle-switch": "~1.2.1",
"metisMenu": "~1.1.3", "metisMenu": "~1.1.3",
"angular-chart.js": "~0.5.2", "angular-chart.js": "~0.5.2",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment