Skip to content

Commit

Permalink
Handle limit errors on posts, post type and users
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran authored and rjmackay committed Dec 14, 2015
1 parent 23f53ea commit 87ac1e3
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 7 deletions.
8 changes: 7 additions & 1 deletion app/common/controllers/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ function (
$scope,
$rootScope
) {
$scope.showNotificationslider = false;
$scope.showNotificationSlider = false;
$scope.showLimitSlider = false;
$scope.showModalAlerts = false;
$rootScope.$on('event:show:notification-slider', function (event, message) {
$scope.notificationSliderMessage = message;
$scope.showNotificationSlider = true;
});

$rootScope.$on('event:show:limit-slider', function (event, message) {
$scope.limitSliderMessage = message;
$scope.showLimitSlider = true;
});

$rootScope.$on('event:show:modal-alerts', function (event, messages) {
$scope.modalAlertMessages = messages;
$scope.showModalAlerts = true;
Expand Down
7 changes: 7 additions & 0 deletions app/common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"feature_limits": {
"view_unavailable" : "The {{value}} view isn't available on your current plan. <a href=\"/settings/plan\">Upgrade your plan</a> to get it!"
},
"limit": {
"plan_limit" : "Ushahidi Plan Limit",
"post_limit_reached" : "You have reached the limit of published Posts for your plan. To get more simply <a href=\"/settings/plan\">upgrade your plan</a>.",
"admin_limit_reached" : "You have reached the limit of admin users for your plan. To get more simply <a href=\"/settings/plan\">upgrade your plan</a>.",
"post_type_limit_reached" : "You have reached the limit of post types for your plan. To get more simply <a href=\"/settings/plan\">upgrade your plan</a>.",
"upgrade" : "Upgrade"
},
"form": {
"add_field" : "Add New Field",
"add_field_instructions": "Add instructions to this field",
Expand Down
7 changes: 6 additions & 1 deletion app/common/services/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function ($window, _, $q, $rootScope) {
$rootScope.$emit('event:show:notification-slider', message);
};

var showLimitSlider = function (message) {
$rootScope.$emit('event:show:limit-slider', message);
};

var showAlerts = function (alertMessages) {
$rootScope.$emit('event:show:modal-alerts', alertMessages);
};
Expand All @@ -40,7 +44,8 @@ function ($window, _, $q, $rootScope) {
showNotificationSlider: showNotificationSlider,
showAlerts: showAlerts,
showApiErrors: showApiErrors,
showConfirm: showConfirm
showConfirm: showConfirm,
showLimitSlider: showLimitSlider
};

}];
16 changes: 15 additions & 1 deletion app/post/directives/post-editor-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,22 @@ function (
$location.path('/');
}
}, function (errorResponse) { // errors
var validationErrors = [];
// @todo refactor limit handling
_.each(errorResponse.data.errors, function (value, key) {
// Ultimately this should check individual status codes
// for the moment just check for the message we expect
if (value.title === 'limit::posts') {
$translate('limit.post_limit_reached').then(function (message) {
Notify.showLimitSlider(message);
});
} else {
validationErrors.push(value);
}
});

Notify.showApiErrors(validationErrors);

Notify.showApiErrors(errorResponse);
$scope.saving_post = false;
});
};
Expand Down
24 changes: 23 additions & 1 deletion app/setting/controllers/setting-forms-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ module.exports = [
'FormEndpoint',
'FormStageEndpoint',
'Notify',
'Config',
'_',
function (
$scope,
$translate,
$location,
$q,
FormEndpoint,
FormStageEndpoint,
Notify
Notify,
Config,
_
) {
$scope.formQuota = Config.features.limits.forms;

$translate('nav.posts_and_entities').then(function (title) {
$scope.title = title;
Expand Down Expand Up @@ -55,6 +60,23 @@ function (
});
$location.url('/settings/forms/' + form.id + '/stages/' + stage.id);
});
}, function (errorResponse) {
var validationErrors = [];
// @todo refactor limit handling
_.each(errorResponse.data.errors, function (value, key) {
// Ultimately this should check individual status codes
// for the moment just check for the message we expect
if (value.title === 'limit::admin') {
$translate('limit.post_type_limit_reached').then(function (message) {
Notify.showLimitSlider(message);
});
} else {
validationErrors.push(value);
}
});

Notify.showApiErrors(validationErrors);
$scope.processing = false;
});
};
// End new form
Expand Down
16 changes: 15 additions & 1 deletion app/setting/controllers/setting-users-create-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,21 @@ function (
$location.path('/settings/users/' + response.id);
}
}, function (errorResponse) { // error
Notify.showApiErrors(errorResponse);
var validationErrors = [];
// @todo refactor limit handling
_.each(errorResponse.data.errors, function (value, key) {
// Ultimately this should check individual status codes
// for the moment just check for the message we expect
if (value.title === 'limit::admin') {
$translate('limit.admin_limit_reached').then(function (message) {
Notify.showLimitSlider(message);
});
} else {
validationErrors.push(value);
}
});

Notify.showApiErrors(validationErrors);
$scope.processing = false;
});
};
Expand Down
17 changes: 16 additions & 1 deletion app/setting/controllers/setting-users-edit-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,22 @@ function (
}
$rootScope.goBack();
}, function (errorResponse) { // error
Notify.showApiErrors(errorResponse);
var validationErrors = [];
// @todo refactor limit handling
_.each(errorResponse.data.errors, function (value, key) {
// Ultimately this should check individual status codes
// for the moment just check for the message we expect
if (value.title === 'limit::admin') {
$translate('limit.admin_limit_reached').then(function (message) {
Notify.showLimitSlider(message);
});
} else {
validationErrors.push(value);
}
});

Notify.showApiErrors(validationErrors);

$scope.processing = false;
});
};
Expand Down
8 changes: 8 additions & 0 deletions server/www/templates/partials/notification-system.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
<p>{{notificationSliderMessage}}</p>
</notification-slider>

<notification-slider visible="showLimitSlider" >
<h1 translate>limit.plan_limit</h1>
<div translate>{{limitSliderMessage}}</div>
<div class="divider padded"></div>
<a class="button" href="/settings/plan" translate>limit.upgrade</a>
<div class="divider white"></div>
</notification-slider>

<modal visible="showModalAlerts" title="notify.generic.alerts">

<div id="alert-modal-text" ng-repeat="alert in modalAlertMessages">
Expand Down
5 changes: 4 additions & 1 deletion server/www/templates/settings/forms/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ <h1 class="title">{{title}}</h1>

<h4>Start from scratch:</h4>
<div class="cards-select">
<div class="selection-card custom">
<div class="selection-card custom" ng-show="forms.length < formQuota || formQuota === true">
<a ng-click="openNewForm()" >
<h3>Add a new post type</h3>
</a>
</div>
<p ng-show="forms.length >= formQuota && formQuota !== true">
<span translate>limit.post_type_limit_reached</span>
</p>
</div>

<div ng-show="forms.length">
Expand Down

0 comments on commit 87ac1e3

Please sign in to comment.