mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-14 06:11:16 +00:00
[wiki] improvement & bug fix for header links, index, & creating wiki by choosing a lib
This commit is contained in:
@@ -805,11 +805,6 @@ textarea:-moz-placeholder {/* for FF */
|
||||
padding:6px 13px;
|
||||
border:1px solid #ccc;
|
||||
}
|
||||
/**** index ****/
|
||||
#index-content li {
|
||||
padding-left: 10px;
|
||||
background: transparent url('../img/li.gif') no-repeat scroll left 6.5px;
|
||||
}
|
||||
/********** container ***********/
|
||||
#main, #footer,
|
||||
#repo-top .block-inner,
|
||||
@@ -2148,6 +2143,13 @@ textarea:-moz-placeholder {/* for FF */
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
.anchor {
|
||||
font-size:0.8em;
|
||||
margin-left:6px;
|
||||
}
|
||||
.anchor:hover {
|
||||
text-decoration:none;
|
||||
}
|
||||
#svg-view {
|
||||
min-height:500px;/*for ff*/
|
||||
}
|
||||
@@ -2598,3 +2600,19 @@ textarea:-moz-placeholder {/* for FF */
|
||||
.help-con {
|
||||
padding:0 0 0 60px;
|
||||
}
|
||||
/* wiki index */
|
||||
.wiki-index {
|
||||
border:1px solid #ddd;
|
||||
padding:10px;
|
||||
background:#f7f7f7;
|
||||
border-radius:5px;
|
||||
margin-top:25px;
|
||||
}
|
||||
.wiki-index h3 {
|
||||
border-bottom:1px solid #ddd;
|
||||
}
|
||||
.wiki-index ul {
|
||||
list-style-type: square;
|
||||
padding-left: 1.5em;
|
||||
margin-bottom:5px;
|
||||
}
|
||||
|
@@ -649,7 +649,8 @@ function trimFilename(name, n) {
|
||||
return str;
|
||||
}
|
||||
|
||||
function buildAnchorName(raw_text) {
|
||||
function addAnchorsToHeaders(html) {
|
||||
var buildAnchorName = function(raw_text) {
|
||||
/*
|
||||
* Only unicode letter category, '-' and '_' will be used to build
|
||||
* an anchor name, spaces will be coverted to '-' and others will be omitted.
|
||||
@@ -658,7 +659,6 @@ function buildAnchorName(raw_text) {
|
||||
return raw_text.replace(punctuation, "").replace(/\s+/g, "-");
|
||||
}
|
||||
|
||||
function addAnchorsToHeaders(html) {
|
||||
var tree = $('<div>'+ html + '</div>');
|
||||
var headers = tree.find('h1,h2');
|
||||
headers.each(function() {
|
||||
@@ -667,9 +667,8 @@ function addAnchorsToHeaders(html) {
|
||||
href: '#' + name,
|
||||
name: name
|
||||
});
|
||||
anchor.append('<span class=icon-link> </span>')
|
||||
.css('textDecoration','none');
|
||||
$(this).prepend(anchor);
|
||||
anchor.append('<span class=icon-link></span>').addClass('anchor vh');
|
||||
$(this).append(anchor);
|
||||
});
|
||||
return tree.html();
|
||||
}
|
||||
|
@@ -8,8 +8,9 @@
|
||||
{% block left_panel %}
|
||||
{{ block.super }}
|
||||
{% if wiki_index_exists %}
|
||||
<h3>{% trans "Index" %}</h3>
|
||||
<div id="index-content"></div><!--content will be offered by js-->
|
||||
<div class="wiki-index">
|
||||
<h3>{% trans "Wiki Index" %}</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -20,7 +21,10 @@
|
||||
<h2 class="alc">{% trans "This group currently has no wiki" %}</h2>
|
||||
<p>{% trans "Seafile Wiki enables you to organize your knowledge in a simple way. The contents of wiki is stored in a normal library with pre-defined file/folder structure. This enables you to edit your wiki in your desktop and then sync back to the server." %}</p>
|
||||
{% if is_staff %}
|
||||
<a id="wiki-create" href="#">{% trans "Create Wiki Now" %}</a>{% trans " or " %}<a id="wiki-use-lib" href="#">{% trans "Choose a Library" %}</a>
|
||||
<a id="wiki-create" href="#">{% trans "Create Wiki Now" %}</a>
|
||||
{% if group_repos %}
|
||||
<br /><a id="wiki-use-lib" href="#">{% trans "Choose a library as wiki" %}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<form id="wiki-create-form" action="" method="post" class="hide">{% csrf_token %}
|
||||
@@ -87,7 +91,16 @@
|
||||
var converter = new Markdown.Converter();
|
||||
{% include 'snippets/md_xss.html' %}
|
||||
Markdown.Extra.init(converter, {extensions: ["fenced_code_gfm", "tables", "def_list"]});
|
||||
$('#wiki-content').html(addAnchorsToHeaders(converter.makeHtml('{{ content|escapejs }}'))).children(':first').css('margin-top', '0');
|
||||
$('#wiki-content')
|
||||
.html(addAnchorsToHeaders(converter.makeHtml('{{ content|escapejs }}')))
|
||||
.find('h1, h2').hover(
|
||||
function() {
|
||||
$('.anchor', $(this)).removeClass('vh');
|
||||
},
|
||||
function() {
|
||||
$('.anchor', $(this)).addClass('vh');
|
||||
}
|
||||
);
|
||||
|
||||
$('#page-create').click(function() {
|
||||
$('#page-create-form').modal({appendTo: '#main', autoResize: true});
|
||||
@@ -163,6 +176,7 @@ $('#wiki-create-form').submit(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
{% if group_repos %}
|
||||
var all_repos = [];
|
||||
{% for a_repo in group_repos %}
|
||||
all_repos.push({
|
||||
@@ -175,18 +189,21 @@ $('#wiki-use-lib').click(function() {
|
||||
file_tree = new FileTree();
|
||||
form.modal({appendTo:'#main', autoResize:true, focus:false});
|
||||
file_tree.renderDirTree($('#repos-dirs').data('site_root', '{{SITE_ROOT}}'), form, all_repos);
|
||||
return false;
|
||||
});
|
||||
$('#wiki-use-lib-form').submit(function() {
|
||||
var dst_repo = $('[name="dst_repo"]', $(this)).val();
|
||||
if (!$.trim(dst_repo)) {
|
||||
$('.error', form).removeClass('hide');
|
||||
$('.error', $(this)).removeClass('hide');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
{% endif %} // END wiki_exists
|
||||
|
||||
{% if wiki_index_exists %}
|
||||
$('#index-content').html(converter.makeHtml('{{ index_content|escapejs }}'));
|
||||
$('.wiki-index').append(converter.makeHtml('{{ index_content|escapejs }}'));
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@@ -1362,7 +1362,17 @@ def group_wiki(request, group, page_name="home"):
|
||||
|
||||
repo_perm = seafile_api.check_repo_access_permission(repo.id, username)
|
||||
|
||||
d = {
|
||||
wiki_index_exists = True
|
||||
index_pagename = 'index'
|
||||
index_content = None
|
||||
try:
|
||||
index_content, index_repo, index_dirent = get_group_wiki_page(username, group, index_pagename)
|
||||
except (WikiDoesNotExist, WikiPageMissing) as e:
|
||||
wiki_index_exists = False
|
||||
else:
|
||||
index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username)
|
||||
|
||||
return render_to_response("group/group_wiki.html", {
|
||||
"group" : group,
|
||||
"is_staff": group.is_staff,
|
||||
"wiki_exists": wiki_exists,
|
||||
@@ -1377,21 +1387,9 @@ def group_wiki(request, group, page_name="home"):
|
||||
"mods_enabled": mods_enabled,
|
||||
"mods_available": mods_available,
|
||||
"repo_perm": repo_perm,
|
||||
}
|
||||
|
||||
wiki_index_exists = True
|
||||
index_pagename = 'index'
|
||||
try:
|
||||
index_content, index_repo, index_dirent = get_group_wiki_page(username, group, index_pagename)
|
||||
except (WikiDoesNotExist, WikiPageMissing) as e:
|
||||
wiki_index_exists = False
|
||||
else:
|
||||
index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username)
|
||||
d["index_content"] = index_content
|
||||
|
||||
d["wiki_index_exists"] = wiki_index_exists
|
||||
|
||||
return render_to_response("group/group_wiki.html", d, context_instance=RequestContext(request))
|
||||
"wiki_index_exists": wiki_index_exists,
|
||||
"index_content": index_content,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@group_check
|
||||
def group_wiki_pages(request, group):
|
||||
@@ -1490,7 +1488,7 @@ def group_wiki_use_lib(request, group):
|
||||
|
||||
# create home page if not exist
|
||||
page_name = "home.md"
|
||||
if not seaserv.get_file_id_by_path(repo_id, "/" + page_name + ".md"):
|
||||
if not seaserv.get_file_id_by_path(repo_id, "/" + page_name):
|
||||
if not seaserv.post_empty_file(repo_id, "/", page_name, username):
|
||||
messages.error(request, _('Failed to create home page. Please retry later'))
|
||||
|
||||
|
@@ -10,8 +10,9 @@
|
||||
{% block left_panel %}
|
||||
{{ block.super }}
|
||||
{% if wiki_index_exists %}
|
||||
<h3>{% trans "Index" %}</h3>
|
||||
<div id="index-content"></div><!--content will be offered by js-->
|
||||
<div class="wiki-index">
|
||||
<h3>{% trans "Wiki Index" %}</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -20,7 +21,10 @@
|
||||
<div class="empty-tips">
|
||||
<h2 class="alc">{% trans "You do not have personal wiki" %}</h2>
|
||||
<p>{% trans "Seafile Wiki enables you to organize your knowledge in a simple way. The contents of wiki is stored in a normal library with pre-defined file/folder structure. This enables you to edit your wiki in your desktop and then sync back to the server." %}</p>
|
||||
<a id="wiki-create" href="#">{% trans "Create Wiki Now" %}</a>{% trans " or " %}<a id="wiki-use-lib" href="#">{% trans "Choose a Library" %}</a>
|
||||
<a id="wiki-create" href="#">{% trans "Create Wiki Now" %}</a>
|
||||
{% if owned_repos %}
|
||||
<br /><a id="wiki-use-lib" href="#">{% trans "Choose a library as wiki" %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<form id="wiki-create-form" action="" method="post" class="hide">{% csrf_token %}
|
||||
<h3>{% trans "Create Wiki" %}</h3>
|
||||
@@ -82,7 +86,16 @@
|
||||
var converter = new Markdown.Converter();
|
||||
{% include 'snippets/md_xss.html' %}
|
||||
Markdown.Extra.init(converter, {extensions: ["fenced_code_gfm", "tables", "def_list"]});
|
||||
$('#wiki-content').html(addAnchorsToHeaders(converter.makeHtml('{{ content|escapejs }}'))).children(':first').css('margin-top', '0');
|
||||
$('#wiki-content')
|
||||
.html(addAnchorsToHeaders(converter.makeHtml('{{ content|escapejs }}')))
|
||||
.find('h1, h2').hover(
|
||||
function() {
|
||||
$('.anchor', $(this)).removeClass('vh');
|
||||
},
|
||||
function() {
|
||||
$('.anchor', $(this)).addClass('vh');
|
||||
}
|
||||
);
|
||||
|
||||
$('#page-create').click(function() {
|
||||
$('#page-create-form').modal({appendTo: '#main', autoResize: true});
|
||||
@@ -159,6 +172,7 @@ $('#wiki-create-form').submit(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
{% if owned_repos %}
|
||||
var all_repos = [];
|
||||
{% for a_repo in owned_repos %}
|
||||
all_repos.push({
|
||||
@@ -171,18 +185,21 @@ $('#wiki-use-lib').click(function() {
|
||||
file_tree = new FileTree();
|
||||
form.modal({appendTo:'#main', autoResize:true, focus:false});
|
||||
file_tree.renderDirTree($('#repos-dirs').data('site_root', '{{SITE_ROOT}}'), form, all_repos);
|
||||
return false;
|
||||
});
|
||||
$('#wiki-use-lib-form').submit(function() {
|
||||
var dst_repo = $('[name="dst_repo"]', $(this)).val();
|
||||
if (!$.trim(dst_repo)) {
|
||||
$('.error', form).removeClass('hide');
|
||||
$('.error', $(this)).removeClass('hide');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
{% endif %} // END wiki_exists
|
||||
|
||||
{% if wiki_index_exists %}
|
||||
$('#index-content').html(converter.makeHtml('{{ index_content|escapejs }}'));
|
||||
$('.wiki-index').append(converter.makeHtml('{{ index_content|escapejs }}'));
|
||||
{% endif %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@@ -69,7 +69,17 @@ def personal_wiki(request, page_name="home"):
|
||||
repo.id, path.encode('utf-8'), file_path_hash, dirent.obj_id)
|
||||
latest_contributor = contributors[0] if contributors else None
|
||||
|
||||
d = {
|
||||
wiki_index_exists = True
|
||||
index_pagename = 'index'
|
||||
index_content = None
|
||||
try:
|
||||
index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename)
|
||||
except (WikiDoesNotExist, WikiPageMissing) as e:
|
||||
wiki_index_exists = False
|
||||
else:
|
||||
index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username)
|
||||
|
||||
return render_to_response("wiki/personal_wiki.html", {
|
||||
"wiki_exists": wiki_exists,
|
||||
"content": content,
|
||||
"page": os.path.splitext(dirent.obj_name)[0],
|
||||
@@ -79,21 +89,9 @@ def personal_wiki(request, page_name="home"):
|
||||
"repo_id": repo.id,
|
||||
"search_repo_id": repo.id,
|
||||
"search_wiki": True,
|
||||
}
|
||||
|
||||
wiki_index_exists = True
|
||||
index_pagename = 'index'
|
||||
try:
|
||||
index_content, index_repo, index_dirent = get_personal_wiki_page(username, index_pagename)
|
||||
except (WikiDoesNotExist, WikiPageMissing) as e:
|
||||
wiki_index_exists = False
|
||||
else:
|
||||
index_content = convert_wiki_link(index_content, url_prefix, index_repo.id, username)
|
||||
d["index_content"] = index_content
|
||||
|
||||
d["wiki_index_exists"] = wiki_index_exists
|
||||
|
||||
return render_to_response("wiki/personal_wiki.html", d, context_instance=RequestContext(request))
|
||||
"wiki_index_exists": wiki_index_exists,
|
||||
"index_content": index_content,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def personal_wiki_pages(request):
|
||||
@@ -170,7 +168,7 @@ def personal_wiki_use_lib(request):
|
||||
|
||||
# create home page if not exist
|
||||
page_name = "home.md"
|
||||
if not seaserv.get_file_id_by_path(repo_id, "/" + page_name + ".md"):
|
||||
if not seaserv.get_file_id_by_path(repo_id, "/" + page_name):
|
||||
if not seaserv.post_empty_file(repo_id, "/", page_name, username):
|
||||
messages.error(request, _('Failed to create home page. Please retry later'))
|
||||
|
||||
|
Reference in New Issue
Block a user