working Fine

main
Ismail TAHA JANAN 2 years ago
parent 5102f7a2da
commit 5f8e5ffd26

@ -27,6 +27,8 @@
EC97FE492A378E59007AEC0A /* UEView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC97FE482A378E59007AEC0A /* UEView.swift */; };
EC97FE4B2A3798B7007AEC0A /* ModuleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC97FE4A2A3798B7007AEC0A /* ModuleView.swift */; };
EC97FE4D2A37A9F6007AEC0A /* UISliderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC97FE4C2A37A9F6007AEC0A /* UISliderView.swift */; };
EC97FE4F2A38F028007AEC0A /* UesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC97FE4E2A38F028007AEC0A /* UesList.swift */; };
EC97FE512A38FDC9007AEC0A /* UeDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC97FE502A38FDC9007AEC0A /* UeDetails.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -70,6 +72,8 @@
EC97FE482A378E59007AEC0A /* UEView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UEView.swift; sourceTree = "<group>"; };
EC97FE4A2A3798B7007AEC0A /* ModuleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleView.swift; sourceTree = "<group>"; };
EC97FE4C2A37A9F6007AEC0A /* UISliderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UISliderView.swift; sourceTree = "<group>"; };
EC97FE4E2A38F028007AEC0A /* UesList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UesList.swift; sourceTree = "<group>"; };
EC97FE502A38FDC9007AEC0A /* UeDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UeDetails.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -192,6 +196,8 @@
isa = PBXGroup;
children = (
EC97FE472A378DBE007AEC0A /* Components */,
EC97FE4E2A38F028007AEC0A /* UesList.swift */,
EC97FE502A38FDC9007AEC0A /* UeDetails.swift */,
);
path = Views;
sourceTree = "<group>";
@ -337,6 +343,7 @@
buildActionMask = 2147483647;
files = (
EC97FE4B2A3798B7007AEC0A /* ModuleView.swift in Sources */,
EC97FE4F2A38F028007AEC0A /* UesList.swift in Sources */,
EC1491962A35B91D00B2D47A /* UE.swift in Sources */,
EC14918F2A29F05A00B2D47A /* UsList.swift in Sources */,
EC14918A2A20D64500B2D47A /* Block.swift in Sources */,
@ -344,6 +351,7 @@
EC97FE492A378E59007AEC0A /* UEView.swift in Sources */,
EC1491A22A361B7600B2D47A /* ManagerVM.swift in Sources */,
EC1491982A35BD3400B2D47A /* Stub.swift in Sources */,
EC97FE512A38FDC9007AEC0A /* UeDetails.swift in Sources */,
EC243AA62A1FA0440017C10A /* ContentView.swift in Sources */,
EC14918D2A20DF2900B2D47A /* MySlider.swift in Sources */,
EC243AA42A1FA0440017C10A /* CalculMoyApp.swift in Sources */,

@ -9,9 +9,13 @@ import SwiftUI
@main
struct CalculMoyApp: App {
var managerVM:ManagerVM=ManagerVM(manager: Manager(ues: Stub.uesData) )
var body: some Scene {
WindowGroup {
ContentView()
UesList(managerVM: managerVM)
}
}
}

@ -49,7 +49,7 @@ struct Stub{
modules: [
Module(id: UUID(), moduleName: "Module - 1", coef: 2, note: 4),
Module(id: UUID(), moduleName: "Module - 2", coef: 3, note: 14),
Module(id: UUID(), moduleName: "Module - 3", coef: 5, note: 10),
Module(id: UUID(), moduleName: "Module - 3", coef: 5, note: 15),
Module(id: UUID(), moduleName: "Module - 4", coef: 2, note: 9),
]
),

@ -9,9 +9,11 @@ import Foundation
class ManagerVM:ObservableObject{
@Published var ueList: [UeVM]
@Published var moyGeneral: Double?
init(ueList: [UeVM]) {
self.ueList = ueList
self.moyGeneral = getMoyGeneral()
}
init(manager:Manager){
@ -19,17 +21,33 @@ class ManagerVM:ObservableObject{
for ue in manager.ues{
ueList.append(UeVM(ue: ue))
}
self.moyGeneral = getMoyGeneral()
}
init(){
ueList=[]
addUEs(ues: Stub.uesData)
self.moyGeneral = getMoyGeneral()
}
func addUEs(ues: [UE]){
for ue in ues {
ueList.append(UeVM(ue: ue))
}
self.moyGeneral = getMoyGeneral()
}
public func updateNoteModule(ueVM: UeVM, moduleVM:ModuleVM){
for obj in ueList{
if obj.id == ueVM.id{
obj.updateModule(modulVM: moduleVM)
}
}
self.moyGeneral = getMoyGeneral()
}

@ -29,4 +29,11 @@ class ModuleVM : ObservableObject{
self.coef = module.coef
self.note = module.note
}
public func updateModule(name:String,coef:Int,note:Double?){
self.moduleName = name
self.coef = coef
self.note = note
}
}

@ -35,23 +35,24 @@ class UeVM:ObservableObject{
}
public init(id: UUID, ueName: String, coef: Int, note: Double? = nil, modules: [ModuleVM]) {
public init(id: UUID, ueName: String, coef: Int, modules: [ModuleVM]) {
self.id = id
self.ueName = ueName
self.coef = coef
self.note = note
self.moduleVMs = modules
self.note = calculMoy()
}
public init (ue: UE){
id = ue.id
ueName = ue.ueName
coef = ue.coef
note = ue.note
//note = ue.note
moduleVMs=[]
for module in ue.modules {
moduleVMs.append(ModuleVM(module: module))
}
self.note = calculMoy()
}
@ -69,4 +70,17 @@ class UeVM:ObservableObject{
return moduleVMs.firstIndex(where: {$0.id == id})
}
public func updateModule(modulVM: ModuleVM){
for obj in moduleVMs{
if obj.id == modulVM.id{
obj.updateModule(name: modulVM.moduleName, coef: modulVM.coef, note: modulVM.note)
self.note = calculMoy()
}
}
}
}

@ -62,6 +62,8 @@ struct ModuleView: View {
newValue in
if editable{
moduleVM.note = newValue
ueVm.updateModule(modulVM: moduleVM)
managerVm.updateNoteModule(ueVM: ueVm, moduleVM: moduleVM)
}
} ),

@ -0,0 +1,50 @@
//
// UeDetails.swift
// CalculMoy
//
// Created by etudiant on 13/06/2023.
//
import SwiftUI
struct UeDetails: View {
@ObservedObject var managerVM: ManagerVM
@ObservedObject var ue:UeVM
var body: some View {
VStack(alignment: .leading){
Text(ue.ueName)
.font(.title)
.padding(.bottom)
UEView(ueVm: ue, managerVm: managerVM)
Divider()
ScrollView{
ForEach (0..<ue.moduleVMs.count){module in
//Text(managerVM.ueList[ue].ueName)
ModuleView(moduleVM: ue.moduleVMs[module], ueVm: ue, managerVm: managerVM)
}
}
}.padding()
}
}
struct UeDetails_Previews: PreviewProvider {
static var managerData:ManagerVM=ManagerVM(
manager: Manager(ues: Stub.uesData)
)
static var previews: some View {
UeDetails(managerVM: managerData,ue: managerData.ueList[0])
}
}

@ -0,0 +1,78 @@
//
// UesList.swift
// CalculMoy
//
// Created by etudiant on 13/06/2023.
//
import SwiftUI
struct UesList: View {
@ObservedObject var managerVM: ManagerVM
var body: some View {
NavigationStack{
ScrollView(){
VStack(alignment: .leading){
Text("Blocs")
.font(.title)
.padding(.bottom)
Text("Vous devez avoir la moyenne à chacun de ces blocs pour avoir votre diplôme.")
.font(.subheadline)
.padding(.bottom)
if let moyGen = managerVM.getMoyGeneral(){
HStack {
Text("Total")
Spacer()
Text(String(format: "%.2f",moyGen))
Image(systemName: moyGen >= 10 ? "graduationcap.fill" : "exclamationmark.bubble.fill")
}
}else{
Text("noData")
}
}.padding()
VStack(alignment: .leading){
Text("UEs")
.font(.title)
.padding(.bottom)
// for ue in managerVM.ueList {
// Text(ue.ueName)
// }
ForEach (0..<managerVM.ueList.count){ue in
//Text(managerVM.ueList[ue].ueName)
NavigationLink(destination:
UeDetails(managerVM: managerVM,ue: managerVM.ueList[ue])
){
UEView(ueVm: managerVM.ueList[ue], managerVm: managerVM)
}
}
}.padding()
}.navigationTitle("Calculette")
}
}
}
struct UesList_Previews: PreviewProvider {
static var managerData:ManagerVM=ManagerVM(
manager: Manager(ues: Stub.uesData)
)
static var previews: some View {
UesList(managerVM: managerData)
}
}
Loading…
Cancel
Save