UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

44 lines (43 loc) 2.2 kB
import path from "path"; import { AbstractDataService } from "@rr0/data"; import { TimeContext } from "../../../../../time/TimeContext.mjs"; export class CaseService extends AbstractDataService { constructor(dataService, factory, timeElementFactory, files) { super(dataService, factory, files); this.timeElementFactory = timeElementFactory; } getLink(context, aCase) { var _a, _b, _c, _d, _e, _f; const details = []; const classList = ["data-resolved"]; const classification = aCase.classification; const hynek = classification === null || classification === void 0 ? void 0 : classification.hynek; if (hynek) { const classificationLabels = context.messages.case.classification.hynek[hynek]; details.push(classificationLabels.short); } const time = aCase.time; const caseContext = context.clone(); if (time) { caseContext.time = new TimeContext((_a = time.year) === null || _a === void 0 ? void 0 : _a.value, (_b = time.month) === null || _b === void 0 ? void 0 : _b.value, (_c = time.day) === null || _c === void 0 ? void 0 : _c.value, (_d = time.hour) === null || _d === void 0 ? void 0 : _d.value, (_e = time.minute) === null || _e === void 0 ? void 0 : _e.value, (_f = time.timeshift) === null || _f === void 0 ? void 0 : _f.toString()); const options = { year: "numeric" }; const { result, replacement } = this.timeElementFactory.renderer.renderContent(caseContext, undefined, { url: false, contentOnly: false }, options); result.append(replacement); details.push(result.outerHTML); } const text = [aCase.title]; if (details.length > 0) { text.push(`(${details.join(", ")})`); } const doc = context.file.document; const link = doc.createElement("a"); link.innerHTML = text.join(" "); link.href = path.join("/", aCase.dirName); const span = doc.createElement("span"); if (classList.length > 0) { span.classList.add(...classList); } span.append(link); return span; } }