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) {
templateUrl: 'components/dashboard/dashboard.html',
controller: 'DashCtrl'
})
.when('/crud/:model/:id', {
.when('/crud/add/:model/:param/:id', {
templateUrl: 'components/crud/templates/add.html',
controller: 'CRUDAddEditCtrl',
reloadOnSearch: true
})
//.when('/crud/:model/edit/:id', {
// templateUrl: 'components/crud/templates/add.html',
// controller: 'CRUDAddEditCtrl'
//})
.when('/crud/:model', {
templateUrl: 'components/crud/templates/list.html',
controller: 'CRUDListCtrl',
reloadOnSearch: true
controller: 'CRUDAddEditCtrl'
})
.when('/crud/edit/:model/:param/:id/: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', {
templateUrl: 'components/crud/templates/show.html',
controller: 'CRUDShowCtrl',
reloadOnSearch: true
controller: 'CRUDShowCtrl'
})
.when('/:model/', {
templateUrl: 'components/wf/templates/add.html',
controller: 'WFAddEditCtrl',
reloadOnSearch: true
controller: 'WFAddEditCtrl'
})
.otherwise({redirectTo: '/dashboard'});
}])
......
......@@ -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) {
$scope.url = 'crud';
$scope.form_params = {'model': $routeParams.model};
if ($routeParams.id) {
$scope.form_params['object_id'] = $routeParams.id;
$scope.url = 'crud/';
$scope.form_params = {'model': $routeParams.model, param: $routeParams.param, id: $routeParams.id};
if ($routeParams.key) {
$scope.form_params['key'] = $routeParams.key;
$scope.form_params['cmd'] = 'edit';
}
else {
......@@ -37,10 +37,10 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt
if (form.$valid) {
Generator.submit($scope)
.success(function(data){
$location.path('/crud/'+$scope.form_params.model).search(data);
.success(function (data) {
$location.path('/crud/' + $scope.form_params.model).search(data);
})
.error(function(data){
.error(function (data) {
$scope.message = data.title;
});
}
......@@ -56,7 +56,7 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
$scope.url = 'crud/';
$scope.form_params = $routeParams;
if ($routeParams.nobjects){
if ($routeParams.nobjects) {
$scope.nobjects = $routeParams.nobjects;
$scope.model = $routeParams.model;
} else {
......@@ -72,16 +72,26 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
/**
* CRUD Show Controller
*/
crud.controller('CRUDShowCtrl', function ($scope, $rootScope, Generator, $routeParams) {
crud.controller('CRUDShowCtrl', function ($scope, $rootScope, $location, Generator, $routeParams) {
$scope.url = 'crud/';
$scope.form_params = {"object_id": $routeParams.id, "cmd": "show", "model": $routeParams.model};
// call generator's get_single_itemfunc
$scope.form_params = {
"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) {
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.object = res.data.object;
angular.forEach($scope.object, function (value, key) {
if(typeof value == 'object'){
if (typeof value == 'object') {
$scope.listobjects[key] = value;
delete $scope.object[key];
}
......
<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">
<h3>{{ node.title }}
......
<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="col-md-12">
<p class="no-content">Listelenecek içerik yok.</p>
......@@ -29,15 +33,16 @@
</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/{{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 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>
</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>
</tr>
</tbody>
......
......@@ -43,7 +43,6 @@ app.directive('headerNotification', function ($http, $rootScope, $interval, REST
$scope.notifications[value.type].push(value);
});
$rootScope.$broadcast("notifications", $scope.notifications);
console.log($scope.notifications);
});
}, 5000);
}
......
......@@ -24,7 +24,10 @@
</a>
<ul class="nav nav-second-level" ng-class="{hidden: $root.collapsed}">
<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>
</li>
</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