aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard/sorting.ts
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-04-06 15:15:47 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-04-06 15:15:47 -0400
commit9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6 (patch)
tree8af111a538a8d6361e1cf07467b9c31568284921 /ufund-ui/src/app/components/cupboard/sorting.ts
parent1ac878b4aaa19ab889c7a98b7dab6acd57c778b3 (diff)
parent04cb51b2e7891785c956c5faa73fb88cc04e82e0 (diff)
downloadJellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.tar.gz
JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.tar.bz2
JellySolutions-9f14b3787a8cfc49fd168b1242adcc6d5fa8bfd6.zip
Merge branch 'main' into light-mode
# Conflicts: # ufund-ui/src/app/app.component.html # ufund-ui/src/app/components/funding-basket/funding-basket.component.html # ufund-ui/src/app/components/need-list/need-list.component.html # ufund-ui/src/app/components/need-page/need-page.component.css
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/sorting.ts')
-rw-r--r--ufund-ui/src/app/components/cupboard/sorting.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/ufund-ui/src/app/components/cupboard/sorting.ts b/ufund-ui/src/app/components/cupboard/sorting.ts
new file mode 100644
index 0000000..5c37019
--- /dev/null
+++ b/ufund-ui/src/app/components/cupboard/sorting.ts
@@ -0,0 +1,69 @@
+import {Need} from '../../models/Need';
+
+interface sortAlgo {
+ (a: Need, b: Need): number;
+}
+
+// sort functions
+const sortByName: sortAlgo = (a: Need, b: Need): number => {
+ if(a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByGoal: sortAlgo = (a: Need, b: Need): number => {
+ if(a.maxGoal == b.maxGoal) {
+ return sortByName(a,b);
+ }
+ else if(a.maxGoal > b.maxGoal) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByCompletion: sortAlgo = (a: Need, b: Need): number => {
+ if(a.current == b.current) {
+ return sortByGoal(a,b);
+ }
+ else if(a.current > b.current) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByPriority: sortAlgo = (a: Need, b: Need): number => {
+ if(a.urgent == b.urgent) {
+ return sortByGoal(a,b);
+ }
+ else if(a.urgent && !b.urgent) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByLocation: sortAlgo = (a: Need, b: Need): number => {
+ if(a.location.toLocaleLowerCase() < b.location.toLocaleLowerCase()) {
+ return -1;
+ }
+ return 1;
+}
+
+const sortByType: sortAlgo = (a:Need, b:Need): number => {
+ if(a.type == b.type) {
+ return sortByName(a,b);
+ }
+ else if(a.type > b.type) {
+ return -1;
+ }
+ return 1;
+}
+
+export const SortingAlgoArrays: {[key: string]: { func: sortAlgo, display: [string, string]}} = {
+ sortByPriority: { func: sortByPriority, display: ["Highest Priority", "Lowest Priority" ] },
+ sortByName: { func: sortByName, display: ["Name (A to Z)", "Name (Z to A)" ] },
+ sortByLocation: { func: sortByLocation, display: ["Location (A to Z)", "Location (Z to A)" ] },
+ sortByCompletion: { func: sortByCompletion, display: ["Most Completed", "Least Completed" ] },
+ sortByGoal: { func: sortByGoal, display: ["Largest Maximum Goal", "Smallest Maximum Goal" ] },
+ sortByType: { func: sortByType, display: ["Type (Physical first)", "Type (Monetary first)" ] },
+};