Skip to content

Commit

Permalink
Implemented publication activity history pane #1663
Browse files Browse the repository at this point in the history
  • Loading branch information
verheyenkoen committed Oct 1, 2024
1 parent 7a79479 commit 8391f06
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 344 deletions.
61 changes: 35 additions & 26 deletions handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,38 +178,15 @@ func RecentActivity(w http.ResponseWriter, r *http.Request) {
c.HandleError(w, r, err)
return
}

for _, p := range pHits.Hits {
prevP, err := c.Repo.GetPublicationSnapshotBefore(p.ID, *p.DateFrom)
if err != nil && !errors.Is(err, models.ErrNotFound) {
c.HandleError(w, r, err)
return
}
act := views.Activity{
Object: views.PublicationObject,
User: p.User,
Datestamp: *p.DateUpdated,
URL: c.PathTo("publication", "id", p.ID).String(),
Status: p.Status,
Title: p.Title,
}
if prevP == nil {
act.Event = views.CreateEvent
} else if p.Status == "public" && prevP.Status == "returned" {
act.Event = views.RepublishEvent
} else if p.Status == "public" && prevP.Status != "public" {
act.Event = views.PublishEvent
} else if p.Status == "returned" && prevP.Status != "returned" {
act.Event = views.WithdrawEvent
} else if p.Locked && !prevP.Locked {
act.Event = views.LockEvent
} else if !p.Locked && prevP.Locked {
act.Event = views.UnlockEvent
} else if p.Message != "" && p.Message != prevP.Message {
act.Event = views.MessageEvent
} else {
act.Event = views.UpdateEvent
}
acts = append(acts, act)

acts = append(acts, GetPublicationActivity(c, p, prevP))
}

dHits, err := c.DatasetSearchIndex.Search(models.NewSearchArgs().
Expand Down Expand Up @@ -260,3 +237,35 @@ func RecentActivity(w http.ResponseWriter, r *http.Request) {

views.RecentActivity(c, acts).Render(r.Context(), w)
}

func GetPublicationActivity(c *ctx.Ctx, p *models.Publication, prevP *models.Publication) views.Activity {
act := views.Activity{
Object: views.PublicationObject,
User: p.User,
Datestamp: *p.DateUpdated,
URL: c.PathTo("publication", "id", p.ID).String(),
Status: p.Status,
RecordID: p.ID,
Title: p.Title,
}

if prevP == nil {
act.Event = views.CreateEvent
} else if p.Status == "public" && prevP.Status == "returned" {
act.Event = views.RepublishEvent
} else if p.Status == "public" && prevP.Status != "public" {
act.Event = views.PublishEvent
} else if p.Status == "returned" && prevP.Status != "returned" {
act.Event = views.WithdrawEvent
} else if p.Locked && !prevP.Locked {
act.Event = views.LockEvent
} else if !p.Locked && prevP.Locked {
act.Event = views.UnlockEvent
} else if p.Message != "" && p.Message != prevP.Message {
act.Event = views.MessageEvent
} else {
act.Event = views.UpdateEvent
}

return act
}
31 changes: 31 additions & 0 deletions handlers/publicationviewing/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"net/http"

"github.com/ugent-library/biblio-backoffice/ctx"
"github.com/ugent-library/biblio-backoffice/handlers"
"github.com/ugent-library/biblio-backoffice/models"
"github.com/ugent-library/biblio-backoffice/views"
publicationviews "github.com/ugent-library/biblio-backoffice/views/publication"
)

Expand Down Expand Up @@ -85,3 +88,31 @@ func ShowActivity(w http.ResponseWriter, r *http.Request) {

publicationviews.Activity(c, p, redirectURL).Render(r.Context(), w)
}

func RecentActivity(w http.ResponseWriter, r *http.Request) {
c := ctx.Get(r)
p := ctx.GetPublication(r)

var (
acts []views.Activity
nextSnapshot *models.Publication
)

err := c.Repo.PublicationHistory(p.ID, func(snapshot *models.Publication) bool {
if nextSnapshot != nil {
acts = append(acts, handlers.GetPublicationActivity(c, nextSnapshot, snapshot))
}

nextSnapshot = snapshot

return true
})
if err != nil {
c.HandleError(w, r, err)
return
}

acts = append(acts, handlers.GetPublicationActivity(c, nextSnapshot, nil))

publicationviews.RecentActivity(c, acts, p).Render(r.Context(), w)
}
1 change: 1 addition & 0 deletions routes/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func Register(c Config) {
r.With(ctx.SetSubNav("datasets")).Get("/datasets", publicationviewing.ShowDatasets).Name("publication_datasets")
r.With(ctx.SetSubNav("activity")).Get("/activity", publicationviewing.ShowActivity).Name("publication_activity")
r.Get("/files/{file_id}", publicationviewing.DownloadFile).Name("publication_download_file")
r.Get("/details/recent-activity", publicationviewing.RecentActivity).Name("publication_details_recent_activity")
})

// edit only
Expand Down
45 changes: 9 additions & 36 deletions views/publication/show.templ
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ templ Show(c *ctx.Ctx, p *models.Publication, redirectURL string) {
ID: "history",
Icon: "if-time",
Title: "Activity history",
Component: historyPane(),
Component: historyPane(c, p),
},
shared.DetailsSidebarStepArgs{
ID: "info",
Expand Down Expand Up @@ -327,41 +327,14 @@ templ messagesPane() {
</div>
}

templ historyPane() {
<ul class="c-activity-list">
<li class="c-activity-item">
<div class="c-activity-item__avatar-wrapper">
<div class="bc-avatar bc-avatar--muted bc-avatar--small">
<i class="if if-edit"></i>
</div>
</div>
<div class="c-activity-item__content">
<div class="c-activity-item__activity">
<div class="c-activity-item__date">21 maart 2022 at 18:34</div>
<div class="c-activity-item__text">
<span class="fw-bold">Wouter Bosmans</span>
edited the access level questions
</div>
</div>
</div>
</li>
<li class="c-activity-item">
<div class="c-activity-item__avatar-wrapper">
<div class="bc-avatar bc-avatar--muted bc-avatar--small">
<i class="if if-edit"></i>
</div>
</div>
<div class="c-activity-item__content">
<div class="c-activity-item__activity">
<div class="c-activity-item__date">21 maart 2022 at 18:34</div>
<div class="c-activity-item__text">
<span class="fw-bold">Wouter Bosmans</span>
started completing the draft publication.
</div>
</div>
</div>
</li>
</ul>
templ historyPane(c *ctx.Ctx, p *models.Publication) {
<div hx-get={ c.PathTo("publication_details_recent_activity", "id", p.ID).String() } hx-trigger="load delay:100ms">
Loading recent activity&hellip;
</div>
}

templ RecentActivity(c *ctx.Ctx, acts []views.Activity, p *models.Publication) {
@views.ActivityList(c, acts, lo.ToPtr(p.ID))
}

templ infoPane(c *ctx.Ctx, p *models.Publication) {
Expand Down
87 changes: 63 additions & 24 deletions views/publication/show_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8391f06

Please sign in to comment.