Commit 562f8061 authored by Evren Kutar's avatar Evren Kutar

Merge branch 'Feature/issue50'

parents dbdcc682 c7aeefcf
......@@ -1636,6 +1636,6 @@ table.dataTable thead .sorting:after {
}
/* end page transitions */
.movetobottom {
.move-to-bottom, .move-to-top {
margin-right: 10px !important;
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ var app = angular.module(
'ulakbus.version',
//'schemaForm',
'gettext',
'ulakbus.uitemplates',
'ulakbus.uitemplates'
]).
/**
* RESTURL is the url of rest api to talk
......@@ -33,7 +33,7 @@ var app = angular.module(
*/
constant("RESTURL", (function () {
// todo: below backendurl definition is for development purpose and will be deleted
var backendurl = location.href.indexOf('nightly') ? "//nightly.api.ulakbus.net/" : "//api.ulakbus.net/";
var backendurl = location.href.indexOf('nightly') > -1 ? "//nightly.api.ulakbus.net/" : "//api.ulakbus.net/";
if (document.cookie.indexOf("backendurl") > -1) {
var cookiearray = document.cookie.split(';');
angular.forEach(cookiearray, function (item) {
......
......@@ -72,8 +72,14 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
});
angular.forEach(value.fields, function (v, k) {
if (value.actions.length > 0 && linkIndexes.fields){
scope.objects[key].fields[k] = {type: linkIndexes.fields.indexOf(k) > -1 ? 'link' : 'str', content: v, cmd: linkIndexes.cmd};
} else {
scope.objects[key].fields[k] = {
type: linkIndexes.fields.indexOf(k) > -1 ? 'link' : 'str',
content: v,
cmd: linkIndexes.cmd,
mode: linkIndexes.mode
};
}
else {
scope.objects[key].fields[k] = {type: 'str', content: v};
}
});
......@@ -128,7 +134,31 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
$scope.reload_cmd = data;
$scope.reload({});
});
if ($routeParams.cmd === 'show') {
// we use form generator for generic forms. this makes form's scope to confuse on the path to generate form
// object by its name. to manage to locate the form to controllers scope we use a directive called form locator
// a bit dirty way to find form working on but solves our problem
$scope.$on('formLocator', function (event) {
$scope.formgenerated = event.targetScope.formgenerated;
});
$scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate');
if (form.$valid) {
Generator.submit($scope);
}
};
$scope.do_action = function (key, cmd, mode) {
Generator.doItemAction($scope, key, cmd, mode || 'normal');
};
$scope.getNumber = function (num) {
return new Array(num);
};
//
$scope.showCmd = function () {
CrudUtility.generateParam($scope, $routeParams, $routeParams.cmd);
// todo: refactor createListObjects func
var createListObjects = function () {
......@@ -155,9 +185,8 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
});
}
createListObjects();
}
if ($routeParams.cmd === 'form' || $routeParams.cmd === 'list') {
};
$scope.listFormCmd = function () {
// function to set scope objects
var setpageobjects = function (data) {
CrudUtility.listPageItems($scope, data);
......@@ -179,39 +208,25 @@ angular.module('ulakbus.crud', ['ui.bootstrap', 'schemaForm', 'formService'])
CrudUtility.generateParam($scope, $routeParams, $routeParams.cmd);
Generator.get_wf($scope);
}
// we use form generator for generic forms. this makes form's scope to confuse on the path to generate form
// object by its name. to manage to locate the form to controllers scope we use a directive called form locator
// a bit dirty way to find form working on but solves our problem
$scope.$on('formLocator', function (event) {
$scope.formgenerated = event.targetScope.formgenerated;
});
$scope.onSubmit = function (form) {
$scope.$broadcast('schemaFormValidate');
if (form.$valid) {
Generator.submit($scope);
}
};
$scope.do_action = function (key, cmd) {
Generator.doItemAction($scope, key, cmd);
};
$scope.getNumber = function (num) {
return new Array(num);
};
}
if ($routeParams.cmd === 'reload') {
};
$scope.reloadCmd = function () {
$scope.reload({});
}
if ($routeParams.cmd === 'reset') {
};
$scope.resetCmd = function () {
delete $scope.token;
$scope.cmd = 'reset';
Generator.get_wf($scope);
}
};
var executeCmd = {
show: $scope.showCmd,
list: $scope.listFormCmd,
form: $scope.listFormCmd,
reload: $scope.reloadCmd,
reset: $scope.resetCmd
};
return executeCmd[$routeParams.cmd]();
})
......
<crud-show-directive ng-if="object"></crud-show-directive>
<crud-form-directive ng-if="forms"></crud-form-directive>
<hr class="col-md-12">
<crud-list-directive ng-if="objects"></crud-list-directive>
\ No newline at end of file
<div class="container">
<h1>{{ schema.title }}</h1>
<div class="buttons-on-top"></div>
<form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model"
ng-submit="onSubmit(formgenerated)" form-locator></form>
......@@ -34,4 +36,5 @@
</div>
<div class="buttons-on-bottom"></div>
</div>
\ No newline at end of file
<div class="starter-template container">
<search-directive ng-if="meta['allow_search']===true"></search-directive>
<div class="clearfix"></div>
<h1>{{form_params.model || form_params.wf}}</h1>
<!--<h1>{{form_params.model || form_params.wf}}</h1>-->
<div class="row" ng-if="!objects[1]">
<div class="col-md-12">
<p class="no-content">Listelenecek içerik yok.</p>
......@@ -34,13 +34,14 @@
<td ng-repeat="field in object.fields track by $index">
<a ng-href="javascript:void(0)"
ng-if="field.type==='link'"
ng-click="do_action(object.key, field.cmd)">{{field.content}}</a>
ng-click="do_action(object.key, field.cmd, field.mode)">{{field.content}}</a>
<span ng-if="field.type==='str'">{{field.content}}</span>
</td>
<td>
<button class="btn btn-primary" style="margin-right: 5px;" ng-repeat="action in object.actions"
ng-if="action.show_as==='button'" ng-click="do_action(object.key, action.cmd)">{{action
ng-if="action.show_as==='button'"
ng-click="do_action(object.key, action.cmd, action.mode)">{{action
.name}}
</button>
<br>
......
......@@ -29,7 +29,7 @@ var app = angular.module(
'templates-prod',
// @endif
// @if NODE_ENV='DEVELOPMENT'
'ulakbus.uitemplates',
'ulakbus.uitemplates'
// @endif
]).
/**
......@@ -38,7 +38,7 @@ var app = angular.module(
*/
constant("RESTURL", (function () {
// todo: below backendurl definition is for development purpose and will be deleted
var backendurl = location.href.indexOf('nightly') ? "//nightly.api.ulakbus.net/" : "//api.ulakbus.net/";
var backendurl = location.href.indexOf('nightly') > -1 ? "//nightly.api.ulakbus.net/" : "//api.ulakbus.net/";
if (document.cookie.indexOf("backendurl") > -1) {
var cookiearray = document.cookie.split(';');
angular.forEach(cookiearray, function (item) {
......
......@@ -139,7 +139,6 @@ app.directive('logout', function ($http, $location, RESTURL) {
controller: function ($scope, $rootScope) {
$rootScope.collapsed = false;
$rootScope.sidebarPinned = $cookies.get('sidebarPinned') || 0;
var cookieSidebar = {1:0,0:1};
$scope.collapseToggle = function () {
if ($window.innerWidth > '768') {
......@@ -148,15 +147,14 @@ app.directive('logout', function ($http, $location, RESTURL) {
jQuery(".manager-view").css("width", "calc(100% - 62px)");
$rootScope.collapsed = true;
$rootScope.sidebarPinned = 0;
$cookies.put('sidebarPinned', cookieSidebar[$cookies.get('sidebarPinned')]);
$cookies.put('sidebarPinned', 0);
} else {
jQuery("span.menu-text, span.arrow, .sidebar footer").fadeIn(400);
jQuery(".sidebar").css("width", "250px");
jQuery(".manager-view").css("width", "calc(100% - 250px)");
$rootScope.collapsed = false;
$rootScope.sidebarPinned = 1;
$cookies.put('sidebarPinned', cookieSidebar[$cookies.get('sidebarPinned')]);
$cookies.put('sidebarPinned', 1);
}
}
};
......
......@@ -13,7 +13,7 @@
* The `formService` module provides generic services for auto generated forms.
*
*/
angular.module('formService', [])
angular.module('formService', ['ui.bootstrap'])
/**
* @name Generator
......@@ -98,6 +98,16 @@ angular.module('formService', [])
* @returns {*}
*/
generator.prepareFormItems = function (scope) {
// todo: remove after backend fix
angular.forEach(scope.form, function (value, key) {
if (value.type === 'select') {
scope.schema.properties[value.key].type = 'select';
scope.schema.properties[value.key].titleMap = value.titleMap;
scope.form[key] = value.key;
}
});
angular.forEach(scope.schema.properties, function (v, k) {
// generically change _id fields model value
......@@ -122,10 +132,11 @@ angular.module('formService', [])
if (v.type === 'submit' || v.type === 'button') {
var buttonPositions = {bottom: 'move-to-bottom', top: 'move-to-top', none: ''};
scope.form[scope.form.indexOf(k)] = {
type: v.type,
title: v.title,
style: "btn-primary movetobottom hide",
style: "btn-primary hide " + (buttonPositions[v.position] || "move-to-bottom"),
onClick: function () {
delete scope.form_params.cmd;
delete scope.form_params.flow;
......@@ -143,15 +154,18 @@ angular.module('formService', [])
}
}
};
// replace buttons according to their position values
$timeout(function () {
var buttons = angular.element(document.querySelector('.movetobottom'));
angular.element(document.querySelector('.buttons-on-bottom')).append(buttons);
buttons.removeClass('hide');
var buttonsToBottom = angular.element(document.querySelector('.move-to-bottom'));
angular.element(document.querySelector('.buttons-on-bottom')).append(buttonsToBottom);
var buttonsToTop = angular.element(document.querySelector('.move-to-top'));
angular.element(document.querySelector('.buttons-on-bottom')).append(buttonsToTop);
buttonsToBottom.removeClass('hide');
buttonsToTop.removeClass('hide');
});
}
// check if type is date and if type date found change it to string
if (v.type === 'date') {
v.type = 'string';
scope.model[k] = generator.dateformatter(scope.model[k]);
......@@ -177,13 +191,12 @@ angular.module('formService', [])
if (v.type === 'text_general') {
v.type = 'string';
v["x-schema-form"] = {
"type": "textarea",
"type": "textarea"
//"placeholder": ""
}
}
// if type is model use foreignKey.html template to show them
if (v.type === 'model') {
var formitem = scope.form[scope.form.indexOf(k)];
......@@ -206,7 +219,15 @@ angular.module('formService', [])
"name": item.value
});
}
// get selected item from titleMap using model value
if (item.key === scope.model[k]) {formitem.selected_item = {value: item.key, name: item.value};}
});
// after rendering change input value to model value
scope.$watch(document.querySelector('input[name='+ v.model_name+']'),
function(){
angular.element(document.querySelector('input[name='+ v.model_name+']')).val(formitem.selected_item.name);
}
);
}),
onSelect: function (item) {
scope.model[k] = item.value;
......@@ -286,13 +307,24 @@ angular.module('formService', [])
return newdatearray.join('.');
}
};
generator.doItemAction = function ($scope, key, cmd) {
$scope.form_params.cmd = cmd;
$scope.form_params.object_id = key;
$scope.form_params.param = $scope.param;
$scope.form_params.id = $scope.param_id;
$scope.form_params.token = $scope.token;
generator.get_wf($scope);
generator.doItemAction = function ($scope, key, cmd, mode) {
// mode could be in ['normal', 'modal', 'new'] . the default mode is 'normal' and it loads data on same
// tab without modal. 'modal' will use modal to manipulate data and do all actions in that modal. 'new'
// will be open new page with response data
var _do = {
normal: function(){
$log.debug('normal mode starts');
$scope.form_params.cmd = cmd;
$scope.form_params.object_id = key;
$scope.form_params.param = $scope.param;
$scope.form_params.id = $scope.param_id;
$scope.form_params.token = $scope.token;
return generator.get_wf($scope);
},
modal: function(){$log.debug('modal mode is not not ready');},
new: function(){$log.debug('new mode is not not ready');}
};
return _do[mode]();
};
generator.get_form = function (scope) {
......@@ -377,6 +409,7 @@ angular.module('formService', [])
/**
* pathDecider is used to redirect related path by looking up the data in response
* @param client_cmd
* @param $scope
* @param data
*/
......@@ -388,7 +421,8 @@ angular.module('formService', [])
* redirectTo function redirects to related controller and path with given data
* before redirect setPageData must be called and pageData need to be defined
* otherwise redirected path will call api for its data
* @param scope, page
* @param scope
* @param page
*/
function redirectTo(scope, page) {
var pathUrl = '/' + scope.form_params.wf;
......
......@@ -6,15 +6,19 @@
* (GPLv3). See LICENSE.txt for details.
*/
'use strict';
describe('form service module', function () {
beforeEach(module('ulakbus'));
beforeEach(module('formService'));
var location;
beforeEach(inject(function($location) {
beforeEach(inject(function($location, $injector) {
location = $location;
// Set up the mock http service responses
$httpBackend = $injector.get('$httpBackend');
// backend definition common for all tests
authRequestHandler = $httpBackend.when('GET', /\.[0-9a-z]+$/i)
.respond({userId: 'userX'}, {'A-Token': 'xxx'});
}));
describe('form service', function () {
......@@ -23,7 +27,7 @@ describe('form service module', function () {
function (Generator) {
expect(Generator.group).not.toBe(null);
var generated_url = Generator.makeUrl({url: 'test', form_params: {}});
expect(generated_url).toEqual("//nightly.api.ulakbus.net/test/");
expect(generated_url).toEqual("//api.ulakbus.net/test/");
}])
);
......@@ -175,15 +179,15 @@ describe('form service module', function () {
it('should get list',
inject(function (Generator, $httpBackend, RESTURL) {
$httpBackend.expectGET(RESTURL.url + 'test/personel')
$httpBackend.expectPOST(RESTURL.url + 'test/personel', {cmd: 'list', model: "personel", object_id: "5821bc25a90aa1"})
.respond(200, {
items: {
"client_cmd": "list_objects",
"is_login": true,
"objects":[
["Ad\u0131", "Soyad\u0131", "TC No", "Durum"],
["Ad\u0131", "Soyad\u0131", "TC No", "Durum"],
["4MsKRH9435cdKOzKCITNPml5bhB", "firstname", "lastname", "dksoap", false]
],
],
"token": "0122b2843f504c15821bc25a90aa1370"
}
});
......@@ -317,10 +321,12 @@ describe('form service module', function () {
object_id: 'xxx11',
wf:'testModel'};
scope.url = 'test';
Generator.get_wf(scope);
$httpBackend.flush();
expect(location.path()).toEqual('/testModel/testModel/add');
expect(location.path()).toEqual('/testModel/testModel/do/f');
})
);
......
This diff is collapsed.
......@@ -1649,7 +1649,7 @@ table.dataTable thead .sorting:after {
}
/* end page transitions */
.movetobottom {
.move-to-bottom, .move-to-top {
margin-right: 10px !important;
}
......
......@@ -24,7 +24,6 @@ angular.module("components/crud/templates/crud.html", []).run(["$templateCache",
$templateCache.put("components/crud/templates/crud.html",
"<crud-show-directive ng-if=\"object\"></crud-show-directive>\n" +
"<crud-form-directive ng-if=\"forms\"></crud-form-directive>\n" +
"<hr class=\"col-md-12\">\n" +
"<crud-list-directive ng-if=\"objects\"></crud-list-directive>");
}]);
......@@ -33,6 +32,8 @@ angular.module("components/crud/templates/form.html", []).run(["$templateCache",
"<div class=\"container\">\n" +
" <h1>{{ schema.title }}</h1>\n" +
"\n" +
" <div class=\"buttons-on-top\"></div>\n" +
"\n" +
" <form id=\"formgenerated\" name=\"formgenerated\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\"\n" +
" ng-submit=\"onSubmit(formgenerated)\" form-locator></form>\n" +
"\n" +
......@@ -66,6 +67,7 @@ angular.module("components/crud/templates/form.html", []).run(["$templateCache",
" </div>\n" +
"\n" +
" <div class=\"buttons-on-bottom\"></div>\n" +
"\n" +
"</div>");
}]);
......@@ -74,7 +76,7 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
"<div class=\"starter-template container\">\n" +
" <search-directive ng-if=\"meta['allow_search']===true\"></search-directive>\n" +
" <div class=\"clearfix\"></div>\n" +
" <h1>{{form_params.model || form_params.wf}}</h1>\n" +
" <!--<h1>{{form_params.model || form_params.wf}}</h1>-->\n" +
" <div class=\"row\" ng-if=\"!objects[1]\">\n" +
" <div class=\"col-md-12\">\n" +
" <p class=\"no-content\">Listelenecek içerik yok.</p>\n" +
......@@ -107,13 +109,14 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
" <td ng-repeat=\"field in object.fields track by $index\">\n" +
" <a ng-href=\"javascript:void(0)\"\n" +
" ng-if=\"field.type==='link'\"\n" +
" ng-click=\"do_action(object.key, field.cmd)\">{{field.content}}</a>\n" +
" ng-click=\"do_action(object.key, field.cmd, field.mode)\">{{field.content}}</a>\n" +
" <span ng-if=\"field.type==='str'\">{{field.content}}</span>\n" +
" </td>\n" +
"\n" +
" <td>\n" +
" <button class=\"btn btn-primary\" style=\"margin-right: 5px;\" ng-repeat=\"action in object.actions\"\n" +
" ng-if=\"action.show_as==='button'\" ng-click=\"do_action(object.key, action.cmd)\">{{action\n" +
" ng-if=\"action.show_as==='button'\"\n" +
" ng-click=\"do_action(object.key, action.cmd, action.mode)\">{{action\n" +
" .name}}\n" +
" </button>\n" +
" <br>\n" +
......@@ -1455,7 +1458,7 @@ angular.module("shared/templates/foreignKey.html", []).run(["$templateCache", fu
" sf-changed=\"form\"\n" +
" class=\"form-control {{form.fieldHtmlClass}}\"\n" +
" schema-validate=\"form\"\n" +
" name=\"{{form.model_name}}\"/>\n" +
" name=\"{{form.model_name}}\" value=\"{{form.selected_item}}\"/>\n" +
" </div>\n" +
"\n" +
" <!--<select ng-model=\"$$value$$\"-->\n" +
......
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