-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(history): add sorting in tables
- Loading branch information
Showing
61 changed files
with
455 additions
and
390 deletions.
There are no files selected for viewing
15 changes: 12 additions & 3 deletions
15
packages/frontend/src/_common/model/usager/HISTORY_ACTIONS.const.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
export const HISTORY_ACTIONS = { | ||
EDIT: "Modification", | ||
DELETE: "Suppression", | ||
CREATION: "Création", | ||
EDIT: { | ||
class: "orange-status", | ||
label: "Modification", | ||
}, | ||
DELETE: { | ||
class: "red-status", | ||
label: "Suppression", | ||
}, | ||
CREATION: { | ||
class: "green-status", | ||
label: "Création", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...-head-sort/table-head-sort.component.html → ...-head-sort/table-head-sort.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ button { | |
padding: 0; | ||
width: 100%; | ||
text-align: left; | ||
font-weight: bold; | ||
color: var(--bs-primary); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...s/frontend/src/app/modules/shared/components/table-head-sort/table-head-sort.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Component, EventEmitter, Input, Output } from "@angular/core"; | ||
import { UsagersFilterCriteriaSortValues } from "../../../manage-usagers/components/usager-filter"; | ||
import { | ||
faArrowDown, | ||
faArrowUp, | ||
faSort, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { NgClass, NgIf } from "@angular/common"; | ||
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; | ||
|
||
@Component({ | ||
selector: "app-table-head-sort", | ||
templateUrl: "./table-head-sort.component.html", | ||
styleUrls: ["./table-head-sort.component.scss"], | ||
standalone: true, | ||
imports: [NgIf, NgClass, FontAwesomeModule], | ||
}) | ||
export class TableHeadSortComponent { | ||
public readonly faArrowDown = faArrowDown; | ||
public readonly faArrowUp = faArrowUp; | ||
public readonly faSort = faSort; | ||
|
||
@Input() public columnName: string; | ||
|
||
@Input() public sortValue: UsagersFilterCriteriaSortValues; | ||
@Output() public sortValueChange = | ||
new EventEmitter<UsagersFilterCriteriaSortValues>(); | ||
|
||
@Input() public sortKey: string; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@Input() public currentKey: any; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@Output() public currentKeyChange = new EventEmitter<any>(); | ||
|
||
public rotate() { | ||
const rotation: { | ||
[key in UsagersFilterCriteriaSortValues]: UsagersFilterCriteriaSortValues; | ||
} = { | ||
asc: "desc", | ||
desc: "asc", | ||
}; | ||
if (this.currentKey === this.sortKey) { | ||
this.sortValueChange.emit(rotation[this.sortValue]); | ||
} else { | ||
this.currentKeyChange.emit(this.sortKey); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// @index('./*.pipe.ts', f => `export * from '${f.path}'`) | ||
export * from "./format-big-number.pipe"; | ||
export * from "./nl2br.pipe"; | ||
export * from "./sort-array.pipe"; | ||
export * from "./usager-nom-complet.pipe"; |
36 changes: 36 additions & 0 deletions
36
packages/frontend/src/app/modules/shared/pipes/sort-array.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Pipe, PipeTransform } from "@angular/core"; | ||
|
||
@Pipe({ | ||
name: "sortArray", | ||
}) | ||
export class SortArrayPipe implements PipeTransform { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
transform(array: any[], sortKey: any, sortValue: "asc" | "desc"): any[] { | ||
if (!array || array.length <= 1) { | ||
return array; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return array.sort((a: any, b: any) => { | ||
const valA = a[sortKey]; | ||
const valB = b[sortKey]; | ||
|
||
if (valA === null) { | ||
return -1; | ||
} | ||
|
||
let comparison = 0; | ||
if (valA === valB) { | ||
return 0; | ||
} else if (typeof valA === "string") { | ||
comparison = valA.localeCompare(valB); | ||
} else if (typeof valA === "boolean") { | ||
comparison = valA === valB ? 0 : valA ? -1 : 1; | ||
} else if (valA instanceof Date) { | ||
comparison = valB instanceof Date ? valA.getTime() - valB.getTime() : 1; | ||
} | ||
|
||
return sortValue === "asc" ? comparison : -comparison; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.