Skip to content

Commit

Permalink
Merge pull request #520 from webgme/Bugs/projectNav_selection_and_cre…
Browse files Browse the repository at this point in the history
…ation

Project creation/selection bugs/improvemnts, closes #519, #516, #513
  • Loading branch information
Zsolt Lattmann committed Aug 31, 2015
2 parents 827fe8a + 933ba53 commit 2e77299
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 21 deletions.
41 changes: 31 additions & 10 deletions src/client/js/Panels/Header/ProjectNavigatorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,37 @@ define([
self.gmeClient.watchDatabase(function (emitter, data) {
self.logger.debug('watchDatabase event', data);
if (data.etype === CONSTANTS.CLIENT.STORAGE.PROJECT_CREATED) {
//TODO: This call should get the rights..
self.gmeClient.getBranches(data.projectId, function (err, branches) {
if (err) {
self.logger.error('Could not get branches for newlycreated project ' + data.projectId);
self.logger.error(err);
} else {
self.addProject(data.projectId); //TODO: Should include rights..

Object.keys(branches).map(function (branchId) {
self.addBranch(data.projectId, branchId);
});
if (err.message.indexOf('Not authorized to read project') > -1) {
// This is anticipated when someone else created the project.
self.logger.debug(err.message);
} else {
self.logger.error('Could not get branches for newly created project ' +
data.projectId);
self.logger.error(err);
}
return;
}
self.logger.debug('Got branches before joining room:', Object.keys(branches));
//TODO: Should include rights, for now complete rights are assumed.
self.addProject(data.projectId, null, true, function (err) {
if (err) {
self.logger.error(err);
return;
}
self.gmeClient.getBranches(data.projectId, function (err, branches) {
if (err) {
self.logger.error(err);
return;
}
self.logger.debug('Got branches after joining room:', Object.keys(branches));
Object.keys(branches).map(function (branchId) {
self.addBranch(data.projectId, branchId);
});
});
});
});
} else if (data.etype === CONSTANTS.CLIENT.STORAGE.PROJECT_DELETED) {
self.removeProject(data.projectId);
Expand Down Expand Up @@ -342,7 +362,7 @@ define([
});
};

ProjectNavigatorController.prototype.addProject = function (projectId, rights, noUpdate) {
ProjectNavigatorController.prototype.addProject = function (projectId, rights, noUpdate, callback) {
var self = this,
i,
showHistory,
Expand Down Expand Up @@ -573,9 +593,10 @@ define([
};

if (self.gmeClient) {
self.gmeClient.watchProject(projectId, self.projects[projectId]._watcher);
self.gmeClient.watchProject(projectId, self.projects[projectId]._watcher, callback);
} else {
self.dummyBranchGenerator('Branch', 10, projectId);
callback(null);
}

for (i = 0; i < self.root.menu.length; i += 1) {
Expand Down
61 changes: 50 additions & 11 deletions src/client/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ define([
}
};

/**
* If branchName is given and it does not exist, the project will be closed and callback resolved with an error.
* If branchName NOT given it will attempt the following in order and break if successful at any step:
* 1) Select the master if available.
* 2) Select any available branch.
* 3) Select the latest commit.
* 4) Close the project and resolve with error.
* @param {string} projectId
* @param {string} [branchName='master']
* @param {function} callback
*/
this.selectProject = function (projectId, branchName, callback) {
if (callback === undefined && typeof branchName === 'function') {
callback = branchName;
Expand Down Expand Up @@ -362,17 +373,45 @@ define([
logger.debug('Picked "' + branchToOpen + '".');
}

ASSERT(branchToOpen, 'No branch available in project');

self.selectBranch(branchToOpen, null, function (err) {
if (err) {
callback(err);
return;
}
logState('info', 'selectBranch');
reLaunchUsers();
callback(null);
});
if (branchToOpen) {
self.selectBranch(branchToOpen, null, function (err) {
if (err) {
callback(err);
return;
}
logState('info', 'selectBranch');
reLaunchUsers();
callback(null);
});
} else {
logger.warn('No branches available in project, will attempt to select latest commit.');
self.getCommits(projectId, (new Date()).getTime(), 1, function (err, commitObjects) {
if (err || commitObjects.length === 0) {
logger.error(err);
closeProject(projectId, function (err) {
if (err) {
logger.error('closeProject after missing any commits failed with err', err);
}
callback(new Error('Project does not have any commits.'));
});
return;
}
self.selectCommit(commitObjects[0]._id, function (err) {
if (err) {
logger.error(err);
closeProject(projectId, function (err) {
if (err) {
logger.error('closeProject after missing any commits failed with err', err);
}
callback(new Error('Failed selecting commit when opening project.'));
});
return;
}
reLaunchUsers();
callback(null);
});
});
}
}

if (state.project) {
Expand Down

0 comments on commit 2e77299

Please sign in to comment.