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.
|
|
|
|
|
*/
|
2021-06-02 15:27:41 +02:00
|
|
|
import React, { FC, ReactNode, useState } from "react";
|
|
|
|
|
import { useTranslation } 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-20 10:18:44 +02:00
|
|
|
import { DateFromNow, ErrorNotification, FileSize, Icon, OpenInFullscreenButton } from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
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
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
file: File;
|
|
|
|
|
repository: Repository;
|
|
|
|
|
revision: string;
|
2020-01-09 09:34:40 +01:00
|
|
|
breadcrumb: React.ReactNode;
|
2021-06-02 15:27:41 +02:00
|
|
|
error?: Error;
|
2018-10-15 16:45:54 +02:00
|
|
|
};
|
|
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
const HeaderWrapper = styled.div`
|
2020-01-09 13:43:04 +01:00
|
|
|
border-bottom: solid 1px #dbdbdb;
|
|
|
|
|
font-size: 1.25em;
|
|
|
|
|
font-weight: 300;
|
|
|
|
|
line-height: 1.25;
|
|
|
|
|
padding: 0.5em 0.75em;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const BorderBottom = styled.div`
|
|
|
|
|
border-bottom: solid 1px #dbdbdb;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-03-04 09:54:08 +01:00
|
|
|
const FullWidthTitleHeader = styled.div`
|
|
|
|
|
max-width: 100%;
|
2019-10-09 16:17:02 +02:00
|
|
|
`;
|
|
|
|
|
|
2020-10-14 22:48:10 +02:00
|
|
|
const BorderLessDiv = styled.div`
|
|
|
|
|
margin: -1.25rem;
|
|
|
|
|
border: none;
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
export type SourceViewSelection = "source" | "annotations" | "history";
|
2020-06-12 17:27:32 +02:00
|
|
|
|
2021-06-23 14:14:56 +02:00
|
|
|
const Content: FC<Props> = ({ file, repository, revision, breadcrumb, error }) => {
|
2021-06-02 15:27:41 +02:00
|
|
|
const [t] = useTranslation("repos");
|
|
|
|
|
const [collapsed, setCollapsed] = useState(true);
|
|
|
|
|
const [selected, setSelected] = useState<SourceViewSelection>("source");
|
|
|
|
|
const [errorFromExtension, setErrorFromExtension] = useState<Error>();
|
2018-10-15 16:45:54 +02:00
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
const wrapContent = (content: ReactNode) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="panel">
|
|
|
|
|
{breadcrumb}
|
|
|
|
|
{content}
|
|
|
|
|
</div>
|
|
|
|
|
<ErrorNotification error={errorFromExtension} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2018-10-29 16:45:32 +01:00
|
|
|
};
|
|
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
const toggleCollapse = () => {
|
|
|
|
|
setCollapsed(!collapsed);
|
2019-09-05 11:32:12 +02:00
|
|
|
};
|
|
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
const showHeader = (content: ReactNode) => {
|
2021-11-03 10:11:40 +01:00
|
|
|
let icon;
|
|
|
|
|
if (collapsed) {
|
|
|
|
|
icon = (
|
|
|
|
|
<Icon
|
|
|
|
|
className={classNames("is-inline", "mr-2")}
|
|
|
|
|
name="angle-right fa-fw"
|
|
|
|
|
color="inherit"
|
|
|
|
|
alt={t("sources.content.showMore")}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
icon = (
|
|
|
|
|
<Icon
|
|
|
|
|
className={classNames("is-inline", "mr-2")}
|
|
|
|
|
name="angle-down fa-fw"
|
|
|
|
|
color="inherit"
|
|
|
|
|
alt={t("sources.content.hideMore")}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-10-29 09:32:30 +01:00
|
|
|
|
2018-11-28 09:28:45 +01:00
|
|
|
const selector = file._links.history ? (
|
2021-03-04 09:54:08 +01:00
|
|
|
<FileButtonAddons
|
|
|
|
|
className="mr-2"
|
2020-06-12 17:27:32 +02:00
|
|
|
selected={selected}
|
2021-06-02 15:27:41 +02:00
|
|
|
showSources={() => setSelected("source")}
|
|
|
|
|
showAnnotations={() => setSelected("annotations")}
|
|
|
|
|
showHistory={() => setSelected("history")}
|
2018-11-28 09:28:45 +01:00
|
|
|
/>
|
|
|
|
|
) : null;
|
|
|
|
|
|
2018-10-29 09:32:30 +01:00
|
|
|
return (
|
2021-06-02 15:27:41 +02:00
|
|
|
<HeaderWrapper>
|
|
|
|
|
<div className={classNames("level", "is-flex-wrap-wrap")}>
|
|
|
|
|
<FullWidthTitleHeader
|
2021-09-15 17:40:08 +02:00
|
|
|
className={classNames("level-left", "is-flex", "is-clickable", "is-word-break", "mr-2")}
|
2021-06-02 15:27:41 +02:00
|
|
|
onClick={toggleCollapse}
|
|
|
|
|
>
|
2021-11-03 10:11:40 +01:00
|
|
|
{icon}
|
2021-06-02 15:27:41 +02:00
|
|
|
{file.name}
|
|
|
|
|
</FullWidthTitleHeader>
|
2021-09-15 17:40:08 +02:00
|
|
|
<div className={classNames("level-right", "buttons", "ml-auto")}>
|
2021-06-02 15:27:41 +02:00
|
|
|
{selector}
|
|
|
|
|
<OpenInFullscreenButton
|
|
|
|
|
modalTitle={file?.name}
|
|
|
|
|
modalBody={<BorderLessDiv className="panel">{content}</BorderLessDiv>}
|
|
|
|
|
tooltipStyle="htmlTitle"
|
|
|
|
|
/>
|
|
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.sources.content.actionbar"
|
|
|
|
|
props={{
|
|
|
|
|
repository,
|
|
|
|
|
file,
|
|
|
|
|
revision: revision ? encodeURIComponent(revision) : "",
|
2021-12-09 09:12:02 +01:00
|
|
|
handleExtensionError: setErrorFromExtension
|
2021-06-02 15:27:41 +02:00
|
|
|
}}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2021-09-15 17:40:08 +02:00
|
|
|
</div>
|
2021-06-02 15:27:41 +02:00
|
|
|
</div>
|
|
|
|
|
</HeaderWrapper>
|
2018-10-29 09:32:30 +01:00
|
|
|
);
|
2021-06-02 15:27:41 +02:00
|
|
|
};
|
2018-10-29 09:32:30 +01:00
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
const showMoreInformation = () => {
|
|
|
|
|
const fileSize = file.directory ? null : <FileSize bytes={file?.length ? file.length : 0} />;
|
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;
|
2021-06-02 15:27:41 +02:00
|
|
|
|
2018-10-29 16:45:32 +01:00
|
|
|
if (!collapsed) {
|
|
|
|
|
return (
|
2020-01-09 13:43:04 +01:00
|
|
|
<>
|
2021-09-15 17:40:08 +02:00
|
|
|
<div className="panel-block has-background-white-bis">
|
|
|
|
|
<table className="table has-background-white-bis">
|
2020-01-09 13:43:04 +01:00
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.path")}</td>
|
|
|
|
|
<td className="is-word-break">{file.path}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>{t("sources.content.branch")}</td>
|
2021-02-24 08:17:40 +01:00
|
|
|
<td className="is-word-break">{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>
|
2021-06-02 15:27:41 +02:00
|
|
|
<td>
|
|
|
|
|
<DateFromNow date={file.commitDate} />
|
|
|
|
|
</td>
|
2020-01-09 13:43:04 +01:00
|
|
|
</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,
|
2021-12-09 09:12:02 +01:00
|
|
|
revision
|
2020-01-09 13:43:04 +01:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</tbody>
|
2021-09-15 17:40:08 +02:00
|
|
|
</table>
|
|
|
|
|
</div>
|
2020-01-09 13:43:04 +01:00
|
|
|
<BorderBottom />
|
|
|
|
|
</>
|
2018-10-29 16:45:32 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2021-06-02 15:27:41 +02:00
|
|
|
};
|
2018-10-29 16:45:32 +01:00
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
if (!file || error) {
|
|
|
|
|
return wrapContent(<ErrorNotification error={error} />);
|
|
|
|
|
}
|
2018-10-25 13:59:13 +02:00
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
let body;
|
|
|
|
|
switch (selected) {
|
|
|
|
|
case "source":
|
2021-06-23 14:14:56 +02:00
|
|
|
body = <SourcesView file={file} repository={repository} revision={revision} />;
|
2021-06-02 15:27:41 +02:00
|
|
|
break;
|
|
|
|
|
case "annotations":
|
2021-06-23 14:14:56 +02:00
|
|
|
body = <AnnotateView file={file} repository={repository} revision={revision} />;
|
2021-06-02 15:27:41 +02:00
|
|
|
break;
|
|
|
|
|
case "history":
|
2021-06-23 14:14:56 +02:00
|
|
|
body = <HistoryView file={file} repository={repository} revision={revision} />;
|
2018-10-15 16:45:54 +02:00
|
|
|
}
|
2021-06-02 15:27:41 +02:00
|
|
|
const header = showHeader(body);
|
|
|
|
|
const moreInformation = showMoreInformation();
|
|
|
|
|
|
|
|
|
|
return wrapContent(
|
|
|
|
|
<>
|
|
|
|
|
{header}
|
|
|
|
|
{moreInformation}
|
|
|
|
|
{body}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
2018-10-15 16:45:54 +02:00
|
|
|
|
2021-06-02 15:27:41 +02:00
|
|
|
export default Content;
|