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