2018-10-15 16:45:54 +02:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
2018-10-29 11:50:55 +01:00
|
|
|
import { translate } from "react-i18next";
|
2018-11-21 16:55:13 +01:00
|
|
|
import type { File, Repository } from "@scm-manager/ui-types";
|
2018-11-26 15:20:44 +01:00
|
|
|
import { DateFromNow } from "@scm-manager/ui-components";
|
2018-10-29 09:32:30 +01:00
|
|
|
import FileSize from "../components/FileSize";
|
2018-10-29 09:59:04 +01:00
|
|
|
import injectSheet from "react-jss";
|
2018-10-29 09:32:30 +01:00
|
|
|
import classNames from "classnames";
|
2019-01-29 14:02:36 +01:00
|
|
|
import FileButtonGroup from "../components/content/FileButtonGroup";
|
2018-11-26 15:20:44 +01:00
|
|
|
import SourcesView from "./SourcesView";
|
|
|
|
|
import HistoryView from "./HistoryView";
|
|
|
|
|
import { getSources } from "../modules/sources";
|
|
|
|
|
import { connect } from "react-redux";
|
2019-02-21 17:08:23 +01:00
|
|
|
import {ExtensionPoint} from "@scm-manager/ui-extensions";
|
2018-10-15 16:45:54 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-10-25 13:45:52 +02:00
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
|
|
|
|
file: File,
|
|
|
|
|
repository: Repository,
|
|
|
|
|
revision: string,
|
|
|
|
|
path: string,
|
|
|
|
|
classes: any,
|
2018-11-01 10:23:08 +01:00
|
|
|
t: string => string
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
2018-11-01 10:33:35 +01:00
|
|
|
collapsed: boolean,
|
2018-11-26 15:20:44 +01:00
|
|
|
showHistory: boolean
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-29 09:59:04 +01:00
|
|
|
const styles = {
|
2018-10-29 16:45:32 +01:00
|
|
|
pointer: {
|
|
|
|
|
cursor: "pointer"
|
2018-11-26 15:20:44 +01:00
|
|
|
},
|
|
|
|
|
marginInHeader: {
|
|
|
|
|
marginRight: "0.5em"
|
2018-11-28 10:33:06 +01:00
|
|
|
},
|
|
|
|
|
isVerticalCenter: {
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center"
|
2018-12-19 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
hasBackground: {
|
|
|
|
|
backgroundColor: "#FBFBFB"
|
2018-10-29 09:59:04 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-15 16:45:54 +02:00
|
|
|
class Content extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2018-11-26 15:20:44 +01:00
|
|
|
collapsed: true,
|
|
|
|
|
showHistory: false
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 16:45:32 +01:00
|
|
|
toggleCollapse = () => {
|
|
|
|
|
this.setState(prevState => ({
|
|
|
|
|
collapsed: !prevState.collapsed
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-26 15:20:44 +01:00
|
|
|
setShowHistoryState(showHistory: boolean) {
|
|
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
|
|
|
|
showHistory
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
showHeader() {
|
2018-11-26 15:56:41 +01:00
|
|
|
const { file, classes } = this.props;
|
2018-11-26 15:20:44 +01:00
|
|
|
const { showHistory, collapsed } = this.state;
|
2018-10-29 16:45:32 +01:00
|
|
|
const icon = collapsed ? "fa-angle-right" : "fa-angle-down";
|
2018-10-29 09:32:30 +01:00
|
|
|
|
2018-11-28 09:28:45 +01:00
|
|
|
const selector = file._links.history ? (
|
2019-01-29 14:02:36 +01:00
|
|
|
<FileButtonGroup
|
2018-11-28 09:28:45 +01:00
|
|
|
file={file}
|
|
|
|
|
historyIsSelected={showHistory}
|
|
|
|
|
showHistory={(changeShowHistory: boolean) =>
|
|
|
|
|
this.setShowHistoryState(changeShowHistory)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
) : null;
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
return (
|
2018-11-26 15:20:44 +01:00
|
|
|
<span className={classes.pointer}>
|
2018-11-28 10:33:06 +01:00
|
|
|
<article className={classNames("media", classes.isVerticalCenter)}>
|
2018-11-26 15:20:44 +01:00
|
|
|
<div className="media-content" onClick={this.toggleCollapse}>
|
|
|
|
|
<i
|
|
|
|
|
className={classNames(
|
|
|
|
|
"fa is-medium",
|
|
|
|
|
icon,
|
|
|
|
|
classes.marginInHeader
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2018-12-19 11:07:39 +01:00
|
|
|
<span className="is-word-break">{file.name}</span>
|
2018-10-29 16:45:32 +01:00
|
|
|
</div>
|
2018-11-28 09:28:45 +01:00
|
|
|
<div className="media-right">{selector}</div>
|
2018-10-29 09:32:30 +01:00
|
|
|
</article>
|
2018-10-29 16:45:32 +01:00
|
|
|
</span>
|
2018-10-29 09:32:30 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 16:45:32 +01:00
|
|
|
showMoreInformation() {
|
|
|
|
|
const collapsed = this.state.collapsed;
|
2018-11-21 16:55:13 +01:00
|
|
|
const { classes, file, revision, t } = this.props;
|
2018-11-01 09:19:29 +01:00
|
|
|
const date = <DateFromNow date={file.lastModified} />;
|
|
|
|
|
const description = file.description ? (
|
|
|
|
|
<p>
|
|
|
|
|
{file.description.split("\n").map((item, key) => {
|
|
|
|
|
return (
|
|
|
|
|
<span key={key}>
|
|
|
|
|
{item}
|
|
|
|
|
<br />
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</p>
|
|
|
|
|
) : null;
|
2018-11-21 16:55:13 +01:00
|
|
|
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
|
2018-10-29 16:45:32 +01:00
|
|
|
if (!collapsed) {
|
|
|
|
|
return (
|
2018-12-19 17:00:21 +01:00
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
"panel-block",
|
|
|
|
|
classes.hasBackground
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<table className={classNames("table", classes.hasBackground)}>
|
2018-11-01 09:19:29 +01:00
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
2018-11-21 16:55:13 +01:00
|
|
|
<td>{t("sources.content.path")}</td>
|
2018-12-19 11:07:39 +01:00
|
|
|
<td className="is-word-break">{file.path}</td>
|
2018-11-01 09:19:29 +01:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2018-11-21 16:55:13 +01:00
|
|
|
<td>{t("sources.content.branch")}</td>
|
2018-12-19 11:07:39 +01:00
|
|
|
<td className="is-word-break">{revision}</td>
|
2018-11-01 09:19:29 +01:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2018-11-21 16:55:13 +01:00
|
|
|
<td>{t("sources.content.size")}</td>
|
|
|
|
|
<td>{fileSize}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.lastModified")}</td>
|
2018-11-01 10:58:47 +01:00
|
|
|
<td>{date}</td>
|
2018-11-01 09:19:29 +01:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2018-11-21 16:55:13 +01:00
|
|
|
<td>{t("sources.content.description")}</td>
|
2018-12-19 11:07:39 +01:00
|
|
|
<td className="is-word-break">{description}</td>
|
2018-11-01 09:19:29 +01:00
|
|
|
</tr>
|
2019-02-21 17:08:23 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.content.metadata"
|
|
|
|
|
props={{ file }}
|
|
|
|
|
>
|
|
|
|
|
</ExtensionPoint>
|
2018-11-01 09:19:29 +01:00
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2018-10-29 16:45:32 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
render() {
|
2019-01-29 17:12:18 +01:00
|
|
|
const { file, revision, repository, path } = this.props;
|
2018-11-26 15:56:41 +01:00
|
|
|
const { showHistory } = this.state;
|
2018-10-25 14:03:45 +02:00
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
const header = this.showHeader();
|
2018-11-28 09:28:45 +01:00
|
|
|
const content =
|
|
|
|
|
showHistory && file._links.history ? (
|
|
|
|
|
<HistoryView file={file} repository={repository} />
|
|
|
|
|
) : (
|
|
|
|
|
<SourcesView
|
|
|
|
|
revision={revision}
|
|
|
|
|
file={file}
|
|
|
|
|
repository={repository}
|
|
|
|
|
path={path}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-10-29 16:45:32 +01:00
|
|
|
const moreInformation = this.showMoreInformation();
|
2018-10-25 13:59:13 +02:00
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
return (
|
|
|
|
|
<div>
|
2019-02-01 17:03:00 +01:00
|
|
|
<div className="panel">
|
|
|
|
|
<div className="panel-heading">{header}</div>
|
2018-10-29 16:45:32 +01:00
|
|
|
{moreInformation}
|
2019-01-29 17:12:18 +01:00
|
|
|
{content}
|
2019-02-01 17:03:00 +01:00
|
|
|
</div>
|
2018-10-29 09:32:30 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
2018-10-15 16:45:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 13:45:52 +02:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
|
|
|
|
const { repository, revision, path } = ownProps;
|
|
|
|
|
|
|
|
|
|
const file = getSources(state, repository, revision, path);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
file
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-29 09:59:04 +01:00
|
|
|
export default injectSheet(styles)(
|
|
|
|
|
connect(mapStateToProps)(translate("repos")(Content))
|
|
|
|
|
);
|