Commit c2faf4f9 authored by Evren Kutar's avatar Evren Kutar

form custom buttons

if forms key in returned data redraw form
sidebar notifications in progress (not work with 'replace:true')
recorrect tests
parent 7d7e4b64
...@@ -38,7 +38,6 @@ crud.controller('CRUDAddEditCtrl', function ($scope, $rootScope, $location, $htt ...@@ -38,7 +38,6 @@ 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){
debugger;
$location.path('/crud/'+$scope.form_params.model).search(data); $location.path('/crud/'+$scope.form_params.model).search(data);
}) })
.error(function(data){ .error(function(data){
......
This diff is collapsed.
...@@ -69,4 +69,23 @@ angular.module('ulakbus.dashboard', ['ngRoute']) ...@@ -69,4 +69,23 @@ angular.module('ulakbus.dashboard', ['ngRoute'])
// $rootScope.selectedUser = {name: $cookies.get("selectedUserName"), tcno: $cookies.get("selectedUserTcNo"), key: $cookies.get("selectedUserKey")}; // $rootScope.selectedUser = {name: $cookies.get("selectedUserName"), tcno: $cookies.get("selectedUserTcNo"), key: $cookies.get("selectedUserKey")};
//} //}
$scope.$on("notifications", function (event, data) {
$scope.notifications = data;
});
})
.directive('sidebarNotifications', function () {
return {
templateUrl: 'shared/templates/directives/sidebar-notification.html',
restrict: 'E',
replace: true,
link: function ($scope) {
// sidebar notifications from rootScope broadcast
//$scope.$on("notifications", function (event, data) {
// $scope.notifications = data;
//});
}
}
}); });
...@@ -29,11 +29,11 @@ describe('dashboard controller module', function () { ...@@ -29,11 +29,11 @@ describe('dashboard controller module', function () {
expect($controller).toBeDefined(); expect($controller).toBeDefined();
})); }));
it('should define section', function() { //it('should define section', function() {
var $scope = {}; // var $scope = {};
var controller = $controller('DashCtrl', { $scope: $scope }); // var controller = $controller('DashCtrl', { $scope: $scope });
$scope.section('test_section'); // $scope.section('test_section');
expect($rootScope.section).toBe('test_section'); // expect($rootScope.section).toBe('test_section');
}); //});
}); });
}); });
\ No newline at end of file
<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 }}
...@@ -9,6 +10,7 @@ ...@@ -9,6 +10,7 @@
</a> </a>
</span> </span>
</h3> </h3>
<div class="node-table"> <div class="node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include> <ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div> </div>
...@@ -22,12 +24,13 @@ ...@@ -22,12 +24,13 @@
</a> </a>
</span> </span>
</h3> </h3>
<div class="list-node-table"> <div class="list-node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include> <ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div> </div>
<hr> <hr>
</div> </div>
<button id="submitbutton" type="button" class="btn btn-primary" ng-click="onSubmit(formgenerated)">Kaydet</button> <!--<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-warning">Düzenle</button> todo: make it conditional -->
<!-- <button type="button" class="btn btn-danger">İptal</button> todo: turn back to previous page --> <!-- <button type="button" class="btn btn-danger">İptal</button> todo: turn back to previous page -->
\ No newline at end of file
...@@ -38,11 +38,10 @@ crud.controller('WFAddEditCtrl', function ($scope, $rootScope, $location, $http, ...@@ -38,11 +38,10 @@ crud.controller('WFAddEditCtrl', function ($scope, $rootScope, $location, $http,
if (form.$valid) { if (form.$valid) {
Generator.submit($scope) Generator.submit($scope)
.success(function(data){ .success(function(data){
debugger;
$location.path('/crud/'+$scope.form_params.model).search(data);
}) })
.error(function(data){ .error(function(data){
$scope.message = data.title; //$scope.message = data.title;
}); });
} }
}; };
......
...@@ -26,7 +26,7 @@ app.directive('logout', function ($http, $location, RESTURL) { ...@@ -26,7 +26,7 @@ app.directive('logout', function ($http, $location, RESTURL) {
* headerNotification directive for header * headerNotification directive for header
*/ */
app.directive('headerNotification', function ($http, $interval, RESTURL) { app.directive('headerNotification', function ($http, $rootScope, $interval, RESTURL) {
return { return {
templateUrl: 'shared/templates/directives/header-notification.html', templateUrl: 'shared/templates/directives/header-notification.html',
restrict: 'E', restrict: 'E',
...@@ -35,9 +35,17 @@ app.directive('headerNotification', function ($http, $interval, RESTURL) { ...@@ -35,9 +35,17 @@ app.directive('headerNotification', function ($http, $interval, RESTURL) {
$interval(function () { $interval(function () {
// ignore loading bar here // ignore loading bar here
$http.get(RESTURL.url+"notify", {ignoreLoadingBar: true}).success(function (data) { $http.get(RESTURL.url+"notify", {ignoreLoadingBar: true}).success(function (data) {
$scope.notifications = data; // notification categories:
// 1: tasks, 2: messages, 3: announcements, 4: recents
$scope.notifications = {1: [], 2: [], 3: [], 4: []};
angular.forEach(data.notifications, function (value, key) {
$scope.notifications[value.type].push(value);
});
$rootScope.$broadcast("notifications", $scope.notifications);
console.log($scope.notifications);
}); });
}, 15000); }, 5000);
} }
}; };
}); });
...@@ -144,22 +152,23 @@ app.directive('sidebar', ['$location', function () { ...@@ -144,22 +152,23 @@ app.directive('sidebar', ['$location', function () {
controller: function ($scope, $rootScope, $cookies, $http, RESTURL, $location, $timeout) { controller: function ($scope, $rootScope, $cookies, $http, RESTURL, $location, $timeout) {
var sidebarmenu = $('#side-menu'); var sidebarmenu = $('#side-menu');
sidebarmenu.metisMenu(); sidebarmenu.metisMenu();
$http.get(RESTURL.url + 'menu/').success(function (data) { $http.get(RESTURL.url + 'menu/')
$scope.allMenuItems = angular.copy(data); .success(function (data) {
$scope.allMenuItems = angular.copy(data);
// broadcast for authorized menu items, consume in dashboard // broadcast for authorized menu items, consume in dashboard
$rootScope.$broadcast("authz", data); $rootScope.$broadcast("authz", data);
$scope.menuItems = {"other": $scope.allMenuItems.other}; $scope.menuItems = {"other": $scope.allMenuItems.other};
// if selecteduser on cookie then add related part to the menu // if selecteduser on cookie then add related part to the menu
//if ($cookies.get("selectedUserType")) { //if ($cookies.get("selectedUserType")) {
// $scope.menuItems[$cookies.get("selectedUserType")] = $scope.allMenuItems[$cookies.get("selectedUserType")]; // $scope.menuItems[$cookies.get("selectedUserType")] = $scope.allMenuItems[$cookies.get("selectedUserType")];
//} //}
$timeout(function(){sidebarmenu.metisMenu()}); $timeout(function(){sidebarmenu.metisMenu()});
}); });
// changing menu items by listening for broadcast // changing menu items by listening for broadcast
......
<ul class="nav navbar-top-links navbar-right"> <ul class="nav navbar-top-links navbar-right">
<li class="dropdown"> <li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-envelope fa-fw"></i> <i class="fa fa-caret-down"></i>
<span class="fa-stack">
<i class="fa fa-envelope fa-fw fa-stack-1x"></i>
<i class="fa fa-stack-1x fa-fw">1</i>
</span>
<i class="fa fa-caret-down"></i>
</a> </a>
<ul class="dropdown-menu dropdown-messages"> <ul class="dropdown-menu dropdown-messages">
<li> <li>
......
<div class="right-sidebar">
<div class="right-sidebar-box">
<div class="right-sidebar-messages">
<div class="right-sidebar-title clearfix">
<h3>Mesajlar</h3>
<span><a href="javascript:void(0)">Tüm Mesajlar</a></span>
</div>
<!-- end of right-sidebar-title -->
<div class="right-sidebar-message-block" ng-repeat="notify in notifications[2] | limitTo:5">
<a class="clearfix" href="javascript:void(0)">
<img src="../../../img/sample-profile-pic.jpg">
<div class="right-sidebar-message-content">
<div>{{notify.title}}</div>
<div>{{notify.body}}</div>
<div>16:05</div>
</div>
<!-- end of right-sidebar-message-content -->
</a>
</div>
<!-- end of right-sidebar-message-block -->
</div>
<!-- end of right-sidebar-messages -->
</div>
<!-- end of right-sidebar-box -->
<div class="right-sidebar-box">
<div class="right-sidebar-tasks">
<div class="right-sidebar-title clearfix">
<h3>Görevler</h3>
<span><a href="javascript:void(0)">Tüm Görevler</a></span>
</div>
<!-- end of right-sidebar-title -->
<!--<div class="right-sidebar-task-block">-->
<!--<div class="task-type">Devam Eden Görevler</div>-->
<!--<a href="javascript:void(0)">-->
<!--<div class="task-title">Öğrenci Kayıt</div>-->
<!--<div class="progress">-->
<!--<div class="progress-bar" role="progressbar" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width:25%;">-->
<!--25%-->
<!--</div>-->
<!--</div>-->
<!--&lt;!&ndash; end of progress &ndash;&gt;-->
<!--</a>-->
<!--</div>-->
<!-- end of right-sidebar-task-block -->
<div class="right-sidebar-task-block">
<div class="task-type">Onay Bekleyen Görevler</div>
<a href="javascript:void(0)" ng-repeat="notify in notifications[1] | limitTo:5">
<div class="task-title">{{notify.title}}</div>
</a>
</div>
<!-- end of right-sidebar-task-block -->
</div>
<!-- end of right-sidebar-tasks -->
</div>
<!-- end of right-sidebar-box -->
<div class="right-sidebar-box">
<div class="right-sidebar-announcements">
<div class="right-sidebar-title clearfix">
<h3>Duyurular</h3>
<span><a href="javascript:void(0)">Tüm Duyurular</a></span>
</div>
<!-- end of right-sidebar-title -->
<div class="right-sidebar-announcement-block">
<a href="javascript:void(0)" ng-repeat="notify in notifications[3] | limitTo:5">{{notify.body}}</a>
</div>
<!-- end of right-sidebar-status-block -->
</div>
<!-- end of right-sidebar-status -->
</div>
<!-- end of right-sidebar-box -->
<div class="right-sidebar-box">
<div class="right-sidebar-last-actions">
<div class="right-sidebar-title clearfix">
<h3>Son İşlemler</h3>
<span><a href="javascript:void(0)">Tüm İşlemler</a></span>
</div>
<!-- end of right-sidebar-title -->
<div class="right-sidebar-last-action-block">
<a href="javascript:void(0)">Birinci dönem bitimine 10 gün kaldı.</a>
<a href="javascript:void(0)">Ders seçimi işlemleri xx tarihinde başlayacaktır.</a>
</div>
<!-- end of right-sidebar-status-block -->
</div>
<!-- end of right-sidebar-status -->
</div>
<!-- end of right-sidebar-box -->
</div>
<!-- end of right-sidebar -->
\ No newline at end of file
...@@ -9,8 +9,8 @@ var form_generator = angular.module('formService', ['general']); ...@@ -9,8 +9,8 @@ var form_generator = angular.module('formService', ['general']);
form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, FormDiff, $rootScope) { form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, FormDiff, $rootScope) {
var generator = {}; var generator = {};
generator.makePostUrl = function (url) { generator.makePostUrl = function (scope) {
return RESTURL.url + url; return RESTURL.url + scope.url;
}; };
generator.makeGetUrl = function (scope) { generator.makeGetUrl = function (scope) {
if (scope.form_params.cmd === "list") { if (scope.form_params.cmd === "list") {
...@@ -62,6 +62,16 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form ...@@ -62,6 +62,16 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form
angular.forEach(scope.schema.properties, function (k, v) { angular.forEach(scope.schema.properties, function (k, v) {
// check if type is date and if type date found change it to string // check if type is date and if type date found change it to string
if (k.type === 'submit' || k.type === 'button') {
//k.type = 'button';
angular.forEach(scope.form, function (value, key) {
if (value === v) {
k.type = 'button';
scope.form[key] = {type: k.type, title: k.title, onClick: function(){scope.model[v]=1;generator.submit(scope);}};
}
});
}
if (k.type === 'date') { if (k.type === 'date') {
k.type = 'string'; k.type = 'string';
scope.model[v] = generator.dateformatter(scope.model[v]); scope.model[v] = generator.dateformatter(scope.model[v]);
...@@ -186,7 +196,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form ...@@ -186,7 +196,7 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form
}; };
generator.get_form = function (scope) { generator.get_form = function (scope) {
return $http return $http
.post(generator.makePostUrl(scope.url), scope.form_params) .post(generator.makePostUrl(scope), scope.form_params)
.then(function (res) { .then(function (res) {
return generator.generate(scope, res.data); return generator.generate(scope, res.data);
}); });
...@@ -239,6 +249,11 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form ...@@ -239,6 +249,11 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form
return deferred.promise; return deferred.promise;
} }
}; };
// custom form submit for custom submit buttons
generator.genericSubmit = function ($scope, data) {
debugger;
return $http.post(generator.makePostUrl($scope), data);
};
generator.submit = function ($scope) { generator.submit = function ($scope) {
// todo: diff for all submits to recognize form change. if no change returns to view with no submit // todo: diff for all submits to recognize form change. if no change returns to view with no submit
angular.forEach($scope.ListNode, function (value, key) { angular.forEach($scope.ListNode, function (value, key) {
...@@ -260,16 +275,14 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form ...@@ -260,16 +275,14 @@ form_generator.factory('Generator', function ($http, $q, $timeout, RESTURL, Form
//data.form = get_diff; //data.form = get_diff;
} }
return $http.post(generator.makePostUrl($scope.url), data); return $http.post(generator.makePostUrl($scope), data)
//.success(function () { .success(function (data) {
// // if return data consists forms key then trogger redraw the form with updated data
//}) if (data.forms) {
//.then(function (res) { generator.generate($scope, data);
// if (res.data.client_cmd) { $scope.$broadcast('schemaFormRedraw')
// console.log("record fin"); }
// $location.path($scope.form_params.model); });
// }
//});
}; };
return generator; return generator;
}); });
......
...@@ -17,7 +17,7 @@ describe('form service module', function () { ...@@ -17,7 +17,7 @@ describe('form service module', function () {
it('should generate url', inject(['Generator', it('should generate url', inject(['Generator',
function (Generator) { function (Generator) {
expect(Generator.group).not.toBe(null); expect(Generator.group).not.toBe(null);
var generated_url = Generator.makePostUrl('test'); var generated_url = Generator.makePostUrl({url: 'test'});
expect(generated_url).toEqual("http://api.ulakbus.net/test"); expect(generated_url).toEqual("http://api.ulakbus.net/test");
}]) }])
); );
...@@ -168,7 +168,7 @@ describe('form service module', function () { ...@@ -168,7 +168,7 @@ describe('form service module', function () {
it('should get list', it('should get list',
inject(function (Generator, $httpBackend, RESTURL) { inject(function (Generator, $httpBackend, RESTURL) {
$httpBackend.expectGET(RESTURL.url + 'test/') $httpBackend.expectGET(RESTURL.url + 'test/personel')
.respond(200, { .respond(200, {
items: { items: {
"client_cmd": "list_objects", "client_cmd": "list_objects",
...@@ -193,7 +193,7 @@ describe('form service module', function () { ...@@ -193,7 +193,7 @@ describe('form service module', function () {
} }
}); });
var cred = {cmd: 'list', param: "personel", object_id: "5821bc25a90aa1"}; var cred = {cmd: 'list', model: "personel", object_id: "5821bc25a90aa1"};
Generator.get_list({url: 'test/', form_params: cred}) Generator.get_list({url: 'test/', form_params: cred})
.then(function (data) { .then(function (data) {
expect(data.data.items.token).toEqual("0122b2843f504c15821bc25a90aa1370"); expect(data.data.items.token).toEqual("0122b2843f504c15821bc25a90aa1370");
...@@ -206,7 +206,7 @@ describe('form service module', function () { ...@@ -206,7 +206,7 @@ describe('form service module', function () {
it('should get single item', it('should get single item',
inject(function (Generator, $httpBackend, RESTURL) { inject(function (Generator, $httpBackend, RESTURL) {
$httpBackend.expectPOST(RESTURL.url + 'test', {cmd: 'show'}) $httpBackend.expectGET(RESTURL.url + 'test/personel?personel=123')
.respond(200, { .respond(200, {
items: { items: {
"client_cmd": "show_object", "client_cmd": "show_object",
...@@ -219,8 +219,8 @@ describe('form service module', function () { ...@@ -219,8 +219,8 @@ describe('form service module', function () {
} }
}); });
var cred = {cmd: 'show'}; var cred = {cmd: 'show', model: 'personel', param: 'personel', object_id: '123'};
Generator.get_list({url: 'test', form_params: cred}) Generator.get_single_item({url: 'test/', form_params: cred})
.then(function (data) { .then(function (data) {
expect(data.data.items.token).toEqual("da73993f439549e7855fd82deafbbc99"); expect(data.data.items.token).toEqual("da73993f439549e7855fd82deafbbc99");
}); });
......
...@@ -10,7 +10,7 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -10,7 +10,7 @@ app.config(['$httpProvider', function ($httpProvider) {
* the interceptor for all requests to check response * the interceptor for all requests to check response
* 4xx - 5xx errors will be handled here * 4xx - 5xx errors will be handled here
*/ */
$httpProvider.interceptors.push(function ($q, $rootScope, $location) { $httpProvider.interceptors.push(function ($q, $rootScope, $location, $timeout) {
return { return {
'request': function (config) { 'request': function (config) {
// todo: delete console logs // todo: delete console logs
...@@ -46,10 +46,9 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -46,10 +46,9 @@ app.config(['$httpProvider', function ($httpProvider) {
$location.reload(); $location.reload();
} }
if (rejection.status === 401) { if (rejection.status === 401) {
$location.path('/login');
if ($location.path() === "/login") { if ($location.path() === "/login") {
console.log("show errors on login form"); console.log("show errors on login form");
} else {
$location.path('/login');
} }
} }
if (rejection.status === 403) { if (rejection.status === 403) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"json3": "~3.3.2", "json3": "~3.3.2",
"es5-shim": "~4.1.10", "es5-shim": "~4.1.10",
"angular-mocks": "1.4.x", "angular-mocks": "1.4.x",
"angular-animate": "1.4.x",
"angular-route": "1.4.x", "angular-route": "1.4.x",
"angular-resource": "1.4.x", "angular-resource": "1.4.x",
"angular-cookies": "1.4.x", "angular-cookies": "1.4.x",
......
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