diff --git a/src/App/App.xcodeproj/project.pbxproj b/src/App/App.xcodeproj/project.pbxproj index ba62493..22cfc71 100644 --- a/src/App/App.xcodeproj/project.pbxproj +++ b/src/App/App.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 1E0D89172A1E838700786FE3 /* UEListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E0D89162A1E838700786FE3 /* UEListItem.swift */; }; 1E0D891B2A1E9BEF00786FE3 /* UEView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E0D891A2A1E9BEF00786FE3 /* UEView.swift */; }; 1E160AB22A1FA51600ECDB3F /* NoteSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E160AB12A1FA51600ECDB3F /* NoteSlider.swift */; }; + 1E4D71792A29E50A008342F0 /* UEEditSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E4D71782A29E50A008342F0 /* UEEditSheet.swift */; }; 1EDC99232A20DDAB00C3561D /* NoteInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EDC99222A20DDAB00C3561D /* NoteInfo.swift */; }; /* End PBXBuildFile section */ @@ -56,6 +57,7 @@ 1E0D89162A1E838700786FE3 /* UEListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UEListItem.swift; sourceTree = ""; }; 1E0D891A2A1E9BEF00786FE3 /* UEView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UEView.swift; sourceTree = ""; }; 1E160AB12A1FA51600ECDB3F /* NoteSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteSlider.swift; sourceTree = ""; }; + 1E4D71782A29E50A008342F0 /* UEEditSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UEEditSheet.swift; sourceTree = ""; }; 1EDC99222A20DDAB00C3561D /* NoteInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteInfo.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -159,6 +161,7 @@ 1E0D891A2A1E9BEF00786FE3 /* UEView.swift */, 1E160AB12A1FA51600ECDB3F /* NoteSlider.swift */, 1EDC99222A20DDAB00C3561D /* NoteInfo.swift */, + 1E4D71782A29E50A008342F0 /* UEEditSheet.swift */, ); path = Views; sourceTree = ""; @@ -303,6 +306,7 @@ 1E0D88E32A1E759A00786FE3 /* AppApp.swift in Sources */, 1EDC99232A20DDAB00C3561D /* NoteInfo.swift in Sources */, 1E0D891B2A1E9BEF00786FE3 /* UEView.swift in Sources */, + 1E4D71792A29E50A008342F0 /* UEEditSheet.swift in Sources */, 1E0D89172A1E838700786FE3 /* UEListItem.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/src/App/App.xcodeproj/xcuserdata/djyohann.xcuserdatad/xcschemes/xcschememanagement.plist b/src/App/App.xcodeproj/xcuserdata/djyohann.xcuserdatad/xcschemes/xcschememanagement.plist index b04f406..74c9b79 100644 --- a/src/App/App.xcodeproj/xcuserdata/djyohann.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/src/App/App.xcodeproj/xcuserdata/djyohann.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ App.xcscheme_^#shared#^_ orderHint - 0 + 3 diff --git a/src/App/Views/UEEditSheet.swift b/src/App/Views/UEEditSheet.swift new file mode 100644 index 0000000..1b0ca10 --- /dev/null +++ b/src/App/Views/UEEditSheet.swift @@ -0,0 +1,29 @@ +import SwiftUI + +struct UEEditSheet: View { + var body: some View { + NavigationStack { + VStack { + Text("SALUT") + } + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button(action: {}) { + Text("Cancel") + } + } + ToolbarItem(placement: .confirmationAction) { + Button(action: {}) { + Text("Save") + } + } + } + } + } +} + +struct UEEditSheet_Previews: PreviewProvider { + static var previews: some View { + UEEditSheet() + } +} diff --git a/src/App/Views/UEView.swift b/src/App/Views/UEView.swift index 231cc7d..1cc57f7 100644 --- a/src/App/Views/UEView.swift +++ b/src/App/Views/UEView.swift @@ -1,13 +1,8 @@ -// -// UEView.swift -// App -// -// Created by BREUIL Yohann on 24/05/2023. -// - import SwiftUI struct UEView: View { + @State private var showingSheet = false + var body: some View { NavigationStack { ScrollView { @@ -47,8 +42,15 @@ struct UEView: View { .padding() .navigationTitle("UE1 Génie logiciel") .toolbar { - Button(action: {}) { - Text("Edit") + ToolbarItem { + Button(action: { + showingSheet = true + }) { + Text("Edit") + } + .sheet(isPresented: $showingSheet) { + UEEditSheet() + } } } } diff --git a/src/AverageCalculator.xcworkspace/contents.xcworkspacedata b/src/AverageCalculator.xcworkspace/contents.xcworkspacedata index 7f870fa..c11534a 100644 --- a/src/AverageCalculator.xcworkspace/contents.xcworkspacedata +++ b/src/AverageCalculator.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,12 @@ + + + + diff --git a/src/AverageCalculator.xcworkspace/xcuserdata/djyohann.xcuserdatad/UserInterfaceState.xcuserstate b/src/AverageCalculator.xcworkspace/xcuserdata/djyohann.xcuserdatad/UserInterfaceState.xcuserstate index d274cf7..4890433 100644 Binary files a/src/AverageCalculator.xcworkspace/xcuserdata/djyohann.xcuserdatad/UserInterfaceState.xcuserstate and b/src/AverageCalculator.xcworkspace/xcuserdata/djyohann.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/src/Model/Sources/Model/Bloc.swift b/src/Model/Sources/Model/Bloc.swift index 7899e39..040a244 100644 --- a/src/Model/Sources/Model/Bloc.swift +++ b/src/Model/Sources/Model/Bloc.swift @@ -1,18 +1,22 @@ import Foundation -public struct Bloc: Identifiable { +public struct Bloc: Identifiable, Equatable { public let id: UUID public var name: String public var ues: [UE] - init(id: UUID, name: String, ues: [UE]) { + public init(id: UUID, name: String, ues: [UE]) { self.id = id self.name = name self.ues = ues } - init(name: String, ues: [UE]) { + public init(name: String, ues: [UE]) { self.init(id: UUID(), name: name, ues: ues) } + + public static func == (lhs: Bloc, rhs: Bloc) -> Bool { + return lhs.id == rhs.id + } } diff --git a/src/Model/Sources/Model/Manager.swift b/src/Model/Sources/Model/Manager.swift new file mode 100644 index 0000000..249f60f --- /dev/null +++ b/src/Model/Sources/Model/Manager.swift @@ -0,0 +1,5 @@ +import Foundation + +struct Manager { + +} diff --git a/src/Model/Sources/Model/Matiere.swift b/src/Model/Sources/Model/Matiere.swift index 95d7a30..e3fb0db 100644 --- a/src/Model/Sources/Model/Matiere.swift +++ b/src/Model/Sources/Model/Matiere.swift @@ -1,20 +1,30 @@ import Foundation -public struct Matiere : Identifiable { +public struct Matiere : Identifiable, Equatable { public let id: UUID public var name: String public var factor: Int public var note: Float - init(id: UUID, name: String, factor: Int, note: Float) { + public var realNote: Float { + get { + return note * Float(factor) + } + } + + public init(id: UUID, name: String, factor: Int, note: Float) { self.id = id self.name = name self.factor = factor self.note = note } - init(name: String, factor: Int, note: Float) { + public init(name: String, factor: Int, note: Float) { self.init(id: UUID(), name: name, factor: factor, note: note) } + + public static func == (lhs: Matiere, rhs: Matiere) -> Bool { + return lhs.id == rhs.id + } } diff --git a/src/Model/Sources/Model/UE.swift b/src/Model/Sources/Model/UE.swift index 550627f..03585e2 100644 --- a/src/Model/Sources/Model/UE.swift +++ b/src/Model/Sources/Model/UE.swift @@ -1,14 +1,14 @@ import Foundation -public struct UE: Identifiable { +public struct UE: Identifiable, Equatable { public let id: UUID - public var number: Int + public var number: Int32 public var name: String - public var factor: Int + public var factor: Int32 public var matieres: [Matiere] - init(id: UUID, number: Int, name: String, factor: Int, matieres: [Matiere]) { + public init(id: UUID, number: Int32, name: String, factor: Int32, matieres: [Matiere]) { self.id = id self.number = number self.name = name @@ -16,7 +16,34 @@ public struct UE: Identifiable { self.matieres = matieres } - init(number: Int, name: String, factor: Int, matieres: [Matiere]) { + public init(number: Int32, name: String, factor: Int32, matieres: [Matiere]) { self.init(id: UUID(), number: number, name: name, factor: factor, matieres: matieres) } + + public mutating func addMatiere(matiere: Matiere) -> Void { + matieres.append(matiere) + } + + public mutating func addMatieres(matieres: Matiere...) -> Void { + self.matieres.append(contentsOf: matieres) + } + + public func findMatiereByName(name: String) -> Matiere? { + if let index = matieres.firstIndex(where: { $0.name == name }) { + return findMatiereByIndex(index: index); + } + return nil + } + + public func findMatiereByIndex(index: Int) -> Matiere { + return matieres[index]; + } + + public mutating func delMatiere(index: Int) -> Void { + matieres.remove(at: index) + } + + public static func == (lhs: UE, rhs: UE) -> Bool { + return lhs.id == rhs.id + } } diff --git a/src/Model/Tests/ModelTests/ModelTests.swift b/src/Model/Tests/ModelTests/ModelTests.swift deleted file mode 100644 index 38c36bb..0000000 --- a/src/Model/Tests/ModelTests/ModelTests.swift +++ /dev/null @@ -1,11 +0,0 @@ -import XCTest -@testable import Model - -final class ModelTests: XCTestCase { - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(Model().text, "Hello, World!") - } -} diff --git a/src/Stub/.gitignore b/src/Stub/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/src/Stub/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/src/Stub/Package.swift b/src/Stub/Package.swift new file mode 100644 index 0000000..1a98407 --- /dev/null +++ b/src/Stub/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version: 5.8 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "Stub", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "Stub", + targets: ["Stub"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(name: "Model", path: "../Model") + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "Stub", + dependencies: ["Model"]), + .testTarget( + name: "StubTests", + dependencies: ["Stub"]), + ] +) diff --git a/src/Stub/README.md b/src/Stub/README.md new file mode 100644 index 0000000..a016ae1 --- /dev/null +++ b/src/Stub/README.md @@ -0,0 +1,3 @@ +# Stub + +A description of this package. diff --git a/src/Model/Sources/Model/Stub.swift b/src/Stub/Sources/Stub/Stub.swift similarity index 88% rename from src/Model/Sources/Model/Stub.swift rename to src/Stub/Sources/Stub/Stub.swift index 72db421..156688c 100644 --- a/src/Model/Sources/Model/Stub.swift +++ b/src/Stub/Sources/Stub/Stub.swift @@ -1,8 +1,11 @@ +import Model import Foundation public struct Stub { - func loadBlocs() -> [Bloc] {[ - Bloc(name: "Total", ues: [ + public func loadBlocs() -> [Bloc] { + var blocs: [Bloc] = [] + + var bloc1 = Bloc(name: "Total", ues: [ UE(number: 1, name: "Génie logiciel", factor: 6, matieres: [ Matiere(name: "Processus de développement", factor: 4, note: 19.04), Matiere(name: "Programmation objets", factor: 9, note: 9.08), @@ -35,8 +38,9 @@ public struct Stub { Matiere(name: "QT Quick", factor: 5, note: 10), Matiere(name: "Xamarin", factor: 5, note: 10) ]), - ]), - Bloc(name: "Projet / Stage", ues: [ + ]) + + var bloc2 = Bloc(name: "Projet / Stage", ues: [ UE(number: 6, name: "Projet", factor: 9, matieres: [ Matiere(name: "Projet", factor: 1, note: 10) ]), @@ -44,5 +48,11 @@ public struct Stub { Matiere(name: "Stage", factor: 1, note: 10) ]) ]) - ]} + + blocs.append(contentsOf: [bloc1, bloc2]) + + return blocs + } + + } diff --git a/src/ViewModel/.gitignore b/src/ViewModel/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/src/ViewModel/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/src/ViewModel/Package.swift b/src/ViewModel/Package.swift new file mode 100644 index 0000000..a40bdb2 --- /dev/null +++ b/src/ViewModel/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version: 5.8 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "ViewModel", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "ViewModel", + targets: ["ViewModel"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(name: "Model", path: "../Model") + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "ViewModel", + dependencies: ["Model"]), + .testTarget( + name: "ViewModelTests", + dependencies: ["ViewModel"]), + ] +) diff --git a/src/ViewModel/README.md b/src/ViewModel/README.md new file mode 100644 index 0000000..74e3704 --- /dev/null +++ b/src/ViewModel/README.md @@ -0,0 +1,3 @@ +# ViewModel + +A description of this package. diff --git a/src/ViewModel/Sources/ViewModel/BlocVM.swift b/src/ViewModel/Sources/ViewModel/BlocVM.swift new file mode 100644 index 0000000..eeae83d --- /dev/null +++ b/src/ViewModel/Sources/ViewModel/BlocVM.swift @@ -0,0 +1,42 @@ +import Foundation +import Model + +@available(iOS 13.0, *) +public class BlocVM : ObservableObject, Identifiable { + public init(model: Bloc) { + self.model = model + } + + public var id: UUID { model.id } + + @Published + var model: Bloc = Bloc(id: UUID(), name: "", ues: []) { + didSet { + if self.name != model.name { + self.name = self.model.name + } + + if self.ues != model.ues { + self.ues = self.model.ues + } + } + } + + @Published + var name: String = "" { + didSet { + if self.name != self.model.name { + self.name = self.model.name + } + } + } + + @Published + var ues: [UE] = [] { + didSet { + if self.ues != self.model.ues { + self.ues = self.model.ues + } + } + } +} diff --git a/src/ViewModel/Sources/ViewModel/MatiereVM.swift b/src/ViewModel/Sources/ViewModel/MatiereVM.swift new file mode 100644 index 0000000..b6d09d4 --- /dev/null +++ b/src/ViewModel/Sources/ViewModel/MatiereVM.swift @@ -0,0 +1,55 @@ +import Foundation +import Model + +@available(iOS 13.0, *) +class MatiereVM : ObservableObject, Identifiable { + public init(model: Matiere) { + self.model = model + } + + public var id: UUID { model.id } + + @Published + var model: Matiere = Matiere(id: UUID(), name: "", factor: 0, note: 0) { + didSet { + if self.name != model.name { + self.name = self.model.name + } + + if self.factor != model.factor { + self.factor = self.model.factor + } + + if self.note != model.note { + self.note = self.model.note + } + } + } + + @Published + var name: String = "" { + didSet { + if model.name != self.model.name { + self.name = self.model.name + } + } + } + + @Published + var factor: Int = 0 { + didSet { + if model.factor != self.model.factor { + self.factor = self.model.factor + } + } + } + + @Published + var note: Float = 0 { + didSet { + if model.note != self.model.note { + self.note = self.model.note + } + } + } +} diff --git a/src/ViewModel/Sources/ViewModel/UEVM.swift b/src/ViewModel/Sources/ViewModel/UEVM.swift new file mode 100644 index 0000000..2ad4b6b --- /dev/null +++ b/src/ViewModel/Sources/ViewModel/UEVM.swift @@ -0,0 +1,68 @@ +import Foundation +import Model + +@available(iOS 13.0, *) +public class UEVM : ObservableObject, Identifiable { + public init(model: UE) { + self.model = model + } + + public var id: UUID { model.id } + + @Published + var model: UE = UE(id: UUID(), number: 0, name: "", factor: 0, matieres: []) { + didSet { + if self.number != self.model.number { + self.number = self.model.number + } + + if self.name != self.model.name { + self.name = self.model.name + } + + if self.factor != self.model.factor { + self.factor = self.model.factor + } + + if self.matieres != self.model.matieres { + self.matieres = self.model.matieres + } + } + } + + @Published + var number: Int32 = 0 { + didSet { + if model.number != self.model.number { + self.number = self.model.number + } + } + } + + @Published + var name: String = "" { + didSet { + if model.name != self.model.name { + self.name = self.model.name + } + } + } + + @Published + var factor: Int32 = 0 { + didSet { + if model.factor != self.model.factor { + self.factor = self.model.factor + } + } + } + + @Published + var matieres: [Matiere] = [] { + didSet { + if model.matieres != self.model.matieres { + self.matieres = self.model.matieres + } + } + } +}