OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/frontend/app/components/wp-fast-table/builders/relation-cell-builder.ts

78 lines
2.7 KiB

import {
WorkPackageResource,
WorkPackageResourceInterface
} from './../../api/api-v3/hal-resources/work-package-resource.service';
import {DisplayField} from './../../wp-display/wp-display-field/wp-display-field.module';
import {WorkPackageDisplayFieldService} from './../../wp-display/wp-display-field/wp-display-field.service';
import {$injectFields, injectorBridge} from '../../angular/angular-injector-bridge.functions';
import {States} from '../../states.service';
import {tdClassName} from './cell-builder';
import {QueryColumn} from '../../api/api-v3/hal-resources/query-resource.service';
import {
RelationsStateValue,
WorkPackageRelationsService
} from '../../wp-relations/wp-relations.service';
import {WorkPackageTableRelationColumnsService} from '../state/wp-table-relation-columns.service';
import {RelationResource} from '../../api/api-v3/hal-resources/relation-resource.service';
export const relationCellTdClassName = 'wp-table--relation-cell-td';
export const relationCellIndicatorClassName = 'wp-table--relation-indicator';
export class RelationCellbuilder {
public states:States;
public wpRelations:WorkPackageRelationsService;
public wpTableRelationColumns:WorkPackageTableRelationColumnsService;
public wpDisplayField:WorkPackageDisplayFieldService;
constructor() {
$injectFields(this, 'states', 'wpRelations', 'wpTableRelationColumns');
}
public build(workPackage:WorkPackageResourceInterface, column:QueryColumn) {
const td = document.createElement('td');
td.classList.add(tdClassName, relationCellTdClassName, column.id);
td.dataset['columnId'] = column.id;
// Get current expansion and value state
const expanded = this.wpTableRelationColumns.getExpandFor(workPackage.id) === column.id;
const relationState = this.wpRelations.relationState(workPackage.id).value;
const relations = this.wpTableRelationColumns.relationsForColumn(workPackage, relationState, column);
const indicator = this.renderIndicator();
const badge = this.renderBadge(relations);
if (expanded) {
td.classList.add('-expanded');
}
if (relations.length > 0) {
td.appendChild(badge);
td.appendChild(indicator);
}
return td;
}
private renderIndicator() {
const indicator = document.createElement('span')
indicator.classList.add(relationCellIndicatorClassName);
indicator.setAttribute('aria-hidden', 'true');
indicator.setAttribute('tabindex', '0');
return indicator;
}
private renderBadge(relations:RelationResource[]) {
const badge = document.createElement('span');
badge.classList.add('wp-table--relation-count');
badge.textContent = '' + relations.length;
badge.classList.add('badge', '-border-only');
return badge;
}
}