Skip to content

Commit 448f8ce

Browse files
authored
Merge pull request #1684 from CodeNow/SAN-4734-plan-upgrade-notification
SAN-4734 Plan Upgrade Notification
2 parents 80e33f1 + 22b1233 commit 448f8ce

5 files changed

Lines changed: 83 additions & 25 deletions

File tree

client/directives/environment/environmentController.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ function EnvironmentController(
1515
$state,
1616
$timeout,
1717
$window,
18-
errs,
1918
favico,
2019
fetchUser,
2120
fetchDockerfileForContextVersion,
2221
fetchInstancesByPod,
2322
fetchOrgMembers,
24-
fetchOrgTeammateInvitations,
2523
helpCards,
2624
keypather,
2725
ModalService,
@@ -142,15 +140,35 @@ function EnvironmentController(
142140
$window.removeEventListener('scroll', scrollHelper);
143141
});
144142

145-
$scope.alert = null;
143+
EC.alert = null;
146144

147145
$scope.$on('alert', function (evt, data) {
148-
$scope.alert = data;
149-
$timeout(function () {
150-
$scope.alert = null;
151-
}, 5000);
146+
EC.alert = data;
147+
if (!data.planChanged) {
148+
$timeout(function () {
149+
EC.actions.closeAlert();
150+
}, 5000);
151+
}
152152
});
153153

154+
EC.actions = {
155+
closeAlert: function () {
156+
EC.alert = null;
157+
},
158+
goToBilling: function () {
159+
EC.actions.closeAlert();
160+
ModalService.showModal({
161+
controller: 'SettingsModalController',
162+
controllerAs: 'SEMC',
163+
templateUrl: 'settingsModalView',
164+
inputs: {
165+
tab: 'billing',
166+
subTab: 'billingForm'
167+
}
168+
});
169+
}
170+
};
171+
154172
$scope.helpPopover = {
155173
data: $scope.help,
156174
actions: {

client/directives/environment/environmentView.jade

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
//- new alerts
22
.grid-block.vertical.notification.notification-sm.js-animate.top-right(
33
ng-class = "{\
4-
'green': alert.type === 'success',\
5-
'red': alert.type === 'deleted',\
6-
'plan-changed text-center': $root.featureFlags.billingPlanChangedNotification\
4+
'green': EC.alert.type === 'success',\
5+
'red': EC.alert.type === 'deleted',\
6+
'plan-changed text-center': EC.alert.newPlan\
77
}"
8-
ng-if = "alert"
8+
ng-if = "EC.alert"
99
)
1010
.grid-block.align-center(
11-
ng-class = "{'justify-center': $root.featureFlags.billingPlanChangedNotification}"
11+
ng-class = "{'justify-center': EC.alert.newPlan}"
1212
)
1313
svg.anchor-left.iconnables.icons-check(
14-
ng-if = "alert.type === 'success'"
14+
ng-if = "EC.alert.type === 'success'"
1515
)
1616
use(
1717
xlink:href = "#icons-check"
1818
)
1919
svg.anchor-left.iconnables.icons-trash(
20-
ng-if = "alert.type === 'deleted'"
20+
ng-if = "EC.alert.type === 'deleted'"
2121
)
2222
use(
2323
xlink:href = "#icons-trash"
2424
)
25-
span {{alert.text}}
25+
span {{EC.alert.text}}
2626
a.link.small.link-undo(
2727
ng-if = "$root.featureFlags.undoDelete"
2828
) Undo
2929
.grid-block.vertical(
30-
ng-if = "$root.featureFlags.billingPlanChangedNotification"
30+
ng-if = "EC.alert.newPlan"
3131
)
3232
small.small You’ve been bumped into the next plan for 
3333
strong.strong free
3434
|  until your next billing period. 
3535
//- to billing tab
36-
a.link Plan Details
37-
button.btn.btn-xs.green Got it, thanks!
36+
a.link(
37+
ng-click = "EC.actions.goToBilling()"
38+
) Plan Details
39+
button.btn.btn-xs.green(
40+
ng-click = "EC.actions.closeAlert()"
41+
) Got it, thanks!
3842

3943
//- environment page
4044
.grid-block.environment-wrapper(

client/services/createAndBuildNewContainerService.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function createAndBuildNewContainer(
1818
createNewInstance,
1919
eventTracking,
2020
fetchInstancesByPod,
21+
fetchPlan,
2122
fetchUser,
2223
helpCards
2324
) {
@@ -27,11 +28,14 @@ function createAndBuildNewContainer(
2728
// Save this in case it changes
2829
var cachedActiveAccount = $rootScope.dataApp.data.activeAccount;
2930
var instance = null;
31+
var oldPlanId = null;
3032
return $q.all({
3133
masterInstances: fetchInstancesByPod(cachedActiveAccount.oauthName()),
32-
user: fetchUser()
34+
user: fetchUser(),
35+
plan: fetchPlan()
3336
})
3437
.then(function (response) {
38+
oldPlanId = response.plan.next.id;
3539
var instanceOptions = {
3640
name: containerName,
3741
owner: {
@@ -47,10 +51,6 @@ function createAndBuildNewContainer(
4751
return $q.when(createPromiseForState);
4852
})
4953
.then(function (newServerModel) {
50-
$rootScope.$broadcast('alert', {
51-
type: 'success',
52-
text: 'Container Created'
53-
});
5454
helpCards.hideActiveCard();
5555
if (options.isolation) {
5656
newServerModel.opts.isIsolationGroupMaster = false;
@@ -63,6 +63,20 @@ function createAndBuildNewContainer(
6363
instance
6464
);
6565
})
66+
.then(function (instance) {
67+
fetchPlan.cache.clear();
68+
return fetchPlan()
69+
.then(function (newPlan) {
70+
$rootScope.$broadcast('alert', {
71+
type: 'success',
72+
text: 'Container Created',
73+
newPlan: newPlan.next.id !== oldPlanId
74+
});
75+
})
76+
.then(function () {
77+
return instance;
78+
});
79+
})
6680
.then(function (instance) {
6781
helpCards.refreshAllCards();
6882
return instance;

client/services/featureFlagService.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function featureFlags(
2121
backup: false,
2222
blankDockerfile: false, // allows users to skip the verification flow
2323
billing: false,
24-
billingPlanChangedNotification: false, // if plan changes because of container created
2524
cardStatus: false,
2625
connections: false,
2726
configTerminal: false, // flag for terminal in config view

test/unit/services/createAndBuildNewContainerService.unit.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var helpCardsMock = require('../apiMocks/HelpCardServiceMock');
1313
var thisUser = runnable.newUser(apiMocks.user);
1414

1515
describe('createAndBuildNewContainer'.bold.underline.blue, function () {
16+
var mockFetchPlan;
17+
var mockPlan;
1618
var ctx = {};
1719

1820
function createMasterPods() {
@@ -49,7 +51,11 @@ describe('createAndBuildNewContainer'.bold.underline.blue, function () {
4951
ctx.pageNameMock = {
5052
setTitle: sinon.spy()
5153
};
52-
54+
mockPlan = {
55+
next: {
56+
id: '1234'
57+
}
58+
};
5359

5460
runnable.reset(apiMocks.user);
5561
angular.mock.module('app', function ($provide) {
@@ -61,6 +67,13 @@ describe('createAndBuildNewContainer'.bold.underline.blue, function () {
6167
$provide.factory('helpCards', helpCardsMock.create(ctx));
6268
$provide.factory('fetchInstancesByPod', fetchInstancesByPodMock.fetch());
6369
$provide.factory('createNewInstance', createNewInstanceMock.fetch());
70+
$provide.factory('fetchPlan', function ($q) {
71+
mockFetchPlan = sinon.stub().returns($q.when(mockPlan));
72+
mockFetchPlan.cache = {
73+
clear: sinon.stub()
74+
};
75+
return mockFetchPlan;
76+
});
6477
$provide.value('errs', ctx.errs);
6578
});
6679
angular.mock.inject(function (
@@ -71,6 +84,7 @@ describe('createAndBuildNewContainer'.bold.underline.blue, function () {
7184
) {
7285
$q = _$q_;
7386
$rootScope = _$rootScope_;
87+
$rootScope.$broadcast = sinon.stub();
7488
createAndBuildNewContainer = _createAndBuildNewContainer_;
7589
keypather = _keypather_;
7690
});
@@ -113,9 +127,18 @@ describe('createAndBuildNewContainer'.bold.underline.blue, function () {
113127
sinon.assert.calledOnce(instances.add);
114128
sinon.assert.calledOnce(ctx.eventTracking.triggeredBuild);
115129

130+
mockFetchPlan.reset();
131+
mockFetchPlan.returns($q.when({next: {id: '5678'}}));
116132
createNewInstanceMock.triggerPromise(instance);
117133
$rootScope.$digest();
118134
sinon.assert.calledOnce(ctx.helpCards.refreshAllCards);
135+
sinon.assert.calledOnce(mockFetchPlan.cache.clear);
136+
sinon.assert.calledOnce(mockFetchPlan);
137+
sinon.assert.calledWith($rootScope.$broadcast, 'alert', {
138+
type: 'success',
139+
text: 'Container Created',
140+
newPlan: true
141+
});
119142
});
120143

121144
it('should create a server with isolation', function () {

0 commit comments

Comments
 (0)