Commit 2072228e authored by Evren Kutar's avatar Evren Kutar

add node item to table and edit

parent 45aca914
...@@ -58,6 +58,7 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP ...@@ -58,6 +58,7 @@ crud.controller('CRUDListCtrl', function ($scope, $rootScope, Generator, $routeP
// 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) {
debugger;
$scope.nobjects = res.data.nobjects; $scope.nobjects = res.data.nobjects;
$scope.model = $routeParams.model; $scope.model = $routeParams.model;
}); });
......
<div> <h1>{{ schema.title }}</h1>
<ng-include src="'shared/templates/add.html'"></ng-include> <form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model"></form>
</div>
\ No newline at end of file <div ng-repeat="node in Node">
<h3>{{ node.title }}
<span ng-if="node.lengthModels < 1">
<a href="javascript:void(0);" modal-for-nodes="{{node.schema.model_name}},Node">
<i class="fa fa-plus-circle fa-fw"></i>
</a>
</span>
</h3>
<div class="node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div>
<hr>
</div>
<div ng-repeat="node in ListNode">
<h3>{{ node.title }}
<span>
<a href="javascript:void(0);" modal-for-nodes="{{node.schema.model_name}},ListNode,add">
<i class="fa fa-plus-circle fa-fw"></i>
</a>
</span>
</h3>
<div class="list-node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div>
<hr>
</div>
<button id="submitbutton" type="button" class="btn btn-primary" ng-click="onSubmit(formgenerated)">Kaydet</button>
<!-- <button type="button" class="btn btn-warning">Düzenle</button> todo: make it conditional -->
<!-- <button type="button" class="btn btn-danger">İptal</button> todo: turn back to previous page -->
\ No newline at end of file
<div class="starter-template"> <div class="starter-template">
<h1>{{model}}</h1> <h1>{{model}} <a href="#/{{model}}/add"><button type="button" class="btn btn-primary">Ekle</button></a></h1>
<div class="tablescroll"> <div class="tablescroll">
<table class="table table-bordered" style="background-color:#fff;"> <table class="table table-bordered" style="background-color:#fff;">
<thead> <thead>
......
<!-- todo: remove this template -->
<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"></form>
{{Node}}
<div ng-repeat="node in Node"> <div ng-repeat="node in Node">
<h3>{{ node.title }} <h3>{{ node.title }}
<span ng-if="node.lengthModels < 1"> <span ng-if="node.lengthModels < 1">
...@@ -8,7 +10,9 @@ ...@@ -8,7 +10,9 @@
</a> </a>
</span> </span>
</h3> </h3>
<ng-include src="'shared/templates/nodeTable.html'"></ng-include> <div class="node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div>
<hr> <hr>
</div> </div>
<div ng-repeat="node in ListNode"> <div ng-repeat="node in ListNode">
...@@ -19,7 +23,9 @@ ...@@ -19,7 +23,9 @@
</a> </a>
</span> </span>
</h3> </h3>
<ng-include src="'shared/templates/nodeTable.html'"></ng-include> <div class="list-node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div>
<hr> <hr>
</div> </div>
......
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
Hepsini Seç Hepsini Seç
</label> </label>
</th> </th>
<th ng-repeat="(key,value) in node.form">{{ value }}</th> <th ng-repeat="(key,value) in node.model">{{ key }}</th>
<th>action</th> <th>action</th>
</tr> </tr>
</thead> </thead>
<tbody ng-class="{true: '', false: 'hidden'}[node.lengthModels > 0]"> <tbody ng-class="{hidden: node.lengthModels < 1}">
<tr>
<tr ng-if="node.schema.formType=='Node'">
<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;">
...@@ -22,11 +23,27 @@ ...@@ -22,11 +23,27 @@
<th scope="row" style="text-align:center">1</th> <th scope="row" style="text-align:center">1</th>
<td ng-repeat="value in node.model">{{ value }}</td> <td ng-repeat="value in node.model">{{ value }}</td>
<td> <td>
<button modal-for-nodes="{{node.title}},ListNode">Edit</button><br> <button modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit">Edit</button><br>
<button>Show</button>
<button>Delete</button>
</td>
</tr>
<tr ng-repeat="listnodemodel in node.model" ng-if="node.schema.formType=='ListNode'">
<td width="60">
<label>
<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">
</label>
</td>
<th scope="row" style="text-align:center">1</th>
<td ng-repeat="value in listnodemodel">{{ value }}</td>
<td>
<button modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit">Edit</button><br>
<button>Show</button> <button>Show</button>
<button>Delete</button> <button>Delete</button>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
\ No newline at end of file
...@@ -76,7 +76,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal ...@@ -76,7 +76,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
var formitem = scope.form[scope.form.indexOf(v)]; var formitem = scope.form[scope.form.indexOf(v)];
var modelscope = {"url": scope.url, "form_params": {model: k.model_name}}; var modelscope = {"url": scope.url, "form_params": {model: k.model_name}};
debugger;
formitem = { formitem = {
type: "template", type: "template",
templateUrl: "shared/templates/foreignKey.html", templateUrl: "shared/templates/foreignKey.html",
...@@ -111,9 +111,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal ...@@ -111,9 +111,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
scope[k.type] = scope[k.type] ? scope[k.type] : {}; scope[k.type] = scope[k.type] ? scope[k.type] : {};
debugger; scope[k.type][v] = {
scope[k.type][k.title] = {
title: k.title, title: k.title,
form: [], form: [],
schema: { schema: {
...@@ -127,32 +125,31 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal ...@@ -127,32 +125,31 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
url: scope.url url: scope.url
}; };
scope[k.type][k.title].model = scope.model[v] != null ? scope.model[v] : {}; if (scope.model[v] == null) {
scope[k.type][v].model = k.type == 'Node' ? [] : {};
} else {
scope[k.type][v].model = scope.model[v];
}
angular.forEach(k.schema, function (item) { angular.forEach(k.schema, function (item) {
scope[k.type][k.title].schema.properties[item.name] = item; scope[k.type][v].schema.properties[item.name] = item;
// if model is empty object then fill it with scope model item
//if (scope[k.type][k.title] == {}){
// scope[k.type][k.title].model[item.name] = item.value;
//}
// prepare required fields // prepare required fields
if (item.required == true && item.name != 'idx') { if (item.required == true && item.name != 'idx') {
scope[k.type][k.title].schema.required.push(item.name); scope[k.type][v].schema.required.push(item.name);
} }
// idx field must be hidden // idx field must be hidden
if (item.name == 'idx') { if (item.name == 'idx') {
scope[k.type][k.title].form.push({type: 'string', key: item.name, htmlClass: 'hidden'}); scope[k.type][v].form.push({type: 'string', key: item.name, htmlClass: 'hidden'});
} else { } else {
scope[k.type][k.title].form.push(item.name); scope[k.type][v].form.push(item.name);
} }
}); });
// lengthModels is length of the listnode models. if greater than 0 show records on template // lengthModels is length of the listnode models. if greater than 0 show records on template
scope[k.type][k.title]['lengthModels'] = scope.model[k.title] ? 1 : 0; scope[k.type][v]['lengthModels'] = scope.model[v] ? 1 : 0;
} }
...@@ -226,6 +223,8 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal ...@@ -226,6 +223,8 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
//data.form = get_diff; //data.form = get_diff;
} }
debugger;
return $http.post(generator.makeUrl($scope.url), data); return $http.post(generator.makeUrl($scope.url), data);
//.success(function () { //.success(function () {
// //
...@@ -287,8 +286,12 @@ form_generator.directive('modalForNodes', function ($modal) { ...@@ -287,8 +286,12 @@ form_generator.directive('modalForNodes', function ($modal) {
resolve: { resolve: {
items: function () { items: function () {
var attribs = attributes['modalForNodes'].split(','); var attribs = attributes['modalForNodes'].split(',');
debugger;
// get node from parent scope catch with attribute // get node from parent scope catch with attribute
var node = angular.copy(scope.$parent.$parent[attribs[1]][attribs[0]]); var node = angular.copy(scope.$parent[attribs[1]][attribs[0]]);
if(attribs[2] == 'add'){
node.model = {};
}
return node; return node;
} }
} }
...@@ -299,16 +302,21 @@ form_generator.directive('modalForNodes', function ($modal) { ...@@ -299,16 +302,21 @@ form_generator.directive('modalForNodes', function ($modal) {
//var subfix = scope.schema.title.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase(); //var subfix = scope.schema.title.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
if (childmodel.schema.formType == 'Node') { if (childmodel.schema.formType == 'Node') {
scope.$parent.model[childmodel.schema.model_name] = childmodel.model; //scope.$parent.model[childmodel.schema.model_name] = childmodel.model;
scope.$parent[childmodel.schema.formType][childmodel.schema.model_name].model = childmodel.model;
} }
if (childmodel.schema.formType == 'ListNode') { if (childmodel.schema.formType == 'ListNode') {
debugger;
if (scope.$parent.model[childmodel.schema.model_name] == null) { if (scope.$parent.model[childmodel.schema.model_name] == null) {
scope.$parent.model[childmodel.schema.model_name] = []; scope.$parent.model[childmodel.schema.model_name] = [];
} }
scope.$parent.model[childmodel.schema.model_name].push(childmodel.model);
//scope.$parent.model[childmodel.schema.model_name].push(childmodel.model);
scope.$parent[childmodel.schema.formType][childmodel.schema.model_name].model.push(childmodel.model);
} }
childmodel.lengthModels += 1;
scope.$parent[childmodel.schema.formType][childmodel.schema.model_name].lengthModels += 1;
}); });
}); });
} }
...@@ -333,7 +341,6 @@ form_generator.directive('addModalForLinkedModel', function ($modal, Generator) ...@@ -333,7 +341,6 @@ form_generator.directive('addModalForLinkedModel', function ($modal, Generator)
size: 'lg', size: 'lg',
resolve: { resolve: {
items: function () { items: function () {
debugger;
return Generator.get_form({ return Generator.get_form({
url: 'crud', url: 'crud',
form_params: {'model': scope.form.model_name, "cmd": "add"} form_params: {'model': scope.form.model_name, "cmd": "add"}
......
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