• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NationalBankBelgium / stark / 9205123826

23 May 2024 08:55AM CUT coverage: 88.822%. Remained the same
9205123826

Pull #3800

github

web-flow
Merge 5208cd19f into 59c39b170
Pull Request #3800: chore(deps): bump zone.js from 0.11.8 to 0.14.6 in /showcase

1260 of 1528 branches covered (82.46%)

Branch coverage included in aggregate %.

3770 of 4135 relevant lines covered (91.17%)

193.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.5
/packages/stark-ui/src/modules/table/components/dialogs/multisort.component.ts
1
import { ChangeDetectionStrategy, Component, ElementRef, Inject, OnInit, Renderer2, ViewEncapsulation } from "@angular/core";
2
import { MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA, MatLegacyDialogRef as MatDialogRef } from "@angular/material/legacy-dialog";
3
import { StarkTableColumnComponent } from "../column.component";
4
import { AbstractStarkUiComponent } from "@nationalbankbelgium/stark-ui/src/internal-common";
5
import { StarkTableColumnSortingDirection } from "../../entities";
6

7
/**
8
 * Content of the data to be passed to the StarkTableMultisortDialogComponent
9
 */
10
export interface StarkTableMultisortDialogData {
11
        /**
12
         * Sortable StarkTable columns whose configuration can be defined in this dialog component
13
         */
14
        columns: StarkTableColumnComponent[];
15
}
16

17
/**
18
 * Rule object to be configured in the StarkTableMultisortDialogComponent
19
 */
20
export interface StarkSortingRule {
21
        /**
22
         * Sortable StarkTable column
23
         */
24
        column: StarkTableColumnComponent;
25
        /**
26
         * Sorting direction: "ascending" or "descending"
27
         */
28
        sortDirection: StarkTableColumnSortingDirection;
29
        /**
30
         * Priority of this rule. Priority is a number between 0 and 100 where 0 represents the higher priority
31
         */
32
        sortPriority: number;
33
}
34

35
/**
36
 * Component to display the multi column sorting configuration
37
 */
38
@Component({
39
        selector: "stark-table-dialog-multisort",
40
        templateUrl: "./multisort.component.html",
41
        encapsulation: ViewEncapsulation.None,
42
        changeDetection: ChangeDetectionStrategy.OnPush,
43
        // We need to use host instead of @HostBinding: https://github.com/NationalBankBelgium/stark/issues/664
44
        host: {
45
                class: "stark-table-dialog-multisort"
46
        }
47
})
48
export class StarkTableMultisortDialogComponent extends AbstractStarkUiComponent implements OnInit {
1✔
49
        /**
50
         * Array of sorting rules currently applied
51
         */
52
        public rules: StarkSortingRule[] = [];
×
53
        /**
54
         * The priority to be set to a new rule when added
55
         */
56
        public currentPriority = 0;
×
57

58
        /**
59
         * Whether the Add button is disabled
60
         */
61
        public isAddDisabled = false;
×
62

63
        /**
64
         * Class constructor
65
         * @param dialogRef - Reference to this dialog opened via the MatDialog service
66
         * @param data - The data to be passed to this dialog component
67
         * @param renderer - Angular `Renderer2` wrapper for DOM manipulations.
68
         * @param elementRef - Reference to the DOM element where this component is attached to.
69
         */
70
        public constructor(
71
                public dialogRef: MatDialogRef<StarkTableMultisortDialogComponent>,
×
72
                @Inject(MAT_DIALOG_DATA) public data: StarkTableMultisortDialogData,
×
73
                renderer: Renderer2,
74
                elementRef: ElementRef
75
        ) {
76
                super(renderer, elementRef);
×
77
        }
78

79
        /**
80
         * Component lifecycle hook
81
         */
82
        public override ngOnInit(): void {
83
                super.ngOnInit();
×
84
                this.data.columns.sort((a: StarkTableColumnComponent, b: StarkTableColumnComponent) => a.sortPriority - b.sortPriority);
×
85

86
                for (const column of this.data.columns) {
×
87
                        if (column.sortable) {
×
88
                                if (column.sortDirection) {
×
89
                                        this.currentPriority++;
×
90
                                }
91
                                this.rules.push({
×
92
                                        column: column,
93
                                        sortDirection: column.sortDirection,
94
                                        sortPriority: column.sortDirection ? this.currentPriority : 100
×
95
                                });
96
                        }
97
                }
98
                this.sortRules();
×
99
        }
100

101
        /**
102
         * Called when Add button is clicked.
103
         * Sets the sorting direction to "asc" to a rule that doesn't have sorting direction yet so it is displayed in the dialog
104
         */
105
        public onAdd(): void {
106
                for (const rule of this.rules) {
×
107
                        if (!rule.sortDirection) {
×
108
                                rule.sortDirection = "asc";
×
109
                                this.currentPriority++;
×
110
                                rule.sortPriority = this.currentPriority;
×
111
                                break;
×
112
                        }
113
                }
114
                this.sortRules();
×
115
        }
116

117
        /**
118
         * Called when Delete button is clicked.
119
         * Deletes the given column sorting rule.
120
         * @param rule - The column sorting rule to be deleted
121
         */
122
        public onDelete(rule: StarkSortingRule): void {
123
                rule.sortDirection = "";
×
124
                rule.sortPriority = 100;
×
125
                this.sortRules();
×
126
        }
127

128
        /**
129
         * Called when Cancel button is clicked.
130
         * Closes this dialog discarding any changes done to the original sorting rules.
131
         */
132
        public onCancel(): void {
133
                this.dialogRef.close(false);
×
134
        }
135

136
        /**
137
         * Called when the sorting rule changes.
138
         * @param oldRule - New state of the sorting rule
139
         * @param newRule - Previous state of the sorting rule
140
         */
141
        public onColumnChange(oldRule: StarkSortingRule, newRule: StarkSortingRule): void {
142
                newRule.sortDirection = oldRule.sortDirection;
×
143
                newRule.sortPriority = oldRule.sortPriority;
×
144
                oldRule.sortDirection = "";
×
145
                oldRule.sortPriority = 100;
×
146
                this.sortRules();
×
147
        }
148

149
        /**
150
         * Called when Save button is clicked.
151
         * Close the dialog returning the updated rules defined back to the dialog opener.
152
         */
153
        public onSave(): void {
154
                this.dialogRef.close(this.rules);
×
155
        }
156

157
        /**
158
         * Sort all sorting rules by priority
159
         */
160
        public sortRules(): void {
161
                this.rules.sort((a: StarkSortingRule, b: StarkSortingRule) => a.sortPriority - b.sortPriority);
×
162
                this.isAddDisabled = this.rules.filter((rule: StarkSortingRule) => !!rule.sortDirection).length === this.rules.length;
×
163
        }
164

165
        /**
166
         * @ignore
167
         */
168
        public trackRuleFn(_index: number, item: StarkSortingRule): string {
169
                return item.column.name;
×
170
        }
171
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc