Add model with stub and view-model

main
DJYohann 2 years ago
parent acbdbdd13c
commit ff1349aa13

@ -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 = "<group>"; };
1E0D891A2A1E9BEF00786FE3 /* UEView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UEView.swift; sourceTree = "<group>"; };
1E160AB12A1FA51600ECDB3F /* NoteSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteSlider.swift; sourceTree = "<group>"; };
1E4D71782A29E50A008342F0 /* UEEditSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UEEditSheet.swift; sourceTree = "<group>"; };
1EDC99222A20DDAB00C3561D /* NoteInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteInfo.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -159,6 +161,7 @@
1E0D891A2A1E9BEF00786FE3 /* UEView.swift */,
1E160AB12A1FA51600ECDB3F /* NoteSlider.swift */,
1EDC99222A20DDAB00C3561D /* NoteInfo.swift */,
1E4D71782A29E50A008342F0 /* UEEditSheet.swift */,
);
path = Views;
sourceTree = "<group>";
@ -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;

@ -7,7 +7,7 @@
<key>App.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>3</integer>
</dict>
</dict>
</dict>

@ -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()
}
}

@ -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,9 +42,16 @@ struct UEView: View {
.padding()
.navigationTitle("UE1 Génie logiciel")
.toolbar {
Button(action: {}) {
ToolbarItem {
Button(action: {
showingSheet = true
}) {
Text("Edit")
}
.sheet(isPresented: $showingSheet) {
UEEditSheet()
}
}
}
}
}

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:Stub">
</FileRef>
<FileRef
location = "group:ViewModel">
</FileRef>
<FileRef
location = "group:Model">
</FileRef>

@ -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
}
}

@ -0,0 +1,5 @@
import Foundation
struct Manager {
}

@ -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
}
}

@ -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
}
}

@ -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!")
}
}

@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

@ -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"]),
]
)

@ -0,0 +1,3 @@
# Stub
A description of this package.

@ -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
}
}

@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

@ -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"]),
]
)

@ -0,0 +1,3 @@
# ViewModel
A description of this package.

@ -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
}
}
}
}

@ -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
}
}
}
}

@ -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
}
}
}
}
Loading…
Cancel
Save