Merge remote-tracking branch 'upstream/gitlink_server' into gitlink_server

This commit is contained in:
黄心宇 2024-03-22 09:15:11 +08:00
commit c5b3dd99dd
7 changed files with 63 additions and 50 deletions

View File

@ -163,13 +163,16 @@ class Setting extends Component {
update=(values)=>{
const { projectsId , owner } = this.props.match.params;
const { private_check , project_units } = this.state;
const {project_language_id, project_category_id, pr_view_admin} = values;
const url = `/${owner}/${projectsId}.json`;
axios.put(url, {
axios.patch(url, {
name: values.project_name,
description: values.project_description,
private: private_check,
identifier:values.project_identifier,
...values,
project_language_id,
project_category_id,
pr_view_admin
}).then((result) => {
if (result) {
this.props.showNotification(`仓库信息修改成功!`);

View File

@ -354,7 +354,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
})(<Input style={{ display: 'none' }} />)}
</Form.Item>
<Checkbox checked={modal} onChange={changeModal}>添加模版</Checkbox>
<Checkbox checked={modal} onChange={changeModal} className='mt10'>添加模版</Checkbox>
<Radio.Group onChange={changeModalType} value={modalType}>
<Radio value='周报'>周报</Radio>

View File

@ -5,7 +5,7 @@ import CopyTool from '../Component/CopyTool';
import Welcome from './Welcome';
import RenderHtml from "../../components/render-html";
import { wikiPages, getWiki, parseSidebar, updateWiki, treeToMd } from './api';
import { wikiPages, getWiki, parseSidebar, updateWiki, treeToMd, deleteSameKey } from './api';
import { httpUrl } from './fetch';
import './Index.scss';
import './components/ModalFun/index.scss';
@ -38,18 +38,9 @@ export default (props) => {
const [addMenuError, setAddMenuError] = useState(undefined);
const [sidebar, setSidebar] = useState(undefined);
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState(undefined);
const [masterProtected, setMasterProtected] = useState(false);
useEffect(()=>{
window.scrollTo(0,0);
// master
if(projectsId && owner){
axios.get(`/v1/${owner}/${projectsId}/branches.json`, {keyword: 'master'}).then(res=>{
if(res && res.data && res.data.total_count === 1){
setMasterProtected(res.data.branches[0].protected);
}
})
}
}, [])
useEffect(()=>{
@ -84,9 +75,9 @@ export default (props) => {
setSidebar(sidebar)
setFileList(menuList);
let firstWikiNode = undefined;
const arr = pathname.split('/');
if(!pathname.endsWith('/wiki')){
firstWikiNode = findNodeByName(menuList, arr[arr.length-2]);
const {wikiName} = match.params;
firstWikiNode = findNodeByName(menuList, wikiName);
} else{
// [[]]
firstWikiNode = findFirstWiki(menuList);
@ -95,14 +86,14 @@ export default (props) => {
!firstWikiNode && (firstWikiNode = findFirstWiki(menuList));
//
setDefaultSelectedKeys([firstWikiNode.key+""]);
const title = firstWikiNode.title.trim().substring(2,firstWikiNode.title.trim().length-2);
const title = firstWikiNode.titleStr;
const firstWiki = res.data.filter(item => { return title === item.name })[0];
setCheckItem({
...firstWiki,
key: firstWikiNode.key
})
if(window.location.pathname.indexOf('/wiki') === -1) return
history.push(`/${owner}/${projectsId}/wiki/${title}/${firstWikiNode.key}`);
history.push(encodeURI(`/${owner}/${projectsId}/wiki/${firstWiki.sub_url}/${firstWikiNode.key}`));
} else {
setFileArr([]);
setFileArrInit([]);
@ -110,9 +101,9 @@ export default (props) => {
});
}, [project, reload])
// wiki
// wiki,sub_url:
useEffect(() => {
project && checkItem.name && getWiki({
project && checkItem.sub_url && getWiki({
owner: owner,
repo: projectsId,
pageName: checkItem.sub_url,
@ -228,11 +219,11 @@ export default (props) => {
}
function goEdit(params) {
history.push(`/${owner}/${projectsId}/wiki/${encodeURI(checkItem.sub_url)}/${checkItem.key}/edit${params}`);
history.push(encodeURI(`/${owner}/${projectsId}/wiki/${checkItem.sub_url}/${checkItem.key}/edit${params}`));
}
function preview() {
window.open(`/${owner}/${projectsId}/wiki/preview/${encodeURI(project.name)}/${project.id}`);
window.open(encodeURI(`/${owner}/${projectsId}/wiki/preview/${project.name}/${project.id}`));
}
// MarkdownHtmlPdf
@ -257,11 +248,18 @@ export default (props) => {
function changeitem(item){
const {name, key} = item;
const wiki = fileArrInit.filter(item => { return item.name == name })[0];
if(!wiki){
// wikisidebarfindSameKeyByDel
const menuListByDel = deleteSameKey(fileList, key);
updateWikiFun(menuListByDel);
message.success("不存在的wiki")
return
}
setCheckItem({
...wiki,
key
})
history.push(`/${owner}/${projectsId}/wiki/${name}/${key}`);
history.push(encodeURI(`/${owner}/${projectsId}/wiki/${name}/${key}`));
}
return (
@ -297,7 +295,7 @@ export default (props) => {
<div className="wiki-nav">
{/* 读sidebar转换成目录树 */}
<Sidebar fileList = {fileList} changeitem={changeitem} projectsId={projectsId} owner={owner} project={project} setReload={setReload} sidebar={sidebar} history={history} permission={permission} defaultSelectedKeys={defaultSelectedKeys} fileArrInit={fileArrInit} masterProtected={masterProtected}/>
<Sidebar fileList = {fileList} changeitem={changeitem} projectsId={projectsId} owner={owner} project={project} setReload={setReload} sidebar={sidebar} history={history} permission={permission} defaultSelectedKeys={defaultSelectedKeys} fileArrInit={fileArrInit}/>
</div>
</div>
@ -327,7 +325,7 @@ export default (props) => {
{permission && <Button type="primary" onClick={()=>{goEdit("")}}>编辑</Button>}
</div>
{itemDetail&&itemDetail.md_content&&<RenderHtml className="wiki-content-detail editor-content-panel imageLayerParent" value={ itemDetail && Base64.decode(itemDetail.md_content) } url={history.location}/>}
{itemDetail && itemDetail.md_content && <RenderHtml className="wiki-content-detail editor-content-panel imageLayerParent" value={Base64.decode(itemDetail.md_content) } url={history.location}/>}
</div>
</div>
</div >

View File

@ -102,13 +102,13 @@ body {
font-family: "PingFangSC-Regular";
}
.has-error .ant-form-explain,
.has-error .ant-form-split {
position: absolute;
}
.wiki-md .ant-form-explain{
bottom: -6px;
}
// .has-error .ant-form-explain,
// .has-error .ant-form-split {
// position: absolute;
// }
// .wiki-md .ant-form-explain{
// bottom: -6px;
// }
.wiki-nav {
max-height: 60vh;
.wiki-search {

View File

@ -60,7 +60,7 @@ export default (props) => {
useEffect(() => {
projectsId && checkItem.name && getWiki({
projectsId && checkItem.sub_url && getWiki({
owner: owner,
repo: projectsId,
pageName: checkItem.sub_url,
@ -111,12 +111,13 @@ export default (props) => {
}
function selectTree(keys,event){
let {title, key} = event.node.props.dataRef;
title = title.trim()
const isFile = title.startsWith('[[') && title.endsWith(']]');
let {isFile, key, titleStr} = event.node.props.dataRef;
if(isFile){
title = title.substring(2,title.length-2);
setCheckItem({name: title, key});
const wiki = fileArr.filter(item => { return item.name == titleStr })[0];
setCheckItem({
...wiki,
key
})
}
}

View File

@ -72,7 +72,7 @@ export async function parseSidebar(wikiList, info){
})
}
ReInfo={
menuList: markdownToTree(list.length ? `${sidebarCont}${wikiSidebar}` : sidebarCont),
menuList: markdownToTree(list.length ? `${sidebarCont}${wikiSidebar}` : sidebarCont, wikiList),
sidebar: sidebarCont
}
}
@ -96,14 +96,14 @@ export async function parseSidebar(wikiList, info){
content_base64: Base64.encode(wikiSidebarStr)
})
ReInfo={
menuList: markdownToTree(wikiSidebarStr),
menuList: markdownToTree(wikiSidebarStr, wikiList),
sidebar: wikiSidebarStr
}
}
return ReInfo;
}
export function markdownToTree(markdownText){
export function markdownToTree(markdownText, wikiList){
const lines = markdownText.split('\n');
let key = -1;
// stack: [{一级目录}{二级目录}]
@ -113,6 +113,10 @@ export function markdownToTree(markdownText){
children: [],
key: key++
}
const wikiNameAndSubUrl = {}
wikiList && wikiList.map(item=>{
return wikiNameAndSubUrl[item.name] = item.sub_url
})
lines.map((item, index) =>{
const title = item.trim();
const isFile = title.startsWith('[[') && title.endsWith(']]');
@ -125,7 +129,7 @@ export function markdownToTree(markdownText){
// 纯内容
titleStr,
// 编码后的title,获取wiki内容用title_sub
title_sub: encodeURIComponent(titleStr),
title_sub: wikiNameAndSubUrl[titleStr],
// 是否是wiki文件
isFile: isFile
}
@ -256,4 +260,17 @@ export function findFirstWiki(list){
}
}
}
}
// 递归过滤相同key值的节点
export function deleteSameKey(list, key){
return list.filter(item => {
if (item.key === key) {
return false
}
if(item.children && item.children.length > 0){
item.children = deleteSameKey(item.children , key)
}
return true
})
}

View File

@ -12,7 +12,7 @@ const {DirectoryTree, TreeNode} = Tree;
// wiki
export default function Sidebar(props) {
const {fileList, changeitem, owner, projectsId, project, setReload, sidebar, history, permission, defaultSelectedKeys, fileArrInit, masterProtected} = props;
const {fileList, changeitem, owner, projectsId, project, setReload, sidebar, history, permission, defaultSelectedKeys, fileArrInit} = props;
const {location:{pathname}} = history;
const [initMenuList, setInitMenuList] = useState(undefined);
const [menuList, setMenuList] = useState(undefined);
@ -66,10 +66,7 @@ export default function Sidebar(props) {
</a>
</Menu.Item>
<Menu.Item>
{
masterProtected && item.children.length ? <a onClick={() => { message.error("由于master分支设置了分支保护不允许删除wiki") }}>删除</a> :
<a onClick={(e) => { deleteFileModal(e, title, isFile, item) }}>删除</a>
}
<a onClick={(e) => { deleteFileModal(e, title, isFile, item) }}>删除</a>
</Menu.Item>
</Menu>
};
@ -82,10 +79,7 @@ export default function Sidebar(props) {
</a>
</Menu.Item>
<Menu.Item>
{
masterProtected ? <a onClick={() => { message.error("由于master分支设置了分支保护不允许删除wiki") }}>删除</a> :
<a onClick={(e) => { deleteFileModal(e, title, isFile, item) }}>删除</a>
}
<a onClick={(e) => { deleteFileModal(e, title, isFile, item) }}>删除</a>
</Menu.Item>
</Menu>
};