1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00

click draft file from activities (#3153)

This commit is contained in:
陈钦亮
2019-03-21 14:29:09 +08:00
committed by Daniel Pan
parent d038b6a8a0
commit e9ce192502
4 changed files with 34 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import moment from 'moment'; import moment from 'moment';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Table } from 'reactstrap'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Table } from 'reactstrap';
import { gettext, siteRoot } from '../../utils/constants'; import { gettext, siteRoot, serviceURL } from '../../utils/constants';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
const propTypes = { const propTypes = {
@@ -33,9 +33,16 @@ class ListCreatedFileDialog extends React.Component {
{ {
activity.createdFilesList.map((item, index) => { activity.createdFilesList.map((item, index) => {
let fileURL = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`; let fileURL = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`;
if (item.name.endsWith('(draft).md')) {
fileURL = serviceURL + '/drafts/' + item.draft_id + '/';
}
let fileLink = <a href={fileURL} target='_blank'>{item.name}</a>
if (item.name.endsWith('(draft).md') && !item.draft_id) {
fileLink = item.name;
}
return ( return (
<tr key={index}> <tr key={index}>
<td><a href={fileURL} target='_blank'>{item.name}</a></td> <td>{fileLink}</td>
<td>{moment(item.time).fromNow()}</td> <td>{moment(item.time).fromNow()}</td>
</tr> </tr>
); );

View File

@@ -25,6 +25,8 @@ class Acticity {
this.old_name = json.old_name; this.old_name = json.old_name;
} else if (json.op_type === 'publish') { } else if (json.op_type === 'publish') {
this.old_path = json.old_path; this.old_path = json.old_path;
} else if (json.name.endsWith('(draft).md')) {
this.draft_id = json.draft_id;
} }
} }
} }

View File

@@ -2,7 +2,7 @@ import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import moment from 'moment'; import moment from 'moment';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import { gettext, siteRoot } from '../../utils/constants'; import { gettext, siteRoot, serviceURL } from '../../utils/constants';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import Loading from '../../components/loading'; import Loading from '../../components/loading';
import Activity from '../../models/activity'; import Activity from '../../models/activity';
@@ -129,7 +129,13 @@ class ActivityItem extends Component {
details = <td>{fileLink}<br />{smallLibLink}</td>; details = <td>{fileLink}<br />{smallLibLink}</td>;
} else if (item.obj_type == 'files') { } else if (item.obj_type == 'files') {
let fileURL = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`; let fileURL = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`;
if (item.name.endsWith('(draft).md')) {
fileURL = serviceURL + '/drafts/' + item.draft_id + '/';
}
let fileLink = `<a href=${fileURL} target="_blank">${item.name}</a>`; let fileLink = `<a href=${fileURL} target="_blank">${item.name}</a>`;
if (item.name.endsWith('(draft).md') && !item.draft_id) {
fileLink = item.name;
}
let fileCount = item.createdFilesCount - 1; let fileCount = item.createdFilesCount - 1;
let firstLine = gettext('{file} and {n} other files'); let firstLine = gettext('{file} and {n} other files');
firstLine = firstLine.replace('{file}', fileLink); firstLine = firstLine.replace('{file}', fileLink);
@@ -143,7 +149,13 @@ class ActivityItem extends Component {
</td>; </td>;
} else if (item.obj_type == 'file') { } else if (item.obj_type == 'file') {
let fileURL = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`; let fileURL = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`;
if (item.name.endsWith('(draft).md')) {
fileURL = serviceURL + '/drafts/' + item.draft_id + '/';
}
let fileLink = <a href={fileURL} target="_blank">{item.name}</a>; let fileLink = <a href={fileURL} target="_blank">{item.name}</a>;
if (item.name.endsWith('(draft).md') && !item.draft_id) {
fileLink = item.name;
}
switch(item.op_type) { switch(item.op_type) {
case 'create': case 'create':
if (item.name.endsWith('(draft).md')) { if (item.name.endsWith('(draft).md')) {

View File

@@ -17,6 +17,7 @@ from seahub.api2.throttling import UserRateThrottle
from seahub.api2.authentication import TokenAuthentication from seahub.api2.authentication import TokenAuthentication
from seahub.base.templatetags.seahub_tags import email2nickname from seahub.base.templatetags.seahub_tags import email2nickname
from seahub.avatar.templatetags.avatar_tags import api_avatar_url from seahub.avatar.templatetags.avatar_tags import api_avatar_url
from seahub.drafts.models import Draft
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -85,6 +86,15 @@ class ActivitiesView(APIView):
d['old_name'] = os.path.basename(e.old_path) d['old_name'] = os.path.basename(e.old_path)
elif e.op_type == 'publish': elif e.op_type == 'publish':
d['old_path'] = e.old_path d['old_path'] = e.old_path
elif d['name'].endswith('(draft).md'):
if e.op_type in ('create', 'edit') and e.obj_type == 'file':
try:
draft = Draft.objects.get(username=e.op_user,
origin_repo_id=e.repo_id,
draft_file_path=e.path)
d['draft_id'] = draft.id
except Draft.DoesNotExist:
pass
events_list.append(d) events_list.append(d)