mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-12-22 13:25:13 +00:00
✨ Adding date of next theory phase start to home screen
- Also some UI stuff, documentation and removal of unused CoreData entities
This commit is contained in:
parent
c8a6ba8008
commit
64bd6bf434
|
@ -1,8 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D62" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
</entity>
|
||||
<entity name="RaPlaEvent" representedClassName="RaPlaEvent" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="category" optional="YES" attributeType="String"/>
|
||||
<attribute name="descr" optional="YES" attributeType="String"/>
|
||||
|
@ -19,7 +16,6 @@
|
|||
<attribute name="name" optional="YES" attributeType="String"/>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="Item" positionX="-63" positionY="-18" width="128" height="44"/>
|
||||
<element name="RaPlaEvent" positionX="-63" positionY="9" width="128" height="149"/>
|
||||
<element name="User" positionX="-63" positionY="-9" width="128" height="74"/>
|
||||
</elements>
|
||||
|
|
|
@ -45,7 +45,7 @@ class UtilityFunctions {
|
|||
}
|
||||
|
||||
public class func deleteAllData() -> Bool {
|
||||
let entities = ["User", "Item"]
|
||||
let entities = ["User", "RaPlaEvent"]
|
||||
var allSuccessful = true
|
||||
|
||||
for entityName in entities {
|
||||
|
|
|
@ -32,6 +32,10 @@ struct HomeView: View {
|
|||
Text("director".localized(tableName: "General", plural: false) + ": ")
|
||||
Text(self.director)
|
||||
}
|
||||
HStack {
|
||||
Text("Next Theory Phase: ")
|
||||
Text(getNextTheoryPhaseStartDate())
|
||||
}
|
||||
|
||||
// Upcoming events section
|
||||
HStack {
|
||||
|
@ -52,9 +56,9 @@ struct HomeView: View {
|
|||
}
|
||||
}
|
||||
.padding()
|
||||
.overlay(
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.blue, lineWidth: 4)
|
||||
.fill(Color.gray)
|
||||
)
|
||||
|
||||
VStack {
|
||||
|
@ -72,9 +76,9 @@ struct HomeView: View {
|
|||
}
|
||||
}
|
||||
.padding()
|
||||
.overlay(
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.blue, lineWidth: 4)
|
||||
.fill(Color.gray)
|
||||
)
|
||||
|
||||
Spacer()
|
||||
|
@ -99,6 +103,10 @@ struct HomeView: View {
|
|||
}
|
||||
}
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.gray)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.red, lineWidth: 4)
|
||||
|
@ -118,6 +126,7 @@ struct HomeView: View {
|
|||
}
|
||||
|
||||
extension HomeView{
|
||||
// Read required data from CoreData and save it to the appropriate variables
|
||||
func readFromCoreData() {
|
||||
let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User")
|
||||
|
||||
|
@ -129,6 +138,8 @@ extension HomeView{
|
|||
}
|
||||
}
|
||||
|
||||
// Get 0...2 of todays lectures from RaPla
|
||||
// Returns a list of RaPlaEvent NSManagedObjects
|
||||
func getTodaysEvents() -> [NSManagedObject] {
|
||||
let searchPredicate = NSPredicate(format: "(category == 'Lehrveranstaltung')")
|
||||
let hiddenPredicate = NSPredicate(format: "isHidden == NO")
|
||||
|
@ -143,6 +154,8 @@ extension HomeView{
|
|||
}
|
||||
}
|
||||
|
||||
// Get 0...2 of tomorrows lectures from RaPla
|
||||
// Returns a list of RaPlaEvent NSManagedObjects
|
||||
func getTomorrowsEvents() -> [NSManagedObject] {
|
||||
let searchPredicate = NSPredicate(format: "(category == 'Lehrveranstaltung')")
|
||||
let hiddenPredicate = NSPredicate(format: "isHidden == NO")
|
||||
|
@ -157,6 +170,8 @@ extension HomeView{
|
|||
}
|
||||
}
|
||||
|
||||
// Get 0...2 of upcoming exams from RaPla
|
||||
// Returns a list of RaPlaEvent NSManagedObjects
|
||||
func getUpcomingExams() -> [NSManagedObject] {
|
||||
let searchPredicate = NSPredicate(format: "category == %@", "Prüfung")
|
||||
let hiddenPredicate = NSPredicate(format: "isHidden == NO")
|
||||
|
@ -171,6 +186,7 @@ extension HomeView{
|
|||
}
|
||||
}
|
||||
|
||||
// Get the required NSPredicates to fetch only RaPla events with a start date that is today
|
||||
func getDayPredicates(today: Bool = false, tomorrow: Bool = false) -> [NSPredicate] {
|
||||
var calendar = Calendar.current
|
||||
calendar.timeZone = NSTimeZone.local
|
||||
|
@ -192,6 +208,30 @@ extension HomeView{
|
|||
|
||||
return [fromPredicate, toPredicate]
|
||||
}
|
||||
|
||||
// Get the formatted date when the next theory phase starts
|
||||
func getNextTheoryPhaseStartDate() -> String {
|
||||
var calendar = Calendar.current
|
||||
calendar.timeZone = NSTimeZone.local
|
||||
let categoryPredicate = NSPredicate(format: "category == %@", "Sonstiger Termin")
|
||||
let datePredicate = NSPredicate(format: "startDate >= %@", calendar.startOfDay(for: Date()) as NSDate)
|
||||
let titlePredicate = NSPredicate(format: "summary CONTAINS[cd] %@", "beginn")
|
||||
let compoundPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [categoryPredicate, datePredicate, titlePredicate])
|
||||
|
||||
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
|
||||
let sortDescriptors = [sectionSortDescriptor]
|
||||
|
||||
let events = UtilityFunctions.getCoreDataObject(entity: "RaPlaEvent", sortDescriptors: sortDescriptors, searchPredicate: compoundPredicate)
|
||||
|
||||
if(!events.isEmpty) {
|
||||
let date = events[0].value(forKey: "startDate") as! Date
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
return formatter.string(from: date)
|
||||
} else {
|
||||
return "N/A"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeView_Previews: PreviewProvider {
|
||||
|
|
Loading…
Reference in New Issue
Block a user