parent
21658f0136
commit
2011f97927
@ -1,29 +0,0 @@
|
||||
//
|
||||
// Manager.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 10/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public struct Manager {
|
||||
let dataManager: DataManager
|
||||
public var ues: [UE] = []
|
||||
|
||||
public init(withDataManager dataManager: DataManager){
|
||||
self.dataManager = dataManager
|
||||
}
|
||||
|
||||
public mutating func loadUes() {
|
||||
self.ues.removeAll()
|
||||
for ue in self.dataManager.loadUes() {
|
||||
self.ues.append(ue)
|
||||
}
|
||||
}
|
||||
|
||||
public func saveUes() {
|
||||
self.dataManager.save(ues:self.ues)
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// BlocCollection.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
struct BlocCollection : Identifiable, Equatable {
|
||||
|
||||
|
||||
var id : UUID
|
||||
|
||||
|
||||
var blocs: [Bloc]
|
||||
|
||||
init(blocs: [Bloc]) {
|
||||
self.id = UUID()
|
||||
self.blocs = blocs
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// MatiereCollection.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
struct MatiereCollection : Identifiable, Equatable{
|
||||
static func == (lhs: MatiereCollection, rhs: MatiereCollection) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
var id : UUID
|
||||
|
||||
var nom: String
|
||||
var matieres: [Matiere]
|
||||
|
||||
init(nom: String, matieres: [Matiere]) {
|
||||
self.id = UUID()
|
||||
self.nom = nom
|
||||
self.matieres = matieres
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// UeCollection.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
struct UeCollection : Identifiable, Equatable {
|
||||
|
||||
public static func == (lhs: UeCollection, rhs: UeCollection) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
var id : UUID
|
||||
|
||||
var nom: String
|
||||
var ues: [Ue]
|
||||
|
||||
init(nom: String, ues: [Ue]) {
|
||||
self.id = UUID()
|
||||
self.nom = nom
|
||||
self.ues = ues
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// NoteColor.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
public struct NoteColor{
|
||||
public let ue_back = Color("background_UE")
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// BlocCollectionVM.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
class BlocCollectionVM : ObservableObject,Identifiable,Equatable {
|
||||
static func == (lhs: BlocCollectionVM, rhs: BlocCollectionVM) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
|
||||
|
||||
public var id: UUID { model.id }
|
||||
|
||||
|
||||
|
||||
@Published var model : BlocCollection = BlocCollection( blocs: []){
|
||||
didSet{
|
||||
|
||||
if !self.model.blocs.compare(to: self.someBlocVM.map({$0.model})){
|
||||
|
||||
self.someBlocVM = self.model.blocs.map({BlocVM(withBloc: $0)})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Published var someBlocVM: [BlocVM] = [] {
|
||||
didSet {
|
||||
let someModelBlocs = self.someBlocVM.map({$0.model})
|
||||
if !self.model.blocs.compare(to: someModelBlocs) {
|
||||
self.model.blocs = someBlocVM.map({$0.model})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init(withbloc blocs : BlocCollection) {
|
||||
self.model = blocs
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
//
|
||||
// CollectionVMUe.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class CollectionVMUe : ObservableObject,Identifiable,Equatable {
|
||||
static func == (lhs: CollectionVMUe, rhs: CollectionVMUe) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
public var id: UUID { model.id }
|
||||
|
||||
|
||||
|
||||
@Published var model : UeCollection = UeCollection(nom: "", ues: []){
|
||||
didSet{
|
||||
if self.model.nom != self.nom {
|
||||
self.nom = self.model.nom
|
||||
}
|
||||
if !self.model.ues.compare(to: self.someUesVM.map({$0.model})){
|
||||
self.someUesVM = self.model.ues.map({UeVM(withUe: $0)})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published var nom: String = "" {
|
||||
didSet {
|
||||
if self.model.nom != self.nom {
|
||||
self.model.nom = self.nom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published var someUesVM: [UeVM] = [] {
|
||||
didSet {
|
||||
let someModelUe = self.someUesVM.map({$0.model})
|
||||
if !self.model.ues.compare(to: someModelUe) {
|
||||
self.model.ues = someUesVM.map({$0.model})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init(withUe ues : UeCollection) {
|
||||
self.model = ues
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
//
|
||||
// ManagerVM.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 11/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class ManagerVM: ObservableObject, Hashable {
|
||||
|
||||
static func == (lhs: ManagerVM, rhs: ManagerVM) -> Bool {
|
||||
lhs.blocs.compare(to: rhs.blocs)
|
||||
}
|
||||
|
||||
@Published var blocs: [BlocVM]
|
||||
|
||||
// abonnée
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine("manager")
|
||||
}
|
||||
|
||||
func onNotifyChanged(source:BlocVM){
|
||||
self.objectWillChange.send()
|
||||
}
|
||||
|
||||
public init(withBloc blocs: [Bloc]){
|
||||
self.blocs = blocs.map({BlocVM(withBloc: $0)})
|
||||
self.blocs.forEach { blocvm in
|
||||
blocvm.subscribe(with: self, andWithFunction: onNotifyChanged(source:))
|
||||
}
|
||||
}
|
||||
|
||||
var total : Double {
|
||||
return Double(blocs.reduce(0) { $0 + $1.totalMoyenne }) / Double(blocs.count)
|
||||
}
|
||||
|
||||
public init(withBlocs blocs: [BlocVM]){
|
||||
self.blocs = blocs
|
||||
self.blocs.forEach { blocvm in
|
||||
blocvm.subscribe(with: self, andWithFunction: onNotifyChanged(source:))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
//
|
||||
// ManagerVM.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 11/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//pouvoir les utiliser dans la vue
|
||||
class ManagerVM: ObservableObject {
|
||||
@Published var blocs: [BlocVm] = []
|
||||
|
||||
public init(withBeds blocs: [BlocModel]){
|
||||
self.blocs = blocs.map({BlocVm(withModel: $0)})
|
||||
}
|
||||
|
||||
public init(withBeds blocs: [BlocVm]){
|
||||
self.blocs = blocs
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
//
|
||||
// MatiereCollectionVM.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class MatiereCollectionVM : ObservableObject,Identifiable,Equatable {
|
||||
static func == (lhs: MatiereCollectionVM, rhs: MatiereCollectionVM) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
public var id: UUID { model.id }
|
||||
|
||||
/*
|
||||
var id : UUID
|
||||
|
||||
var nom: String
|
||||
var matieres: [Matiere]
|
||||
*/
|
||||
|
||||
@Published var model : MatiereCollection = MatiereCollection(nom: "", matieres: []){
|
||||
didSet{
|
||||
if self.model.nom != self.nom {
|
||||
self.nom = self.model.nom
|
||||
}
|
||||
if !self.model.matieres.compare(to: self.someMatieresVM.map({$0.model})){
|
||||
self.someMatieresVM = self.model.matieres.map({MatiereVM(withMat: $0)})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published var nom: String = "" {
|
||||
didSet {
|
||||
if self.model.nom != self.nom {
|
||||
self.model.nom = self.nom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published var someMatieresVM: [MatiereVM] = [] {
|
||||
didSet {
|
||||
let someModelMatiere = self.someMatieresVM.map({$0.model})
|
||||
if !self.model.matieres.compare(to: someModelMatiere){
|
||||
self.model.matieres = someMatieresVM.map({$0.model})
|
||||
}
|
||||
print("vjgjjh")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init(withMat matieres : MatiereCollection) {
|
||||
self.model = matieres
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// AddSheet.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AddSheet: View {
|
||||
@ObservedObject var mat : MatiereVM
|
||||
var body: some View {
|
||||
VStack{
|
||||
HStack{
|
||||
Text("Nom : ")
|
||||
TextField("Description", text: $mat.name)
|
||||
}
|
||||
HStack{
|
||||
Text("Coef : ")
|
||||
TextField("Coefficient", value: $mat.coef, format: .number)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct AddSheet_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddSheet(mat: MatiereVM())
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
//
|
||||
// BlocView.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 25/05/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct BlocView: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Label("Blocs", systemImage: "doc.on.doc.fill")
|
||||
.font(.title)
|
||||
Text("Vous devez avoir la moyenne à chacun de ces blocs pour avoir votre diplôme.")
|
||||
HStack {
|
||||
Label("Total", systemImage: "doc.on.doc.fill")
|
||||
Spacer()
|
||||
Label("11.67", systemImage: "graduationcap.circle.fill")
|
||||
}
|
||||
HStack {
|
||||
Label("Total", systemImage: "doc.on.doc.fill")
|
||||
Spacer()
|
||||
Label("11.67", systemImage: "graduationcap.circle.fill")
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.background(Color("ListItemBackgroundColor"))
|
||||
.cornerRadius(12)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct BlocView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
BlocView()
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Block.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
|
||||
import SwiftUI
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct Block: View {
|
||||
|
||||
@ObservedObject var manager : ManagerVM
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
|
||||
HStack {
|
||||
Image(systemName: "menucard.fill")
|
||||
Text("Blocs").bold().font(.title)
|
||||
}
|
||||
|
||||
Text("Vous devez avoir la moyenne à chacun de ces blocs pour avoir votre diplôme.").padding(.bottom)
|
||||
BlockItem(total: .constant( manager.total), name: .constant("Total"))
|
||||
|
||||
ForEach(manager.blocs) { item in
|
||||
if item.isUnique {
|
||||
BlockItem(total: .constant(item.totalMoyenne), name: .constant(item.nom))
|
||||
Divider()
|
||||
}
|
||||
|
||||
}
|
||||
}.padding().background(NoteColor().ue_back).cornerRadius(10)
|
||||
}
|
||||
}
|
||||
struct Block_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let blocs = [
|
||||
BlocVM(withBloc: Bloc(nom: "Total", ues:DataStub().load(),isUq: false)),
|
||||
BlocVM(withBloc: Bloc(nom: "Projet", ues: DataStub().loadUeStage_Proj(), isUq: true))]
|
||||
Block(manager: ManagerVM(withBlocs: blocs) )
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
//
|
||||
// BlockItem.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 20/06/2023.
|
||||
//
|
||||
import SwiftUI
|
||||
|
||||
struct BlockItem: View {
|
||||
@Binding var total : Double
|
||||
@Binding var name : String
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 15) {
|
||||
Grid{
|
||||
GridRow {
|
||||
Image(systemName: "rectangle.on.rectangle")
|
||||
Text(self.name).font(.title3)
|
||||
Text( self.total,format: .number)
|
||||
|
||||
Image(systemName: "graduationcap.circle.fill")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct BlockItem_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
BlockItem(total: .constant( 12.9), name: .constant( "Total"))
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,93 @@
|
||||
//
|
||||
// EditSheet.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct EditSheet : View{
|
||||
@ObservedObject var ue: UeVM
|
||||
@Binding var isEditMode: Bool
|
||||
var body: some View {
|
||||
|
||||
NavigationView {
|
||||
|
||||
VStack{
|
||||
Section(header: Text("UE Info").font(.title))
|
||||
{
|
||||
VStack{
|
||||
TextField("Description", text: $ue.nom)
|
||||
TextField("Coefficient", value: $ue.coef, format: .number)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Divider()
|
||||
Section(header: Text("Matieres").font(.title)) {
|
||||
ForEach(ue.someMatieresVM) { matiere in
|
||||
HStack{
|
||||
MatiereEditView(matiere: matiere)
|
||||
Button(action: {
|
||||
self.ue.onDeleted(matiere)
|
||||
}){
|
||||
Text("Supprimer")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Spacer()
|
||||
Button(action: {
|
||||
self.ue.onAdding()
|
||||
}) {
|
||||
Text("Ajouter une matiere")
|
||||
}
|
||||
}
|
||||
}.padding().background(NoteColor().ue_back)
|
||||
|
||||
}
|
||||
.navigationBarItems(trailing:
|
||||
Button(action: {
|
||||
self.ue.onEdited()
|
||||
}) {
|
||||
Text( self.ue.isEditing ? "Done" : "Modifier")
|
||||
})
|
||||
|
||||
// Feuille d'ajout
|
||||
.sheet(isPresented: $ue.isAdding){
|
||||
NavigationStack{
|
||||
|
||||
AddSheet(mat: self.ue.addedItem ?? MatiereVM())
|
||||
|
||||
.toolbar{
|
||||
ToolbarItem(id: "Ajouter", placement: .confirmationAction){
|
||||
Button(action: {
|
||||
self.ue.onAdded()
|
||||
}){
|
||||
Text("Add")
|
||||
}
|
||||
}
|
||||
ToolbarItem(id: "cancel", placement: .cancellationAction){
|
||||
Button(action: {
|
||||
self.ue.onAdded(isCancelled: true)
|
||||
}){
|
||||
Text("Cancel")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationBarTitle("Ajout d'une nouvelle matière")
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
struct EditSheet_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let uevm : UeVM = UeVM(withUe: DataStub().ue_proj)
|
||||
EditSheet(ue: uevm, isEditMode: .constant(true))
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
//
|
||||
// EditableView.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 10/06/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
|
||||
struct EditableView: View {
|
||||
@ObservedObject var editableUe:UeVm
|
||||
@State var isEditing: Bool = false
|
||||
var body: some View {
|
||||
NavigationStack{
|
||||
Form{
|
||||
NavigationLink{
|
||||
Form{
|
||||
TextField("", text: $editableUe.nom, prompt: Text("enter the name"))
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle("Name")
|
||||
}
|
||||
label: {
|
||||
HStack{
|
||||
Text("Name")
|
||||
Spacer()
|
||||
Text(editableUe.nom)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
NavigationLink{
|
||||
Form{
|
||||
TextField("", value: $editableUe.coefficient, format: .number, prompt: Text("enter the COEF"))
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle("enter the COEFt")
|
||||
}
|
||||
label: {
|
||||
HStack{
|
||||
Text("enter the COEFt")
|
||||
Spacer()
|
||||
Text(String(editableUe.coefficient))
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
NavigationLink{
|
||||
Form{
|
||||
TextField("", value: $editableUe.moyenne, format: .number, prompt: Text("enter the NOTE"))
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle("enter the NOTE")
|
||||
}
|
||||
label: {
|
||||
HStack{
|
||||
Text("enter the NOTE")
|
||||
Spacer()
|
||||
Text(String(editableUe.moyenne))
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EditableView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let ueee = Stub().loadUes()[0]
|
||||
EditableView(editableUe:UeVm(withModel:ueee))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
//
|
||||
// Home.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct Home: View {
|
||||
// @State public var ues = DataStub().load()
|
||||
@StateObject var manager: ManagerVM
|
||||
var body: some View {
|
||||
NavigationView{
|
||||
|
||||
VStack(alignment : .leading){
|
||||
|
||||
HStack {
|
||||
|
||||
Text("Calculette").bold().font(.title)
|
||||
}
|
||||
Block(manager: manager )
|
||||
VStack(alignment : .leading){
|
||||
HStack(alignment:.bottom){
|
||||
Image(systemName: "menucard.fill")
|
||||
Text("UEs").bold().font(.title)
|
||||
}.padding()
|
||||
|
||||
ScrollView{
|
||||
ForEach(manager.blocs) { item in
|
||||
ForEach(item.someUesVM) {
|
||||
ue in
|
||||
|
||||
UeView(bloc: item, ue: ue)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}.padding().background(NoteColor().ue_back).cornerRadius(10)
|
||||
|
||||
|
||||
}.padding()
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct Home_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let managerVM = ManagerVM(withBlocs: [BlocVM(withBloc: Bloc(nom: "Total", ues: DataStub().load(), isUq: false)),BlocVM(withBloc: Bloc(nom: "Projet", ues: DataStub().loadUeStage_Proj(),isUq: true))])
|
||||
Home(manager: managerVM )
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
//
|
||||
// HomeView.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/05/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HomeView: View{
|
||||
|
||||
var body: some View {
|
||||
Text("Calculatrice ")
|
||||
.font(.headline)
|
||||
.padding(.trailing, 20)
|
||||
.font(.headline)
|
||||
.foregroundColor(.blue)
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HomeView()
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
//
|
||||
// ListUe.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 25/05/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ListUe: View {
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack(alignment: .leading) {
|
||||
Label("UEs", systemImage: "doc.fill")
|
||||
.font(.title)
|
||||
Text("Détails des UEs")
|
||||
LazyVStack {
|
||||
HStack {
|
||||
UeView(blocs: BlocVm(withModel: BlocModel(Nombloc: "HST", Moyenneg: 14, listeUE: [])))
|
||||
Divider()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.padding()
|
||||
.background(Color("ListItemBackgroundColor"))
|
||||
.cornerRadius(12)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct ListUe_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ListUe()
|
||||
}
|
||||
}}
|
@ -0,0 +1,98 @@
|
||||
//
|
||||
// CapsuleMatiere.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
|
||||
|
||||
struct ExpandingCapsuleViewMatiere : View{
|
||||
@ObservedObject var matiere : MatiereVM
|
||||
@ObservedObject var ue : UeVM
|
||||
@ObservedObject var bloc : BlocVM
|
||||
var islock : Bool = true
|
||||
@GestureState private var dragState = DragState.inactive
|
||||
@State private var capsuleWidth: CGFloat = 25.0
|
||||
var widthMax = 100.0
|
||||
var widthMin = 5.0
|
||||
enum DragState {
|
||||
case inactive
|
||||
case dragging(translation: CGSize)
|
||||
|
||||
var translation: CGSize {
|
||||
switch self {
|
||||
case .inactive:
|
||||
return .zero
|
||||
case .dragging(let translation):
|
||||
return translation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public var body: some View {
|
||||
let dragGesture = DragGesture()
|
||||
|
||||
.onEnded { value in
|
||||
let dragThreshold: CGFloat = 0.02
|
||||
let dragTranslation = value.translation.width
|
||||
|
||||
if CGFloat(matiere.moyenne)*5 <= 100 {
|
||||
if dragTranslation > dragThreshold {
|
||||
capsuleWidth += (dragTranslation - dragThreshold)
|
||||
updateMoy()
|
||||
// print(capsuleWidth/5)
|
||||
} else if dragTranslation < -dragThreshold {
|
||||
|
||||
capsuleWidth = dragTranslation/5 - dragThreshold
|
||||
updateMoy()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return GeometryReader { geometry in
|
||||
Capsule()
|
||||
.frame(width: Double(matiere.moyenne * 5) >= widthMax ? 100.0 : CGFloat(matiere.moyenne) * 5 + 2 , height: 22)
|
||||
.foregroundColor(CGFloat(matiere.moyenne) * 5 < 50 ? .red : .green)
|
||||
.gesture( islock ? DragGesture().onEnded({_ in }) : dragGesture)
|
||||
.animation(.spring())
|
||||
.offset(x: dragState.translation.width, y: 0)
|
||||
.onAppear {
|
||||
// Set initial capsule width
|
||||
capsuleWidth = min(geometry.size.width, geometry.size.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updateMoy(){
|
||||
self.matiere.moyenne += Float(capsuleWidth) / 5
|
||||
if matiere.moyenne > 20 { matiere.moyenne = 20 }
|
||||
if matiere.moyenne < 0 { matiere.moyenne = 0 }
|
||||
ue.totalMoyenne = ue.updateTotalMoyenne()
|
||||
bloc.totalMoyenne = bloc.updateTotalMoyenne()
|
||||
|
||||
|
||||
|
||||
print(bloc.nom)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
struct CapsuleMatiere_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
|
||||
ExpandingCapsuleViewMatiere(matiere: MatiereVM(withMat: Matiere(name: "Projet", moy: 12, coef: 9)),ue: UeVM(withUe: DataStub().loadUeStage_Proj()[0]),
|
||||
bloc: BlocVM(withBloc: Bloc(nom: "", ues: DataStub().loadUeStage_Proj(), isUq: true)) )
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
// MatiereUniq.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 30/05/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MatiereUniq: View {
|
||||
//1 changement avec Vm
|
||||
@ObservedObject var mat: MatiereVm
|
||||
@State private var islocked = true
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text(mat.nom)
|
||||
.font(.title2)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(mat.coefficient)")
|
||||
.font(.title2)
|
||||
.padding(.horizontal, 30.0)
|
||||
}
|
||||
.padding(.horizontal, 11.0)
|
||||
|
||||
HStack {
|
||||
Button(action: {
|
||||
islocked.toggle()
|
||||
}) {
|
||||
Image(systemName: islocked ? "lock" : "lock.open")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
|
||||
GeometryReader { geometry in
|
||||
HStack {
|
||||
Capsule()
|
||||
.fill(mat.note < 10 ? .red : .blue)
|
||||
.frame(height: 20)
|
||||
.frame(width: CGFloat(mat.note) / 30 * geometry.size.width)
|
||||
.gesture(
|
||||
islocked ? DragGesture(minimumDistance: 0).onChanged({_ in })
|
||||
: DragGesture(minimumDistance: 23)
|
||||
.onChanged({ value in
|
||||
let newNote = value.location.x / geometry.size.width * 20
|
||||
mat.note = min(max(newNote, 0), 20)
|
||||
})
|
||||
)
|
||||
|
||||
Text("\(Double(mat.note))")
|
||||
|
||||
if !islocked {
|
||||
Image("gouffle")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MatiereUniq_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MatiereUniq(mat: MatiereVm(withModel: Matiere(id: UUID(), nom: "JAVA", coefficient: 6, note: 19)))
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
//
|
||||
// MatiereUi.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct MatiereUnq: View{
|
||||
@ObservedObject var matiere : MatiereVM
|
||||
@ObservedObject var ue : UeVM
|
||||
@ObservedObject var bloc : BlocVM
|
||||
@State var islocked : Bool = true
|
||||
var body: some View {
|
||||
VStack(alignment:.leading){
|
||||
Divider()
|
||||
HStack(spacing: 20){
|
||||
Text(matiere.name ).bold().font(.caption).padding()
|
||||
}
|
||||
|
||||
|
||||
HStack(spacing: 15){
|
||||
Button(action: {
|
||||
if self.matiere.isEditing {
|
||||
|
||||
self.matiere.onEdited(isCancelled: true)
|
||||
print(self.matiere.moyenne)
|
||||
|
||||
} else {
|
||||
self.matiere.onEditing()
|
||||
|
||||
}
|
||||
}) {
|
||||
|
||||
Image(systemName: !matiere.isEditing ? "lock.fill" : "lock.open.fill")
|
||||
}
|
||||
ExpandingCapsuleViewMatiere(matiere: matiere, ue : ue, bloc : bloc ,islock: !matiere.isEditing).frame(width:50,height: 20)
|
||||
|
||||
Spacer()
|
||||
Text(matiere.moyenne.description)
|
||||
|
||||
Spacer()
|
||||
Text(matiere.coef.description)
|
||||
|
||||
}
|
||||
|
||||
}.padding()
|
||||
}
|
||||
}
|
||||
|
||||
struct MatiereUnq_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MatiereUnq(matiere: MatiereVM(withMat: Matiere(name : "Projet",moy: 12, coef: 9)), ue: UeVM(withUe: DataStub().loadUeStage_Proj()[0]),
|
||||
bloc: BlocVM(withBloc: Bloc(nom: "", ues: DataStub().loadUeStage_Proj(), isUq: true)),
|
||||
islocked: true)
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
|
||||
struct MatiereView: View {
|
||||
@ObservedObject var ue : UeVm
|
||||
@State var isEditing: Bool = false
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading) {
|
||||
|
||||
Label("Coefficient :\(ue.coefficient)", systemImage: "xmark.circle.fill")
|
||||
Label("Détails des notes: ", systemImage: "note.text")
|
||||
}
|
||||
VStack {
|
||||
ForEach(ue.someMatVM) { matiere in
|
||||
MatiereUniq(mat: matiere)
|
||||
}
|
||||
}
|
||||
.toolbar{
|
||||
Button(action: {
|
||||
self.isEditing.toggle()
|
||||
}){
|
||||
Text("Edit")
|
||||
}
|
||||
}
|
||||
|
||||
.sheet(isPresented: $isEditing){
|
||||
NavigationStack{
|
||||
EditableView(editableUe: ue)
|
||||
.toolbar{
|
||||
ToolbarItem(id: "done", placement: .confirmationAction){
|
||||
Button(action: {
|
||||
self.isEditing.toggle()
|
||||
}){
|
||||
Text("Done")
|
||||
}
|
||||
}
|
||||
ToolbarItem(id: "cancel", placement: .cancellationAction){
|
||||
Button(action: {
|
||||
self.isEditing.toggle()
|
||||
}){
|
||||
Text("Cancel")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Edit: \(ue.nom)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MatiereView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MatiereView(ue: UeVm(withModel: UE(id: UUID(), coefficient: 2, moyenne: 16, nom: "MAT", listeMatiere: [])))
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
//
|
||||
// Note.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 08/06/2023.
|
||||
//
|
||||
|
||||
//
|
||||
// NoteInfo.swift
|
||||
// App
|
||||
//
|
||||
// Created by BREUIL Yohann on 26/05/2023.
|
||||
//
|
||||
|
||||
/*import SwiftUI
|
||||
|
||||
struct NoteInfo: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
|
||||
MatiereView(ue: <#UeVm#> )
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NoteInfo_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NoteInfo()
|
||||
}
|
||||
}*/
|
@ -0,0 +1,91 @@
|
||||
//
|
||||
// CapsuleUe.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
struct ExpandingCapsuleView : View{
|
||||
@ObservedObject var ue : UeVM
|
||||
@GestureState private var dragState = DragState.inactive
|
||||
@State private var capsuleWidth: CGFloat = 5.0
|
||||
private var widthMax = 100.0
|
||||
private var widthMin = 5.0
|
||||
private enum DragState {
|
||||
case inactive
|
||||
case dragging(translation: CGSize)
|
||||
|
||||
var translation: CGSize {
|
||||
switch self {
|
||||
case .inactive:
|
||||
return .zero
|
||||
case .dragging(let translation):
|
||||
return translation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
init(ue: UeVM) {
|
||||
self.ue = ue
|
||||
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let dragGesture = DragGesture()
|
||||
|
||||
.onEnded { value in
|
||||
let dragThreshold: CGFloat = 1.005
|
||||
let dragTranslation = value.translation.width
|
||||
|
||||
if dragTranslation > dragThreshold {
|
||||
|
||||
|
||||
capsuleWidth += dragTranslation - dragThreshold
|
||||
updateMoy()
|
||||
|
||||
} else if dragTranslation < -dragThreshold {
|
||||
|
||||
capsuleWidth -= abs(dragTranslation) - dragThreshold
|
||||
updateMoy()
|
||||
}
|
||||
}
|
||||
|
||||
return GeometryReader { geometry in
|
||||
Capsule()
|
||||
.frame(width: capsuleWidth >= widthMax ? 100.0 : capsuleWidth , height: 30)
|
||||
.foregroundColor(.blue)
|
||||
.gesture(dragGesture)
|
||||
.animation(.spring())
|
||||
.offset(x: dragState.translation.width, y: 0)
|
||||
.onAppear {
|
||||
// Set initial capsule width
|
||||
capsuleWidth = min(geometry.size.width, geometry.size.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updateMoy(){
|
||||
var da = ue.model.totalMoyenne * capsuleWidth / 100
|
||||
ue.model.coef = ue.model.coef + 1
|
||||
print(da)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
struct CapsuleV_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
|
||||
|
||||
ExpandingCapsuleView(ue : UeVM(withUe: Ue( nom: "UE 2", matieres: DataStub().loadMartiereUE2(),coef: 9)))
|
||||
}
|
||||
}
|
@ -1,45 +1,45 @@
|
||||
import SwiftUI
|
||||
|
||||
|
||||
struct UeView: View {
|
||||
|
||||
@ObservedObject var blocs : BlocVm
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ForEach(blocs.someUeVM) { ue in
|
||||
HStack {
|
||||
Text(ue.nom)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
Text("\(ue.coefficient)")
|
||||
NavigationLink(destination: MatiereView(ue: UeVm(withModel: UE(id: UUID(), coefficient: 4, moyenne: 3, nom: "HST", listeMatiere: [])) )) {
|
||||
Image(systemName: "square.and.pencil")
|
||||
}
|
||||
.foregroundColor(.blue)
|
||||
}
|
||||
.padding(.bottom, 10)
|
||||
HStack {
|
||||
Capsule()
|
||||
.fill(ue.moyenne < 10 ? .red : .blue)
|
||||
.frame(height: 20)
|
||||
.frame(width: CGFloat(ue.moyenne) * 10)
|
||||
.background(Color.clear)
|
||||
Text("\(ue.moyenne)")
|
||||
}
|
||||
.padding()
|
||||
|
||||
Divider()
|
||||
public struct UeView : View{
|
||||
@ObservedObject var bloc : BlocVM
|
||||
@ObservedObject var ue : UeVM
|
||||
public var body: some View {
|
||||
|
||||
VStack(alignment:.leading){
|
||||
|
||||
Divider()
|
||||
HStack(spacing: 20){
|
||||
Text(ue.nom ).bold().font(.caption).padding()
|
||||
Spacer()
|
||||
Text(ue.coef.description)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
||||
|
||||
HStack(){
|
||||
Capsule().foregroundColor( ue.totalMoyenne * 5 < 50 ? .red : .green).frame(width: ue.totalMoyenne * 5 ,height: 22)
|
||||
Spacer()
|
||||
Text(ue.totalMoyenne.description)
|
||||
Spacer()
|
||||
NavigationLink(destination: Uee(ue: ue, bloc: bloc)) {
|
||||
Image(systemName: "square.and.pencil")
|
||||
}
|
||||
}
|
||||
Divider()
|
||||
|
||||
|
||||
}.padding()
|
||||
}
|
||||
}
|
||||
|
||||
struct UeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
UeView(blocs: BlocVm(withModel: BlocModel(Nombloc: "ANG", Moyenneg: 12, listeUE: [])))
|
||||
}
|
||||
}
|
||||
|
||||
let ue = DataStub().load()[0]
|
||||
let ueVM = UeVM(withUe: ue)
|
||||
|
||||
UeView(bloc: BlocVM(withBloc: Bloc(nom: "Projet/Stage", ues: DataStub().loadUeStage_Proj(),isUq: true)), ue: ueVM)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
//
|
||||
// UePage.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
struct Uee: View {
|
||||
@ObservedObject var ue: UeVM
|
||||
@ObservedObject var bloc: BlocVM
|
||||
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
HStack(spacing: 20) {
|
||||
Text(ue.nom)
|
||||
.bold()
|
||||
.font(.title)
|
||||
}
|
||||
Divider()
|
||||
HStack(spacing: 15) {
|
||||
Capsule()
|
||||
.foregroundColor(ue.totalMoyenne * 5 < 50 ? .red : .green)
|
||||
.frame(width: ue.totalMoyenne * 5, height: 22)
|
||||
Text(ue.coef.description)
|
||||
Text(ue.totalMoyenne.description)
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
ForEach(ue.someMatieresVM) { mat in
|
||||
MatiereUnq(matiere: mat, ue : ue, bloc : bloc, islocked: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
.navigationBarItems(trailing: Button(action: {
|
||||
|
||||
self.ue.onEditing()
|
||||
}) {
|
||||
Text( self.ue.isEditing ? "Done" : "Modifier")
|
||||
})
|
||||
.sheet(isPresented: $ue.isEditing) {
|
||||
EditSheet(ue: ue, isEditMode: $ue.isAdding)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
//
|
||||
// VuePrincipale.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 25/05/2023.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct VuePrincipale: View {
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ScrollView {
|
||||
BlocView()
|
||||
Divider()
|
||||
ListUe()
|
||||
}
|
||||
.navigationTitle("Calculette")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VuePrincipale_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VuePrincipale()
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
//
|
||||
// edit.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 23/06/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct edit: View {
|
||||
@Binding public var ue : Ue
|
||||
|
||||
var body: some View {
|
||||
NavigationView{
|
||||
VStack{
|
||||
Text(ue.nom)
|
||||
TextField("name", text:$ue.nom )
|
||||
}
|
||||
}.toolbar{
|
||||
Button(action: {
|
||||
|
||||
}) {
|
||||
|
||||
Image(systemName: "square.and.pencil")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
//
|
||||
// stbmat.swift
|
||||
// SwiftMvvm
|
||||
//
|
||||
// Created by etudiant on 30/05/2023.
|
||||
//
|
||||
|
||||
/*import SwiftUI
|
||||
|
||||
/*struct stbmat: View {
|
||||
let matieres: [Matiere] = [
|
||||
Matiere(id: UUID(), nom: "Mathématiques", coefficient: 2.0, note: 15.0),
|
||||
Matiere(id: UUID(), nom: "Physique", coefficient: 1.5, note: 12.0),
|
||||
Matiere(id: UUID(), nom: "Chimie", coefficient: 1.0, note: 10.5)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ForEach(matieres) { matiere in
|
||||
MatiereUniq(mat: matiere)
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/*/
|
Loading…
Reference in new issue