Skip to content

Commit fad415a

Browse files
committed
Fix stack selector for all views
1 parent 43a1780 commit fad415a

File tree

8 files changed

+337
-15
lines changed

8 files changed

+337
-15
lines changed

client/directives/components/serverModalButtons/serverModalButtonsDirective.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ function serverModalButtonsDirective(
1818
},
1919
link: function ($scope) {
2020
$scope.showSaveAndBuild = function () {
21-
return (!$scope.SMC.instance && $scope.SMC.state.step < 4) || ($scope.SMC.isDirty() === 'build' && !$rootScope.isLoading[$scope.SMC.name]);
21+
return (
22+
(!$scope.SMC.instance && $scope.SMC.isMirroingDockerfile) ||
23+
(!$scope.SMC.instance && $scope.SMC.state.step < 4) ||
24+
($scope.SMC.isDirty() === 'build' && !$rootScope.isLoading[$scope.SMC.name])
25+
);
2226
};
2327
$scope.createServerOrUpdate = function () {
2428
if ($scope.isPrimaryButtonDisabled()) {

client/directives/components/serverModalButtons/serverModalButtonsView.jade

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
button.btn.btn-md.gray.btn-cancel.float-left.js-animate(
22
ng-click = "SMC.actions.close()"
3-
ng-if = "!SMC.instance && SMC.state.step < 4"
3+
ng-if = "!SMC.instance"
44
type = "button"
55
) Cancel
66

@@ -9,14 +9,14 @@ button.btn.btn-md.btn-done.white.float-right(
99
'js-animate': SMC.state.step > 3\
1010
}"
1111
ng-click = "SMC.actions.close()"
12-
ng-if = "SMC.instance || SMC.state.step > 3"
12+
ng-if = "SMC.instance"
1313
type = "button"
1414
) Done
1515

1616
button.btn.btn-md.btn-primary.white.text-next.float-right(
1717
ng-click = "SMC.goToNextStep()"
1818
ng-disabled = "isPrimaryButtonDisabled()"
19-
ng-if = "SMC.state.step < 3"
19+
ng-if = "SMC.state.step && SMC.state.step < 3"
2020
type = "button"
2121
)
2222
span.btn-text.float-left Next
@@ -40,7 +40,7 @@ button.btn.btn-md.white.btn-primary.float-right.js-animate(
4040
}"
4141
ng-click = "thisForm.$invalid || createServerOrUpdate()"
4242
ng-disabled = "(SMC.needToBeDirtyToSaved() && !SMC.isDirty()) || isPrimaryButtonDisabled()"
43-
ng-if = "SMC.instance || SMC.state.step > 2"
43+
ng-if = "SMC.instance || SMC.isTabVisible('buildfiles')"
4444
type = "submit"
4545
)
4646
span.btn-text.float-left Save

client/directives/environment/modals/forms/formStack/stackSelectorFormDirective.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function stackSelectorForm(
1919
scope: {
2020
loadingPromisesTarget: '@?',
2121
state: '=',
22+
showStackSelector: '=',
2223
isNewContainer: '=?'
2324
},
2425
link: function ($scope) {

client/directives/environment/modals/forms/formStack/viewFormStack.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.label.clearfix(
2+
ng-if = "showStackSelector"
23
ng-include = "'viewFormStackSelector'"
34
)
45

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.modal-backdrop.in
2+
form.modal-dialog.modal-edit(
3+
name = "SMC.serverForm"
4+
ng-include = "'serverModalView'"
5+
ng-class = "{\
6+
'ace-active': (SMC.selectedTab === 'buildfiles' || SMC.selectedTab === 'env'),\
7+
'disabled': $root.isLoading[SMC.name] || $root.isLoading[SMC.name + 'IsBuilding'],\
8+
'xl': (SMC.selectedTab === 'buildfiles' || SMC.selectedTab === 'env' || SMC.selectedTab === 'logs')\
9+
}"
10+
)
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
'use strict';
2+
3+
require('app')
4+
.controller('SetupMirrorServerModalController', SetupMirrorServerModalController);
5+
6+
var tabVisibility = {
7+
buildfiles: { advanced: true, mirror: true },
8+
repository: { advanced: true, mirror: true },
9+
whitelist: { advanced: true, mirror: 3, featureFlagName: 'whitelist' },
10+
ports: { advanced: false, mirror: false },
11+
env: { advanced: true, mirror: true },
12+
translation: { advanced: true, mirror: false },
13+
logs: { advanced: true, mirror: false },
14+
};
15+
16+
function SetupMirrorServerModalController(
17+
$scope,
18+
$controller,
19+
$q,
20+
$rootScope,
21+
createAndBuildNewContainer,
22+
createBuildFromContextVersionId,
23+
errs,
24+
eventTracking,
25+
fetchUser,
26+
helpCards,
27+
keypather,
28+
loading,
29+
loadingPromises,
30+
promisify,
31+
cardInfoTypes,
32+
OpenItems,
33+
close,
34+
repo,
35+
build,
36+
masterBranch
37+
) {
38+
var SMC = this; // Server Modal Controller (shared with EditServerModalController)
39+
window.SMC = SMC;
40+
SMC.helpCards = helpCards;
41+
42+
var parentController = $controller('ServerModalController as SMC', { $scope: $scope });
43+
angular.extend(SMC, {
44+
'closeWithConfirmation': parentController.closeWithConfirmation.bind(SMC),
45+
'changeTab': parentController.changeTab.bind(SMC),
46+
'insertHostName': parentController.insertHostName.bind(SMC),
47+
'isDirty': parentController.isDirty.bind(SMC),
48+
'getNumberOfOpenTabs': parentController.getNumberOfOpenTabs.bind(SMC),
49+
'getUpdatePromise': parentController.getUpdatePromise.bind(SMC),
50+
'openDockerfile': parentController.openDockerfile.bind(SMC),
51+
'populateStateFromData': parentController.populateStateFromData.bind(SMC),
52+
'rebuildAndOrRedeploy': parentController.rebuildAndOrRedeploy.bind(SMC),
53+
'requiresRebuild': parentController.requiresRebuild.bind(SMC),
54+
'requiresRedeploy': parentController.requiresRedeploy.bind(SMC),
55+
'resetStateContextVersion': parentController.resetStateContextVersion.bind(SMC),
56+
'saveInstanceAndRefreshCards': parentController.saveInstanceAndRefreshCards.bind(SMC),
57+
'updateInstanceAndReset': parentController.updateInstanceAndReset.bind(SMC)
58+
});
59+
60+
var mainRepoContainerFile = new cardInfoTypes.MainRepository();
61+
// Set initial state
62+
angular.extend(SMC, {
63+
name: 'setupServerModal',
64+
isLoading: $rootScope.isLoading,
65+
portsSet: false,
66+
isNewContainer: true,
67+
openItems: new OpenItems(),
68+
getDisplayName: function () {
69+
if (SMC.instance) {
70+
return SMC.instance.getDisplayName();
71+
}
72+
return SMC.state.repo.attrs.name;
73+
},
74+
getElasticHostname: function () {
75+
if (keypather.get(SMC, 'state.repo.attrs')) {
76+
// NOTE: Is SMC the best way to get the hostname?
77+
var repo = SMC.state.repo;
78+
var repoName = repo.attrs.name;
79+
var repoOwner = repo.attrs.owner.login.toLowerCase();
80+
var domain = SMC.state.repo.opts.userContentDomain;
81+
// NOTE: How can I know whether it will be staging or not?
82+
var hostname = repoName + '-staging-' + repoOwner + '.' + domain;
83+
return hostname;
84+
}
85+
return '';
86+
},
87+
state: {
88+
advanced: false,
89+
containerFiles: [
90+
mainRepoContainerFile
91+
],
92+
mainRepoContainerFile: mainRepoContainerFile,
93+
ports: [],
94+
packages: new cardInfoTypes.Packages(),
95+
promises: {},
96+
opts: {
97+
masterPod: true,
98+
name: '',
99+
env: [],
100+
ipWhitelist: {
101+
enabled: false
102+
}
103+
},
104+
whitelist: [
105+
{address: ['1.1.1.1', '1.1.1.10'], description: ''},
106+
{address: ['1.1.1.3'], description: 'Test'},
107+
{address: ['1.1.1.9'], description: 'Runnable'},
108+
{address: ['1.1.1.4', '1.1.1.5'], description: ''}
109+
]
110+
},
111+
actions: {
112+
close: SMC.closeWithConfirmation.bind(SMC, close)
113+
},
114+
data: {},
115+
selectedTab: 'buildfiles'
116+
});
117+
loading.reset(SMC.name);
118+
loadingPromises.clear(SMC.name);
119+
loading.reset(SMC.name + 'IsBuilding');
120+
121+
if (!(repo && build && masterBranch)) {
122+
throw new Error('Repo, build and masterBranch are needed');
123+
}
124+
125+
// If a repo is passed into this controller, select that repo
126+
angular.extend(SMC.state, {
127+
repo: repo,
128+
build: build,
129+
contextVersion: build.contextVersion,
130+
acv: build.contextVersion.getMainAppCodeVersion(),
131+
branch: masterBranch,
132+
repoSelected: true,
133+
advanced: false
134+
});
135+
SMC.state.mainRepoContainerFile.name = repo.attrs.name;
136+
SMC.state.opts.name = normalizeRepoName(repo);
137+
SMC.state.promises.contextVersion = $q.when(SMC.state.contextVersion);
138+
SMC.state.isMirroingDockerfile = true;
139+
var fullpath = keypather.get(SMC, 'state.build.contextVersion.attrs.buildDockerfilePath');
140+
// Get everything before the last '/' and add a '/' at the end
141+
var path = fullpath.replace(/^(.*)\/.*$/, '$1') + '/';
142+
// Get everything after the last '/'
143+
var name = fullpath.replace(/^.*\/(.*)$/, '$1');
144+
fetchUser()
145+
.then(function (user) {
146+
// TODO: Match with dockefile path
147+
SMC.state.dockerfile = SMC.state.contextVersion.newFile({
148+
_id: repo.dockerfiles[0].sha,
149+
id: repo.dockerfiles[0].sha,
150+
body: atob(repo.dockerfiles[0].content),
151+
name: name,
152+
path: path
153+
});
154+
SMC.openItems.add(SMC.state.dockerfile);
155+
});
156+
157+
$scope.$on('resetStateContextVersion', function ($event, contextVersion, showSpinner) {
158+
$event.stopPropagation();
159+
if (showSpinner) {
160+
loading(SMC.name, true);
161+
}
162+
SMC.resetStateContextVersion(contextVersion, showSpinner)
163+
.catch(errs.handler)
164+
.finally(function () {
165+
if (showSpinner) {
166+
loading(SMC.name, false);
167+
}
168+
});
169+
});
170+
171+
function normalizeRepoName(repo) {
172+
return repo.attrs.name.replace(/[^a-zA-Z0-9-]/g, '-');
173+
}
174+
175+
SMC.showStackSelector = function () {
176+
return false;
177+
};
178+
179+
SMC.rebuild = function (noCache, forceRebuild) {
180+
loading(SMC.name, true);
181+
return SMC.rebuildAndOrRedeploy(noCache, forceRebuild)
182+
.then(function () {
183+
return SMC.resetStateContextVersion(SMC.instance.contextVersion, true);
184+
})
185+
.then(function (contextVersion) {
186+
return contextVersion;
187+
})
188+
.catch(errs.handler)
189+
.finally(function () {
190+
loading(SMC.name, false);
191+
});
192+
};
193+
194+
SMC.createServer = function () {
195+
// Wait until all changes to the context version have been resolved before
196+
// creating a build with that context version
197+
return loadingPromises.finished(SMC.name)
198+
.then(function () {
199+
console.log('1');
200+
if (SMC.state.acv.attrs.branch !== SMC.state.branch.attrs.name) {
201+
return promisify(SMC.state.acv, 'update')({
202+
repo: SMC.state.repo.attrs.full_name,
203+
branch: SMC.state.branch.attrs.name,
204+
commit: SMC.state.branch.attrs.commit.sha
205+
});
206+
}
207+
})
208+
.then(function () {
209+
return promisify(SMC.state.build, 'build')({
210+
message: 'Initial Build'
211+
});
212+
})
213+
.then(function (build) {
214+
console.log('2', build);
215+
console.log('.', keypather.get(build, 'contextVersion'));
216+
console.log('.', keypather.get(build, 'contextVersion.attrs.build'));
217+
console.log('.', keypather.get(build, 'contextVersion.attrs.build.started'));
218+
var opts = {
219+
masterPod: true,
220+
name: SMC.state.name,
221+
build: build.id(),
222+
owner: {
223+
github: $rootScope.dataApp.data.activeAccount.oauthId()
224+
},
225+
env: [],
226+
ipWhitelist: {
227+
enabled: false
228+
}
229+
};
230+
return fetchUser().then(function (user) {
231+
console.log('createNewInstance 3.2', opts);
232+
return promisify(user, 'createInstance')(opts);
233+
});
234+
235+
})
236+
.then(function instanceSetHandler (instance) {
237+
console.log('2.5');
238+
if (instance) {
239+
SMC.instance = instance;
240+
SMC.state.instance = instance;
241+
// Reset the opts, in the same way as `EditServerModalController`
242+
SMC.state.opts = {
243+
env: keypather.get(instance, 'attrs.env') || [],
244+
ipWhitelist: angular.copy(keypather.get(instance, 'attrs.ipWhitelist')) || {
245+
enabled: false
246+
}
247+
};
248+
return instance;
249+
}
250+
return $q.reject(new Error('Instance not created properly'));
251+
})
252+
.then(function () {
253+
console.log('3');
254+
eventTracking.createdRepoContainer(SMC.instance.attrs.owner.github, SMC.state.repo.attrs.name);
255+
return SMC.resetStateContextVersion(SMC.instance.contextVersion, true);
256+
})
257+
.catch(function (err) {
258+
// If creating the server fails, reset the context version
259+
return SMC.resetStateContextVersion(SMC.state.contextVersion, false)
260+
.then(function () {
261+
// Since we failed to build, we need loading promises to have something in it
262+
loadingPromises.add(SMC.name, $q.when(true));
263+
return $q.reject(err);
264+
});
265+
});
266+
};
267+
268+
/**
269+
* This function determines if a tab chooser should be shown
270+
*
271+
* @param tabname
272+
* @returns {Boolean}
273+
*/
274+
SMC.isTabVisible = function (tabName) {
275+
if (!tabVisibility[tabName]) {
276+
return false;
277+
}
278+
if (tabVisibility[tabName].featureFlagName && !$rootScope.featureFlags[tabVisibility[tabName].featureFlagName]) {
279+
return false;
280+
}
281+
if (SMC.state.isMirroingDockerfile) {
282+
return tabVisibility[tabName].mirror;
283+
}
284+
if (SMC.state.sadvanced) {
285+
return tabVisibility[tabName].advanced;
286+
}
287+
return false;
288+
};
289+
290+
SMC.isPrimaryButtonDisabled = function (serverFormInvalid) {
291+
return SMC.repositoryForm && SMC.repositoryForm.$invalid;
292+
};
293+
294+
SMC.needToBeDirtyToSaved = function () {
295+
if (!SMC.instance) {
296+
return false;
297+
}
298+
return true;
299+
};
300+
301+
}

client/directives/environment/modals/modalSetupServer/setupServerModalController.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ function SetupServerModalController(
433433
return true;
434434
};
435435

436+
SMC.showStackSelector = function () {
437+
return !SMC.state.advanced;
438+
};
439+
436440
// TODO: Remove code when removing `dockerFileMirroing` code
437441
SMC.selectRepo = function (repo) {
438442
if (SMC.repoSelected || repo.isAdded) { return; }

0 commit comments

Comments
 (0)