diff --git a/handlers/dashboard.go b/handlers/dashboard.go
index e75a537dd..48c6323b7 100644
--- a/handlers/dashboard.go
+++ b/handlers/dashboard.go
@@ -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().
@@ -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
+}
diff --git a/handlers/publicationviewing/show.go b/handlers/publicationviewing/show.go
index 8595747c5..d0c6760f6 100644
--- a/handlers/publicationviewing/show.go
+++ b/handlers/publicationviewing/show.go
@@ -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"
)
@@ -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)
+}
diff --git a/routes/register.go b/routes/register.go
index b20d1f85b..4cd1c56ef 100644
--- a/routes/register.go
+++ b/routes/register.go
@@ -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
diff --git a/views/publication/show.templ b/views/publication/show.templ
index f6f3ef7db..7436f1125 100644
--- a/views/publication/show.templ
+++ b/views/publication/show.templ
@@ -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",
@@ -327,41 +327,14 @@ templ messagesPane() {
}
-templ historyPane() {
-
-
-
-
-
-
21 maart 2022 at 18:34
-
- Wouter Bosmans
- edited the access level questions
-
-
-
-
-
-
-
-
-
21 maart 2022 at 18:34
-
- Wouter Bosmans
- started completing the draft publication.
-
-
-
-
-
+templ historyPane(c *ctx.Ctx, p *models.Publication) {
+
+ Loading recent activity…
+
+}
+
+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) {
diff --git a/views/publication/show_templ.go b/views/publication/show_templ.go
index 2808c9f54..489b78696 100644
--- a/views/publication/show_templ.go
+++ b/views/publication/show_templ.go
@@ -760,7 +760,7 @@ func Show(c *ctx.Ctx, p *models.Publication, redirectURL string) templ.Component
ID: "history",
Icon: "if-time",
Title: "Activity history",
- Component: historyPane(),
+ Component: historyPane(c, p),
},
shared.DetailsSidebarStepArgs{
ID: "info",
@@ -817,7 +817,7 @@ func messagesPane() templ.Component {
})
}
-func historyPane() templ.Component {
+func historyPane(c *ctx.Ctx, p *models.Publication) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
@@ -835,7 +835,46 @@ func historyPane() templ.Component {
templ_7745c5c3_Var42 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("21 maart 2022 at 18:34
Wouter Bosmans edited the access level questions
21 maart 2022 at 18:34
Wouter Bosmans started completing the draft publication.
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Loading recent activity…
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+}
+
+func RecentActivity(c *ctx.Ctx, acts []views.Activity, p *models.Publication) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var44 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var44 == nil {
+ templ_7745c5c3_Var44 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ templ_7745c5c3_Err = views.ActivityList(c, acts, lo.ToPtr(p.ID)).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -856,9 +895,9 @@ func infoPane(c *ctx.Ctx, p *models.Publication) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var43 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var43 == nil {
- templ_7745c5c3_Var43 = templ.NopComponent
+ templ_7745c5c3_Var45 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var45 == nil {
+ templ_7745c5c3_Var45 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Created by ")
@@ -866,12 +905,12 @@ func infoPane(c *ctx.Ctx, p *models.Publication) templ.Component {
return templ_7745c5c3_Err
}
if p.Creator != nil {
- var templ_7745c5c3_Var44 string
- templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(p.Creator.FullName)
+ var templ_7745c5c3_Var46 string
+ templ_7745c5c3_Var46, templ_7745c5c3_Err = templ.JoinStringErrs(p.Creator.FullName)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 373, Col: 25}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 346, Col: 25}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var46))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -885,12 +924,12 @@ func infoPane(c *ctx.Ctx, p *models.Publication) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var45 string
- templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(p.DateCreated.Format("2006-01-02"))
+ var templ_7745c5c3_Var47 string
+ templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(p.DateCreated.Format("2006-01-02"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 381, Col: 42}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 354, Col: 42}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -903,12 +942,12 @@ func infoPane(c *ctx.Ctx, p *models.Publication) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var46 string
- templ_7745c5c3_Var46, templ_7745c5c3_Err = templ.JoinStringErrs(lo.Capitalize(p.SourceDB))
+ var templ_7745c5c3_Var48 string
+ templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(lo.Capitalize(p.SourceDB))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 386, Col: 34}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 359, Col: 34}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var46))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -964,8 +1003,8 @@ func infoPane(c *ctx.Ctx, p *models.Publication) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var47 templ.SafeURL = templ.URL(fmt.Sprintf("%s/publication/%s", c.FrontendURL, p.ID))
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var47)))
+ var templ_7745c5c3_Var49 templ.SafeURL = templ.URL(fmt.Sprintf("%s/publication/%s", c.FrontendURL, p.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var49)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -973,12 +1012,12 @@ func infoPane(c *ctx.Ctx, p *models.Publication) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var48 string
- templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(p.ID)
+ var templ_7745c5c3_Var50 string
+ templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(p.ID)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 412, Col: 12}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `publication/show.templ`, Line: 385, Col: 12}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/views/recent_activity.templ b/views/recent_activity.templ
index 56a8d223b..aea50fc95 100644
--- a/views/recent_activity.templ
+++ b/views/recent_activity.templ
@@ -1,8 +1,10 @@
package views
import (
+ "context"
"github.com/ugent-library/biblio-backoffice/ctx"
"github.com/ugent-library/biblio-backoffice/models"
+ "strings"
"time"
)
@@ -23,6 +25,28 @@ const (
MessageEvent
)
+var activityEventTexts = map[ActivityEvent]string{
+ CreateEvent: "started",
+ PublishEvent: "published",
+ RepublishEvent: "republished",
+ WithdrawEvent: "withdrew",
+ LockEvent: "locked",
+ UnlockEvent: "unlocked",
+ UpdateEvent: "edited",
+ MessageEvent: "left a comment on",
+}
+
+var activityEventIcons = map[ActivityEvent]string{
+ CreateEvent: "if-article",
+ PublishEvent: "if-book",
+ RepublishEvent: "if-book",
+ WithdrawEvent: "if-arrow-go-back",
+ LockEvent: "if-lock",
+ UnlockEvent: "if-lock-unlock",
+ UpdateEvent: "if-edit",
+ MessageEvent: "if-message",
+}
+
type Activity struct {
Event ActivityEvent
User *models.Person
@@ -30,6 +54,7 @@ type Activity struct {
Datestamp time.Time
Status string
URL string
+ RecordID string
Title string
}
@@ -40,86 +65,90 @@ templ RecentActivity(c *ctx.Ctx, acts []Activity) {
Recent activity
- if len(acts) > 0 {
-
- for _, act := range acts {
-
-
-
- switch act.Event {
- case CreateEvent:
-
- case PublishEvent, RepublishEvent:
-
- case WithdrawEvent:
-
- case LockEvent:
-
- case UnlockEvent:
-
- case UpdateEvent:
-
- case MessageEvent:
-
- }
-
+ @ActivityList(c, acts, nil)
+
+}
+
+templ ActivityList(c *ctx.Ctx, acts []Activity, currentRecordID *string) {
+ if len(acts) > 0 {
+
+ for _, act := range acts {
+
+
+
+
-
-
-
{ act.Datestamp.In(c.Timezone).Format("2006-01-02 15:04") }
-
-
- if act.User != nil && act.User.ID == c.User.ID {
- You
- } else if act.User != nil && c.Repo.CanCurate(act.User) && !c.Repo.CanCurate(c.User) {
- A Biblio team member
- } else if act.User != nil {
- { act.User.FullName }
- } else {
- System
- }
-
- { " " }
- switch act.Event {
- case CreateEvent:
- started a { c.Loc.Get("activity_statuses." + act.Status) }
- case PublishEvent:
- published a
- case RepublishEvent:
- republished a
- case WithdrawEvent:
- withdrew a
- case LockEvent:
- locked a
- case UnlockEvent:
- unlocked a
- case UpdateEvent:
- edited a
- case MessageEvent:
- left a comment on a
- }
- { " " }
- switch act.Object {
- case PublicationObject:
- publication:
- case DatasetObject:
- dataset:
- }
-
- if act.Title != "" {
- { act.Title }
- } else {
- Untitled record
- }
- .
-
+
+
+
+
{ act.Datestamp.In(c.Timezone).Format("2006-01-02 15:04") }
+
+ @templ.Raw(generateActivityText(c, act, currentRecordID))
-
- }
-
+
+
+ }
+
+ } else {
+
No activity to show.
+ }
+}
+
+func generateActivityText(c *ctx.Ctx, act Activity, currentRecordID *string) string {
+ sb := strings.Builder{}
+
+ if act.User != nil && act.User.ID == c.User.ID {
+ sb.WriteString("You")
+ } else if act.User != nil && c.Repo.CanCurate(act.User) && !c.Repo.CanCurate(c.User) {
+ sb.WriteString("A Biblio team member")
+ } else if act.User != nil {
+ sb.WriteString(act.User.FullName)
+ } else {
+ sb.WriteString("System")
+ }
+
+ sb.WriteString(" ")
+ sb.WriteString(activityEventTexts[act.Event])
+ sb.WriteString(" ")
+
+ isCurrentRecord := currentRecordID != nil && *currentRecordID == act.RecordID
+ if isCurrentRecord {
+ sb.WriteString("this")
+ } else {
+ sb.WriteString("a")
+ }
+
+ if act.Event == CreateEvent {
+ sb.WriteString(" ")
+ sb.WriteString(c.Loc.Get("activity_statuses." + act.Status))
+ }
+
+ sb.WriteString(" ")
+
+ switch act.Object {
+ case PublicationObject:
+ sb.WriteString("publication")
+ case DatasetObject:
+ sb.WriteString("dataset")
+ }
+
+ if !isCurrentRecord {
+ sb.WriteString(": ")
+ titleLink(act).Render(context.Background(), &sb)
+ }
+
+ sb.WriteString(".")
+
+ return sb.String()
+}
+
+templ titleLink(act Activity) {
+
+ if act.Title != "" {
+ { act.Title }
} else {
- No activity to show.
+ Untitled record
}
-
+
}
diff --git a/views/recent_activity_templ.go b/views/recent_activity_templ.go
index 096ec26eb..26e62460e 100644
--- a/views/recent_activity_templ.go
+++ b/views/recent_activity_templ.go
@@ -9,8 +9,10 @@ import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
import (
+ "context"
"github.com/ugent-library/biblio-backoffice/ctx"
"github.com/ugent-library/biblio-backoffice/models"
+ "strings"
"time"
)
@@ -31,6 +33,28 @@ const (
MessageEvent
)
+var activityEventTexts = map[ActivityEvent]string{
+ CreateEvent: "started",
+ PublishEvent: "published",
+ RepublishEvent: "republished",
+ WithdrawEvent: "withdrew",
+ LockEvent: "locked",
+ UnlockEvent: "unlocked",
+ UpdateEvent: "edited",
+ MessageEvent: "left a comment on",
+}
+
+var activityEventIcons = map[ActivityEvent]string{
+ CreateEvent: "if-article",
+ PublishEvent: "if-book",
+ RepublishEvent: "if-book",
+ WithdrawEvent: "if-arrow-go-back",
+ LockEvent: "if-lock",
+ UnlockEvent: "if-lock-unlock",
+ UpdateEvent: "if-edit",
+ MessageEvent: "if-message",
+}
+
type Activity struct {
Event ActivityEvent
User *models.Person
@@ -38,6 +62,7 @@ type Activity struct {
Datestamp time.Time
Status string
URL string
+ RecordID string
Title string
}
@@ -63,6 +88,36 @@ func RecentActivity(c *ctx.Ctx, acts []Activity) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+ templ_7745c5c3_Err = ActivityList(c, acts, nil).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+}
+
+func ActivityList(c *ctx.Ctx, acts []Activity, currentRecordID *string) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var2 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var2 == nil {
+ templ_7745c5c3_Var2 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
if len(acts) > 0 {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
if templ_7745c5c3_Err != nil {
@@ -73,213 +128,46 @@ func RecentActivity(c *ctx.Ctx, acts []Activity) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- switch act.Event {
- case CreateEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case PublishEvent, RepublishEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case WithdrawEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case LockEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case UnlockEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case UpdateEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case MessageEvent:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var2 string
- templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(act.Datestamp.In(c.Timezone).Format("2006-01-02 15:04"))
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `recent_activity.templ`, Line: 69, Col: 100}
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ var templ_7745c5c3_Var3 = []any{"if", activityEventIcons[act.Event]}
+ templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var3...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- if act.User != nil && act.User.ID == c.User.ID {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("You")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- } else if act.User != nil && c.Repo.CanCurate(act.User) && !c.Repo.CanCurate(c.User) {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("A Biblio team member")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- } else if act.User != nil {
- var templ_7745c5c3_Var3 string
- templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(act.User.FullName)
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `recent_activity.templ`, Line: 77, Col: 30}
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- } else {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("System")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ var templ_7745c5c3_Var5 string
+ templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(act.Datestamp.In(c.Timezone).Format("2006-01-02 15:04"))
if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `recent_activity.templ`, Line: 84, Col: 99}
}
- switch act.Object {
- case PublicationObject:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("publication: ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- case DatasetObject:
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("dataset: ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
+ templ_7745c5c3_Err = templ.Raw(generateActivityText(c, act, currentRecordID)).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- if act.Title != "" {
- var templ_7745c5c3_Var8 string
- templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(act.Title)
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `recent_activity.templ`, Line: 110, Col: 22}
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- } else {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Untitled record")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(".
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -294,7 +182,106 @@ func RecentActivity(c *ctx.Ctx, acts []Activity) templ.Component {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ return templ_7745c5c3_Err
+ })
+}
+
+func generateActivityText(c *ctx.Ctx, act Activity, currentRecordID *string) string {
+ sb := strings.Builder{}
+
+ if act.User != nil && act.User.ID == c.User.ID {
+ sb.WriteString("You")
+ } else if act.User != nil && c.Repo.CanCurate(act.User) && !c.Repo.CanCurate(c.User) {
+ sb.WriteString("A Biblio team member")
+ } else if act.User != nil {
+ sb.WriteString(act.User.FullName)
+ } else {
+ sb.WriteString("System")
+ }
+
+ sb.WriteString(" ")
+ sb.WriteString(activityEventTexts[act.Event])
+ sb.WriteString(" ")
+
+ isCurrentRecord := currentRecordID != nil && *currentRecordID == act.RecordID
+ if isCurrentRecord {
+ sb.WriteString("this")
+ } else {
+ sb.WriteString("a")
+ }
+
+ if act.Event == CreateEvent {
+ sb.WriteString(" ")
+ sb.WriteString(c.Loc.Get("activity_statuses." + act.Status))
+ }
+
+ sb.WriteString(" ")
+
+ switch act.Object {
+ case PublicationObject:
+ sb.WriteString("publication")
+ case DatasetObject:
+ sb.WriteString("dataset")
+ }
+
+ if !isCurrentRecord {
+ sb.WriteString(": ")
+ titleLink(act).Render(context.Background(), &sb)
+ }
+
+ sb.WriteString(".")
+
+ return sb.String()
+}
+
+func titleLink(act Activity) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var6 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var6 == nil {
+ templ_7745c5c3_Var6 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if act.Title != "" {
+ var templ_7745c5c3_Var8 string
+ templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(act.Title)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `recent_activity.templ`, Line: 149, Col: 14}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ } else {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Untitled record")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}