2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2019-10-20 18:02:52 +02:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { File, Repository } from "@scm-manager/ui-types";
|
2020-10-14 22:48:10 +02:00
|
|
|
import {
|
|
|
|
|
DateFromNow,
|
|
|
|
|
ErrorNotification,
|
|
|
|
|
FileSize,
|
|
|
|
|
Icon,
|
|
|
|
|
OpenInFullscreenButton,
|
|
|
|
|
FullscreenModal
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { getSources } from "../modules/sources";
|
|
|
|
|
import FileButtonAddons from "../components/content/FileButtonAddons";
|
|
|
|
|
import SourcesView from "./SourcesView";
|
|
|
|
|
import HistoryView from "./HistoryView";
|
2020-06-12 17:27:32 +02:00
|
|
|
import AnnotateView from "./AnnotateView";
|
2018-10-15 16:45:54 +02:00
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
type Props = WithTranslation & {
|
2019-10-19 16:38:07 +02:00
|
|
|
loading: boolean;
|
|
|
|
|
file: File;
|
|
|
|
|
repository: Repository;
|
|
|
|
|
revision: string;
|
|
|
|
|
path: string;
|
2020-01-09 09:34:40 +01:00
|
|
|
breadcrumb: React.ReactNode;
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
2019-10-19 16:38:07 +02:00
|
|
|
collapsed: boolean;
|
2020-06-12 17:27:32 +02:00
|
|
|
selected: SourceViewSelection;
|
2019-10-19 16:38:07 +02:00
|
|
|
errorFromExtension?: Error;
|
2020-10-14 22:48:10 +02:00
|
|
|
showFullscreenModal: boolean;
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
|
2020-01-09 13:43:04 +01:00
|
|
|
const Header = styled.div`
|
|
|
|
|
border-bottom: solid 1px #dbdbdb;
|
|
|
|
|
font-size: 1.25em;
|
|
|
|
|
font-weight: 300;
|
|
|
|
|
line-height: 1.25;
|
|
|
|
|
padding: 0.5em 0.75em;
|
|
|
|
|
`;
|
|
|
|
|
|
2019-10-16 17:28:06 +02:00
|
|
|
const VCenteredChild = styled.div`
|
2019-10-09 16:17:02 +02:00
|
|
|
align-items: center;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const RightMarginIcon = styled(Icon)`
|
|
|
|
|
margin-right: 0.5em;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const RightMarginFileButtonAddons = styled(FileButtonAddons)`
|
|
|
|
|
margin-right: 0.5em;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-01-09 13:43:04 +01:00
|
|
|
const BorderBottom = styled.div`
|
|
|
|
|
border-bottom: solid 1px #dbdbdb;
|
|
|
|
|
`;
|
|
|
|
|
|
2019-10-09 16:17:02 +02:00
|
|
|
const LighterGreyBackgroundPanelBlock = styled.div`
|
|
|
|
|
background-color: #fbfbfb;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const LighterGreyBackgroundTable = styled.table`
|
|
|
|
|
background-color: #fbfbfb;
|
|
|
|
|
`;
|
2018-10-29 09:59:04 +01:00
|
|
|
|
2020-10-14 22:48:10 +02:00
|
|
|
const BorderLessDiv = styled.div`
|
|
|
|
|
margin: -1.25rem;
|
|
|
|
|
border: none;
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-06-12 17:27:32 +02:00
|
|
|
export type SourceViewSelection = "source" | "history" | "annotations";
|
|
|
|
|
|
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,
|
2020-10-14 22:48:10 +02:00
|
|
|
selected: "source",
|
|
|
|
|
showFullscreenModal: false
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 16:45:32 +01:00
|
|
|
toggleCollapse = () => {
|
|
|
|
|
this.setState(prevState => ({
|
2019-10-20 18:02:52 +02:00
|
|
|
collapsed: !prevState.collapsed
|
2018-10-29 16:45:32 +01:00
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-14 22:48:10 +02:00
|
|
|
openModal = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
showFullscreenModal: true
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
closeModal = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
showFullscreenModal: false
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-05 11:32:12 +02:00
|
|
|
handleExtensionError = (error: Error) => {
|
2019-10-19 16:38:07 +02:00
|
|
|
this.setState({
|
2019-10-20 18:02:52 +02:00
|
|
|
errorFromExtension: error
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
2019-09-05 11:32:12 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
showHeader() {
|
2019-10-30 12:59:54 +01:00
|
|
|
const { repository, file, revision } = this.props;
|
2020-06-12 17:27:32 +02:00
|
|
|
const { selected, collapsed } = this.state;
|
2019-10-20 18:02:52 +02:00
|
|
|
const icon = collapsed ? "angle-right" : "angle-down";
|
2018-10-29 09:32:30 +01:00
|
|
|
|
2018-11-28 09:28:45 +01:00
|
|
|
const selector = file._links.history ? (
|
2019-10-09 16:17:02 +02:00
|
|
|
<RightMarginFileButtonAddons
|
2020-06-12 17:27:32 +02:00
|
|
|
selected={selected}
|
|
|
|
|
showSources={() => this.setState({ selected: "source" })}
|
|
|
|
|
showHistory={() => this.setState({ selected: "history" })}
|
|
|
|
|
showAnnotations={() => this.setState({ selected: "annotations" })}
|
2018-11-28 09:28:45 +01:00
|
|
|
/>
|
|
|
|
|
) : null;
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
return (
|
2019-10-09 16:17:02 +02:00
|
|
|
<span className="has-cursor-pointer">
|
2019-10-20 18:02:52 +02:00
|
|
|
<VCenteredChild className={classNames("media", "is-flex")}>
|
2018-11-26 15:20:44 +01:00
|
|
|
<div className="media-content" onClick={this.toggleCollapse}>
|
2019-10-09 16:17:02 +02:00
|
|
|
<RightMarginIcon name={icon} color="inherit" />
|
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>
|
2019-08-28 09:37:43 +02:00
|
|
|
<div className="buttons is-grouped">
|
2019-10-09 16:17:02 +02:00
|
|
|
{selector}
|
2020-10-14 22:48:10 +02:00
|
|
|
<OpenInFullscreenButton onClick={this.openModal} />
|
2019-09-12 14:44:42 +02:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.sources.content.actionbar"
|
|
|
|
|
props={{
|
2019-10-30 12:59:54 +01:00
|
|
|
repository,
|
2019-09-12 14:44:42 +02:00
|
|
|
file,
|
|
|
|
|
revision,
|
2019-10-20 18:02:52 +02:00
|
|
|
handleExtensionError: this.handleExtensionError
|
2019-09-12 14:44:42 +02:00
|
|
|
}}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-08-28 09:37:43 +02:00
|
|
|
</div>
|
2019-10-09 16:17:02 +02:00
|
|
|
</VCenteredChild>
|
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;
|
2019-10-09 16:17:02 +02:00
|
|
|
const { file, revision, t, repository } = this.props;
|
2019-12-18 11:48:17 +01:00
|
|
|
const date = <DateFromNow date={file.commitDate} />;
|
2018-11-01 09:19:29 +01:00
|
|
|
const description = file.description ? (
|
|
|
|
|
<p>
|
2019-10-20 18:02:52 +02:00
|
|
|
{file.description.split("\n").map((item, key) => {
|
2018-11-01 09:19:29 +01:00
|
|
|
return (
|
|
|
|
|
<span key={key}>
|
|
|
|
|
{item}
|
|
|
|
|
<br />
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</p>
|
|
|
|
|
) : null;
|
2020-01-09 13:43:04 +01:00
|
|
|
const fileSize = file.directory ? "" : <FileSize bytes={file?.length ? file.length : 0} />;
|
2018-10-29 16:45:32 +01:00
|
|
|
if (!collapsed) {
|
|
|
|
|
return (
|
2020-01-09 13:43:04 +01:00
|
|
|
<>
|
|
|
|
|
<LighterGreyBackgroundPanelBlock className="panel-block">
|
|
|
|
|
<LighterGreyBackgroundTable className="table">
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.path")}</td>
|
|
|
|
|
<td className="is-word-break">{file.path}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.branch")}</td>
|
2020-01-17 08:12:37 +01:00
|
|
|
<td className="is-word-break">{decodeURIComponent(revision)}</td>
|
2020-01-09 13:43:04 +01:00
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.size")}</td>
|
|
|
|
|
<td>{fileSize}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.commitDate")}</td>
|
|
|
|
|
<td>{date}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.description")}</td>
|
|
|
|
|
<td className="is-word-break">{description}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.content.metadata"
|
|
|
|
|
renderAll={true}
|
|
|
|
|
props={{
|
|
|
|
|
file,
|
|
|
|
|
repository,
|
|
|
|
|
revision
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</tbody>
|
|
|
|
|
</LighterGreyBackgroundTable>
|
|
|
|
|
</LighterGreyBackgroundPanelBlock>
|
|
|
|
|
<BorderBottom />
|
|
|
|
|
</>
|
2018-10-29 16:45:32 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
render() {
|
2020-01-09 09:34:40 +01:00
|
|
|
const { file, revision, repository, path, breadcrumb } = this.props;
|
2020-10-14 22:48:10 +02:00
|
|
|
const { selected, errorFromExtension, showFullscreenModal } = this.state;
|
2018-10-25 14:03:45 +02:00
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
const header = this.showHeader();
|
2020-06-12 17:27:32 +02:00
|
|
|
let content;
|
|
|
|
|
switch (selected) {
|
|
|
|
|
case "source":
|
2020-10-14 22:48:10 +02:00
|
|
|
content = <SourcesView revision={revision} file={file} repository={repository} path={path} />;
|
2020-06-12 17:27:32 +02:00
|
|
|
break;
|
|
|
|
|
case "history":
|
2020-10-14 22:48:10 +02:00
|
|
|
content = <HistoryView file={file} repository={repository} />;
|
2020-06-12 17:27:32 +02:00
|
|
|
break;
|
|
|
|
|
case "annotations":
|
2020-10-14 22:48:10 +02:00
|
|
|
content = <AnnotateView file={file} repository={repository} />;
|
2020-06-12 17:27:32 +02:00
|
|
|
}
|
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">
|
2020-01-09 09:34:40 +01:00
|
|
|
{breadcrumb}
|
2020-01-09 13:43:04 +01:00
|
|
|
<Header>{header}</Header>
|
|
|
|
|
{moreInformation}
|
2019-01-29 17:12:18 +01:00
|
|
|
{content}
|
2020-10-14 22:48:10 +02:00
|
|
|
<FullscreenModal
|
|
|
|
|
title={file?.name}
|
|
|
|
|
closeFunction={() => this.closeModal()}
|
|
|
|
|
body={<BorderLessDiv className="panel">{content}</BorderLessDiv>}
|
|
|
|
|
active={showFullscreenModal}
|
|
|
|
|
/>
|
2019-02-01 17:03:00 +01:00
|
|
|
</div>
|
2019-09-05 11:32:12 +02:00
|
|
|
{errorFromExtension && <ErrorNotification error={errorFromExtension} />}
|
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 {
|
2019-10-20 18:02:52 +02:00
|
|
|
file
|
2018-10-25 13:45:52 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
export default connect(mapStateToProps)(withTranslation("repos")(Content));
|