mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-03 16:10:26 +00:00
[activity] bugfix & improvement
This commit is contained in:
@@ -813,11 +813,11 @@
|
|||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</script>
|
</script>
|
||||||
<script type="text/template" id="activity-group-tmpl">
|
<script type="text/template" id="activity-group-hd-tmpl">
|
||||||
<div>
|
|
||||||
<h4 class="activity-group-hd"><%= date %></h4>
|
<h4 class="activity-group-hd"><%= date %></h4>
|
||||||
|
</script>
|
||||||
|
<script type="text/template" id="activity-group-bd-tmpl">
|
||||||
<ol class="activity-group-bd"></ol>
|
<ol class="activity-group-bd"></ol>
|
||||||
</div>
|
|
||||||
</script>
|
</script>
|
||||||
<script type="text/template" id="activity-item-tmpl">
|
<script type="text/template" id="activity-item-tmpl">
|
||||||
<%= activity.avatar %>
|
<%= activity.avatar %>
|
||||||
|
@@ -1913,14 +1913,18 @@ def repo_history_changes(request, repo_id):
|
|||||||
|
|
||||||
repo = get_repo(repo_id)
|
repo = get_repo(repo_id)
|
||||||
if not repo:
|
if not repo:
|
||||||
return HttpResponse(json.dumps(changes), content_type=content_type)
|
err_msg = _(u'Library does not exist.')
|
||||||
|
return HttpResponse(json.dumps({'error': err_msg}),
|
||||||
|
status=400, content_type=content_type)
|
||||||
|
|
||||||
# perm check
|
# perm check
|
||||||
if check_repo_access_permission(repo.id, request.user) is None:
|
if check_repo_access_permission(repo.id, request.user) is None:
|
||||||
if request.user.is_staff is True:
|
if request.user.is_staff is True:
|
||||||
pass # Allow system staff to check repo changes
|
pass # Allow system staff to check repo changes
|
||||||
else:
|
else:
|
||||||
return HttpResponse(json.dumps(changes), content_type=content_type)
|
err_msg = _(u"Permission denied")
|
||||||
|
return HttpResponse(json.dumps({"error": err_msg}), status=403,
|
||||||
|
content_type=content_type)
|
||||||
|
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
try:
|
try:
|
||||||
@@ -1932,11 +1936,15 @@ def repo_history_changes(request, repo_id):
|
|||||||
if repo.encrypted and \
|
if repo.encrypted and \
|
||||||
(repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
|
(repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
|
||||||
and not is_passwd_set(repo_id, username):
|
and not is_passwd_set(repo_id, username):
|
||||||
return HttpResponse(json.dumps(changes), content_type=content_type)
|
err_msg = _(u'Library is encrypted.')
|
||||||
|
return HttpResponse(json.dumps({'error': err_msg}),
|
||||||
|
status=403, content_type=content_type)
|
||||||
|
|
||||||
commit_id = request.GET.get('commit_id', '')
|
commit_id = request.GET.get('commit_id', '')
|
||||||
if not commit_id:
|
if not commit_id:
|
||||||
return HttpResponse(json.dumps(changes), content_type=content_type)
|
err_msg = _(u'Argument missing')
|
||||||
|
return HttpResponse(json.dumps({'error': err_msg}),
|
||||||
|
status=400, content_type=content_type)
|
||||||
|
|
||||||
changes = get_diff(repo_id, '', commit_id)
|
changes = get_diff(repo_id, '', commit_id)
|
||||||
|
|
||||||
|
@@ -12,11 +12,8 @@ define([
|
|||||||
|
|
||||||
el: $('#activities'),
|
el: $('#activities'),
|
||||||
|
|
||||||
activityGroupTemplate: _.template($('#activity-group-tmpl').html()),
|
activityGroupHdTemplate: _.template($('#activity-group-hd-tmpl').html()),
|
||||||
|
activityGroupBdTemplate: _.template($('#activity-group-bd-tmpl').html()),
|
||||||
events: {
|
|
||||||
'click #activities-more': 'getMoreActivities'
|
|
||||||
},
|
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.activities = new ActivityCollection();
|
this.activities = new ActivityCollection();
|
||||||
@@ -28,6 +25,10 @@ define([
|
|||||||
this.moreOffset = 0;
|
this.moreOffset = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
events: {
|
||||||
|
'click #activities-more': 'getMoreActivities'
|
||||||
|
},
|
||||||
|
|
||||||
getMoreActivities: function () {
|
getMoreActivities: function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.$loadingTip.show();
|
this.$loadingTip.show();
|
||||||
@@ -56,18 +57,20 @@ define([
|
|||||||
allActivities = allActivities.concat(activitiesJson[i]['events']);
|
allActivities = allActivities.concat(activitiesJson[i]['events']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return sth. like {2015-07-27: [{...},], 2015-06-04: [{...}] ...}
|
||||||
var groupedActivities = _.groupBy(allActivities, 'date');
|
var groupedActivities = _.groupBy(allActivities, 'date');
|
||||||
|
|
||||||
|
var $groupDate, $groupActivities;
|
||||||
for (var date in groupedActivities) {
|
for (var date in groupedActivities) {
|
||||||
var $activityGroup = $(this.activityGroupTemplate({'date': date})),
|
$groupDate = $(this.activityGroupHdTemplate({'date': date}));
|
||||||
activityList = groupedActivities[date];
|
$groupActivities = $(this.activityGroupBdTemplate());
|
||||||
|
|
||||||
this.$activitiesBody.append($activityGroup);
|
_.each(groupedActivities[date], function(activity) {
|
||||||
|
|
||||||
_.each(activityList, function (activity) {
|
|
||||||
var view = new ActivityItemView(activity);
|
var view = new ActivityItemView(activity);
|
||||||
$activityGroup.children('ol').append(view.render().el);
|
$groupActivities.append(view.render().el);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.$activitiesBody.append($groupDate).append($groupActivities);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (more) {
|
if (more) {
|
||||||
|
@@ -24,37 +24,76 @@ define([
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDetails: function () {
|
getDetails: function () {
|
||||||
var repo_id = this.repo_id, cmmt_id = this.cmmt_id,
|
var _this = this;
|
||||||
details_title, item_data, item_html,
|
|
||||||
_this = this;
|
|
||||||
|
|
||||||
Common.ajaxGet({
|
Common.ajaxGet({
|
||||||
get_url: Common.getUrl({ name:'get_history_changes', repo_id: repo_id}),
|
get_url: Common.getUrl({
|
||||||
data: {'commit_id': cmmt_id},
|
name:'get_history_changes',
|
||||||
|
repo_id: this.repo_id
|
||||||
|
}),
|
||||||
|
data: {'commit_id': this.cmmt_id},
|
||||||
after_op_success: function (data) {
|
after_op_success: function (data) {
|
||||||
_this.$('.loading-tip').hide();
|
_this.$('.loading-tip').hide();
|
||||||
_this.$('.commit-time').html(data['date_time']);
|
_this.$('.commit-time').html(data['date_time']);
|
||||||
|
|
||||||
for (var item in data) {
|
var showDetails = function(params) {
|
||||||
if (item == "cmt_desc") {
|
_this.$el.append(_this.detailItemTemplate({
|
||||||
_this.$el.append(data[item]);
|
"details_title": params.title,
|
||||||
} else if (data[item].length > 0 && item != 'date_time') {
|
"details": params.content
|
||||||
if (item == "new") { details_title = gettext("New files") }
|
}));
|
||||||
if (item == "removed") { details_title = gettext("Deleted files") }
|
};
|
||||||
if (item == "renamed") { details_title = gettext("Renamed or Moved files") }
|
if (data['new'].length > 0) {
|
||||||
if (item == "modified") { details_title = gettext("Modified files") }
|
showDetails({
|
||||||
if (item == "newdir") { details_title = gettext("New directories") }
|
'title': gettext("New files"),
|
||||||
if (item == "deldir") { details_title = gettext("Deleted directories") }
|
'content': data['new']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data['removed'].length > 0) {
|
||||||
|
showDetails({
|
||||||
|
'title': gettext("Deleted files"),
|
||||||
|
'content': data['removed']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data['renamed'].length > 0) {
|
||||||
|
showDetails({
|
||||||
|
'title': gettext("Renamed or Moved files"),
|
||||||
|
'content': data['renamed']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data['modified'].length > 0) {
|
||||||
|
showDetails({
|
||||||
|
'title': gettext("Modified files"),
|
||||||
|
'content': data['modified']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data['newdir'].length > 0) {
|
||||||
|
showDetails({
|
||||||
|
'title': gettext("New directories"),
|
||||||
|
'content': data['newdir']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data['deldir'].length > 0) {
|
||||||
|
showDetails({
|
||||||
|
'title': gettext("Deleted directories"),
|
||||||
|
'content': data['deldir']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
item_data = {"details_title": details_title, "details": data[item]};
|
// most of the time, no 'cmt_desc'
|
||||||
item_html = _this.detailItemTemplate(item_data);
|
if (data['cmt_desc']) {
|
||||||
_this.$el.append(item_html);
|
_this.$el.append('<p>' + Common.HTMLescape(data['cmt_desc']) + '</p>');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).resize();
|
$(window).resize();
|
||||||
},
|
},
|
||||||
after_op_error: function() {
|
after_op_error: function(xhr) {
|
||||||
$('#ls-ch').html(gettext("Unknown error"));
|
var err_msg;
|
||||||
|
if (xhr.responseText) {
|
||||||
|
err_msg = $.parseJSON(xhr.responseText).error;
|
||||||
|
} else {
|
||||||
|
err_msg = gettext("Failed. Please check the network.");
|
||||||
|
}
|
||||||
|
_this.$el.html('<p class="error">' + err_msg + '</p>');
|
||||||
setTimeout(function() { $.modal.close(); }, 2500);
|
setTimeout(function() { $.modal.close(); }, 2500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user