Commit 89e95582 authored by Evren Kutar's avatar Evren Kutar

ADD markdown filter support for content

rfix #5015
REFACTOR $http service of angular to native websocket
FIX app-wide fixes for websocket support
REFACTOR error handling move to error_service from interceptors
rref #5120
parent 478646db
......@@ -124,6 +124,7 @@ module.exports = function (grunt) {
"app/zetalib/interceptors.js",
"app/zetalib/general.js",
"app/zetalib/form_service.js",
"app/zetalib/error_service.js",
"app/zetalib/action_service.js",
"app/zetalib/socket.js",
"app/shared/directives.js",
......@@ -150,6 +151,8 @@ module.exports = function (grunt) {
"app/bower_components/angular-resource/angular-resource.js",
"app/bower_components/angular-bootstrap/ui-bootstrap.js",
"app/bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"app/bower_components/showdown/dist/showdown.min.js",
"app/bower_components/angular-markdown-filter/markdown.js",
"app/bower_components/angular-sanitize/angular-sanitize.js",
"app/bower_components/tv4/tv4.js",
"app/bower_components/objectpath/lib/ObjectPath.js",
......
......@@ -36,6 +36,7 @@ angular.module(
'ulakbus.devSettings',
'ulakbus.version',
'gettext',
'markdown',
])
/**
* @memberof ulakbus
......@@ -75,4 +76,9 @@ angular.module(
.constant('toastr', window.toastr)
.config(function ($logProvider) {
$logProvider.debugEnabled(true);
})
.config(function(markdownProvider) {
//markdownProvider.config({
// extensions: ['table']
//});
});
\ No newline at end of file
......@@ -53,6 +53,8 @@ angular.module('ulakbus')
$rootScope.loggedInUser = true;
$rootScope.loginAttempt = 0;
$rootScope.websocketIsOpen = false;
$rootScope.current_user = true;
$rootScope.$on("$routeChangeStart", function (event, next, current) {
// will be used when needed
});
......
......@@ -25,19 +25,17 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies'])
* @description LoginCtrl responsible to handle login process.<br>
* Using 'ulakbus.formService.get_form' function generates the login form and post it to the API with input datas.
*/
.controller('LoginController', function ($scope, $q, $timeout, $routeParams, $rootScope, $log, Generator, AuthService) {
.controller('LoginController', function ($scope, $q, $timeout, $location, $routeParams, $rootScope, $log, Generator, AuthService) {
$scope.url = 'login';
$scope.form_params = {};
$scope.form_params['clear_wf'] = 1;
Generator.get_form($scope).then(function (data) {
AuthService.get_form($scope).then(function (data) {
if (data.login) { $location.path('/'); }
$scope.form = [
{key: "username", type: "string", title: "Kullanıcı Adı"},
{key: "password", type: "password", title: "Şifre"},
{type: 'submit', title: 'Giriş Yap'}
];
// to show page items showApp must be set to true
// it prevents to show empty nonsense page items when http401/403
//$rootScope.showApp = true;
});
$scope.loggingIn = false;
$scope.onSubmit = function (form) {
......@@ -47,6 +45,10 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies'])
$rootScope.loginAttempt = 1;
Generator.button_switch(false);
AuthService.login($scope.url, $scope.model)
.success(function (data) {
$scope.message = data.title;
$scope.loggingIn = false;
})
.error(function (data) {
$scope.message = data.title;
$scope.loggingIn = false;
......
......@@ -15,9 +15,17 @@ angular.module('ulakbus.auth')
* @name AuthService
* @description provides generic functions for authorization process.
*/
.factory('AuthService', function ($http, $rootScope, $location, $log, Generator, RESTURL) {
.factory('AuthService', function ($http, $rootScope, $location, $log, $route, Generator, RESTURL, WSOps) {
var authService = {};
authService.get_form = function (scope) {
return $http
.post(Generator.makeUrl(scope), scope.form_params)
.then(function (res) {
return Generator.generate(scope, res.data);
});
};
/**
* @memberof ulakbus.auth
* @ngdoc function
......@@ -36,11 +44,19 @@ angular.module('ulakbus.auth')
.success(function (data, status, headers, config) {
//$window.sessionStorage.token = data.token;
Generator.button_switch(true);
$rootScope.loggedInUser = true;
if (data.status_code !== 403) {
$rootScope.loggedInUser = true;
$rootScope.$broadcast("regenerate_menu");
$location.path('/dashboard');
}
if (data.status_code === 403) {
data.title = "İşlem başarısız oldu. Lütfen girdiğiniz bilgileri kontrol ediniz.";
return data;
}
})
.error(function (data, status, headers, config) {
// Handle login errors here
data.title = "İşlem başarısız oldu. Lütfen girdiğiniz bilgileri kontrol ediniz."
data.title = "İşlem başarısız oldu. Lütfen girdiğiniz bilgileri kontrol ediniz.";
return data;
});
};
......@@ -54,8 +70,9 @@ angular.module('ulakbus.auth')
* @returns {*}
*/
authService.logout = function () {
$log.debug("logout");
return $http.post(RESTURL.url + 'logout', {}).success(function (data) {
$rootScope.loginAttempt = 0;
WSOps.request({wf: 'logout'}).then(function (data) {
$rootScope.loggedInUser = false;
$log.debug("loggedout");
$location.path("/login");
......
<div ng-app="ulakbus.auth" class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Giriş Yap <span ng-if="loggingIn" class="loader pull-right"></span></h3>
</div>
<div class="panel-body">
<span class="label label-warning">{{message}}</span>
<form name="loginForm" sf-schema="schema" sf-form="form" sf-model="model" ng-submit="onSubmit(loginForm)"></form>
<div style="width: 100%; height: 100%; position: fixed; z-index: 1100; top:0; left:0; background: #fff;">
<div ng-app="ulakbus.auth" class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="login-panel panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Giriş Yap <span ng-if="loggingIn" class="loader pull-right"></span></h3>
</div>
<div class="panel-body">
<form name="loginForm" sf-schema="schema" sf-form="form" sf-model="model"
ng-submit="onSubmit(loginForm)"></form>
</div>
</div>
<span class="label label-inverse label-warning">{{message}}</span>
</div>
</div>
</div>
......
......@@ -154,6 +154,12 @@ angular.module('ulakbus.crud', ['schemaForm', 'ulakbus.formService'])
*/
.controller('CRUDListFormController', function ($scope, $rootScope, $location, $sce, $http, $log, $uibModal, $timeout, Generator, $routeParams, CrudUtility) {
$scope.paginate = function (reloadData) {
$scope.form_params.cmd = $scope.reload_cmd;
$scope.form_params = angular.extend($scope.form_params, reloadData);
$log.debug('reload data', $scope);
Generator.get_wf($scope);
};
$scope.$on('reload_cmd', function(event, data){
$scope.reload_cmd = data;
$scope.reloadCmd();
......
......@@ -34,8 +34,8 @@
<td ng-repeat="field in object.fields track by $index">
<a role="button" ng-if="field.type==='link'"
ng-click="do_action(object.key, field)" ng-bind-html="field.content"></a>
<span ng-if="field.type==='str'" ng-bind-html="field.content"></span>
ng-click="do_action(object.key, field)" ng-bind-html="field.content | markdown"></a>
<span ng-if="field.type==='str'" ng-bind-html="field.content | markdown"></span>
</td>
<td>
......@@ -55,16 +55,16 @@
<nav ng-if="pagination && pagination.total_pages > 1" class="text-center">
<ul class="pagination">
<li ng-class="{disabled:pagination.page===1}">
<a aria-label="Önceki" ng-click="reload({page:pagination.page-1})">
<a aria-label="Önceki" ng-click="paginate({page:pagination.page-1})">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li ng-repeat="page in getNumber(pagination.total_pages) track by $index"
ng-class="{active:$index+1===pagination.page}">
<a ng-click="reload({page:$index+1})">{{$index+1}}</a>
<a ng-click="paginate({page:$index+1})">{{$index+1}}</a>
</li>
<li ng-class="{disabled:pagination.page===pagination.total_pages}">
<a aria-label="Sonraki" ng-click="reload({page:pagination.page+1})">
<a aria-label="Sonraki" ng-click="paginate({page:pagination.page+1})">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
......
......@@ -21,7 +21,8 @@ angular.module('ulakbus.dashboard', [])
$uibTooltipProvider.setTriggers({'click': 'mouseleave'});
})
.controller('DashController', function ($scope, $rootScope, $timeout, $http, $cookies, RESTURL, Generator) {
.controller('DashController', function ($scope, $rootScope, $routeParams, $route, $timeout, $http, $cookies, RESTURL, Generator, WSOps) {
$scope.section = function (section_index) {
$rootScope.section = section_index;
};
......@@ -37,28 +38,27 @@ angular.module('ulakbus.dashboard', [])
$scope.staffs = [];
$scope.search = function (where) {
$timeout(function () {
if (where === 'personel') {
// if input length greater than 2 search for the value
if ($scope.keyword.staff.length > 2) {
$scope.getItems(where, $scope.keyword.staff).success(function (data) {
if ($scope.keyword.staff.length > 2 || $scope.keyword.student.length > 2) {
$timeout(function () {
if (where === 'personel') {
// if input length greater than 2 search for the value
$scope.getItems(where, $scope.keyword.staff).then(function (data) {
$scope.staffs = data.results;
});
}
}
if (where === 'ogrenci') {
if ($scope.keyword.student.length > 2) {
$scope.getItems(where, $scope.keyword.student).success(function (data) {
if (where === 'ogrenci') {
$scope.getItems(where, $scope.keyword.student).then(function (data) {
$scope.students = data.results;
})
}
}
}, 500);
}, 500);
}
};
$scope.getItems = function (where, what) {
$scope.showResults = true;
return $http.get(RESTURL.url + 'ara/' + where + '/' + what);
return WSOps.request({view: where + '_ara', query: what});
};
$scope.userPopover = {templateUrl: 'components/dashboard/user-info.html'};
......@@ -96,7 +96,11 @@ angular.module('ulakbus.dashboard', [])
$scope.markAsRead = function (items) {
$rootScope.$broadcast("markasread", items);
}
};
//if ($routeParams.cmd = 'reload') {
// $route.reload();
//}
})
.directive('sidebarNotifications', function () {
......
......@@ -30,7 +30,7 @@
</head>
<body ng-controller="KeyListenController" ng-keydown="down($event)">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.loggedInUser">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.current_user">
<collapse-menu></collapse-menu>
<!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>-->
......@@ -53,12 +53,12 @@
<header-notification></header-notification>
</nav>
<sidebar ng-if="$root.loggedInUser"></sidebar>
<sidebar ng-if="$root.current_user"></sidebar>
<div class="manager-view">
<div class="manager-view-inner">
<!-- manager-header -->
<header-sub-menu ng-if="$root.loggedInUser"></header-sub-menu>
<header-sub-menu ng-if="$root.current_user"></header-sub-menu>
<!-- end of manager-header -->
<div class="manager-view-content">
<div class="row">
......@@ -82,10 +82,12 @@
<!--<script src="bower_components/angular-resource/angular-resource.min.js"></script>-->
<!--<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>-->
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="bower_components/showdown/dist/showdown.min.js"></script>
<script src="bower_components/angular-markdown-filter/markdown.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<script src="bower_components/tv4/tv4.js"></script>
<script src="bower_components/objectpath/lib/ObjectPath.js"></script>
<script src="bower_components/angular-schema-form/dist/schema-form.min.js"></script>
<script src="bower_components/angular-schema-form/dist/schema-form.js"></script>
<script src="bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="bower_components/angular-gettext/dist/angular-gettext.min.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
......@@ -106,6 +108,7 @@
<script src="zetalib/interceptors.js"></script>
<script src="zetalib/form_service.js"></script>
<script src="zetalib/action_service.js"></script>
<script src="zetalib/error_service.js"></script>
<script src="zetalib/socket.js"></script>
<!-- components -->
......
......@@ -37,7 +37,7 @@
</head>
<body ng-controller="KeyListenController" ng-keydown="down($event)">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.loggedInUser">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.current_user">
<collapse-menu></collapse-menu>
<!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>-->
......@@ -60,12 +60,12 @@
<header-notification></header-notification>
</nav>
<sidebar ng-if="$root.loggedInUser"></sidebar>
<sidebar ng-if="$root.current_user"></sidebar>
<div class="manager-view">
<div class="manager-view-inner">
<!-- manager-header -->
<header-sub-menu ng-if="$root.loggedInUser"></header-sub-menu>
<header-sub-menu ng-if="$root.current_user"></header-sub-menu>
<!-- end of manager-header -->
<div class="manager-view-content">
<div class="row">
......@@ -90,10 +90,12 @@
<!--<script src="bower_components/angular-resource/angular-resource.min.js"></script>-->
<!--<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>-->
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="bower_components/showdown/dist/showdown.min.js"></script>
<script src="bower_components/angular-markdown-filter/markdown.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<script src="bower_components/tv4/tv4.js"></script>
<script src="bower_components/objectpath/lib/ObjectPath.js"></script>
<script src="bower_components/angular-schema-form/dist/schema-form.min.js"></script>
<script src="bower_components/angular-schema-form/dist/schema-form.js"></script>
<script src="bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="bower_components/angular-gettext/dist/angular-gettext.min.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
......@@ -114,6 +116,7 @@
<script src="zetalib/interceptors.js"></script>
<script src="zetalib/form_service.js"></script>
<script src="zetalib/action_service.js"></script>
<script src="zetalib/error_service.js"></script>
<script src="zetalib/socket.js"></script>
<!-- components -->
......
......@@ -36,6 +36,7 @@ angular.module(
'ulakbus.devSettings',
'ulakbus.version',
'gettext',
'markdown',
// @if NODE_ENV='PRODUCTION'
'templates-prod',
// @endif
......@@ -85,4 +86,9 @@ angular.module(
// @if NODE_ENV='DEVELOPMENT'
$logProvider.debugEnabled(true);
// @endif
})
.config(function(markdownProvider) {
//markdownProvider.config({
// extensions: ['table']
//});
});
\ No newline at end of file
......@@ -14,14 +14,15 @@ angular.module('ulakbus')
* @description logout directive provides a button with click event. When triggered it post to
* '/logout' path of the API.
*/
.directive('logout', function ($http, $location, RESTURL) {
.directive('logout', function ($http, $location, RESTURL, AuthService) {
return {
link: function ($scope, $element, $rootScope) {
$element.on('click', function () {
$http.post(RESTURL.url + 'logout', {}).then(function () {
$rootScope.loggedInUser = false;
$location.path("/login");
});
AuthService.logout();
//$http.post(RESTURL.url + 'logout', {}).then(function () {
// $rootScope.loggedInUser = false;
// $location.path("/login");
//});
});
}
};
......@@ -61,10 +62,10 @@ angular.module('ulakbus')
*/
$scope.getNotifications = function () {
// ignore loading bar here
$http.get(RESTURL.url + "notify", {ignoreLoadingBar: true}).success(function (data) {
$scope.groupNotifications(data.notifications);
$rootScope.$broadcast("notifications", $scope.notifications);
});
//$http.get(RESTURL.url + "notify", {ignoreLoadingBar: true}).success(function (data) {
// $scope.groupNotifications(data.notifications);
// $rootScope.$broadcast("notifications", $scope.notifications);
//});
};
$scope.getNotifications();
......@@ -82,11 +83,11 @@ angular.module('ulakbus')
* @todo: do it in detail page of notification
*/
$scope.markAsRead = function (items) {
$http.post(RESTURL.url + "notify", {ignoreLoadingBar: true, read: [items]})
.success(function (data) {
$scope.groupNotifications(data.notifications);
$rootScope.$broadcast("notifications", $scope.notifications);
});
//$http.post(RESTURL.url + "notify", {ignoreLoadingBar: true, read: [items]})
// .success(function (data) {
// $scope.groupNotifications(data.notifications);
// $rootScope.$broadcast("notifications", $scope.notifications);
// });
};
// if markasread triggered outside the directive
......@@ -133,10 +134,10 @@ angular.module('ulakbus')
$scope.$broadcast('schemaFormValidate');
if (form.$valid) {
var searchparams = {
url: $scope.wf,
token: $scope.$parent.token,
object_id: $scope.$parent.object_id,
form_params: {
wf: $scope.$parent.wf,
model: $scope.$parent.form_params.model,
cmd: $scope.$parent.reload_cmd,
flow: $scope.$parent.form_params.flow,
......@@ -144,10 +145,7 @@ angular.module('ulakbus')
}
};
Generator.submit(searchparams).success(function (data) {
// update objects item of page scope
$rootScope.$broadcast('updateObjects', data.objects);
});
Generator.submit(searchparams);
}
};
}
......@@ -310,59 +308,66 @@ angular.module('ulakbus')
return newMenuItems;
};
var sidebarmenu = $('#side-menu');
sidebarmenu.metisMenu();
$http.get(RESTURL.url + 'menu/')
.success(function (data) {
$scope.allMenuItems = angular.copy(data);
// regroup menu items based on their category
function reGroupMenuItems(items, baseCategory) {
var newItems = {};
angular.forEach(items, function (value, key) {
newItems[value.kategori] = newItems[value.kategori] || [];
value['baseCategory'] = baseCategory;
newItems[value.kategori].push(value);
});
return newItems;
}
angular.forEach($scope.allMenuItems, function (value, key) {
if (key !== 'current_user' && key !== 'settings') {
$scope.allMenuItems[key] = reGroupMenuItems(value, key);
var generate_menu = function () {
var sidebarmenu = $('#side-menu');
sidebarmenu.metisMenu();
$http.get(RESTURL.url + 'menu', {ignoreLoadingBar: true})
.success(function (data) {
$scope.allMenuItems = angular.copy(data);
// regroup menu items based on their category
function reGroupMenuItems(items, baseCategory) {
var newItems = {};
angular.forEach(items, function (value, key) {
newItems[value.kategori] = newItems[value.kategori] || [];
value['baseCategory'] = baseCategory;
newItems[value.kategori].push(value);
});
return newItems;
}
});
// quick menus to dashboard via rootscope
angular.forEach($scope.allMenuItems, function (value, key) {
if (key !== 'current_user' && key !== 'settings') {
$scope.allMenuItems[key] = reGroupMenuItems(value, key);
}
});
$rootScope.quick_menu = reGroupMenuItems(data.quick_menu, 'quick_menus');
$rootScope.quick_menu = data.quick_menu;
delete data.quick_menu;
$log.debug('quick menu', $rootScope.quick_menu);
// quick menus to dashboard via rootscope
// broadcast for authorized menu items, consume in dashboard to show search inputs and/or
// related items
$rootScope.$broadcast("authz", data);
$rootScope.searchInputs = data;
$rootScope.quick_menu = reGroupMenuItems(data.quick_menu, 'quick_menus');
$rootScope.quick_menu = data.quick_menu;
delete data.quick_menu;
$log.debug('quick menu', $rootScope.quick_menu);
$rootScope.current_user = data.current_user;
if (data.ogrenci || data.personel) {
$rootScope.current_user.can_search = true;
}
$rootScope.settings = data.settings;
// broadcast for authorized menu items, consume in dashboard to show search inputs and/or
// related items
$rootScope.$broadcast("authz", data);
$rootScope.$broadcast("ws_turn_on");
$rootScope.searchInputs = data;
$scope.menuItems = $scope.prepareMenu({other: $scope.allMenuItems.other});
$rootScope.current_user = data.current_user;
if (data.ogrenci || data.personel) {
$rootScope.current_user.can_search = true;
}
$rootScope.settings = data.settings;
$timeout(function () {
sidebarmenu.metisMenu();
// to show page items showApp must be set to true
// it prevents to show empty nonsense page items when http401/403
//$rootScope.showApp = true;
$scope.menuItems = $scope.prepareMenu({other: $scope.allMenuItems.other});
$timeout(function () {
sidebarmenu.metisMenu();
});
})
.error(function (data, status, headers, config) {
$log.error('menu not retrieved', data);
$location.path('/login');
});
});
};
$scope.$on("regenerate_menu", function () {
generate_menu();
});
generate_menu();
// changing menu items by listening for broadcast
$scope.$on("menuitems", function (event, data) {
var menu = {};
menu[data] = $scope.allMenuItems[data];
......
/**
* Copyright (C) 2015 ZetaOps Inc.
*
* This file is licensed under the GNU General Public License v3
* (GPLv3). See LICENSE.txt for details.
*
* @author Evren Kutar
*/
angular.module('ulakbus')
.factory('ErrorService', function (toastr, $rootScope, $location, $log) {
var error_service = {};
error_service.handle = function (rejection, prtcl) {
var errorInModal;
if (prtcl === 'http') {
if (rejection.data) {
errorInModal = ('error' in rejection.data);
} else {
errorInModal = false;
}
}
if (prtcl === 'ws') {
rejection.status = rejection.status || rejection.code;
rejection.data = {error: rejection.error};
errorInModal = true;
}
var errorModal = function () {
if ($rootScope.loginAttempt === 0 && prtcl === 'http') {
$log.debug('not logged in, no alert message triggered');
return;
}
var codefield = "";
if (rejection.data.error) {
codefield = '<p><pre>' +
rejection.data.error +
'</pre></p>';
}
$('<div class="modal">' +
'<div class="modal-dialog" style="width:100%;" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span' +
' aria-hidden="true">&times;</span></button>' +
'<h4 class="modal-title" id="exampleModalLabel">' +
"Error Status: " + rejection.status + "<br>Error Title: " + rejection.data.title +
'</h4>' +
'</div>' +
'<div class="modal-body">' +
'<div class="alert alert-danger">' +
'<strong>' +
rejection.data.description +
'</strong>' +
codefield +
'</div>' +
'</div>' +
'<div class="modal-footer">' +
'<button type="button" class="btn btn-default" data-dismiss="modal">Kapat</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>').modal();
try {
$('pre:not(.hljs)').each(function (i, block) {
hljs.highlightBlock(block);
});
}
catch (e) {
$log.debug('Exception: ', e.message);
}
};
var errorInAlertBox = function (alertContent) {
if (errorInModal) {
errorModal();
} else {
if ($rootScope.loginAttempt > 0) {
toastr.error(alertContent.msg, alertContent.title);
}
}
};
var errorForAlertBox = {
title: rejection.status,
msg: rejection.data ? rejection.data.description : 'Error',
type: 'error'
};
var errorDispatch = {
"-1": function () {
//rejection.status = 'Sunucu hatası';
//rejection.data = rejection.data || {};
//rejection.data.title = rejection.data.title || "Sunucu Hatası";
//rejection.data.description = rejection.data.description || 'Sunucu bağlantısında bir hata oluştu. Lütfen yetkili personelle iletişime geçiniz.';
$log.error('-1 returned:', rejection);
//errorInAlertBox(errorForAlertBox);
//$location.path('/login');
},
"400": function () {
$location.reload();
},
"401": function () {
$location.path('/login');
if ($location.path() === "/login") {
$log.debug("show errors on login form");
}
},
"403": function () {
if (rejection.data.is_login === true) {
$rootScope.loggedInUser = true;
if ($location.path() === "/login") {
$location.path("/dashboard");
}
}
},
"404": function () {
errorInAlertBox(errorForAlertBox);
},
"500": function () {
errorInAlertBox(errorForAlertBox);
},
"503": function () {
rejection.data = {description: "Servise erişilemiyor."};
errorInAlertBox(errorForAlertBox);
}
};
errorDispatch[rejection.status]();
};
return error_service;
});
\ No newline at end of file
......@@ -182,10 +182,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
)
});
$log.debug('grouped form: ', newForm);
$log.debug('rest of form: ', scope.form);
$log.debug('form united: ', newForm.concat(scope.form));
if (newForm.length > 0) {
$log.debug('grouped form: ', newForm);
$log.debug('rest of form: ', scope.form);
$log.debug('form united: ', newForm.concat(scope.form));
}
scope.form = newForm.concat(scope.form);
return scope;
};
......@@ -598,7 +599,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
var modelScope = {
"url": v.wf,
"wf": v.wf,
"form_params": {model: v.model_name, cmd: v.list_cmd}
"form_params": {wf: v.wf, model: v.model_name, cmd: v.list_cmd}
};
//scope.$on('refreshTitleMap', function (event, data) {
......@@ -608,7 +609,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
scope.generateTitleMap = function (modelScope) {
return generator.get_list(modelScope).then(function (res) {
formitem.titleMap = [];
angular.forEach(res.data.objects, function (item) {
angular.forEach(res.objects, function (item) {
if (item !== -1) {
formitem.titleMap.push({
"value": item.key,
......@@ -624,28 +625,6 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
});
};
// get selected item from titleMap using model value
if (scope.model[k]) {
generator.get_list({
url: 'crud',
form_params: {model: v.model_name, object_id: scope.model[k], cmd: 'object_name'}
})
.then(function (data) {
try {
scope.$watch(document.querySelector('input[name=' + v.model_name + ']'),
function () {
document.querySelector('input[name=' + k + ']').value = data.data.object_name;
}
);
}
catch (e) {
document.querySelector('input[name=' + k + ']').value = data.data.object_name;
$log.debug('exception', e);
}
});
}
formitem = {
type: "template",
templateUrl: "shared/templates/foreignKey.html",
......@@ -689,6 +668,32 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
};
scope.form[scope.form.indexOf(k)] = formitem;
// get selected item from titleMap using model value
if (scope.model[k]) {
generator.get_list({
url: 'crud',
form_params: {
wf: v.wf,
model: v.model_name,
object_id: scope.model[k],
cmd: 'object_name'
}
})
.then(function (data) {
try {
$timeout(function () {
document.querySelector('input[name=' + k + ']').value = data.object_name;
}, 200);
}
catch (e) {
document.querySelector('input[name=' + k + ']').value = data.object_name;
$log.debug('exception', e);
}
});
}
}
},
Node: {
......@@ -760,6 +765,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
normal: function () {
$log.debug('normal mode starts');
$scope.form_params.cmd = todo.cmd;
$scope.form_params.wf = $scope.wf;
if (todo.wf) {
$scope.url = todo.wf;
$scope.form_params.wf = todo.wf;
......@@ -811,12 +817,22 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*}
*/
generator.get_form = function (scope) {
return $http
.post(generator.makeUrl(scope), scope.form_params)
.then(function (res) {
//generator.button_switch(true);
return generator.generate(scope, res.data);
});
if ($rootScope.websocketIsOpen === true) {
return WSOps.request(scope.form_params)
.then(function (data) {
return generator.generate(scope, data);
});
} else {
$timeout(function () {
generator.get_form(scope);
}, 500);
}
//return $http
// .post(generator.makeUrl(scope), scope.form_params)
// .then(function (res) {
// //generator.button_switch(true);
// return generator.generate(scope, res.data);
// });
};
/**
* @memberof ulakbus.formService
......@@ -827,12 +843,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*}
*/
generator.get_list = function (scope) {
return $http
.post(generator.makeUrl(scope), scope.form_params)
.then(function (res) {
//generator.button_switch(true);
return res;
});
//return $http
// .post(generator.makeUrl(scope), scope.form_params)
// .then(function (res) {
// //generator.button_switch(true);
// return res;
// });
if ($rootScope.websocketIsOpen === true) {
return WSOps.request(scope.form_params)
.then(function (data) {
return data;
});
} else {
$timeout(function () {
generator.get_list(scope);
}, 500);
}
};
/**
* @memberof ulakbus.formService
......@@ -844,16 +871,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*}
*/
generator.get_wf = function (scope) {
//WSOps.request(scope.form_params)
// .then(function (data) {
// return generator.pathDecider(data.client_cmd, scope, data);
// });
if ($rootScope.websocketIsOpen === true) {
WSOps.request(scope.form_params)
.then(function (data) {
return generator.pathDecider(data.client_cmd || ['list'], scope, data);
});
} else {
$timeout(function () {
generator.get_wf(scope);
}, 500);
}
return $http
.post(generator.makeUrl(scope), scope.form_params)
.then(function (res) {
return generator.pathDecider(res.data.client_cmd, scope, res.data);
});
//return $http
// .post(generator.makeUrl(scope), scope.form_params)
// .then(function (res) {
// return generator.pathDecider(res.data.client_cmd, scope, res.data);
// });
};
/**
* @memberof ulakbus.formService
......@@ -928,7 +962,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
data['param'] = $scope.form_params.param;
data['param_id'] = $scope.form_params.id;
data['pageData'] = true;
data['second_client_cmd'] = client_cmd[1];
//data['second_client_cmd'] = client_cmd[1];
generator.setPageData(data);
redirectTo($scope, client_cmd[0]);
......@@ -1069,11 +1103,13 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
angular.forEach($scope.Node, function (value, key) {
$scope.model[key] = value.model;
});
var data = {
// todo: unused var delete
var send_data = {
"form": $scope.model,
"object_key": $scope.object_key,
"token": $scope.token,
"model": $scope.form_params.model,
"wf": $scope.form_params.wf,
"cmd": $scope.form_params.cmd,
"flow": $scope.form_params.flow,
"object_id": $scope.object_id,
......@@ -1081,37 +1117,43 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
"query": $scope.form_params.query
};
//WSOps.request(scope.form_params)
// .then(function (data) {
// return generator.pathDecider(data.client_cmd, $scope, data);
// });
if ($rootScope.websocketIsOpen === true) {
WSOps.request(send_data)
.then(function (data) {
return generator.pathDecider(data.client_cmd || ['list'], $scope, data);
});
} else {
$timeout(function () {
generator.scope($scope, redirectTo);
}, 500);
}
return $http.post(generator.makeUrl($scope), data)
.success(function (data, status, headers) {
if (headers('content-type') === "application/pdf") {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var file = new Blob([data], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
var fileName = $scope.schema.title;
a.href = fileURL;
a.download = fileName;
a.click();
}
if (redirectTo === true) {
if (data.client_cmd) {
generator.pathDecider(data.client_cmd, $scope, data);
}
if (data.msgbox) {
$scope.msgbox = data.msgbox;
var newElement = $compile("<msgbox></msgbox>")($scope);
// this is the default action, which is removing page items and reload page with msgbox
angular.element(document.querySelector('.main.ng-scope')).children().remove();
angular.element(document.querySelector('.main.ng-scope')).append(newElement);
}
}
});
//return $http.post(generator.makeUrl($scope), data)
// .success(function (data, status, headers) {
// if (headers('content-type') === "application/pdf") {
// var a = document.createElement("a");
// document.body.appendChild(a);
// a.style = "display: none";
// var file = new Blob([data], {type: 'application/pdf'});
// var fileURL = URL.createObjectURL(file);
// var fileName = $scope.schema.title;
// a.href = fileURL;
// a.download = fileName;
// a.click();
// }
// if (redirectTo === true) {
// if (data.client_cmd) {
// generator.pathDecider(data.client_cmd, $scope, data);
// }
// if (data.msgbox) {
// $scope.msgbox = data.msgbox;
// var newElement = $compile("<msgbox></msgbox>")($scope);
// // this is the default action, which is removing page items and reload page with msgbox
// angular.element(document.querySelector('.main.ng-scope')).children().remove();
// angular.element(document.querySelector('.main.ng-scope')).append(newElement);
// }
// }
// });
};
return generator;
})
......@@ -1128,6 +1170,9 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {Object} returns value for modal
*/
.controller('ModalController', function ($scope, $uibModalInstance, Generator, items) {
$scope.$watch('form', function () {
console.log($scope.form);
});
angular.forEach(items, function (value, key) {
$scope[key] = items[key];
});
......@@ -1315,9 +1360,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
items: function () {
var formName = attributes.addModalForLinkedModel;
return Generator.get_form({
url: scope.form.wf,
wf: scope.form.wf,
form_params: {model: scope.form.model_name, cmd: scope.form.add_cmd},
form_params: {
wf: scope.form.wf,
model: scope.form.model_name,
cmd: scope.form.add_cmd
},
modalElements: {
// define button position properties
buttonPositions: {
......
......@@ -21,7 +21,7 @@ angular.module('ulakbus')
* - API returns `is_login` key to check if current user is authenticated. Interceptor checks and if not logged
* in redirects to login page.
*/
$httpProvider.interceptors.push(function ($q, $rootScope, $location, $timeout, $log, toastr) {
$httpProvider.interceptors.push(function (ErrorService, $q, $rootScope, $location, $timeout, $log, toastr) {
return {
'request': function (config) {
if (config.method === "POST") {
......@@ -62,101 +62,7 @@ angular.module('ulakbus')
return response;
},
'responseError': function (rejection) {
var errorInModal = ('error' in rejection.data);
var errorModal = function () {
if ($rootScope.loginAttempt === 0) {
$log.debug('not logged in, no alert message triggered');
return;
}
var codefield = "";
if (rejection.data.error) {
codefield = '<p><pre>' +
rejection.data.error +
'</pre></p>';
}
$('<div class="modal">' +
'<div class="modal-dialog" style="width:100%;" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span' +
' aria-hidden="true">&times;</span></button>' +
'<h4 class="modal-title" id="exampleModalLabel">' +
"Error Status: " + rejection.status + "<br>Error Title: " + rejection.data.title +
'</h4>' +
'</div>' +
'<div class="modal-body">' +
'<div class="alert alert-danger">' +
'<strong>' +
rejection.data.description +
'</strong>' +
codefield +
'</div>' +
'</div>' +
'<div class="modal-footer">' +
'<button type="button" class="btn btn-default" data-dismiss="modal">Kapat</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>').modal();
try {
$('pre:not(.hljs)').each(function (i, block) {
hljs.highlightBlock(block);
});
}
catch (e) {
$log.debug('Exception: ', e.message);
}
};
var errorInAlertBox = function (alertContent) {
if (errorInModal) {
errorModal();
} else {
//$rootScope.$broadcast('alertBox', alertContent);
toastr.error(alertContent.msg, alertContent.title);
}
};
var errorForAlertBox = {
title: rejection.status,
msg: rejection.data.description,
type: 'error'
};
var errorDispatch = {
"-1" : function () {
rejection.status = 'Sunucu hatası';
rejection.data.title = rejection.data.title || "Sunucu Hatası";
rejection.data.description = rejection.data.description || 'Sunucu bağlantısında bir hata oluştu. Lütfen yetkili personelle iletişime geçiniz.';
errorInAlertBox(errorForAlertBox);
},
"400": function () {
$location.reload();
},
"401": function () {
$location.path('/login');
if ($location.path() === "/login") {
$log.debug("show errors on login form");
}
},
"403": function () {
if (rejection.data.is_login === true) {
$rootScope.loggedInUser = true;
if ($location.path() === "/login") {
$location.path("/dashboard");
}
}
},
"404": function () {
errorInAlertBox(errorForAlertBox);
},
"500": function () {
errorInAlertBox(errorForAlertBox);
}
};
errorDispatch[rejection.status]();
ErrorService.handle(rejection, 'http');
return $q.reject(rejection);
}
......
......@@ -11,8 +11,9 @@ angular.module('ulakbus')
/**
* WSUri returns websocket uri
*/
.service('WSUri', function () {
return {url: 'ws://localhost:9001/ws'}
.service('WSUri', function (RESTURL) {
var base = RESTURL.url.replace('http', 'ws');
return {url: base + 'ws'}
})
/**
* websocket with callbackId
......@@ -24,64 +25,102 @@ angular.module('ulakbus')
/**
* WSOps operates all websocket interactions
*/
.factory('WSOps', function (WSUri, $q, $log) {
var websocket = new WebSocket(WSUri.url);
websocket.onopen = function (evt) {
wsOps.onOpen(evt)
};
websocket.onclose = function (evt) {
wsOps.onClose(evt)
};
websocket.onmessage = function (evt) {
wsOps.onMessage(evt)
};
websocket.onerror = function (evt) {
wsOps.onError(evt)
.factory('WSOps', function (WSUri, $q, $log, $rootScope, $timeout, ErrorService) {
$rootScope.$on('ws_turn_on', function () {
generate_ws();
});
var websocket;
var generate_ws = function () {
$log.info('Openning web socket...');
websocket = new WebSocket(WSUri.url);
websocket.onopen = function (evt) {
wsOps.onOpen(evt)
};
websocket.onclose = function (evt) {
wsOps.onClose(evt);
generate_ws();
};
websocket.onmessage = function (evt) {
wsOps.onMessage(evt)
};
websocket.onerror = function (evt) {
wsOps.onError(evt)
};
};
var wsOps = {};
wsOps.onOpen = function(evt) {
wsOps.onOpen = function (evt) {
$rootScope.websocketIsOpen = true;
$log.info("CONNECTED", evt);
};
wsOps.onClose = function(event) {
wsOps.onClose = function (event) {
$rootScope.websocketIsOpen = false;
$log.info("DISCONNEDTED", event);
};
// two types of data can be come from websocket: with / without callback
//
wsOps.callbacks = {};
wsOps.onMessage = function(event) {
wsOps.onMessage = function (event) {
var data = angular.fromJson(event.data);
if (angular.isDefined(callbacks[data.request_id])) {
var callback = callbacks[data.request_id];
delete callbacks[data.request_id];
if (data.hasOwnProperty('error')) {
ErrorService.handle(data, 'ws');
}
if (angular.isDefined(wsOps.callbacks[data.callbackID])) {
var callback = wsOps.callbacks[data.callbackID];
delete wsOps.callbacks[data.callbackID];
callback.resolve(data);
} else {
$log.info("Data without callback: %o", data);
}
$log.info("MESSAGE:", event.data);
$log.info("MESSAGE:", event, "Data:", JSON.parse(event.data));
};
wsOps.onError = function(evt) {
wsOps.onError = function (evt) {
$log.error("ERROR :: " + evt);
};
wsOps.doSend = function(data) {
wsOps.doSend = function (data) {
websocket.send(data);
$log.info('SENT:', data);
};
wsOps.retryCount = 0;
// reactor with promise
wsOps.request = function(data) {
wsOps.request = function (data) {
var request = {
request_id: Math.random().toString(36).substring(7),
callbackID: Math.random().toString(36).substring(7),
data: data
};
var deferred = $q.defer();
wsOps.callbacks[request.request_id] = deferred;
wsOps.callbacks[request.callbackID] = deferred;
websocket.send(angular.toJson(request));
return deferred.promise.then(function(response) {
request.response = response;
return response;
});
$log.info('SENT:', data);
return deferred.promise.then(function (response) {
request.response = response;
return response;
}
);
};
wsOps.waitForSocketConnection = function (socket, callback) {
$timeout(
function () {
if (angular.isDefined(socket)) {
if (socket.readyState === 1) {
$log.info("Connection made.");
if (callback != null) {
callback();
}
} else {
$log.info("waiting for connection...");
wsOps.waitForSocketConnection(socket, callback);
}
} else {
$log.info("waiting for connection...");
wsOps.waitForSocketConnection(socket, callback);
}
}, 50); // wait 50 milisecond for the connection...
};
return wsOps;
});
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -21,7 +21,7 @@
</head>
<body ng-controller="KeyListenController" ng-keydown="down($event)">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.loggedInUser">
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0" ng-if="$root.current_user">
<collapse-menu></collapse-menu>
<!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>-->
......@@ -44,12 +44,12 @@
<header-notification></header-notification>
</nav>
<sidebar ng-if="$root.loggedInUser"></sidebar>
<sidebar ng-if="$root.current_user"></sidebar>
<div class="manager-view">
<div class="manager-view-inner">
<!-- manager-header -->
<header-sub-menu ng-if="$root.loggedInUser"></header-sub-menu>
<header-sub-menu ng-if="$root.current_user"></header-sub-menu>
<!-- end of manager-header -->
<div class="manager-view-content">
<div class="row">
......
......@@ -2,17 +2,20 @@ angular.module('templates-prod', ['components/auth/login.html', 'components/crud
angular.module("components/auth/login.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("components/auth/login.html",
"<div ng-app=\"ulakbus.auth\" class=\"container\">\n" +
" <div class=\"row\">\n" +
" <div class=\"col-md-4 col-md-offset-4\">\n" +
" <div class=\"login-panel panel panel-default\">\n" +
" <div class=\"panel-heading\">\n" +
" <h3 class=\"panel-title\">Giriş Yap <span ng-if=\"loggingIn\" class=\"loader pull-right\"></span></h3>\n" +
" </div>\n" +
" <div class=\"panel-body\">\n" +
" <span class=\"label label-warning\">{{message}}</span>\n" +
" <form name=\"loginForm\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\" ng-submit=\"onSubmit(loginForm)\"></form>\n" +
"<div style=\"width: 100%; height: 100%; position: fixed; z-index: 1100; top:0; left:0; background: #fff;\">\n" +
" <div ng-app=\"ulakbus.auth\" class=\"container\">\n" +
" <div class=\"row\">\n" +
" <div class=\"col-md-6 col-md-offset-3\">\n" +
" <div class=\"login-panel panel panel-default\">\n" +
" <div class=\"panel-heading\">\n" +
" <h3 class=\"panel-title\">Giriş Yap <span ng-if=\"loggingIn\" class=\"loader pull-right\"></span></h3>\n" +
" </div>\n" +
" <div class=\"panel-body\">\n" +
" <form name=\"loginForm\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\"\n" +
" ng-submit=\"onSubmit(loginForm)\"></form>\n" +
" </div>\n" +
" </div>\n" +
" <span class=\"label label-inverse label-warning\">{{message}}</span>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n" +
......@@ -204,8 +207,8 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
"\n" +
" <td ng-repeat=\"field in object.fields track by $index\">\n" +
" <a role=\"button\" ng-if=\"field.type==='link'\"\n" +
" ng-click=\"do_action(object.key, field)\" ng-bind-html=\"field.content\"></a>\n" +
" <span ng-if=\"field.type==='str'\" ng-bind-html=\"field.content\"></span>\n" +
" ng-click=\"do_action(object.key, field)\" ng-bind-html=\"field.content | markdown\"></a>\n" +
" <span ng-if=\"field.type==='str'\" ng-bind-html=\"field.content | markdown\"></span>\n" +
" </td>\n" +
"\n" +
" <td>\n" +
......@@ -225,16 +228,16 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
" <nav ng-if=\"pagination && pagination.total_pages > 1\" class=\"text-center\">\n" +
" <ul class=\"pagination\">\n" +
" <li ng-class=\"{disabled:pagination.page===1}\">\n" +
" <a aria-label=\"Önceki\" ng-click=\"reload({page:pagination.page-1})\">\n" +
" <a aria-label=\"Önceki\" ng-click=\"paginate({page:pagination.page-1})\">\n" +
" <span aria-hidden=\"true\">&laquo;</span>\n" +
" </a>\n" +
" </li>\n" +
" <li ng-repeat=\"page in getNumber(pagination.total_pages) track by $index\"\n" +
" ng-class=\"{active:$index+1===pagination.page}\">\n" +
" <a ng-click=\"reload({page:$index+1})\">{{$index+1}}</a>\n" +
" <a ng-click=\"paginate({page:$index+1})\">{{$index+1}}</a>\n" +
" </li>\n" +
" <li ng-class=\"{disabled:pagination.page===pagination.total_pages}\">\n" +
" <a aria-label=\"Sonraki\" ng-click=\"reload({page:pagination.page+1})\">\n" +
" <a aria-label=\"Sonraki\" ng-click=\"paginate({page:pagination.page+1})\">\n" +
" <span aria-hidden=\"true\">&raquo;</span>\n" +
" </a>\n" +
" </li>\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