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
// call generator's get_list func
Generator.get_list($scope)
.then(function (res) {
debugger;
$scope.nobjects = res.data.nobjects;
$scope.model = $routeParams.model;
});
......
<div>
<ng-include src="'shared/templates/add.html'"></ng-include>
</div>
\ No newline at end of file
<h1>{{ schema.title }}</h1>
<form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model"></form>
<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">
<h1>{{model}}</h1>
<h1>{{model}} <a href="#/{{model}}/add"><button type="button" class="btn btn-primary">Ekle</button></a></h1>
<div class="tablescroll">
<table class="table table-bordered" style="background-color:#fff;">
<thead>
......
<!-- todo: remove this template -->
<h1>{{ schema.title }}</h1>
<form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model"></form>
{{Node}}
<div ng-repeat="node in Node">
<h3>{{ node.title }}
<span ng-if="node.lengthModels < 1">
......@@ -8,7 +10,9 @@
</a>
</span>
</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>
</div>
<div ng-repeat="node in ListNode">
......@@ -19,7 +23,9 @@
</a>
</span>
</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>
</div>
......
......@@ -8,12 +8,13 @@
Hepsini Seç
</label>
</th>
<th ng-repeat="(key,value) in node.form">{{ value }}</th>
<th ng-repeat="(key,value) in node.model">{{ key }}</th>
<th>action</th>
</tr>
</thead>
<tbody ng-class="{true: '', false: 'hidden'}[node.lengthModels > 0]">
<tr>
<tbody ng-class="{hidden: node.lengthModels < 1}">
<tr ng-if="node.schema.formType=='Node'">
<td width="60">
<label>
<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">
......@@ -22,11 +23,27 @@
<th scope="row" style="text-align:center">1</th>
<td ng-repeat="value in node.model">{{ value }}</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>Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
\ No newline at end of file
......@@ -76,7 +76,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
var formitem = scope.form[scope.form.indexOf(v)];
var modelscope = {"url": scope.url, "form_params": {model: k.model_name}};
debugger;
formitem = {
type: "template",
templateUrl: "shared/templates/foreignKey.html",
......@@ -111,9 +111,7 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
scope[k.type] = scope[k.type] ? scope[k.type] : {};
debugger;
scope[k.type][k.title] = {
scope[k.type][v] = {
title: k.title,
form: [],
schema: {
......@@ -127,32 +125,31 @@ form_generator.factory('Generator', function ($http, $q, $log, $location, $modal
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) {
scope[k.type][k.title].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;
//}
scope[k.type][v].schema.properties[item.name] = item;
// prepare required fields
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
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 {
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
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
//data.form = get_diff;
}
debugger;
return $http.post(generator.makeUrl($scope.url), data);
//.success(function () {
//
......@@ -287,8 +286,12 @@ form_generator.directive('modalForNodes', function ($modal) {
resolve: {
items: function () {
var attribs = attributes['modalForNodes'].split(',');
debugger;
// 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;
}
}
......@@ -299,16 +302,21 @@ form_generator.directive('modalForNodes', function ($modal) {
//var subfix = scope.schema.title.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
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') {
debugger;
if (scope.$parent.model[childmodel.schema.model_name] == null) {
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)
size: 'lg',
resolve: {
items: function () {
debugger;
return Generator.get_form({
url: 'crud',
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