fix issues with club

multistore
Razmig Sarkissian 1 year ago
parent 252bde5860
commit fbd408c01c
  1. 4
      PadelClub.xcodeproj/project.pbxproj
  2. 6
      PadelClub/Data/Club.swift
  3. 2
      PadelClub/Data/Federal/FederalTournament.swift
  4. 16
      PadelClub/Views/Cashier/Event/EventCreationView.swift
  5. 27
      PadelClub/Views/Club/ClubDetailView.swift
  6. 5
      PadelClub/Views/Club/ClubRowView.swift
  7. 14
      PadelClub/Views/Club/ClubsView.swift
  8. 19
      PadelClub/Views/Club/CreateClubView.swift
  9. 21
      PadelClub/Views/Navigation/MainView.swift

@ -1908,7 +1908,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 65; CURRENT_PROJECT_VERSION = 66;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\"";
@ -1949,7 +1949,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 65; CURRENT_PROJECT_VERSION = 66;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\"";
DEVELOPMENT_TEAM = BQ3Y44M3Q6; DEVELOPMENT_TEAM = BQ3Y44M3Q6;

@ -170,7 +170,7 @@ class Club : ModelObject, Storable, Hashable {
extension Club { extension Club {
var isValid: Bool { var isValid: Bool {
name.isEmpty == false && acronym.isEmpty == false name.isEmpty == false && name.count > 3
} }
func automaticShortName() -> String { func automaticShortName() -> String {
@ -216,7 +216,7 @@ extension Club {
} }
func hasBeenCreated(by creatorId: String?) -> Bool { func hasBeenCreated(by creatorId: String?) -> Bool {
return creatorId == creator return creatorId == creator || creator == nil
} }
func isFavorite() -> Bool { func isFavorite() -> Bool {
@ -235,7 +235,7 @@ extension Club {
if clubs.isEmpty == false { if clubs.isEmpty == false {
return clubs.first! return clubs.first!
} else { } else {
return Club(name: name, code: code, city: city, zipCode: zipCode) return Club(creator: Store.main.userId, name: name, code: code, city: city, zipCode: zipCode)
} }
} }

@ -20,7 +20,7 @@ struct FederalTournament: Identifiable, Codable {
let club = DataStore.shared.user.clubsObjects().first(where: { $0.code == codeClub }) let club = DataStore.shared.user.clubsObjects().first(where: { $0.code == codeClub })
var event = DataStore.shared.events.first(where: { $0.tenupId == id.string }) var event = DataStore.shared.events.first(where: { $0.tenupId == id.string })
if event == nil { if event == nil {
event = Event(creator: DataStore.shared.user.id, club: club?.id, name: libelle, tenupId: id.string) event = Event(creator: Store.main.userId, club: club?.id, name: libelle, tenupId: id.string)
do { do {
try DataStore.shared.events.addOrUpdate(instance: event!) try DataStore.shared.events.addOrUpdate(instance: event!)
} catch { } catch {

@ -130,10 +130,6 @@ struct EventCreationView: View {
private func _validate() { private func _validate() {
let event = Event(creator: Store.main.userId, name: eventName) let event = Event(creator: Store.main.userId, name: eventName)
event.club = selectedClub?.id
tournaments.forEach { tournament in
tournament.event = event.id
}
do { do {
try dataStore.events.addOrUpdate(instance: event) try dataStore.events.addOrUpdate(instance: event)
@ -142,6 +138,7 @@ struct EventCreationView: View {
} }
tournaments.forEach { tournament in tournaments.forEach { tournament in
tournament.event = event.id
tournament.courtCount = selectedClub?.courtCount ?? 2 tournament.courtCount = selectedClub?.courtCount ?? 2
tournament.startDate = startingDate tournament.startDate = startingDate
tournament.dayDuration = duration tournament.dayDuration = duration
@ -154,6 +151,17 @@ struct EventCreationView: View {
Logger.error(error) Logger.error(error)
} }
if let selectedClub, let verifiedSelectedClubId = dataStore.clubs.first(where: { selectedClub.id == $0.id })?.id {
event.club = verifiedSelectedClubId
do {
try dataStore.events.addOrUpdate(instance: event)
} catch {
Logger.error(error)
}
}
dismiss() dismiss()
navigation.path.append(tournaments.first!) navigation.path.append(tournaments.first!)
} }

@ -53,7 +53,7 @@ struct ClubDetailView: View {
} }
Section { Section {
TextField("Nom du club", text: $club.name) TextField("Nom du club (4 lettres mini)", text: $club.name)
.autocorrectionDisabled() .autocorrectionDisabled()
.keyboardType(.alphabet) .keyboardType(.alphabet)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
@ -187,31 +187,6 @@ struct ClubDetailView: View {
} }
} }
if displayContext == .addition {
Section {
} header: {
HStack {
VStack {
Divider()
}
Text("ou")
VStack {
Divider()
}
}
}
Section {
NavigationLink {
ClubSearchView(displayContext: .edition, club: club)
} label: {
Label("Chercher dans la base fédérale", systemImage: "magnifyingglass")
}
} footer: {
Text("Vous pouvez chercher un club dans la base fédérale et importer les informations directement.")
}
}
ClubCourtSetupView(club: club, displayContext: displayContext, selectedCourt: $selectedCourt, hideLockForEditingMessage: true) ClubCourtSetupView(club: club, displayContext: displayContext, selectedCourt: $selectedCourt, hideLockForEditingMessage: true)
if displayContext == .edition { if displayContext == .edition {

@ -19,7 +19,12 @@ struct ClubRowView: View {
// .foregroundStyle(club.isFavorite() ? .green : .logoRed) // .foregroundStyle(club.isFavorite() ? .green : .logoRed)
// } // }
} label: { } label: {
HStack {
Text(club.name) Text(club.name)
Spacer()
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
} }
} }
} }

@ -27,6 +27,20 @@ struct ClubsView: View {
var body: some View { var body: some View {
List { List {
#if DEBUG
Section {
RowButtonView("Delete unexisted clubs", action: {
var ids = dataStore.user.clubs
ids.forEach { clubId in
if dataStore.clubs.findById(clubId) == nil {
dataStore.user.clubs.removeAll(where: { $0 == clubId })
}
}
dataStore.saveUser()
})
}
#endif
let clubs : [Club] = dataStore.user.clubsObjects(includeCreated: false) let clubs : [Club] = dataStore.user.clubsObjects(includeCreated: false)
let onlyCreatedClubs : [Club] = dataStore.user.createdClubsObjectsNotFavorite() let onlyCreatedClubs : [Club] = dataStore.user.createdClubsObjectsNotFavorite()

@ -30,6 +30,10 @@ struct CreateClubView: View {
ProgressView() ProgressView()
} else { } else {
ButtonValidateView { ButtonValidateView {
if club.acronym.isEmpty {
club.acronym = club.name.canonicalVersion.replaceCharactersFromSet(characterSet: .whitespacesAndNewlines).acronym()
}
validationInProgress = true validationInProgress = true
} }
.disabled(club.isValid == false) .disabled(club.isValid == false)
@ -45,26 +49,25 @@ struct CreateClubView: View {
Logger.error(error) Logger.error(error)
} }
let club = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode) let newClub = Club.findOrCreate(name: club.name, code: club.code, city: club.city, zipCode: club.zipCode)
club.creator = Store.main.userId
//update existing club if rights ok / freshly created club with data input from user //update existing club if rights ok / freshly created club with data input from user
if club.hasBeenCreated(by: Store.main.userId) { if newClub.hasBeenCreated(by: Store.main.userId) {
club.update(fromClub: club) newClub.update(fromClub: club)
do { do {
try dataStore.clubs.addOrUpdate(instance: club) try dataStore.clubs.addOrUpdate(instance: newClub)
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
} }
//save into user //save into user
if dataStore.user.clubs.contains(where: { $0 == club.id }) == false { if dataStore.user.clubs.contains(where: { $0 == newClub.id }) == false {
dataStore.user.clubs.append(club.id) dataStore.user.clubs.append(newClub.id)
self.dataStore.saveUser() self.dataStore.saveUser()
} }
dismiss() dismiss()
selection?(club) selection?(newClub)
} }
} }
} }

@ -92,6 +92,27 @@ struct MainView: View {
.environmentObject(dataStore) .environmentObject(dataStore)
.task { .task {
await self._checkSourceFileAvailability() await self._checkSourceFileAvailability()
if Store.main.hasToken() {
do {
try await dataStore.clubs.loadDataFromServerIfAllowed()
} catch {
Logger.error(error)
}
let ids = dataStore.user.clubs
var save = false
ids.forEach { clubId in
if dataStore.clubs.findById(clubId) == nil {
dataStore.user.clubs.removeAll(where: { $0 == clubId })
save = true
}
}
if save {
dataStore.saveUser()
}
}
} }
// .refreshable { // .refreshable {
// Task { // Task {

Loading…
Cancel
Save