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
1 change: 1 addition & 0 deletions client/assets/styles/scss/modals/modals-sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
transform: translate3d(0,0,0);
transition: transform .15s ease-in;
width: 210px;
height: 100%;
z-index: $z-modal-sidebar;

.show-sidebar & {
Expand Down
4 changes: 3 additions & 1 deletion client/controllers/instance/controllerInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function ControllerInstance(
fetchUser
) {
var dataInstance = $scope.dataInstance = {
data: {},
data: {
unsavedAcvs: []
},
actions: {}
};
var data = dataInstance.data;
Expand Down
28 changes: 3 additions & 25 deletions client/controllers/instanceEdit/controllerInstanceEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function ControllerInstanceEdit(
) {

var dataInstanceEdit = $scope.dataInstanceEdit = {
data: {},
data: {
unsavedAcvs: []
},
actions: {}
};
var data = dataInstanceEdit.data;
Expand Down Expand Up @@ -77,29 +79,6 @@ function ControllerInstanceEdit(
.go();
}

// This is to fetch the list of instances. This is separate so the page can load quickly
// since it will have its instance. Only the modals use this list
function fetchInstances(cb) {
new QueryAssist($scope.user, cb)
.wrapFunc('fetchInstances', cb)
.query({
githubUsername: $stateParams.userName
})
.cacheFetch(function (instances, cached, cb) {
if (!cached && instances.models.length === 0) {
throw new Error('instance not found');
}
data.instances = instances;
cb();
})
.resolve(function (err, instances, cb) {
if (err) { return $log.error(err); }
data.instances = instances;
cb();
})
.go();
}

// open "Dockerfile" build file by default
function setDefaultTabs() {
var rootDir = keypather.get($scope, 'build.contextVersions.models[0].rootDir');
Expand Down Expand Up @@ -128,7 +107,6 @@ function ControllerInstanceEdit(
if (err) { return errs.handler(err); }
if (redirect) { return; }
setDefaultTabs();
fetchInstances(angular.noop);
});

}
3 changes: 2 additions & 1 deletion client/controllers/setup/controllerSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function ControllerSetup(

var dataSetup = $scope.dataSetup = {
data: {
instanceOpts: {}
instanceOpts: {},
unsavedAcvs: []
},
actions: {}
};
Expand Down
23 changes: 14 additions & 9 deletions client/directives/activePanel/directiveActivePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,31 @@ function activePanel(
}
var updateFileDebounce = debounce(updateFile, 333);


$scope.$watch('openItems.activeHistory.last().state.body', function (newVal, oldVal) {
if (typeof newVal === 'string' &&
$scope.openItems.activeHistory.last() &&
$scope.openItems.activeHistory.last().id() === $scope.thisFileId) {
if ($scope.update) {
updateFileDebounce();
}
}
});

function fetchFile() {
var openItems = $scope.openItems;
var last = openItems.activeHistory.last();
$scope.thisFileId = last.id();
if (openItems.isFile(last)) {
last.fetch(function () {
last.state.reset();
});
}
}

$scope.$watch('openItems.activeHistory.last().state.body', function (newVal, oldVal) {
if (typeof newVal === 'string' && $scope.openItems.activeHistory.last()) {
if ($scope.update) {
updateFileDebounce();
}
}
});

$scope.$watch('openItems.activeHistory.last().id()', function (newVal, oldVal) {
var openFileWatch = $scope.$watch('openItems.activeHistory.last().id()', function (newVal, oldVal) {
if (newVal) {
openFileWatch();
if (!$scope.update) {
var file = $scope.openItems.activeHistory.last();
if (!(file.state && (typeof file.state.body === 'string'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function instanceEditPrimaryActions(
QueryAssist,
$rootScope,
$state,
errs,
$stateParams
) {
return {
Expand All @@ -17,7 +18,8 @@ function instanceEditPrimaryActions(
user: '=',
instance: '=',
loading: '=',
openItems: '='
openItems: '=',
unsavedAcvs: '='
},
link: function ($scope, elem, attrs) {
// prevent multiple clicks
Expand Down Expand Up @@ -48,31 +50,34 @@ function instanceEditPrimaryActions(
}
}, cb);
},
updateAppCodeVersions,
function () {
var build = $scope.newBuild;
// Catch the update file error
$scope.newBuild.build(
buildObj,
function (err) {
if (err) { throw err; }
if (err) {
return handleError(err);
}
var opts = {
build: build.id()
};
if ($scope.instance.state && $scope.instance.state.env) {
opts.env = $scope.instance.state.env;
}
$scope.instance.update(opts, function (err) {
if (err) { throw err; }
if (err) {
return handleError(err);
}
// will trigger display of completed message if build completes
// before reaching next state
// $scope.dataInstanceLayout.data.showBuildCompleted = true;
$state.go('instance.instance', $stateParams);
});
});
}
], function (err) {
if (err) { throw err; }
});
], handleError);
});
};

Expand All @@ -97,12 +102,63 @@ function instanceEditPrimaryActions(
$scope.newBuild = build;
cb();
})
.resolve(function (err) {
if (err) { throw err; }
})
.resolve(handleError)
.go();
}

function updateAppCodeVersions(cb) {
var modifiedAcvs = $scope.unsavedAcvs.filter(function (obj) {
return obj.unsavedAcv.attrs.commit !== obj.acv.attrs.commit;
});
if (!modifiedAcvs.length) {
return cb();
}

var context = $scope.newBuild.contexts.models[0];
var contextVersion = $scope.newBuild.contextVersions.models[0];
var infraCodeVersionId = contextVersion.attrs.infraCodeVersion;

var appCodeVersionStates = $scope.unsavedAcvs.map(function (obj) {
var acv = obj.unsavedAcv;
return {
repo: acv.attrs.repo,
branch: acv.attrs.branch,
commit: acv.attrs.commit
};
});
async.waterfall([
createContextVersion,
createBuild
], cb);

function createContextVersion(cb) {
var body = {
infraCodeVersion: infraCodeVersionId
};
var newContextVersion = context.createVersion(body, function (err) {
async.each(appCodeVersionStates, function (acvState, cb) {
newContextVersion.appCodeVersions.create(acvState, cb);
}, function (err) {
cb(err, newContextVersion);
});
});
}
function createBuild(contextVersion, cb) {
var build = $scope.user.createBuild({
contextVersions: [contextVersion.id()],
owner: $scope.instance.attrs.owner
}, function (err) {
$scope.newBuild = build;
cb(err, build);
});
}
}
function handleError(err) {
if (err) {
$scope.loading = false;
errs.handler(err);
}
}
}
};
}
36 changes: 14 additions & 22 deletions client/directives/repoList/directiveRepoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function repoList(
restrict: 'A',
templateUrl: 'viewRepoList',
scope: {
loading: '='
loading: '=',
unsavedAcvs: '='
},
link: function ($scope, elem) {

Expand All @@ -43,10 +44,12 @@ function repoList(

// track all temp acvs generated
// for each repo/child-scope
$scope.unsavedAcvs = [];
$scope.newUnsavedAcv = function (acv) {
var cv = $scope.build.contextVersions.models[0];
var newAcv = cv.newAppCodeVersion(acv.toJSON(), {
var acvJson = acv.toJSON();
delete acvJson._id;
delete acvJson.id;
var newAcv = cv.newAppCodeVersion(acvJson, {
warn: false
});
$scope.unsavedAcvs.push({
Expand Down Expand Up @@ -109,25 +112,14 @@ function repoList(
// if we find this contextVersion, reuse it.
// otherwise create a new one
function findOrCreateContextVersion(cb) {
var foundCVs = context.fetchVersions({
infraCodeVersion: infraCodeVersionId,
appCodeVersions: appCodeVersionStates
}, function (err) {
if (err) {
return cb(err);
}
if (foundCVs.models.length) {
return cb(null, foundCVs.models[0]);
}
var body = {
infraCodeVersion: infraCodeVersionId
};
var newContextVersion = context.createVersion(body, function (err) {
async.each(appCodeVersionStates, function (acvState, cb) {
newContextVersion.appCodeVersions.create(acvState, cb);
}, function (err) {
cb(err, newContextVersion);
});
var body = {
infraCodeVersion: infraCodeVersionId
};
var newContextVersion = context.createVersion(body, function (err) {
async.each(appCodeVersionStates, function (acvState, cb) {
newContextVersion.appCodeVersions.create(acvState, cb);
}, function (err) {
cb(err, newContextVersion);
});
});
}
Expand Down
1 change: 1 addition & 0 deletions client/templates/instance/viewInstance.jade
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ section.sidebar.box-sidebar.load

section.row.repo-list(
repo-list
unsaved-acvs = "dataInstance.data.unsavedAcvs"
loading = "dataApp.data.loading"
)

Expand Down
2 changes: 2 additions & 0 deletions client/templates/instanceEdit/viewInstanceEdit.jade
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ header.box-header
instance-edit-primary-actions(
user = "user"
instance = "dataInstanceEdit.data.instance"
unsaved-acvs = "dataInstanceEdit.data.unsavedAcvs"
loading = "dataApp.data.loading"
open-items = "dataInstanceEdit.data.openItems"
)
Expand All @@ -22,6 +23,7 @@ section.sidebar.box-sidebar

section.row.repo-list(
repo-list
unsaved-acvs = "dataInstanceEdit.data.unsavedAcvs"
)

docker-validation(
Expand Down
1 change: 1 addition & 0 deletions client/templates/setup/viewSetup.jade
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ section.sidebar.box-sidebar

section.row.repo-list(
repo-list
unsaved-acvs = "dataSetup.data.unsavedAcvs"
)

docker-templates(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"_id": "544ad1004daca7552128f092",
"branch": "master",
"commit": "1f27c310a4bcca758f708358601fa25976d56d94",
"lowerBranch": "master",
"lowerRepo": "cflynn07/bitcoin",
"privateKey": "cflynn07/bitcoin.key",
"publicKey": "cflynn07/bitcoin.key.pub",
"repo": "cflynn07/bitcoin",
"id": "544ad1004daca7552128f09c"
}
3 changes: 2 additions & 1 deletion test/unit/apiMocks/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
appCodeVersions: {
bitcoinAppCodeVersion: require('./appCodeVersions/bitcoinAppCodeVersion')
bitcoinAppCodeVersion: require('./appCodeVersions/bitcoinAppCodeVersion'),
differentBitcoinAppCodeVersion: require('./appCodeVersions/differentBitcoinAppCodeVersion')
},
builds: {
setup: require('./builds/setup')
Expand Down
15 changes: 12 additions & 3 deletions test/unit/directives/directiveRepoList.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ describe('directiveRepoList'.bold.underline.blue, function () {
$httpBackend.whenGET(host + '/contexts/54398933f5afb6410069bc33/versions/54398934f5afb6410069bc34?')
.respond(mocks.contextVersions.setup);

var tpl = directiveTemplate.attribute('repo-list');
var tpl = directiveTemplate.attribute('repo-list', {
'unsaved-acvs': 'unsavedAcvs'
});
$scope.unsavedAcvs = [];

element = $compile(tpl)($scope);
$scope.$digest();
Expand Down Expand Up @@ -97,7 +100,10 @@ describe('directiveRepoList'.bold.underline.blue, function () {
.whenGET(compareUrl)
.respond(mocks.gh.compare);

var tpl = directiveTemplate.attribute('repo-list');
var tpl = directiveTemplate.attribute('repo-list', {
'unsaved-acvs': 'unsavedAcvs'
});
$scope.unsavedAcvs = [];

element = $compile(tpl)($scope);
$scope.$digest();
Expand Down Expand Up @@ -147,7 +153,10 @@ describe('directiveRepoList'.bold.underline.blue, function () {
.whenGET(compareUrl)
.respond(mocks.gh.compare);

var tpl = directiveTemplate.attribute('repo-list');
var tpl = directiveTemplate.attribute('repo-list', {
'unsaved-acvs': 'unsavedAcvs'
});
$scope.unsavedAcvs = [];

element = $compile(tpl)($scope);
$scope.$digest();
Expand Down
Loading