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

Commit

Permalink
Merge pull request #323 from MITLibraries/313_view_interests
Browse files Browse the repository at this point in the history
Provides links to Interests by Scheme on Subscriber Dashboard
  • Loading branch information
JPrevost committed Aug 18, 2015
2 parents c189ffb + c735f53 commit 8425470
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/Subscriber.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ case class Subscriber(id: Int, // DB key
}
}

def interestCountIn(schemeTag: String) = {
DB.withConnection { implicit c =>
SQL("""select COUNT(*) from interest
where subscriber_id = {sub_id}
and scheme_tag = {stag}""")
.on('sub_id -> id, 'stag -> schemeTag).as(scalar[Long].single)
}
}

def interestIn(schemeTag: String) = {
DB.withConnection { implicit c =>
SQL("select * from interest where subscriber_id = {sub_id} and scheme_tag = {stag}")
Expand Down
9 changes: 9 additions & 0 deletions app/views/subscriber/dashboard.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ <h4>Destinations</h4>
<a href="@routes.Application.newChannel(sub.id)">Add a new destination</a>
</li>
</ul>

<h4>Interests by Scheme</h4>
@for(s <- Scheme.withGentype("topic").filter(_.tag != "meta").sortWith(_.tag.toLowerCase < _.tag.toLowerCase)) {
<li class="list-group-item" id="interest_scheme-@s.id">
<span class="badge">@sub.interestCountIn(s.tag)</span>
<a href="@routes.Application.interestBrowse("scheme", s.tag)">@s.tag</a>
<a href="@routes.Application.scheme(s.id)"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span></a>
</li>
}
</div>

<div class="col-md-9">
Expand Down
17 changes: 17 additions & 0 deletions test/unit/SubscriberSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ class SubscriberSpec extends Specification {
}
}

"#interestsCountIn" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
Subscriber.all must haveSize(0)
val u = User.make("bob", "bob@example.com", "pwd", "role1")
val s = Subscriber.make(u.id, "Sub Name", "cat", "contact", Some("link"), Some("logo"))
s.interests must haveSize(0)
val sch1 = Scheme.make("tag", "gentype", "cat", "desc", Some("link"), Some("logo"))
val sch2 = Scheme.make("tag1", "gentype", "cat", "desc", Some("link"), Some("logo"))
s.interestCountIn("tag") must equalTo(0)
s.interestCountIn("tag1") must equalTo(0)
s.addInterest(sch1, "MIT", true)
s.addInterest(sch1, "Stanford", false)
s.interestCountIn("tag") must equalTo(2)
s.interestCountIn("tag1") must equalTo(0)
}
}

"#interestIn" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
Subscriber.all must haveSize(0)
Expand Down

0 comments on commit 8425470

Please sign in to comment.