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/handlers/state/hierarchy-transformer.ts

53 lines
2.0 KiB

import {injectorBridge} from "../../../angular/angular-injector-bridge.functions";
import {States} from "../../../states.service";
import {collapsedGroupClass, hierarchyGroupClass, hierarchyRootClass} from "../../helpers/wp-table-hierarchy-helpers";
import {WorkPackageTable} from "../../wp-fast-table";
import {WorkPackageTableHierarchiesService} from './../../state/wp-table-hierarchy.service';
import {WorkPackageTableHierarchies} from "../../wp-table-hierarchies";
import {indicatorCollapsedClass} from "../../builders/modes/hierarchy/single-hierarchy-row-builder";
export class HierarchyTransformer {
public wpTableHierarchies:WorkPackageTableHierarchiesService;
public states:States;
constructor(table:WorkPackageTable) {
injectorBridge(this);
let enabled = false;
this.wpTableHierarchies
.observeUntil(this.states.table.stopAllSubscriptions)
.subscribe((state: WorkPackageTableHierarchies) => {
if (enabled !== state.isEnabled) {
table.refreshBody();
table.postRender();
} else if (enabled) {
// No change in hierarchy mode
// Refresh groups
this.renderHierarchyState(state);
}
enabled = state.isEnabled;
});
}
/**
* Update all currently visible rows to match the selection state.
*/
private renderHierarchyState(state:WorkPackageTableHierarchies) {
// Show all hierarchies
jQuery('[class^="__hierarchy-group-"]').removeClass((i:number, classNames:string):string => {
return (classNames.match(/__collapsed-group-\d+/g) || []).join(' ');
});
// Hide all collapsed hierarchies
_.each(state.collapsed, (isCollapsed:boolean, wpId:string) => {
// Hide/Show the descendants.
jQuery(`.${hierarchyGroupClass(wpId)}`).toggleClass(collapsedGroupClass(wpId), isCollapsed);
// Toggle the root style
jQuery(`.${hierarchyRootClass(wpId)} .wp-table--hierarchy-indicator`).toggleClass(indicatorCollapsedClass, isCollapsed);
});
}
}
HierarchyTransformer.$inject = ['wpTableHierarchies', 'states'];