mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-08 21:27:45 +03:00
TSK-1436: change deleting spaces to removing, add action to move all non-valid requests to correct spaces (#3149)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
93268d4dbc
commit
238f2da750
@ -328,9 +328,9 @@ export function createModel (builder: Builder): void {
|
||||
createAction(
|
||||
builder,
|
||||
{
|
||||
action: view.actionImpl.Delete,
|
||||
label: view.string.Delete,
|
||||
icon: view.icon.Delete,
|
||||
action: view.actionImpl.Archive,
|
||||
label: view.string.Archive,
|
||||
icon: view.icon.Archive,
|
||||
input: 'any',
|
||||
category: hr.category.HR,
|
||||
keyBinding: ['Meta + Backspace', 'Ctrl + Backspace'],
|
||||
@ -339,9 +339,10 @@ export function createModel (builder: Builder): void {
|
||||
_id: { $nin: [hr.ids.Head] }
|
||||
},
|
||||
target: hr.class.Department,
|
||||
context: { mode: 'context', application: hr.app.HR, group: 'create' }
|
||||
context: { mode: ['context', 'browser'], group: 'tools' },
|
||||
override: [view.action.Archive, view.action.Delete]
|
||||
},
|
||||
hr.action.DeleteDepartment
|
||||
hr.action.ArchiveDepartment
|
||||
)
|
||||
|
||||
createAction(
|
||||
|
@ -60,9 +60,9 @@ async function fixDepartmentsFromStaff (tx: TxOperations): Promise<void> {
|
||||
if (department._id === hr.ids.Head) continue
|
||||
ancestors.set(department._id, department.space)
|
||||
}
|
||||
for (const departmentTest of departments) {
|
||||
const parents: Department[] = parentsWithDepartmentMap.get(departmentTest._id) ?? []
|
||||
let _id = departmentTest._id
|
||||
for (const departmentItem of departments) {
|
||||
const parents: Department[] = parentsWithDepartmentMap.get(departmentItem._id) ?? []
|
||||
let _id = departmentItem._id
|
||||
while (true) {
|
||||
const department = departmentsMap.get(_id)
|
||||
if (department === undefined) break
|
||||
@ -71,7 +71,7 @@ async function fixDepartmentsFromStaff (tx: TxOperations): Promise<void> {
|
||||
if (next === undefined) break
|
||||
_id = next
|
||||
}
|
||||
parentsWithDepartmentMap.set(departmentTest._id, parents)
|
||||
parentsWithDepartmentMap.set(departmentItem._id, parents)
|
||||
}
|
||||
const staff = await tx.findAll(hr.mixin.Staff, {})
|
||||
const promises = []
|
||||
@ -93,6 +93,24 @@ async function fixDepartmentsFromStaff (tx: TxOperations): Promise<void> {
|
||||
}
|
||||
await Promise.all(promises)
|
||||
}
|
||||
|
||||
async function fixInvalidRequests (tx: TxOperations): Promise<void> {
|
||||
const departments = await tx.findAll(hr.class.Department, {})
|
||||
const staff = await tx.findAll(hr.mixin.Staff, {})
|
||||
const staffDepartmentMap = new Map(staff.map((s) => [s._id, s.department]))
|
||||
const requests = await tx.findAll(hr.class.Request, { space: { $nin: departments.map((d) => d._id) } })
|
||||
const res = []
|
||||
for (const request of requests) {
|
||||
const currentStaffDepartment = staffDepartmentMap.get(request.attachedTo)
|
||||
if (currentStaffDepartment !== null) {
|
||||
res.push(tx.update(request, { space: currentStaffDepartment }))
|
||||
} else {
|
||||
res.push(tx.update(request, { space: hr.ids.Head }))
|
||||
}
|
||||
}
|
||||
await Promise.all(res)
|
||||
}
|
||||
|
||||
function toTzDate (date: number): TzDate {
|
||||
const res = new Date(date)
|
||||
return {
|
||||
@ -234,5 +252,6 @@ export const hrOperation: MigrateOperation = {
|
||||
await createSpace(tx)
|
||||
await fixDuplicatesInDepartments(tx)
|
||||
await fixDepartmentsFromStaff(tx)
|
||||
await fixInvalidRequests(tx)
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export default mergeIds(hrId, hr, {
|
||||
},
|
||||
action: {
|
||||
EditDepartment: '' as Ref<Action>,
|
||||
DeleteDepartment: '' as Ref<Action>,
|
||||
ArchiveDepartment: '' as Ref<Action>,
|
||||
EditRequest: '' as Ref<Action>,
|
||||
EditRequestType: '' as Ref<Action>,
|
||||
DeleteRequest: '' as Ref<Action>
|
||||
|
@ -27,9 +27,8 @@ export function createModel (builder: Builder): void {
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverHr.trigger.OnDepartmentStaff,
|
||||
txMatch: {
|
||||
_class: core.class.TxCollectionCUD,
|
||||
'tx.objectClass': hr.mixin.Staff,
|
||||
'tx._class': core.class.TxMixin
|
||||
_class: core.class.TxMixin,
|
||||
mixin: hr.mixin.Staff
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -252,7 +252,8 @@ export const actionTemplates = template({
|
||||
context: {
|
||||
mode: ['context', 'browser'],
|
||||
group: 'tools'
|
||||
}
|
||||
},
|
||||
override: [view.action.Archive, view.action.Delete]
|
||||
},
|
||||
unarchiveSpace: {
|
||||
label: task.string.Unarchive,
|
||||
|
@ -1183,7 +1183,8 @@ export function createModel (builder: Builder): void {
|
||||
context: {
|
||||
mode: ['context', 'browser'],
|
||||
group: 'edit'
|
||||
}
|
||||
},
|
||||
override: [view.action.Archive, view.action.Delete]
|
||||
},
|
||||
tracker.action.DeleteProject
|
||||
)
|
||||
|
@ -508,6 +508,24 @@ export function createModel (builder: Builder): void {
|
||||
view.action.Delete
|
||||
)
|
||||
|
||||
createAction(
|
||||
builder,
|
||||
{
|
||||
action: view.actionImpl.Archive,
|
||||
label: view.string.Archive,
|
||||
icon: view.icon.Archive,
|
||||
category: view.category.General,
|
||||
input: 'any',
|
||||
query: {
|
||||
archived: false
|
||||
},
|
||||
target: core.class.Space,
|
||||
context: { mode: ['context', 'browser'], group: 'tools' },
|
||||
override: [view.action.Delete]
|
||||
},
|
||||
view.action.Archive
|
||||
)
|
||||
|
||||
// Keyboard actions.
|
||||
createAction(
|
||||
builder,
|
||||
|
@ -21,6 +21,7 @@ import view from '@hcengineering/view-resources/src/plugin'
|
||||
export default mergeIds(viewId, view, {
|
||||
actionImpl: {
|
||||
Delete: '' as ViewAction,
|
||||
Archive: '' as ViewAction,
|
||||
Move: '' as ViewAction,
|
||||
MoveLeft: '' as ViewAction,
|
||||
MoveRight: '' as ViewAction,
|
||||
|
@ -51,7 +51,10 @@
|
||||
|
||||
query.query(
|
||||
hr.class.Department,
|
||||
resultQuery,
|
||||
{
|
||||
...resultQuery,
|
||||
archived: false
|
||||
},
|
||||
(res) => {
|
||||
head = res.find((p) => p._id === hr.ids.Head)
|
||||
descendants.clear()
|
||||
|
@ -13,6 +13,8 @@
|
||||
"Role": "Role",
|
||||
"DeleteObject": "Delete object",
|
||||
"DeleteObjectConfirm": "Do you want to delete this {count, plural, =1 {object} other {# objects}}?",
|
||||
"Archive": "Archive",
|
||||
"ArchiveConfirm": "Do you want to archive this {count, plural, =1 {object} other {# objects}}?",
|
||||
"Open": "Open",
|
||||
"Assignees": "Assignees",
|
||||
"Labels": "Labels",
|
||||
|
@ -12,7 +12,9 @@
|
||||
"Table": "Таблица",
|
||||
"Role": "Роль",
|
||||
"DeleteObject": "Удалить объект",
|
||||
"DeleteObjectConfirm": "Вы действительно хотите удалить {count, plural, =1 {этот обьект} other {эти # обьекта}}?",
|
||||
"DeleteObjectConfirm": "Вы действительно хотите удалить {count, plural, =1 {этот объект} other {эти # объекта}}?",
|
||||
"Archive": "Архивировать",
|
||||
"ArchiveConfirm": "Вы действительно хотите заархивировать {count, plural, =1 {этот объект} other {эти # объекта}}?",
|
||||
"Open": "Открыть",
|
||||
"Assignees": "Исполнители",
|
||||
"Labels": "Метки",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Class, Doc, DocumentQuery, Hierarchy, Ref } from '@hcengineering/core'
|
||||
import { Class, Doc, DocumentQuery, Hierarchy, Ref, Space, TxResult } from '@hcengineering/core'
|
||||
import { Asset, getResource, IntlString, Resource } from '@hcengineering/platform'
|
||||
import { getClient, MessageBox, updateAttribute } from '@hcengineering/presentation'
|
||||
import {
|
||||
@ -70,6 +70,27 @@ function Delete (object: Doc | Doc[]): void {
|
||||
)
|
||||
}
|
||||
|
||||
function Archive (object: Space | Space[]): void {
|
||||
showPopup(
|
||||
MessageBox,
|
||||
{
|
||||
label: view.string.Archive,
|
||||
message: view.string.ArchiveConfirm,
|
||||
params: { count: Array.isArray(object) ? object.length : 1 },
|
||||
action: async () => {
|
||||
const objs = Array.isArray(object) ? object : [object]
|
||||
const client = getClient()
|
||||
const promises: Array<Promise<TxResult>> = []
|
||||
for (const obj of objs) {
|
||||
promises.push(client.update(obj, { archived: true }))
|
||||
}
|
||||
await Promise.all(promises)
|
||||
}
|
||||
},
|
||||
undefined
|
||||
)
|
||||
}
|
||||
|
||||
async function Move (docs: Doc | Doc[]): Promise<void> {
|
||||
showPopup(MoveView, { selected: docs })
|
||||
}
|
||||
@ -408,6 +429,7 @@ async function getPopupAlignment (
|
||||
export const actionImpl = {
|
||||
CopyTextToClipboard,
|
||||
Delete,
|
||||
Archive,
|
||||
Move,
|
||||
MoveUp,
|
||||
MoveDown,
|
||||
|
@ -159,12 +159,6 @@ export function filterActions (
|
||||
if (role < AccountRole.Maintainer && action.secured === true) {
|
||||
continue
|
||||
}
|
||||
if (action.query !== undefined) {
|
||||
const r = matchQuery([doc], action.query, doc._class, hierarchy)
|
||||
if (r.length === 0) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (
|
||||
(hierarchy.isDerived(doc._class, action.target) && client.getHierarchy().isDerived(action.target, derived)) ||
|
||||
(hierarchy.isMixin(action.target) && hierarchy.hasMixin(doc, action.target))
|
||||
@ -172,6 +166,12 @@ export function filterActions (
|
||||
if (action.override !== undefined) {
|
||||
overrideRemove.push(...action.override)
|
||||
}
|
||||
if (action.query !== undefined) {
|
||||
const r = matchQuery([doc], action.query, doc._class, hierarchy)
|
||||
if (r.length === 0) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
result.push(action)
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ export default mergeIds(viewId, view, {
|
||||
ChooseAColor: '' as IntlString,
|
||||
DeleteObject: '' as IntlString,
|
||||
DeleteObjectConfirm: '' as IntlString,
|
||||
Archive: '' as IntlString,
|
||||
ArchiveConfirm: '' as IntlString,
|
||||
Assignees: '' as IntlString,
|
||||
Labels: '' as IntlString,
|
||||
ActionPlaceholder: '' as IntlString,
|
||||
|
@ -652,6 +652,7 @@ const view = plugin(viewId, {
|
||||
},
|
||||
action: {
|
||||
Delete: '' as Ref<Action>,
|
||||
Archive: '' as Ref<Action>,
|
||||
Move: '' as Ref<Action>,
|
||||
MoveLeft: '' as Ref<Action>,
|
||||
MoveRight: '' as Ref<Action>,
|
||||
|
Loading…
Reference in New Issue
Block a user