Commit 249c92e4 authored by Evren Kutar's avatar Evren Kutar

Merge branch 'route_fixes'

parents ed7dbd75 3e2708ab
......@@ -492,6 +492,7 @@ select {
.sidebar .nav-third-level li a {
padding-left: 52px;
font-size: 12px;
}
.sidebar-person-info {
......
......@@ -10,22 +10,42 @@ app.config(['$routeProvider', function ($routeProvider, $route) {
templateUrl: 'components/dashboard/dashboard.html',
controller: 'DashCtrl'
})
.when('/crud/add/:model/:param/:id', {
//.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'
//})
// use crud without selected user
.when('/crud/:model/list', {
templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl'
})
.when('/crud/:model/add', {
templateUrl: 'components/crud/templates/add.html',
controller: 'CRUDAddEditCtrl'
})
.when('/crud/edit/:model/:param/:id/:key', {
.when('/crud/:model/edit/:key', {
templateUrl: 'components/crud/templates/add.html',
controller: 'CRUDAddEditCtrl'
})
.when('/crud/:model/:param/:id', {
templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl'
})
.when('/crud/detail/:model/:param/:id/:key', {
.when('/crud/:model/detail/:key', {
templateUrl: 'components/crud/templates/show.html',
controller: 'CRUDShowCtrl'
})
// wf links just need model
.when('/:model/', {
templateUrl: 'components/wf/templates/add.html',
controller: 'WFAddEditCtrl'
......
......@@ -7,10 +7,8 @@
'use strict';
var crud = angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService']);
/**
* CRUDAddEditCtrl is a controller
* which provide a form with form generator.
......@@ -18,7 +16,14 @@ var crud = angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formSe
crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $http, $log, $modal, $timeout, Generator, $routeParams) {
$scope.url = 'crud/';
$scope.form_params = {'model': $routeParams.model, param: $routeParams.param, id: $routeParams.id};
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';
......@@ -56,7 +61,14 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeParams) {
$scope.url = 'crud/';
$scope.form_params = $routeParams;
angular.forEach($routeParams, function (value, key) {
if (key.indexOf('_id') > -1) {
$scope.param = key;
$scope.param_id = value;
}
});
//$scope.form_params = $routeParams;
$scope.form_params = {'model': $routeParams.model, param: $scope.param, id: $scope.param_id};
if ($routeParams.nobjects) {
$scope.nobjects = $routeParams.nobjects;
......@@ -76,19 +88,23 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
*/
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": $routeParams.id,
"id": $scope.param_id,
"object_id": $routeParams.key,
"cmd": "show",
param: $routeParams.param,
param: $scope.param,
"model": $routeParams.model
};
// call generator's get_single_item func
Generator.get_single_item($scope).then(function (res) {
// if no data to show redirect to add/edit view
//if (res.data.nobjects[0] === "-1") {
// $location.path('crud/' + $scope.form_params.model + '/' + $scope.form_params.param + '/' + $scope.form_params.id + '/edit');
//}
$scope.listobjects = {};
$scope.object = res.data.object;
......@@ -99,7 +115,6 @@ crud.controller('CRUDShowCtrl', function ($scope, $rootScope, $location, Generat
}
});
$scope.model = $routeParams.model;
});
});
\ No newline at end of file
<div class="starter-template">
<h1>{{model}}
<a href="#/crud/add/{{model}}/{{form_params.param}}/{{form_params.id}}">
<a href="{{nobjects.addLink}}">
<button type="button" class="btn btn-primary">Ekle</button>
</a>
</h1>
......@@ -32,17 +32,17 @@
</label>
</td>
<th scope="row" style="text-align:center">{{$index}}</th>
<td ng-repeat="k in object track by $index" ng-if="nobjects[0]=='-1' && $index>0">
<a ng-href="#/crud/detail/{{model}}/{{form_params.param}}/{{form_params.id}}/{{object[0]}}">{{object[1]}}</a>
<!-- 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>1">
<a ng-href="{{object[2].detailLink}}">{{object[1]}}</a>
</td>
<td ng-repeat="(key,value) in object track by $index" ng-if="nobjects[0]!='-1' && $index>0">
<a ng-href="#/crud/detail/{{model}}/{{form_params.param}}/{{form_params.id}}/{{object[0]}}"
ng-if="$index==1">{{object[key]}}</a>
<td ng-repeat="(key,value) in object track by $index" ng-if="nobjects[0]!='-1' && $index>1">
<a ng-href="{{object[2].detailLink}}" ng-if="$index==1">{{object[key]}}</a>
<span ng-if="$index!=1">{{object[key]}}</span>
</td>
<td>
<a ng-href="#/crud/edit/{{model}}/{{form_params.param}}/{{form_params.id}}/{{object[0]}}">Edit</a>
<a ng-href="{{object[2].editLink}}">Edit</a>
<br>
</td>
</tr>
......
......@@ -183,6 +183,21 @@ app.directive('sidebar', ['$location', function () {
.success(function (data) {
$scope.allMenuItems = angular.copy(data);
function reGroupMenuItems(items) {
var newItems = {};
angular.forEach(items, function (value, key) {
newItems[value.kategori] = newItems[value.kategori] || [];
newItems[value.kategori].push(value);
});
return newItems;
}
angular.forEach($scope.allMenuItems, function (value, key) {
$scope.allMenuItems[key] = reGroupMenuItems(value);
});
console.log($scope.allMenuItems);
// broadcast for authorized menu items, consume in dashboard
$rootScope.$broadcast("authz", data);
......
......@@ -23,12 +23,18 @@
<span class="fa arrow" ng-class="{hidden: $root.collapsed}"></span>
</a>
<ul class="nav nav-second-level" ng-class="{hidden: $root.collapsed}">
<li ng-repeat="v in item">
<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}}/{{v.param}}/{{$root.selectedUser.key}}"
ng-click="breadcrumb([key, v.text], $event)">{{v.text}}</a>
<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 -->
......
......@@ -213,6 +213,38 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form
return newdatearray.join('.');
}
};
generator.itemLinksGenerator = function (scope, itemlist) {
angular.forEach(itemlist.data.nobjects, function (value, key) {
//var detailLink = "#/" + scope.url + "detail/" + scope.form_params.model;
//var addLink = "#/" + scope.url + "add/" + scope.form_params.model;
//var editLink = "#/" + scope.url + "edit/" + scope.form_params.model;
function makelink (page) {
if (value === '-1') {
return;
}
var link = "#" + scope.url + scope.form_params.model;
if (page === 'edit/' || page === 'detail/') {
link += "/" + page + value[0];
}
if (page === 'add/') {
link += "/add";
}
if (scope.form_params.param) {
link += "?" + scope.form_params.param + "=" + scope.form_params.id;
}
return link;
}
itemlist.data.nobjects.addLink = makelink("add/");
value[2] = {detailLink: makelink("detail/"), editLink: makelink("edit/")};
});
};
generator.get_form = function (scope) {
return $http
.post(generator.makeUrl(scope), scope.form_params)
......@@ -225,6 +257,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form
.get(generator.makeUrl(scope))
.then(function (res) {
//generator.dateformatter(res);
generator.itemLinksGenerator(scope, res);
return res;
});
};
......
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