Skip to content

Commit

Permalink
Merge branch 'feature/bug-fixing-and-improvements' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaelemasotti committed Oct 22, 2015
2 parents 5b6bd11 + a067b6f commit 752b9a1
Show file tree
Hide file tree
Showing 26 changed files with 706 additions and 620 deletions.
15 changes: 14 additions & 1 deletion app/src/AnnotationSidebar/AnnotationDetails.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ angular.module('Pundit2.AnnotationSidebar')
return results;
};

var convertTime = function(serverdate) {
var annotationServerVersion = Config.annotationServerVersion;

if (annotationServerVersion === 'v2') {
var momentDate = moment(serverdate).utc().format('YYYY-MM-DD HH:mm:ss');
var localTime = moment.utc(momentDate).toDate();
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');
return localTime.toString();
}
return serverdate;
};

annotationDetails.openConfirmModal = function(currentElement, currentId)  {
// promise is needed to open modal when template is ready
modalScope.notifyMessage = 'Are you sure you want to delete this annotation? Please be aware that deleted annotations cannot be recovered.';
Expand Down Expand Up @@ -468,12 +480,13 @@ angular.module('Pundit2.AnnotationSidebar')
currentColor = template.hasColor;
}


if (typeof(state.annotations[currentId]) === 'undefined') {
state.annotations[currentId] = {
id: currentId,
creator: currentAnnotation.creator,
creatorName: currentAnnotation.creatorName,
created: currentAnnotation.created,
created: convertTime(currentAnnotation.created),
notebookId: currentAnnotation.isIncludedIn,
notebookName: notebookName,
scopeReference: scope,
Expand Down
2 changes: 1 addition & 1 deletion app/src/Client/ClientPro.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ angular.module('Pundit2.Client')
message: "<a href=\"javascript:void(0)\" data-inner-callback=\"0\">Log in or register</a> to Pundit to save your annotations and see your private notebooks.",
callbacks: [
function( /*alert*/ ) {
MyPundit.login();
MyPundit.loginWithoutSwitch();
return true;
}
]
Expand Down
120 changes: 81 additions & 39 deletions app/src/Core/MyPundit.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ angular.module('Pundit2.Core')
notebookLabel: undefined
};

var loginExecute = function(where, popoverPlacement, skipClose) {
loginPromise = $q.defer();

if (myPundit.isUserLogged()) {
loginPromise.resolve(true);
} else {
loginStatus = 'loggedOff';
myPundit.popoverLogin(where, popoverPlacement, skipClose);
}

return loginPromise.promise;
};

myPundit.useCookies = true;

/**
Expand Down Expand Up @@ -158,7 +171,10 @@ angular.module('Pundit2.Core')
angular.extend(infoCookie, data);
var expirationDate = (new Date()).getTime() + myPundit.options.userCookieExpireTime;
expirationDate = new Date(expirationDate);
$cookies.putObject('pundit.Info', infoCookie, {expires: expirationDate, path: '/'});
$cookies.putObject('pundit.Info', infoCookie, {
expires: expirationDate,
path: '/'
});
};

/**
Expand Down Expand Up @@ -201,11 +217,11 @@ angular.module('Pundit2.Core')
path: '/'
});
EventDispatcher.sendEvent('MyPundit.isUserLogged', isUserLogged);
$timeout(function () {
$timeout(function() {
promise.resolve(true);
}, 5);

$timeout(function(){
$timeout(function() {
myPundit.checkLoggedIn(true);
}, 500);

Expand All @@ -229,24 +245,39 @@ angular.module('Pundit2.Core')
if (data.loginStatus === 0) {
isUserLogged = false;
EventDispatcher.sendEvent('MyPundit.isUserLogged', isUserLogged);
$cookies.remove('pundit.User', {path: '/'});
$cookies.remove('pundit.Info', {path: '/'});
$cookies.remove('pundit.User', {
path: '/'
});
$cookies.remove('pundit.Info', {
path: '/'
});
promise.resolve(false);
} else {
// user is logged in
isUserLogged = true;
loginStatus = 'loggedIn';
userData = data;
$cookies.putObject('pundit.User', data, {expires: expirationDate, path: '/'});
$cookies.putObject('pundit.User', data, {
expires: expirationDate,
path: '/'
});
EventDispatcher.sendEvent('MyPundit.isUserLogged', isUserLogged);
promise.resolve(true);
}
if (dispatchDocumentEvent) {
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {event: 'Pundit.userLoggedStatusChanged', data: null});
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {
event: 'Pundit.userLoggedStatusChanged',
data: null
});
}
}).error(function() {
myPundit.err('Server error');
EventDispatcher.sendEvent('Pundit.alert', {title: 'Oops! Something went wrong.', id: 'ERROR', timeout: null, message: 'There was an error while trying to communicate with server. Please reaload the page in few minutes'});
EventDispatcher.sendEvent('Pundit.alert', {
title: 'Oops! Something went wrong.',
id: 'ERROR',
timeout: null,
message: 'There was an error while trying to communicate with server. Please reaload the page in few minutes'
});
promise.reject('check logged in promise error');
});

Expand All @@ -271,16 +302,11 @@ angular.module('Pundit2.Core')
*
*/
myPundit.login = function(popoverPlacement) {
loginPromise = $q.defer();

if (myPundit.isUserLogged()) {
loginPromise.resolve(true);
} else {
loginStatus = 'loggedOff';
myPundit.popoverLogin('login', popoverPlacement);
}
return loginExecute('login', popoverPlacement, false);
};

return loginPromise.promise;
myPundit.loginWithoutSwitch = function(popoverPlacement) {
return loginExecute('login', popoverPlacement, true);
};

// TODO remove it, remove the old login popup and manage popover in unit test
Expand Down Expand Up @@ -412,13 +438,20 @@ angular.module('Pundit2.Core')
userData = {};
logoutPromise.resolve(true);
Analytics.track('main-events', 'user--logout');
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {event: 'Pundit.userProfileUpdated', data: null});
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {
event: 'Pundit.userProfileUpdated',
data: null
});
}).error(function() {
logoutPromise.reject('logout promise error');
});

$cookies.remove('pundit.User', {path: '/'});
$cookies.remove('pundit.Info', {path: '/'});
$cookies.remove('pundit.User', {
path: '/'
});
$cookies.remove('pundit.Info', {
path: '/'
});

return logoutPromise.promise;
};
Expand Down Expand Up @@ -486,28 +519,28 @@ angular.module('Pundit2.Core')
if (params.data === 'loginPageLoaded' || params.data === 'pageLoaded') {
popoverState.popover.$scope.isLoading = false;
popoverState.popover.$scope.$digest();
}
else if (params.data === 'loginCheck') {
} else if (params.data === 'loginCheck') {
popoverState.popover.$scope.isLoading = true;
popoverState.popover.$scope.postLoginPreCheck = true;
popoverState.popover.$scope.$digest();
}
else if (params.data === 'profileSuccessfullyUpdated') {
} else if (params.data === 'profileSuccessfullyUpdated') {
$timeout.cancel(popoverState.autoCloseTimeout);
popoverState.autoCloseTimeout = $timeout(function() {
myPundit.closeLoginPopover();
}, 2500);
if (!updateUser) {
console.log("updating user name by event");
updateUser = true;
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {event: 'Pundit.userProfileUpdated', data: null});
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {
event: 'Pundit.userProfileUpdated',
data: null
});
myPundit.checkLoggedIn(true).then(function() {
updateUser = false;
$rootScope.$$phase || $rootScope.$digest();
});
}
}
else if (params.data === 'forcePopoverClose') {
} else if (params.data === 'forcePopoverClose') {
if (typeof popoverState.autoCloseTimeout !== 'undefined' && popoverState.autoCloseTimeout !== null) {
$timeout.cancel(popoverState.autoCloseTimeout);
}
Expand All @@ -518,24 +551,25 @@ angular.module('Pundit2.Core')
console.log("updating user name by force close");
updateUser = true;
$timeout(function() {
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {event: 'Pundit.userProfileUpdated', data: null});
EventDispatcher.sendEvent('Pundit.dispatchDocumentEvent', {
event: 'Pundit.userProfileUpdated',
data: null
});
myPundit.checkLoggedIn(true).then(function() {
updateUser = false;
$rootScope.$$phase || $rootScope.$digest();
});
}, 50);
}
myPundit.closeLoginPopover();
}
else if (params.data === 'userLoggedIn') {
} else if (params.data === 'userLoggedIn') {
popoverState.popover.$scope.postLoginPreCheck = true;
myPundit.checkLoggedIn().then(function(status) {
popoverState.popover.$scope.isLoading = false;
if (status) {
popoverState.loginSuccess();
loginPromise.resolve(true);
}
else {
} else {
popoverState.popover.$scope.loginSomeError = true;
loginPromise.resolve(false);
}
Expand Down Expand Up @@ -586,14 +620,18 @@ angular.module('Pundit2.Core')
myPundit.addPostMessageListener();

// TODO This is not really a popoverLogin but more a popover toggler
myPundit.popoverLogin = function(where, popoverPlacement) {
myPundit.popoverLogin = function(where, popoverPlacement, skipClose) {
if (typeof(loginPromise) === 'undefined' && where !== 'editProfile') {
return;
// loginPromise = $q.defer();
}

// If there's already a Login popover I close and destroy it
if (popoverState.popover !== null) {
if (typeof skipClose !== 'undefined' && skipClose) {
return;
}

popoverState.popover.hide();
popoverState.popover.destroy(); // TODO Doesn't remove the code?????
popoverState.popover = null;
Expand All @@ -603,7 +641,7 @@ angular.module('Pundit2.Core')

// popoverState.anchor = angular.element('.pnd-toolbar-login-button');
// popoverState.popover = $popover(angular.element(".pnd-toolbar-toggle-button"), popoverState.options);

var popoverOptions = popoverState.options;
if (typeof popoverPlacement !== 'undefined') {
popoverOptions = angular.copy(popoverState.options);
Expand Down Expand Up @@ -646,7 +684,7 @@ angular.module('Pundit2.Core')
checkPopoverPosition();
});

if (typeof loginPromise !== 'undefined'){
if (typeof loginPromise !== 'undefined') {
return loginPromise.promise;
}
};
Expand Down Expand Up @@ -687,19 +725,23 @@ angular.module('Pundit2.Core')

myPundit.checkUserCookie = function() {
// TODO: expand this check
$cookies.remove('pundit.User', {path: '/'});
$cookies.remove('pundit.Info', {path: '/'});
$cookies.remove('pundit.User', {
path: '/'
});
$cookies.remove('pundit.Info', {
path: '/'
});
};

var clientHidden = false;
EventDispatcher.addListener('Client.hide', function(/*e*/) {
EventDispatcher.addListener('Client.hide', function( /*e*/ ) {
if (!clientHidden) {
myPundit.removePostMessageListener();
}
clientHidden = true;
});

EventDispatcher.addListener('Client.show', function(/*e*/) {
EventDispatcher.addListener('Client.show', function( /*e*/ ) {
if (clientHidden) {
myPundit.addPostMessageListener();
}
Expand Down
Loading

0 comments on commit 752b9a1

Please sign in to comment.