mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 11:42:30 +03:00
Modify request popup (#2676)
Signed-off-by: Denis Maslennikov <denis.maslennikov@gmail.com>
This commit is contained in:
parent
4a5532af10
commit
0dcd81bf5b
@ -31,11 +31,12 @@ import {
|
||||
TypeString,
|
||||
UX
|
||||
} from '@hcengineering/model'
|
||||
import core, { TAttachedDoc } from '@hcengineering/model-core'
|
||||
import { Request, RequestDecisionComment, RequestStatus } from '@hcengineering/request'
|
||||
import core, { TAttachedDoc, TClass } from '@hcengineering/model-core'
|
||||
import { Request, RequestDecisionComment, RequestStatus, RequestPresenter } from '@hcengineering/request'
|
||||
import request from './plugin'
|
||||
import view from '@hcengineering/model-view'
|
||||
import { TComment } from '@hcengineering/model-chunter'
|
||||
import { AnyComponent } from '@hcengineering/ui'
|
||||
|
||||
export const DOMAIN_REQUEST = 'request' as Domain
|
||||
|
||||
@ -69,8 +70,13 @@ export class TRequest extends TAttachedDoc implements Request {
|
||||
@Mixin(request.mixin.RequestDecisionComment, chunter.class.Comment)
|
||||
export class TRequestDecisionComment extends TComment implements RequestDecisionComment {}
|
||||
|
||||
@Mixin(request.mixin.RequestPresenter, core.class.Class)
|
||||
export class TRequestPresenter extends TClass implements RequestPresenter {
|
||||
presenter!: AnyComponent
|
||||
}
|
||||
|
||||
export function createModel (builder: Builder): void {
|
||||
builder.createModel(TRequest, TRequestDecisionComment)
|
||||
builder.createModel(TRequest, TRequestDecisionComment, TRequestPresenter)
|
||||
|
||||
builder.mixin(request.class.Request, core.class.Class, view.mixin.ObjectEditor, {
|
||||
editor: request.component.EditRequest
|
||||
@ -80,6 +86,10 @@ export function createModel (builder: Builder): void {
|
||||
presenter: request.component.RequestPresenter
|
||||
})
|
||||
|
||||
builder.mixin(request.class.Request, core.class.Class, request.mixin.RequestPresenter, {
|
||||
presenter: request.component.RequestView
|
||||
})
|
||||
|
||||
builder.createDoc(
|
||||
activity.class.TxViewlet,
|
||||
core.space.Model,
|
||||
|
@ -27,8 +27,7 @@ export default mergeIds(requestId, request, {
|
||||
RequestLabel: '' as AnyComponent
|
||||
},
|
||||
component: {
|
||||
EditRequest: '' as AnyComponent,
|
||||
RequestPresenter: '' as AnyComponent
|
||||
EditRequest: '' as AnyComponent
|
||||
},
|
||||
ids: {
|
||||
TxRequestCreate: '' as Ref<TxViewlet>
|
||||
|
@ -14,12 +14,11 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { EmployeeAccount } from '@hcengineering/contact'
|
||||
import { getCurrentAccount, Ref } from '@hcengineering/core'
|
||||
import { createQuery } from '@hcengineering/presentation'
|
||||
import { Class, getCurrentAccount, Ref } from '@hcengineering/core'
|
||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { Request, RequestStatus } from '@hcengineering/request'
|
||||
import { Label, Scroller, deviceOptionsStore as deviceInfo } from '@hcengineering/ui'
|
||||
import { Label, Scroller, deviceOptionsStore as deviceInfo, AnyComponent, Component } from '@hcengineering/ui'
|
||||
import request from '../plugin'
|
||||
import RequestView from './RequestView.svelte'
|
||||
|
||||
let requests: Request[] = []
|
||||
const me = getCurrentAccount()._id as Ref<EmployeeAccount>
|
||||
@ -35,6 +34,31 @@
|
||||
(p) => p.requested.filter((a) => a === me).length > p.approved.filter((a) => a === me).length
|
||||
))
|
||||
)
|
||||
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
const defaultPresenter = request.component.RequestPresenter
|
||||
|
||||
$: classes = new Set(requests.map((r) => r._class))
|
||||
|
||||
const presenters: Record<Ref<Class<Request>>, AnyComponent> = {}
|
||||
|
||||
function getEditor (_class: Ref<Class<Request>>): AnyComponent {
|
||||
const clazz = hierarchy.getClass(_class)
|
||||
const mixin = hierarchy.as(clazz, request.mixin.RequestPresenter)
|
||||
if (mixin?.presenter == null && clazz.extends != null) return getEditor(clazz.extends)
|
||||
return mixin.presenter
|
||||
}
|
||||
|
||||
$: updatePresenters(classes)
|
||||
|
||||
function updatePresenters (classes: Set<Ref<Class<Request>>>) {
|
||||
classes.forEach((cl) => {
|
||||
const presenter = getEditor(cl)
|
||||
presenters[cl] = presenter || defaultPresenter
|
||||
})
|
||||
}
|
||||
|
||||
$: isMobile = $deviceInfo.isMobile
|
||||
</script>
|
||||
|
||||
@ -44,8 +68,8 @@
|
||||
</div>
|
||||
{#if requests.length > 0}
|
||||
<Scroller padding={'0 .5rem'}>
|
||||
{#each requests as request (request._id)}
|
||||
<RequestView value={request} />
|
||||
{#each requests as request}
|
||||
<Component is={presenters[request._class]} props={{ value: request }} />
|
||||
{/each}
|
||||
</Scroller>
|
||||
{:else}
|
||||
|
@ -19,6 +19,7 @@ import TxCreateRequest from './components/activity/TxCreateRequest.svelte'
|
||||
import RequestLabel from './components/activity/TxRequestLabel.svelte'
|
||||
import EditRequest from './components/EditRequest.svelte'
|
||||
import RequestPresenter from './components/RequestPresenter.svelte'
|
||||
import RequestView from './components/RequestView.svelte'
|
||||
|
||||
export default async (): Promise<Resources> => ({
|
||||
activity: {
|
||||
@ -28,6 +29,7 @@ export default async (): Promise<Resources> => ({
|
||||
component: {
|
||||
RequestsPopup,
|
||||
EditRequest,
|
||||
RequestPresenter
|
||||
RequestPresenter,
|
||||
RequestView
|
||||
}
|
||||
})
|
||||
|
@ -47,6 +47,13 @@ export enum RequestStatus {
|
||||
Rejected = 'Rejected'
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface RequestPresenter extends Class<Doc> {
|
||||
presenter: AnyComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@ -60,10 +67,13 @@ const request = plugin(requestId, {
|
||||
Request: '' as Ref<Class<Request>>
|
||||
},
|
||||
mixin: {
|
||||
RequestDecisionComment: '' as Ref<Mixin<RequestDecisionComment>>
|
||||
RequestDecisionComment: '' as Ref<Mixin<RequestDecisionComment>>,
|
||||
RequestPresenter: '' as Ref<Mixin<RequestPresenter>>
|
||||
},
|
||||
component: {
|
||||
RequestsPopup: '' as AnyComponent
|
||||
RequestsPopup: '' as AnyComponent,
|
||||
RequestPresenter: '' as AnyComponent,
|
||||
RequestView: '' as AnyComponent
|
||||
},
|
||||
string: {
|
||||
Requests: '' as IntlString
|
||||
|
Loading…
Reference in New Issue
Block a user