mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 01:41:39 +00:00
Merge pull request #2644 from haiwen/search-module-improve
Search module improve
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Router } from '@reach/router';
|
import { Router, navigate } from '@reach/router';
|
||||||
import { siteRoot } from './utils/constants';
|
import { siteRoot } from './utils/constants';
|
||||||
|
import { Utils } from './utils/utils';
|
||||||
import SidePanel from './components/side-panel';
|
import SidePanel from './components/side-panel';
|
||||||
import MainPanel from './components/main-panel';
|
import MainPanel from './components/main-panel';
|
||||||
import DraftsView from './pages/drafts/drafts-view';
|
import DraftsView from './pages/drafts/drafts-view';
|
||||||
@@ -96,8 +97,20 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = () => {
|
onSearchedClick = (selectedItem) => {
|
||||||
//todos
|
if (selectedItem.is_dir === true) {
|
||||||
|
this.setState({currentTab: '', pathPrefix: []});
|
||||||
|
let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path;
|
||||||
|
navigate(url, {repalce: true});
|
||||||
|
} else if (Utils.isMarkdownFile(selectedItem.path)) {
|
||||||
|
let url = siteRoot + 'wiki/lib/' + selectedItem.repo_id + selectedItem.path;
|
||||||
|
let newWindow = window.open('markdown-editor');
|
||||||
|
newWindow.location.href = url;
|
||||||
|
} else {
|
||||||
|
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + selectedItem.path;
|
||||||
|
let newWindow = window.open('about:blank');
|
||||||
|
newWindow.location.href = url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tabItemClick = (tabName, groupID) => {
|
tabItemClick = (tabName, groupID) => {
|
||||||
|
@@ -325,8 +325,18 @@ class DirView extends React.Component {
|
|||||||
// todo update upload file to direntList
|
// todo update upload file to direntList
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = () => {
|
onSearchedClick = (selectedItem) => {
|
||||||
// todo
|
if (selectedItem.is_dir === true) {
|
||||||
|
this.setState({path: selectedItem.path});
|
||||||
|
} else if (Utils.isMarkdownFile(selectedItem.path)) {
|
||||||
|
let url = siteRoot + 'wiki/lib/' + selectedItem.repo_id + selectedItem.path;
|
||||||
|
let newWindow = window.open('markdown-editor');
|
||||||
|
newWindow.location.href = url;
|
||||||
|
} else {
|
||||||
|
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + selectedItem.path;
|
||||||
|
let newWindow = window.open('about:blank');
|
||||||
|
newWindow.location.href = url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resetSelected = () => {
|
resetSelected = () => {
|
||||||
|
@@ -6,8 +6,8 @@ import editorUtilities from '../../utils/editor-utilties';
|
|||||||
import More from '../more';
|
import More from '../more';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
placeholder: PropTypes.string,
|
|
||||||
repoID: PropTypes.string,
|
repoID: PropTypes.string,
|
||||||
|
placeholder: PropTypes.string,
|
||||||
onSearchedClick: PropTypes.func.isRequired,
|
onSearchedClick: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,9 +65,7 @@ class Search extends Component {
|
|||||||
let queryData = {
|
let queryData = {
|
||||||
q: newValue,
|
q: newValue,
|
||||||
search_repo: repoID ? repoID : 'all',
|
search_repo: repoID ? repoID : 'all',
|
||||||
search_ftypes: repoID ? 'custom' : 'all',
|
search_ftypes: 'all',
|
||||||
ftype: repoID ? 'Markdown' : '',
|
|
||||||
input_fexts: repoID ? 'md' : ''
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
@@ -146,6 +144,8 @@ class Search extends Component {
|
|||||||
items[i]['name'] = data[i].name;
|
items[i]['name'] = data[i].name;
|
||||||
items[i]['path'] = data[i].fullpath;
|
items[i]['path'] = data[i].fullpath;
|
||||||
items[i]['repo_id'] = data[i].repo_id;
|
items[i]['repo_id'] = data[i].repo_id;
|
||||||
|
items[i]['repo_name'] = data[i].repo_name;
|
||||||
|
items[i]['is_dir'] = data[i].is_dir;
|
||||||
items[i]['link_content'] = decodeURI(data[i].fullpath).substring(1);
|
items[i]['link_content'] = decodeURI(data[i].fullpath).substring(1);
|
||||||
items[i]['content'] = data[i].content_highlight;
|
items[i]['content'] = data[i].content_highlight;
|
||||||
}
|
}
|
||||||
|
@@ -13,12 +13,13 @@ const propTypes = {
|
|||||||
|
|
||||||
class CommonToolbar extends React.Component {
|
class CommonToolbar extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
|
let searchPlaceholder = this.props.searchPlaceholder || 'Search Files'
|
||||||
return (
|
return (
|
||||||
<div className="common-toolbar">
|
<div className="common-toolbar">
|
||||||
{isPro && (
|
{isPro && (
|
||||||
<Search
|
<Search
|
||||||
repoID={this.props.repoID}
|
repoID={this.props.repoID}
|
||||||
placeholder={gettext(this.props.searchPlaceholder)}
|
placeholder={gettext(searchPlaceholder)}
|
||||||
onSearchedClick={this.props.onSearchedClick}
|
onSearchedClick={this.props.onSearchedClick}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@@ -13,7 +13,6 @@ class GeneralToolbar extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
// todo get repoID?
|
// todo get repoID?
|
||||||
let { onShowSidePanel, onSearchedClick } = this.props;
|
let { onShowSidePanel, onSearchedClick } = this.props;
|
||||||
let placeHolder = this.props.searchPlaceholder || 'Search files in this library';
|
|
||||||
return (
|
return (
|
||||||
<div className="main-panel-north">
|
<div className="main-panel-north">
|
||||||
<div className="cur-view-toolbar">
|
<div className="cur-view-toolbar">
|
||||||
@@ -24,8 +23,7 @@ class GeneralToolbar extends React.Component {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<CommonToolbar
|
<CommonToolbar
|
||||||
repoID={'todo'}
|
searchPlaceholder={this.props.searchPlaceholder}
|
||||||
searchPlaceholder={placeHolder}
|
|
||||||
onSearchedClick={onSearchedClick}
|
onSearchedClick={onSearchedClick}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -19,7 +19,6 @@ class GroupsToolbar extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { onShowSidePanel, onSearchedClick } = this.props;
|
let { onShowSidePanel, onSearchedClick } = this.props;
|
||||||
let placeHolder = this.props.searchPlaceholder || 'Search files in this library';
|
|
||||||
return (
|
return (
|
||||||
<div className="main-panel-north">
|
<div className="main-panel-north">
|
||||||
<div className="cur-view-toolbar">
|
<div className="cur-view-toolbar">
|
||||||
@@ -32,7 +31,7 @@ class GroupsToolbar extends React.Component {
|
|||||||
className="sf2-icon-menu side-nav-toggle hidden-md-up d-md-none">
|
className="sf2-icon-menu side-nav-toggle hidden-md-up d-md-none">
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<CommonToolbar searchPlaceholder={placeHolder} onSearchedClick={onSearchedClick}/>
|
<CommonToolbar searchPlaceholder={this.props.searchPlaceholder} onSearchedClick={onSearchedClick}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
.search-input {
|
.search-input {
|
||||||
height: 1.875rem;
|
height: 1.875rem;
|
||||||
|
width: 15rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-result-container {
|
.search-result-container {
|
||||||
|
@@ -283,13 +283,26 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = (item) => {
|
onSearchedClick = (item) => {
|
||||||
//just for file
|
if (item.is_dir) {
|
||||||
let path = item.path;
|
let path = item.path.slice(0, item.path.length - 1);
|
||||||
if (this.state.currentFilePath !== path) {
|
if (this.state.currentFilePath !== path) {
|
||||||
let tree = this.state.treeData.clone();
|
let tree = this.state.treeData.clone();
|
||||||
let node = tree.getNodeByPath(path);
|
let node = tree.getNodeByPath(path);
|
||||||
tree.expandNode(node);
|
tree.expandNode(node);
|
||||||
this.showFile(node.path);
|
this.showDir(node.path);
|
||||||
|
}
|
||||||
|
} else if (Utils.isMarkdownFile(item.path)) {
|
||||||
|
let path = item.path;
|
||||||
|
if (this.state.currentFilePath !== path) {
|
||||||
|
let tree = this.state.treeData.clone();
|
||||||
|
let node = tree.getNodeByPath(path);
|
||||||
|
tree.expandNode(node);
|
||||||
|
this.showFile(node.path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let url = siteRoot + 'lib/' + item.repo_id + '/file' + item.path;
|
||||||
|
let newWindow = window.open('about:blank');
|
||||||
|
newWindow.location.href = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -320,6 +320,19 @@ export const Utils = {
|
|||||||
} else {
|
} else {
|
||||||
return bytes + ' B';
|
return bytes + ' B';
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
isMarkdownFile: function(filePath) {
|
||||||
|
let index = filePath.lastIndexOf('.');
|
||||||
|
if (index === -1) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
let type = filePath.substring(index).toLowerCase();
|
||||||
|
if (type === '.md' || type === '.markdown') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -5,6 +5,7 @@ import MainPanel from './pages/wiki/main-panel';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { slug, repoID, siteRoot, initialPath } from './utils/constants';
|
import { slug, repoID, siteRoot, initialPath } from './utils/constants';
|
||||||
import editorUtilities from './utils/editor-utilties';
|
import editorUtilities from './utils/editor-utilties';
|
||||||
|
import { Utils } from './utils/utils';
|
||||||
import Node from './components/tree-view/node';
|
import Node from './components/tree-view/node';
|
||||||
import Tree from './components/tree-view/tree';
|
import Tree from './components/tree-view/tree';
|
||||||
import './assets/css/fa-solid.css';
|
import './assets/css/fa-solid.css';
|
||||||
@@ -113,14 +114,28 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = (item) => {
|
onSearchedClick = (item) => {
|
||||||
let path = item.path;
|
if (item.is_dir) {
|
||||||
if (this.state.filePath !== path) {
|
let path = item.path.slice(0, item.path.length - 1);
|
||||||
this.initMainPanelData(path);
|
if (this.state.filePath !== path) {
|
||||||
|
let tree = this.state.tree_data.clone();
|
||||||
let tree = this.state.tree_data.clone();
|
let node = tree.getNodeByPath(path);
|
||||||
let node = tree.getNodeByPath(path);
|
tree.expandNode(node);
|
||||||
tree.expandNode(node);
|
this.exitViewFileState(tree, node);
|
||||||
this.enterViewFileState(tree, node, node.path);
|
}
|
||||||
|
} else if (Utils.isMarkdownFile(item.path)) {
|
||||||
|
let path = item.path;
|
||||||
|
if (this.state.filePath !== path) {
|
||||||
|
this.initMainPanelData(path);
|
||||||
|
|
||||||
|
let tree = this.state.tree_data.clone();
|
||||||
|
let node = tree.getNodeByPath(path);
|
||||||
|
tree.expandNode(node);
|
||||||
|
this.enterViewFileState(tree, node, node.path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let url = siteRoot + 'lib/' + item.repo_id + '/file' + item.path;
|
||||||
|
let newWindow = window.open('about:blank');
|
||||||
|
newWindow.location.href = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user