-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenvironmentController.js
More file actions
executable file
·171 lines (157 loc) · 4.41 KB
/
environmentController.js
File metadata and controls
executable file
·171 lines (157 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
require('app')
.controller('EnvironmentController', EnvironmentController);
/**
* EnvironmentController
* @constructor
* @export
* @ngInject
*/
function EnvironmentController(
$q,
$rootScope,
$scope,
$state,
$timeout,
ahaGuide,
currentOrg,
favico,
fetchDockerfileForContextVersion,
fetchOrgMembers,
fetchUser,
instancesByPod,
keypather,
ModalService,
pageName
) {
var EC = this;
EC.isAddingFirstRepo = ahaGuide.isAddingFirstRepo;
EC.isInGuide = ahaGuide.isInGuide;
EC.isPersonalAccount = keypather.get(currentOrg, 'poppa.attrs.isPersonalAccount');
EC.showInviteButton = EC.isPersonalAccount;
EC.showCreateTemplate = true;
EC.getClassForSubstep = ahaGuide.getClassForSubstep;
$scope.$on('ahaGuideEvent', function(event, info) {
if (info.isClear) {
EC.errorState = null;
} else {
EC.errorState = info.error;
}
});
var unbindUpdateTeammateInvitation = $rootScope.$on('updateTeammateInvitations', function (event, invitesCreated) {
if (invitesCreated) {
updateShowInviteButton();
}
});
$scope.$on('$destroy', unbindUpdateTeammateInvitation);
function updateShowInviteButton() {
return $q.all({
user: fetchUser(),
members: fetchOrgMembers($state.params.userName)
})
.then(function (res) {
var username = keypather.get(res.user, 'attrs.accounts.github.username');
var isOrg = (username !== $state.params.userName);
EC.showInviteButton = isOrg && res.members.uninvited.length > 0 || EC.isPersonalAccount;
EC.orgMembers = res.members;
});
}
// On init, determine whether to show invites
updateShowInviteButton();
EC.triggerModal = {
newContainer: function () {
$rootScope.$broadcast('close-popovers');
return ModalService.showModal({
controller: 'NewContainerModalController',
controllerAs: 'MC', // Shared
templateUrl: 'newContainerModalView'
});
},
inviteTeammate: function () {
return ModalService.showModal({
controller: 'InviteModalController',
controllerAs: 'IMC',
templateUrl: 'inviteModalView',
inputs: {
teamName: $state.params.userName,
unInvitedMembers: null,
isPersonalAccount: EC.isPersonalAccount,
orgMembers: EC.orgMembers
}
});
}
};
$scope.$state = $state;
favico.reset();
pageName.setTitle('Configure - Runnable');
$scope.data = { };
$scope.data.instances = instancesByPod;
var isAddFirstRepo = ahaGuide.isAddingFirstRepo();
if (isAddFirstRepo && instancesByPod.models.length === 0) {
$rootScope.$broadcast('ahaGuide::launchModal');
}
// Asynchronously fetch the Dockerfile and check for working instances
instancesByPod.forEach(function (instance) {
if (instance.hasDockerfileMirroring()) {
return fetchDockerfileForContextVersion(instance.contextVersion)
.then(function (dockerfile) {
instance.mirroredDockerfile = dockerfile;
});
}
// Differentiate between non-fetched and non-existing
instance.mirroredDockerfile = null;
});
$scope.state = {
validation: {
env: {}
},
newServerButton: {
active: false
}
};
EC.alert = null;
$scope.$on('alert', function (evt, data) {
EC.alert = data;
var timeoutDelay = 5000;
if (data.newPlan) {
if (keypather.get(currentOrg, 'poppa.attrs.hasPaymentMethod')) {
timeoutDelay *= 2;
} else {
EC.alert.newPlan = null;
}
}
$timeout(function () {
EC.actions.closeAlert();
}, timeoutDelay);
});
EC.actions = {
closeAlert: function () {
EC.alert = null;
},
goToBilling: function () {
EC.actions.closeAlert();
ModalService.showModal({
controller: 'SettingsModalController',
controllerAs: 'SEMC',
templateUrl: 'settingsModalView',
inputs: {
tab: 'billing',
subTab: 'billingForm'
}
});
},
endGuide: ahaGuide.endGuide
};
if (ahaGuide.isInGuide()) {
if (keypather.get(instancesByPod, 'models.length')) {
if (instancesByPod.models.some(function (instance) {
return instance.attrs.hasAddedBranches || keypather.get(instance, 'children.models.length');
})) {
// timeout for the animation
$timeout(function () {
$rootScope.$broadcast('ahaGuide::launchModal');
});
}
}
}
}