2018-12-20 09:48:01 +01:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
import injectSheet from "react-jss";
|
|
|
|
|
import type { Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import { DateFromNow } from "@scm-manager/ui-components";
|
|
|
|
|
import RepositoryEntryLink from "./RepositoryEntryLink";
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
import RepositoryAvatar from "./RepositoryAvatar";
|
|
|
|
|
|
|
|
|
|
const styles = {
|
|
|
|
|
overlay: {
|
|
|
|
|
position: "absolute",
|
|
|
|
|
height: "calc(120px - 1.5rem)",
|
|
|
|
|
width: "calc(50% - 3rem)"
|
|
|
|
|
},
|
|
|
|
|
inner: {
|
|
|
|
|
position: "relative",
|
|
|
|
|
pointerEvents: "none",
|
|
|
|
|
zIndex: 1
|
|
|
|
|
},
|
|
|
|
|
innerLink: {
|
|
|
|
|
pointerEvents: "all"
|
2018-12-20 10:11:23 +01:00
|
|
|
},
|
|
|
|
|
centerImage: {
|
|
|
|
|
marginTop: "0.8em",
|
|
|
|
|
marginLeft: "1em !important"
|
2018-12-20 09:48:01 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
2018-12-20 11:31:32 +01:00
|
|
|
fullColumnWidth?: boolean,
|
2018-12-20 09:48:01 +01:00
|
|
|
// context props
|
|
|
|
|
classes: any
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RepositoryEntry extends React.Component<Props> {
|
|
|
|
|
createLink = (repository: Repository) => {
|
|
|
|
|
return `/repo/${repository.namespace}/${repository.name}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderChangesetsLink = (repository: Repository, repositoryLink: string) => {
|
|
|
|
|
if (repository._links["changesets"]) {
|
|
|
|
|
return (
|
|
|
|
|
<RepositoryEntryLink
|
|
|
|
|
iconClass="fa-code-branch fa-lg"
|
|
|
|
|
to={repositoryLink + "/changesets"}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderSourcesLink = (repository: Repository, repositoryLink: string) => {
|
|
|
|
|
if (repository._links["sources"]) {
|
|
|
|
|
return (
|
|
|
|
|
<RepositoryEntryLink
|
|
|
|
|
iconClass="fa-code fa-lg"
|
|
|
|
|
to={repositoryLink + "/sources"}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderModifyLink = (repository: Repository, repositoryLink: string) => {
|
|
|
|
|
if (repository._links["update"]) {
|
|
|
|
|
return (
|
|
|
|
|
<RepositoryEntryLink
|
|
|
|
|
iconClass="fa-cog fa-lg"
|
|
|
|
|
to={repositoryLink + "/edit"}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-12-20 11:31:32 +01:00
|
|
|
const { repository, classes, fullColumnWidth } = this.props;
|
2018-12-20 09:48:01 +01:00
|
|
|
const repositoryLink = this.createLink(repository);
|
2018-12-20 11:31:32 +01:00
|
|
|
const halfColumn = fullColumnWidth ? "is-full" : "is-half";
|
2018-12-20 09:48:01 +01:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
"box",
|
|
|
|
|
"box-link-shadow",
|
2018-12-20 11:12:04 +01:00
|
|
|
"column",
|
|
|
|
|
"is-clipped",
|
|
|
|
|
halfColumn
|
2018-12-20 09:48:01 +01:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Link className={classNames(classes.overlay)} to={repositoryLink} />
|
|
|
|
|
<article className={classNames("media", classes.inner)}>
|
2018-12-20 10:11:23 +01:00
|
|
|
<figure className={classNames(classes.centerImage, "media-left")}>
|
2018-12-20 09:48:01 +01:00
|
|
|
<RepositoryAvatar repository={repository} />
|
|
|
|
|
</figure>
|
2018-12-20 16:27:41 +01:00
|
|
|
<div className={classNames("media-content", "text-box")}>
|
2018-12-20 09:48:01 +01:00
|
|
|
<div className="content">
|
2018-12-20 10:30:46 +01:00
|
|
|
<p className="is-marginless">
|
2018-12-20 09:48:01 +01:00
|
|
|
<strong>{repository.name}</strong>
|
|
|
|
|
</p>
|
|
|
|
|
<p className={"shorten-text"}>{repository.description}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<nav className="level is-mobile">
|
|
|
|
|
<div className="level-left">
|
|
|
|
|
{this.renderChangesetsLink(repository, repositoryLink)}
|
|
|
|
|
{this.renderSourcesLink(repository, repositoryLink)}
|
|
|
|
|
{this.renderModifyLink(repository, repositoryLink)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="level-right is-hidden-mobile">
|
|
|
|
|
<small className="level-item">
|
|
|
|
|
<DateFromNow date={repository.creationDate} />
|
|
|
|
|
</small>
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default injectSheet(styles)(RepositoryEntry);
|