kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
201 lines
7.2 KiB
201 lines
7.2 KiB
8 years ago
|
import {WorkPackageTable} from "../../../wp-fast-table";
|
||
|
import {WorkPackageTableRow} from "../../../wp-table.interfaces";
|
||
|
import {WorkPackageResourceInterface} from "../../../../api/api-v3/hal-resources/work-package-resource.service";
|
||
|
import {WorkPackageTableHierarchiesService} from "../../../state/wp-table-hierarchy.service";
|
||
|
import {$injectFields} from "../../../../angular/angular-injector-bridge.functions";
|
||
|
import {Observable} from 'rxjs';
|
||
|
import {RowRefreshBuilder} from "../../rows/row-refresh-builder";
|
||
|
import {WorkPackageEditForm} from "../../../../wp-edit-form/work-package-edit-form";
|
||
|
import {collapsedGroupClass, hierarchyRootClass} from "../../../helpers/wp-table-hierarchy-helpers";
|
||
|
import {QueryColumn} from "../../../../api/api-v3/hal-resources/query-resource.service";
|
||
|
import {UiStateLinkBuilder} from "../../ui-state-link-builder";
|
||
8 years ago
|
|
||
|
export const indicatorCollapsedClass = '-hierarchy-collapsed';
|
||
8 years ago
|
export const hierarchyCellClassName = 'wp-table--hierarchy-span';
|
||
8 years ago
|
|
||
8 years ago
|
export class SingleHierarchyRowBuilder extends RowRefreshBuilder {
|
||
|
// Injected
|
||
8 years ago
|
public wpTableHierarchies:WorkPackageTableHierarchiesService;
|
||
8 years ago
|
|
||
8 years ago
|
public uiStateBuilder = new UiStateLinkBuilder();
|
||
8 years ago
|
public text:{
|
||
|
leaf:(level:number) => string;
|
||
|
expanded:(level:number) => string;
|
||
|
collapsed:(level:number) => string;
|
||
|
};
|
||
8 years ago
|
|
||
8 years ago
|
constructor(protected stopExisting$: Observable<any>, protected workPackageTable: WorkPackageTable) {
|
||
|
super(stopExisting$, workPackageTable);
|
||
|
$injectFields(this, 'wpTableHierarchies');
|
||
8 years ago
|
|
||
|
this.text = {
|
||
8 years ago
|
leaf: (level:number) => this.I18n.t('js.work_packages.hierarchy.leaf', { level: level }),
|
||
|
expanded: (level:number) => this.I18n.t('js.work_packages.hierarchy.children_expanded', { level: level }),
|
||
|
collapsed: (level:number) => this.I18n.t('js.work_packages.hierarchy.children_collapsed', { level: level }),
|
||
8 years ago
|
};
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
/**
|
||
|
* Refresh a single row after structural changes.
|
||
|
* Remembers and re-adds the hierarchy indicator if neccessary.
|
||
|
*/
|
||
8 years ago
|
public refreshRow(row: WorkPackageTableRow, editForm: WorkPackageEditForm | undefined): HTMLElement | null {
|
||
8 years ago
|
// Remove any old hierarchy
|
||
8 years ago
|
const newRow = super.refreshRow(row, editForm);
|
||
8 years ago
|
|
||
|
if (newRow) {
|
||
|
jQuery(newRow).find(`.wp-table--hierarchy-span`).remove();
|
||
|
this.appendHierarchyIndicator(row.object, newRow);
|
||
|
}
|
||
|
|
||
|
return newRow;
|
||
|
}
|
||
|
|
||
8 years ago
|
/**
|
||
|
* Build the columns on the given empty row
|
||
|
*/
|
||
|
public buildEmpty(workPackage:WorkPackageResourceInterface) {
|
||
|
const element = super.buildEmpty(workPackage);
|
||
8 years ago
|
const state = this.wpTableHierarchies.currentState;
|
||
8 years ago
|
|
||
8 years ago
|
workPackage.ancestors.forEach((ancestor:WorkPackageResourceInterface) => {
|
||
8 years ago
|
element.classList.add(`__hierarchy-group-${ancestor.id}`);
|
||
|
|
||
|
if (state.collapsed[ancestor.id]) {
|
||
|
element.classList.add(collapsedGroupClass(ancestor.id));
|
||
|
}
|
||
|
});
|
||
8 years ago
|
|
||
8 years ago
|
element.classList.add(`__hierarchy-root-${workPackage.id}`);
|
||
|
this.appendHierarchyIndicator(workPackage, element);
|
||
8 years ago
|
return element;
|
||
|
}
|
||
|
|
||
8 years ago
|
/**
|
||
|
* Append an additional ancestor row that is not yet loaded
|
||
|
*/
|
||
|
public buildAncestorRow(
|
||
|
table:WorkPackageTable,
|
||
|
ancestor:WorkPackageResourceInterface,
|
||
|
ancestorGroups:string[],
|
||
|
index:number):HTMLElement {
|
||
|
|
||
|
const loadedRow = table.rowIndex[ancestor.id];
|
||
|
|
||
|
if (loadedRow) {
|
||
|
const tr = this.buildEmpty(loadedRow.object);
|
||
|
tr.classList.add('wp-table--hierarchy-aditional-row');
|
||
|
return tr;
|
||
|
}
|
||
|
|
||
|
const tr = this.createEmptyRow(ancestor);
|
||
|
const columns = this.wpTableColumns.getColumns();
|
||
|
|
||
|
tr.classList.add(`wp-table--hierarchy-aditional-row`, hierarchyRootClass(ancestor.id), ...ancestorGroups);
|
||
|
|
||
|
// Set available information for ID and subject column
|
||
|
// and print hierarchy indicator at subject field.
|
||
|
columns.forEach((column:QueryColumn) => {
|
||
|
const td = document.createElement('td');
|
||
|
|
||
|
if (column.id === 'subject') {
|
||
|
const textNode = document.createTextNode(ancestor.name);
|
||
|
td.appendChild(this.buildHierarchyIndicator(ancestor, index));
|
||
|
td.appendChild(textNode);
|
||
|
}
|
||
|
|
||
|
if (column.id === 'id') {
|
||
|
const link = this.uiStateBuilder.linkToShow(
|
||
|
ancestor.id,
|
||
|
ancestor.subject,
|
||
|
ancestor.id
|
||
|
);
|
||
|
|
||
|
td.appendChild(link);
|
||
|
td.classList.add('hierarchy-row--id-cell');
|
||
|
}
|
||
|
|
||
|
tr.appendChild(td);
|
||
|
});
|
||
|
|
||
|
// Append details icon
|
||
|
const td = document.createElement('td');
|
||
|
tr.appendChild(td);
|
||
|
|
||
|
return tr;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Append to the row of hierarchy level <level> a hierarchy indicator.
|
||
|
* @param workPackage
|
||
|
* @param row
|
||
|
* @param level
|
||
|
*/
|
||
8 years ago
|
private appendHierarchyIndicator(workPackage:WorkPackageResourceInterface, row:HTMLElement, level?:number):void {
|
||
8 years ago
|
const jRow = jQuery(row);
|
||
|
const hierarchyElement = this.buildHierarchyIndicator(workPackage, level);
|
||
8 years ago
|
|
||
8 years ago
|
jRow.find('td.subject')
|
||
8 years ago
|
.addClass('-with-hierarchy')
|
||
|
.prepend(hierarchyElement);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
/**
|
||
|
* Build the hierarchy indicator at the given indentation level.
|
||
|
*/
|
||
8 years ago
|
private buildHierarchyIndicator(workPackage:WorkPackageResourceInterface, index:number|null = null):HTMLElement {
|
||
8 years ago
|
const level = index === null ? workPackage.ancestors.length : index;
|
||
|
const hierarchyIndicator = document.createElement('span');
|
||
|
const collapsed = this.wpTableHierarchies.collapsed(workPackage.id);
|
||
|
hierarchyIndicator.classList.add(hierarchyCellClassName);
|
||
|
hierarchyIndicator.style.width = 25 + (20 * level) + 'px';
|
||
|
|
||
|
if (workPackage.$loaded && !this.hasChildrenInTable(workPackage)) {
|
||
|
hierarchyIndicator.innerHTML = `
|
||
8 years ago
|
<span tabindex="0" class="wp-table--leaf-indicator">
|
||
|
<span class="hidden-for-sighted">${this.text.leaf(level)}</span>
|
||
|
</span>
|
||
8 years ago
|
`;
|
||
8 years ago
|
} else {
|
||
|
const className = collapsed ? indicatorCollapsedClass : '';
|
||
|
hierarchyIndicator.innerHTML = `
|
||
8 years ago
|
<a href tabindex="0" role="button" class="wp-table--hierarchy-indicator ${className}">
|
||
8 years ago
|
<span class="wp-table--hierarchy-indicator-icon" aria-hidden="true"></span>
|
||
8 years ago
|
<span class="wp-table--hierarchy-indicator-expanded hidden-for-sighted">${this.text.expanded(level)}</span>
|
||
|
<span class="wp-table--hierarchy-indicator-collapsed hidden-for-sighted">${this.text.collapsed(level)}</span>
|
||
8 years ago
|
</a>
|
||
|
`;
|
||
8 years ago
|
}
|
||
|
return hierarchyIndicator;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns whether any of the children of this work package
|
||
|
* are visible in the table results.
|
||
|
*/
|
||
|
private hasChildrenInTable(workPackage:WorkPackageResourceInterface) {
|
||
|
if (workPackage.isLeaf) {
|
||
|
return false; // Work Package has no children at all
|
||
|
}
|
||
|
|
||
|
const rows = this.workPackageTable.rows;
|
||
|
const total = rows.length;
|
||
|
if (rows[total - 1] === workPackage.id) {
|
||
|
return false; // Last element, can have no children
|
||
|
}
|
||
|
|
||
|
// If immediately following child has element
|
||
|
const row = this.workPackageTable.rowIndex[workPackage.id];
|
||
|
const nextIndex = row.position + 1;
|
||
|
|
||
|
if (nextIndex < total) {
|
||
|
const nextId = rows[nextIndex].toString();
|
||
|
return !!_.find(workPackage.children, (child:WorkPackageResourceInterface) => child.idFromLink === nextId);
|
||
|
}
|
||
|
|
||
|
return false;
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
SingleHierarchyRowBuilder.$inject = ['states', 'I18n'];
|