Skip to content

Commit 0e799a6

Browse files
committed
Merge pull request #384 from CodeNow/ASAP-fix-multi-repo-commit
Fixing multi repo edit
2 parents 58fa456 + 4a2e524 commit 0e799a6

File tree

14 files changed

+236
-81
lines changed

14 files changed

+236
-81
lines changed

client/assets/styles/scss/modals/modals-sidebar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
transform: translate3d(0,0,0);
99
transition: transform .15s ease-in;
1010
width: 210px;
11+
height: 100%;
1112
z-index: $z-modal-sidebar;
1213

1314
.show-sidebar & {

client/controllers/instance/controllerInstance.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ function ControllerInstance(
1818
fetchUser
1919
) {
2020
var dataInstance = $scope.dataInstance = {
21-
data: {},
21+
data: {
22+
unsavedAcvs: []
23+
},
2224
actions: {}
2325
};
2426
var data = dataInstance.data;

client/controllers/instanceEdit/controllerInstanceEdit.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ function ControllerInstanceEdit(
2121
) {
2222

2323
var dataInstanceEdit = $scope.dataInstanceEdit = {
24-
data: {},
24+
data: {
25+
unsavedAcvs: []
26+
},
2527
actions: {}
2628
};
2729
var data = dataInstanceEdit.data;
@@ -77,29 +79,6 @@ function ControllerInstanceEdit(
7779
.go();
7880
}
7981

80-
// This is to fetch the list of instances. This is separate so the page can load quickly
81-
// since it will have its instance. Only the modals use this list
82-
function fetchInstances(cb) {
83-
new QueryAssist($scope.user, cb)
84-
.wrapFunc('fetchInstances', cb)
85-
.query({
86-
githubUsername: $stateParams.userName
87-
})
88-
.cacheFetch(function (instances, cached, cb) {
89-
if (!cached && instances.models.length === 0) {
90-
throw new Error('instance not found');
91-
}
92-
data.instances = instances;
93-
cb();
94-
})
95-
.resolve(function (err, instances, cb) {
96-
if (err) { return $log.error(err); }
97-
data.instances = instances;
98-
cb();
99-
})
100-
.go();
101-
}
102-
10382
// open "Dockerfile" build file by default
10483
function setDefaultTabs() {
10584
var rootDir = keypather.get($scope, 'build.contextVersions.models[0].rootDir');
@@ -128,7 +107,6 @@ function ControllerInstanceEdit(
128107
if (err) { return errs.handler(err); }
129108
if (redirect) { return; }
130109
setDefaultTabs();
131-
fetchInstances(angular.noop);
132110
});
133111

134112
}

client/controllers/setup/controllerSetup.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function ControllerSetup(
2525

2626
var dataSetup = $scope.dataSetup = {
2727
data: {
28-
instanceOpts: {}
28+
instanceOpts: {},
29+
unsavedAcvs: []
2930
},
3031
actions: {}
3132
};

client/directives/activePanel/directiveActivePanel.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,31 @@ function activePanel(
100100
}
101101
var updateFileDebounce = debounce(updateFile, 333);
102102

103+
104+
$scope.$watch('openItems.activeHistory.last().state.body', function (newVal, oldVal) {
105+
if (typeof newVal === 'string' &&
106+
$scope.openItems.activeHistory.last() &&
107+
$scope.openItems.activeHistory.last().id() === $scope.thisFileId) {
108+
if ($scope.update) {
109+
updateFileDebounce();
110+
}
111+
}
112+
});
113+
103114
function fetchFile() {
104115
var openItems = $scope.openItems;
105116
var last = openItems.activeHistory.last();
117+
$scope.thisFileId = last.id();
106118
if (openItems.isFile(last)) {
107119
last.fetch(function () {
108120
last.state.reset();
109121
});
110122
}
111123
}
112124

113-
$scope.$watch('openItems.activeHistory.last().state.body', function (newVal, oldVal) {
114-
if (typeof newVal === 'string' && $scope.openItems.activeHistory.last()) {
115-
if ($scope.update) {
116-
updateFileDebounce();
117-
}
118-
}
119-
});
120-
121-
$scope.$watch('openItems.activeHistory.last().id()', function (newVal, oldVal) {
125+
var openFileWatch = $scope.$watch('openItems.activeHistory.last().id()', function (newVal, oldVal) {
122126
if (newVal) {
127+
openFileWatch();
123128
if (!$scope.update) {
124129
var file = $scope.openItems.activeHistory.last();
125130
if (!(file.state && (typeof file.state.body === 'string'))) {

client/directives/instanceEditPrimaryActions/directiveInstanceEditPrimaryActions.js

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function instanceEditPrimaryActions(
88
QueryAssist,
99
$rootScope,
1010
$state,
11+
errs,
1112
$stateParams
1213
) {
1314
return {
@@ -17,7 +18,8 @@ function instanceEditPrimaryActions(
1718
user: '=',
1819
instance: '=',
1920
loading: '=',
20-
openItems: '='
21+
openItems: '=',
22+
unsavedAcvs: '='
2123
},
2224
link: function ($scope, elem, attrs) {
2325
// prevent multiple clicks
@@ -48,31 +50,34 @@ function instanceEditPrimaryActions(
4850
}
4951
}, cb);
5052
},
53+
updateAppCodeVersions,
5154
function () {
5255
var build = $scope.newBuild;
5356
// Catch the update file error
5457
$scope.newBuild.build(
5558
buildObj,
5659
function (err) {
57-
if (err) { throw err; }
60+
if (err) {
61+
return handleError(err);
62+
}
5863
var opts = {
5964
build: build.id()
6065
};
6166
if ($scope.instance.state && $scope.instance.state.env) {
6267
opts.env = $scope.instance.state.env;
6368
}
6469
$scope.instance.update(opts, function (err) {
65-
if (err) { throw err; }
70+
if (err) {
71+
return handleError(err);
72+
}
6673
// will trigger display of completed message if build completes
6774
// before reaching next state
6875
// $scope.dataInstanceLayout.data.showBuildCompleted = true;
6976
$state.go('instance.instance', $stateParams);
7077
});
7178
});
7279
}
73-
], function (err) {
74-
if (err) { throw err; }
75-
});
80+
], handleError);
7681
});
7782
};
7883

@@ -97,12 +102,63 @@ function instanceEditPrimaryActions(
97102
$scope.newBuild = build;
98103
cb();
99104
})
100-
.resolve(function (err) {
101-
if (err) { throw err; }
102-
})
105+
.resolve(handleError)
103106
.go();
104107
}
105108

109+
function updateAppCodeVersions(cb) {
110+
var modifiedAcvs = $scope.unsavedAcvs.filter(function (obj) {
111+
return obj.unsavedAcv.attrs.commit !== obj.acv.attrs.commit;
112+
});
113+
if (!modifiedAcvs.length) {
114+
return cb();
115+
}
116+
117+
var context = $scope.newBuild.contexts.models[0];
118+
var contextVersion = $scope.newBuild.contextVersions.models[0];
119+
var infraCodeVersionId = contextVersion.attrs.infraCodeVersion;
120+
121+
var appCodeVersionStates = $scope.unsavedAcvs.map(function (obj) {
122+
var acv = obj.unsavedAcv;
123+
return {
124+
repo: acv.attrs.repo,
125+
branch: acv.attrs.branch,
126+
commit: acv.attrs.commit
127+
};
128+
});
129+
async.waterfall([
130+
createContextVersion,
131+
createBuild
132+
], cb);
133+
134+
function createContextVersion(cb) {
135+
var body = {
136+
infraCodeVersion: infraCodeVersionId
137+
};
138+
var newContextVersion = context.createVersion(body, function (err) {
139+
async.each(appCodeVersionStates, function (acvState, cb) {
140+
newContextVersion.appCodeVersions.create(acvState, cb);
141+
}, function (err) {
142+
cb(err, newContextVersion);
143+
});
144+
});
145+
}
146+
function createBuild(contextVersion, cb) {
147+
var build = $scope.user.createBuild({
148+
contextVersions: [contextVersion.id()],
149+
owner: $scope.instance.attrs.owner
150+
}, function (err) {
151+
$scope.newBuild = build;
152+
cb(err, build);
153+
});
154+
}
155+
}
156+
function handleError(err) {
157+
if (err) {
158+
$scope.loading = false;
159+
errs.handler(err);
160+
}
161+
}
106162
}
107163
};
108164
}

client/directives/repoList/directiveRepoList.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function repoList(
1717
restrict: 'A',
1818
templateUrl: 'viewRepoList',
1919
scope: {
20-
loading: '='
20+
loading: '=',
21+
unsavedAcvs: '='
2122
},
2223
link: function ($scope, elem) {
2324

@@ -43,10 +44,12 @@ function repoList(
4344

4445
// track all temp acvs generated
4546
// for each repo/child-scope
46-
$scope.unsavedAcvs = [];
4747
$scope.newUnsavedAcv = function (acv) {
4848
var cv = $scope.build.contextVersions.models[0];
49-
var newAcv = cv.newAppCodeVersion(acv.toJSON(), {
49+
var acvJson = acv.toJSON();
50+
delete acvJson._id;
51+
delete acvJson.id;
52+
var newAcv = cv.newAppCodeVersion(acvJson, {
5053
warn: false
5154
});
5255
$scope.unsavedAcvs.push({
@@ -109,25 +112,14 @@ function repoList(
109112
// if we find this contextVersion, reuse it.
110113
// otherwise create a new one
111114
function findOrCreateContextVersion(cb) {
112-
var foundCVs = context.fetchVersions({
113-
infraCodeVersion: infraCodeVersionId,
114-
appCodeVersions: appCodeVersionStates
115-
}, function (err) {
116-
if (err) {
117-
return cb(err);
118-
}
119-
if (foundCVs.models.length) {
120-
return cb(null, foundCVs.models[0]);
121-
}
122-
var body = {
123-
infraCodeVersion: infraCodeVersionId
124-
};
125-
var newContextVersion = context.createVersion(body, function (err) {
126-
async.each(appCodeVersionStates, function (acvState, cb) {
127-
newContextVersion.appCodeVersions.create(acvState, cb);
128-
}, function (err) {
129-
cb(err, newContextVersion);
130-
});
115+
var body = {
116+
infraCodeVersion: infraCodeVersionId
117+
};
118+
var newContextVersion = context.createVersion(body, function (err) {
119+
async.each(appCodeVersionStates, function (acvState, cb) {
120+
newContextVersion.appCodeVersions.create(acvState, cb);
121+
}, function (err) {
122+
cb(err, newContextVersion);
131123
});
132124
});
133125
}

client/templates/instance/viewInstance.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ section.sidebar.box-sidebar.load
3939

4040
section.row.repo-list(
4141
repo-list
42+
unsaved-acvs = "dataInstance.data.unsavedAcvs"
4243
loading = "dataApp.data.loading"
4344
)
4445

client/templates/instanceEdit/viewInstanceEdit.jade

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ header.box-header
77
instance-edit-primary-actions(
88
user = "user"
99
instance = "dataInstanceEdit.data.instance"
10+
unsaved-acvs = "dataInstanceEdit.data.unsavedAcvs"
1011
loading = "dataApp.data.loading"
1112
open-items = "dataInstanceEdit.data.openItems"
1213
)
@@ -22,6 +23,7 @@ section.sidebar.box-sidebar
2223

2324
section.row.repo-list(
2425
repo-list
26+
unsaved-acvs = "dataInstanceEdit.data.unsavedAcvs"
2527
)
2628

2729
docker-validation(

client/templates/setup/viewSetup.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ section.sidebar.box-sidebar
2727

2828
section.row.repo-list(
2929
repo-list
30+
unsaved-acvs = "dataSetup.data.unsavedAcvs"
3031
)
3132

3233
docker-templates(

0 commit comments

Comments
 (0)