Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tweaks for EQMS-1317 #7854

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "Hlavní",
"Minor": "Vedlejší",
"Patch": "Oprava",
"DocumentApprovals": "Revize a schválení",
"ValidationWorkflow": "Ověřovací pracovní postup",
"ChangeOwner": "Změnit vlastníka dokumentu",
"ChangeOwnerHintBeginning": "Převést vlastnictví",
"ChangeOwnerHintEnd": "na jinou osobu.",
Expand Down
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "Hauptversion",
"Minor": "Nebenversion",
"Patch": "Patch",
"DocumentApprovals": "Prüfungen und Genehmigungen",
"ValidationWorkflow": "Validierungsworkflow",
"ChangeOwner": "Dokumentenbesitzer ändern",
"ChangeOwnerHintBeginning": "Übertragen Sie den Besitz des",
"ChangeOwnerHintEnd": "an eine andere Person.",
Expand Down
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "Major",
"Minor": "Minor",
"Patch": "Patch",
"DocumentApprovals": "Reviews and Approvals",
"ValidationWorkflow": "Validation workflow",
"ChangeOwner": "Change document owner",
"ChangeOwnerHintBeginning": "Transfer ownership of the",
"ChangeOwnerHintEnd": "to another person.",
Expand Down
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "Majeur",
"Minor": "Mineur",
"Patch": "Correctif",
"DocumentApprovals": "Révisions et approbations",
"ValidationWorkflow": "Flux de validation",
"ChangeOwner": "Changer le propriétaire du document",
"ChangeOwnerHintBeginning": "Transférer la propriété du",
"ChangeOwnerHintEnd": "à une autre personne.",
Expand Down
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "Maggiore",
"Minor": "Minore",
"Patch": "Patch",
"DocumentApprovals": "Revisioni e Approvazioni",
"ValidationWorkflow": "Flusso di convalida",
"ChangeOwner": "Cambia proprietario del documento",
"ChangeOwnerHintBeginning": "Trasferisci la proprietà del",
"ChangeOwnerHintEnd": "a un'altra persona.",
Expand Down
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "Мажорная",
"Minor": "Минорная",
"Patch": "Патч",
"DocumentApprovals": "Рецензии и утверждения",
"ValidationWorkflow": "Процесс валидации",
"ChangeOwner": "Изменить владельца документа",
"ChangeOwnerHintBeginning": "Передайте права владельца документа",
"ChangeOwnerHintEnd": "другому лицу.",
Expand Down
2 changes: 1 addition & 1 deletion plugins/controlled-documents-assets/lang/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Major": "主要",
"Minor": "次要",
"Patch": "补丁",
"DocumentApprovals": "审查和批准",
"ValidationWorkflow": "验证工作流程",
"ChangeOwner": "更改文档所有者",
"ChangeOwnerHintBeginning": "转移所有权",
"ChangeOwnerHintEnd": "给其他人。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ControlledDocument,
ControlledDocumentState,
DocumentRequest,
DocumentState,
Project
} from '@hcengineering/controlled-documents'
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
Expand Down Expand Up @@ -163,10 +164,15 @@
return
}

const hierarchy = client.getHierarchy()

const isReviewed = $controlledDocument.controlledState === ControlledDocumentState.Reviewed
const isApprovalRequest = hierarchy.isDerived(requestClass, documents.class.DocumentApprovalRequest)

const teamPopupData: TeamPopupData = {
controlledDoc: $controlledDocument,
requestClass,
requireSignature: true
requireSignature: !(isReviewed && isApprovalRequest)
}

showPopup(TeamPopup, teamPopupData, 'center')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,121 +13,68 @@
// limitations under the License.
-->
<script lang="ts">
import { Ref, SortingOrder } from '@hcengineering/core'
import { Label, Scroller } from '@hcengineering/ui'
import { createQuery } from '@hcengineering/presentation'
import documents, { DocumentApprovalRequest, DocumentReviewRequest } from '@hcengineering/controlled-documents'
import { employeeByIdStore } from '@hcengineering/contact-resources'
import { Employee, Person, formatName } from '@hcengineering/contact'
import { employeeByIdStore, personIdByAccountId } from '@hcengineering/contact-resources'
import documents, {
DocumentRequest,
emptyBundle,
extractValidationWorkflow
} from '@hcengineering/controlled-documents'
import { Ref } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import { Label, Scroller } from '@hcengineering/ui'

import documentsRes from '../../plugin'
import { $controlledDocument as controlledDocument } from '../../stores/editors/document/editor'
import {
$controlledDocument as controlledDocument,
$documentSnapshots as documentSnapshots
} from '../../stores/editors/document/editor'
import { formatSignatureDate } from '../../utils'

interface Signer {
id?: Ref<Person>
role: 'author' | 'reviewer' | 'approver'
name: string
date: string
}
let requests: DocumentRequest[] = []

let signers: Signer[] = []

let reviewRequest: DocumentReviewRequest
let approvalRequest: DocumentApprovalRequest

const reviewQuery = createQuery()
const approvalQuery = createQuery()

$: if ($controlledDocument !== undefined) {
reviewQuery.query(
documents.class.DocumentReviewRequest,
{
attachedTo: $controlledDocument?._id,
attachedToClass: $controlledDocument?._class
},
(res) => {
reviewRequest = res[0]
},
{
sort: { createdOn: SortingOrder.Descending },
limit: 1
}
)

approvalQuery.query(
documents.class.DocumentApprovalRequest,
{
attachedTo: $controlledDocument?._id,
attachedToClass: $controlledDocument?._class
},
(res) => {
approvalRequest = res[0]
},
{
sort: { createdOn: SortingOrder.Descending },
limit: 1
}
)
} else {
reviewQuery.unsubscribe()
approvalQuery.unsubscribe()
const client = getClient()
const hierarchy = client.getHierarchy()

$: doc = $controlledDocument

$: if (doc) {
void client.findAll(documents.class.DocumentRequest, { attachedTo: doc._id }).then((r) => {
requests = r
})
}

$: if ($controlledDocument !== null) {
const getNameByEmployeeId = (id: Ref<Person> | undefined): string => {
if (id === undefined) {
return ''
$: workflow = extractValidationWorkflow(
hierarchy,
{
...emptyBundle(),
ControlledDocument: doc ? [doc] : [],
DocumentRequest: requests,
DocumentSnapshot: $documentSnapshots
},
(ref) => $personIdByAccountId.get(ref)
)

$: state = (doc ? workflow?.get(doc._id) ?? [] : [])[0]
$: signers = (state?.approvals ?? [])
.filter((a) => a.state === 'approved')
.map((a) => {
return {
person: a.person,
role: a.role,
name: getNameByEmployeeId(a.person),
date: a.timestamp ? formatSignatureDate(a.timestamp) : ''
}
})

const employee = $employeeByIdStore.get(id as Ref<Employee>)
const rawName = employee?.name

return rawName !== undefined ? formatName(rawName) : ''
}
function getNameByEmployeeId (id: Ref<Person> | undefined): string {
if (id === undefined) return ''

const authorSignDate =
reviewRequest !== undefined
? reviewRequest.createdOn
: approvalRequest !== undefined
? approvalRequest.createdOn
: $controlledDocument.createdOn

signers = [
{
id: $controlledDocument.author,
role: 'author',
name: getNameByEmployeeId($controlledDocument.author),
date: authorSignDate !== undefined ? formatSignatureDate(authorSignDate) : ''
}
]

if (reviewRequest !== undefined) {
reviewRequest.approved.forEach((reviewer, idx) => {
const date = reviewRequest.approvedDates?.[idx]

signers.push({
id: reviewer,
role: 'reviewer',
name: getNameByEmployeeId(reviewer),
date: formatSignatureDate(date ?? reviewRequest.modifiedOn)
})
})
}
const employee = $employeeByIdStore.get(id as Ref<Employee>)
const rawName = employee?.name

if (approvalRequest !== undefined) {
approvalRequest.approved.forEach((approver, idx) => {
const date = approvalRequest.approvedDates?.[idx]

signers.push({
id: approver,
role: 'approver',
name: getNameByEmployeeId(approver),
date: formatSignatureDate(date ?? approvalRequest.modifiedOn)
})
})
}
return rawName !== undefined ? formatName(rawName) : ''
}

function getSignerLabel (role: 'author' | 'reviewer' | 'approver'): IntlString {
Expand Down Expand Up @@ -161,7 +108,7 @@
{signer.name}
</div>
<div class="code">
{signer.id}
{signer.person}
</div>
</div>
</div>
Expand Down
Loading