forked from UWICompSociety/fst_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
693 additions
and
396 deletions.
There are no files selected for viewing
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,22 +1,162 @@ | ||
class Scholarship { | ||
//Attributes of the Class | ||
String name; | ||
String description; | ||
String details; | ||
String name, details, numAwards, tenure, value, eligible, criteria ,method , special, condition; | ||
|
||
//Constructor for the Scholarship Class | ||
Scholarship({this.name, this.description, this.details}); | ||
|
||
//Getter Methods for the attributes | ||
String get scholarshipName => name; | ||
String get scholarshipDescription => description; | ||
String get scholarshipDetails => details; | ||
|
||
//This method converts a json map into an Scholarship Object | ||
factory Scholarship.fromJson(Map<String, dynamic> parsedJSON) { | ||
return Scholarship( | ||
name: parsedJSON['name'], | ||
description: parsedJSON['description'], | ||
details: parsedJSON['details']); | ||
Scholarship({this.name, | ||
this.details, | ||
this.numAwards, | ||
this.value, | ||
this.tenure, | ||
this.eligible, | ||
this.criteria, | ||
this.method, | ||
this.special, | ||
this.condition | ||
}); | ||
|
||
//This constructor converts a json map into an Scholarship Object | ||
Scholarship.fromJson(Map<String, dynamic> parsedJson){ | ||
name = parsedJson['name']; | ||
details = parsedJson['additional_details']; | ||
numAwards = parsedJson['number_of_awards']; | ||
value = parsedJson['value']; | ||
tenure = parsedJson['max_tenure']; | ||
eligible = parsedJson['eligibility']; | ||
criteria = parsedJson['criteria']; | ||
method = parsedJson['method_of_selection']; | ||
special = parsedJson['special_requirements']; | ||
condition = parsedJson['condition']; | ||
} | ||
|
||
//TODO: documentation @palmer-matthew | ||
String buildListItem(String title, content, bool inList){ | ||
|
||
if(content == "" && inList){ | ||
return "\u2022 $title\n"; | ||
} | ||
|
||
return "- $title \n $content\n"; | ||
} | ||
|
||
String buildHeading(title, content){ | ||
List<String> secondary; | ||
String result = ""; | ||
try { | ||
if(content.contains(":")){ | ||
List<String> list = content.split(":"); | ||
if(list[1].contains(";") && list.length == 2){ | ||
secondary = list[1].split(";"); | ||
String slist = ""; | ||
for(String b in secondary){ | ||
if(b != ""){ | ||
slist += buildListItem(b, "", true); | ||
} | ||
} | ||
result += buildListItem(title, list[0]+":", false); | ||
result += slist; | ||
return result; | ||
}else if(list[1].contains(";") && list.length == 3){ | ||
secondary = list[1].split(";"); | ||
String slist = ""; | ||
result += buildListItem(title, "" , false); | ||
result += "\t" + buildListItem(list[0], "", true); | ||
for(String b in secondary){ | ||
if(b != ""){ | ||
slist += "\t\t" + buildListItem(b, "", true); | ||
} | ||
} | ||
result += slist; | ||
result += "\t" + buildListItem(list[2], "", true); | ||
return result; | ||
}else if(list.length == 2 && !list[1].contains(";")){ | ||
result += buildListItem(title, list[0]+":", false); | ||
result += "\t" + buildListItem(list[1], "", true); | ||
return result; | ||
}else { | ||
return buildListItem(title, list[1], false); | ||
} | ||
}else if(content.contains(";")){ | ||
List<String> list = content.split(";"); | ||
String slist = ""; | ||
for(String b in list){ | ||
if(b != ""){ | ||
slist += "\t" + buildListItem(b, "", true); | ||
} | ||
} | ||
result += buildListItem(title, "", false); | ||
result += slist; | ||
return result; | ||
}else{ | ||
return buildListItem(title, content, false); | ||
} | ||
} on Exception catch (e) { | ||
print(e); | ||
return "Something went wrong"; | ||
} | ||
|
||
} | ||
|
||
String buildDescriptionContent(){ | ||
String result = ""; | ||
try{ | ||
|
||
if(numAwards != ""){ | ||
result += buildHeading('Number of Awards', numAwards) + "_____________________\n\n"; | ||
} | ||
|
||
if(value != ""){ | ||
result += buildHeading('Value', value) + "_____________________\n\n"; | ||
} | ||
|
||
if(tenure != ""){ | ||
result += buildHeading('Maximum Tenure', tenure) + "_____________________\n\n"; | ||
} | ||
|
||
if(eligible != ""){ | ||
result += buildHeading("Eligibility", eligible) + "_____________________\n\n"; | ||
} | ||
|
||
}on Exception catch(e){ | ||
print(e); | ||
result = "Something went wrong"; | ||
} | ||
return result; | ||
} | ||
|
||
String buildDetailContent(){ | ||
String result = ""; | ||
try{ | ||
|
||
if(criteria != ""){ | ||
result += buildHeading("Criteria", criteria) + "_____________________\n\n"; | ||
} | ||
|
||
if(method != ""){ | ||
result += buildHeading("Method Of Selection", method) + "_____________________\n\n"; | ||
} | ||
|
||
if(special != ""){ | ||
result += buildHeading("Special Requirements", special) + "_____________________\n\n"; | ||
} | ||
|
||
if(condition != ""){ | ||
result += buildHeading("Condition", condition) + "_____________________\n\n"; | ||
} | ||
|
||
if(details != ""){ | ||
result += buildHeading("Additional Details", details) + "_____________________\n\n"; | ||
} | ||
|
||
}on Exception catch(e){ | ||
print(e); | ||
result = "Something went wrong"; | ||
} | ||
return result; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return "${name.toUpperCase()}\n\n" + buildDescriptionContent() + buildDetailContent(); | ||
} | ||
} |
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,116 +1,41 @@ | ||
import 'package:fst_app_flutter/models/from_postgres/scholarship/scholarship.dart'; | ||
import 'package:fst_app_flutter/utils/debouncer.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
// Defines the model for the manager of the list of Scholarships | ||
class ScholarshipList with ChangeNotifier{ | ||
|
||
bool isPerformingRequest; // illustrates if the manager is processing a request | ||
bool isAtEnd; // signifies if the list has shown all the data | ||
bool hasResults; // signifies if the search results has any data | ||
int start; //signifies the start index in the original list of scholarship from data request | ||
|
||
List<Scholarship> scholarships; // original list of scholarships from http requests | ||
List<Scholarship> current; // The current list which is used in the list view | ||
List<Scholarship> viewList; // The paginated list of scholarship | ||
|
||
final int size = 10; //The amount of scholarships added during each request | ||
|
||
ScholarshipList({scholarships}){ | ||
this.scholarships = scholarships; | ||
start = 0; | ||
isPerformingRequest = false; | ||
isAtEnd = false; | ||
hasResults = true; | ||
|
||
|
||
//If the original list of scholarships has a length less than size then it will assigned the list as the viewList | ||
//otherwise it will get a list with length of size from the original list and assign it to viewlist | ||
if(scholarships.length <= size){ | ||
viewList = scholarships.getRange(start, scholarships.length).toList(); | ||
start += (scholarships.length - start); | ||
}else{ | ||
viewList = scholarships.getRange(start, start+size).toList(); | ||
start += size; | ||
} | ||
current = viewList; | ||
} | ||
|
||
//Getter Methods | ||
List<Scholarship> get scholarList => current; | ||
bool get atEnd => isAtEnd; | ||
bool get doesHaveResults => hasResults; | ||
bool get processRequests => isPerformingRequest; | ||
bool get isViewList => current == viewList; | ||
bool get isSearching => current != scholarships; | ||
|
||
//Factory Method for converting json into the model used | ||
factory ScholarshipList.fromJson(List<dynamic> parsedJson) { | ||
List<Scholarship> lst = new List<Scholarship>(); | ||
lst = parsedJson.map((i) => Scholarship.fromJson(i)).toList(); | ||
return new ScholarshipList( | ||
scholarships: lst, | ||
); | ||
ScholarshipList({scholarships}){ | ||
this.scholarships = scholarships; | ||
hasResults = true; | ||
current = this.scholarships; | ||
} | ||
|
||
//Function which searches to see if the query is contained in the Scholarship Name | ||
//Possibly could be refined for better searching methods | ||
void search(String query){ | ||
|
||
current = scholarships.where((p) => p.scholarshipName.toLowerCase().contains(query.toLowerCase())).toList(); | ||
current = scholarships.where((p) => p.name.toLowerCase().contains(query.toLowerCase())).toList(); | ||
|
||
if(current.isEmpty){ | ||
current = [Scholarship(name:"No Search Results")]; | ||
hasResults = false; | ||
}else if(query == ""){ | ||
current = viewList; | ||
hasResults = true; | ||
}else{ | ||
hasResults = true; | ||
} | ||
|
||
|
||
notifyListeners(); | ||
|
||
} | ||
|
||
void getMoreData() async{ | ||
|
||
if (!isPerformingRequest) { | ||
|
||
isPerformingRequest = true; | ||
|
||
notifyListeners(); | ||
|
||
List<Scholarship> newEntries; //new entries of scholarships for the paginated list | ||
|
||
if((scholarships.length - start) == 0){ | ||
newEntries = []; | ||
}else if((scholarships.length - start) < size){ | ||
newEntries = scholarships.getRange(start, scholarships.length).toList(); | ||
start += (scholarships.length - start); | ||
}else { | ||
newEntries = scholarships.getRange(start, start+size).toList(); | ||
start += size; | ||
} | ||
|
||
if (newEntries.isEmpty){ | ||
isAtEnd = true; | ||
} | ||
|
||
await Debouncer.wait(); | ||
|
||
viewList.addAll(newEntries); | ||
isPerformingRequest = false; | ||
|
||
notifyListeners(); | ||
} | ||
} | ||
|
||
//switches the list to the paginated list | ||
void switchList(){ | ||
current = viewList; | ||
notifyListeners(); | ||
} | ||
|
||
|
||
} |
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.