diff --git a/src/forge/Settings/Setting.js b/src/forge/Settings/Setting.js index 00e0b2e0a..34dcd7f9b 100644 --- a/src/forge/Settings/Setting.js +++ b/src/forge/Settings/Setting.js @@ -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(`仓库信息修改成功!`); diff --git a/src/forge/Wiki/EditWiki.jsx b/src/forge/Wiki/EditWiki.jsx index 728f6e775..bf89653c8 100644 --- a/src/forge/Wiki/EditWiki.jsx +++ b/src/forge/Wiki/EditWiki.jsx @@ -354,7 +354,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail, })()} - 添加模版 + 添加模版 周报 diff --git a/src/forge/Wiki/Index.jsx b/src/forge/Wiki/Index.jsx index 1c8eb99cd..08288c366 100644 --- a/src/forge/Wiki/Index.jsx +++ b/src/forge/Wiki/Index.jsx @@ -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}`)); } // 支持 Markdown,Html,Pdf格式文件 @@ -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){ + // 不存在的wiki,修正sidebarfindSameKeyByDel + 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) => {
{/* 读sidebar转换成目录树 */} - +
@@ -327,7 +325,7 @@ export default (props) => { {permission && } - {itemDetail&&itemDetail.md_content&&} + {itemDetail && itemDetail.md_content && } diff --git a/src/forge/Wiki/Index.scss b/src/forge/Wiki/Index.scss index e79567d69..58ffcef09 100644 --- a/src/forge/Wiki/Index.scss +++ b/src/forge/Wiki/Index.scss @@ -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 { diff --git a/src/forge/Wiki/Preview.jsx b/src/forge/Wiki/Preview.jsx index 2b700f60c..4dfec1cc3 100644 --- a/src/forge/Wiki/Preview.jsx +++ b/src/forge/Wiki/Preview.jsx @@ -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 + }) } } diff --git a/src/forge/Wiki/api.js b/src/forge/Wiki/api.js index 2250ec5f4..301d096cf 100644 --- a/src/forge/Wiki/api.js +++ b/src/forge/Wiki/api.js @@ -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 + }) } \ No newline at end of file diff --git a/src/forge/Wiki/components/sidebar/index.jsx b/src/forge/Wiki/components/sidebar/index.jsx index d7046edb0..5004a0345 100644 --- a/src/forge/Wiki/components/sidebar/index.jsx +++ b/src/forge/Wiki/components/sidebar/index.jsx @@ -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) { - { - masterProtected && item.children.length ? { message.error("由于master分支设置了分支保护,不允许删除wiki") }}>删除 : - { deleteFileModal(e, title, isFile, item) }}>删除 - } + { deleteFileModal(e, title, isFile, item) }}>删除 }; @@ -82,10 +79,7 @@ export default function Sidebar(props) { - { - masterProtected ? { message.error("由于master分支设置了分支保护,不允许删除wiki") }}>删除 : - { deleteFileModal(e, title, isFile, item) }}>删除 - } + { deleteFileModal(e, title, isFile, item) }}>删除 };