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

Fix/no config enabled users errors and timezone mapper #3011

Merged
Merged
14 changes: 8 additions & 6 deletions plugins/push/frontend/public/javascripts/countly.models.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,15 +1346,14 @@
type: dto.info && dto.info.scheduled ? SendEnum.LATER : SendEnum.NOW,
};
model.audienceSelection = triggerDto.delayed ? AudienceSelectionEnum.BEFORE : AudienceSelectionEnum.NOW;
model.timezone = triggerDto.tz ? TimezoneEnum.SAME : TimezoneEnum.DEVICE;
model.timezone = triggerDto.tz ? TimezoneEnum.DEVICE : TimezoneEnum.SAME;
return model;
},
mapDtoToAutomaticModel: function(dto) {
var model = this.mapDtoToBaseModel(dto);
model.type = TypeEnum.AUTOMATIC;
var triggerDto = dto.triggers[0];
model.cohorts = triggerDto.cohorts || [];
model.timezone = triggerDto.tz ? TimezoneEnum.SAME : TimezoneEnum.DEVICE;
model.delivery = {
startDate: moment(triggerDto.start).valueOf(),
endDate: triggerDto.end ? moment(triggerDto.end).valueOf() : null,
Expand Down Expand Up @@ -1727,6 +1726,9 @@
}
if (self.hasUserProperties(pushNotificationModel.message[localizationKey], 'title')) {
localeDto.titlePers = self.mapUserProperties(pushNotificationModel.message[localizationKey], 'title');
if (!title) {
localeDto.title = title;
}
}
if (pushNotificationModel.message[localizationKey].buttons.length) {
localeDto.buttons = self.mapButtons(pushNotificationModel.message[localizationKey]);
Expand All @@ -1746,12 +1748,12 @@
start: model.delivery.startDate,
};
if (model.delivery.type === SendEnum.LATER) {
result.tz = model.timezone === TimezoneEnum.SAME;
if (model.timezone === TimezoneEnum.DEVICE) {
result.tz = true;
result.sctz = new Date().getTimezoneOffset();
}
result.delayed = model.audienceSelection === AudienceSelectionEnum.BEFORE;
}
if (model.timezone === TimezoneEnum.SAME && model.delivery.type === SendEnum.LATER) {
result.sctz = new Date().getTimezoneOffset();
}
return [result];
},
mapAutomaticTrigger: function(model, options) {
Expand Down
35 changes: 30 additions & 5 deletions plugins/push/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,6 @@
var preparePushNotificationModel = Object.assign({}, self.pushNotificationUnderEdit);
preparePushNotificationModel.type = self.type;
countlyPushNotification.service.estimate(preparePushNotificationModel, options).then(function(response) {
if (response.total === 0) {
resolve(false);
CountlyHelpers.notify({ message: 'No users were found from selected configuration.', type: "error"});
return;
}
self.setLocalizationOptions(response.localizations);
self.setCurrentNumberOfUsers(response.total);
if (self.pushNotificationUnderEdit.type === self.TypeEnum.ONE_TIME || self.type === self.TypeEnum.ONE_TIME) {
Expand All @@ -475,6 +470,11 @@
if (response._id) {
self.setId(response._id);
}
if (response.total === 0) {
resolve(false);
CountlyHelpers.notify({ message: 'No users were found from selected configuration.', type: "error"});
return;
}
resolve(true);
}).catch(function(error) {
console.error(error);
Expand Down Expand Up @@ -1063,14 +1063,33 @@
this.updateIosPlatformSettingsStateIfFound();
this.updateAndroidPlatformSettingsStateIfFound();
},
resetDelivery: function() {
this.pushNotificationUnderEdit.delivery.startDate = Date.now();
this.pushNotificationUnderEdit.delivery.endDate = null;
this.pushNotificationUnderEdit.delivery.type = this.SendEnum.NOW;
},
updateOneTimeOptions: function() {
if (this.userCommand === this.UserCommandEnum.DUPLICATE) {
this.resetDelivery();
}
},
updateAutomaticOptions: function() {
if (this.userCommand === this.UserCommandEnum.DUPLICATE) {
this.resetDelivery();
this.pushNotificationUnderEdit.automatic.usersTimezone = null;
}
if (this.pushNotificationUnderEdit.automatic.usersTimezone) {
this.isUsersTimezoneSet = true;
}
if (this.pushNotificationUnderEdit.delivery.endDate) {
this.isEndDateSet = true;
}
},
updateTransactionalOptions: function() {
if (this.userCommand === this.UserCommandEnum.DUPLICATE) {
this.resetDelivery();
}
},
fetchPushNotificationById: function() {
var self = this;
this.setIsLoading(true);
Expand All @@ -1085,6 +1104,12 @@
if (self.pushNotificationUnderEdit.type === self.TypeEnum.AUTOMATIC) {
self.updateAutomaticOptions();
}
if (self.pushNotificationUnderEdit.type === self.TypeEnum.ONE_TIME) {
self.updateOneTimeOptions();
}
if (self.pushNotificationUnderEdit.type === self.TypeEnum.TRANSACTIONAL) {
self.updateTransactionalOptions();
}
})
.catch(function(error) {
console.error(error);
Expand Down
9 changes: 6 additions & 3 deletions plugins/push/frontend/public/templates/common-components.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,12 @@ <h5>{{ category }}</h5>
</details-tab-row>
<details-tab-row :label="i18n('push-notification-details.geolocation')">
<div class="bu-is-flex bu-is-flex-direction-column">
<div class="bu-level" v-for="locationName in locations">
{{locationName}}
</div>
<template v-if="locations.length">
<div class="bu-level" v-for="locationName in locations">
{{locationName}}
</div>
</template>
<template><span>-</span></template>
</div>
</details-tab-row>
</template>
Expand Down