Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket removing #124

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3d8cbe6
when you are not logged in yet there are many bugs. they are fixed no…
Dec 3, 2017
d5a8abd
websocket not changed yet.
Dec 3, 2017
8c9ed89
websocket not removed yet
Dec 3, 2017
cc74707
websocket not removed yet.
Dec 3, 2017
57c9e27
websocket changed to http
Dec 4, 2017
566d7df
temporary commit. requests not fixed yet.
Dec 11, 2017
b5c81fd
http not working in chrome. not fixed yet.
Dec 12, 2017
ea61685
handle get_form reqeuest's response error. entire bug is not fixed yet.
Dec 12, 2017
0d4c1b5
chrome takes response now but all responses are 401.
ChnTklc Dec 13, 2017
69f52f5
deleted wf name at the end of the api url in bap requests.
ChnTklc Dec 17, 2017
1831a40
temporary commit. http bug not fixed yet.
ChnTklc Dec 18, 2017
ee4b177
http bu not fixed yet. withCredentials=true enabled.
ChnTklc Dec 18, 2017
b244b8a
typo fixed
ChnTklc Dec 18, 2017
5956dd9
callbackID added all request's data. unnecessary logs deleted.
ChnTklc Dec 18, 2017
bdef64f
Merge branch 'develop' of https://github.com/zetaops/ulakbus-ui into …
ChnTklc Dec 20, 2017
371e67f
branches rebased. websocket switched to http. started detail testing.
ChnTklc Dec 20, 2017
1d4713d
forgetten variable added.
ChnTklc Dec 20, 2017
fe899c4
error handled according to data status code inside response.
ChnTklc Dec 23, 2017
3ccbd45
dilek's commit about buttons position added this branch too.
ChnTklc Dec 25, 2017
5690b0f
message box was shown just after login then disappear. now it shows e…
ChnTklc Dec 25, 2017
804b9e2
forgotten dependency about previous commit.
ChnTklc Dec 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions app/app_routes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
'use strict';

angular.module('ulakbus')
.config(['$routeProvider', function ($routeProvider, $route) {
.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/login', {
templateUrl: '/components/auth/login.html',
controller: 'LoginController'
})
.when('/logout', {
controller: function (AuthService) {
AuthService.logout();
}
})
.when('/dashboard', {
templateUrl: '/components/dashboard/dashboard.html',
controller: 'DashController'
Expand Down Expand Up @@ -46,7 +51,6 @@ angular.module('ulakbus')
controller: 'CRUDController',
isPublic: true
})

.when('/cwf/:wf/:token', {
templateUrl: '/components/crud/templates/crud.html',
controller: 'CRUDController'
Expand Down Expand Up @@ -81,28 +85,45 @@ angular.module('ulakbus')
.otherwise({redirectTo: '/login'});
}])

.run(function ($rootScope, AuthService, $location) {
.run(function ($rootScope, AuthService, $location, $window) {
$rootScope.loggedInUser = false;
$rootScope.loginAttempt = 0;
$rootScope.current_user = true;
//check if page is not a public page
if(location.hash.indexOf('/pub/') === -1){
AuthService.check_auth();
if(location.hash.indexOf('/pub/') === -1 && $window.sessionStorage.userID === undefined){
return $location.path('/login');
//AuthService.check_auth();
}
//reset the value of user interaction on form when page refreshes
$rootScope.isUserClicked = false;

$rootScope.$on("$routeChangeStart", function (event, next, current) {
if(!$rootScope.loggedInUser && $location.path() !== '/login'){
$location.path('/login');
event.preventDefault();
$rootScope.$on("$routeChangeStart", function (angularEvent, next, current) {
if ($window.sessionStorage.userID === undefined) {
return $location.path('/login');
}
});
})
.config(['$httpProvider', function ($httpProvider) {
.config(function ($httpProvider) {
$httpProvider.interceptors.push(function (){
return {
'request': function (config) {
if (config.method === "POST") {
config.data.callbackID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16)
});
}
return config;
},
'response': function (response) {
return response;
}
};
});

// to send cookies CORS
$httpProvider.defaults.withCredentials = true;
}])
})
.run(function (gettextCatalog) {
gettextCatalog.setCurrentLanguage('tr');
gettextCatalog.debug = true;
Expand Down
8 changes: 4 additions & 4 deletions app/bap/controller/bap-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('ulakbusBap')
$scope.dashboardData = {};

var dashboardEndpoint = 'bap_anasayfa';
$http.post(Generator.makeUrl(dashboardEndpoint), {})
$http.post(Generator.makeUrl(dashboardEndpoint), {wf: dashboardEndpoint})
.success(function (response, status) {
if(status===200){
$scope.dashboardData = response;
Expand Down Expand Up @@ -266,12 +266,12 @@ angular.module('ulakbusBap')
list: $scope.listFormCmd,
form: $scope.listFormCmd,
reload: $scope.reloadCmd,
download: $scope.listFormCmd,
reset: $scope.resetCmd
reset: $scope.resetCmd,
download: $scope.listFormCmd
};

return executeCmd[$routeParams.cmd]();

})
});


9 changes: 6 additions & 3 deletions app/bap/service/bap-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ angular.module('ulakbusBap')
* @returns {string}
*/
generator.makeUrl = function (wfName) {
return RESTURL.url + wfName;
return RESTURL.url/* + wfName*/;
};
/**
* @memberof ulakbusBap
Expand Down Expand Up @@ -320,6 +320,9 @@ angular.module('ulakbusBap')
.post(generator.makeUrl(send_data.wf), send_data)
.success(function (data) {
// if response data.cmd is 'upgrade'
if(data.download_url !== undefined){
Utils.saveToDisk(data.download_url);
}
wfMetadata.setWfMeta(data.wf_meta);
if(data.download_url !== undefined){
Utils.saveToDisk(data.download_url);
Expand Down Expand Up @@ -1495,7 +1498,7 @@ angular.module('ulakbusBap')
};

generator.get_form = function (scope) {
return $http.post(generator.makeUrl(scope.form_params.wf), {})
return $http.post(generator.makeUrl(scope.form_params.wf), {wf: scope.form_params.wf})
.success(function (response, status, headers, config) {
wfMetadata.setWfMeta(response.wf_meta);
return generator.generate(scope, response);
Expand All @@ -1507,7 +1510,7 @@ angular.module('ulakbusBap')

var isSearchResult = ((form_params.cmd === 'select_list' || form_params.cmd === 'object_name') && (form_params.wf === 'crud'))?true:false;

return $http.post(generator.makeUrl(scope.form_params.wf), {})
return $http.post(generator.makeUrl(scope.form_params.wf), {wf: scope.form_params.wf})
.success(function (data, status, headers, config) {
//we need to set the wf_meta of the main wf and not from the response of typeahead
if(!isSearchResult){
Expand Down
6 changes: 3 additions & 3 deletions app/components/auth/auth_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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, $location, $routeParams, $rootScope, $log, WSOps, Generator, AuthService,$cookies) {
.controller('LoginController', function ($http, $scope, $window, $q, $timeout, $location, $routeParams, $rootScope, $log, /*WSOps,*/ Generator, AuthService, $cookies) {
$scope.showLogo = false;
$scope.url = 'login';
$scope.msgbox=angular.fromJson($cookies.get("logoutmsg"));
Expand All @@ -38,8 +38,8 @@ angular.module('ulakbus.auth', ['ngRoute', 'ngCookies'])
},5000)
}
$scope.form_params = {};
$scope.form_params['clear_wf'] = 1;
// if websocket status is open ---> ws close
$scope.form_params['wf'] = "login";
//if websocket status is open ---> ws close
AuthService.get_form($scope).then(function (data) {
if (data.login) { $location.path('/'); }
$scope.form = [
Expand Down
80 changes: 46 additions & 34 deletions app/components/auth/auth_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,33 @@ angular.module('ulakbus.auth')
* @name AuthService
* @description provides generic functions for authorization process.
*/
.factory('AuthService', function ($http, $rootScope, $location, $log, $route, Generator, RESTURL, WSOps, $window,$cookies) {
.factory('AuthService', function ($http, $rootScope, $location, $log, $route, Generator, RESTURL, $window) {
var authService = {};

authService.get_form = function (scope) {
return $http
.post(Generator.makeUrl(scope), scope.form_params)
return $http.post(RESTURL.url, scope.form_params)
.success(function (data, status, headers, config) {
// if response data.cmd is 'upgrade'
if (data.cmd === 'upgrade') {
$rootScope.loggedInUser = true;
$rootScope.$broadcast("ws_turn_on");
$rootScope.$broadcast("setPublicWf", false);
return $location.path('/dashboard');
}
if (data.cmd === 'retry') {
$location.path('/login');
} else{
if (angular.isDefined(data.forms) && $location.path() !== '/login'){
$location.path('/login');
if($window.sessionStorage.userID !== undefined){
authService.logout();
} else {
if (data.user_id !== undefined) {
$window.sessionStorage.userID = data.user_id;
$rootScope.loggedInUser = true;
//$rootScope.$broadcast("ws_turn_on");
$rootScope.$broadcast("setPublicWf", false);
$location.path('/dashboard');

}else {
if (angular.isDefined(data.forms) && $location.path() !== '/login'){
$location.path('/login');
}
return Generator.generate(scope, data);
}
return Generator.generate(scope, data);
}
})
.error(function (data) {
console.log(data);
return data;
});
};

Expand All @@ -53,19 +58,24 @@ angular.module('ulakbus.auth')
*/
authService.login = function (url, credentials) {
credentials['cmd'] = "do";
return $http
.post(RESTURL.url + url, credentials)
credentials['wf'] = url;
if($window.sessionStorage.userID !== undefined){
authService.logout();
}
return $http.post(RESTURL.url, credentials)
.success(function (data, status, headers, config) {
//$window.sessionStorage.token = data.token;
Generator.button_switch(true);
if (data.cmd === 'upgrade') {
if(data.status_code !== undefined)
status = data.status_code;
if (status === 200) {
$window.sessionStorage.userID = data.user_id;
$rootScope.loggedInUser = true;
// $rootScope.$broadcast("regenerate_menu");
// to display main view without flickering
$rootScope.$broadcast("ws_turn_on");
// $rootScope.$broadcast("ws_turn_on");
$location.path('/dashboard');
}
if (data.status_code === 403) {
if (status !== 200) {
data.title = "İşlem başarısız oldu. Lütfen girdiğiniz bilgileri kontrol ediniz.";
}
return data;
Expand All @@ -88,21 +98,23 @@ angular.module('ulakbus.auth')
authService.logout = function () {
$rootScope.$broadcast("show_main_loader");
$rootScope.loginAttempt = 0;
WSOps.request({wf: 'logout'}).then(function (data) { //TODO not working callback
$rootScope.loggedInUser = false;
$rootScope.current_user = true;
$rootScope.$broadcast("user_logged_out");
$log.debug("loggedout");
WSOps.close('loggedout');
$location.path("/login");
window.location.reload();
});
$http.post(RESTURL.url, {wf: 'logout'})
.then(function (data) { //TODO not working callback
$window.sessionStorage.clear();
$rootScope.loggedInUser = false;
$rootScope.current_user = true;
$rootScope.$broadcast("user_logged_out");
$log.debug("loggedout");
//WSOps.close('loggedout');
$location.path("/login");
window.location.reload();
})
};

authService.check_auth = function () {
var post_data = {url: 'login', form_params:{}};
/*authService.check_auth = function () {
var post_data = { form_params:{ wf: 'login' } };
return authService.get_form(post_data);
};
};*/

return authService;
});
9 changes: 5 additions & 4 deletions app/components/crud/crud_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
};
})

.controller("crudTimetableDirectiveCtrl", function($scope, WSOps, $q){
.controller("crudTimetableDirectiveCtrl", function($scope, /*WSOps,*/ $http, RESTURL, $q){
// todo: replace with utils service method
function groupBy (list, propName) {
return list.reduce(function(acc, item) {
Expand All @@ -516,16 +516,17 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
var fieldName = $scope.mainFieldName || 'ogretim_elemani_zt';
data.token = $scope.token;
data.wf = $scope.wf;
return WSOps.request(data).then(function(result){
return $http.post(RESTURL.url, data).then(function(resp){
var result = resp.data;
if (result[fieldName]){
return result;
}
Generator.pathDecider(result.client_cmd || ['list'], $scope, result);
// prevent result processing
return $q.reject();
}).then(function(result){
$scope.message = result.notification;
return result[fieldName]
$scope.message = result.data.notification;
return result.data[fieldName]
})
};

Expand Down
2 changes: 1 addition & 1 deletion app/components/crud/templates/form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="clearfix container" ng-class="{'form-container': !objects}">
<div class="clearfix" ng-class="{'form-container': !objects}">
<div class="buttons-on-top"></div>

<form id="formgenerated" name="formgenerated" sf-schema="schema" sf-form="form" sf-model="model"
Expand Down
15 changes: 9 additions & 6 deletions app/components/dashboard/dashboard_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ angular.module('ulakbus.dashboard', [])
$uibTooltipProvider.setTriggers({'click': 'mouseleave'});
})

.controller('DashController', function ($scope, $rootScope, $routeParams, $route, $timeout, $http, $cookies, $log, RESTURL, Generator, WSOps) {
.controller('DashController', function ($scope, $rootScope, $window, $location, $routeParams, $route, $timeout, $http, $cookies, $log, RESTURL, Generator/*, WSOps*/ ) {
// first generate_dashboard broadcasted to get menu and dashboard items
// sidebar directive listens for "generate_dashboard"
// $rootScope.$broadcast("generate_dashboard");
if($window.sessionStorage.userID === undefined)
$location.path('/login');
//$rootScope.$broadcast("generate_dashboard");

$scope.section = function (section_index) {
$rootScope.section = section_index;
Expand Down Expand Up @@ -79,12 +81,12 @@ angular.module('ulakbus.dashboard', [])
});

$scope.getItems(where, q).then(function (data) {
$scope.staffs = data.results;
$scope.staffs = data.data.results;
});
}
if (where === 'ogrenci') {
$scope.getItems(where, $scope.keyword.student).then(function (data) {
$scope.students = data.results;
$scope.students = data.data.results;
})
}
}, 500);
Expand All @@ -93,7 +95,7 @@ angular.module('ulakbus.dashboard', [])

$scope.getItems = function (where, what) {
$scope.showResults = true;
return WSOps.request({view: where + '_ara', query_params: what});
return $http.post(RESTURL.url, {view: where + '_ara', query_params: what});
};

$scope.userPopover = {templateUrl: '/components/dashboard/user-info.html'};
Expand All @@ -107,7 +109,8 @@ angular.module('ulakbus.dashboard', [])
*/
$scope.get_info = function (type, key) {
Generator.get_list({url: 'crud', form_params: {wf: 'crud', model: type, object_id: key, cmd: 'show'}})
.then(function (data) {
.then(function (resp) {
var data = resp.data;
$scope.userPopover.name = data.object['Ad'] + " " + data.object['Soyad'];
$scope.userPopover.tcno = data.object['TC Kimlik No'];
$scope.userPopover.image = data.object['Avatar'] || 'img/sample-profile-pic.jpg';
Expand Down
Loading