1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-01 15:23:05 +00:00

Merge pull request #1423 from haiwen/new

[dir view] redesigned 'new folder/file'
This commit is contained in:
Daniel Pan 2017-01-04 13:53:04 +08:00 committed by GitHub
commit 1273ffa83d
9 changed files with 126 additions and 39 deletions

View File

@ -1644,9 +1644,6 @@ button.sf-dropdown-toggle:focus {
margin-bottom:.5em;
border-radius:2px;
}
#dir-view .repo-op {
position: relative; /* for '#upload-menu' */
}
#right-panel .hd,
.tabnav,
.wiki-top {
@ -2121,6 +2118,11 @@ button.sf-dropdown-toggle:focus {
#dir-view .repo-op .op-btn {
padding:5px 14px;
}
#new-file-menu {
margin-top:4px;
border-top:1px solid #ddd;
padding-top:4px;
}
.repo-file-list {
margin:0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,7 @@
import os
import logging
import posixpath
import requests
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
@ -15,11 +16,13 @@ from seahub.api2.throttling import UserRateThrottle
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.utils import api_error
from seahub.utils import check_filename_with_rename, is_pro_version
from seahub.utils import check_filename_with_rename, is_pro_version, \
gen_file_upload_url
from seahub.utils.timeutils import timestamp_to_isoformat_timestr
from seahub.views import check_folder_permission, check_file_lock
from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, FILE_LOCK_EXPIRATION_DAYS
from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, \
FILE_LOCK_EXPIRATION_DAYS, OFFICE_TEMPLATE_ROOT
from seaserv import seafile_api
from pysearpc import SearpcError
@ -147,7 +150,7 @@ class FileView(APIView):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# create file
# create new empty file
new_file_name = os.path.basename(path)
new_file_name = check_filename_with_rename(repo_id, parent_dir, new_file_name)
@ -158,6 +161,32 @@ class FileView(APIView):
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
# update office file by template
if new_file_name.endswith('.xlsx'):
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.xlsx')
elif new_file_name.endswith('.pptx'):
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.pptx')
elif new_file_name.endswith('.docx'):
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.docx')
else:
empty_file_path = ''
if empty_file_path:
# get file server update url
update_token = seafile_api.get_fileserver_access_token(
repo_id, 'dummy', 'update', username)
update_url = gen_file_upload_url(update_token, 'update-api')
# update file
try:
requests.post(
update_url,
data={'filename': new_file_name, 'target_file': path},
files={'file': open(empty_file_path, 'rb')}
)
except Exception as e:
logger.error(e)
new_file_path = posixpath.join(parent_dir, new_file_name)
file_info = self.get_file_info(username, repo_id, new_file_path)
return Response(file_info)

View File

@ -508,6 +508,9 @@ THUMBNAIL_SIZE_FOR_GRID = 192
THUMBNAIL_IMAGE_SIZE_LIMIT = 20
THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT = 256
# template for create new office file
OFFICE_TEMPLATE_ROOT = os.path.join(MEDIA_ROOT, 'office-template')
#####################
# Global AddressBook #
#####################

View File

@ -13,18 +13,9 @@
<script type="text/template" id="add-new-file-form-template">
<form id="add-new-file-form" action="" method="post" class="hide">{% csrf_token %}
<h3 id="dialogTitle">{% trans "New File" %}</h3>
<div id="featured-filetype">
<label>{% trans "Featured File Type" %}</label><br />
<button type="button" class="set-file-type" data-filetype="md" title="{% trans "Click to choose" %}">markdown</button> <span>{% trans "simple markup format." %}</span>
{% if LANGUAGE_CODE == 'zh-cn' %}
<a href="http://www.seafile.com/help/markdown/" target="_blank">{% trans 'Details' %}</a>
{% else %}
<a href="http://www.seafile.com/en/help/markdown/" target="_blank">{% trans 'Details' %}</a>
{% endif %}
</div>
<label for="file-name">{% trans "File Name" %}</label><br/>
<input type="text" name="name" value="" class="input" maxlength="{{max_file_name}}" id="file-name" /><br />
<h3 id="dialogTitle"><%= title %></h3>
<label for="file-name">{% trans "Name" %}</label><br/>
<input type="text" name="name" value="<%= initial_file_name %>" class="input" maxlength="{{max_file_name}}" id="file-name" /><br />
<p class="error hide"></p>
<button type="submit" class="submit">{% trans "Submit" %}</button>
<button class="simplemodal-close">{% trans "Cancel" %}</button>

View File

@ -145,8 +145,21 @@
<% } else { %>
<button class="op-btn btn-disabled" disabled="disabled" title="{% trans "Out of quota" %}">{% trans "Upload" %}</button>
<% } %>
<button id="add-new-dir" class="op-btn">{% trans "New Folder" %}</button>
<button id="add-new-file" class="op-btn">{% trans "New File" %}</button>
<div id="add-new" class="sf-dropdown sf-dropdown-inline">
<button class="sf-dropdown-toggle op-btn">{% trans "New" %}</button>
<div class="sf-dropdown-menu hide">
<ul>
<li><a id="add-new-dir" class="op" href="#">{% trans "New Folder" %}</a></li>
<li><a id="add-new-file" class="op" href="#">{% trans "New File" %}</a></li>
</ul>
<ul id="new-file-menu">
<li><a id="add-new-md-file" class="op" href="#">{% trans "New Markdown File" %}</a></li>
<li><a id="add-new-excel-file" class="op" href="#">{% trans "New Excel File" %}</a></li>
<li><a id="add-new-ppt-file" class="op" href="#">{% trans "New PowerPoint File" %}</a></li>
<li><a id="add-new-word-file" class="op" href="#">{% trans "New Word File" %}</a></li>
</ul>
</div>
</div>
<% } %>
<% if (!encrypted && (can_generate_share_link || can_generate_upload_link || is_repo_owner)) { %>

View File

@ -441,6 +441,13 @@ define([
can_generate_upload_link: app.pageOptions.can_generate_upload_link,
enable_upload_folder: app.pageOptions.enable_upload_folder
})));
if (dir.user_perm == 'rw') {
// add new folder/file
this.new_dropdown = new DropdownView({
el: this.$("#add-new")
});
}
},
renderDirentsHd: function() {
@ -461,7 +468,11 @@ define([
// Directory Operations
events: {
'click #add-new-dir': 'newDir',
'click #add-new-file': 'newFile',
'click #add-new-file': 'newCommonFile',
'click #add-new-md-file': 'newMdFile',
'click #add-new-excel-file': 'newExcelFile',
'click #add-new-ppt-file': 'newPPTFile',
'click #add-new-word-file': 'newWordFile',
'click #share-cur-dir': 'share',
'click #js-switch-grid-view': 'switchToGridView',
'click #js-switch-list-view': 'switchToListView',
@ -535,31 +546,29 @@ define([
return false;
});
return false;
},
newFile: function() {
var form = $(this.newFileTemplate()),
form_id = form.attr('id'),
file_name = form.find('input[name="name"]'),
newFile: function(options) {
var $form = $(this.newFileTemplate(options)),
form_id = $form.attr('id'),
$input = $('input[name="name"]', $form),
dir = this.dir,
dirView = this;
form.modal({
$form.modal({
appendTo: '#main',
focus: false,
containerCss: {'padding':'20px 25px'}
});
file_name.focus();
$('#simplemodal-container').css({'height':'auto'});
$('.set-file-type', form).click(function() {
file_name.val('.' + $(this).data('filetype'));
Common.setCaretPos(file_name[0], 0);
file_name.focus();
});
Common.setCaretPos($input[0], 0);
$input.focus();
form.submit(function() {
var dirent_name = $.trim(file_name.val());
$form.submit(function() {
var dirent_name = $.trim($input.val());
if (!dirent_name) {
Common.showFormError(form_id, gettext("It is required."));
@ -579,10 +588,10 @@ define([
$.modal.close();
var new_dirent = dir.add({
'is_file': true,
'is_img': Common.imageCheck(data['obj_name']),
'obj_name': data['obj_name'],
'file_size': Common.fileSizeFormat(0),
'obj_id': '0000000000000000000000000000000000000000',
'is_img': Common.imageCheck(data.obj_name),
'obj_name': data.obj_name,
'file_size': Common.fileSizeFormat(data.size),
'obj_id': data.obj_id,
'file_icon': 'file.png',
'starred': false,
'perm': 'rw',
@ -593,7 +602,7 @@ define([
};
Common.ajaxPost({
'form': form,
'form': $form,
'post_url': post_url,
'post_data': post_data,
'after_op_success': after_op_success,
@ -604,6 +613,46 @@ define([
});
},
newCommonFile: function() {
this.newFile({
title: gettext('New File'),
initial_file_name: ''
});
return false;
},
newMdFile: function() {
this.newFile({
title: gettext('New Markdown File'),
initial_file_name: '.md'
});
return false;
},
newExcelFile: function() {
this.newFile({
title: gettext('New Excel File'),
initial_file_name: '.xlsx'
});
return false;
},
newPPTFile: function() {
this.newFile({
title: gettext('New PowerPoint File'),
initial_file_name: '.pptx'
});
return false;
},
newWordFile: function() {
this.newFile({
title: gettext('New Word File'),
initial_file_name: '.docx'
});
return false;
},
addNewFile: function(new_dirent) {
var dirView = this,
dir = this.dir;