Commit 5c4f12cc authored by Evren Kutar's avatar Evren Kutar

menu rename to dashboard and get it with socket

parent d7aeee26
......@@ -2191,3 +2191,12 @@ table.dataTable thead .sorting:after {
top:43px; left:0;
z-index: 1000;
}
.body-mask {
width: 100%;
height: 100%;
background: #fff;
position: absolute;
top:0; left:0;
z-index: 1099;
}
\ No newline at end of file
......@@ -59,7 +59,7 @@ angular.module('ulakbus')
}])
.run(function ($rootScope) {
$rootScope.loggedInUser = true;
$rootScope.loggedInUser = false;
$rootScope.loginAttempt = 0;
$rootScope.websocketIsOpen = false;
$rootScope.current_user = true;
......
......@@ -21,8 +21,18 @@ angular.module('ulakbus.auth')
authService.get_form = function (scope) {
return $http
.post(Generator.makeUrl(scope), scope.form_params)
.then(function (res) {
return Generator.generate(scope, res.data);
.success(function (data, status, headers, config) {
if (data.cmd === 'upgrade') {
$rootScope.loggedInUser = true;
$rootScope.$broadcast("user_ready");
$rootScope.$broadcast("ws_turn_on");
return $location.path('/dashboard');
} else{
if (angular.isDefined(data.forms) && $location.path() !== '/login'){
$location.path('/login');
}
return Generator.generate(scope, data);
}
});
};
......@@ -44,9 +54,12 @@ angular.module('ulakbus.auth')
.success(function (data, status, headers, config) {
//$window.sessionStorage.token = data.token;
Generator.button_switch(true);
if (data.status_code !== 403) {
if (data.cmd === 'upgrade') {
$rootScope.loggedInUser = true;
$rootScope.$broadcast("regenerate_menu");
// $rootScope.$broadcast("regenerate_menu");
// to display main view without flickering
$rootScope.$broadcast("user_ready");
$rootScope.$broadcast("ws_turn_on");
$location.path('/dashboard');
}
if (data.status_code === 403) {
......@@ -80,5 +93,10 @@ angular.module('ulakbus.auth')
});
};
authService.check_auth = function () {
var post_data = {url: 'login', form_params:{}};
return authService.get_form(post_data);
};
return authService;
});
\ No newline at end of file
......@@ -92,6 +92,37 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
angular.forEach(pageData, function (value, key) {
scope[key] = value;
});
if (scope.meta['selective_listing'] === true) {
angular.forEach(scope.objects, function (_v, _k) {
angular.forEach(_v.objects, function (value, key) {
if (key > 0) {
var linkIndexes = {};
angular.forEach(value.actions, function (v, k) {
if (v.show_as === 'link') {linkIndexes = v}
});
angular.forEach(value.fields, function (v, k) {
try {
if (value.actions.length > 0 && linkIndexes.fields){
scope.objects[_k][key].fields[k] = {
type: linkIndexes.fields.indexOf(k) > -1 ? 'link' : 'str',
content: v,
cmd: linkIndexes.cmd,
mode: linkIndexes.mode
};
}
else {
scope.objects[_k]['objects'][key].fields[k] = {type: 'str', content: v};
}
} catch (e) {
$log.error(e);
scope.objects[_k]['objects'][key].fields[k] = {type: 'str', content: v};
}
});
}
});
});
} else {
angular.forEach(scope.objects, function (value, key) {
if (key > 0) {
var linkIndexes = {};
......@@ -113,6 +144,8 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
});
}
});
}
$log.debug(scope.objects);
}
}
......@@ -262,9 +295,8 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
};
// selective listing for list page todo: add to documentation
$scope.selective_list_key = 0;
$scope.update_selective_list = function () {
$scope.objects = $scope.all_objects[$scope.selective_list_key]["objects"];
$scope.update_selective_list = function (key) {
$scope.objects = $scope.all_objects[key]["objects"];
};
// end of selective listing
$scope.listFormCmd = function () {
......
......@@ -9,17 +9,17 @@
</div>
</div>
<!-- todo: add `selective_list` to documentation -->
<div ng-if="meta.selective_listing === true">
<div ng-if="meta.selective_listing === true" class="row" style="margin-bottom: 25px;">
<label for="selective_list">{{meta.selective_listing_label || "Sayfa içinde filtrelemek için seçim yapınız."}}</label>
<select name="selective_list" id="selective_list"
ng-change="update_selective_list()"
ng-change="update_selective_list(selective_list_key)"
ng-model="selective_list_key"
class="form-control">
<option ng-repeat="item in all_objects" value="{{$index}}">{{item.key}}</option>
<option ng-repeat="item in all_objects" value="{{$index}}" ng-selected="selective_list_key">{{item.key}}</option>
</select>
</div>
<div class="tablescroll" ng-if="objects[1]">
<table class="table table-bordered" style="background-color:#fff;">
<table class="table table-bordered table-striped" style="background-color:#fff;">
<thead>
<tr>
<td ng-if="meta.allow_selection === true">
......@@ -30,7 +30,7 @@
</td>
<td ng-repeat="value in objects[0] track by $index" ng-if="objects[0]!='-1'">{{value}}</td>
<td ng-if="objects[0]=='-1'">{{ schema.title||model}}</td>
<td>İşlem</td>
<td ng-if="meta.allow_actions !== false">İşlem</td>
</tr>
</thead>
<tbody>
......@@ -51,7 +51,7 @@
<!--<span ng-if="field.type==='str'">{{trustashtml(field.content) | markdown}}</span>-->
</td>
<td>
<td ng-if="meta.allow_actions !== false">
<button class="btn btn-info" style="margin-right: 5px;" ng-repeat="action in object.actions track by $index"
ng-if="action.show_as==='button'"
ng-click="do_action(object.key, action)">{{action
......
......@@ -22,6 +22,9 @@ angular.module('ulakbus.dashboard', [])
})
.controller('DashController', function ($scope, $rootScope, $routeParams, $route, $timeout, $http, $cookies, RESTURL, Generator, WSOps) {
// first generate_dashboard broadcasted to get menu and dashboard items
// sidebar directive listens for "generate_dashboard"
$rootScope.$broadcast("generate_dashboard");
$scope.section = function (section_index) {
$rootScope.section = section_index;
......
......@@ -30,7 +30,14 @@
</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.current_user">
<div ng-show="user_ready === false" class="body-mask">
<div class="text-center">
<span class="loader"></span>
</div>
</div>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0"
ng-show="user_ready === true">
<collapse-menu></collapse-menu>
<!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>-->
......@@ -40,7 +47,7 @@
<!--</ul>-->
<div class="navbar-header">
<div class="brand">
<a href="#/dashboard" class="logo"><img src="/img/brand-logo.png" /></a>
<a href="#/dashboard" class="logo"><img src="/img/brand-logo.png"/></a>
</div>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
......@@ -53,7 +60,7 @@
<header-notification></header-notification>
</nav>
<sidebar ng-if="$root.current_user"></sidebar>
<sidebar ng-show="user_ready === true"></sidebar>
<div class="manager-view">
<div class="manager-view-inner">
......
......@@ -37,7 +37,14 @@
</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.current_user">
<div ng-show="user_ready === false" class="body-mask">
<div class="text-center">
<span class="loader"></span>
</div>
</div>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0"
ng-show="user_ready === true">
<collapse-menu></collapse-menu>
<!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>-->
......@@ -47,7 +54,7 @@
<!--</ul>-->
<div class="navbar-header">
<div class="brand">
<a href="#/dashboard" class="logo"><img src="/img/brand-logo.png" /></a>
<a href="#/dashboard" class="logo"><img src="/img/brand-logo.png"/></a>
</div>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
......@@ -60,7 +67,7 @@
<header-notification></header-notification>
</nav>
<sidebar ng-if="$root.current_user"></sidebar>
<sidebar ng-show="user_ready === true"></sidebar>
<div class="manager-view">
<div class="manager-view-inner">
......
......@@ -74,8 +74,8 @@ angular.module('ulakbus')
* @todo: do it in detail page of notification
*/
$scope.markAsRead = function (item, group, index) {
WSOps.doSend(angular.toJson({data: {view: 'notify', id:item.id}}));
$scope.notifications[group].splice(index,1);
WSOps.doSend(angular.toJson({data: {view: 'notify', id: item.id}}));
$scope.notifications[group].splice(index, 1);
};
// if markasread triggered outside the directive
......@@ -285,7 +285,7 @@ angular.module('ulakbus')
restrict: 'E',
replace: true,
scope: {},
controller: function ($scope, $rootScope, $cookies, $route, $http, RESTURL, DESIGN, $log, $location, $window, $timeout) {
controller: function ($scope, $rootScope, $cookies, $route, AuthService, WSOps, RESTURL, DESIGN, $log, $location, $window, $timeout) {
$scope.prepareMenu = function (menuItems) {
var newMenuItems = {};
angular.forEach(menuItems, function (value, key) {
......@@ -296,11 +296,18 @@ angular.module('ulakbus')
return newMenuItems;
};
var generate_menu = function () {
// check login status
AuthService.check_auth();
var generate_dashboard = function () {
if ($rootScope.current_user !== true){
return;
}
if ($rootScope.websocketIsOpen) {
var sidebarmenu = $('#side-menu');
sidebarmenu.metisMenu();
$http.get(RESTURL.url + 'menu', {ignoreLoadingBar: true})
.success(function (data) {
WSOps.request({view: 'dashboard'})
.then(function (data) {
$scope.allMenuItems = angular.copy(data);
// regroup menu items based on their category
......@@ -333,7 +340,9 @@ angular.module('ulakbus')
$rootScope.searchInputs = data;
if (data.current_user) {
$rootScope.$broadcast("ws_turn_on");
// $rootScope.$broadcast("ws_turn_on");
// to display main view without flickering
// $rootScope.$broadcast("user_ready");
}
$rootScope.current_user = data.current_user;
......@@ -347,19 +356,24 @@ angular.module('ulakbus')
$timeout(function () {
sidebarmenu.metisMenu();
});
})
.error(function (data, status, headers, config) {
$log.error('menu not retrieved', data);
$log.info('design switch', DESIGN.switch);
if (!DESIGN.switch) {
$location.path('/login');
}
});
// .error(function (data, status, headers, config) {
// $log.error('menu not retrieved', data);
// $log.info('design switch', DESIGN.switch);
// if (!DESIGN.switch) {
// $location.path('/login');
// }
// });
} else {
$timeout(function () {
generate_dashboard();
}, 500);
}
};
$scope.$on("regenerate_menu", function () {
generate_menu();
$scope.$on("generate_dashboard", function () {
generate_dashboard();
});
generate_menu();
// generate_menu();
// changing menu items by listening for broadcast
$scope.$on("menuitems", function (event, data) {
......@@ -377,26 +391,26 @@ angular.module('ulakbus')
delete $scope.selectedMenuItems;
};
$scope.openSidebar = function () {
if ($window.innerWidth > '768') {
if ($rootScope.sidebarPinned === 0) {
jQuery("span.menu-text, span.arrow, .sidebar footer, #side-menu").fadeIn(400);
jQuery(".sidebar").css("width", "250px");
jQuery(".manager-view").css("width", "calc(100% - 250px)");
$rootScope.collapsed = false;
}
}
};
$scope.closeSidebar = function () {
if ($window.innerWidth > '768') {
if ($rootScope.sidebarPinned === 0) {
jQuery(".sidebar").css("width", "62px");
jQuery(".manager-view").css("width", "calc(100% - 62px)");
$rootScope.collapsed = true;
}
}
};
// $scope.openSidebar = function () {
// if ($window.innerWidth > '768') {
// if ($rootScope.sidebarPinned === 0) {
// jQuery("span.menu-text, span.arrow, .sidebar footer, #side-menu").fadeIn(400);
// jQuery(".sidebar").css("width", "250px");
// jQuery(".manager-view").css("width", "calc(100% - 250px)");
// $rootScope.collapsed = false;
// }
// }
// };
//
// $scope.closeSidebar = function () {
// if ($window.innerWidth > '768') {
// if ($rootScope.sidebarPinned === 0) {
// jQuery(".sidebar").css("width", "62px");
// jQuery(".manager-view").css("width", "calc(100% - 62px)");
// $rootScope.collapsed = true;
// }
// }
// };
$rootScope.$watch(function ($rootScope) {
return $rootScope.section;
......
<div class="navbar-default sidebar" role="navigation" ng-mouseenter="openSidebar()" ng-mouseleave="closeSidebar()">
<div class="navbar-default sidebar" role="navigation">
<div class="sidebar-container">
<div class="sidebar-nav navbar-collapse">
<ul class="nav in" id="side-menu" ng-class="{hidden: $root.loggedInUser != true}" data-step="1"
<ul class="nav in" id="side-menu" data-step="1"
data-intro="Genel menüler yer almaktadır. yapılacak işlemi buradan seçebilirsiniz.">
<!--<sidebar-search></sidebar-search>-->
<li ui-sref-active="active">
......
......@@ -19,6 +19,12 @@ angular.module('ulakbus')
$scope.keylog.shift();
$scope.keylog.push(e.keyCode);
};
// when user_ready broadcasted then change value of user_ready=true to display view
$scope.$on('user_ready', function () {
$scope.user_ready = true;
});
$scope.user_ready = false;
})
.factory('action_service', function ($uibModal, $log) {
var actions = {};
......
......@@ -31,6 +31,7 @@ angular.module('ulakbus')
});
var websocket;
var ws_is_generated;
var refresh_count = 0;
var refresh_websocket = refresh_count < 5 ? 1000 : 5000;
var isSupported = function() {
......@@ -47,10 +48,10 @@ angular.module('ulakbus')
websocket.onclose = function (evt) {
wsOps.onClose(evt);
if (wsOps.loggedOut === true) {return;}
$timeout(function () {
generate_ws();
refresh_count += 1;
}, refresh_websocket);
// $timeout(function () {
// generate_ws();
// refresh_count += 1;
// }, refresh_websocket);
};
websocket.onmessage = function (evt) {
wsOps.onMessage(evt)
......@@ -58,6 +59,7 @@ angular.module('ulakbus')
websocket.onerror = function (evt) {
wsOps.onError(evt)
};
ws_is_generated = true;
} else {
var error = {
error: "Tarayıcınız websocket desteklememektedir. Lütfen güncel bir tarayıcı kullanınız.",
......@@ -101,6 +103,11 @@ angular.module('ulakbus')
},
notification: function () {
$rootScope.$broadcast('notifications', msg_data["notifications"]);
},
dashboard: function () {
var callback = wsOps.callbacks[msg_data.callbackID];
delete wsOps.callbacks[msg_data.callbackID];
callback.resolve(msg_data);
}
};
// do_action is the dispatcher function for incoming events
......@@ -115,7 +122,8 @@ angular.module('ulakbus')
return msg_methods[action](args[0]);
};
var msg_data = angular.fromJson(event.data);
do_action(msg_data, msg_data.cmd || 'error');
if (msg_data.error) {msg_data.cmd = 'error';}
do_action(msg_data, msg_data.cmd);
$log.info("MESSAGE:", event, "Data:", JSON.parse(event.data));
};
......@@ -128,6 +136,7 @@ angular.module('ulakbus')
};
// reactor with promise
wsOps.request = function (data) {
if (ws_is_generated) {
var request = {
callbackID: Math.random().toString(36).substring(7),
data: data
......@@ -136,11 +145,18 @@ angular.module('ulakbus')
wsOps.callbacks[request.callbackID] = deferred;
websocket.send(angular.toJson(request));
$log.info('SENT:', data);
// todo: add success & error promises
return deferred.promise.then(function (response) {
request.response = response;
return response;
}
);
} else {
// is ws_is_generated is not true try again in one second
$timeout(function () {
wsOps.request(data);
}, 1000);
}
};
wsOps.close = function () {
......@@ -148,7 +164,7 @@ angular.module('ulakbus')
websocket.close();
$log.info("CLOSED");
delete websocket;
}
};
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.
......@@ -2206,6 +2206,15 @@ table.dataTable thead .sorting:after {
z-index: 1000;
}
.body-mask {
width: 100%;
height: 100%;
background: #fff;
position: absolute;
top:0; left:0;
z-index: 1099;
}
/*
* metismenu - v1.1.3
* Easy menu jQuery plugin for Twitter Bootstrap 3
......
......@@ -21,7 +21,14 @@
</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.current_user">
<div ng-show="user_ready === false" class="body-mask">
<div class="text-center">
<span class="loader"></span>
</div>
</div>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0"
ng-show="user_ready === true">
<collapse-menu></collapse-menu>
<!--<ul class="header-menu">-->
<!--<li><a href="">Mesajlar</a></li>-->
......@@ -31,7 +38,7 @@
<!--</ul>-->
<div class="navbar-header">
<div class="brand">
<a href="#/dashboard" class="logo"><img src="/img/brand-logo.png" /></a>
<a href="#/dashboard" class="logo"><img src="/img/brand-logo.png"/></a>
</div>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
......@@ -44,7 +51,7 @@
<header-notification></header-notification>
</nav>
<sidebar ng-if="$root.current_user"></sidebar>
<sidebar ng-show="user_ready === true"></sidebar>
<div class="manager-view">
<div class="manager-view-inner">
......
......@@ -261,17 +261,17 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
" </div>\n" +
" </div>\n" +
" <!-- todo: add `selective_list` to documentation -->\n" +
" <div ng-if=\"meta.selective_listing === true\">\n" +
" <div ng-if=\"meta.selective_listing === true\" class=\"row\" style=\"margin-bottom: 25px;\">\n" +
" <label for=\"selective_list\">{{meta.selective_listing_label || \"Sayfa içinde filtrelemek için seçim yapınız.\"}}</label>\n" +
" <select name=\"selective_list\" id=\"selective_list\"\n" +
" ng-change=\"update_selective_list()\"\n" +
" ng-change=\"update_selective_list(selective_list_key)\"\n" +
" ng-model=\"selective_list_key\"\n" +
" class=\"form-control\">\n" +
" <option ng-repeat=\"item in all_objects\" value=\"{{$index}}\">{{item.key}}</option>\n" +
" <option ng-repeat=\"item in all_objects\" value=\"{{$index}}\" ng-selected=\"selective_list_key\">{{item.key}}</option>\n" +
" </select>\n" +
" </div>\n" +
" <div class=\"tablescroll\" ng-if=\"objects[1]\">\n" +
" <table class=\"table table-bordered\" style=\"background-color:#fff;\">\n" +
" <table class=\"table table-bordered table-striped\" style=\"background-color:#fff;\">\n" +
" <thead>\n" +
" <tr>\n" +
" <td ng-if=\"meta.allow_selection === true\">\n" +
......@@ -282,7 +282,7 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
" </td>\n" +
" <td ng-repeat=\"value in objects[0] track by $index\" ng-if=\"objects[0]!='-1'\">{{value}}</td>\n" +
" <td ng-if=\"objects[0]=='-1'\">{{ schema.title||model}}</td>\n" +
" <td>İşlem</td>\n" +
" <td ng-if=\"meta.allow_actions !== false\">İşlem</td>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
......@@ -303,7 +303,7 @@ angular.module("components/crud/templates/list.html", []).run(["$templateCache",
" <!--<span ng-if=\"field.type==='str'\">{{trustashtml(field.content) | markdown}}</span>-->\n" +
" </td>\n" +
"\n" +
" <td>\n" +
" <td ng-if=\"meta.allow_actions !== false\">\n" +
" <button class=\"btn btn-info\" style=\"margin-right: 5px;\" ng-repeat=\"action in object.actions track by $index\"\n" +
" ng-if=\"action.show_as==='button'\"\n" +
" ng-click=\"do_action(object.key, action)\">{{action\n" +
......@@ -2313,11 +2313,11 @@ angular.module("shared/templates/directives/sidebar-search.html", []).run(["$tem
angular.module("shared/templates/directives/sidebar.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("shared/templates/directives/sidebar.html",
"<div class=\"navbar-default sidebar\" role=\"navigation\" ng-mouseenter=\"openSidebar()\" ng-mouseleave=\"closeSidebar()\">\n" +
"<div class=\"navbar-default sidebar\" role=\"navigation\">\n" +
"\n" +
" <div class=\"sidebar-container\">\n" +
" <div class=\"sidebar-nav navbar-collapse\">\n" +
" <ul class=\"nav in\" id=\"side-menu\" ng-class=\"{hidden: $root.loggedInUser != true}\" data-step=\"1\"\n" +
" <ul class=\"nav in\" id=\"side-menu\" data-step=\"1\"\n" +
" data-intro=\"Genel menüler yer almaktadır. yapılacak işlemi buradan seçebilirsiniz.\">\n" +
" <!--<sidebar-search></sidebar-search>-->\n" +
" <li ui-sref-active=\"active\">\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