Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove duplicate calculation of colspan

Oliver Günthera64cbdf71d9c
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-render-pass.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-render-pass.ts
index 3982ee18a28..3fcfb68c679 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-render-pass.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-render-pass.ts
@@ -8,8 +8,14 @@ import { WorkPackageTable } from '../../../wp-fast-table';
import { WorkPackageTableRow } from '../../../wp-table.interfaces';
import { SingleRowBuilder } from '../../rows/single-row-builder';
import { PlainRenderPass } from '../plain/plain-render-pass';
-import { groupClassNameFor, GroupHeaderBuilder } from './group-header-builder';
-import { groupByProperty, groupedRowClassName } from './grouped-rows-helpers';
+import {
+ groupClassNameFor,
+ GroupHeaderBuilder,
+} from './group-header-builder';
+import {
+ groupByProperty,
+ groupedRowClassName,
+} from './grouped-rows-helpers';
export const groupRowClass = '-group-row';
@@ -20,7 +26,8 @@ export class GroupedRenderPass extends PlainRenderPass {
public workPackageTable:WorkPackageTable,
public groups:GroupObject[],
public headerBuilder:GroupHeaderBuilder,
- public colspan:number) {
+ public colspan:number,
+ ) {
super(injector, workPackageTable, new SingleRowBuilder(injector, workPackageTable));
}
@@ -28,7 +35,7 @@ export class GroupedRenderPass extends PlainRenderPass {
* Rebuild the entire grouped tbody from the given table
*/
protected doRender() {
- let currentGroup:GroupObject | null = null;
+ let currentGroup:GroupObject|null = null;
const { length } = this.workPackageTable.originalRows;
this.workPackageTable.originalRows.forEach((wpId:string, index:number) => {
const row = this.workPackageTable.originalRowIndex[wpId];
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-rows-builder.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-rows-builder.ts
index 0ced6a148a3..2a36ad1b6f5 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-rows-builder.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/modes/grouped/grouped-rows-builder.ts
@@ -51,11 +51,6 @@ export class GroupedRowsBuilder extends RowsBuilder {
return this.querySpace.collapsedGroups.value || {};
}
- public get colspan() {
- // Columns + manual sorting column + settings column
- return this.wpTableColumns.columnCount + 2;
- }
-
public buildRows() {
const builder = new GroupHeaderBuilder(this.injector);
return new GroupedRenderPass(
@@ -63,7 +58,7 @@ export class GroupedRowsBuilder extends RowsBuilder {
this.workPackageTable,
this.getGroupData(),
builder,
- this.colspan,
+ this.workPackageTable.colspan,
).render();
}
@@ -82,7 +77,7 @@ export class GroupedRowsBuilder extends RowsBuilder {
const group = groups[groupIndex];
// Refresh the group header
- const newRow = builder.buildGroupRow(group, this.colspan);
+ const newRow = builder.buildGroupRow(group, this.workPackageTable.colspan);
if (oldRow.parentNode) {
oldRow.parentNode.replaceChild(newRow, oldRow);
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/wp-fast-table.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/wp-fast-table.ts
index ebb11f8ef69..f0015bd1e54 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/wp-fast-table.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/wp-fast-table.ts
@@ -30,6 +30,8 @@ export class WorkPackageTable {
public originalRows:string[] = [];
+ public colspan:number;
+
public originalRowIndex:{ [id:string]:WorkPackageTableRow } = {};
private hierarchyRowsBuilder = new HierarchyRowsBuilder(this.injector, this);
@@ -49,13 +51,15 @@ export class WorkPackageTable {
// and their contexts
public editing:WorkPackageTableEditingContext = new WorkPackageTableEditingContext(this, this.injector);
- constructor(public readonly injector:Injector,
+ constructor(
+ public readonly injector:Injector,
public tableAndTimelineContainer:HTMLElement,
public scrollContainer:HTMLElement,
public tbody:HTMLElement,
public timelineBody:HTMLElement,
public timelineController:WorkPackageTimelineTableController,
- public configuration:WorkPackageTableConfiguration) {
+ public configuration:WorkPackageTableConfiguration,
+ ) {
}
public get renderedRows() {
diff --git a/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts b/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts
index e32bf11e112..44037019a3c 100644
--- a/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-inline-create/wp-inline-create.component.ts
@@ -68,11 +68,13 @@ import { onClickOrEnter } from '../wp-fast-table/handlers/click-or-enter-handler
templateUrl: './wp-inline-create.component.html',
})
export class WorkPackageInlineCreateComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {
- @Input('wp-inline-create--table') table:WorkPackageTable;
+ @Input() colspan:number;
- @Input('wp-inline-create--project-identifier') projectIdentifier:string;
+ @Input() table:WorkPackageTable;
- @Output('wp-inline-create--showing') showing = new EventEmitter<boolean>();
+ @Input() projectIdentifier:string;
+
+ @Output() showing = new EventEmitter<boolean>();
// inner state
public canAdd = false;
@@ -314,8 +316,4 @@ export class WorkPackageInlineCreateComponent extends UntilDestroyedMixin implem
this.mode = 'create';
this.cdRef.detectChanges();
}
-
- public get colspan():number {
- return this.wpTableColumns.columnCount + 1;
- }
}
diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html
index 27b3171dd28..8a717a72df0 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.html
@@ -2,11 +2,11 @@
<div class="work-packages-tabletimeline--table-side work-package-table--container __hidden_overflow_container">
<table
class="keyboard-accessible-list generic-table work-package-table"
- [class.op-table-timestamps]="wpTableBaseline.isActive()"
+ [class.op-table-baseline]="baselineEnabled"
>
<colgroup>
<col *ngIf="configuration.dragAndDropEnabled">
- <col *ngIf="wpTableBaseline.isActive()">
+ <col *ngIf="baselineEnabled">
<!-- Generate col elements dynamically(!) for each requested column plus one for the action menu's column. -->
<col opHighlightCol *ngFor="let column of [].constructor(columns.length)">
<col opHighlightCol *ngIf="configuration.columnMenuEnabled">
@@ -24,7 +24,7 @@
<op-icon *ngIf="manualSortEnabled" icon-classes="icon-sort-by"></op-icon>
</div>
</th>
- <th *ngIf="wpTableBaseline.isActive()" class="wp-table--baseline-th -short hide-when-print">
+ <th *ngIf="baselineEnabled" class="wp-table--baseline-th -short hide-when-print">
<div class="generic-table--empty-header">
<op-icon icon-classes="icon-baseline"></op-icon>
</div>
@@ -52,7 +52,7 @@
</thead>
<tbody class="work-package--empty-tbody" *ngIf="!isEmbedded && query && results.count === 0">
<tr id="empty-row-notification">
- <td [attr.colspan]="columns.length + 2">
+ <td [attr.colspan]="numTableColumns">
<span>
<op-icon icon-classes="icon-info1 icon-context"></op-icon>
<span>
@@ -76,9 +76,10 @@
<tbody *ngIf="tableElement && configuration.inlineCreateEnabled"
wpInlineCreate
- [wp-inline-create--table]="workPackageTable"
- [wp-inline-create--project-identifier]="projectIdentifier"
- (wp-inline-create--showing)="inlineCreateVisible = $event"
+ [colspan]="numTableColumns"
+ [table]="workPackageTable"
+ [projectIdentifier]="projectIdentifier"
+ (showing)="inlineCreateVisible = $event"
>
</tbody>
</table>
diff --git a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts
index 04448104168..250f6f6e468 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/wp-table.component.ts
@@ -30,16 +30,21 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
- ElementRef, EventEmitter,
+ ElementRef,
+ EventEmitter,
Injector,
Input,
NgZone,
- OnInit, Output,
+ OnInit,
+ Output,
ViewEncapsulation,
} from '@angular/core';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { TableEventComponent, TableHandlerRegistry } from 'core-app/features/work-packages/components/wp-fast-table/handlers/table-handler-registry';
+import {
+ TableEventComponent,
+ TableHandlerRegistry,
+} from 'core-app/features/work-packages/components/wp-fast-table/handlers/table-handler-registry';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { combineLatest } from 'rxjs';
import { QueryColumn } from 'core-app/features/work-packages/components/wp-query/query-column';
@@ -71,8 +76,8 @@ export interface WorkPackageFocusContext {
}
@Component({
- templateUrl: './wp-table.directive.html',
- styleUrls: ['./wp-table.styles.sass'],
+ templateUrl: './wp-table.component.html',
+ styleUrls: ['./wp-table.component.sass'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'wp-table',
@@ -124,6 +129,8 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements O
public manualSortEnabled:boolean;
+ public baselineEnabled:boolean;
+
public limitedResults = false;
// We need to sync certain height difference to the timeline
@@ -180,6 +187,7 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements O
this.wpTableTimeline.live$(),
this.wpTableSortBy.live$(),
this.wpTableSums.live$(),
+ this.wpTableBaseline.live$(),
]);
statesCombined.pipe(
@@ -192,18 +200,32 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements O
this.groupBy = groupBy;
this.columns = columns;
- // Total columns = all available columns + id + checkbox
- this.numTableColumns = this.columns.length + 2;
-
- if (this.scrollSyncUpdate && this.timelineVisible !== timelines.visible) {
- this.scrollSyncUpdate(timelines.visible);
- }
this.timelineVisible = timelines.visible;
this.manualSortEnabled = this.wpTableSortBy.isManualSortingMode;
+ this.baselineEnabled = this.wpTableBaseline.isActive();
this.limitedResults = this.manualSortEnabled && results.total > results.count;
+ // Total columns = all available columns + id + context menu
+ this.numTableColumns = this.columns.length + 2;
+
+ if (this.manualSortEnabled) {
+ this.numTableColumns += 1;
+ }
+
+ if (this.baselineEnabled) {
+ this.numTableColumns += 1;
+ }
+
+ if (this.workPackageTable) {
+ this.workPackageTable.colspan = this.numTableColumns;
+ }
+
+ if (this.scrollSyncUpdate && this.timelineVisible !== timelines.visible) {
+ this.scrollSyncUpdate(timelines.visible);
+ }
+
this.cdRef.detectChanges();
});
@@ -233,6 +255,8 @@ export class WorkPackagesTableComponent extends UntilDestroyedMixin implements O
// Table configuration
this.configuration,
);
+ this.workPackageTable.colspan = this.numTableColumns;
+
this.tbody = tbody;
controller.workPackageTable = this.workPackageTable;
new TableHandlerRegistry(this.injector).attachTo(this);