Skip to content
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
48 changes: 43 additions & 5 deletions client/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ module.exports = [
orgs: function (fetchWhitelistedOrgs) {
return fetchWhitelistedOrgs();
},
activeOrg: function (
$stateParams,
whitelists,
moment
) {
var lowerAccountName = $stateParams.userName.toLowerCase();
var activeOrg = whitelists.find(function (whitelist) {
return whitelist.attrs.lowerName === lowerAccountName;
});
// All of this should be moved to inside @runnable/api-client
activeOrg.attrs.trialEnd = moment().add(2, 'days').toISOString();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Next steps will be to move this to api-client....

activeOrg.attrs.activePeriodEnd = moment().subtract(1, 'days').toISOString();
activeOrg.attrs.gracePeriodEnd = moment().add(5, 'days').toISOString();
activeOrg.attrs.stripeCustomerId = 1234;
activeOrg.attrs.hasPaymentMethod = false;
activeOrg.isInTrial = function () {
return moment(activeOrg.attrs.trialEnd) > moment().utc();
};
activeOrg.isInGrace = function () {
return !activeOrg.isInTrial() && moment(activeOrg.attrs.gracePeriodEnd) > moment().utc();
};
activeOrg.isInActivePeriod = function () {
return moment(activeOrg.attrs.activePeriodEnd) > moment().utc();
};
activeOrg.isGraceExpired = function () {
return !activeOrg.isInTrial() && moment.utc(activeOrg.attrs.gracePeriodEnd) < moment().utc();
};
activeOrg.trialDaysRemaining = function () {
return moment(activeOrg.attrs.trialEnd).diff(moment.utc(), 'days');
};
return activeOrg;
},
activeAccount: function (
$q,
$stateParams,
Expand All @@ -131,7 +163,8 @@ module.exports = [
whitelists,
$timeout,
user,
eventTracking
eventTracking,
activeOrg
) {
var lowerAccountName = $stateParams.userName.toLowerCase();
var userName = user.oauthName().toLowerCase();
Expand All @@ -151,10 +184,7 @@ module.exports = [
return $q.reject(new Error('User Unauthorized for Organization'));
});
}
var foundWhitelist = whitelists.find(function (whitelist) {
return whitelist.attrs.lowerName === lowerAccountName;
});
if (!foundWhitelist.attrs.allowed) {
if (!activeOrg.attrs.allowed) {
// There is a bug in ui-router and a timeout is the workaround
return $timeout(function () {
$state.go('paused');
Expand All @@ -163,6 +193,14 @@ module.exports = [
}
eventTracking.boot(user, {orgName: $stateParams.userName});
return matchedOrg;
},
populateCurrentOrgService: function (
activeOrg,
activeAccount,
currentOrg
) {
currentOrg.poppa = activeOrg;
currentOrg.github = activeAccount;
}
}
}, {
Expand Down
13 changes: 7 additions & 6 deletions client/controllers/controllerApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function ControllerApp(
keypather,
ModalService,
pageName,
currentOrg,

user,
orgs,
Expand Down Expand Up @@ -119,9 +120,9 @@ function ControllerApp(
}
};

if ($rootScope.featureFlags.billing && (activeAccount.isInGrace() || activeAccount.isGraceExpired())) {
if ($rootScope.featureFlags.billing && (currentOrg.poppa.isInGrace() || currentOrg.poppa.isGraceExpired())) {
// Determine if it's a trial end or just a normal payment due
if (activeAccount.attrs.hasPaymentMethod) {
if (currentOrg.poppa.attrs.hasPaymentMethod) {
ModalService.showModal({
controller: 'ExpiredAccountController',
controllerAs: 'EAC',
Expand All @@ -146,13 +147,13 @@ function ControllerApp(

CA.showTrialEndingNotification = function () {
return $rootScope.featureFlags.billing &&
activeAccount.isInTrial() &&
activeAccount.trialDaysRemaining() <= 3 &&
!activeAccount.attrs.hasPaymentMethod && !keypather.get($localStorage, 'hasDismissedTrialNotification.' + activeAccount.attrs.id);
currentOrg.poppa.isInTrial() &&
currentOrg.poppa.trialDaysRemaining() <= 3 &&
!currentOrg.poppa.attrs.hasPaymentMethod && !keypather.get($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

currentOrg.github.attrs.id should be able to come from poppa

(currentOrg.poppa.attrs.githubId)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yea, but I have the github object anyways, and if I'm looking for a github ID what better place than from the actual github object we have.

};

CA.closeTrialEndingNotification = function () {
keypather.set($localStorage, 'hasDismissedTrialNotification.' + activeAccount.attrs.id, true);
keypather.set($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id, true);
};

}
12 changes: 7 additions & 5 deletions client/directives/accountsSelect/directiveAccountsSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function accountsSelect (
errs,
keypather,
ModalService,
promisify
promisify,
currentOrg
) {
return {
restrict: 'A',
Expand Down Expand Up @@ -87,6 +88,7 @@ function accountsSelect (
$scope.$watch('data.activeAccount', function (account) {
if (!account) { return; }
keypather.set($scope, 'popoverAccountMenu.data.activeAccount', account);
keypather.set($scope, 'popoverAccountMenu.data.currentOrg', currentOrg);
keypather.set($scope, 'popoverAccountMenu.data.orgs', $scope.data.orgs);
keypather.set($scope, 'popoverAccountMenu.data.user', $scope.data.user);

Expand All @@ -102,8 +104,8 @@ function accountsSelect (
if (!$rootScope.featureFlags.billing) {
return '';
}
if ($scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod) {
return $scope.data.activeAccount.trialDaysRemaining();
if (currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod) {
return currentOrg.poppa.trialDaysRemaining();
}
return '';
};
Expand All @@ -113,8 +115,8 @@ function accountsSelect (
return {};
}
return {
badge: $scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod,
'badge-orange': $scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod
badge: currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod,
'badge-orange': currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod
};
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ul.list.popover-list(
ng-if = "data.showIntegrations"
)
li.list-item.popover-list-item.small.disabled {{data.activeAccount.oauthName()}} Settings
li.list-item.popover-list-item.small.disabled {{data.currentOrg.github.oauthName()}} Settings
//- *****************
//- $root.featureFlags.billing
li.list-item.popover-list-item(
Expand All @@ -34,10 +34,10 @@
)
| Billing
btn.btn-xxs.btn-badge.anchor-right.orange(
ng-if = "data.activeAccount.isInTrial() && !data.activeAccount.attrs.hasPaymentMethod"
title = "{{data.activeAccount.trialDaysRemaining() + ' days left in your trial'}}"
ng-if = "data.currentOrg.poppa.isInTrial() && !data.currentOrg.poppa.attrs.hasPaymentMethod"
title = "{{data.currentOrg.poppa.trialDaysRemaining() + ' days left in your trial'}}"
)
| {{data.activeAccount.trialDaysRemaining() + ' days left'}}
| {{data.currentOrg.poppa.trialDaysRemaining() + ' days left'}}
li.list-item.popover-list-item(
ng-click = "actions.openSettingsModal('teamManagement')"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ require('app')
keypather,
ModalService,
parseDockerfileForCardInfoFromInstance,
promisify
promisify,
currentOrg
) {
return {
restrict: 'A',
Expand Down Expand Up @@ -80,7 +81,7 @@ require('app')
};
$scope.helpCards = helpCards;
$scope.server = {};
$scope.activeAccount = $rootScope.dataApp.data.activeAccount;
$scope.activeAccount = currentOrg.github; // I'm unsure if this is used.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You mean our old practice of using stuff attached to the scope from 5 or 6 levels up is not great for determining how and when a variable is used... impossible!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Something like that.


function scrollIntoView() {
$document.scrollToElement(ele, 100, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require('app')

function NewContainerModalController(
$q,
$rootScope,
$timeout,
createNewBuildAndFetchBranch,
createNonRepoInstance,
Expand All @@ -19,7 +18,8 @@ function NewContainerModalController(
keypather,
loading,
ModalService,
close
close,
currentOrg
) {
var NCMC = this;
var helpCard = helpCards.getActiveCard();
Expand All @@ -43,7 +43,7 @@ function NewContainerModalController(
loading(NCMC.name + 'Repos', true);
$q.all({
instances: fetchInstancesByPod(),
repoList: fetchOwnerRepos($rootScope.dataApp.data.activeAccount.oauthName())
repoList: fetchOwnerRepos(currentOrg.github.oauthName())
})
.then(function (data) {
NCMC.instances = data.instances;
Expand Down Expand Up @@ -169,7 +169,7 @@ function NewContainerModalController(
.then(function (dockerfiles) {
if (dockerfiles.length === 0) {
NCMC.state.configurationMethod = 'new';
}
}
loading(NCMC.name + 'SingleRepo', false);
repo.loading = false;
repo.dockerfiles = dockerfiles;
Expand All @@ -180,7 +180,7 @@ function NewContainerModalController(

NCMC.createBuildAndGoToNewRepoModal = function (instanceName, repo, dockerfile, configurationMethod) {
loading(NCMC.name + 'SingleRepo', true);
return createNewBuildAndFetchBranch($rootScope.dataApp.data.activeAccount, repo, keypather.get(dockerfile, 'path'))
return createNewBuildAndFetchBranch(currentOrg.github, repo, keypather.get(dockerfile, 'path'))
.then(function (repoBuildAndBranch) {
repoBuildAndBranch.instanceName = instanceName;
if (configurationMethod === 'dockerfile' && dockerfile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@
ng-class = "{'in': isActivePanel()}"
trial-form
from-modal = 'true'
ng-if = "activeAccount.isInTrial() && !activeAccount.attrs.hasPaymentMethod"
ng-if = "currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod"
)
.grid-block.vertical.form-plan.fade(
ng-class = "{'in': isActivePanel()}"
ng-init = "state.hasDuration = false"
plan-status-form
ng-show = "!$root.isLoading.billingForm"
ng-if = "activeAccount.isInTrial() && !activeAccount.attrs.hasPaymentMethod"
ng-if = "currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod"
)

.grid-block.vertical.form-plan.label.padding-sm.fade(
ng-class = "{'in': isActivePanel()}"
ng-include = "'showPlanForm'"
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
)
.grid-block.vertical.label.padding-sm.fade(
ng-class = "{'in': isActivePanel()}"
show-payment-form
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
)
.grid-block.vertical.label.padding-sm.fade(
ng-class = "{'in': isActivePanel()}"
billing-history-form
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
)
.grid-block.vertical.label.padding-sm.fade(
ng-class = "{'in': isActivePanel()}"
ng-include = "'disableOrgForm'"
ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)"
ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)"
)
animated-panel(
name = "planStatusForm"
Expand All @@ -62,12 +62,12 @@
change-payment-form
save = "actions.save"
cancel = "actions.cancel"
updating = "activeAccount.attrs.hasPaymentMethod"
updating = "currentOrg.poppa.attrs.hasPaymentMethod"
)
animated-panel(
name = "confirmationForm"
)
.grid-block.vertical.form-plan.fade(
ng-class = "{'in': isActivePanel()}"
ng-include = "'confirmationForm'"
confirmation-form
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('app').directive('billingForm', billingForm);

function billingForm(
$rootScope
currentOrg
) {
return {
restrict: 'A',
Expand All @@ -16,7 +16,7 @@ function billingForm(
$scope.SEMC.showFooter = panelName === 'billingForm';
});
$scope.$broadcast('go-to-panel', $scope.SEMC.subTab || 'billingForm', 'immediate');
$scope.activeAccount = $rootScope.dataApp.data.activeAccount;
$scope.currentOrg = currentOrg;
$scope.actions = {
save: function () {
$scope.$broadcast('go-to-panel', 'confirmationForm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ form.padding-md(
)

.grid-block.well.padding-xxs.small.justify-center.text-center(
ng-if = "!CPFC.paymentMethod || !CPFC.activeAccount.isInTrial()"
ng-if = "!CPFC.paymentMethod || !CPFC.currentOrg.poppa.isInTrial()"
payment-summary
show-next = 'false'
)

//- 3 users is the minimum amount
p.grid-content.p.text-gray.text-center.padding-sm(
ng-if = "!CPFC.activeAccount.isInActivePeriod()"
ng-if = "!CPFC.currentOrg.poppa.isInActivePeriod()"
) We prorate your account for users added in the middle of a billing period.&#32;
a.link(
href = "#"
target = "_blank"
) Details

p.grid-content.p.text-gray.text-center.padding-sm(
ng-if = "CPFC.activeAccount.isInActivePeriod()"
ng-if = "CPFC.currentOrg.poppa.isInActivePeriod()"
) Your payment changes will be applied to your next billing date on {{getBillingDate()}}.

footer.modal-footer.clearfix
Expand All @@ -135,7 +135,7 @@ footer.modal-footer.clearfix
button.btn.btn-md.green.float-right(
ng-click = "CPFC.actions.save()"
ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment"
ng-if = "CPFC.updating && !(CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired())"
ng-if = "CPFC.updating && !(CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())"
)
.spinner-wrapper.spinner-sm.spinner-white.in(
ng-include = "'spinner'"
Expand All @@ -146,7 +146,7 @@ footer.modal-footer.clearfix
button.btn.btn-md.green.float-right(
ng-click = "CPFC.actions.save()"
ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment"
ng-if = "!CPFC.updating && !(CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired())"
ng-if = "!CPFC.updating && !(CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())"
type = "button"
)
.spinner-wrapper.spinner-sm.spinner-white.in(
Expand All @@ -159,7 +159,7 @@ footer.modal-footer.clearfix
button.btn.btn-md.green.btn-block(
ng-click = "CPFC.actions.save()"
ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment"
ng-if = "CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired()"
ng-if = "!CPFC.updating && (CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())"
type = "button"
)
.spinner-wrapper.spinner-sm.spinner-white.in(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require('app')
function ChangePaymentFormController(
stripe,
loading,
$rootScope,
fetchPaymentMethod
fetchPaymentMethod,
currentOrg
) {
var CPFC = this;
CPFC.activeAccount = $rootScope.dataApp.data.activeAccount;
if (CPFC.activeAccount.isInTrial()) {
CPFC.currentOrg = currentOrg;
if (currentOrg.poppa.isInTrial()) {
loading('billingForm', true);
fetchPaymentMethod()
.then(function (paymentMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function changePaymentForm(
!$scope.paymentForm.$error.ccExp;
};
$scope.getBillingDate = function () {
return moment($scope.CPFC.activeAccount.attrs.activePeriodEnd).format('MMM Do, YYYY');
return moment($scope.CPFC.currentOrg.poppa.attrs.activePeriodEnd).format('MMM Do, YYYY');
};
}
};
Expand Down
Loading