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 { Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import { CardColumn, DateFromNow } from "@scm-manager/ui-components";
|
|
|
|
|
import RepositoryEntryLink from "./RepositoryEntryLink";
|
|
|
|
|
import RepositoryAvatar from "./RepositoryAvatar";
|
2020-03-14 20:50:25 +01:00
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
2018-12-20 09:48:01 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
repository: Repository;
|
2018-12-20 09:48:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RepositoryEntry extends React.Component<Props> {
|
|
|
|
|
createLink = (repository: Repository) => {
|
|
|
|
|
return `/repo/${repository.namespace}/${repository.name}`;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-28 13:40:38 +01:00
|
|
|
renderBranchesLink = (repository: Repository, repositoryLink: string) => {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (repository._links["branches"]) {
|
2019-10-21 10:57:56 +02:00
|
|
|
return <RepositoryEntryLink icon="code-branch" to={repositoryLink + "/branches"} />;
|
2019-03-28 13:40:38 +01:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-20 09:48:01 +01:00
|
|
|
renderChangesetsLink = (repository: Repository, repositoryLink: string) => {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (repository._links["changesets"]) {
|
2020-01-10 09:19:09 +01:00
|
|
|
return <RepositoryEntryLink icon="exchange-alt" to={repositoryLink + "/code/changesets/"} />;
|
2018-12-20 09:48:01 +01:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderSourcesLink = (repository: Repository, repositoryLink: string) => {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (repository._links["sources"]) {
|
2020-01-10 09:19:09 +01:00
|
|
|
return <RepositoryEntryLink icon="code" to={repositoryLink + "/code/sources/"} />;
|
2018-12-20 09:48:01 +01:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderModifyLink = (repository: Repository, repositoryLink: string) => {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (repository._links["update"]) {
|
2019-10-21 10:57:56 +02:00
|
|
|
return <RepositoryEntryLink icon="cog" to={repositoryLink + "/settings/general"} />;
|
2018-12-20 09:48:01 +01:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-09 13:29:25 +02:00
|
|
|
createFooterLeft = (repository: Repository, repositoryLink: string) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{this.renderBranchesLink(repository, repositoryLink)}
|
|
|
|
|
{this.renderChangesetsLink(repository, repositoryLink)}
|
|
|
|
|
{this.renderSourcesLink(repository, repositoryLink)}
|
2020-03-14 20:50:25 +01:00
|
|
|
<ExtensionPoint name={"repository.card.quickLink"} props={{ repository, repositoryLink }} renderAll={true} />
|
2019-07-09 13:29:25 +02:00
|
|
|
{this.renderModifyLink(repository, repositoryLink)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
createFooterRight = (repository: Repository) => {
|
|
|
|
|
return (
|
|
|
|
|
<small className="level-item">
|
|
|
|
|
<DateFromNow date={repository.creationDate} />
|
|
|
|
|
</small>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-19 13:12:03 +01:00
|
|
|
createTitle = () => {
|
|
|
|
|
const { repository } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2020-03-24 08:46:58 +01:00
|
|
|
<ExtensionPoint name="repository.card.beforeTitle" props={{ repository }} /> <strong>{repository.name}</strong>
|
2020-03-19 13:12:03 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-20 09:48:01 +01:00
|
|
|
render() {
|
2019-07-09 13:29:25 +02:00
|
|
|
const { repository } = this.props;
|
2018-12-20 09:48:01 +01:00
|
|
|
const repositoryLink = this.createLink(repository);
|
2019-07-09 13:29:25 +02:00
|
|
|
const footerLeft = this.createFooterLeft(repository, repositoryLink);
|
|
|
|
|
const footerRight = this.createFooterRight(repository);
|
2020-03-19 13:12:03 +01:00
|
|
|
const title = this.createTitle();
|
2018-12-20 09:48:01 +01:00
|
|
|
return (
|
2019-07-09 13:29:25 +02:00
|
|
|
<CardColumn
|
|
|
|
|
avatar={<RepositoryAvatar repository={repository} />}
|
2020-03-19 13:12:03 +01:00
|
|
|
title={title}
|
2019-07-09 13:29:25 +02:00
|
|
|
description={repository.description}
|
|
|
|
|
link={repositoryLink}
|
|
|
|
|
footerLeft={footerLeft}
|
|
|
|
|
footerRight={footerRight}
|
|
|
|
|
/>
|
2018-12-20 09:48:01 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 13:29:25 +02:00
|
|
|
export default RepositoryEntry;
|