Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
software-articles.js 6.02 KiB
Newer Older
peter_rabbit's avatar
peter_rabbit committed
"use strict";

const { software_articles_url } = require("../../../../constants");
const ImageCarousel = require("../../../generic-components/image-carousel");
const { loadArticles, getArticleBody, getArticleDate } = require("../../../lib/article-utils");
const objectHtmlRenderer = require("../../../lib/object-html-renderer");

class SoftwareArticle {
    constructor(props) {
        this.props = props;
    }

    render() {
peter_rabbit's avatar
peter_rabbit committed
        const { title, date, status, body, subtitle, images, path, technical } = this.props;
peter_rabbit's avatar
peter_rabbit committed
        return {
            tag: "article",
            class: "software-article",
            contents: [
                {
                    tag: "h2",
                    class: "software-title",
                    contents: title,
                },
                {
                    tag: "h3",
                    class: "software-subtitle",
                    contents: subtitle,
                },
peter_rabbit's avatar
peter_rabbit committed
                {
                    tag: "div",
                    class: "software-infos",
                    contents: [
                        {
                            tag: "span",
                            class: "software-date",
                            contents: getArticleDate(date),
                        },
                        {
                            tag: "span",
                            class: "software-status",
                            contents: status,
                        },
                    ],
                },
peter_rabbit's avatar
peter_rabbit committed
                {
                    tag: "div",
                    class: "software-description",
                    contents: getArticleBody(body),
                },
                new ImageCarousel({ images: images.map(img => `${path}/images/${img}`) }).render(),
                {
                    tag: "div",
                    class: "software-technical",
                    contents: [
                        {
                            tag: "h2",
peter_rabbit's avatar
peter_rabbit committed
                            contents: "Details",
peter_rabbit's avatar
peter_rabbit committed
                        },
                        {
                            tag: "table",
                            contents: [
                                {
                                    tag: "tr",
                                    contents: [
                                        { tag: "td", contents: "Stack" },
                                        {
                                            tag: "td",
                                            contents: [
                                                {
                                                    tag: "ul",
                                                    contents: technical.stack.map(tech => {
                                                        return { tag: "li", contents: tech };
                                                    }),
                                                },
                                            ],
                                        },
                                    ],
                                },
peter_rabbit's avatar
peter_rabbit committed
                                {
                                    tag: "tr",
                                    contents: [
                                        { tag: "td", contents: "Version actuelle" },
                                        {
                                            tag: "td",
                                            contents: technical.version,
                                        },
                                    ],
                                },
peter_rabbit's avatar
peter_rabbit committed
                                {
                                    tag: "tr",
                                    contents: [
                                        { tag: "td", contents: "License" },
                                        { tag: "td", contents: technical.license },
                                    ],
                                },
                                {
                                    tag: "tr",
                                    contents: [
                                        { tag: "td", contents: "Dépôt code source" },
                                        {
                                            tag: "td",
                                            contents: [
                                                {
                                                    tag: "a",
                                                    href: technical.repository,
                                                    contents: technical.repository,
                                                },
                                            ],
                                        },
                                    ],
                                },
                            ],
                        },
                    ],
                },
            ],
        };
    }
}

class SoftwareArticles {
    constructor(props) {
        this.props = props;
        this.state = {
            articles: [],
        };
        this.id = performance.now();
        this.loadArticles();
    }

    loadArticles() {
        loadArticles(software_articles_url)
            .then(articles => {
                this.state.articles = articles;
                this.refresh();
            })
            .catch(e => console.log(e));
    }

    renderPlaceholder() {
        return {
            tag: "article",
            class: "placeholder",
            contents: [{ tag: "div" }, { tag: "div" }],
        };
    }

    refresh() {
        objectHtmlRenderer.subRender(this.render(), document.getElementById(this.id), {
            mode: "replace",
        });
    }

    render() {
        const { articles } = this.state;
        return {
            tag: "section",
            class: "software-articles page-contents-center",
            id: this.id,
            contents:
                articles.length > 0
                    ? articles.map(article => new SoftwareArticle({ ...article }).render())
                    : [this.renderPlaceholder()],
        };
    }
}

module.exports = SoftwareArticles;