diff --git a/src/main/resources/update/1_2.sql b/src/main/resources/update/1_2.sql index 5040157..373596e 100644 --- a/src/main/resources/update/1_2.sql +++ b/src/main/resources/update/1_2.sql @@ -3,6 +3,7 @@ USER_NAME VARCHAR(100) NOT NULL, REPOSITORY_NAME VARCHAR(100) NOT NULL, ACTIVITY_USER_NAME VARCHAR(100) NOT NULL, + ACTIVITY_TYPE VARCHAR(100) NOT NULL, MESSAGE TEXT NOT NULL, ADDITIONAL_INFO TEXT, ACTIVITY_DATE TIMESTAMP NOT NULL diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala index c9fa16a..405733d 100644 --- a/src/main/scala/app/WikiController.scala +++ b/src/main/scala/app/WikiController.scala @@ -6,10 +6,12 @@ import jp.sf.amateras.scalatra.forms._ class WikiController extends WikiControllerBase - with WikiService with RepositoryService with AccountService with CollaboratorsAuthenticator with ReferrerAuthenticator + with WikiService with RepositoryService with AccountService with ActivityService + with CollaboratorsAuthenticator with ReferrerAuthenticator trait WikiControllerBase extends ControllerBase { - self: WikiService with RepositoryService with CollaboratorsAuthenticator with ReferrerAuthenticator => + self: WikiService with RepositoryService with ActivityService + with CollaboratorsAuthenticator with ReferrerAuthenticator => case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String) @@ -72,9 +74,13 @@ }) post("/:owner/:repository/wiki/_edit", editForm)(collaboratorsOnly { (form, repository) => + val loginAccount = context.loginAccount.get + saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName, - form.content, context.loginAccount.get, form.message.getOrElse("")) + form.content, loginAccount, form.message.getOrElse("")) + updateLastActivityDate(repository.owner, repository.name) + recordEditWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName) redirect("/%s/%s/wiki/%s".format(repository.owner, repository.name, form.pageName)) }) @@ -84,9 +90,13 @@ }) post("/:owner/:repository/wiki/_new", newForm)(collaboratorsOnly { (form, repository) => + val loginAccount = context.loginAccount.get + saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName, form.content, context.loginAccount.get, form.message.getOrElse("")) + updateLastActivityDate(repository.owner, repository.name) + recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName) redirect("/%s/%s/wiki/%s".format(repository.owner, repository.name, form.pageName)) }) diff --git a/src/main/scala/model/Activity.scala b/src/main/scala/model/Activity.scala index 632d291..ba42bb6 100644 --- a/src/main/scala/model/Activity.scala +++ b/src/main/scala/model/Activity.scala @@ -5,11 +5,12 @@ object Activities extends Table[Activity]("ACTIVITY") with BasicTemplate with Functions { def activityId = column[Int]("ACTIVITY_ID", O AutoInc) def activityUserName = column[String]("ACTIVITY_USER_NAME") + def activityType = column[String]("ACTIVITY_TYPE") def message = column[String]("MESSAGE") def additionalInfo = column[String]("ADDITIONAL_INFO") def activityDate = column[java.util.Date]("ACTIVITY_DATE") - def * = activityId ~ userName ~ repositoryName ~ activityUserName ~ message ~ additionalInfo.? ~ activityDate <> (Activity, Activity.unapply _) - def autoInc = userName ~ repositoryName ~ activityUserName ~ message ~ additionalInfo.? ~ activityDate returning activityId + def * = activityId ~ userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate <> (Activity, Activity.unapply _) + def autoInc = userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate returning activityId } case class Activity( @@ -17,6 +18,7 @@ userName: String, repositoryName: String, activityUserName: String, + activityType: String, message: String, additionalInfo: Option[String], activityDate: java.util.Date diff --git a/src/main/scala/service/ActivityService.scala b/src/main/scala/service/ActivityService.scala index 263add7..59bdf48 100644 --- a/src/main/scala/service/ActivityService.scala +++ b/src/main/scala/service/ActivityService.scala @@ -18,31 +18,57 @@ }) .sortBy { case (t1, t2) => t1.activityId desc } .map { case (t1, t2) => t1 } + .take(30) .list } def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit = Activities.autoInc insert(userName, repositoryName, activityUserName, + "create_repository", "[[%s]] created [[%s/%s]]".format(activityUserName, userName, repositoryName), - None, currentDate) + None, + currentDate) def recordCreateIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit = Activities.autoInc insert(userName, repositoryName, activityUserName, + "open_issue", "[[%s]] opened issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId), - Some(title), currentDate) + Some(title), + currentDate) def recordCloseIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit = Activities.autoInc insert(userName, repositoryName, activityUserName, + "close_issue", "[[%s]] closed issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId), - Some(title), currentDate) + Some(title), + currentDate) def recordReopenIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, title: String): Unit = Activities.autoInc insert(userName, repositoryName, activityUserName, + "reopen_issue", "[[%s]] closed reopened [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId), - Some(title), currentDate) + Some(title), + currentDate) def recordCommentIssueActivity(userName: String, repositoryName: String, activityUserName: String, issueId: Int, comment: String): Unit = Activities.autoInc insert(userName, repositoryName, activityUserName, + "comment_issue", "[[%s]] commented on issue [[%s/%s#%d]]".format(activityUserName, userName, repositoryName, issueId), - Some(comment), currentDate) + Some(comment), + currentDate) + + def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String) = + Activities.autoInc insert(userName, repositoryName, activityUserName, + "create_wiki", + "[[%s]] created the [[%s/%s]] wiki".format(activityUserName, userName, repositoryName), + Some(pageName), + currentDate) + + def recordEditWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String) = + Activities.autoInc insert(userName, repositoryName, activityUserName, + "edit_wiki", + "[[%s]] edited the [[%s/%s]] wiki".format(activityUserName, userName, repositoryName), + Some(pageName), + currentDate) + } diff --git a/src/main/twirl/account/activity.scala.html b/src/main/twirl/account/activity.scala.html index 023d91f..fedb46c 100644 --- a/src/main/twirl/account/activity.scala.html +++ b/src/main/twirl/account/activity.scala.html @@ -23,7 +23,17 @@