mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 22:01:06 +00:00
added func: source file edit
This commit is contained in:
1
media/ace/theme-twilight.js
Normal file
1
media/ace/theme-twilight.js
Normal file
@@ -0,0 +1 @@
|
||||
define("ace/theme/twilight",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!0,t.cssClass="ace-twilight",t.cssText=".ace-twilight .ace_editor { border: 2px solid rgb(159, 159, 159);}.ace-twilight .ace_editor.ace_focus { border: 2px solid #327fbd;}.ace-twilight .ace_gutter { background: #232323; color: #F8F8F8;}.ace-twilight .ace_print_margin { width: 1px; background: #232323;}.ace-twilight .ace_scroller { background-color: #141414;}.ace-twilight .ace_text-layer { color: #F8F8F8;}.ace-twilight .ace_cursor { border-left: 2px solid #A7A7A7;}.ace-twilight .ace_cursor.ace_overwrite { border-left: 0px; border-bottom: 1px solid #A7A7A7;}.ace-twilight .ace_marker-layer .ace_selection { background: rgba(221, 240, 255, 0.20);}.ace-twilight.multiselect .ace_selection.start { box-shadow: 0 0 3px 0px #141414; border-radius: 2px;}.ace-twilight .ace_marker-layer .ace_step { background: rgb(102, 82, 0);}.ace-twilight .ace_marker-layer .ace_bracket { margin: -1px 0 0 -1px; border: 1px solid rgba(255, 255, 255, 0.25);}.ace-twilight .ace_marker-layer .ace_active_line { background: rgba(255, 255, 255, 0.031);}.ace-twilight .ace_gutter_active_line { background-color: rgba(255, 255, 255, 0.031);}.ace-twilight .ace_marker-layer .ace_selected_word { border: 1px solid rgba(221, 240, 255, 0.20);}.ace-twilight .ace_invisible { color: rgba(255, 255, 255, 0.25);}.ace-twilight .ace_keyword, .ace-twilight .ace_meta { color:#CDA869;}.ace-twilight .ace_constant, .ace-twilight .ace_constant.ace_other { color:#CF6A4C;}.ace-twilight .ace_constant.ace_character, { color:#CF6A4C;}.ace-twilight .ace_constant.ace_character.ace_escape, { color:#CF6A4C;}.ace-twilight .ace_invalid.ace_illegal { color:#F8F8F8;background-color:rgba(86, 45, 86, 0.75);}.ace-twilight .ace_invalid.ace_deprecated { text-decoration:underline;font-style:italic;color:#D2A8A1;}.ace-twilight .ace_support { color:#9B859D;}.ace-twilight .ace_support.ace_constant { color:#CF6A4C;}.ace-twilight .ace_fold { background-color: #AC885B; border-color: #F8F8F8;}.ace-twilight .ace_support.ace_function { color:#DAD085;}.ace-twilight .ace_storage { color:#F9EE98;}.ace-twilight .ace_variable { color:#AC885B;}.ace-twilight .ace_string { color:#8F9D6A;}.ace-twilight .ace_string.ace_regexp { color:#E9C062;}.ace-twilight .ace_comment { font-style:italic;color:#5F5A60;}.ace-twilight .ace_variable { color:#7587A6;}.ace-twilight .ace_xml_pe { color:#494949;}.ace-twilight .ace_meta.ace_tag { color:#AC885B;}.ace-twilight .ace_entity.ace_name.ace_function { color:#AC885B;}.ace-twilight .ace_markup.ace_underline { text-decoration:underline;}.ace-twilight .ace_markup.ace_heading { color:#CF6A4C;}.ace-twilight .ace_markup.ace_list { color:#F9EE98;}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
@@ -742,7 +742,7 @@ p {
|
||||
}
|
||||
.file-op a {
|
||||
font-weight:normal;
|
||||
margin-right:2px;
|
||||
margin-left:2px;
|
||||
}
|
||||
.file-op button {
|
||||
color:#444;
|
||||
@@ -854,7 +854,19 @@ p {
|
||||
#md-view a {
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
#file-edit-form {
|
||||
margin-top:10px;
|
||||
}
|
||||
#file-edit-form label {
|
||||
margin:5px 0;
|
||||
}
|
||||
#file-edit-commit-msg,
|
||||
#file-edit-commit-details {
|
||||
width:75%;
|
||||
}
|
||||
#file-edit-commit-details {
|
||||
height:50px;
|
||||
}
|
||||
/* shareadmin */
|
||||
.view-link-alert p {
|
||||
display: inline-block;
|
||||
|
71
templates/repo_edit_file.html
Normal file
71
templates/repo_edit_file.html
Normal file
@@ -0,0 +1,71 @@
|
||||
{% extends base_template %}
|
||||
{% load seahub_tags %}
|
||||
|
||||
{% block main_panel %}
|
||||
<h2>{{ u_filename }}</h2>
|
||||
<div class="w100 ovhd">
|
||||
<p class="path fleft">
|
||||
当前路径:
|
||||
{% for name, link in zipped %}
|
||||
{% if not forloop.last %}
|
||||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> /
|
||||
{% else %}
|
||||
{{ name }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
|
||||
<div class="file-op fright">
|
||||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}">返回</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="file-view">
|
||||
<p>文件内容读取中...</p>
|
||||
</div>
|
||||
|
||||
<form action="post" method="post" id="file-edit-form">
|
||||
<input type="hidden" name="modified-file" />
|
||||
<label>修改信息:</label><br />
|
||||
<input type="text" name="commit-msg" id="file-edit-commit-msg" /><br />
|
||||
<label>更多描述:</label><br />
|
||||
<textarea name="commit-details" id="file-edit-commit-details"></textarea><br />
|
||||
<input type="submit" class="submit" value="提交" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_script %}
|
||||
<script type="text/javascript" src="{{MEDIA_URL}}ace/ace.js"></script>
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}ace/theme-twilight.js"></script>
|
||||
{% include "snippets/file_view_js.html" %}
|
||||
<script type="text/javascript">
|
||||
var url = "{{ SITE_ROOT }}repo/{{ repo.id }}/file/get/?p={{ path|urlencode }}&t={{ token }}&u={{ request.user.username }}";
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
$('#file-view').html('<div id="docu-view" class="vh">' + '</div>');
|
||||
editor = ace.edit("docu-view");
|
||||
$('#docu-view').removeClass('vh');
|
||||
editor.setShowPrintMargin(false); // rm the vertical line in the center
|
||||
editor.renderer.scrollBar.element.style.display = "none"; // hide right scrollbar
|
||||
editor.renderer.scrollBar.width = 0; // enlarge ace_content width
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
{% include "snippets/editor_set_mode.html" %}
|
||||
editor.session.getDocument().setValue(data['content']);
|
||||
$('#docu-view').css({'position': 'relative', 'height': editor.session.getScreenLength() * parseInt($('#docu-view').css('line-height'))});
|
||||
editor.session.setScrollLeft(0); // make bottom scrollbar start from the left-most
|
||||
editor.resize(); // fix some problem for showing some file in ie8
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
||||
$('#file-view').html('<p class="error">' + jsonVal['error'] + '</p>');
|
||||
}
|
||||
});
|
||||
|
||||
$('#file-edit-form').submit(function() {
|
||||
$(this).find('[name="modified-file"]').val(editor.session.getValue());
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@@ -37,6 +37,9 @@
|
||||
<div class="file-op fright">
|
||||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=view" target="_blank">查看原始文件</a>
|
||||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=download" target="_blank">下载文件</a>
|
||||
{% if filetype == 'Text' %}
|
||||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/file/edit/?p={{ path }}">编辑文件</a>
|
||||
{% endif %}
|
||||
<br />
|
||||
|
||||
{% if not view_history %}
|
||||
@@ -76,26 +79,19 @@ function hideLink() {
|
||||
$('#get-shared-link').removeClass('hide');
|
||||
}
|
||||
|
||||
{% if view_history %}
|
||||
var url = "{{ SITE_ROOT }}repo/{{ repo.id }}/file/get/?obj_id={{ obj_id }}&p={{ path|urlencode }}&t={{ token }}&u={{ request.user.username }}";
|
||||
{% else %}
|
||||
var url = "{{ SITE_ROOT }}repo/{{ repo.id }}/file/get/?p={{ path|urlencode }}&t={{ token }}&u={{ request.user.username }}";
|
||||
{% endif %}
|
||||
|
||||
$(window).load(function() {
|
||||
var view_history = '{{ view_history }}',
|
||||
url = '',
|
||||
t = '{{ fileshare.token }}';
|
||||
{% if fileshare.token %}
|
||||
showLink();
|
||||
{% else %}
|
||||
hideLink();
|
||||
{% endif %}
|
||||
|
||||
if (view_history == 'True') {
|
||||
url = "{{ SITE_ROOT }}repo/{{ repo.id }}/file/get/?obj_id={{ obj_id }}&p={{ path|urlencode }}&t={{ token }}&u={{ request.user.username }}";
|
||||
} else {
|
||||
url = "{{ SITE_ROOT }}repo/{{ repo.id }}/file/get/?p={{ path|urlencode }}&t={{ token }}&u={{ request.user.username }}";
|
||||
}
|
||||
|
||||
if (t) {
|
||||
showLink();
|
||||
} else {
|
||||
hideLink();
|
||||
}
|
||||
|
||||
{% include "snippets/repo_file_get.html" %}
|
||||
});
|
||||
{% include "snippets/repo_file_get.html" %}
|
||||
|
||||
$('#get-shared-link').click(function() {
|
||||
var url = $(this).attr('data');
|
||||
|
36
templates/snippets/editor_set_mode.html
Normal file
36
templates/snippets/editor_set_mode.html
Normal file
@@ -0,0 +1,36 @@
|
||||
{% if fileext = 'html' or fileext == 'xhtml' or fileext == 'htm' %}
|
||||
editor.session.setMode('ace/mode/html');
|
||||
{% endif %}
|
||||
{% if fileext = 'css' %}
|
||||
editor.session.setMode('ace/mode/css');
|
||||
{% endif %}
|
||||
{% if fileext = 'java' %}
|
||||
editor.session.setMode('ace/mode/java');
|
||||
{% endif %}
|
||||
{% if fileext = 'js' %}
|
||||
editor.session.setMode('ace/mode/javascript');
|
||||
{% endif %}
|
||||
{% if fileext = 'c' or fileext == 'cpp' or fileext == 'cc' %}
|
||||
editor.session.setMode('ace/mode/c_cpp');
|
||||
{% endif %}
|
||||
{% if fileext = 'tex' %}
|
||||
editor.session.setMode('ace/mode/latex');
|
||||
{% endif %}
|
||||
{% if fileext = 'pl' %}
|
||||
editor.session.setMode('ace/mode/perl');
|
||||
{% endif %}
|
||||
{% if fileext = 'php' %}
|
||||
editor.session.setMode('ace/mode/php');
|
||||
{% endif %}
|
||||
{% if fileext = 'py' %}
|
||||
editor.session.setMode('ace/mode/python');
|
||||
{% endif %}
|
||||
{% if fileext = 'rb' %}
|
||||
editor.session.setMode('ace/mode/ruby');
|
||||
{% endif %}
|
||||
{% if fileext = 'sh' %}
|
||||
editor.session.setMode('ace/mode/sh');
|
||||
{% endif %}
|
||||
{% if fileext = 'xml' %}
|
||||
editor.session.setMode('ace/mode/xml');
|
||||
{% endif %}
|
@@ -14,44 +14,7 @@
|
||||
editor.renderer.scrollBar.element.style.display = "none"; // hide right scrollbar
|
||||
editor.renderer.scrollBar.width = 0; // enlarge ace_content width
|
||||
editor.setTheme("ace/theme/chrome");
|
||||
|
||||
{% if fileext = 'html' or fileext == 'xhtml' or fileext == 'htm' %}
|
||||
editor.session.setMode('ace/mode/html');
|
||||
{% endif %}
|
||||
{% if fileext = 'css' %}
|
||||
editor.session.setMode('ace/mode/css');
|
||||
{% endif %}
|
||||
{% if fileext = 'java' %}
|
||||
editor.session.setMode('ace/mode/java');
|
||||
{% endif %}
|
||||
{% if fileext = 'js' %}
|
||||
editor.session.setMode('ace/mode/javascript');
|
||||
{% endif %}
|
||||
{% if fileext = 'c' or fileext == 'cpp' or fileext == 'cc' %}
|
||||
editor.session.setMode('ace/mode/c_cpp');
|
||||
{% endif %}
|
||||
{% if fileext = 'tex' %}
|
||||
editor.session.setMode('ace/mode/latex');
|
||||
{% endif %}
|
||||
{% if fileext = 'pl' %}
|
||||
editor.session.setMode('ace/mode/perl');
|
||||
{% endif %}
|
||||
{% if fileext = 'php' %}
|
||||
editor.session.setMode('ace/mode/php');
|
||||
{% endif %}
|
||||
{% if fileext = 'py' %}
|
||||
editor.session.setMode('ace/mode/python');
|
||||
{% endif %}
|
||||
{% if fileext = 'rb' %}
|
||||
editor.session.setMode('ace/mode/ruby');
|
||||
{% endif %}
|
||||
{% if fileext = 'sh' %}
|
||||
editor.session.setMode('ace/mode/sh');
|
||||
{% endif %}
|
||||
{% if fileext = 'xml' %}
|
||||
editor.session.setMode('ace/mode/xml');
|
||||
{% endif %}
|
||||
|
||||
{% include "snippets/editor_set_mode.html" %}
|
||||
editor.session.getDocument().setValue(data['content']);
|
||||
$('#docu-view').css({'position': 'relative', 'height': editor.session.getScreenLength() * parseInt($('#docu-view').css('line-height'))});
|
||||
editor.session.setScrollLeft(0); // make bottom scrollbar start from the left-most
|
||||
|
3
urls.py
3
urls.py
@@ -5,7 +5,7 @@ from django.views.generic.simple import direct_to_template
|
||||
from seahub.views import root, myhome, \
|
||||
repo, repo_history, modify_token, remove_repo, sys_seafadmin, sys_useradmin, \
|
||||
activate_user, user_add, user_remove, sys_group_admin, sys_org_admin, \
|
||||
ownerhome, repo_history_revert, repo_file_get, org_remove, \
|
||||
ownerhome, repo_history_revert, repo_file_get, repo_file_edit, org_remove, \
|
||||
user_info, repo_set_access_property, repo_access_file, \
|
||||
repo_remove_share, repo_download, org_info, repo_view_file, pdf_full_view, \
|
||||
seafile_access_check, repo_history_changes, \
|
||||
@@ -68,6 +68,7 @@ urlpatterns = patterns('',
|
||||
# (r'^repo/setap/(?P<repo_id>[^/]+)/$', repo_set_access_property),
|
||||
url(r'^repo/(?P<repo_id>[^/]+)/files/$', repo_view_file, name="repo_view_file"),
|
||||
(r'^repo/(?P<repo_id>[^/]+)/file/get/$', repo_file_get),
|
||||
(r'^repo/(?P<repo_id>[^/]+)/file/edit/$', repo_file_edit),
|
||||
(r'^pdf_full_view/$', pdf_full_view),
|
||||
url(r'^repo/(?P<repo_id>[^/]+)/(?P<obj_id>[^/]+)/$', repo_access_file, name='repo_access_file'),
|
||||
|
||||
|
50
views.py
50
views.py
@@ -818,7 +818,6 @@ def repo_view_file(request, repo_id):
|
||||
|
||||
return render_to_response('repo_view_file.html', {
|
||||
'repo': repo,
|
||||
'path': path,
|
||||
'obj_id': obj_id,
|
||||
'u_filename': u_filename,
|
||||
'file_name': filename,
|
||||
@@ -910,7 +909,54 @@ def pdf_full_view(request):
|
||||
'file_src': file_src,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
def repo_file_edit(request, repo_id):
|
||||
|
||||
if request.method == 'POST':
|
||||
pass
|
||||
|
||||
path = request.GET.get('p', '/')
|
||||
if path[-1] == '/':
|
||||
path = path[:-1]
|
||||
u_filename = os.path.basename(path)
|
||||
filename = urllib2.quote(u_filename.encode('utf-8'))
|
||||
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
raise Http404
|
||||
|
||||
try:
|
||||
obj_id = seafserv_threaded_rpc.get_file_by_path(repo_id, path)
|
||||
except:
|
||||
obj_id = None
|
||||
if not obj_id:
|
||||
return render_error(request, '文件不存在')
|
||||
|
||||
token = ''
|
||||
if access_to_repo(request, repo_id, ''):
|
||||
# Get a token to visit file
|
||||
token = gen_token()
|
||||
seafserv_rpc.web_save_access_token(token, repo_id, obj_id,
|
||||
'view', request.user.username)
|
||||
else:
|
||||
render_permission_error(request, '无法查看该文件')
|
||||
|
||||
# generate path and link
|
||||
zipped = gen_path_link(path, repo.name)
|
||||
|
||||
filetype, fileext = valid_previewed_file(filename)
|
||||
|
||||
return render_to_response('repo_edit_file.html', {
|
||||
'repo':repo,
|
||||
'u_filename':u_filename,
|
||||
'path':path,
|
||||
'zipped':zipped,
|
||||
'token':token,
|
||||
'fileext':fileext,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
def repo_access_file(request, repo_id, obj_id):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
|
Reference in New Issue
Block a user