Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Allfollowups #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ trait FollowupFinder {
def findAllFollowupsByCommitForUser(userId: ObjectId): FollowupsByCommitListView

def findFollowupForUser(userId: ObjectId, followupId: ObjectId): Either[String, SingleFollowupView]

def findFollowupforAdmin(followupId: ObjectId): Either[String, SingleFollowupView]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should be renamed to findFollowup - we do not restrict to admins anymore, right?


def countFollowupsForUser(userId: ObjectId): Long

def countFollowupsForUserSince(date: DateTime, userId: ObjectId): Long

def findAllFollowupsByCommitForAdmin(): FollowupsByCommitListView
}

Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,39 @@ class SQLFollowupFinder(val database: SQLDatabase, userDAO: UserDAO) extends Fol
case like: Like => FollowupLastLikeView(like.id.toString, author.name, like.postingTime, author.avatarUrl)
}
}
def findAllFollowupsByCommitForAdmin(): FollowupsByCommitListView = db.withTransaction { implicit session =>
val followups = findAllFollowups()
val followupReactions = findFollowupReactions(followups)
val lastReactions = findLastReactionsForFollowups(followups)
val reactionAuthors = findReactionAuthors(lastReactions)
val commits = findCommitsForFollowups(followups)

val followupsGroupedByCommit = followups.groupBy(_.threadCommitId)

val sortFollowupsForCommitByDate = (f1: FollowupReactionsView, f2: FollowupReactionsView) => f1.lastReaction.date.isAfter(f2.lastReaction.date)

val followupsForCommits = followupsGroupedByCommit.map {
case (commitId, commitFollowups) =>
val followupsForCommitViews = commitFollowups
.map(f => followupToReactionsView(f, followupReactions.getOrElse(f.id, Nil), lastReactions, reactionAuthors))
.sortWith(sortFollowupsForCommitByDate)
val commit = commits(commitId)
val commitView = FollowupCommitView(commit.id.toString, commit.sha, commit.repoName, commit.authorName, commit.message, commit.authorDate)
FollowupsByCommitView(commitView, followupsForCommitViews)
}
FollowupsByCommitListView(sortFollowupGroupsByNewest(followupsForCommits))
}
private def findAllFollowups()(implicit session: Session): List[SQLFollowup] = {
followups.list()
}
def findFollowupforAdmin(followupId: ObjectId) = db.withTransaction { implicit session =>
val r = for {
followup <- followups.filter(f => f.id === followupId).firstOption
reaction <- findLastReaction(followup.lastReactionId)
author <- userDAO.findPartialUserDetails(List(reaction.authorId)).headOption
commit <- commitInfos.filter(_.id === followup.threadCommitId).firstOption()
} yield recordsToFollowupView(commit, reaction, author, followup)

r.fold[Either[String, SingleFollowupView]](Left("No such followup"))(Right(_))
}
}
1 change: 1 addition & 0 deletions codebrag-rest/src/main/scala/ScalatraBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ScalatraBootstrap extends LifeCycle with Logging {
context.mount(new CommitsServlet(authenticator, toReviewCommitsFinder, allCommitsFinder, reactionFinder, addCommentUseCase,
reviewCommitUseCase, userReactionService, userDao, diffWithCommentsService, unlikeUseCaseFactory, likeUseCase), Prefix + CommitsServlet.MAPPING_PATH)
context.mount(new FollowupsServlet(authenticator, followupFinder, followupDoneUseCase), Prefix + FollowupsServlet.MappingPath)
context.mount(new AllFollowupsServlet(authenticator, followupFinder, followupDoneUseCase), Prefix + AllFollowupsServlet.MappingPath)
context.mount(new VersionServlet, Prefix + "version")
context.mount(new ConfigServlet(config, authenticator), Prefix + "config")
context.mount(new InvitationServlet(authenticator, generateInvitationCodeUseCase, sendInvitationEmailUseCase), Prefix + "invitation")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.softwaremill.codebrag.rest

import com.softwaremill.codebrag.service.user.Authenticator
import org.scalatra.json.JacksonJsonSupport
import org.bson.types.ObjectId
import org.scalatra.NotFound
import com.softwaremill.codebrag.dao.finders.followup.FollowupFinder
import com.softwaremill.codebrag.dao.finders.views.SingleFollowupView
import com.softwaremill.codebrag.usecases.reactions.FollowupDoneUseCase

class AllFollowupsServlet(val authenticator: Authenticator,
followupFinder: FollowupFinder,
followupDoneUseCase: FollowupDoneUseCase)
extends JsonServletWithAuthentication with JacksonJsonSupport {

get("/") {
haltIfNotAuthenticated()
followupFinder.findAllFollowupsByCommitForAdmin()
}

get("/:id") {
haltIfNotAuthenticated()
val followupId = params("id")
followupFinder.findFollowupforAdmin(new ObjectId(followupId)) match {
case Right(followup) => followup
case Left(msg) => NotFound(msg)
}
}

delete("/:id") {
haltIfNotAuthenticated()
followupDoneUseCase.execute(user.id, new ObjectId(params("id")))
}
}

object AllFollowupsServlet {
val MappingPath = "allfollowups"
}
14 changes: 13 additions & 1 deletion codebrag-ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@

<!-- follow-ups -->
<script type="text/javascript" src="scripts/followups/followupsCtrl.js"></script>
<script type="text/javascript" src="scripts/followups/allfollowupsCtrl.js"></script>
<script type="text/javascript" src="scripts/followups/followupListItemCtrl.js"></script>
<script type="text/javascript" src="scripts/followups/allfollowupListItemCtrl.js"></script>
<script type="text/javascript" src="scripts/followups/followupDetailsCtrl.js"></script>
<script type="text/javascript" src="scripts/followups/allfollowupDetailsCtrl.js"></script>
<script type="text/javascript" src="scripts/followups/followupsService.js"></script>
<script type="text/javascript" src="scripts/followups/allfollowupsService.js"></script>

<!--invitations-->
<script type="text/javascript" src="scripts/invitations/inviteFormPopupCtrl.js"></script>
Expand Down Expand Up @@ -225,6 +229,14 @@
</span>
</a>
</li>
<li>
<a id="allfollowups-btn" ng-click="openAllFollowups()" class="button" active-for-states="allfollowups,allfollowups.list,allfollowups.details">
<span class="number">
Dashboard
<span class="ghost-notification" ng-show="followupsNotificationAvailable"></span>
</span>
</a>
</li>
</ul>
</nav>
<div class="pull-right-wrapper">
Expand All @@ -248,4 +260,4 @@
<section ui-view></section>
<div message-popup></div>
</body>
</html>
</html>
22 changes: 22 additions & 0 deletions codebrag-ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ angular.module('codebrag.commits', [

angular.module('codebrag.followups', ['ngResource', 'ui.compat', 'codebrag.auth', 'codebrag.events', 'codebrag.tour']);

angular.module('codebrag.allfollowups', ['ngResource', 'ui.compat', 'codebrag.auth', 'codebrag.events', 'codebrag.tour','codebrag.followups']);

angular.module('codebrag.invitations', ['ui.validate', 'ui.keypress']);

angular.module('codebrag.profile', ['codebrag.session']);
Expand All @@ -47,6 +49,7 @@ angular.module('codebrag', [
'codebrag.commits',
'codebrag.branches',
'codebrag.followups',
'codebrag.allfollowups',
'codebrag.repostatus',
'codebrag.favicon',
'codebrag.tour',
Expand Down Expand Up @@ -159,3 +162,22 @@ angular.module('codebrag.common')
angular.module('codebrag.userMgmt').run(function(userMgmtService) {
userMgmtService.initialize();
});

angular.module('codebrag.allfollowups')
.config(function ($stateProvider, authenticatedUser) {
$stateProvider
.state('allfollowups', {
url: '/allfollowups',
abstract: true,
templateUrl: 'views/secured/followups/allfollowups.html',
resolve: authenticatedUser
})
.state('allfollowups.list', {
url: '',
templateUrl: 'views/secured/followups/emptyFollowups.html'
})
.state('allfollowups.details', {
url: '/{followupId}/comments/{commentId}',
templateUrl: 'views/secured/followups/allfollowupDetails.html'
});
});
32 changes: 32 additions & 0 deletions codebrag-ui/app/scripts/followups/allfollowupDetailsCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
angular.module('codebrag.allfollowups')

.controller('AllFollowupDetailsCtrl', function ($stateParams, $state, $scope, allfollowupsService, commitsService) {

var followupId = $stateParams.followupId;

$scope.scrollTo = $stateParams.commentId;

allfollowupsService.loadFollowupDetails(followupId).then(function(followup) {
$scope.currentFollowup = followup;
commitsService.commitDetails(followup.commit.sha, followup.commit.repoName).then(function(commit) {
$scope.currentCommit = new codebrag.CurrentCommit(commit);

});
});

$scope.markCurrentFollowupAsDone = function() {
allfollowupsService.removeAndGetNext(followupId).then(function(nextFollowup) {
goTo(nextFollowup);
});
};

function goTo(nextFollowup) {
if (_.isNull(nextFollowup)) {
$state.transitionTo('allfollowups.list');
} else {
$state.transitionTo('allfollowups.details', {followupId: nextFollowup.followupId, commentId: nextFollowup.lastReaction.reactionId});
}
}


});
28 changes: 28 additions & 0 deletions codebrag-ui/app/scripts/followups/allfollowupListItemCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
angular.module('codebrag.allfollowups')

.controller('AllFollowupListItemCtrl', function ($scope, $state, $stateParams, allfollowupsService, $rootScope, events) {

$scope.openFollowupDetails = function (followup) {
if(_thisFollowupOpened(followup)) {
$rootScope.$broadcast(events.scrollOnly);
} else {
$state.transitionTo('allfollowups.details', {followupId: followup.followupId, commentId: followup.lastReaction.reactionId});
}
};

$scope.dismiss = function (followup) {
allfollowupsService.removeAndGetNext(followup.followupId).then(function(nextFollowup) {
if(nextFollowup) {
$state.transitionTo('allfollowups.details', {followupId: nextFollowup.followupId, commentId: nextFollowup.lastReaction.reactionId});
} else {
$state.transitionTo('allfollowups.list');
}
});
};

function _thisFollowupOpened(followup) {
return $state.current.name === 'allfollowups.details' && $state.params.followupId === followup.followupId;
}


});
22 changes: 22 additions & 0 deletions codebrag-ui/app/scripts/followups/allfollowupsCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
angular.module('codebrag.allfollowups')

.controller('AllFollowupsCtrl', function ($scope, $http, allfollowupsService, pageTourService, events) {

$scope.$on(events.allfollowupsTabOpened, initCtrl);


$scope.pageTourForFollowupsVisible = function() {
return pageTourService.stepActive('allfollowups') || pageTourService.stepActive('invites');
};

function initCtrl() {
allfollowupsService.allFollowups().then(function(followups) {
$scope.followupCommits = followups;
});
$scope.hasFollowupsAvailable = allfollowupsService.hasFollowups;
$scope.mightHaveFollowups = allfollowupsService.mightHaveFollowups;
}

initCtrl();

});
118 changes: 118 additions & 0 deletions codebrag-ui/app/scripts/followups/allfollowupsService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
angular.module('codebrag.allfollowups')

.factory('allfollowupsService', function($http, $rootScope, events) {

var followupsListLocal = new codebrag.followups.LocalFollowupsList();
var listFetched = false;

function allFollowups() {
return _httpRequest('GET').then(function(response) {
followupsListLocal.addAll(response.data.followupsByCommit);
listFetched = true;
return followupsListLocal.collection;
});
}

function removeAndGetNext(followupId, commitId) {
return _httpRequest('DELETE', followupId, {unique: true, requestId: 'removeFollowup_' + followupId}).then(function() {
triggerCounterDecrease();
var nextFollowup = followupsListLocal.removeOneAndGetNext(followupId, commitId);
return nextFollowup;
});

}

function loadFollowupDetails(followupId) {
return _httpRequest('GET', followupId).then(function(response) {
return response.data;
});
}

function hasFollowups() {
return followupsListLocal.hasFollowups();
}

function mightHaveFollowups() {
return !listFetched || followupsListLocal.hasFollowups()
}

function _httpRequest(method, id, config) {
var followupsUrl = 'rest/allfollowups/' + (id || '');
var reqConfig = angular.extend(config || {}, {method: method, url: followupsUrl});
return $http(reqConfig);
}

function triggerCounterDecrease() {
$rootScope.$broadcast(events.followupDone);
}

return {
allFollowups: allFollowups,
removeAndGetNext: removeAndGetNext,
loadFollowupDetails: loadFollowupDetails,
hasFollowups: hasFollowups,
mightHaveFollowups: mightHaveFollowups
};

});

var codebrag = codebrag || {};
codebrag.followups = codebrag.followups || {};

codebrag.followups.LocalFollowupsList = function(collection) {

var self = this;

this.collection = collection || [];

this.addAll = function(newCollection) {
this.collection.length = 0;
Array.prototype.push.apply(this.collection, newCollection);
};

function nextFollowup(commit, removeAtIndex) {
var followupToReturn = null;
var currentCommitIndex = self.collection.indexOf(commit);

if (commit.followups[removeAtIndex]) {
followupToReturn = commit.followups[removeAtIndex];
} else if (self.collection[currentCommitIndex + 1]) {
followupToReturn = self.collection[currentCommitIndex + 1].followups[0];
} else if (removeAtIndex > 0) {
followupToReturn = commit.followups[removeAtIndex - 1];
} else if (removeAtIndex === 0 && currentCommitIndex > 0) {
var previousCommitFollowupsLength = self.collection[currentCommitIndex - 1].followups.length;
followupToReturn = self.collection[currentCommitIndex - 1].followups[previousCommitFollowupsLength - 1];
}
if (!commit.followups.length) {
self.collection.splice(currentCommitIndex, 1);
}
return followupToReturn;
}

this.removeOneAndGetNext = function(followupId) {
var currentCommit = _.find(this.collection, function(group) {
return _.some(group.followups, function(followup) {
return followup.followupId === followupId;
});
});
var followupToRemove = _.find(currentCommit.followups, function(followup) {
return followup.followupId === followupId;
});
var indexToRemove = currentCommit.followups.indexOf(followupToRemove);
currentCommit.followups.splice(indexToRemove, 1);
return nextFollowup(currentCommit, indexToRemove);
};

this.hasFollowups = function() {
return this.collection.length > 0;
};

this.followupsCount = function() {
return _.reduce(this.collection, function(sum, followupsGroup) {
return sum + followupsGroup.followups.length;
}, 0);
};

};

4 changes: 2 additions & 2 deletions codebrag-ui/app/scripts/followups/followupsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module('codebrag.followups')
};

function initCtrl() {
followupsService.allFollowups().then(function(followups) {
followupsService.followups().then(function(followups) {
$scope.followupCommits = followups;
});
$scope.hasFollowupsAvailable = followupsService.hasFollowups;
Expand All @@ -19,4 +19,4 @@ angular.module('codebrag.followups')

initCtrl();

});
});
Loading