Skip to content

Commit

Permalink
Don't re-open a manually closed disclaimer
Browse files Browse the repository at this point in the history
  • Loading branch information
llienher committed Mar 23, 2023
1 parent ef77191 commit bc88420
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/message/Disclaimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,32 @@ export class MessageDisclaimerService extends ngeoMessageMessage {
this.messages_ = {};

/**
* Increments if the message is used or not.
* @type {Object<string, number>}
* @private
*/
this.messagesConsumerCount_ = {};

/**
* The messages UID currently active and visible.
* @type {Object<string, boolean>}
* @private
*/
this.uids_ = {};

/**
* The messages activated once.
* @type{string}
* @private
*/
this.validMessages_ = [];

/**
* The messages closed manually.
* @type{string}
* @private
*/
this.closedMessages_ = [];
}

/**
Expand Down Expand Up @@ -145,6 +161,15 @@ export class MessageDisclaimerService extends ngeoMessageMessage {
return;
}

// If already closed previously.
if (this.isClosedMessage_(uid) && this.isValidMessage_(uid)) {
return;
}

// Set the message status as opened once
this.validMessages_ = this.validMessages_.filter((msg) => msg !== uid);
this.validMessages_.push(uid);

this.uids_[uid] = true;

if (message.popup === true) {
Expand Down Expand Up @@ -202,6 +227,9 @@ export class MessageDisclaimerService extends ngeoMessageMessage {
const msg = angular.element('<span />').html(message.msg);
el.append(button).append(msg);

// Set the message status as manually closed
button.on('click', () => this.closedMessages_.push(uid));

let container;

if (message.target) {
Expand Down Expand Up @@ -240,6 +268,24 @@ export class MessageDisclaimerService extends ngeoMessageMessage {
return `${message.msg}-${message.type}`;
}

/**
* @param {string} uid The disclaimer UID.
* @returns {boolean} True if the uid is present.
* @private
*/
isClosedMessage_(uid) {
return this.closedMessages_.find((msg) => msg === uid);
}

/**
* @param {string} uid The disclaimer UID.
* @returns {boolean} True if the uid is present.
* @private
*/
isValidMessage_(uid) {
return this.validMessages_.find((msg) => msg === uid);
}

/**
* Close the message.
*
Expand All @@ -252,6 +298,11 @@ export class MessageDisclaimerService extends ngeoMessageMessage {

// (1) No need to do anything if message doesn't exist
if (!this.uids_[uid]) {
// If the message has been closed previously
if (this.isClosedMessage_(uid) && this.isValidMessage_(uid)) {
this.closedMessages_ = this.closedMessages_.filter((msg) => msg !== uid);
this.validMessages_ = this.validMessages_.filter((msg) => msg !== uid);
}
return;
}
delete this.uids_[uid];
Expand Down
2 changes: 1 addition & 1 deletion src/message/Message_OLD.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class {
*/
show(object) {
const msgObjects = this.getMessageObjects(object);
msgObjects.forEach(this.showMessage, this);
msgObjects.forEach((msg) => this.showMessage(msg));
}

/**
Expand Down

0 comments on commit bc88420

Please sign in to comment.