Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #203 from jfucci/master
Browse files Browse the repository at this point in the history
Multiple repository support
  • Loading branch information
agundy committed Oct 27, 2015
2 parents 2b70dca + 6fb9bdc commit ee6bb0e
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 40 deletions.
10 changes: 9 additions & 1 deletion client/app/projects/profile/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ <h1 ng-hide="edittingName">{{project.name}}</h1>
<div ng-show='isAdmin() && project.markedDefault' class="btn btn-success" ng-click='unmarkDefault()'>Unmark Default</div>
<div ng-show='isAdmin() && !project.markedDefault' class="btn btn-success" ng-click='markDefault()'>Mark Default</div>
<a class="btn btn-info" href="{{project.websiteUrl}}" title="">Website</a>
<a class="btn btn-info" href="{{project.repositoryUrl}}" title="">Repository</a>
<a class="btn btn-info" href="{{project.repositories[0]}}" title="" ng-show="project.repositories.length == 1">Repository <span class="glyphicon glyphicon-menu-right"></span></a>
<div class="btn-group" ng-show="project.repositories.length > 1">
<a class="btn btn-info dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Repositories <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="{{repo}}" ng-repeat="repo in project.repositories">{{repo}} <span class="glyphicon glyphicon-menu-right"></span></a></li>
</ul>
</div>
<a class="btn btn-info" href="/projects/{{project.githubUsername}}/{{project.githubProjectName}}/blog" title="">Blog</a>

</div>
Expand Down
6 changes: 5 additions & 1 deletion client/app/projects/profile/profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,8 @@ desc textarea{

#nameDiv {
margin-top: 30px
}
}

#repos {
display: block;
}
17 changes: 12 additions & 5 deletions client/app/projects/projects.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('observatory3App')

.controller('ProjectsCtrl', function ($scope, $location, $http, Auth) {
$scope.projects = [];
$scope.projectToAdd = {active: true};
$scope.projectToAdd = {active: true, repositories: [""]};
$scope.loggedIn = false;

Auth.isLoggedInAsync(function(loggedIn){
Expand All @@ -30,10 +30,8 @@ angular.module('observatory3App')
};

$scope.getInfo = function() {
if($scope.projectToAdd.repositoryUrl) {
var splitUrl = $scope.projectToAdd.repositoryUrl.split('/');
$scope.projectToAdd.githubUsername = splitUrl[splitUrl.length - 2];
$scope.projectToAdd.githubProjectName = $scope.projectToAdd.name = splitUrl[splitUrl.length - 1];
if($scope.projectToAdd.githubUsername && $scope.projectToAdd.githubProjectName) {
$scope.projectToAdd.name = $scope.projectToAdd.githubProjectName;
$.getJSON('https://api.github.com/repos/' + $scope.projectToAdd.githubUsername + '/' + $scope.projectToAdd.githubProjectName, function(response) {
$scope.projectToAdd.websiteURL = response.homepage;
$scope.projectToAdd.description = response.description;
Expand All @@ -42,11 +40,20 @@ angular.module('observatory3App')
}
};

$scope.addRepository = function() {
$scope.projectToAdd.repositories[$scope.projectToAdd.repositories.length] = "";
}

$scope.removeRepository = function(index) {
$scope.projectToAdd.repositories.splice(index, 1);
}

$scope.submit = function(form) {
$scope.submitted = true;

if(form.$valid) {
$scope.submitted = false;
$scope.projectToAdd.repositories[0] = "https://github.com/" + $scope.projectToAdd.githubUsername + "/" + $scope.projectToAdd.githubProjectName;
$('#addProject').modal('hide');
// use setTimeout because hiding the modal takes longer than the post request
// and results in the modal disappearing but the overlay staying if not used
Expand Down
66 changes: 41 additions & 25 deletions client/app/projects/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,39 @@ <h1> {{ past ? "Past" : "Current" }} RCOS Projects</h1>
<h4 class="modal-title" id="addProjectLabel">Add a Project</h4>
</div>
<div class="modal-body" >
<label>Your project's github URL</label>
<form ng-submit="getInfo()">
<input id="repositoryUrl" ng-model="projectToAdd.repositoryUrl" class="form-control" />
<button id="getInfo" type="submit" class="btn btn-default" >Auto-Complete</button>
</form>

<form class="form" name="addProjectForm" ng-submit="submit(addProjectForm)" novalidate>
<label>Your project's github repository</label>
<div class="input-group">
<span class="input-group-addon">https://github.com/</span>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.githubUsername.$valid && submitted,
'has-error': addProjectForm.githubUsername.$invalid && submitted }">
<input type="text" name="githubUsername" class="form-control" ng-model="projectToAdd.githubUsername" required/>
</div>
<span class="input-group-addon">/</span>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.githubProjectName.$valid && submitted,
'has-error': addProjectForm.githubProjectName.$invalid && submitted }">
<input type="text" name="githubProjectName" id="githubProjectName" class="form-control" ng-model="projectToAdd.githubProjectName" required/>
</div>
</div>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.githubUsername.$valid && submitted,
'has-error': addProjectForm.githubUsername.$invalid && submitted }">
<p class="help-block" ng-show="addProjectForm.githubUsername.$error.required && submitted">
The project owner's github username is required
</p>
</div>
<div class="form-group" ng-class="{ 'has-success': addProjectForm.githubProjectName.$valid && submitted,
'has-error': addProjectForm.githubProjectName.$invalid && submitted }">
<p class="help-block" ng-show="addProjectForm.githubProjectName.$error.required && submitted">
The project's github name is required
</p>
</div>

<div id="getInfo" align="right">
<button type="button" class="btn btn-default" ng-click="getInfo()" >Auto-complete info via github</button>
</div>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.name.$valid && submitted,
'has-error': addProjectForm.name.$invalid && submitted }">
Expand All @@ -57,24 +83,14 @@ <h4 class="modal-title" id="addProjectLabel">Add a Project</h4>
</p>
</div>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.githubUsername.$valid && submitted,
'has-error': addProjectForm.githubUsername.$invalid && submitted }">
<label>Project owner's github username</label>

<input type="text" name="githubUsername" class="form-control" ng-model="projectToAdd.githubUsername" required/>
<p class="help-block" ng-show="addProjectForm.githubUsername.$error.required && submitted">
The project owner's github username is required
</p>
</div>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.githubProjectName.$valid && submitted,
'has-error': addProjectForm.githubProjectName.$invalid && submitted }">
<label>Github project name</label>
<div class="form-group">
<label>Additional repositories</label>
<button class="btn btn-xs btn-success" type="button" ng-click="addRepository()">+</button>

<input type="text" name="githubProjectName" class="form-control" ng-model="projectToAdd.githubProjectName" required/>
<p class="help-block" ng-show="addProjectForm.githubProjectName.$error.required && submitted">
The project's github name is required
</p>
<div ng-repeat="repo in projectToAdd.repositories track by $id($index)" ng-if="$index >= 1">
<input type="text" name="repository" class="form-control repo" ng-model="projectToAdd.repositories[$index]" />
<button class="btn btn-danger repoButton" type="button" ng-click="removeRepository($index)">-</button>
</div>
</div>

<div class="form-group" ng-class="{ 'has-success': addProjectForm.description.$valid && submitted,
Expand All @@ -94,7 +110,7 @@ <h4 class="modal-title" id="addProjectLabel">Add a Project</h4>

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" />
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
Expand All @@ -108,7 +124,7 @@ <h2 id="name"><a href="/projects/{{project.githubUsername}}/{{project.githubProj
<ul class="project-info">
<li><a href="{{ project.websiteUrl }}">Website</a></li>
<li><a href="/projects/{{project.githubUsername}}/{{project.githubProjectName}}/blog">Blog</a></li>
<li><a href="{{ project.repositoryUrl }}">Repository</a></li>
<li><a href="{{ project.repositories[0] }}">Repository</a></li>
</ul>
<div class="clear"></div>
<div id="description" btf-markdown="project.description"></div>
Expand Down
29 changes: 22 additions & 7 deletions client/app/projects/projects.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ h2 {
color: black;
}

#repositoryUrl {
width: 78%;
display: inline;
margin-bottom: 15px;
#getInfo {
margin-bottom: 10px;
border-bottom: 1px solid #E5E5E5;
}

#getInfo {
width: 20%;
float: right;
#getInfo .btn {
margin-bottom: 15px;
}

#active {
Expand All @@ -139,3 +137,20 @@ h2 {
margin-left: 10px;
margin-top: -7px;
}

.repo {
width: 93%;
float: left;
padding-bottom: 10px;
margin-bottom: 10px;
}

.repoButton {
float: right;
width: 6%;
}

#githubProjectName {
border-bottom-right-radius: 4px;
border-top-right-radius: 4px;
}
16 changes: 16 additions & 0 deletions scripts/migrateRepositoryUrlToRepositories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file is to help migrate the old database which had projects with a single
// "repositoryUrl" property to a new database in which projects have a "repositories" array
// holding the old repositoryUrl as the first repository and having the ability to add more

var projectsWithRepoUrl = db.projects.find({ "repositoryUrl": { $exists: true } });

while(projectsWithRepoUrl.hasNext()) {
db.projects.update(
{ "repositoryUrl": { $exists: true } },
{
$set: { repositories: [ projectsWithRepoUrl.next().repositoryUrl ] },
$unset: { repositoryUrl: 1 }
}
);
}

2 changes: 1 addition & 1 deletion server/api/project/project.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var ProjectSchema = new Schema({
description: String,
// Where is the project hosted? Github, Google Code, etc.
repositoryType: {type: String, default: 'github'},
repositoryUrl: String,
repositories: [String],
websiteUrl: String,
githubUsername: {type: String, index: true},
githubProjectName: {type: String, index: true},
Expand Down

0 comments on commit ee6bb0e

Please sign in to comment.