Verified Commit 4582218c authored by Jakob Moser's avatar Jakob Moser
Browse files

Get protocol date via (local) API method

parent fa4938cd
Loading
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import { Base } from "./Base.mjs"
import { Agenda } from "../pieces/Agenda.mjs"
import { getKey } from "../../account.mjs"
import { ButtonAndTextLink } from "../pieces/ButtonAndTextLink.mjs"
import { getLatestProtocolDate } from "../../gitlab.mjs"

const items = {
    all: null,
@@ -28,17 +29,17 @@ const items = {
    },
}

let protocolDate = null

export const Fachschaftssitzung = {
    oncreate() {
        document.title = "Fachschaftssitzung · FS Coli Portal"
    },
    oninit() {
    async oninit() {
        items.fetch()
        protocolDate = await getLatestProtocolDate()
    },
    view() {
        const now = new Date()
        const today = now.toISOString().split("T")[0]

        return m(Base, [
            m(Agenda, {
                items: items.all?.map(item => item.name),
@@ -48,7 +49,9 @@ export const Fachschaftssitzung = {
                m(
                    "p",
                    m(ButtonAndTextLink, {
                        href: `https://gitlab.cl.uni-heidelberg.de/-/ide/project/fachschaft/protokolle/edit/master/-/${today.slice(0, 4)}/${today}.md`,
                        href:
                            protocolDate &&
                            `https://gitlab.cl.uni-heidelberg.de/-/ide/project/fachschaft/protokolle/edit/master/-/${protocolDate.slice(0, 4)}/${protocolDate}.md`,
                        icon: "fa-solid fa-file-pen",
                        name: "Aktuelles Protokoll bearbeiten",
                    }),
@@ -56,7 +59,9 @@ export const Fachschaftssitzung = {
                m(
                    "p",
                    m(ButtonAndTextLink, {
                        href: `https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pdfs/${today}.pdf?job=convert-to-pdf`,
                        href:
                            protocolDate &&
                            `https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pdfs/${protocolDate}.pdf?job=convert-to-pdf`,
                        icon: "fa-regular fa-file-pdf",
                        name: "Protokoll als PDF herunterladen",
                    }),
@@ -64,7 +69,9 @@ export const Fachschaftssitzung = {
                m(
                    "p",
                    m(ButtonAndTextLink, {
                        href: `https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pdfs/${today}_nur_Beschlüsse.pdf?job=convert-to-pdf`,
                        href:
                            protocolDate &&
                            `https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pdfs/${protocolDate}_nur_Beschlüsse.pdf?job=convert-to-pdf`,
                        icon: "fa-solid fa-gavel",
                        name: "Beschlüsse als PDF herunterladen",
                    }),
+13 −2
Original line number Diff line number Diff line
@@ -60,7 +60,18 @@ export async function isLoggedIn() {}
 * @returns if the browser session has access to the protocols repo on GitLab
 */
export async function canAccessProtocols() {
    return await canAccess("https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pixel.png?job=create-test-pixel")
    return await canAccess(
        "https://gitlab.cl.uni-heidelberg.de/api/v4/projects/1193/jobs/artifacts/master/raw/pixel.png?job=create-test-pixel",
    )
}

export async function getLatestProtocolFileName() {}
/**
 * @returns the date of the latest protocol, e.g. "2024-06-19"
 */
export async function getLatestProtocolDate() {
    // TODO Actually fetch the information from GitLab somehow
    const now = new Date()
    const today = now.toISOString().split("T")[0]

    return today
}