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
This diff is collapsed.
......@@ -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 diff is collapsed.
......@@ -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