Calendar/src/v2/features/resource/ResourceRenderer.ts

38 lines
994 B
TypeScript
Raw Normal View History

import { from, IEnumerable } from 'ts-linq-light';
import { IGroupingRenderer, RenderContext } from '../../core/IGroupingRenderer';
import { NextFunction, RenderData } from '../../core/RenderBuilder';
2025-12-06 01:22:04 +01:00
interface Resource {
id: string;
name?: string;
}
export class ResourceRenderer implements IGroupingRenderer<Resource> {
2025-12-06 01:22:04 +01:00
readonly type = 'resource';
render(
resources: IEnumerable<Resource>,
data: RenderData,
next: NextFunction,
context: RenderContext
): void {
const dates = data.dates || from([]);
for (const resource of resources) {
const colspan = next.count(dates);
2025-12-06 01:22:04 +01:00
const cell = document.createElement('swp-resource-header');
cell.dataset.resourceId = resource.id;
cell.textContent = resource.name || resource.id;
if (colspan > 1) {
cell.style.gridColumn = `span ${colspan}`;
}
2025-12-06 01:22:04 +01:00
context.headerContainer.appendChild(cell);
next.render(dates);
2025-12-06 01:22:04 +01:00
}
}
}