2021-08-06 08:31:17 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
2022-02-03 09:03:53 +00:00
|
|
|
//
|
2021-08-06 08:31:17 +00:00
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
2022-02-03 09:03:53 +00:00
|
|
|
//
|
2021-08-06 08:31:17 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
2022-02-03 09:03:53 +00:00
|
|
|
//
|
2021-08-06 08:31:17 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2022-03-04 09:01:46 +00:00
|
|
|
import type { Class, Client, Obj, Ref, Space } from '@anticrm/core'
|
2021-08-24 18:42:32 +00:00
|
|
|
import type { Asset } from '@anticrm/platform'
|
2022-04-25 17:15:13 +00:00
|
|
|
import { getResource } from '@anticrm/platform'
|
2022-03-04 09:01:46 +00:00
|
|
|
import { NavigatorModel } from '@anticrm/workbench'
|
2022-04-25 17:15:13 +00:00
|
|
|
import view from '@anticrm/view'
|
2021-08-06 08:31:17 +00:00
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
export function classIcon (client: Client, _class: Ref<Class<Obj>>): Asset | undefined {
|
2021-08-06 08:31:17 +00:00
|
|
|
return client.getHierarchy().getClass(_class).icon
|
|
|
|
}
|
2022-04-29 05:27:17 +00:00
|
|
|
export function getSpecialSpaceClass (model: NavigatorModel): Array<Ref<Class<Space>>> {
|
2022-04-25 17:15:13 +00:00
|
|
|
const spaceResult = model.spaces.map((x) => x.spaceClass)
|
|
|
|
const result = (model.specials ?? []).map((it) => it.spaceClass).filter((it) => it !== undefined)
|
2022-03-04 09:01:46 +00:00
|
|
|
return spaceResult.concat(result as Array<Ref<Class<Space>>>)
|
|
|
|
}
|
2022-04-25 17:15:13 +00:00
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
export async function getSpaceName (client: Client, space: Space): Promise<string> {
|
2022-04-25 17:15:13 +00:00
|
|
|
const hierarchy = client.getHierarchy()
|
|
|
|
const clazz = hierarchy.getClass(space._class)
|
|
|
|
const nameMixin = hierarchy.as(clazz, view.mixin.SpaceName)
|
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
if (nameMixin?.getName !== undefined) {
|
2022-04-25 17:15:13 +00:00
|
|
|
const getSpaceName = await getResource(nameMixin.getName)
|
|
|
|
const name = await getSpaceName(client, space)
|
|
|
|
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
return space.name
|
|
|
|
}
|