| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // =============================================================
- // INFRASTRUCTURE: ПУБЛИЧНЫЙ СПРАВОЧНИК СОТРУДНИКОВ И ПОДПИСЕЙ
- // =============================================================
- // ФИО, обычная должность и имя файла не являются приватными.
- // Наличие подписи и её индивидуальное смещение задаются только в
- // игнорируемом Git файле /.private/settings.typ.
- #import "../domain/document.typ": fail
- #let employee-directory = (
- tkachenko: (
- name: "Ткаченко А.С.",
- default-role: "Автор",
- signature-file: "Tkachenko.png",
- ),
- )
- #let empty-private-settings = (
- companies: (:),
- signatures: (:),
- )
- #let validate-private-settings(settings) = {
- if type(settings) != dictionary {
- fail("private-settings", "ожидался словарь из .private/settings.typ")
- }
- for field in ("companies", "signatures") {
- if type(settings.at(field, default: (:))) != dictionary {
- fail("private-settings." + field, "ожидался словарь")
- }
- }
- settings
- }
- #let private-company-media(settings, company-id) = {
- let settings = validate-private-settings(settings)
- let company = settings.companies.at(company-id, default: none)
- if company == none {
- (signature: none, stamp: none)
- } else {
- if type(company) != dictionary {
- fail("private-settings.companies." + company-id, "ожидался словарь")
- }
- let has-signature = company.at("signature", default: false)
- let has-stamp = company.at("stamp", default: false)
- if type(has-signature) != bool or type(has-stamp) != bool {
- fail(
- "private-settings.companies." + company-id,
- "поля signature и stamp должны быть true или false",
- )
- }
- (
- signature: if has-signature {
- path("/.private/" + company-id + "/sign.png")
- } else {
- none
- },
- stamp: if has-stamp {
- path("/.private/" + company-id + "/stamp.png")
- } else {
- none
- },
- )
- }
- }
- #let report-executor(employee-id, role: auto, private-settings: empty-private-settings) = {
- if type(employee-id) != str or not employee-directory.keys().contains(employee-id) {
- fail(
- "report-executor.employee-id",
- "неизвестный сотрудник " + repr(employee-id) + "; доступны "
- + employee-directory.keys().join(", "),
- )
- }
- let person = employee-directory.at(employee-id)
- let resolved-role = if role == auto { person.default-role } else { role }
- if type(resolved-role) != str or resolved-role.trim() == "" {
- fail("report-executor.role", "должность должна быть непустой строкой")
- }
- let settings = validate-private-settings(private-settings)
- let signature = settings.signatures.at(employee-id, default: none)
- let signature-image = none
- let signature-offset = 0cm
- if signature != none {
- if type(signature) != dictionary {
- fail("private-settings.signatures." + employee-id, "ожидался словарь")
- }
- let enabled = signature.at("enabled", default: true)
- if type(enabled) != bool {
- fail(
- "private-settings.signatures." + employee-id + ".enabled",
- "ожидалось true или false",
- )
- }
- if enabled {
- signature-image = path("/.private/executors/" + person.signature-file)
- signature-offset = signature.at("offset", default: 0cm)
- if type(signature-offset) != length {
- fail(
- "private-settings.signatures." + employee-id + ".offset",
- "ожидалась длина, например 1.25cm",
- )
- }
- }
- }
- (
- resolved-role,
- person.name,
- signature-image,
- signature-offset,
- )
- }
|