mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 15:20:01 +01:00
dashboard/feeds: able to load more history (#2511)
This commit is contained in:
2
gogs.go
2
gogs.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.10.19.0316"
|
const APP_VER = "0.10.20.0316"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|||||||
@@ -671,14 +671,12 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error
|
|||||||
// GetFeeds returns action list of given user in given context.
|
// GetFeeds returns action list of given user in given context.
|
||||||
// actorID is the user who's requesting, ctxUserID is the user/org that is requested.
|
// actorID is the user who's requesting, ctxUserID is the user/org that is requested.
|
||||||
// actorID can be -1 when isProfile is true or to skip the permission check.
|
// actorID can be -1 when isProfile is true or to skip the permission check.
|
||||||
func GetFeeds(ctxUser *User, actorID int64, page int, isProfile bool) ([]*Action, error) {
|
func GetFeeds(ctxUser *User, actorID, afterID int64, isProfile bool) ([]*Action, error) {
|
||||||
if page <= 0 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
actions := make([]*Action, 0, setting.UI.User.NewsFeedPagingNum)
|
actions := make([]*Action, 0, setting.UI.User.NewsFeedPagingNum)
|
||||||
sess := x.Limit(setting.UI.User.NewsFeedPagingNum, (page-1)*setting.UI.User.NewsFeedPagingNum).
|
sess := x.Limit(setting.UI.User.NewsFeedPagingNum).Where("user_id = ?", ctxUser.ID).Desc("id")
|
||||||
Desc("id").Where("user_id = ?", ctxUser.ID)
|
if afterID > 0 {
|
||||||
|
sess.And("id < ?", afterID)
|
||||||
|
}
|
||||||
if isProfile {
|
if isProfile {
|
||||||
sess.And("is_private = ?", false).And("act_user_id = ?", ctxUser.ID)
|
sess.And("is_private = ?", false).And("act_user_id = ?", ctxUser.ID)
|
||||||
} else if actorID != -1 && ctxUser.IsOrganization() {
|
} else if actorID != -1 && ctxUser.IsOrganization() {
|
||||||
|
|||||||
@@ -1339,6 +1339,30 @@ $(document).ready(function () {
|
|||||||
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
|
e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// AJAX load buttons
|
||||||
|
$('.ajax-load-button').click(function () {
|
||||||
|
var $this = $(this);
|
||||||
|
$this.addClass('disabled');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: $this.data('url'),
|
||||||
|
headers: {
|
||||||
|
'X-AJAX': "true"
|
||||||
|
}
|
||||||
|
}).success(function (data, status, request) {
|
||||||
|
$(data).insertBefore($this);
|
||||||
|
|
||||||
|
// Update new URL or remove self if no more feeds
|
||||||
|
var url = request.getResponseHeader('X-AJAX-URL');
|
||||||
|
if (url) {
|
||||||
|
$this.data('url', url);
|
||||||
|
$this.removeClass('disabled');
|
||||||
|
} else {
|
||||||
|
$this.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Helpers.
|
// Helpers.
|
||||||
$('.delete-button').click(function () {
|
$('.delete-button').click(function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
DASHBOARD base.TplName = "user/dashboard/dashboard"
|
DASHBOARD base.TplName = "user/dashboard/dashboard"
|
||||||
|
NEWS_FEED base.TplName = "user/dashboard/feeds"
|
||||||
ISSUES base.TplName = "user/dashboard/issues"
|
ISSUES base.TplName = "user/dashboard/issues"
|
||||||
PROFILE base.TplName = "user/profile"
|
PROFILE base.TplName = "user/profile"
|
||||||
ORG_HOME base.TplName = "org/home"
|
ORG_HOME base.TplName = "org/home"
|
||||||
@@ -52,8 +53,8 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
|
|||||||
// retrieveFeeds loads feeds from database by given context user.
|
// retrieveFeeds loads feeds from database by given context user.
|
||||||
// The user could be organization so it is not always the logged in user,
|
// The user could be organization so it is not always the logged in user,
|
||||||
// which is why we have to explicitly pass the context user ID.
|
// which is why we have to explicitly pass the context user ID.
|
||||||
func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID int64, page int, isProfile bool) {
|
func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID int64, isProfile bool) {
|
||||||
actions, err := models.GetFeeds(ctxUser, userID, page, isProfile)
|
actions, err := models.GetFeeds(ctxUser, userID, ctx.QueryInt64("after_id"), isProfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetFeeds", err)
|
ctx.Handle(500, "GetFeeds", err)
|
||||||
return
|
return
|
||||||
@@ -81,6 +82,11 @@ func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID int64, pag
|
|||||||
feeds = append(feeds, act)
|
feeds = append(feeds, act)
|
||||||
}
|
}
|
||||||
ctx.Data["Feeds"] = feeds
|
ctx.Data["Feeds"] = feeds
|
||||||
|
if len(feeds) > 0 {
|
||||||
|
afterID := feeds[len(feeds)-1].ID
|
||||||
|
ctx.Data["AfterID"] = afterID
|
||||||
|
ctx.Header().Set("X-AJAX-URL", fmt.Sprintf("%s?after_id=%d", ctx.Data["Link"], afterID))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dashboard(ctx *context.Context) {
|
func Dashboard(ctx *context.Context) {
|
||||||
@@ -89,6 +95,16 @@ func Dashboard(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retrieveFeeds(ctx, ctxUser, ctx.User.ID, false)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Req.Header.Get("X-AJAX") == "true" {
|
||||||
|
ctx.HTML(200, NEWS_FEED)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard")
|
ctx.Data["Title"] = ctxUser.DisplayName() + " - " + ctx.Tr("dashboard")
|
||||||
ctx.Data["PageIsDashboard"] = true
|
ctx.Data["PageIsDashboard"] = true
|
||||||
ctx.Data["PageIsNews"] = true
|
ctx.Data["PageIsNews"] = true
|
||||||
@@ -143,10 +159,6 @@ func Dashboard(ctx *context.Context) {
|
|||||||
ctx.Data["MirrorCount"] = len(mirrors)
|
ctx.Data["MirrorCount"] = len(mirrors)
|
||||||
ctx.Data["Mirrors"] = mirrors
|
ctx.Data["Mirrors"] = mirrors
|
||||||
|
|
||||||
retrieveFeeds(ctx, ctxUser, ctx.User.ID, 1, false)
|
|
||||||
if ctx.Written() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.HTML(200, DASHBOARD)
|
ctx.HTML(200, DASHBOARD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func Profile(ctx *context.Context) {
|
|||||||
ctx.Data["TabName"] = tab
|
ctx.Data["TabName"] = tab
|
||||||
switch tab {
|
switch tab {
|
||||||
case "activity":
|
case "activity":
|
||||||
retrieveFeeds(ctx, ctxUser, -1, 0, true)
|
retrieveFeeds(ctx, ctxUser, -1, true)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.10.19.0316
|
0.10.20.0316
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
<div class="ten wide column">
|
<div class="ten wide column">
|
||||||
{{template "user/dashboard/feeds" .}}
|
{{template "user/dashboard/feeds" .}}
|
||||||
|
<button class="ui fluid basic button center ajax-load-button" data-url="{{.Link}}?after_id={{.AfterID}}">More</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="six wide column">
|
<div class="six wide column">
|
||||||
<div class="ui {{if not .ContextUser.IsOrganization}}three{{else}}two{{end}} item tabable menu">
|
<div class="ui {{if not .ContextUser.IsOrganization}}three{{else}}two{{end}} item tabable menu">
|
||||||
|
|||||||
@@ -89,4 +89,4 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
Reference in New Issue
Block a user