From d555409ca117ffc6953e710aab365e001690eb13 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Tue, 11 Jan 2022 16:05:53 +0700 Subject: [PATCH] Unify contacts (#778) Signed-off-by: Andrey Sobolev --- models/contact/src/index.ts | 49 ++---- models/contact/src/plugin.ts | 4 +- models/recruit/src/index.ts | 8 +- models/recruit/src/plugin.ts | 4 +- models/view/src/index.ts | 9 +- packages/core/src/hierarchy.ts | 11 +- packages/ui/src/components/Menu.svelte | 15 +- plugins/contact-assets/lang/en.json | 3 +- plugins/contact-resources/package.json | 3 +- .../src/components/Contacts.svelte | 122 +++++++++++++++ .../src/components/CreateContact.svelte | 32 ++++ .../src/components/CreateOrganization.svelte | 11 +- .../src/components/CreatePerson.svelte | 11 +- .../src/components/EditContact.svelte | 21 +-- .../src/components/EditPerson.svelte | 14 +- .../src/components/RolePresenter.svelte | 72 +++++++++ .../src/components/icons/Edit.svelte | 24 +++ plugins/contact-resources/src/index.ts | 6 +- plugins/contact-resources/src/plugin.ts | 3 +- plugins/contact-resources/src/utils.ts | 10 ++ plugins/contact/src/index.ts | 19 ++- .../src/components/ModelView.svelte | 2 + .../src/components/CreateCandidate.svelte | 17 +- .../src/components/EditCandidate.svelte | 148 ------------------ .../src/components/KanbanCard.svelte | 6 +- plugins/recruit-resources/src/index.ts | 30 ++-- .../view-resources/src/components/Menu.svelte | 16 +- plugins/view/src/index.ts | 13 +- .../src/components/Workbench.svelte | 135 +++++++++------- plugins/workbench/src/index.ts | 3 + 30 files changed, 466 insertions(+), 355 deletions(-) create mode 100644 plugins/contact-resources/src/components/Contacts.svelte create mode 100644 plugins/contact-resources/src/components/CreateContact.svelte create mode 100644 plugins/contact-resources/src/components/RolePresenter.svelte create mode 100644 plugins/contact-resources/src/components/icons/Edit.svelte create mode 100644 plugins/contact-resources/src/utils.ts delete mode 100644 plugins/recruit-resources/src/components/EditCandidate.svelte diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index b634787e3d..a641ec9f7e 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -71,13 +71,14 @@ export class TContact extends TDoc implements Contact { @Prop(Collection(chunter.class.Comment), 'Comments' as IntlString) comments?: number + + @Prop(TypeString(), 'Location' as IntlString) + city!: string } @Model(contact.class.Person, contact.class.Contact) @UX('Person' as IntlString, contact.icon.Person, undefined, 'name') export class TPerson extends TContact implements Person { - @Prop(TypeString(), 'City' as IntlString) - city!: string } @Model(contact.class.Organization, contact.class.Contact) @@ -85,6 +86,7 @@ export class TPerson extends TContact implements Person { export class TOrganization extends TContact implements Organization {} @Model(contact.class.Employee, contact.class.Person) +@UX('Employee' as IntlString, contact.icon.Person) export class TEmployee extends TPerson implements Employee {} @Model(contact.class.EmployeeAccount, core.class.Account) @@ -114,44 +116,23 @@ export function createModel (builder: Builder): void { TEmployeeAccount ) - builder.mixin(contact.class.Persons, core.class.Class, workbench.mixin.SpaceView, { - view: { - class: contact.class.Person, - createItemDialog: contact.component.CreatePerson - } + builder.mixin(contact.class.Person, core.class.Class, view.mixin.ObjectFactory, { + component: contact.component.CreatePerson }) - builder.mixin(contact.class.Organizations, core.class.Class, workbench.mixin.SpaceView, { - view: { - class: contact.class.Organization, - createItemDialog: contact.component.CreateOrganization - } + builder.mixin(contact.class.Organization, core.class.Class, view.mixin.ObjectFactory, { + component: contact.component.CreateOrganization }) builder.createDoc(workbench.class.Application, core.space.Model, { label: contact.string.Contacts, icon: contact.icon.Person, hidden: false, - navigatorModel: { - spaces: [ - { - label: contact.string.Persons, - spaceClass: contact.class.Persons, - addSpaceLabel: contact.string.CreatePersons, - createComponent: contact.component.CreatePersons - }, - { - label: contact.string.Organizations, - spaceClass: contact.class.Organizations, - addSpaceLabel: contact.string.CreateOrganizations, - createComponent: contact.component.CreateOrganizations - } - ] - } + component: contact.component.Contacts }, contact.app.Contacts) builder.createDoc(view.class.Viewlet, core.space.Model, { - attachTo: contact.class.Person, + attachTo: contact.class.Contact, descriptor: view.viewlet.Table, open: contact.component.EditContact, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions @@ -161,19 +142,11 @@ export function createModel (builder: Builder): void { 'city', { presenter: attachment.component.AttachmentsPresenter, label: 'Files', sortingKey: 'attachments' }, 'modifiedOn', + { presenter: contact.component.RolePresenter, label: 'Role' }, 'channels' ] }) - builder.createDoc(view.class.Viewlet, core.space.Model, { - attachTo: contact.class.Organization, - descriptor: view.viewlet.Table, - open: contact.component.EditContact, - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - options: {}, - config: ['', { presenter: attachment.component.AttachmentsPresenter, label: 'Files', sortingKey: 'attachments' }, 'modifiedOn', 'channels'] - }) - builder.mixin(contact.class.Person, core.class.Class, view.mixin.ObjectEditor, { editor: contact.component.EditPerson }) diff --git a/models/contact/src/plugin.ts b/models/contact/src/plugin.ts index 79d4b94202..0ef9bf59e2 100644 --- a/models/contact/src/plugin.ts +++ b/models/contact/src/plugin.ts @@ -36,7 +36,9 @@ export const ids = mergeIds(contactId, contact, { CreateOrganization: '' as AnyComponent, CreatePersons: '' as AnyComponent, CreateOrganizations: '' as AnyComponent, - OrganizationPresenter: '' as AnyComponent + OrganizationPresenter: '' as AnyComponent, + Contacts: '' as AnyComponent, + RolePresenter: '' as AnyComponent }, string: { Organizations: '' as IntlString, diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 3c3e588672..97a00c68ee 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -100,6 +100,10 @@ export function createModel (builder: Builder): void { editor: recruit.component.Applications }) + builder.mixin(recruit.mixin.Candidate, core.class.Mixin, view.mixin.ObjectFactory, { + component: recruit.component.CreateCandidate + }) + builder.createDoc( workbench.class.Application, core.space.Model, @@ -235,10 +239,6 @@ export function createModel (builder: Builder): void { card: recruit.component.KanbanCard }) - builder.mixin(recruit.mixin.Candidate, core.class.Class, view.mixin.ObjectEditor, { - editor: recruit.component.EditCandidate - }) - builder.mixin(recruit.class.Applicant, core.class.Class, view.mixin.ObjectEditor, { editor: recruit.component.EditApplication }) diff --git a/models/recruit/src/plugin.ts b/models/recruit/src/plugin.ts index e526f61cb9..f8e771857c 100644 --- a/models/recruit/src/plugin.ts +++ b/models/recruit/src/plugin.ts @@ -44,7 +44,6 @@ export default mergeIds(recruitId, recruit, { component: { CreateVacancy: '' as AnyComponent, CreateApplication: '' as AnyComponent, - EditCandidate: '' as AnyComponent, KanbanCard: '' as AnyComponent, ApplicationPresenter: '' as AnyComponent, ApplicationsPresenter: '' as AnyComponent, @@ -52,7 +51,8 @@ export default mergeIds(recruitId, recruit, { EditApplication: '' as AnyComponent, TemplatesIcon: '' as AnyComponent, Applications: '' as AnyComponent, - Candidates: '' as AnyComponent + Candidates: '' as AnyComponent, + CreateCandidate: '' as AnyComponent }, template: { DefaultVacancy: '' as Ref diff --git a/models/view/src/index.ts b/models/view/src/index.ts index c68d9338d5..f694d5f941 100644 --- a/models/view/src/index.ts +++ b/models/view/src/index.ts @@ -19,7 +19,7 @@ import { Builder, Mixin, Model } from '@anticrm/model' import core, { TClass, TDoc } from '@anticrm/model-core' import type { Asset, IntlString, Resource, Status } from '@anticrm/platform' import type { AnyComponent } from '@anticrm/ui' -import type { Action, ActionTarget, AttributeEditor, AttributePresenter, ObjectEditor, ObjectValidator, Viewlet, ViewletDescriptor } from '@anticrm/view' +import type { Action, ActionTarget, AttributeEditor, AttributePresenter, ObjectEditor, ObjectFactory, ObjectValidator, Viewlet, ViewletDescriptor } from '@anticrm/view' import view from './plugin' @Mixin(view.mixin.AttributeEditor, core.class.Class) @@ -42,6 +42,11 @@ export class TObjectValidator extends TClass implements ObjectValidator { validator!: Resource<((doc: T, client: Client) => Promise>)> } +@Mixin(view.mixin.ObjectFactory, core.class.Class) +export class TObjectFactory extends TClass implements ObjectFactory { + component!: AnyComponent +} + @Model(view.class.ViewletDescriptor, core.class.Doc, DOMAIN_MODEL) export class TViewletDescriptor extends TDoc implements ViewletDescriptor { component!: AnyComponent @@ -70,7 +75,7 @@ export class TActionTarget extends TDoc implements ActionTarget { } export function createModel (builder: Builder): void { - builder.createModel(TAttributeEditor, TAttributePresenter, TObjectEditor, TViewletDescriptor, TViewlet, TAction, TActionTarget, TObjectValidator) + builder.createModel(TAttributeEditor, TAttributePresenter, TObjectEditor, TViewletDescriptor, TViewlet, TAction, TActionTarget, TObjectValidator, TObjectFactory) builder.mixin(core.class.TypeString, core.class.Class, view.mixin.AttributeEditor, { editor: view.component.StringEditor diff --git a/packages/core/src/hierarchy.ts b/packages/core/src/hierarchy.ts index 2e4b7990aa..2dd2e6f416 100644 --- a/packages/core/src/hierarchy.ts +++ b/packages/core/src/hierarchy.ts @@ -157,7 +157,7 @@ export class Hierarchy { } private txMixin (tx: TxMixin): void { - if (tx.objectClass === core.class.Class) { + if (this.isDerived(tx.objectClass, core.class.Class)) { const obj = this.getClass(tx.objectId as Ref>) as any TxProcessor.updateMixin4Doc(obj, tx.mixin, tx.attributes) } @@ -304,7 +304,14 @@ export class Hierarchy { const result = new Map() let ancestors = this.getAncestors(clazz) if (to !== undefined) { - ancestors = ancestors.filter(c => this.isDerived(c, to) && c !== to) + const toAncestors = this.getAncestors(to) + for (const uto of toAncestors) { + if (ancestors.includes(uto)) { + to = uto + break + } + } + ancestors = ancestors.filter(c => this.isDerived(c, to as Ref>) && c !== to) } for (const cls of ancestors) { diff --git a/packages/ui/src/components/Menu.svelte b/packages/ui/src/components/Menu.svelte index b81d9bbd5f..8c678755b0 100644 --- a/packages/ui/src/components/Menu.svelte +++ b/packages/ui/src/components/Menu.svelte @@ -14,27 +14,22 @@ -->