|
|
@ -19,13 +19,15 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
let pathArray = []
|
|
|
|
let pathArray = []
|
|
|
|
var splitArray = window.location.pathname.split('shixun_show/');
|
|
|
|
var splitArray = window.location.pathname.split('shixun_show/');
|
|
|
|
if (splitArray[1]) {
|
|
|
|
if (splitArray[1]) {
|
|
|
|
pathArray = splitArray[1].split('/')
|
|
|
|
// pathArray = splitArray[1].split('/')
|
|
|
|
|
|
|
|
pathArray = decodeURIComponent(splitArray[1]).split('/')
|
|
|
|
if (pathArray[pathArray.length - 1] == '') {
|
|
|
|
if (pathArray[pathArray.length - 1] == '') {
|
|
|
|
// 有可能是这么访问的: http://localhost:3007/shixuns/3ozvy5f8/repository/fsu7tkaw/master/shixun_show/src/
|
|
|
|
// 有可能是这么访问的: http://localhost:3007/shixuns/3ozvy5f8/repository/fsu7tkaw/master/shixun_show/src/
|
|
|
|
pathArray.length = pathArray.length - 1;
|
|
|
|
pathArray.length = pathArray.length - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.state = {
|
|
|
|
this.state = {
|
|
|
|
|
|
|
|
listItemtype:false,
|
|
|
|
repositoryLoading: true,
|
|
|
|
repositoryLoading: true,
|
|
|
|
pathArray: pathArray,
|
|
|
|
pathArray: pathArray,
|
|
|
|
isContentWidth100: this._isFileInPathArray(pathArray)
|
|
|
|
isContentWidth100: this._isFileInPathArray(pathArray)
|
|
|
@ -33,6 +35,9 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (this.props.secret_repository_tab != prevProps.secret_repository_tab) {
|
|
|
|
if (this.props.secret_repository_tab != prevProps.secret_repository_tab) {
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
listItemtype:false,
|
|
|
|
|
|
|
|
})
|
|
|
|
this.fetchRepo()
|
|
|
|
this.fetchRepo()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,7 +69,7 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trace_collapse('tpm save code res: ', response)
|
|
|
|
trace_collapse('tpm save code res: ', response)
|
|
|
|
this.props.showSnackbar('文件保存成功')
|
|
|
|
this.props.showNotification('文件保存成功')
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((error)=>{
|
|
|
|
}).catch((error)=>{
|
|
|
|
console.log(error)
|
|
|
|
console.log(error)
|
|
|
@ -75,7 +80,7 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
|
|
|
|
|
|
|
|
// https://testeduplus2.educoder.net/shixuns/3ozvy5f8/file_content.json
|
|
|
|
// https://testeduplus2.educoder.net/shixuns/3ozvy5f8/file_content.json
|
|
|
|
this.setContentWidth100(true)
|
|
|
|
this.setContentWidth100(true)
|
|
|
|
this.setState({ repositoryLoading: true, pathArray: newPathArray })
|
|
|
|
//
|
|
|
|
let id = this.props.match.params.shixunId;
|
|
|
|
let id = this.props.match.params.shixunId;
|
|
|
|
let url = `/shixuns/${id}/file_content.json`;
|
|
|
|
let url = `/shixuns/${id}/file_content.json`;
|
|
|
|
axios.post(url, {
|
|
|
|
axios.post(url, {
|
|
|
@ -85,21 +90,37 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
trace_collapse('repository res: ', response)
|
|
|
|
trace_collapse('repository res: ', response)
|
|
|
|
|
|
|
|
|
|
|
|
if (response.data.status == -1) {
|
|
|
|
if (response.data.status == -1) {
|
|
|
|
this.props.showSnackbar('无法找到对应的资源,请变更地址或联系管理员!')
|
|
|
|
//this.props.showNotification('无法找到对应的资源,请变更地址或联系管理员!')
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.data.status == -2) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.props.showNotification(response.data.message)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(response.status === 200){
|
|
|
|
if(response.status === 200){
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
listItemtypes:true
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({ repositoryLoading: true, pathArray: newPathArray })
|
|
|
|
this.setState({
|
|
|
|
this.setState({
|
|
|
|
fileContent: response.data.content,
|
|
|
|
fileContent: response.data.content,
|
|
|
|
repositoryLoading: false
|
|
|
|
repositoryLoading: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if(response.data.content){
|
|
|
|
if(response.data.content){
|
|
|
|
this.props.history.replace(`${this.props.match.url}/master/shixun_show/${newPathArray.join('/')}`)
|
|
|
|
this.props.history
|
|
|
|
|
|
|
|
.replace(`/shixuns/${id}/repository` +
|
|
|
|
|
|
|
|
(newPathArray.length ? `/master/shixun_show/${newPathArray.join('/')}` : ''))
|
|
|
|
|
|
|
|
// this.props.history.replace(`${this.props.match.url}/master/shixun_show/${newPathArray.join('/')}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((error)=>{
|
|
|
|
}).catch((error)=>{
|
|
|
|
this.props.showSnackbar('无法找到对应的资源,请变更地址或联系管理员!')
|
|
|
|
// this.props.showNotification('无法找到对应的资源,请变更地址或联系管理员!')
|
|
|
|
console.log(error)
|
|
|
|
console.log(error)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,27 +135,42 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// listItem 如果是num,则是通过面包屑点击过来的,取pathArray的子集
|
|
|
|
// listItem 如果是num,则是通过面包屑点击过来的,取pathArray的子集
|
|
|
|
fetchRepo = (listItem) => {
|
|
|
|
fetchRepo = (listItem) => {
|
|
|
|
console.log(1)
|
|
|
|
|
|
|
|
debugger
|
|
|
|
// if(listItem === "main"||listItem){
|
|
|
|
|
|
|
|
// this.props.history.replace(`/shixuns/${this.props.match.params.shixunId}/repository`)
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// }
|
|
|
|
const { pathArray } = this.state;
|
|
|
|
const { pathArray } = this.state;
|
|
|
|
let newPathArray = pathArray.slice(0)
|
|
|
|
let newPathArray = pathArray.slice(0)
|
|
|
|
|
|
|
|
|
|
|
|
if (listItem === 0 || listItem) {
|
|
|
|
if (listItem === 0 || listItem) {
|
|
|
|
|
|
|
|
|
|
|
|
this.setContentWidth100(false)
|
|
|
|
this.setContentWidth100(false)
|
|
|
|
this.nameTypeMap[listItem.name] = listItem.type
|
|
|
|
this.nameTypeMap[listItem.name] = listItem.type
|
|
|
|
if (typeof listItem == 'number') { // 参数是数字的话,做截取
|
|
|
|
if (typeof listItem == 'number') { // 参数是数字的话,做截取
|
|
|
|
// if (this._isFileName(newPathArray[listItem])) { // 面包屑中的文件不让点击了
|
|
|
|
// if (this._isFileName(newPathArray[listItem])) { // 面包屑中的文件不让点击了
|
|
|
|
// listItem--;
|
|
|
|
// listItem--;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
listItemtypes:false
|
|
|
|
|
|
|
|
})
|
|
|
|
newPathArray = newPathArray.slice(0, listItem)
|
|
|
|
newPathArray = newPathArray.slice(0, listItem)
|
|
|
|
} else if (listItem.type === 'tree') {
|
|
|
|
} else if (listItem.type === 'tree') {
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
listItemtypes:false
|
|
|
|
|
|
|
|
})
|
|
|
|
newPathArray.push(listItem.name)
|
|
|
|
newPathArray.push(listItem.name)
|
|
|
|
} else if (listItem.type === 'blob') {
|
|
|
|
} else if (listItem.type === 'blob') {
|
|
|
|
|
|
|
|
|
|
|
|
newPathArray.push(listItem.name)
|
|
|
|
newPathArray.push(listItem.name)
|
|
|
|
this.setState({ pathArray: newPathArray })
|
|
|
|
// this.setState({ pathArray: newPathArray })
|
|
|
|
this.fetchCode(newPathArray)
|
|
|
|
this.fetchCode(newPathArray)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
listItemtypes:false
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// https://testeduplus2.educoder.net/shixuns/3ozvy5f8/repository.json
|
|
|
|
// https://testeduplus2.educoder.net/shixuns/3ozvy5f8/repository.json
|
|
|
|
this.setState({ repositoryLoading: true, pathArray: newPathArray })
|
|
|
|
this.setState({ repositoryLoading: true, pathArray: newPathArray })
|
|
|
@ -143,6 +179,7 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
if (newPathArray.length) {
|
|
|
|
if (newPathArray.length) {
|
|
|
|
fileInPathArray = this.nameTypeMap[newPathArray[newPathArray.length - 1]] ? this.nameTypeMap[newPathArray[newPathArray.length - 1]] !== 'tree'
|
|
|
|
fileInPathArray = this.nameTypeMap[newPathArray[newPathArray.length - 1]] ? this.nameTypeMap[newPathArray[newPathArray.length - 1]] !== 'tree'
|
|
|
|
: (listItem ? listItem.type !== 'tree' : this._isFileName( newPathArray[newPathArray.length - 1] ))
|
|
|
|
: (listItem ? listItem.type !== 'tree' : this._isFileName( newPathArray[newPathArray.length - 1] ))
|
|
|
|
|
|
|
|
|
|
|
|
if ( fileInPathArray ) {
|
|
|
|
if ( fileInPathArray ) {
|
|
|
|
urlNewPathArray = newPathArray.slice(0, newPathArray.length - 1)
|
|
|
|
urlNewPathArray = newPathArray.slice(0, newPathArray.length - 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -151,16 +188,18 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
|
|
|
|
|
|
|
|
let id = this.props.match.params.shixunId;
|
|
|
|
let id = this.props.match.params.shixunId;
|
|
|
|
let url = `/shixuns/${id}/${this.props.secret_repository_tab ? 'secret_repository' : 'repository'}.json`;
|
|
|
|
let url = `/shixuns/${id}/${this.props.secret_repository_tab ? 'secret_repository' : 'repository'}.json`;
|
|
|
|
|
|
|
|
|
|
|
|
// this.props.setLoadingContent(true)
|
|
|
|
// this.props.setLoadingContent(true)
|
|
|
|
axios.post(url, {
|
|
|
|
axios.post(url, {
|
|
|
|
path: path ? path : ''
|
|
|
|
path: path ? path : ''
|
|
|
|
}).then((response) => {
|
|
|
|
}).then((response) => {
|
|
|
|
|
|
|
|
|
|
|
|
// this.props.setLoadingContent(false)
|
|
|
|
// this.props.setLoadingContent(false)
|
|
|
|
|
|
|
|
|
|
|
|
const trees = response.data.trees
|
|
|
|
const trees = response.data.trees
|
|
|
|
const treeIsFileMap = {}
|
|
|
|
const treeIsFileMap = {}
|
|
|
|
if (!trees || !Array.isArray(trees)) {
|
|
|
|
if (!trees || !Array.isArray(trees)) {
|
|
|
|
// this.props.showSnackbar('无法找到对应的资源,请变更地址或联系管理员!')
|
|
|
|
// this.props.showNotification('无法找到对应的资源,请变更地址或联系管理员!')
|
|
|
|
// return;
|
|
|
|
// return;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
trees.forEach(item => {
|
|
|
|
trees.forEach(item => {
|
|
|
@ -169,19 +208,20 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(response.status === 200){
|
|
|
|
if(response.status === 200){
|
|
|
|
this.setState({
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
|
|
|
|
treeIsFileMap,
|
|
|
|
treeIsFileMap,
|
|
|
|
...response.data,
|
|
|
|
...response.data,
|
|
|
|
repositoryLoading: false
|
|
|
|
repositoryLoading: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// console.log(response)
|
|
|
|
|
|
|
|
// console.log(newPathArray.length)
|
|
|
|
this.props.history
|
|
|
|
// this.props.history
|
|
|
|
.replace(`/shixuns/${id}/repository` +
|
|
|
|
// .replace(`${this.props.match.url}` +
|
|
|
|
(newPathArray.length ? `/master/shixun_show/${newPathArray.join('/')}` : ''))
|
|
|
|
// (newPathArray.length ? `/master/shixun_show/${newPathArray.join('/')}` : ''))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化时,repo接口完毕后需要看是否需要fetchCode
|
|
|
|
// 初始化时,repo接口完毕后需要看是否需要fetchCode
|
|
|
|
if (fileInPathArray) {
|
|
|
|
if (fileInPathArray) {
|
|
|
|
|
|
|
|
//
|
|
|
|
this.fetchCode(newPathArray)
|
|
|
|
this.fetchCode(newPathArray)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// info(response)
|
|
|
|
// info(response)
|
|
|
@ -192,30 +232,45 @@ class TPMRepositoryComponent extends Component {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oncodechanner=()=>{
|
|
|
|
|
|
|
|
this.fetchRepo(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
render() {
|
|
|
|
const { isContentWidth100 } = this.state;
|
|
|
|
const { listItemtypes } = this.state;
|
|
|
|
let matchpath =this.props.match.path;
|
|
|
|
let matchpath =this.props.match.path;
|
|
|
|
let flag =false;
|
|
|
|
let flag =false;
|
|
|
|
if(matchpath==="/shixuns/:shixunId/repository"){
|
|
|
|
|
|
|
|
flag =true;
|
|
|
|
// if(matchpath==="/shixuns/:shixunId/repository"){
|
|
|
|
}else if(matchpath==="/shixuns/:shixunId/secret_repository"){
|
|
|
|
// flag =true;
|
|
|
|
flag =true;
|
|
|
|
// }else if(matchpath==="/shixuns/:shixunId/secret_repository"){
|
|
|
|
}
|
|
|
|
// flag =true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 需要重构
|
|
|
|
// 需要重构
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<React.Fragment>
|
|
|
|
{ flag ? <TPMRepository
|
|
|
|
{ listItemtypes===false? <TPMRepository
|
|
|
|
{...this.props}
|
|
|
|
{...this.props}
|
|
|
|
{...this.state}
|
|
|
|
{...this.state}
|
|
|
|
nameTypeMap={this.nameTypeMap}
|
|
|
|
nameTypeMap={this.nameTypeMap}
|
|
|
|
fetchRepo={this.fetchRepo}
|
|
|
|
fetchRepo={this.fetchRepo}
|
|
|
|
is_jupyter={this.props.is_jupyter}
|
|
|
|
is_jupyter={this.props.is_jupyter}
|
|
|
|
isflag={flag}
|
|
|
|
listItemtypes={listItemtypes}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
</TPMRepository>
|
|
|
|
</TPMRepository>
|
|
|
|
:""
|
|
|
|
: <div>
|
|
|
|
|
|
|
|
{/* 可能会影响到其他页面的样式,需要测试、协商 */}
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
<RepositoryCodeEditor
|
|
|
|
|
|
|
|
{...this.state}
|
|
|
|
|
|
|
|
{...this.props}
|
|
|
|
|
|
|
|
fetchRepo={this.fetchRepo}
|
|
|
|
|
|
|
|
saveCode={this.saveCode}
|
|
|
|
|
|
|
|
nameTypeMap={this.nameTypeMap}
|
|
|
|
|
|
|
|
oncodechanner={this.oncodechanner}
|
|
|
|
|
|
|
|
></RepositoryCodeEditor>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</React.Fragment>
|
|
|
|
</React.Fragment>
|
|
|
|