1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-23 12:27:48 +00:00
Files
seahub/frontend/src/repo-snapshot.js
llj e9f8a52abe Icon bg (#7871)
* ['Files', 'my libs', 'shared with me', 'shared with all', 'group', 'department' pages] added background to the library items' operation icons when hovering on them

* ['share' dialog] 'Share Link'(link list, link-authenticated-emails, link-authenticated-users): added background to the items' operation icons when hovering on them

* ['share' dialog] 'Share to user': added background for the sharing items and the operation icons when hover on them

* [select editor] improved it; added background to the 'edit' icon when hover on it

* ['share' dialog] 'Share to group': added background for the sharing items and the operation icons when hover on them; fixed it for mobile

* ['share' dialog] 'Custom sharing permissions': added background for the permission items and the operation icons when hover on them

* ['share' dialog] 'Invite Guest': added background for the items and the operation icons when hover on them

* ['share' dialog] 'Share to other server': added background for the items and the operation icons when hover on them

* [repo 'Folder Permission' dialog] 'User Permission': added background for the items and the operation icons when hover on them

* [repo 'Folder Permission' dialog] 'Group Permission': added background for the items and the operation icons when hover on them

* [repo 'Share Admin' dialog] 'Share Link': added background for the sharing items and the operation icons when hover on them; improved it

* [repo 'Share Admin' dialog] 'Upload Link': added background for the sharing items and the operation icons when hover on them; improved it

* [repo 'Share Admin' dialog] 'User Shares': added background for the sharing items and the operation icons when hover on them; improved the permission editor

* [repo 'Share Admin' dialog] 'Group Shares': added background for the sharing items and the operation icons when hover on them; improved the permission editor

* [repo 'API Token' dialog] added background for the items and the operation icons when hover on them

* [group/department 'Manage group members' dialog] added background for the operation icons when hover on them

* ['select members from departments' dialog] added background for the operation icons when hover on them

* [library list pages] removed the background when hover on the 'star/unstar' icons of the library items

* ['back' icons] added background for the 'go back' icons when hover on them

* ['my deleted repos' dialog] added background for the operation icons when hover on them

* ['Favorites' page] added background for the items and the operation icons when hover on them

* ['Wikis' page] added background for the operation icons when hover on them

* ['Invite Guest' page] added background for the items and the operation icons when hover on them

* ['Share Admin'] 'Libraries' page: added background for the items and the operation icons when hover on them

* ['Share Admin'] 'Folders' page: added background for the items and the operation icons when hover on them

* ['Share Admin'] 'Share Links' page: added background for the items and the operation icons when hover on them

* ['Share Admin'] 'Upload Links' page: added background for the operation icons when hover on them

* [repo 'Modification History' dialog] added background for the operation icons when hover on them

* [repo 'Snapshot' page] added background for the items and  the operation icons when hover on them

* [folder 'share link' page] added background for the items and the operation icons when hover on them

* [file 'History Versions' page] changed the 'more' icon and added background for the the operation icons when hover on them

* [personal 'settings' page] 'Linked Devices': added background for the items and the operation icons when hover on them

* ['library view' page] 'move/copy' dialog: added background for the 'clear search keyword' icon when hover on it

* ['library view' page] added background for the operation icons when hover on them

* ['system admin'] 'Devices' pages: added background for the items and the operation icons when hover on them

* [system admin] repos/users/groups/inst/... pages: added background for the operation icons when hover on them

* [system admin] 'Libraries - Trash' page: added background for the items and the operation icons when hover on them

* [system admin] 'Users' pages: added background for the operation icons when hover on them

* [system admin] 'Departments' pages: added background for the operation icons when hover on them

* [system admin] 'Organizations' & 'Search Organizations' pages: added background for the operation icons when hover on them

* [system admin] 'Institutions' pages: added background for items & the operation icons when hover on them

* [system admin] 'terms and conditions' pages: added background for items & the operation icons when hover on them

* [system admin] 'Links - Share Links' pages: added background for items & the operation icons when hover on them

* [system admin] 'Links - Upload Links' pages: added background for items & the operation icons when hover on them

* org page use new op-icon

* use common edit icon

---------

Co-authored-by: Michael An <1822852997@qq.com>
2025-05-31 12:01:08 +08:00

360 lines
12 KiB
JavaScript

import React from 'react';
import { createRoot } from 'react-dom/client';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { navigate } from '@gatsbyjs/reach-router';
import { Utils } from './utils/utils';
import { gettext, siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle } from './utils/constants';
import { seafileAPI } from './utils/seafile-api';
import Loading from './components/loading';
import ModalPortal from './components/modal-portal';
import toaster from './components/toast';
import CommonToolbar from './components/toolbar/common-toolbar';
import ConfirmRestoreRepo from './components/dialog/confirm-restore-repo';
import './css/toolbar.css';
import './css/search.css';
import './css/repo-snapshot.css';
const {
repoID, repoName, canRestoreRepo,
commitID, commitTime, commitDesc, commitRelativeTime,
showAuthor, authorAvatarURL, authorName, authorNickName
} = window.app.pageOptions;
class RepoSnapshot extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
errorMsg: '',
folderPath: '/',
folderItems: [],
isConfirmDialogOpen: false
};
}
componentDidMount() {
this.renderFolder(this.state.folderPath);
}
toggleDialog = () => {
this.setState({
isConfirmDialogOpen: !this.state.isConfirmDialogOpen
});
};
onSearchedClick = (selectedItem) => {
if (selectedItem.is_dir === true) {
let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path;
navigate(url, { replace: true });
} else {
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path);
let newWindow = window.open('about:blank');
newWindow.location.href = url;
}
};
goBack = (e) => {
e.preventDefault();
window.history.back();
};
renderFolder = (folderPath) => {
this.setState({
folderPath: folderPath,
folderItems: [],
isLoading: true
});
seafileAPI.listCommitDir(repoID, commitID, folderPath).then((res) => {
this.setState({
isLoading: false,
folderItems: res.data.dirent_list
});
}).catch((error) => {
this.setState({
isLoading: false,
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403
});
});
};
clickFolderPath = (folderPath, e) => {
e.preventDefault();
this.renderFolder(folderPath);
};
renderPath = () => {
const path = this.state.folderPath;
const pathList = path.split('/');
if (path == '/') {
return <span className="text-truncate" title={repoName}>{repoName}</span>;
}
return (
<React.Fragment>
<a href="#" onClick={this.clickFolderPath.bind(this, '/')} className="text-truncate" title={repoName}>{repoName}</a>
<span className="mx-1">/</span>
{pathList.map((item, index) => {
if (index > 0 && index != pathList.length - 1) {
return (
<React.Fragment key={index}>
<a href="#" onClick={this.clickFolderPath.bind(this, pathList.slice(0, index + 1).join('/'))} className="text-truncate" title={pathList[index]}>{pathList[index]}</a>
<span className="mx-1">/</span>
</React.Fragment>
);
}
return null;
}
)}
<span className="text-truncate" title={pathList[pathList.length - 1]}>{pathList[pathList.length - 1]}</span>
</React.Fragment>
);
};
restoreRepo = () => {
seafileAPI.revertRepo(repoID, commitID).then((res) => {
this.toggleDialog();
toaster.success(gettext('Successfully restored the library.'));
}).catch((error) => {
let errorMsg = Utils.getErrorMsg(error);
this.toggleDialog();
toaster.danger(errorMsg);
});
};
render() {
const { isConfirmDialogOpen, folderPath } = this.state;
let title = gettext('{placeholder} Snapshot');
title = title.replace('{placeholder}', '<span class="op-target text-truncate mx-1">' + Utils.HTMLescape(repoName) + '</span>');
return (
<React.Fragment>
<div className="h-100 d-flex flex-column">
<div className="top-header d-flex justify-content-between">
<a href={siteRoot}>
<img src={mediaUrl + logoPath} height={logoHeight} width={logoWidth} title={siteTitle} alt="logo" />
</a>
<CommonToolbar onSearchedClick={this.onSearchedClick} />
</div>
<div className="flex-auto container-fluid pt-4 pb-6 o-auto">
<div className="row">
<div className="col-md-10 offset-md-1">
<h2>
<span dangerouslySetInnerHTML={{ __html: title }} className="d-flex mw-100"></span>
<span className="heading-commit-time ml-1">({commitTime})</span>
</h2>
<a href="#" className="go-back" title={gettext('Back')} role="button" aria-label={gettext('Back')} onClick={this.goBack}>
<span className="sf3-font sf3-font-down rotate-90 d-inline-block"></span>
</a>
{folderPath == '/' && (
<div className="d-flex mb-2 align-items-center">
<p className="m-0 text-truncate" title={commitDesc}>{commitDesc}</p>
<div className="ml-4 border-start pl-4 d-flex align-items-center flex-shrink-0">
{showAuthor ? (
<React.Fragment>
<img src={authorAvatarURL} width="20" height="20" alt="" className="rounded mr-1" />
<a href={`${siteRoot}profile/${encodeURIComponent(authorName)}/`}>{authorNickName}</a>
</React.Fragment>
) : <span>{gettext('Unknown')}</span>}
<p className="m-0 ml-2" dangerouslySetInnerHTML={{ __html: commitRelativeTime }}></p>
</div>
</div>
)}
<div className="d-flex justify-content-between align-items-center op-bar">
<p className="m-0 text-truncate d-flex"><span className="mr-1">{gettext('Current path: ')}</span>{this.renderPath()}</p>
{(folderPath == '/' && canRestoreRepo) &&
<button className="btn btn-secondary op-bar-btn flex-shrink-0 ml-4" onClick={this.toggleDialog}>{gettext('Restore')}</button>
}
</div>
<Content
data={this.state}
renderFolder={this.renderFolder}
/>
</div>
</div>
</div>
</div>
{isConfirmDialogOpen &&
<ModalPortal>
<ConfirmRestoreRepo
restoreRepo={this.restoreRepo}
toggle={this.toggleDialog}
/>
</ModalPortal>
}
</React.Fragment>
);
}
}
class Content extends React.Component {
constructor(props) {
super(props);
this.theadData = [
{ width: '5%', text: '' },
{ width: '55%', text: gettext('Name') },
{ width: '20%', text: gettext('Size') },
{ width: '20%', text: '' }
];
}
render() {
const { isLoading, errorMsg, folderPath, folderItems } = this.props.data;
if (isLoading) {
return <Loading />;
}
if (errorMsg) {
return <p className="error mt-6 text-center">{errorMsg}</p>;
}
return (
<table className="table-hover">
<thead>
<tr>
{this.theadData.map((item, index) => {
return <th key={index} width={item.width}>{item.text}</th>;
})}
</tr>
</thead>
<tbody>
{folderItems.map((item, index) => {
return <FolderItem
key={index}
item={item}
folderPath={folderPath}
renderFolder={this.props.renderFolder}
/>;
})
}
</tbody>
</table>
);
}
}
Content.propTypes = {
data: PropTypes.object.isRequired,
renderFolder: PropTypes.func.isRequired,
};
class FolderItem extends React.Component {
constructor(props) {
super(props);
this.state = {
isHighlighted: false,
isIconShown: false
};
}
handleMouseOver = () => {
this.setState({
isHighlighted: true,
isIconShown: true
});
};
handleMouseOut = () => {
this.setState({
isHighlighted: false,
isIconShown: false
});
};
restoreItem = () => {
const item = this.props.item;
const path = Utils.joinPath(this.props.folderPath, item.name);
const request = item.type == 'dir' ?
seafileAPI.revertFolder(repoID, path, commitID) :
seafileAPI.revertFile(repoID, path, commitID);
request.then((res) => {
toaster.success(gettext('Restored 1 item'));
}).catch((error) => {
let errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
};
renderFolder = (e) => {
e.preventDefault();
const item = this.props.item;
const { folderPath } = this.props;
this.props.renderFolder(Utils.joinPath(folderPath, item.name));
};
render() {
const item = this.props.item;
const { isIconShown, isHighlighted } = this.state;
const { folderPath } = this.props;
return item.type == 'dir' ? (
<tr
className={classnames({
'tr-highlight': isHighlighted
})}
onMouseOver={this.handleMouseOver}
onMouseOut={this.handleMouseOut}
onFocus={this.handleMouseOver}
>
<td className="text-center"><img src={Utils.getFolderIconUrl()} alt={gettext('Folder')} width="24" /></td>
<td><a href="#" onClick={this.renderFolder}>{item.name}</a></td>
<td></td>
<td>
<i
role="button"
className={`op-icon sf2-icon-reply ${isIconShown ? '' : 'invisible'}`}
onClick={this.restoreItem}
title={gettext('Restore')}
aria-label={gettext('Restore')}
>
</i>
</td>
</tr>
) : (
<tr
className={classnames({
'tr-highlight': isHighlighted
})}
onMouseOver={this.handleMouseOver}
onMouseOut={this.handleMouseOut}
onFocus={this.handleMouseOver}
>
<td className="text-center"><img src={Utils.getFileIconUrl(item.name)} alt={gettext('File')} width="24" /></td>
<td><a href={`${siteRoot}repo/${repoID}/snapshot/files/?obj_id=${item.obj_id}&commit_id=${commitID}&p=${encodeURIComponent(Utils.joinPath(folderPath, item.name))}`} target="_blank" rel="noreferrer">{item.name}</a></td>
<td>{Utils.bytesToSize(item.size)}</td>
<td>
<div className="d-flex align-items-center">
<i
className={`op-icon sf2-icon-reply ${isIconShown ? '' : 'invisible'}`}
onClick={this.restoreItem}
title={gettext('Restore')}
aria-label={gettext('Restore')}
role="button"
>
</i>
<a href={`${siteRoot}repo/${repoID}/${item.obj_id}/download/?file_name=${encodeURIComponent(item.name)}&p=${encodeURIComponent(Utils.joinPath(folderPath, item.name))}`} className={`op-icon sf3-font sf3-font-download1 ${isIconShown ? '' : 'invisible'}`} title={gettext('Download')}></a>
</div>
</td>
</tr>
);
}
}
FolderItem.propTypes = {
item: PropTypes.object.isRequired,
folderPath: PropTypes.string.isRequired,
renderFolder: PropTypes.func.isRequired,
};
const root = createRoot(document.getElementById('wrapper'));
root.render(<RepoSnapshot />);