From 0652eb445728806d7fd6a50021a763051503ab36 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 3 Apr 2025 14:55:55 -0400 Subject: get checkout abstraction kinda working --- ufund-ui/src/app/components/cupboard/sorting.ts | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ufund-ui/src/app/components/cupboard/sorting.ts (limited to 'ufund-ui/src/app/components/cupboard/sorting.ts') 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..a512f22 --- /dev/null +++ b/ufund-ui/src/app/components/cupboard/sorting.ts @@ -0,0 +1,58 @@ +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; +} + +export const SortingAlgoArrays = { + 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" ] }, +}; -- cgit v1.2.3 From ad651c44ce2515d497c8e5214147c69126e25903 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 3 Apr 2025 19:48:54 -0400 Subject: abstraction working with search and sort --- ufund-ui/src/app/components/cupboard/sorting.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/sorting.ts') diff --git a/ufund-ui/src/app/components/cupboard/sorting.ts b/ufund-ui/src/app/components/cupboard/sorting.ts index a512f22..7cb3f39 100644 --- a/ufund-ui/src/app/components/cupboard/sorting.ts +++ b/ufund-ui/src/app/components/cupboard/sorting.ts @@ -49,10 +49,10 @@ const sortByLocation: sortAlgo = (a: Need, b: Need): number => { return 1; } -export const SortingAlgoArrays = { - 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" ] }, +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" ] }, }; -- cgit v1.2.3 From 43b036dc8ac03100787ec691a4f4ebe3670f861f Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 3 Apr 2025 23:22:16 -0400 Subject: code cleanup --- ufund-ui/src/app/components/cupboard/sorting.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/sorting.ts') diff --git a/ufund-ui/src/app/components/cupboard/sorting.ts b/ufund-ui/src/app/components/cupboard/sorting.ts index 7cb3f39..73a5ba9 100644 --- a/ufund-ui/src/app/components/cupboard/sorting.ts +++ b/ufund-ui/src/app/components/cupboard/sorting.ts @@ -50,9 +50,9 @@ const sortByLocation: sortAlgo = (a: Need, b: Need): number => { } 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" ] }, + 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" ] }, }; -- cgit v1.2.3 From 1dcb3ca5345609fa03e73f58693327cee7ab7cf9 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 4 Apr 2025 23:25:54 -0400 Subject: Add sort by type --- ufund-ui/src/app/components/cupboard/sorting.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/sorting.ts') diff --git a/ufund-ui/src/app/components/cupboard/sorting.ts b/ufund-ui/src/app/components/cupboard/sorting.ts index 73a5ba9..5c37019 100644 --- a/ufund-ui/src/app/components/cupboard/sorting.ts +++ b/ufund-ui/src/app/components/cupboard/sorting.ts @@ -49,10 +49,21 @@ const sortByLocation: sortAlgo = (a: Need, b: Need): number => { 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" ] }, + 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)" ] }, }; -- cgit v1.2.3