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) { ...@@ -124,6 +124,7 @@ module.exports = function (grunt) {
"app/zetalib/interceptors.js", "app/zetalib/interceptors.js",
"app/zetalib/general.js", "app/zetalib/general.js",
"app/zetalib/form_service.js", "app/zetalib/form_service.js",
"app/zetalib/error_service.js",
"app/zetalib/action_service.js", "app/zetalib/action_service.js",
"app/zetalib/socket.js", "app/zetalib/socket.js",
"app/shared/directives.js", "app/shared/directives.js",
...@@ -150,6 +151,8 @@ module.exports = function (grunt) { ...@@ -150,6 +151,8 @@ module.exports = function (grunt) {
"app/bower_components/angular-resource/angular-resource.js", "app/bower_components/angular-resource/angular-resource.js",
"app/bower_components/angular-bootstrap/ui-bootstrap.js", "app/bower_components/angular-bootstrap/ui-bootstrap.js",
"app/bower_components/angular-bootstrap/ui-bootstrap-tpls.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/angular-sanitize/angular-sanitize.js",
"app/bower_components/tv4/tv4.js", "app/bower_components/tv4/tv4.js",
"app/bower_components/objectpath/lib/ObjectPath.js", "app/bower_components/objectpath/lib/ObjectPath.js",
......
...@@ -36,6 +36,7 @@ angular.module( ...@@ -36,6 +36,7 @@ angular.module(
'ulakbus.devSettings', 'ulakbus.devSettings',
'ulakbus.version', 'ulakbus.version',
'gettext', 'gettext',
'markdown',
]) ])
/** /**
* @memberof ulakbus * @memberof ulakbus
...@@ -75,4 +76,9 @@ angular.module( ...@@ -75,4 +76,9 @@ angular.module(
.constant('toastr', window.toastr) .constant('toastr', window.toastr)
.config(function ($logProvider) { .config(function ($logProvider) {
$logProvider.debugEnabled(true); $logProvider.debugEnabled(true);
})
.config(function(markdownProvider) {
//markdownProvider.config({
// extensions: ['table']
//});
}); });
\ No newline at end of file
...@@ -53,6 +53,8 @@ angular.module('ulakbus') ...@@ -53,6 +53,8 @@ angular.module('ulakbus')
$rootScope.loggedInUser = true; $rootScope.loggedInUser = true;
$rootScope.loginAttempt = 0; $rootScope.loginAttempt = 0;
$rootScope.websocketIsOpen = false;
$rootScope.current_user = true;
$rootScope.$on("$routeChangeStart", function (event, next, current) { $rootScope.$on("$routeChangeStart", function (event, next, current) {
// will be used when needed // will be used when needed
}); });
......
...@@ -25,19 +25,17 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies']) ...@@ -25,19 +25,17 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies'])
* @description LoginCtrl responsible to handle login process.<br> * @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. * 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.url = 'login';
$scope.form_params = {}; $scope.form_params = {};
$scope.form_params['clear_wf'] = 1; $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 = [ $scope.form = [
{key: "username", type: "string", title: "Kullanıcı Adı"}, {key: "username", type: "string", title: "Kullanıcı Adı"},
{key: "password", type: "password", title: "Şifre"}, {key: "password", type: "password", title: "Şifre"},
{type: 'submit', title: 'Giriş Yap'} {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.loggingIn = false;
$scope.onSubmit = function (form) { $scope.onSubmit = function (form) {
...@@ -47,6 +45,10 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies']) ...@@ -47,6 +45,10 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies'])
$rootScope.loginAttempt = 1; $rootScope.loginAttempt = 1;
Generator.button_switch(false); Generator.button_switch(false);
AuthService.login($scope.url, $scope.model) AuthService.login($scope.url, $scope.model)
.success(function (data) {
$scope.message = data.title;
$scope.loggingIn = false;
})
.error(function (data) { .error(function (data) {
$scope.message = data.title; $scope.message = data.title;
$scope.loggingIn = false; $scope.loggingIn = false;
......
...@@ -15,9 +15,17 @@ angular.module('ulakbus.auth') ...@@ -15,9 +15,17 @@ angular.module('ulakbus.auth')
* @name AuthService * @name AuthService
* @description provides generic functions for authorization process. * @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 = {}; 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 * @memberof ulakbus.auth
* @ngdoc function * @ngdoc function
...@@ -36,11 +44,19 @@ angular.module('ulakbus.auth') ...@@ -36,11 +44,19 @@ angular.module('ulakbus.auth')
.success(function (data, status, headers, config) { .success(function (data, status, headers, config) {
//$window.sessionStorage.token = data.token; //$window.sessionStorage.token = data.token;
Generator.button_switch(true); Generator.button_switch(true);
if (data.status_code !== 403) {
$rootScope.loggedInUser = true; $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) { .error(function (data, status, headers, config) {
// Handle login errors here // 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; return data;
}); });
}; };
...@@ -54,8 +70,9 @@ angular.module('ulakbus.auth') ...@@ -54,8 +70,9 @@ angular.module('ulakbus.auth')
* @returns {*} * @returns {*}
*/ */
authService.logout = function () { 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; $rootScope.loggedInUser = false;
$log.debug("loggedout"); $log.debug("loggedout");
$location.path("/login"); $location.path("/login");
......
<div ng-app="ulakbus.auth" class="container"> <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="row">
<div class="col-md-4 col-md-offset-4"> <div class="col-md-6 col-md-offset-3">
<div class="login-panel panel panel-default"> <div class="login-panel panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Giriş Yap <span ng-if="loggingIn" class="loader pull-right"></span></h3> <h3 class="panel-title">Giriş Yap <span ng-if="loggingIn" class="loader pull-right"></span></h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<span class="label label-warning">{{message}}</span> <form name="loginForm" sf-schema="schema" sf-form="form" sf-model="model"
<form name="loginForm" sf-schema="schema" sf-form="form" sf-model="model" ng-submit="onSubmit(loginForm)"></form> ng-submit="onSubmit(loginForm)"></form>
</div> </div>
</div> </div>
<span class="label label-inverse label-warning">{{message}}</span>
</div>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -154,6 +154,12 @@ angular.module('ulakbus.crud', ['schemaForm', 'ulakbus.formService']) ...@@ -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) { .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.$on('reload_cmd', function(event, data){
$scope.reload_cmd = data; $scope.reload_cmd = data;
$scope.reloadCmd(); $scope.reloadCmd();
......
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
<td ng-repeat="field in object.fields track by $index"> <td ng-repeat="field in object.fields track by $index">
<a role="button" ng-if="field.type==='link'" <a role="button" ng-if="field.type==='link'"
ng-click="do_action(object.key, field)" ng-bind-html="field.content"></a> 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"></span> <span ng-if="field.type==='str'" ng-bind-html="field.content | markdown"></span>
</td> </td>
<td> <td>
...@@ -55,16 +55,16 @@ ...@@ -55,16 +55,16 @@
<nav ng-if="pagination && pagination.total_pages > 1" class="text-center"> <nav ng-if="pagination && pagination.total_pages > 1" class="text-center">
<ul class="pagination"> <ul class="pagination">
<li ng-class="{disabled:pagination.page===1}"> <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> <span aria-hidden="true">&laquo;</span>
</a> </a>
</li> </li>
<li ng-repeat="page in getNumber(pagination.total_pages) track by $index" <li ng-repeat="page in getNumber(pagination.total_pages) track by $index"
ng-class="{active:$index+1===pagination.page}"> 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>
<li ng-class="{disabled:pagination.page===pagination.total_pages}"> <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> <span aria-hidden="true">&raquo;</span>
</a> </a>
</li> </li>
......
...@@ -21,7 +21,8 @@ angular.module('ulakbus.dashboard', []) ...@@ -21,7 +21,8 @@ angular.module('ulakbus.dashboard', [])
$uibTooltipProvider.setTriggers({'click': 'mouseleave'}); $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) { $scope.section = function (section_index) {
$rootScope.section = section_index; $rootScope.section = section_index;
}; };
...@@ -37,28 +38,27 @@ angular.module('ulakbus.dashboard', []) ...@@ -37,28 +38,27 @@ angular.module('ulakbus.dashboard', [])
$scope.staffs = []; $scope.staffs = [];
$scope.search = function (where) { $scope.search = function (where) {
if ($scope.keyword.staff.length > 2 || $scope.keyword.student.length > 2) {
$timeout(function () { $timeout(function () {
if (where === 'personel') { if (where === 'personel') {
// if input length greater than 2 search for the value // 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) { $scope.getItems(where, $scope.keyword.staff).then(function (data) {
$scope.staffs = data.results; $scope.staffs = data.results;
}); });
} }
}
if (where === 'ogrenci') { if (where === 'ogrenci') {
if ($scope.keyword.student.length > 2) { $scope.getItems(where, $scope.keyword.student).then(function (data) {
$scope.getItems(where, $scope.keyword.student).success(function (data) {
$scope.students = data.results; $scope.students = data.results;
}) })
} }
}
}, 500); }, 500);
}
}; };
$scope.getItems = function (where, what) { $scope.getItems = function (where, what) {
$scope.showResults = true; $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'}; $scope.userPopover = {templateUrl: 'components/dashboard/user-info.html'};
...@@ -96,7 +96,11 @@ angular.module('ulakbus.dashboard', []) ...@@ -96,7 +96,11 @@ angular.module('ulakbus.dashboard', [])
$scope.markAsRead = function (items) { $scope.markAsRead = function (items) {
$rootScope.$broadcast("markasread", items); $rootScope.$broadcast("markasread", items);
} };
//if ($routeParams.cmd = 'reload') {
// $route.reload();
//}
}) })
.directive('sidebarNotifications', function () { .directive('sidebarNotifications', function () {
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</head> </head>
<body ng-controller="KeyListenController" ng-keydown="down($event)"> <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> <collapse-menu></collapse-menu>
<!--<ul class="header-menu">--> <!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>--> <!--<li><a href="">Mesajlar</a></li>-->
...@@ -53,12 +53,12 @@ ...@@ -53,12 +53,12 @@
<header-notification></header-notification> <header-notification></header-notification>
</nav> </nav>
<sidebar ng-if="$root.loggedInUser"></sidebar> <sidebar ng-if="$root.current_user"></sidebar>
<div class="manager-view"> <div class="manager-view">
<div class="manager-view-inner"> <div class="manager-view-inner">
<!-- manager-header --> <!-- 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 --> <!-- end of manager-header -->
<div class="manager-view-content"> <div class="manager-view-content">
<div class="row"> <div class="row">
...@@ -82,10 +82,12 @@ ...@@ -82,10 +82,12 @@
<!--<script src="bower_components/angular-resource/angular-resource.min.js"></script>--> <!--<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.min.js"></script>-->
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.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/angular-sanitize/angular-sanitize.min.js"></script>
<script src="bower_components/tv4/tv4.js"></script> <script src="bower_components/tv4/tv4.js"></script>
<script src="bower_components/objectpath/lib/ObjectPath.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-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="bower_components/angular-gettext/dist/angular-gettext.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> <script src="bower_components/moment/min/moment.min.js"></script>
...@@ -106,6 +108,7 @@ ...@@ -106,6 +108,7 @@
<script src="zetalib/interceptors.js"></script> <script src="zetalib/interceptors.js"></script>
<script src="zetalib/form_service.js"></script> <script src="zetalib/form_service.js"></script>
<script src="zetalib/action_service.js"></script> <script src="zetalib/action_service.js"></script>
<script src="zetalib/error_service.js"></script>
<script src="zetalib/socket.js"></script> <script src="zetalib/socket.js"></script>
<!-- components --> <!-- components -->
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</head> </head>
<body ng-controller="KeyListenController" ng-keydown="down($event)"> <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> <collapse-menu></collapse-menu>
<!--<ul class="header-menu">--> <!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>--> <!--<li><a href="">Mesajlar</a></li>-->
...@@ -60,12 +60,12 @@ ...@@ -60,12 +60,12 @@
<header-notification></header-notification> <header-notification></header-notification>
</nav> </nav>
<sidebar ng-if="$root.loggedInUser"></sidebar> <sidebar ng-if="$root.current_user"></sidebar>
<div class="manager-view"> <div class="manager-view">
<div class="manager-view-inner"> <div class="manager-view-inner">
<!-- manager-header --> <!-- 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 --> <!-- end of manager-header -->
<div class="manager-view-content"> <div class="manager-view-content">
<div class="row"> <div class="row">
...@@ -90,10 +90,12 @@ ...@@ -90,10 +90,12 @@
<!--<script src="bower_components/angular-resource/angular-resource.min.js"></script>--> <!--<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.min.js"></script>-->
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.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/angular-sanitize/angular-sanitize.min.js"></script>
<script src="bower_components/tv4/tv4.js"></script> <script src="bower_components/tv4/tv4.js"></script>
<script src="bower_components/objectpath/lib/ObjectPath.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-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="bower_components/angular-gettext/dist/angular-gettext.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> <script src="bower_components/moment/min/moment.min.js"></script>
...@@ -114,6 +116,7 @@ ...@@ -114,6 +116,7 @@
<script src="zetalib/interceptors.js"></script> <script src="zetalib/interceptors.js"></script>
<script src="zetalib/form_service.js"></script> <script src="zetalib/form_service.js"></script>
<script src="zetalib/action_service.js"></script> <script src="zetalib/action_service.js"></script>
<script src="zetalib/error_service.js"></script>
<script src="zetalib/socket.js"></script> <script src="zetalib/socket.js"></script>
<!-- components --> <!-- components -->
......
...@@ -36,6 +36,7 @@ angular.module( ...@@ -36,6 +36,7 @@ angular.module(
'ulakbus.devSettings', 'ulakbus.devSettings',
'ulakbus.version', 'ulakbus.version',
'gettext', 'gettext',
'markdown',
// @if NODE_ENV='PRODUCTION' // @if NODE_ENV='PRODUCTION'
'templates-prod', 'templates-prod',
// @endif // @endif
...@@ -85,4 +86,9 @@ angular.module( ...@@ -85,4 +86,9 @@ angular.module(
// @if NODE_ENV='DEVELOPMENT' // @if NODE_ENV='DEVELOPMENT'
$logProvider.debugEnabled(true); $logProvider.debugEnabled(true);
// @endif // @endif
})
.config(function(markdownProvider) {
//markdownProvider.config({
// extensions: ['table']
//});
}); });
\ No newline at end of file
...@@ -14,14 +14,15 @@ angular.module('ulakbus') ...@@ -14,14 +14,15 @@ angular.module('ulakbus')
* @description logout directive provides a button with click event. When triggered it post to * @description logout directive provides a button with click event. When triggered it post to
* '/logout' path of the API. * '/logout' path of the API.
*/ */
.directive('logout', function ($http, $location, RESTURL) { .directive('logout', function ($http, $location, RESTURL, AuthService) {
return { return {
link: function ($scope, $element, $rootScope) { link: function ($scope, $element, $rootScope) {
$element.on('click', function () { $element.on('click', function () {
$http.post(RESTURL.url + 'logout', {}).then(function () { AuthService.logout();
$rootScope.loggedInUser = false; //$http.post(RESTURL.url + 'logout', {}).then(function () {
$location.path("/login"); // $rootScope.loggedInUser = false;
}); // $location.path("/login");
//});
}); });
} }
}; };
...@@ -61,10 +62,10 @@ angular.module('ulakbus') ...@@ -61,10 +62,10 @@ angular.module('ulakbus')
*/ */
$scope.getNotifications = function () { $scope.getNotifications = 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.groupNotifications(data.notifications); // $scope.groupNotifications(data.notifications);
$rootScope.$broadcast("notifications", $scope.notifications); // $rootScope.$broadcast("notifications", $scope.notifications);
}); //});
}; };
$scope.getNotifications(); $scope.getNotifications();
...@@ -82,11 +83,11 @@ angular.module('ulakbus') ...@@ -82,11 +83,11 @@ angular.module('ulakbus')
* @todo: do it in detail page of notification * @todo: do it in detail page of notification
*/ */
$scope.markAsRead = function (items) { $scope.markAsRead = function (items) {
$http.post(RESTURL.url + "notify", {ignoreLoadingBar: true, read: [items]}) //$http.post(RESTURL.url + "notify", {ignoreLoadingBar: true, read: [items]})
.success(function (data) { // .success(function (data) {
$scope.groupNotifications(data.notifications); // $scope.groupNotifications(data.notifications);
$rootScope.$broadcast("notifications", $scope.notifications); // $rootScope.$broadcast("notifications", $scope.notifications);
}); // });
}; };
// if markasread triggered outside the directive // if markasread triggered outside the directive
...@@ -133,10 +134,10 @@ angular.module('ulakbus') ...@@ -133,10 +134,10 @@ angular.module('ulakbus')
$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
if (form.$valid) { if (form.$valid) {
var searchparams = { var searchparams = {
url: $scope.wf,
token: $scope.$parent.token, token: $scope.$parent.token,
object_id: $scope.$parent.object_id, object_id: $scope.$parent.object_id,
form_params: { form_params: {
wf: $scope.$parent.wf,
model: $scope.$parent.form_params.model, model: $scope.$parent.form_params.model,
cmd: $scope.$parent.reload_cmd, cmd: $scope.$parent.reload_cmd,
flow: $scope.$parent.form_params.flow, flow: $scope.$parent.form_params.flow,
...@@ -144,10 +145,7 @@ angular.module('ulakbus') ...@@ -144,10 +145,7 @@ angular.module('ulakbus')
} }
}; };
Generator.submit(searchparams).success(function (data) { Generator.submit(searchparams);
// update objects item of page scope
$rootScope.$broadcast('updateObjects', data.objects);
});
} }
}; };
} }
...@@ -310,9 +308,10 @@ angular.module('ulakbus') ...@@ -310,9 +308,10 @@ angular.module('ulakbus')
return newMenuItems; return newMenuItems;
}; };
var generate_menu = function () {
var sidebarmenu = $('#side-menu'); var sidebarmenu = $('#side-menu');
sidebarmenu.metisMenu(); sidebarmenu.metisMenu();
$http.get(RESTURL.url + 'menu/') $http.get(RESTURL.url + 'menu', {ignoreLoadingBar: true})
.success(function (data) { .success(function (data) {
$scope.allMenuItems = angular.copy(data); $scope.allMenuItems = angular.copy(data);
...@@ -343,6 +342,7 @@ angular.module('ulakbus') ...@@ -343,6 +342,7 @@ angular.module('ulakbus')
// broadcast for authorized menu items, consume in dashboard to show search inputs and/or // broadcast for authorized menu items, consume in dashboard to show search inputs and/or
// related items // related items
$rootScope.$broadcast("authz", data); $rootScope.$broadcast("authz", data);
$rootScope.$broadcast("ws_turn_on");
$rootScope.searchInputs = data; $rootScope.searchInputs = data;
$rootScope.current_user = data.current_user; $rootScope.current_user = data.current_user;
...@@ -355,14 +355,19 @@ angular.module('ulakbus') ...@@ -355,14 +355,19 @@ angular.module('ulakbus')
$timeout(function () { $timeout(function () {
sidebarmenu.metisMenu(); 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;
}); });
})
.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 // changing menu items by listening for broadcast
$scope.$on("menuitems", function (event, data) { $scope.$on("menuitems", function (event, data) {
var menu = {}; var menu = {};
menu[data] = $scope.allMenuItems[data]; 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']) ...@@ -182,10 +182,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
) )
}); });
if (newForm.length > 0) {
$log.debug('grouped form: ', newForm); $log.debug('grouped form: ', newForm);
$log.debug('rest of form: ', scope.form); $log.debug('rest of form: ', scope.form);
$log.debug('form united: ', newForm.concat(scope.form)); $log.debug('form united: ', newForm.concat(scope.form));
}
scope.form = newForm.concat(scope.form); scope.form = newForm.concat(scope.form);
return scope; return scope;
}; };
...@@ -598,7 +599,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -598,7 +599,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
var modelScope = { var modelScope = {
"url": v.wf, "url": v.wf,
"wf": 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) { //scope.$on('refreshTitleMap', function (event, data) {
...@@ -608,7 +609,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -608,7 +609,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
scope.generateTitleMap = function (modelScope) { scope.generateTitleMap = function (modelScope) {
return generator.get_list(modelScope).then(function (res) { return generator.get_list(modelScope).then(function (res) {
formitem.titleMap = []; formitem.titleMap = [];
angular.forEach(res.data.objects, function (item) { angular.forEach(res.objects, function (item) {
if (item !== -1) { if (item !== -1) {
formitem.titleMap.push({ formitem.titleMap.push({
"value": item.key, "value": item.key,
...@@ -624,28 +625,6 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -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 = { formitem = {
type: "template", type: "template",
templateUrl: "shared/templates/foreignKey.html", templateUrl: "shared/templates/foreignKey.html",
...@@ -689,6 +668,32 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -689,6 +668,32 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
}; };
scope.form[scope.form.indexOf(k)] = formitem; 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: { Node: {
...@@ -760,6 +765,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -760,6 +765,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
normal: function () { normal: function () {
$log.debug('normal mode starts'); $log.debug('normal mode starts');
$scope.form_params.cmd = todo.cmd; $scope.form_params.cmd = todo.cmd;
$scope.form_params.wf = $scope.wf;
if (todo.wf) { if (todo.wf) {
$scope.url = todo.wf; $scope.url = todo.wf;
$scope.form_params.wf = todo.wf; $scope.form_params.wf = todo.wf;
...@@ -811,12 +817,22 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -811,12 +817,22 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*} * @returns {*}
*/ */
generator.get_form = function (scope) { generator.get_form = function (scope) {
return $http if ($rootScope.websocketIsOpen === true) {
.post(generator.makeUrl(scope), scope.form_params) return WSOps.request(scope.form_params)
.then(function (res) { .then(function (data) {
//generator.button_switch(true); return generator.generate(scope, data);
return generator.generate(scope, res.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 * @memberof ulakbus.formService
...@@ -827,12 +843,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -827,12 +843,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*} * @returns {*}
*/ */
generator.get_list = function (scope) { generator.get_list = function (scope) {
return $http //return $http
.post(generator.makeUrl(scope), scope.form_params) // .post(generator.makeUrl(scope), scope.form_params)
.then(function (res) { // .then(function (res) {
//generator.button_switch(true); // //generator.button_switch(true);
return res; // 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 * @memberof ulakbus.formService
...@@ -844,16 +871,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -844,16 +871,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*} * @returns {*}
*/ */
generator.get_wf = function (scope) { generator.get_wf = function (scope) {
//WSOps.request(scope.form_params) if ($rootScope.websocketIsOpen === true) {
// .then(function (data) { WSOps.request(scope.form_params)
// return generator.pathDecider(data.client_cmd, scope, data); .then(function (data) {
// }); return generator.pathDecider(data.client_cmd || ['list'], scope, data);
return $http
.post(generator.makeUrl(scope), scope.form_params)
.then(function (res) {
return generator.pathDecider(res.data.client_cmd, scope, res.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);
// });
}; };
/** /**
* @memberof ulakbus.formService * @memberof ulakbus.formService
...@@ -928,7 +962,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -928,7 +962,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
data['param'] = $scope.form_params.param; data['param'] = $scope.form_params.param;
data['param_id'] = $scope.form_params.id; data['param_id'] = $scope.form_params.id;
data['pageData'] = true; data['pageData'] = true;
data['second_client_cmd'] = client_cmd[1]; //data['second_client_cmd'] = client_cmd[1];
generator.setPageData(data); generator.setPageData(data);
redirectTo($scope, client_cmd[0]); redirectTo($scope, client_cmd[0]);
...@@ -1069,11 +1103,13 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1069,11 +1103,13 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
angular.forEach($scope.Node, function (value, key) { angular.forEach($scope.Node, function (value, key) {
$scope.model[key] = value.model; $scope.model[key] = value.model;
}); });
var data = { // todo: unused var delete
var send_data = {
"form": $scope.model, "form": $scope.model,
"object_key": $scope.object_key, "object_key": $scope.object_key,
"token": $scope.token, "token": $scope.token,
"model": $scope.form_params.model, "model": $scope.form_params.model,
"wf": $scope.form_params.wf,
"cmd": $scope.form_params.cmd, "cmd": $scope.form_params.cmd,
"flow": $scope.form_params.flow, "flow": $scope.form_params.flow,
"object_id": $scope.object_id, "object_id": $scope.object_id,
...@@ -1081,37 +1117,43 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1081,37 +1117,43 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
"query": $scope.form_params.query "query": $scope.form_params.query
}; };
//WSOps.request(scope.form_params) if ($rootScope.websocketIsOpen === true) {
// .then(function (data) { WSOps.request(send_data)
// return generator.pathDecider(data.client_cmd, $scope, data); .then(function (data) {
// }); return generator.pathDecider(data.client_cmd || ['list'], $scope, data);
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);
}
}
}); });
} 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 generator; return generator;
}) })
...@@ -1128,6 +1170,9 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1128,6 +1170,9 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {Object} returns value for modal * @returns {Object} returns value for modal
*/ */
.controller('ModalController', function ($scope, $uibModalInstance, Generator, items) { .controller('ModalController', function ($scope, $uibModalInstance, Generator, items) {
$scope.$watch('form', function () {
console.log($scope.form);
});
angular.forEach(items, function (value, key) { angular.forEach(items, function (value, key) {
$scope[key] = items[key]; $scope[key] = items[key];
}); });
...@@ -1315,9 +1360,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1315,9 +1360,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
items: function () { items: function () {
var formName = attributes.addModalForLinkedModel; var formName = attributes.addModalForLinkedModel;
return Generator.get_form({ return Generator.get_form({
url: scope.form.wf, form_params: {
wf: scope.form.wf, wf: scope.form.wf,
form_params: {model: scope.form.model_name, cmd: scope.form.add_cmd}, model: scope.form.model_name,
cmd: scope.form.add_cmd
},
modalElements: { modalElements: {
// define button position properties // define button position properties
buttonPositions: { buttonPositions: {
......
...@@ -21,7 +21,7 @@ angular.module('ulakbus') ...@@ -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 * - API returns `is_login` key to check if current user is authenticated. Interceptor checks and if not logged
* in redirects to login page. * 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 { return {
'request': function (config) { 'request': function (config) {
if (config.method === "POST") { if (config.method === "POST") {
...@@ -62,101 +62,7 @@ angular.module('ulakbus') ...@@ -62,101 +62,7 @@ angular.module('ulakbus')
return response; return response;
}, },
'responseError': function (rejection) { 'responseError': function (rejection) {
var errorInModal = ('error' in rejection.data); ErrorService.handle(rejection, 'http');
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]();
return $q.reject(rejection); return $q.reject(rejection);
} }
......
...@@ -11,8 +11,9 @@ angular.module('ulakbus') ...@@ -11,8 +11,9 @@ angular.module('ulakbus')
/** /**
* WSUri returns websocket uri * WSUri returns websocket uri
*/ */
.service('WSUri', function () { .service('WSUri', function (RESTURL) {
return {url: 'ws://localhost:9001/ws'} var base = RESTURL.url.replace('http', 'ws');
return {url: base + 'ws'}
}) })
/** /**
* websocket with callbackId * websocket with callbackId
...@@ -24,13 +25,21 @@ angular.module('ulakbus') ...@@ -24,13 +25,21 @@ angular.module('ulakbus')
/** /**
* WSOps operates all websocket interactions * WSOps operates all websocket interactions
*/ */
.factory('WSOps', function (WSUri, $q, $log) { .factory('WSOps', function (WSUri, $q, $log, $rootScope, $timeout, ErrorService) {
var websocket = new WebSocket(WSUri.url); $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) { websocket.onopen = function (evt) {
wsOps.onOpen(evt) wsOps.onOpen(evt)
}; };
websocket.onclose = function (evt) { websocket.onclose = function (evt) {
wsOps.onClose(evt) wsOps.onClose(evt);
generate_ws();
}; };
websocket.onmessage = function (evt) { websocket.onmessage = function (evt) {
wsOps.onMessage(evt) wsOps.onMessage(evt)
...@@ -38,50 +47,80 @@ angular.module('ulakbus') ...@@ -38,50 +47,80 @@ angular.module('ulakbus')
websocket.onerror = function (evt) { websocket.onerror = function (evt) {
wsOps.onError(evt) wsOps.onError(evt)
}; };
};
var wsOps = {}; var wsOps = {};
wsOps.onOpen = function(evt) { wsOps.onOpen = function (evt) {
$rootScope.websocketIsOpen = true;
$log.info("CONNECTED", evt); $log.info("CONNECTED", evt);
}; };
wsOps.onClose = function(event) { wsOps.onClose = function (event) {
$rootScope.websocketIsOpen = false;
$log.info("DISCONNEDTED", event); $log.info("DISCONNEDTED", event);
}; };
// two types of data can be come from websocket: with / without callback // two types of data can be come from websocket: with / without callback
// //
wsOps.callbacks = {}; wsOps.callbacks = {};
wsOps.onMessage = function(event) { wsOps.onMessage = function (event) {
var data = angular.fromJson(event.data); var data = angular.fromJson(event.data);
if (angular.isDefined(callbacks[data.request_id])) { if (data.hasOwnProperty('error')) {
var callback = callbacks[data.request_id]; ErrorService.handle(data, 'ws');
delete callbacks[data.request_id]; }
if (angular.isDefined(wsOps.callbacks[data.callbackID])) {
var callback = wsOps.callbacks[data.callbackID];
delete wsOps.callbacks[data.callbackID];
callback.resolve(data); callback.resolve(data);
} else { } else {
$log.info("Data without callback: %o", data); $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); $log.error("ERROR :: " + evt);
}; };
wsOps.doSend = function(data) { wsOps.doSend = function (data) {
websocket.send(data); websocket.send(data);
$log.info('SENT:', data); $log.info('SENT:', data);
}; };
wsOps.retryCount = 0;
// reactor with promise // reactor with promise
wsOps.request = function(data) { wsOps.request = function (data) {
var request = { var request = {
request_id: Math.random().toString(36).substring(7), callbackID: Math.random().toString(36).substring(7),
data: data data: data
}; };
var deferred = $q.defer(); var deferred = $q.defer();
wsOps.callbacks[request.request_id] = deferred; wsOps.callbacks[request.callbackID] = deferred;
websocket.send(angular.toJson(request)); websocket.send(angular.toJson(request));
return deferred.promise.then(function(response) { $log.info('SENT:', data);
return deferred.promise.then(function (response) {
request.response = response; request.response = response;
return 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; 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 @@ ...@@ -21,7 +21,7 @@
</head> </head>
<body ng-controller="KeyListenController" ng-keydown="down($event)"> <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> <collapse-menu></collapse-menu>
<!--<ul class="header-menu">--> <!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>--> <!--<li><a href="">Mesajlar</a></li>-->
...@@ -44,12 +44,12 @@ ...@@ -44,12 +44,12 @@
<header-notification></header-notification> <header-notification></header-notification>
</nav> </nav>
<sidebar ng-if="$root.loggedInUser"></sidebar> <sidebar ng-if="$root.current_user"></sidebar>
<div class="manager-view"> <div class="manager-view">
<div class="manager-view-inner"> <div class="manager-view-inner">
<!-- manager-header --> <!-- 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 --> <!-- end of manager-header -->
<div class="manager-view-content"> <div class="manager-view-content">
<div class="row"> <div class="row">
......
...@@ -2,18 +2,21 @@ angular.module('templates-prod', ['components/auth/login.html', 'components/crud ...@@ -2,18 +2,21 @@ angular.module('templates-prod', ['components/auth/login.html', 'components/crud
angular.module("components/auth/login.html", []).run(["$templateCache", function($templateCache) { angular.module("components/auth/login.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("components/auth/login.html", $templateCache.put("components/auth/login.html",
"<div ng-app=\"ulakbus.auth\" class=\"container\">\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=\"row\">\n" +
" <div class=\"col-md-4 col-md-offset-4\">\n" + " <div class=\"col-md-6 col-md-offset-3\">\n" +
" <div class=\"login-panel panel panel-default\">\n" + " <div class=\"login-panel panel panel-default\">\n" +
" <div class=\"panel-heading\">\n" + " <div class=\"panel-heading\">\n" +
" <h3 class=\"panel-title\">Giriş Yap <span ng-if=\"loggingIn\" class=\"loader pull-right\"></span></h3>\n" + " <h3 class=\"panel-title\">Giriş Yap <span ng-if=\"loggingIn\" class=\"loader pull-right\"></span></h3>\n" +
" </div>\n" + " </div>\n" +
" <div class=\"panel-body\">\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\"\n" +
" <form name=\"loginForm\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\" ng-submit=\"onSubmit(loginForm)\"></form>\n" + " ng-submit=\"onSubmit(loginForm)\"></form>\n" +
" </div>\n" + " </div>\n" +
" </div>\n" + " </div>\n" +
" <span class=\"label label-inverse label-warning\">{{message}}</span>\n" +
" </div>\n" +
" </div>\n" + " </div>\n" +
" </div>\n" + " </div>\n" +
"</div>"); "</div>");
...@@ -204,8 +207,8 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache", ...@@ -204,8 +207,8 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
"\n" + "\n" +
" <td ng-repeat=\"field in object.fields track by $index\">\n" + " <td ng-repeat=\"field in object.fields track by $index\">\n" +
" <a role=\"button\" ng-if=\"field.type==='link'\"\n" + " <a role=\"button\" ng-if=\"field.type==='link'\"\n" +
" ng-click=\"do_action(object.key, field)\" ng-bind-html=\"field.content\"></a>\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\"></span>\n" + " <span ng-if=\"field.type==='str'\" ng-bind-html=\"field.content | markdown\"></span>\n" +
" </td>\n" + " </td>\n" +
"\n" + "\n" +
" <td>\n" + " <td>\n" +
...@@ -225,16 +228,16 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache", ...@@ -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" + " <nav ng-if=\"pagination && pagination.total_pages > 1\" class=\"text-center\">\n" +
" <ul class=\"pagination\">\n" + " <ul class=\"pagination\">\n" +
" <li ng-class=\"{disabled:pagination.page===1}\">\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" + " <span aria-hidden=\"true\">&laquo;</span>\n" +
" </a>\n" + " </a>\n" +
" </li>\n" + " </li>\n" +
" <li ng-repeat=\"page in getNumber(pagination.total_pages) track by $index\"\n" + " <li ng-repeat=\"page in getNumber(pagination.total_pages) track by $index\"\n" +
" ng-class=\"{active:$index+1===pagination.page}\">\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>\n" +
" <li ng-class=\"{disabled:pagination.page===pagination.total_pages}\">\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" + " <span aria-hidden=\"true\">&raquo;</span>\n" +
" </a>\n" + " </a>\n" +
" </li>\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