Begin statistics creation
This commit is contained in:
@@ -38,9 +38,9 @@ final class Post: Item, DateItem, LocalizedItem {
|
||||
@Published
|
||||
var linkedPage: Page?
|
||||
|
||||
/// The workout associated with the post
|
||||
/// The workouts associated with the post
|
||||
@Published
|
||||
var associatedWorkout: FileResource?
|
||||
var associatedWorkouts: [FileResource]
|
||||
|
||||
init(content: Content,
|
||||
id: String,
|
||||
@@ -52,7 +52,7 @@ final class Post: Item, DateItem, LocalizedItem {
|
||||
german: LocalizedPost,
|
||||
english: LocalizedPost,
|
||||
linkedPage: Page? = nil,
|
||||
associatedWorkout: FileResource? = nil) {
|
||||
associatedWorkouts: [FileResource] = []) {
|
||||
self.isDraft = isDraft
|
||||
self.createdDate = createdDate
|
||||
self.startDate = startDate
|
||||
@@ -62,7 +62,7 @@ final class Post: Item, DateItem, LocalizedItem {
|
||||
self.german = german
|
||||
self.english = english
|
||||
self.linkedPage = linkedPage
|
||||
self.associatedWorkout = associatedWorkout
|
||||
self.associatedWorkouts = associatedWorkouts
|
||||
super.init(content: content, id: id)
|
||||
}
|
||||
|
||||
@@ -182,11 +182,13 @@ final class Post: Item, DateItem, LocalizedItem {
|
||||
}
|
||||
|
||||
func updateLabelsFromWorkout() {
|
||||
guard let overview = associatedWorkout?.routeOverview else {
|
||||
let workouts = associatedWorkouts.compactMap { $0.routeOverview }
|
||||
guard !workouts.isEmpty else {
|
||||
return
|
||||
}
|
||||
german.updateLabels(from: overview, locale: Locale(identifier: "de_DE"))
|
||||
english.updateLabels(from: overview, locale: Locale(identifier: "en_US"))
|
||||
let overview = RouteOverview.combine(workouts)
|
||||
overview.update(labels: &german.labels, language: .german)
|
||||
overview.update(labels: &english.labels, language: .english)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +206,7 @@ extension Post: StorageItem {
|
||||
german: .init(context: context, data: data.german),
|
||||
english: .init(context: context, data: data.english),
|
||||
linkedPage: data.linkedPageId.map(context.page),
|
||||
associatedWorkout: data.associatedWorkoutId.map(context.file))
|
||||
associatedWorkouts: data.associatedWorkoutIds?.compactMap(context.file) ?? [])
|
||||
savedData = data
|
||||
}
|
||||
|
||||
@@ -217,7 +219,7 @@ extension Post: StorageItem {
|
||||
let german: LocalizedPost.Data
|
||||
let english: LocalizedPost.Data
|
||||
let linkedPageId: String?
|
||||
let associatedWorkoutId: String?
|
||||
let associatedWorkoutIds: [String]?
|
||||
}
|
||||
|
||||
var data: Data {
|
||||
@@ -230,7 +232,7 @@ extension Post: StorageItem {
|
||||
german: german.data,
|
||||
english: english.data,
|
||||
linkedPageId: linkedPage?.identifier,
|
||||
associatedWorkoutId: associatedWorkout?.identifier)
|
||||
associatedWorkoutIds: associatedWorkouts.map { $0.identifier}.nonEmpty )
|
||||
}
|
||||
|
||||
func saveToDisk(_ data: Data) -> Bool {
|
||||
|
||||
Reference in New Issue
Block a user