Skip to content

Commit

Permalink
[repo] online GC: improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
llj committed Oct 14, 2014
1 parent c0553b3 commit af0c749
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
3 changes: 3 additions & 0 deletions seahub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
# Enable or disable repo history setting
ENABLE_REPO_HISTORY_SETTING = True

# Enable or disable online GC for user, i.e., show 'clean' in repo trash page or not.
ENABLE_USER_CLEAN_HISTORY = False

# File preview
FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024
OFFICE_PREVIEW_MAX_SIZE = 2 * 1024 * 1024
Expand Down
45 changes: 23 additions & 22 deletions seahub/templates/repo_recycle_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<div class="w100 ovhd">
<h2 class="fleft">{{repo.props.name}} {% trans "'s trash" %}</h2>
<div class="fright">
{% if is_repo_owner and not use_sqlite %}
<button data="{% url 'repo' repo.id %}" id="online-gc">{% trans "Clean" %}</button>
{% if enable_clean %}
<button id="online-gc">{% trans "Clean" %}</button>
{% endif %}
<button data="{% url 'repo' repo.id %}" id="back">{% trans "Back to Library" %}</button>
</div>
Expand All @@ -19,11 +19,11 @@ <h2 class="fleft">{{repo.props.name}} {% trans "'s trash" %}</h2>
<div class="repo-file-list-topbar">
<span class="path">
{% trans "Current path: " %}
<a href="{% url 'repo_recycle_view' repo.id %}?days={{days}}">{{repo.props.name}} {% trans "'s trash" %}</a>
<a href="?days={{days}}">{{repo.props.name}} {% trans "'s trash" %}</a>
{% if not show_recycle_root %}
{% for name, link in zipped %}
{% if not forloop.last %}
/ <a href="{% url 'repo_recycle_view' repo.id %}?commit_id={{ commit_id }}&base={{ basedir|urlencode }}&p={{ link|urlencode }}&days={{days}}">{{ name }}</a>
/ <a href="?commit_id={{ commit_id }}&base={{ basedir|urlencode }}&p={{ link|urlencode }}&days={{days}}">{{ name }}</a>
{% else %}
/ {{ name }}
{% endif %}
Expand All @@ -34,17 +34,17 @@ <h2 class="fleft">{{repo.props.name}} {% trans "'s trash" %}</h2>
{% if show_recycle_root %}
<span class="fright">
{% if days != 7 %}
<a href="{% url 'repo_recycle_view' repo.id %}?days=7">{% trans "a week" %}</a> /
<a href="?days=7">{% trans "a week" %}</a> /
{% else %}
{% trans "a week" %} /
{% endif %}
{% if days != 30 %}
<a href="{% url 'repo_recycle_view' repo.id %}?days=30">{% trans "a month" %}</a> /
<a href="?days=30">{% trans "a month" %}</a> /
{% else %}
{% trans "a month" %} /
{% endif %}
{% if days != 0 %}
<a href="{% url 'repo_recycle_view' repo.id %}?days=0">{% trans "all" %}</a>
<a href="?days=0">{% trans "all" %}</a>
{% else %}
{% trans "all" %}
{% endif %}
Expand All @@ -65,12 +65,12 @@ <h2 class="fleft">{{repo.props.name}} {% trans "'s trash" %}</h2>
<tr>
<td class="alc"><img src="{{ MEDIA_URL }}img/folder-icon-24.png" alt="{% trans "Directory" %}" /></td>
{% if show_recycle_root %}
<td><a href="{% url 'repo_recycle_view' repo.id %}?commit_id={{ dirent.commit_id }}&base={{ dirent.basedir|urlencode }}&p=/{{ dirent.obj_name|urlencode }}&days={{days}}">{{ dirent.obj_name }}</a></td>
<td><a href="?commit_id={{ dirent.commit_id }}&base={{ dirent.basedir|urlencode }}&p=/{{ dirent.obj_name|urlencode }}&days={{days}}">{{ dirent.obj_name }}</a></td>
<td>{{ dirent.delete_time|translate_seahub_time }}</td>
<td></td>
<td><a class="op vh" href="{% url 'repo_revert_dir' repo.id %}?commit={{ dirent.commit_id }}&p={{ dirent.basedir|urlencode }}{{dirent.obj_name|urlencode}}">{% trans "Restore" %}</a></td>
{% else %}
<td><a href="{% url 'repo_recycle_view' repo.id %}?commit_id={{ commit_id }}&base={{ basedir|urlencode }}&p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}&days={{days}}">{{ dirent.obj_name }}</a></td>
<td><a href="?commit_id={{ commit_id }}&base={{ basedir|urlencode }}&p={{ path|urlencode }}{{ dirent.obj_name|urlencode }}&days={{days}}">{{ dirent.obj_name }}</a></td>
<td></td>
<td></td>
<td></td>
Expand Down Expand Up @@ -98,12 +98,16 @@ <h2 class="fleft">{{repo.props.name}} {% trans "'s trash" %}</h2>
</div>
</div>

{% if is_repo_owner and not use_sqlite %}
{% if enable_clean %}
<form id="gc-form" class="hide">
<h3>{% trans "Clean" %}</h3>
<p>{% trans "Clean items deleted before the following days:" %}</p>
<input type="text" name="day" class="input" value="" placeholder="{% trans "please input an integer greater than 0" %}" /><br />
<p class="error hide"></p>
<p>{% trans "Clear files in trash and history:" %}</p>
<select name="day" class="w100" style="margin-bottom:5px;">
<option value="3">{% trans "3 days ago" %}</option>
<option value="7">{% trans "1 week ago" %}</option>
<option value="30">{% trans "1 month ago" %}</option>
<option value="0">{% trans "all" %}</option>
</select>
<button type="submit" class="submit">{% trans "Submit" %}</button>
<button type="button" class="simplemodal-close">{% trans "Cancel" %}</button>
</form>
Expand All @@ -116,26 +120,23 @@ <h3>{% trans "Clean" %}</h3>
location.href = $(this).attr('data');
});

{% if is_repo_owner and not use_sqlite %}
{% if enable_clean %}
$('#online-gc').click(function() {
$('#gc-form').modal();
$('#gc-form').modal({focus:false});
$("#simplemodal-container").css({'height':'auto'});
});
$('#gc-form').submit(function () {
var form = $(this);
var day = parseInt($.trim($('[name="day"]', form).val())); // turn the string into int
if (!day || day < 0) { // day can be NaN, 0, -n
apply_form_error(form.attr('id'), "{% trans "Please input a valid number" %}");
return false;
}
var day = $('[name="day"]', form).val();
disable($('[type="submit"]', form));
form.append('<p style="color:#222;">' + "{% trans "It could take a while, you can close this popup now." %}" + '</p>');
$.ajax({
url: '{% url "repo_online_gc" repo.id %}?day=' + parseInt(day),
url: '{% url "repo_online_gc" repo.id %}?day=' + day,
dataType: 'json',
cache: false,
success: function () {
$.modal.close();
feedback("{% trans "Clean is done." %}", 'success');
location.reload();
},
error: function (xhr, textStatus, errorThrown) {
$.modal.close();
Expand Down
17 changes: 12 additions & 5 deletions seahub/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
from seahub.settings import FILE_PREVIEW_MAX_SIZE, INIT_PASSWD, USE_PDFJS, \
FILE_ENCODING_LIST, FILE_ENCODING_TRY_LIST, AVATAR_FILE_STORAGE, \
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER, SEND_EMAIL_ON_RESETTING_USER_PASSWD, \
ENABLE_SUB_LIBRARY, ENABLE_REPO_HISTORY_SETTING, REPO_PASSWORD_MIN_LENGTH
ENABLE_SUB_LIBRARY, ENABLE_REPO_HISTORY_SETTING, REPO_PASSWORD_MIN_LENGTH, \
ENABLE_USER_CLEAN_HISTORY

# Get an instance of a logger
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -314,14 +315,17 @@ def render_recycle_root(request, repo_id):
if 'sqlite' in db_backend:
use_sqlite = True

enable_clean = False
if is_repo_owner and not use_sqlite and ENABLE_USER_CLEAN_HISTORY:
enable_clean = True

return render_to_response('repo_recycle_view.html', {
'show_recycle_root': True,
'repo': repo,
'dir_list': dir_list,
'file_list': file_list,
'days': days,
'is_repo_owner': is_repo_owner,
'use_sqlite': use_sqlite,
'enable_clean': enable_clean,
}, context_instance=RequestContext(request))

def render_recycle_dir(request, repo_id, commit_id):
Expand Down Expand Up @@ -360,6 +364,10 @@ def render_recycle_dir(request, repo_id, commit_id):
if 'sqlite' in db_backend:
use_sqlite = True

enable_clean = False
if is_repo_owner and not use_sqlite and ENABLE_USER_CLEAN_HISTORY:
enable_clean = True

return render_to_response('repo_recycle_view.html', {
'show_recycle_root': False,
'repo': repo,
Expand All @@ -370,8 +378,7 @@ def render_recycle_dir(request, repo_id, commit_id):
'basedir': basedir,
'path': path,
'days': days,
'is_repo_owner': is_repo_owner,
'use_sqlite': use_sqlite,
'enable_clean': enable_clean,
}, context_instance=RequestContext(request))

@login_required
Expand Down
5 changes: 3 additions & 2 deletions seahub/views/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,8 +1832,9 @@ def repo_online_gc(request, repo_id):
content_type=content_type)

day = int(request.GET.get('day'))
if not day:
error = _('Argument missing')

if not settings.ENABLE_USER_CLEAN_HISTORY:
error = _('Not supported.')
return HttpResponse(json.dumps({'error': error}), status=400,
content_type=content_type)

Expand Down

0 comments on commit af0c749

Please sign in to comment.