employees.typ 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // =============================================================
  2. // INFRASTRUCTURE: ПУБЛИЧНЫЙ СПРАВОЧНИК СОТРУДНИКОВ И ПОДПИСЕЙ
  3. // =============================================================
  4. // ФИО, обычная должность и имя файла не являются приватными.
  5. // Наличие подписи и её индивидуальное смещение задаются только в
  6. // игнорируемом Git файле /.private/settings.typ.
  7. #import "../domain/document.typ": fail
  8. #let employee-directory = (
  9. tkachenko: (
  10. name: "Ткаченко А.С.",
  11. default-role: "Автор",
  12. signature-file: "Tkachenko.png",
  13. ),
  14. )
  15. #let empty-private-settings = (
  16. companies: (:),
  17. signatures: (:),
  18. )
  19. #let validate-private-settings(settings) = {
  20. if type(settings) != dictionary {
  21. fail("private-settings", "ожидался словарь из .private/settings.typ")
  22. }
  23. for field in ("companies", "signatures") {
  24. if type(settings.at(field, default: (:))) != dictionary {
  25. fail("private-settings." + field, "ожидался словарь")
  26. }
  27. }
  28. settings
  29. }
  30. #let private-company-media(settings, company-id) = {
  31. let settings = validate-private-settings(settings)
  32. let company = settings.companies.at(company-id, default: none)
  33. if company == none {
  34. (signature: none, stamp: none)
  35. } else {
  36. if type(company) != dictionary {
  37. fail("private-settings.companies." + company-id, "ожидался словарь")
  38. }
  39. let has-signature = company.at("signature", default: false)
  40. let has-stamp = company.at("stamp", default: false)
  41. if type(has-signature) != bool or type(has-stamp) != bool {
  42. fail(
  43. "private-settings.companies." + company-id,
  44. "поля signature и stamp должны быть true или false",
  45. )
  46. }
  47. (
  48. signature: if has-signature {
  49. path("/.private/" + company-id + "/sign.png")
  50. } else {
  51. none
  52. },
  53. stamp: if has-stamp {
  54. path("/.private/" + company-id + "/stamp.png")
  55. } else {
  56. none
  57. },
  58. )
  59. }
  60. }
  61. #let report-executor(employee-id, role: auto, private-settings: empty-private-settings) = {
  62. if type(employee-id) != str or not employee-directory.keys().contains(employee-id) {
  63. fail(
  64. "report-executor.employee-id",
  65. "неизвестный сотрудник " + repr(employee-id) + "; доступны "
  66. + employee-directory.keys().join(", "),
  67. )
  68. }
  69. let person = employee-directory.at(employee-id)
  70. let resolved-role = if role == auto { person.default-role } else { role }
  71. if type(resolved-role) != str or resolved-role.trim() == "" {
  72. fail("report-executor.role", "должность должна быть непустой строкой")
  73. }
  74. let settings = validate-private-settings(private-settings)
  75. let signature = settings.signatures.at(employee-id, default: none)
  76. let signature-image = none
  77. let signature-offset = 0cm
  78. if signature != none {
  79. if type(signature) != dictionary {
  80. fail("private-settings.signatures." + employee-id, "ожидался словарь")
  81. }
  82. let enabled = signature.at("enabled", default: true)
  83. if type(enabled) != bool {
  84. fail(
  85. "private-settings.signatures." + employee-id + ".enabled",
  86. "ожидалось true или false",
  87. )
  88. }
  89. if enabled {
  90. signature-image = path("/.private/executors/" + person.signature-file)
  91. signature-offset = signature.at("offset", default: 0cm)
  92. if type(signature-offset) != length {
  93. fail(
  94. "private-settings.signatures." + employee-id + ".offset",
  95. "ожидалась длина, например 1.25cm",
  96. )
  97. }
  98. }
  99. }
  100. (
  101. resolved-role,
  102. person.name,
  103. signature-image,
  104. signature-offset,
  105. )
  106. }