diff --git a/server/activity_handler.go b/server/activity_handler.go index 7f883f1..fc45567 100644 --- a/server/activity_handler.go +++ b/server/activity_handler.go @@ -16,7 +16,21 @@ type jsonResponse struct { func ActivityHandler(db Database) echo.HandlerFunc { return func(c echo.Context) error { - activity, next, err := db.Activity(LocaleForRequest(c.Request()), c.QueryParam("next"), 50) + locale := LocaleForRequest(c.Request()) + filter := func(a Activity) bool { + return true + } + if c.QueryParam("nohelp") == "true" { + filter = func(a Activity) bool { + if fp, ok := a.(*ForumPost); ok { + if fp.ForumId == locale.HelpForumId { + return false + } + } + return true + } + } + activity, next, err := db.Activity(locale, c.QueryParam("next"), 50, filter) if err != nil { return err } diff --git a/server/bolt_database.go b/server/bolt_database.go index 5a83aec..5b23285 100644 --- a/server/bolt_database.go +++ b/server/bolt_database.go @@ -43,7 +43,7 @@ func (db *BoltDatabase) AddActivity(activity []Activity) error { }) } -func (db *BoltDatabase) Activity(locale *Locale, start string, count int) ([]Activity, string, error) { +func (db *BoltDatabase) Activity(locale *Locale, start string, count int, filter func(a Activity) bool) ([]Activity, string, error) { ret := []Activity(nil) next := "" if err := db.db.View(func(tx *bolt.Tx) error { @@ -66,7 +66,7 @@ func (db *BoltDatabase) Activity(locale *Locale, start string, count int) ([]Act activity, err := unmarshalActivity(k, v) if err != nil { return err - } else if activity != nil && locale.ActivityFilter(activity) { + } else if activity != nil && locale.ActivityFilter(activity) && filter(activity) { ret = append(ret, activity) next = base64.RawURLEncoding.EncodeToString(k) } diff --git a/server/database.go b/server/database.go index e144320..8118b45 100644 --- a/server/database.go +++ b/server/database.go @@ -17,7 +17,7 @@ const ( type Database interface { AddActivity(activity []Activity) error - Activity(locale *Locale, start string, count int) ([]Activity, string, error) + Activity(locale *Locale, start string, count int, filter func(a Activity) bool) ([]Activity, string, error) Close() error } diff --git a/server/database_test.go b/server/database_test.go index 6654c54..4193c8b 100644 --- a/server/database_test.go +++ b/server/database_test.go @@ -31,21 +31,23 @@ func testDatabase_ForumPosts(t *testing.T, db Database) { db.AddActivity([]Activity{post1, post2}) - posts, next, err := db.Activity(locale, "", 1) + all := func(a Activity) bool { return true } + + posts, next, err := db.Activity(locale, "", 1, all) require.NoError(t, err) require.Equal(t, 1, len(posts)) assert.Equal(t, post1.Id, posts[0].(*ForumPost).Id) assert.Equal(t, post1.Poster, posts[0].(*ForumPost).Poster) assert.Equal(t, post1.Time.Unix(), posts[0].(*ForumPost).Time.Unix()) - posts, next, err = db.Activity(locale, next, 1) + posts, next, err = db.Activity(locale, next, 1, all) require.NoError(t, err) require.Equal(t, 1, len(posts)) assert.Equal(t, post2.Id, posts[0].(*ForumPost).Id) assert.Equal(t, post2.Poster, posts[0].(*ForumPost).Poster) assert.Equal(t, post2.Time.Unix(), posts[0].(*ForumPost).Time.Unix()) - posts, _, err = db.Activity(locale, next, 1) + posts, _, err = db.Activity(locale, next, 1, all) require.NoError(t, err) require.Equal(t, 0, len(posts)) } diff --git a/server/dynamodb_database.go b/server/dynamodb_database.go index b339081..d498949 100644 --- a/server/dynamodb_database.go +++ b/server/dynamodb_database.go @@ -82,7 +82,7 @@ func (db *DynamoDBDatabase) AddActivity(activity []Activity) error { return nil } -func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int) ([]Activity, string, error) { +func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int, filter func(a Activity) bool) ([]Activity, string, error) { var activity []Activity var startKey map[string]dynamodb.AttributeValue @@ -120,7 +120,7 @@ func (db *DynamoDBDatabase) Activity(locale *Locale, start string, count int) ([ for _, item := range result.Items { if a, err := unmarshalActivity(item["rk"].B, item["v"].B); err != nil { return nil, "", err - } else if a != nil { + } else if a != nil && filter(a) { activity = append(activity, a) } } diff --git a/server/index_handler.go b/server/index_handler.go index f5ac837..927177e 100644 --- a/server/index_handler.go +++ b/server/index_handler.go @@ -43,6 +43,7 @@ var index = `
 
             | ').attr('colspan', 6).text('Loading...'))) + } + + $.get('activity.json?next=' + page + '&nohelp=' + nohelp, function(data) { var $tbody = $('#activity-table tbody'); $tbody.empty(); @@ -135,7 +141,21 @@ function loadActivity() { $tbody.append($tr); } - $('#activity-nav').empty().append($('').text('Next Page').attr('href', '#page=' + data.next).click(function() { + var nohelpText; + var nohelpHref; + if (nohelp != 'true') { + nohelpText = 'Hide Help Forum'; + nohelpHref = '#page=' + page + '&nohelp=true'; + } else { + nohelpText = 'Show Help Forum'; + nohelpHref = '#page=' + page + '&nohelp=false'; + } + $('#help-toggle').empty().append($('').text(nohelpText).attr('href', nohelpHref).click(function() { + currentPage = undefined; + window.scrollTo(0, 0); + })); + + $('#activity-nav').empty().append($('').text('Next Page').attr('href', '#page=' + data.next + '&nohelp=' + nohelp).click(function() { window.scrollTo(0, 0); })); }).fail(function() { diff --git a/server/static/style.css b/server/static/style.css index 1a5cf08..f6714c3 100644 --- a/server/static/style.css +++ b/server/static/style.css @@ -99,6 +99,12 @@ div.container { opacity: 1.0; } +#help-toggle { + position: absolute; + top: 24px; + right: 50px; +} + div.content-box h1 { padding: 6px; padding-top: 0px; |