Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Fix popup bug when displaying multiple popups #330

Merged
merged 2 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions uw-frame-components/portal/features/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ define(['angular','require'], function(angular, require) {
//local functions ---------------------------------------------------------

var getPopups = function(){
if(!$rootScope.GuestMode) {
if (!$rootScope.GuestMode) {
portalFeaturesService.getUnseenPopups().then(function(unseenPopups) {
if(unseenPopups.length !=0 && !$rootScope.GuestMode){
if (unseenPopups.length !=0 && !$rootScope.GuestMode) {
var orderedPopups = $filter('orderBy')(unseenPopups, ['popup.startYear', 'popup.startMonth', 'popup.startDay', 'id']);
$scope.latestFeature = orderedPopups[0];

Expand All @@ -80,6 +80,7 @@ define(['angular','require'], function(angular, require) {
clickOutsideToClose: true,
openFrom: 'left',
closeTo: 'right',
preserveScope: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I remember getting caught by this before.

scope: $scope,
controller: function DialogController($scope, $mdDialog) {
$scope.closeDialog = function(action) {
Expand Down
114 changes: 56 additions & 58 deletions uw-frame-components/portal/features/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ define(['angular'], function(angular) {
for(var i=0; i<=data.id; i++){
seenAnnouncements.push(i);
}
$sessionStorage.seenAnnouncmentIds = seenAnnouncements;
keyValueService.setValue(KV_KEYS.VIEWED_ANNOUNCEMENT_IDS, $sessionStorage.seenAnnouncmentIds).then(function(data){
$sessionStorage.seenAnnouncementIds = seenAnnouncements;
keyValueService.setValue(KV_KEYS.VIEWED_ANNOUNCEMENT_IDS, $sessionStorage.seenAnnouncementIds).then(function(data){
keyValueService.deleteValue("lastviewedannouncementid").then(function(){
return resolve(null);
}, function(response){
Expand Down Expand Up @@ -132,98 +132,100 @@ define(['angular'], function(angular) {
});
}

var getSeenAnnouncments = function(){
var getSeenAnnouncements = function(){
return $q(function(resolve, reject){
if(!$sessionStorage.seenAnnouncmentIds){
if(!$sessionStorage.seenAnnouncementIds){
updateLegacySeenAnnouncements().then(function(){
keyValueService.getValue(KV_KEYS.VIEWED_ANNOUNCEMENT_IDS).then(function(data){
if(!Array.isArray(data)){
$sessionStorage.seenAnnouncmentIds = [];
$sessionStorage.seenAnnouncementIds = [];
}else{
$sessionStorage.seenAnnouncmentIds = data;
$sessionStorage.seenAnnouncementIds = data;
}
return resolve($sessionStorage.seenAnnouncmentIds);
return resolve($sessionStorage.seenAnnouncementIds);
}, function(response){
return reject(response);
});
}, function(response){
return reject(response);
});
}else{
return resolve($sessionStorage.seenAnnouncmentIds);
return resolve($sessionStorage.seenAnnouncementIds);
};
});
}

var getSeenPopups = function(){
return $q(function(resolve, reject){
if(!$sessionStorage.seenPopupIds){
updateLegacyPopups().then(function(){
keyValueService.getValue(KV_KEYS.VIEWED_POPUP_IDS).then(function(data){
if(!Array.isArray(data)){
return $q(function(resolve, reject) {
if (!$sessionStorage.seenPopupIds) {
updateLegacyPopups().then(function() {
keyValueService.getValue(KV_KEYS.VIEWED_POPUP_IDS).then(function(data) {
if(!Array.isArray(data)) {
$sessionStorage.seenPopupIds = [];
}else{
} else {
$sessionStorage.seenPopupIds = data;
}
return resolve($sessionStorage.seenPopupIds);
}, function(response){
}, function(response) {
return reject(response);
});
}, function(response){
}, function(response) {
return reject(response);
});
}else{
} else {
return resolve($sessionStorage.seenPopupIds);
};
}
});
}
};

var markAnnouncementSeen = function(announcementID){
return $q(function(resolve, reject){
//Store in session storage
if(!$sessionStorage.seenAnnouncmentIds){
$sessionStorage.seenAnnouncmentIds = [announcementID];
if(!$sessionStorage.seenAnnouncementIds){
$sessionStorage.seenAnnouncementIds = [announcementID];
}else{
$sessionStorage.seenAnnouncmentIds.push(announcementID);
$sessionStorage.seenAnnouncementIds.push(announcementID);
}
//Store in keyvalueStorage if able
if(keyValueService.isKVStoreActivated()){
keyValueService.setValue(KV_KEYS.VIEWED_ANNOUNCEMENT_IDS, $sessionStorage.seenAnnouncmentIds).then(function(data){
return resolve($sessionStorage.seenAnnouncmentIds);
keyValueService.setValue(KV_KEYS.VIEWED_ANNOUNCEMENT_IDS, $sessionStorage.seenAnnouncementIds).then(function(data){
return resolve($sessionStorage.seenAnnouncementIds);
},function(response){
return reject(response);
});
}else{
return resolve($sessionStorage.seenAnnouncmentIds);
return resolve($sessionStorage.seenAnnouncementIds);
}
});
}

var markPopupSeen = function(popupID){
return $q(function(resolve, reject){
var markPopupSeen = function(popupID) {
return $q(function(resolve, reject) {
//Store in session storage
if(!$sessionStorage.seenPopupIds){
if (!$sessionStorage.seenPopupIds) {
$sessionStorage.seenPopupIds = [popupID];
}else{
} else {
$sessionStorage.seenPopupIds.push(popupID);
}
//Store in keyvalueStorage if able
if(keyValueService.isKVStoreActivated()){
keyValueService.setValue(KV_KEYS.VIEWED_POPUP_IDS, $sessionStorage.seenPopupIds).then(function(data){
return resolve($sessionStorage.seenPopupIds);
},function(response){
return reject(response);
});
}else{
if (keyValueService.isKVStoreActivated()) {
keyValueService.setValue(KV_KEYS.VIEWED_POPUP_IDS, $sessionStorage.seenPopupIds)
.then(function(data) {
return resolve($sessionStorage.seenPopupIds);
},
function(response) {
return reject(response);
});
} else {
return resolve($sessionStorage.seenPopupIds);
}
});
}
};

var getUnseenAnnouncements = function(){
var successFn, errorFn;
successFn = function(data){
//features in data[0] //seenAnnouncments in data[1]
//features in data[0] //seenAnnouncements in data[1]
var announcements = filterFilter(data[0], {isBuckyAnnouncement : true});
if(announcements && announcements.length != 0) {
//filter down to ones they haven't seen
Expand All @@ -247,47 +249,43 @@ define(['angular'], function(angular) {
};
errorFn = function(reason){
//Currently logging errors to console.
console.log("error retreiving unseenAnnouncements: " + reason.status);
console.log("error retrieving unseenAnnouncements: " + reason.status);
return reason;
};

return $q.all([getFeatures(), getSeenAnnouncments()]).then(successFn, errorFn);
return $q.all([getFeatures(), getSeenAnnouncements()]).then(successFn, errorFn);
}


var getUnseenPopups = function(){
var getUnseenPopups = function() {
var successFn, errorFn;
successFn = function(data){
successFn = function(data) {
var popupFeatures = filterFilter(data[0], {isPopup : true});
if(popupFeatures.length != 0){
if (popupFeatures.length != 0) {
var today = Date.parse(new Date());
var filterExpiredPopups = function(feature){
var filterExpiredPopups = function(feature) {
var startDate = Date.parse(new Date(feature.popup.startYear, feature.popup.startMonth, feature.popup.startDay));
var endDate = Date.parse(new Date(feature.popup.endYear, feature.popup.endMonth, feature.popup.endDay));
return (today > startDate && today < endDate);
}
var filterUnEnabledPopups = function(feature){
};
var filterUnEnabledPopups = function(feature) {
return feature.popup.enabled;
}
var filterSeenPopups = function(feature){
if(data[1].indexOf(feature.id) !== -1){
return false;
}
return true;
}
var filteredPopupFeatures = popupFeatures.filter(filterSeenPopups).filter(filterExpiredPopups).filter(filterUnEnabledPopups);
return filteredPopupFeatures;
};
var filterSeenPopups = function(feature) {
return !(data[1].indexOf(feature.id) !== -1);
};
return popupFeatures.filter(filterSeenPopups).filter(filterExpiredPopups).filter(filterUnEnabledPopups);
}
}
};

errorFn = function(reason){
//Currently logging errors to console.
console.log("error retreiving unseenPopups: " + reason.status);
console.log("error retrieving unseenPopups: " + reason.status);
return reason;
};

return $q.all([getFeatures(), getSeenPopups()]).then(successFn, errorFn);
}
};


return {
Expand Down