-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add short term hints and refactor interpolation
- Loading branch information
1 parent
e387f0d
commit e97cd68
Showing
3 changed files
with
60 additions
and
62 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
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,42 +1,51 @@ | ||
// Project imports: | ||
import "package:graded/calculations/calculation_object.dart"; | ||
import "package:graded/calculations/manager.dart"; | ||
import "package:graded/calculations/subject.dart"; | ||
import "package:graded/localization/translations.dart"; | ||
|
||
String getHint(String prefix, List<CalculationObject> data) { | ||
String hint = ""; | ||
int i = data.length; | ||
|
||
do { | ||
i++; | ||
hint = "$prefix $i"; | ||
} while (isDuplicateName(hint, data)); | ||
|
||
return hint; | ||
} | ||
|
||
bool isDuplicateName(String name, List<CalculationObject> data) { | ||
return data.any((e) => e.name == name || (e is Subject && e.children.any((child) => child.name == name))); | ||
} | ||
|
||
String getTermName({required int termIndex}) { | ||
final int termCount = getCurrentYear().termCount; | ||
|
||
if (termIndex == -1) return translations.year_overview; | ||
|
||
if (termIndex == termCount) return translations.exams; | ||
|
||
switch (termCount) { | ||
case 4: | ||
return "${translations.quarterOne} ${termIndex + 1}"; | ||
case 3: | ||
return "${translations.trimesterOne} ${termIndex + 1}"; | ||
case 2: | ||
return "${translations.semesterOne} ${termIndex + 1}"; | ||
case 1: | ||
return translations.yearOne; | ||
default: | ||
return "${translations.school_termOne} ${termIndex + 1}"; | ||
} | ||
} | ||
// Project imports: | ||
import "package:graded/calculations/calculation_object.dart"; | ||
import "package:graded/calculations/manager.dart"; | ||
import "package:graded/calculations/subject.dart"; | ||
import "package:graded/localization/translations.dart"; | ||
|
||
String getHint(String prefix, List<CalculationObject> data) { | ||
String hint = ""; | ||
int i = data.length; | ||
|
||
do { | ||
i++; | ||
hint = "$prefix $i"; | ||
} while (isDuplicateName(hint, data)); | ||
|
||
return hint; | ||
} | ||
|
||
bool isDuplicateName(String name, List<CalculationObject> data) { | ||
return data.any((e) => e.name == name || (e is Subject && e.children.any((child) => child.name == name))); | ||
} | ||
|
||
String getTermName({required int termIndex}) { | ||
final int termCount = getCurrentYear().termCount; | ||
|
||
if (termIndex == -1) return translations.year_overview; | ||
|
||
if (termIndex == termCount) return translations.exams; | ||
|
||
return switch (termCount) { | ||
4 => translations.quartile_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
3 => translations.trimester_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
2 => translations.semester_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
1 => translations.yearOne, | ||
_ => translations.school_term_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
}; | ||
} | ||
|
||
String getTermNameShort({required int termIndex}) { | ||
final int termCount = getCurrentYear().termCount; | ||
|
||
if (termIndex == -1) return translations.year_overview; | ||
|
||
return switch (termCount) { | ||
4 => translations.quartile_short_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
3 => translations.trimester_short_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
2 => translations.semester_short_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
1 => translations.yearOne, | ||
_ => translations.school_term_short_num.replaceFirst("%s", (termIndex + 1).toString()), | ||
}; | ||
} |
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