mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
add search module
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;
|
||||||
}
|
}
|
||||||
|
@@ -283,7 +283,15 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = (item) => {
|
onSearchedClick = (item) => {
|
||||||
//just for file
|
if (item.is_dir) {
|
||||||
|
let path = item.path.slice(0, item.path.length - 1);
|
||||||
|
if (this.state.currentFilePath !== path) {
|
||||||
|
let tree = this.state.treeData.clone();
|
||||||
|
let node = tree.getNodeByPath(path);
|
||||||
|
tree.expandNode(node);
|
||||||
|
this.showDir(node.path);
|
||||||
|
}
|
||||||
|
} else if (Utils.isMarkdownFile(item.path)) {
|
||||||
let path = item.path;
|
let path = item.path;
|
||||||
if (this.state.currentFilePath !== path) {
|
if (this.state.currentFilePath !== path) {
|
||||||
let tree = this.state.treeData.clone();
|
let tree = this.state.treeData.clone();
|
||||||
@@ -291,6 +299,11 @@ class Wiki extends Component {
|
|||||||
tree.expandNode(node);
|
tree.expandNode(node);
|
||||||
this.showFile(node.path);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMainNavBarClick = (nodePath) => {
|
onMainNavBarClick = (nodePath) => {
|
||||||
|
@@ -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,6 +114,15 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSearchedClick = (item) => {
|
onSearchedClick = (item) => {
|
||||||
|
if (item.is_dir) {
|
||||||
|
let path = item.path.slice(0, item.path.length - 1);
|
||||||
|
if (this.state.filePath !== path) {
|
||||||
|
let tree = this.state.tree_data.clone();
|
||||||
|
let node = tree.getNodeByPath(path);
|
||||||
|
tree.expandNode(node);
|
||||||
|
this.exitViewFileState(tree, node);
|
||||||
|
}
|
||||||
|
} else if (Utils.isMarkdownFile(item.path)) {
|
||||||
let path = item.path;
|
let path = item.path;
|
||||||
if (this.state.filePath !== path) {
|
if (this.state.filePath !== path) {
|
||||||
this.initMainPanelData(path);
|
this.initMainPanelData(path);
|
||||||
@@ -122,6 +132,11 @@ class Wiki extends Component {
|
|||||||
tree.expandNode(node);
|
tree.expandNode(node);
|
||||||
this.enterViewFileState(tree, node, node.path);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMainNavBarClick = (nodePath) => {
|
onMainNavBarClick = (nodePath) => {
|
||||||
|
Reference in New Issue
Block a user