mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 00:00:00 +00:00
added 'more' for events
This commit is contained in:
@@ -774,6 +774,20 @@ textarea:-moz-placeholder {/* for FF */
|
||||
.event-item .avatar {
|
||||
border-radius:3px;
|
||||
}
|
||||
#events-loading,
|
||||
#events-more {
|
||||
text-align:center;
|
||||
width:610px;
|
||||
margin-left:60px;
|
||||
}
|
||||
#events-more {
|
||||
color:#777;
|
||||
padding:.5em 0;
|
||||
}
|
||||
#events-more:hover {
|
||||
color:#000;
|
||||
background:#dfdfdf;
|
||||
}
|
||||
/* avatar */
|
||||
.avatar-op .avatar,
|
||||
.home-profile .avatar,
|
||||
|
@@ -38,7 +38,7 @@ from seahub.forms import RepoCreateForm, SharedRepoCreateForm
|
||||
import seahub.settings as seahub_settings
|
||||
from seahub.utils import render_error, render_permission_error, gen_token, \
|
||||
validate_group_name, string2list, calculate_repo_last_modify, MAX_INT, \
|
||||
EVENTS_ENABLED, get_org_user_events, get_starred_files
|
||||
EVENTS_ENABLED, get_starred_files
|
||||
from seahub.views import myhome
|
||||
from seahub.signals import repo_created
|
||||
|
||||
@@ -159,9 +159,9 @@ def org_personal(request, url_prefix):
|
||||
|
||||
# events
|
||||
if EVENTS_ENABLED:
|
||||
events = get_org_user_events(org.org_id, user)
|
||||
events = True
|
||||
else:
|
||||
events = None
|
||||
events = False
|
||||
|
||||
quota_usage = seafserv_threaded_rpc.get_org_user_quota_usage(org.org_id, user)
|
||||
starred_files = get_starred_files(user, org_id=org.org_id)
|
||||
|
@@ -1,67 +1,9 @@
|
||||
{% load seahub_tags avatar_tags group_avatar_tags i18n %}
|
||||
{% load url from future %}
|
||||
{% load i18n %}
|
||||
<h3>{% trans 'Recent Events' %}</h3>
|
||||
<ul id="events" class="hide">
|
||||
{% for ev in events %}
|
||||
<li class="event-item w100 ovhd">
|
||||
{% if ev.etype == 'repo-update' %}
|
||||
{% with author=ev.commit.creator_name commit=ev.commit repo=ev.repo %}
|
||||
<div class="pic fleft" data="{{ author }}">
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{% avatar author 40 %}</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<div class="event-hd">
|
||||
<span class="time">{{ commit.ctime|translate_seahub_time }}</span>
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{{ author|email2nickname }}</a>
|
||||
</div>
|
||||
<p>{% trans 'Updated library' %} <a href="{{SITE_ROOT}}repo/{{repo.id}}">{{ repo.name }}</a></p>
|
||||
<p class="commit-msg ovhd">{{ commit.desc|translate_commit_desc }}
|
||||
{% if repo.encrypted %}
|
||||
{% if repo.password_set %}
|
||||
<a class="lsch-encrypted" password_set="true" href="{{ SITE_ROOT }}repo/history/changes/{{ repo.id }}/?commit_id={{ commit.id }}" repo_id="{{repo.id}}" repo_name="{{repo.name}}" data="{{ commit.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
|
||||
{% else %}
|
||||
<a class="lsch-encrypted" password_set="false" href="{{ SITE_ROOT }}repo/history/changes/{{ repo.id }}/?commit_id={{ commit.id }}" repo_id="{{repo.id}}" repo_name="{{repo.name}}" data="{{ commit.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a class="lsch" href="{{ SITE_ROOT }}repo/history/changes/{{ repo.id }}/?commit_id={{ commit.id }}" data="{{ commit.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% if ev.etype == 'repo-create' %}
|
||||
{% with author=ev.creator repo_id=ev.repo_id repo_name=ev.repo_name %}
|
||||
<div class="pic fleft" data="{{ author }}">
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{% avatar author 40 %}</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<div class="event-hd">
|
||||
<span class="time">{{ ev.timestamp|translate_seahub_time }}</span>
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{{ author|email2nickname }}</a>
|
||||
</div>
|
||||
<p>{% trans 'Created library' %} <a href="{{SITE_ROOT}}repo/{{repo_id}}">{{ repo_name }}</a></p>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% if ev.etype == 'repo-delete' %}
|
||||
{% with author=ev.repo_owner repo_name=ev.repo_name %}
|
||||
<div class="pic fleft" data="{{ author }}">
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{% avatar author 40 %}</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<div class="event-hd">
|
||||
<span class="time">{{ ev.timestamp|translate_seahub_time }}</span>
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{{ author|email2nickname }}</a>
|
||||
</div>
|
||||
<p>{% trans 'Deleted library' %} {{ repo_name }}</p>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<ul id="events" class="hide"></ul>
|
||||
<div id="events-loading" class="hide"><img src="{{MEDIA_URL}}img/loading-icon.gif" alt="{% trans 'Loading...' %}" /></div>
|
||||
<button id="events-more" class="hide">{% trans 'More' %}</button>
|
||||
<p id="events-error" class="error hide"></p>
|
||||
<form id="repo-set-password-form" class="hide">
|
||||
<h3>{% trans 'Library' %} <span class="repo-name"></span> {% trans 'is encrypted' %}</h3>
|
||||
<input type="hidden" name="repo_id" value="" />
|
||||
|
58
templates/snippets/events_.html
Normal file
58
templates/snippets/events_.html
Normal file
@@ -0,0 +1,58 @@
|
||||
{% load seahub_tags avatar_tags i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% for ev in events %}
|
||||
<li class="event-item w100 ovhd">
|
||||
{% if ev.etype == 'repo-update' %}
|
||||
{% with author=ev.commit.creator_name commit=ev.commit repo=ev.repo %}
|
||||
<div class="pic fleft" data="{{ author }}">
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{% avatar author 40 %}</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<div class="event-hd">
|
||||
<span class="time">{{ commit.ctime|translate_seahub_time }}</span>
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{{ author|email2nickname }}</a>
|
||||
</div>
|
||||
<p>{% trans 'Updated library' %} <a href="{% url 'repo' repo.id %}">{{ repo.name }}</a></p>
|
||||
<p class="commit-msg ovhd">{{ commit.desc|translate_commit_desc }}
|
||||
{% if repo.encrypted %}
|
||||
<a class="lsch-encrypted"{% if repo.password_set %} data-passwordset="true"{% endif %} href="{% url 'repo_history_changes' repo.id %}?commit_id={{ commit.id }}" data-repoid="{{repo.id}}" data-reponame="{{repo.name}}" data="{{ commit.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
|
||||
{% else %}
|
||||
<a class="lsch" href="{% url 'repo_history_changes' repo.id %}?commit_id={{ commit.id }}" data="{{ commit.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% if ev.etype == 'repo-create' %}
|
||||
{% with author=ev.creator repo_id=ev.repo_id repo_name=ev.repo_name %}
|
||||
<div class="pic fleft" data="{{ author }}">
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{% avatar author 40 %}</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<div class="event-hd">
|
||||
<span class="time">{{ ev.timestamp|translate_seahub_time }}</span>
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{{ author|email2nickname }}</a>
|
||||
</div>
|
||||
<p>{% trans 'Created library' %} <a href="{% url 'repo' repo_id %}">{{ repo_name }}</a></p>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% if ev.etype == 'repo-delete' %}
|
||||
{% with author=ev.repo_owner repo_name=ev.repo_name %}
|
||||
<div class="pic fleft" data="{{ author }}">
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{% avatar author 40 %}</a>
|
||||
</div>
|
||||
<div class="txt fright">
|
||||
<div class="event-hd">
|
||||
<span class="time">{{ ev.timestamp|translate_seahub_time }}</span>
|
||||
<a href="{% url 'user_profile' author %}" title="{{ author|email2nickname}}">{{ author|email2nickname }}</a>
|
||||
</div>
|
||||
<p>{% trans 'Deleted library' %} {{ repo_name }}</p>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
@@ -1,30 +1,71 @@
|
||||
{% include 'snippets/list_commit_detail.html' %}
|
||||
$('.event-item').each(function(index) {
|
||||
if (index > 0 && $(this).children('.pic').attr('data') == $(this).prev().children('.pic').attr('data')) {
|
||||
$(this).children('.pic').addClass('hide');
|
||||
}
|
||||
});
|
||||
$('#events').removeClass('hide');
|
||||
{% load i18n %}
|
||||
function reqEvents(start) {
|
||||
$('#events-loading').removeClass('hide');
|
||||
$.ajax({
|
||||
url:'{{SITE_ROOT}}events/?start=' + start{% if org %} + '&org_id={{ org.org_id }}'{% endif %},
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
$('#events').append(data['html']);
|
||||
|
||||
// 查看加密 repo 的详情时, 先为其设置密码
|
||||
var cur_event;
|
||||
$('a.lsch-encrypted').click(function() {
|
||||
if ($(this).attr('password_set') == 'true') {
|
||||
list_commit_change($(this));
|
||||
} else {
|
||||
cur_event = $(this);
|
||||
$('#repo-set-password-form input[name="repo_id"]').val($(this).attr('repo_id'));
|
||||
$('#repo-set-password-form .repo-name').html($(this).attr('repo_name'));
|
||||
$('#repo-set-password-form').modal({appendTo:'#main'});
|
||||
}
|
||||
return false;
|
||||
$('.event-item').each(function(index) {
|
||||
if (index > 0 && $(this).children('.pic').attr('data') == $(this).prev().children('.pic').attr('data')) {
|
||||
$(this).children('.pic').addClass('hide');
|
||||
}
|
||||
});
|
||||
if (start == 0) {
|
||||
$('#events').removeClass('hide');
|
||||
}
|
||||
|
||||
$('#events-loading').addClass('hide');
|
||||
|
||||
if (data['more']) {
|
||||
$('#events-more').data('start', start + 10).removeClass('hide');
|
||||
} else {
|
||||
$('#events-more').addClass('hide');
|
||||
}
|
||||
|
||||
// 查看加密 repo 的详情时, 先为其设置密码
|
||||
$('a.lsch-encrypted').click(function() {
|
||||
if ($(this).data('passwordset')) {
|
||||
list_commit_change($(this));
|
||||
} else {
|
||||
$('#repo-set-password-form input[name="repo_id"]').val($(this).data('repoid'));
|
||||
$('#repo-set-password-form .repo-name').html($(this).data('reponame'));
|
||||
$('#repo-set-password-form').data('cur_event', $(this)).modal({appendTo:'#main'});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$('.lsch').click(function() {
|
||||
list_commit_change($(this));
|
||||
return false;
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
var str = '{% trans "Unknown error." %}';
|
||||
if ($('#events-more').hasClass('hide')) {
|
||||
str += '{% trans "Please refresh the page later." %}';
|
||||
} else {
|
||||
str += '{% trans "Please try again later." %}';
|
||||
}
|
||||
$('#events-error').html(str).removeClass('hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
reqEvents(0);
|
||||
$('#events-more').click(function() {
|
||||
$(this).addClass('hide');
|
||||
reqEvents($(this).data('start'));
|
||||
});
|
||||
|
||||
{% include 'snippets/list_commit_detail.html' %}
|
||||
|
||||
$('#repo-set-password-form .submit').click(function() {
|
||||
var input_password = $('#repo-set-password-form input[name="password"]');
|
||||
var repo_id = $('#repo-set-password-form input[name="repo_id"]').val();
|
||||
var password = input_password.val();
|
||||
if (!password) {
|
||||
apply_form_error('repo-set-password-form', "密码不能为空");
|
||||
apply_form_error('repo-set-password-form', '{% trans "Password is required." %}');
|
||||
} else {
|
||||
apply_form_error('repo-set-password-form', '');
|
||||
$.ajax({
|
||||
@@ -41,15 +82,15 @@ $('#repo-set-password-form .submit').click(function() {
|
||||
success: function(data) {
|
||||
if (data['success']) {
|
||||
$.modal.close();
|
||||
$('a.lsch-encrypted[repo_id="' + repo_id + '"]').attr('password_set', 'true');
|
||||
list_commit_change(cur_event);
|
||||
$('a.lsch-encrypted[data-repoid="' + repo_id + '"]').attr('data-passwordset', true);
|
||||
list_commit_change($('#repo-set-password-form').data('cur_event'));
|
||||
} else {
|
||||
input_password.val('');
|
||||
apply_form_error('repo-set-password-form', data['error']);
|
||||
}
|
||||
},
|
||||
error: function(data, textStatus, jqXHR) {
|
||||
apply_form_error('repo-set-password-form', '访问网站出错');
|
||||
apply_form_error('repo-set-password-form', '{% trans "Unknown error." %}');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
<!-- <script type="text/javascript"> -->
|
||||
{% load i18n %}
|
||||
function get_commit_diff(url, callback) {
|
||||
$.ajax({
|
||||
|
3
urls.py
3
urls.py
@@ -51,7 +51,7 @@ urlpatterns = patterns('',
|
||||
url(r'^repo/history/view/(?P<repo_id>[^/]+)/$', RepoHistoryView.as_view(), name='repo_history_view'),
|
||||
url(r'^repo/recycle/(?P<repo_id>[^/]+)/$', repo_recycle_view, name='repo_recycle_view'),
|
||||
url(r'^repo/snapshot/view/(?P<repo_id>[^/]+)/$', repo_view_snapshot, name='repo_view_snapshot'),
|
||||
(r'^repo/history/changes/(?P<repo_id>[^/]+)/$', repo_history_changes),
|
||||
url(r'^repo/history/changes/(?P<repo_id>[^/]+)/$', repo_history_changes, name='repo_history_changes'),
|
||||
(r'^repo/remove/(?P<repo_id>[^/]+)/$', repo_remove),
|
||||
url(r'^repo/(?P<repo_id>[^/]+)/files/$', repo_view_file, name="repo_view_file"),
|
||||
(r'^repo/(?P<repo_id>[^/]+)/file/edit/$', repo_file_edit),
|
||||
@@ -60,6 +60,7 @@ urlpatterns = patterns('',
|
||||
url(r'^f/(?P<token>[^/]+)/$', view_shared_file, name='view_shared_file'),
|
||||
(r'^file_upload_progress_page/$', file_upload_progress_page),
|
||||
(r'^publicrepo/create/$', public_repo_create),
|
||||
(r'^events/$', events),
|
||||
(r'^file_comment/$', file_comment),
|
||||
(r'^pdf_full_view/$', pdf_full_view),
|
||||
(r'^pubinfo/$', pubinfo),
|
||||
|
8
utils.py
8
utils.py
@@ -451,9 +451,9 @@ if hasattr(settings, 'EVENTS_CONFIG_FILE'):
|
||||
EVENTS_ENABLED = True
|
||||
SeafEventsSession = seafevents.init_db_session_class(settings.EVENTS_CONFIG_FILE)
|
||||
|
||||
def get_user_events(username):
|
||||
def get_user_events(username, start):
|
||||
ev_session = SeafEventsSession()
|
||||
events = seafevents.get_user_events(ev_session, username, 0, 10)
|
||||
events = seafevents.get_user_events(ev_session, username, start, start + 11)
|
||||
ev_session.close()
|
||||
for ev in events:
|
||||
if ev.etype == 'repo-update':
|
||||
@@ -468,10 +468,10 @@ if hasattr(settings, 'EVENTS_CONFIG_FILE'):
|
||||
|
||||
return events
|
||||
|
||||
def get_org_user_events(org_id, username):
|
||||
def get_org_user_events(org_id, username, start):
|
||||
ev_session = SeafEventsSession()
|
||||
events = seafevents.get_org_user_events(ev_session, \
|
||||
org_id, username, 0, 10)
|
||||
org_id, username, start, start + 11)
|
||||
ev_session.close()
|
||||
for ev in events:
|
||||
if ev.etype == 'repo-update':
|
||||
|
25
views.py
25
views.py
@@ -70,7 +70,7 @@ from utils import render_permission_error, render_error, list_to_string, \
|
||||
get_file_revision_id_size, get_ccnet_server_addr_port, \
|
||||
gen_file_get_url, string2list, MAX_INT, \
|
||||
gen_file_upload_url, check_and_get_org_by_repo, \
|
||||
get_file_contributors, EVENTS_ENABLED, get_user_events, \
|
||||
get_file_contributors, EVENTS_ENABLED, get_user_events, get_org_user_events, \
|
||||
get_starred_files, star_file, unstar_file, is_file_starred
|
||||
try:
|
||||
from settings import DOCUMENT_CONVERTOR_ROOT
|
||||
@@ -915,7 +915,7 @@ def myhome(request):
|
||||
|
||||
# events
|
||||
if EVENTS_ENABLED:
|
||||
events = get_user_events(request.user.username)
|
||||
events = True
|
||||
else:
|
||||
events = None
|
||||
|
||||
@@ -2679,3 +2679,24 @@ def repo_download_dir(request, repo_id):
|
||||
url = gen_file_get_url(token, filename)
|
||||
|
||||
return redirect(url)
|
||||
|
||||
def events(request):
|
||||
username = request.user.username
|
||||
start = int(request.GET.get('start', 0))
|
||||
if request.cloud_mode:
|
||||
org_id = request.GET.get('org_id')
|
||||
events = get_org_user_events(org_id, username, start)
|
||||
else:
|
||||
events = get_user_events(username, start)
|
||||
|
||||
events_more = False
|
||||
if len(events) == 11:
|
||||
events_more = True
|
||||
events = events[:10]
|
||||
|
||||
ctx = {}
|
||||
ctx['events'] = events
|
||||
html = render_to_string("snippets/events_.html", ctx)
|
||||
|
||||
return HttpResponse(json.dumps({'html':html, 'more':events_more}),
|
||||
content_type='application/json; charset=utf-8')
|
||||
|
Reference in New Issue
Block a user