Commit d136b928 authored by Evren Kutar's avatar Evren Kutar

crud views edit according to new structure of api

parent 012529d5
...@@ -10,29 +10,25 @@ app.config(['$routeProvider', function ($routeProvider, $route) { ...@@ -10,29 +10,25 @@ app.config(['$routeProvider', function ($routeProvider, $route) {
templateUrl: 'components/dashboard/dashboard.html', templateUrl: 'components/dashboard/dashboard.html',
controller: 'DashCtrl' controller: 'DashCtrl'
}) })
.when('/crud/:model/:id', { .when('/crud/add/:model/:param/:id', {
templateUrl: 'components/crud/templates/add.html', templateUrl: 'components/crud/templates/add.html',
controller: 'CRUDAddEditCtrl', controller: 'CRUDAddEditCtrl'
reloadOnSearch: true })
}) .when('/crud/edit/:model/:param/:id/:key', {
//.when('/crud/:model/edit/:id', { templateUrl: 'components/crud/templates/add.html',
// templateUrl: 'components/crud/templates/add.html', controller: 'CRUDAddEditCtrl'
// controller: 'CRUDAddEditCtrl'
//})
.when('/crud/:model', {
templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl',
reloadOnSearch: true
}) })
.when('/crud/:model/:param/:id', { .when('/crud/:model/:param/:id', {
templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl'
})
.when('/crud/detail/:model/:param/:id/:key', {
templateUrl: 'components/crud/templates/show.html', templateUrl: 'components/crud/templates/show.html',
controller: 'CRUDShowCtrl', controller: 'CRUDShowCtrl'
reloadOnSearch: true
}) })
.when('/:model/', { .when('/:model/', {
templateUrl: 'components/wf/templates/add.html', templateUrl: 'components/wf/templates/add.html',
controller: 'WFAddEditCtrl', controller: 'WFAddEditCtrl'
reloadOnSearch: true
}) })
.otherwise({redirectTo: '/dashboard'}); .otherwise({redirectTo: '/dashboard'});
}]) }])
......
...@@ -17,10 +17,10 @@ var crud = angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formSe ...@@ -17,10 +17,10 @@ var crud = angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formSe
*/ */
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) {
$scope.url = 'crud'; $scope.url = 'crud/';
$scope.form_params = {'model': $routeParams.model}; $scope.form_params = {'model': $routeParams.model, param: $routeParams.param, id: $routeParams.id};
if ($routeParams.id) { if ($routeParams.key) {
$scope.form_params['object_id'] = $routeParams.id; $scope.form_params['key'] = $routeParams.key;
$scope.form_params['cmd'] = 'edit'; $scope.form_params['cmd'] = 'edit';
} }
else { else {
...@@ -37,10 +37,10 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt ...@@ -37,10 +37,10 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
if (form.$valid) { if (form.$valid) {
Generator.submit($scope) Generator.submit($scope)
.success(function(data){ .success(function (data) {
$location.path('/crud/'+$scope.form_params.model).search(data); $location.path('/crud/' + $scope.form_params.model).search(data);
}) })
.error(function(data){ .error(function (data) {
$scope.message = data.title; $scope.message = data.title;
}); });
} }
...@@ -56,7 +56,7 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP ...@@ -56,7 +56,7 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
$scope.url = 'crud/'; $scope.url = 'crud/';
$scope.form_params = $routeParams; $scope.form_params = $routeParams;
if ($routeParams.nobjects){ if ($routeParams.nobjects) {
$scope.nobjects = $routeParams.nobjects; $scope.nobjects = $routeParams.nobjects;
$scope.model = $routeParams.model; $scope.model = $routeParams.model;
} else { } else {
...@@ -72,16 +72,26 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP ...@@ -72,16 +72,26 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
/** /**
* CRUD Show Controller * CRUD Show Controller
*/ */
crud.controller('CRUDShowCtrl', function ($scope, $rootScope, Generator, $routeParams) { crud.controller('CRUDShowCtrl', function ($scope, $rootScope, $location, Generator, $routeParams) {
$scope.url = 'crud/'; $scope.url = 'crud/';
$scope.form_params = {"object_id": $routeParams.id, "cmd": "show", "model": $routeParams.model}; $scope.form_params = {
// call generator's get_single_itemfunc "object_id": $routeParams.id,
"cmd": "show",
param: $routeParams.param,
"model": $routeParams.model
};
// call generator's get_single_item func
Generator.get_single_item($scope).then(function (res) { Generator.get_single_item($scope).then(function (res) {
console.log(res.data.nobjects);
// 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.object_id + '/edit');
}
$scope.listobjects = {}; $scope.listobjects = {};
$scope.object = res.data.object; $scope.object = res.data.object;
angular.forEach($scope.object, function (value, key) { angular.forEach($scope.object, function (value, key) {
if(typeof value == 'object'){ if (typeof value == 'object') {
$scope.listobjects[key] = value; $scope.listobjects[key] = value;
delete $scope.object[key]; delete $scope.object[key];
} }
......
<h1>{{ schema.title }}</h1> <h1>{{ schema.title }}</h1>
<form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model"></form> <form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model" ng-submit="onSubmit(formgenerated)"></form>
<div ng-repeat="node in Node"> <div ng-repeat="node in Node">
<h3>{{ node.title }} <h3>{{ node.title }}
......
<div class="starter-template"> <div class="starter-template">
<h1>{{model}} <a href="#/crud/{{model}}/add"><button type="button" class="btn btn-primary">Ekle</button></a></h1> <h1>{{model}}
<a href="#/crud/add/{{model}}/{{form_params.param}}/{{form_params.id}}">
<button type="button" class="btn btn-primary">Ekle</button>
</a>
</h1>
<div class="row" ng-if="!nobjects[1]"> <div class="row" ng-if="!nobjects[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>
...@@ -29,15 +33,16 @@ ...@@ -29,15 +33,16 @@
</td> </td>
<th scope="row" style="text-align:center">{{$index}}</th> <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"> <td ng-repeat="k in object track by $index" ng-if="nobjects[0]=='-1' && $index>0">
<a ng-href="#/crud/{{model}}/{{object[0]}}">{{object[1]}}</a> <a ng-href="#/crud/edit/{{model}}/{{form_params.param}}/{{form_params.id}}{{object[0]}}">{{object[1]}}</a>
</td> </td>
<td ng-repeat="(key,value) in object track by $index" ng-if="nobjects[0]!='-1' && $index>0"> <td ng-repeat="(key,value) in object track by $index" ng-if="nobjects[0]!='-1' && $index>0">
<a ng-href="#/crud/{{model}}/{{object[0]}}" ng-if="$index==1">{{object[key]}}</a> <a ng-href="#/crud/edit/{{model}}/{{form_params.param}}/{{form_params.id}}{{object[0]}}" ng-if="$index==1">{{object[key]}}</a>
<span ng-if="$index!=1">{{object[key]}}</span> <span ng-if="$index!=1">{{object[key]}}</span>
</td> </td>
<td> <td>
<a ng-href="#/crud/{{model}}/edit/{{object[0]}}">Edit</a><br> <a ng-href="#/crud/edit/{{model}}/{{form_params.param}}/{{form_params.id}}{{object[0]}}">Edit</a>
<br>
</td> </td>
</tr> </tr>
</tbody> </tbody>
......
...@@ -43,7 +43,6 @@ app.directive('headerNotification', function ($http, $rootScope, $interval, REST ...@@ -43,7 +43,6 @@ app.directive('headerNotification', function ($http, $rootScope, $interval, REST
$scope.notifications[value.type].push(value); $scope.notifications[value.type].push(value);
}); });
$rootScope.$broadcast("notifications", $scope.notifications); $rootScope.$broadcast("notifications", $scope.notifications);
console.log($scope.notifications);
}); });
}, 5000); }, 5000);
} }
......
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
</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="v in item"> <li ng-repeat="v in item">
<a ng-href="#{{v.url}}{{$root.selectedUser.key}}" <a ng-if="key == 'other'" ng-href="#{{v.url}}/{{$root.selectedUser.key}}"
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> ng-click="breadcrumb([key, v.text], $event)">{{v.text}}</a>
</li> </li>
</ul> </ul>
......
This diff is collapsed.
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