From c353f7322a184f721931a0cce5f1a1faaf560eaa Mon Sep 17 00:00:00 2001
From: "sylor_huang@126.com"
Date: Thu, 4 Jun 2020 18:28:26 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/AppConfig.js | 2 +-
src/forge/Main/CoderRootDirectory.js | 698 ++++++++++++++---------
src/forge/Main/Detail.js | 13 +-
src/forge/Main/IndexItem.js | 2 +-
src/forge/Newfile/Index.js | 2 -
src/forge/Newfile/UserSubmitComponent.js | 34 +-
src/forge/Newfile/index.css | 8 +-
src/forge/Newfile/m_editor.js | 4 +-
src/forge/Newfile/upload_file.js | 75 +++
src/forge/Upload/Index.js | 4 +-
src/forge/Upload/read.js | 104 ++++
src/forge/UsersList/focus_button.js | 3 +-
src/forge/UsersList/user_list.js | 12 +-
src/forge/comments/new.js | 8 +-
src/forge/users/Infos.js | 7 +-
src/modules/login/LoginDialog.js | 8 +-
src/modules/tpm/NewHeader.js | 4 +-
17 files changed, 674 insertions(+), 314 deletions(-)
create mode 100644 src/forge/Newfile/upload_file.js
create mode 100644 src/forge/Upload/read.js
diff --git a/src/AppConfig.js b/src/AppConfig.js
index 3299fdb0..d94d50e6 100644
--- a/src/AppConfig.js
+++ b/src/AppConfig.js
@@ -100,7 +100,7 @@ export function initAxiosInterceptors(props) {
// TODO 读取到package.json中的配置?
var proxy = "http://localhost:3000"
// proxy = "https://pre-newweb.educoder.net"
- // proxy = "https://testforgeplus.trustie.net/"
+ proxy = "https://testforgeplus.trustie.net/"
// 在这里使用requestMap控制,避免用户通过双击等操作发出重复的请求;
// 如果需要支持重复的请求,考虑config里面自定义一个allowRepeat参考来控制
diff --git a/src/forge/Main/CoderRootDirectory.js b/src/forge/Main/CoderRootDirectory.js
index 5757d229..2e397034 100644
--- a/src/forge/Main/CoderRootDirectory.js
+++ b/src/forge/Main/CoderRootDirectory.js
@@ -1,17 +1,17 @@
-import React , { Component } from 'react';
-import {Menu, Spin} from 'antd';
-import { getImageUrl } from 'educoder';
-import { Link } from 'react-router-dom';
+import React, { Component } from "react";
+import { Menu, Spin, Button } from "antd";
+import { getImageUrl } from "educoder";
+import { Link } from "react-router-dom";
-import './list.css';
-import SelectBranch from '../Branch/SelectBranch';
-import CloneAddress from '../Branch/CloneAddress';
-import RootTable from './RootTable';
-import CoderRootFileDetail from './CoderRootFileDetail';
-import { truncateCommitId } from '../common/util';
-import RenderHtml from '../../components/render-html';
+import "./list.css";
+import SelectBranch from "../Branch/SelectBranch";
+import CloneAddress from "../Branch/CloneAddress";
+import RootTable from "./RootTable";
+import CoderRootFileDetail from "./CoderRootFileDetail";
+import { truncateCommitId } from "../common/util";
+import RenderHtml from "../../components/render-html";
-import axios from 'axios';
+import axios from "axios";
/**
* address:http和SSH,http_url(对应git地址)
* branch:当前分支
@@ -20,389 +20,533 @@ import axios from 'axios';
* readMeContent:根目录下面的readme文件内容
*/
-class CoderRootDirectory extends Component{
- constructor(props){
+class CoderRootDirectory extends Component {
+ constructor(props) {
super(props);
- this.state={
- address:"http",
- branch:"master",
- filePath:undefined,
- subFileType:undefined,
- readMeContent:undefined,
+ this.state = {
+ address: "http",
+ branch: "master",
+ filePath: undefined,
+ subFileType: undefined,
+ readMeContent: undefined,
readMeFile: undefined,
- isSpin:true,
+ isSpin: true,
- branchList:undefined,
- fileDetail:undefined,
- branchLastCommit:undefined,
- lastCommitAuthor:undefined,
+ branchList: undefined,
+ fileDetail: undefined,
+ branchLastCommit: undefined,
+ lastCommitAuthor: undefined,
- rootList:undefined,
+ rootList: undefined,
readOnly: true,
- zip_url:undefined,
- tar_url:undefined
- }
+ zip_url: undefined,
+ tar_url: undefined,
+ };
}
- changeAddress=(address)=>{
+ changeAddress = (address) => {
this.setState({
- address
- })
- }
+ address,
+ });
+ };
-
- componentDidMount=()=>{
+ componentDidMount = () => {
this.Init();
- }
+ };
- componentDidUpdate=(prevState)=>{
- const {location} = this.props;
+ componentDidUpdate = (prevState) => {
+ const { location } = this.props;
const prevlocation = prevState && prevState.location;
- if(location !== prevlocation){
+ if (location !== prevlocation) {
this.setState({
- isSpin:true
- })
+ isSpin: true,
+ });
this.Init();
}
- }
+ };
- Init=()=>{
+ Init = () => {
let { search } = this.props.history.location;
let branchName = undefined;
- if(search && search.indexOf("?branch=")>-1){
+ if (search && search.indexOf("?branch=") > -1) {
branchName = search.split("?branch=")[1];
this.setState({
- branch:branchName
- })
+ branch: branchName,
+ });
}
- if(search && search.indexOf("?url=")>-1){
- let url =search.split("?url=")[1];
+ if (search && search.indexOf("?url=") > -1) {
+ let url = search.split("?url=")[1];
this.setState({
- filePath:url
- })
+ filePath: url,
+ });
this.getFileDetail(url);
- }else{
+ } else {
const { branch } = this.state;
- this.getProjectRoot( branchName || branch);
+ this.getProjectRoot(branchName || branch);
}
- }
+ };
// 页面地址返回到主目录
- returnMain=(branch)=>{
+ returnMain = (branch) => {
const { projectsId } = this.props.match.params;
this.props.history.push(`/projects/${projectsId}/coders`);
this.getProjectRoot(branch);
- }
+ };
// 获取根目录
- getProjectRoot=(branch)=>{
+ getProjectRoot = (branch) => {
const { projectsId } = this.props.match.params;
const url = `/repositories/${projectsId}/entries.json`;
- axios.get((url),{
- params:{
- branch
- }
- }).then((result)=>{
- if(result){
- let last_commit = result.data && result.data.last_commit;
- let entries = result.data && result.data.entries;
- this.setState({
- filePath:undefined,
- fileDetail:undefined,
- isSpin: false,
- branchLastCommit:last_commit && last_commit.commit,
- lastCommitAuthor:last_commit && (last_commit.author || (last_commit.commit && last_commit.commit.author)),
- zip_url:result.data.zip_url,
- tar_url:result.data.tar_url
- })
- if(entries && entries.length > 0){
- this.renderData(entries);
+ axios
+ .get(url, {
+ params: {
+ branch,
+ },
+ })
+ .then((result) => {
+ if (result) {
+ let last_commit = result.data && result.data.last_commit;
+ let entries = result.data && result.data.entries;
+ this.setState({
+ filePath: undefined,
+ fileDetail: undefined,
+ isSpin: false,
+ branchLastCommit: last_commit && last_commit.commit,
+ lastCommitAuthor:
+ last_commit &&
+ (last_commit.author ||
+ (last_commit.commit && last_commit.commit.author)),
+ zip_url: result.data.zip_url,
+ tar_url: result.data.tar_url,
+ });
+ if (entries && entries.length > 0) {
+ this.renderData(entries);
+ }
+ this.setState({
+ rootList: entries,
+ subFileType: true,
+ });
}
- this.setState({
- rootList:entries,
- subFileType:true
- })
- }
+ })
+ .catch((error) => {});
+ };
- }).catch((error)=>{})
- }
-
- ChangeFile=(arr,readOnly)=>{
+ ChangeFile = (arr, readOnly) => {
const { projectsId } = this.props.match.params;
//点击直接跳转页面 加载一次路由
this.props.history.push(`/projects/${projectsId}/coders?url=${arr.path}`);
this.setState({
- readOnly: readOnly
- })
- }
+ readOnly: readOnly,
+ });
+ };
- renderUrl=(name,path,type)=>{
- let list =[];
+ renderUrl = (name, path, type) => {
+ let list = [];
const { filePath } = this.state;
- if(path.indexOf("/")){
+ if (path.indexOf("/")) {
const array = path.split("/");
let str = "";
- array.map((i,k)=>{
- str += '/'+i;
+ array.map((i, k) => {
+ str += "/" + i;
return list.push({
- key:k,
- index:k,
- name:i,
- path:str.substr(1),
- type:(filePath && filePath.length>0) ? (filePath[k] ? filePath[k].type : type) : type
- })
- })
+ key: k,
+ index: k,
+ name: i,
+ path: str.substr(1),
+ type:
+ filePath && filePath.length > 0
+ ? filePath[k]
+ ? filePath[k].type
+ : type
+ : type,
+ });
+ });
const { projectsId } = this.props.match.params;
//点击直接跳转页面 加载一次路由
- this.props.history.push(`/projects/${projectsId}/coders?url=${str.substr(1)}`);
- }else{
+ this.props.history.push(
+ `/projects/${projectsId}/coders?url=${str.substr(1)}`
+ );
+ } else {
list.push({
- index:0,
- name,path,type
- })
+ index: 0,
+ name,
+ path,
+ type,
+ });
}
this.setState({
- filePath:list
- })
- }
+ filePath: list,
+ });
+ };
// 获取子目录
- getFileDetail=(path,ref)=>{
+ getFileDetail = (path, ref) => {
const { projectsId } = this.props.match.params;
const { branch } = this.state;
- const url =`/repositories/${projectsId}/sub_entries.json`;
+ const url = `/repositories/${projectsId}/sub_entries.json`;
- axios.get(url,{
- params:{
- filepath:path,
- ref:ref || branch
- }
- }).then((result)=>{
- let entries = result.data && result.data.entries
- if(entries && entries.length > 0){
- // 当前返回的子目录只有一条数据,且这条数据返回的是文件类型
- if(entries.length === 1 && entries[0].type === "file"){
- this.setState({
- fileDetail:entries,
- rootList:undefined,
- isSpin:false,
- subFileType:false
- })
- }else{
- this.setState({
- fileDetail:undefined,
- rootList:entries,
- isSpin:false,
- branchLastCommit:result.data.last_commit && result.data.last_commit.commit,
- lastCommitAuthor:result.data.last_commit && (result.data.last_commit.author || (result.data.last_commit.commit && result.data.last_commit.commit.author))
- })
- this.renderData(entries);
+ axios
+ .get(url, {
+ params: {
+ filepath: path,
+ ref: ref || branch,
+ },
+ })
+ .then((result) => {
+ let entries = result.data && result.data.entries;
+ if (entries && entries.length > 0) {
+ // 当前返回的子目录只有一条数据,且这条数据返回的是文件类型
+ if (entries.length === 1 && entries[0].type === "file") {
+ this.setState({
+ fileDetail: entries,
+ rootList: undefined,
+ isSpin: false,
+ subFileType: false,
+ });
+ } else {
+ this.setState({
+ fileDetail: undefined,
+ rootList: entries,
+ isSpin: false,
+ branchLastCommit:
+ result.data.last_commit && result.data.last_commit.commit,
+ lastCommitAuthor:
+ result.data.last_commit &&
+ (result.data.last_commit.author ||
+ (result.data.last_commit.commit &&
+ result.data.last_commit.commit.author)),
+ });
+ this.renderData(entries);
+ }
}
- }
- }).catch((error)=>{
- console.log(error);
- })
- }
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ };
- renderData=(data)=>{
+ renderData = (data) => {
const rootList = [];
const readMeContent = [];
const readMeFile = [];
- data && data.map((item,key)=>{
- rootList.push({
- key,
- message:item.commit && item.commit.message,
- ...item
- })
- if(item.name === 'README.md'){
- readMeContent.push({...item})
- readMeFile.push({...item})
- }
- })
+ data &&
+ data.map((item, key) => {
+ rootList.push({
+ key,
+ message: item.commit && item.commit.message,
+ ...item,
+ });
+ if (item.name === "README.md") {
+ readMeContent.push({ ...item });
+ readMeFile.push({ ...item });
+ }
+ });
this.setState({
- rootList:rootList,
+ rootList: rootList,
readMeContent,
- readMeFile
- })
- }
+ readMeFile,
+ });
+ };
// 点击跳转到子目录
- goToSubRoot=(path)=>{
+ goToSubRoot = (path) => {
const { projectsId } = this.props.match.params;
this.props.history.push(`/projects/${projectsId}/coders?url=${path}`);
- }
+ };
// readme文件内容
- renderReadMeContent=(readMeContent, permission)=>{
- const { fileDetail,readMeFile } = this.state;
- if(fileDetail){return;}
- if(readMeContent && readMeContent.length > 0){
- return(
+ renderReadMeContent = (readMeContent, permission) => {
+ const { fileDetail, readMeFile } = this.state;
+ if (fileDetail) {
+ return;
+ }
+ if (readMeContent && readMeContent.length > 0) {
+ return (
- {
- readMeContent[0].content ?
-
- :
+ {readMeContent[0].content ? (
+
+ ) : (
暂无~
- }
+ )}
- )
+ );
}
- }
+ };
// 选择分支
- changeBranch=(value)=>{
+ changeBranch = (value) => {
this.setState({
- branch:value,
- isSpin: true
- })
+ branch: value,
+ isSpin: true,
+ });
let { search } = this.props.history.location;
- if(search && search.indexOf("?url=")>-1){
- let url =search.split("?url=")[1];
+ if (search && search.indexOf("?url=") > -1) {
+ let url = search.split("?url=")[1];
this.setState({
- filePath:url
- })
+ filePath: url,
+ });
this.getFileDetail(url, value);
- }else{
- this.getProjectRoot( value );
+ } else {
+ this.getProjectRoot(value);
}
- }
- render(){
- const { branchLastCommit , lastCommitAuthor , rootList , branch ,filePath , fileDetail , subFileType , readMeContent, isSpin , zip_url , tar_url} = this.state;
- const { isManager , isDeveloper , projectDetail } = this.props;
+ };
+ render() {
+ const {
+ branchLastCommit,
+ lastCommitAuthor,
+ rootList,
+ branch,
+ filePath,
+ fileDetail,
+ subFileType,
+ readMeContent,
+ isSpin,
+ zip_url,
+ tar_url,
+ } = this.state;
+ const { isManager, isDeveloper, projectDetail } = this.props;
const { projectsId } = this.props.match.params;
const columns = [
{
- dataIndex: 'name',
- width:"30%",
- render: (text,item) => (
- this.goToSubRoot(item.path)} className="ml12">
- {text}
+ dataIndex: "name",
+ width: "30%",
+ render: (text, item) => (
+ this.goToSubRoot(item.path)} className="ml12">
+
+ {text}
),
- },{
- dataIndex:"commit",
- width:"60%",
- render:(text,item)=>
- (
- item.commit && item.commit.message ? {item.commit.message} :""
- )
- },{
- dataIndex:"commit",
- width:"10%",
- className:"edu-txt-right",
- render:(text,item)=>(
- item.commit && item.commit.time_from_now ? {item.commit.time_from_now} :""
- )
- }
+ },
+ {
+ dataIndex: "commit",
+ width: "60%",
+ render: (text, item) =>
+ item.commit && item.commit.message ? (
+
+ {item.commit.message}
+
+ ) : (
+ ""
+ ),
+ },
+ {
+ dataIndex: "commit",
+ width: "10%",
+ className: "edu-txt-right",
+ render: (text, item) =>
+ item.commit && item.commit.time_from_now ? (
+
+ {item.commit.time_from_now}
+
+ ) : (
+ ""
+ ),
+ },
];
- const title = () =>{
- if(branchLastCommit){
- return(
+ const title = () => {
+ if (branchLastCommit) {
+ return (
- {
- lastCommitAuthor ?
-
- {
- lastCommitAuthor.login ?
-
-
- {lastCommitAuthor.name}
- :
+ {lastCommitAuthor ? (
+
+ {lastCommitAuthor.login ? (
+
+
{lastCommitAuthor.name}
- }
-
- :""
- }
- {branchLastCommit.message}
+
+ ) : (
+ {lastCommitAuthor.name}
+ )}
+
+ ) : (
+ ""
+ )}
+
+ {branchLastCommit.message}
+
{branchLastCommit.time_from_now}
-
{truncateCommitId(branchLastCommit.sha)}
+
+ {truncateCommitId(branchLastCommit.sha)}
+
- )
- }else{
+ );
+ } else {
return undefined;
}
- }
+ };
- const downloadUrl = ()=>(
+ const downloadUrl = () => (
- )
+ );
- const urlRoot = filePath === undefined ? '':`/${filePath}`;
+ const urlRoot = filePath === undefined ? "" : `/${filePath}`;
let array = filePath && filePath.split("/");
- return(
+ return (
- {
- subFileType && (isManager || isDeveloper) &&
-
- 新建文件
-
- }
- {
- projectDetail && projectDetail.clone_url &&
- }
+ {subFileType && (isManager || isDeveloper) && (
+
+
+
+
+
+
+
+
+ )}
+ {projectDetail && projectDetail.clone_url && (
+
+ )}
{/* 主目录列表 */}
- {
- rootList &&
-
title()}>
- }
+ {rootList && (
+
title()}
+ >
+ )}
{/* 子目录列表、文件 */}
- {
- fileDetail && fileDetail.length>0 &&
-
- }
+ {fileDetail && fileDetail.length > 0 && (
+
+ )}
{/* readme.txt (isManager || isDeveloper)*/}
- { this.renderReadMeContent(readMeContent,(isManager || isDeveloper)) }
+ {this.renderReadMeContent(readMeContent, isManager || isDeveloper)}
- )
+ );
}
}
export default CoderRootDirectory;
diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js
index 9993e1fb..feeaaacc 100644
--- a/src/forge/Main/Detail.js
+++ b/src/forge/Main/Detail.js
@@ -25,6 +25,10 @@ const FileNew = Loadable({
loader: () => import('../Newfile/Index'),
loading: Loading,
})
+const UploadFile = Loadable({
+ loader: () => import('../Newfile/upload_file'),
+ loading: Loading,
+})
const Setting = Loadable({
loader: () => import('../Settings/Index'),
loading: Loading,
@@ -356,8 +360,8 @@ class Detail extends Component {
{
- projectDetail && projectDetail.type && projectDetail.type === 2 &&
- 同步镜像
+ projectDetail && projectDetail.type && projectDetail.type === 2 ?
+ 同步镜像 : ""
}
this.focusFunc(watched)}>
@@ -443,6 +447,11 @@ class Detail extends Component {
(props) => ()
}
>
+ ()
+ }
+ >
()
diff --git a/src/forge/Main/IndexItem.js b/src/forge/Main/IndexItem.js
index c579aa75..97229c5f 100644
--- a/src/forge/Main/IndexItem.js
+++ b/src/forge/Main/IndexItem.js
@@ -33,7 +33,7 @@ class IndexItem extends Component {
: ""
}
{
- item.mirror_url && item.mirror_url.length > 0 &&
+ item.type && item.type !== 0 &&
diff --git a/src/forge/Newfile/Index.js b/src/forge/Newfile/Index.js
index 1c09015d..a3016171 100644
--- a/src/forge/Newfile/Index.js
+++ b/src/forge/Newfile/Index.js
@@ -124,8 +124,6 @@ class Index extends Component {
})}
-
-
{
+ this.setState({
+ filename: e.target.value,
+ });
+ };
+
// 提交变更
subMitFrom = () => {
const { filepath, content } = this.props;
const { branch, projectsId } = this.props.match.params;
- const { submitType } = this.state;
+ const { submitType, filename } = this.state;
let path = filepath.substr(1);
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
const url = `/repositories/${projectsId}/create_file.json`;
axios
.post(url, {
- filepath: path,
+ filepath: filename ? filename : path,
branch: branch,
new_branch: submitType === "1" ? values.branchname : undefined,
content,
@@ -88,7 +96,7 @@ class UserSubmitComponent extends Component {
};
render() {
- const { submitType } = this.state;
+ const { submitType,filename } = this.state;
const { getFieldDecorator } = this.props.form;
const { branch, projectsId } = this.props.match.params;
@@ -143,16 +151,26 @@ class UserSubmitComponent extends Component {
+
{getFieldDecorator("path", {
rules: [],
})(
+ //
+
+
)}
@@ -188,7 +206,7 @@ class UserSubmitComponent extends Component {