parent
ff1349aa13
commit
5cf7e4c4a1
@ -1,17 +1,12 @@
|
|||||||
//
|
|
||||||
// AppApp.swift
|
|
||||||
// App
|
|
||||||
//
|
|
||||||
// Created by BREUIL Yohann on 24/05/2023.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import ViewModel
|
||||||
|
import Stub
|
||||||
|
|
||||||
@main
|
@main
|
||||||
struct AppApp: App {
|
struct AppApp: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView()
|
ContentView(odin: OdinVM(blocs: Stub().loadBlocs()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
//
|
|
||||||
// ContentView.swift
|
|
||||||
// App
|
|
||||||
//
|
|
||||||
// Created by BREUIL Yohann on 24/05/2023.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import ViewModel
|
||||||
|
import Stub
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
|
@StateObject var odin: OdinVM
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
CalculatorView()
|
NavigationStack {
|
||||||
|
ScrollView {
|
||||||
|
BlocListItem(odin: odin)
|
||||||
|
Divider()
|
||||||
|
UEListItem(odin: odin)
|
||||||
|
}
|
||||||
|
.navigationTitle("Calculette")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ContentView()
|
let odinVM = OdinVM(blocs: Stub().loadBlocs())
|
||||||
|
|
||||||
|
ContentView(odin: odinVM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct CalculatorView: View {
|
|
||||||
var body: some View {
|
|
||||||
NavigationStack {
|
|
||||||
ScrollView {
|
|
||||||
BlocListItem()
|
|
||||||
Divider()
|
|
||||||
UEListItem()
|
|
||||||
}
|
|
||||||
.navigationTitle("Calculette")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CalculatorView_Previews: PreviewProvider {
|
|
||||||
static var previews: some View {
|
|
||||||
CalculatorView()
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// Exemple.swift
|
||||||
|
// App
|
||||||
|
//
|
||||||
|
// Created by BREUIL Yohann on 17/06/2023.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct Exemple: View {
|
||||||
|
var body: some View {
|
||||||
|
@State var number = 100
|
||||||
|
Form{
|
||||||
|
TextField("inputNumber",value:$number,format: .number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Exemple_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
Exemple()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import Stub
|
||||||
|
import ViewModel
|
||||||
|
|
||||||
|
struct MatiereInfo: View {
|
||||||
|
@StateObject var matiereVM: MatiereVM
|
||||||
|
|
||||||
|
var canEdit: Bool
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
HStack() {
|
||||||
|
Text("\(matiereVM.name)")
|
||||||
|
Spacer()
|
||||||
|
Text("\(matiereVM.factor)")
|
||||||
|
}
|
||||||
|
MatiereNoteSlider(matiereVM: matiereVM, canEdit: canEdit)
|
||||||
|
Divider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MatiereInfo_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
let odin = OdinVM(blocs: Stub().loadBlocs())
|
||||||
|
let matiereVM = odin.blocsVM[0].uesVM[0].matieresVM[0]
|
||||||
|
|
||||||
|
MatiereInfo(matiereVM: matiereVM, canEdit: true)
|
||||||
|
//NoteInfo(canEdit: false)
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
//
|
|
||||||
// NoteInfo.swift
|
|
||||||
// App
|
|
||||||
//
|
|
||||||
// Created by BREUIL Yohann on 26/05/2023.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct NoteInfo: View {
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
HStack() {
|
|
||||||
Text("Qualité de Développement")
|
|
||||||
Spacer()
|
|
||||||
Text("6")
|
|
||||||
}
|
|
||||||
NoteSlider()
|
|
||||||
Divider()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct NoteInfo_Previews: PreviewProvider {
|
|
||||||
static var previews: some View {
|
|
||||||
NoteInfo()
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,81 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import ViewModel
|
||||||
|
import Stub
|
||||||
|
|
||||||
|
struct UEEdit: View {
|
||||||
|
@ObservedObject var ueEditVM : UEVM
|
||||||
|
|
||||||
|
@State var newMatiereName = ""
|
||||||
|
|
||||||
|
@State var number: Int32 = 2
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
Form {
|
||||||
|
Section(header: Text("UE\(String(ueEditVM.number))")) {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("Nom").font(.headline)
|
||||||
|
TextField("Nom", text: $ueEditVM.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("Coefficient").font(.headline)
|
||||||
|
TextField("Coefficient",value: $ueEditVM.factor, format: .number)
|
||||||
|
.keyboardType(.numberPad)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Section(header: Text("Matières")) {
|
||||||
|
ForEach($ueEditVM.matieresVM) { $matiereVM in
|
||||||
|
VStack {
|
||||||
|
TextField("Nom", text: $matiereVM.name)
|
||||||
|
TextField("Coeeficient", value: $matiereVM.factor, format: .number)
|
||||||
|
.keyboardType(.numberPad)
|
||||||
|
}
|
||||||
|
|
||||||
|
.swipeActions(edge:.trailing){
|
||||||
|
Button(role: .destructive) {
|
||||||
|
|
||||||
|
} label: {
|
||||||
|
Label("Delete", systemImage: "trash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
TextField("Nouvelle matière", text: $newMatiereName)
|
||||||
|
Button(action: {}) {
|
||||||
|
Image(systemName: "plus.circle.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.navigationTitle("UE\(String(ueEditVM.number))")
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
|
Button(action: {
|
||||||
|
ueEditVM.onEdited(isCancelled: true)
|
||||||
|
}) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
|
Button(action: {
|
||||||
|
ueEditVM.onEdited()
|
||||||
|
}) {
|
||||||
|
Text("Done")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UEEdit_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
let odin = OdinVM(blocs: Stub().loadBlocs())
|
||||||
|
let ueVM = odin.blocsVM[0].uesVM[0]
|
||||||
|
|
||||||
|
UEEdit(ueEditVM: ueVM)
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,28 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import Stub
|
||||||
|
import ViewModel
|
||||||
|
|
||||||
|
struct UEInfo: View {
|
||||||
|
@StateObject var ueVM: UEVM
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
HStack() {
|
||||||
|
Text("UE\(ueVM.number) \(ueVM.name)")
|
||||||
|
Spacer()
|
||||||
|
Text("\(ueVM.factor)")
|
||||||
|
}
|
||||||
|
UENoteSlider(ueVM: ueVM)
|
||||||
|
Divider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UEInfo_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
let odin = OdinVM(blocs: Stub().loadBlocs())
|
||||||
|
let ueVM = odin.blocsVM[0].uesVM[0]
|
||||||
|
|
||||||
|
UEInfo(ueVM: ueVM)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import Stub
|
||||||
|
import ViewModel
|
||||||
|
|
||||||
|
struct UENoteSlider: View {
|
||||||
|
@StateObject var ueVM: UEVM
|
||||||
|
|
||||||
|
@State private var sliderProgress: CGFloat = 0
|
||||||
|
@State private var sliderWidth: CGFloat = 20
|
||||||
|
@State private var sliderMaxWidth: CGFloat = 220
|
||||||
|
@State private var sliderCurrentWidth: CGFloat = 0
|
||||||
|
|
||||||
|
var drag: some Gesture {
|
||||||
|
DragGesture()
|
||||||
|
.onEnded { _ in
|
||||||
|
sliderWidth = sliderWidth > sliderMaxWidth ? sliderMaxWidth : sliderWidth
|
||||||
|
sliderWidth = sliderWidth >= 0 ? sliderWidth : 20
|
||||||
|
|
||||||
|
sliderCurrentWidth = sliderWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
Rectangle()
|
||||||
|
.fill(ueVM.average < 10 ? Color("BadColor") : Color("GoodColor"))
|
||||||
|
.frame(width: CGFloat(ueVM.average) * 10, height: 25)
|
||||||
|
.clipShape(Capsule())
|
||||||
|
.gesture(drag, including: .none)
|
||||||
|
Spacer()
|
||||||
|
Text("\(String(format: "%.2f", ueVM.average))")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UENoteSlider_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
let odin = OdinVM(blocs: Stub().loadBlocs())
|
||||||
|
let ueVM = odin.blocsVM[0].uesVM[0]
|
||||||
|
|
||||||
|
UENoteSlider(ueVM: ueVM)
|
||||||
|
}
|
||||||
|
}
|
@ -1,64 +1,59 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import Stub
|
||||||
|
import ViewModel
|
||||||
|
|
||||||
struct UEView: View {
|
struct UEView: View {
|
||||||
@State private var showingSheet = false
|
@StateObject var ueVM: UEVM
|
||||||
|
|
||||||
|
@State private var canEditNote = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
NoteInfo()
|
UEInfo(ueVM: ueVM)
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Label("Coefficcient : 6", systemImage: "xmark.circle.fill")
|
Label("Coefficcient : \(ueVM.factor)", systemImage: "xmark.circle.fill")
|
||||||
Label("Détails des notes ", systemImage: "note.text")
|
Label("Détails des notes ", systemImage: "note.text")
|
||||||
}
|
}
|
||||||
|
.padding()
|
||||||
|
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
HStack {
|
ForEach(ueVM.matieresVM) { matiereVM in
|
||||||
Button(action: {}) {
|
HStack {
|
||||||
Image(systemName: "lock")
|
Button(action: {
|
||||||
}
|
canEditNote.toggle()
|
||||||
NoteInfo()
|
}) {
|
||||||
}
|
Image(systemName: canEditNote ? "lock.open" : "lock")
|
||||||
HStack {
|
}
|
||||||
Button(action: {}) {
|
MatiereInfo(matiereVM: matiereVM, canEdit: canEditNote)
|
||||||
Image(systemName: "lock")
|
|
||||||
}
|
|
||||||
NoteInfo()
|
|
||||||
}
|
|
||||||
HStack {
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "lock")
|
|
||||||
}
|
|
||||||
NoteInfo()
|
|
||||||
}
|
|
||||||
HStack {
|
|
||||||
Button(action: {}) {
|
|
||||||
Image(systemName: "lock")
|
|
||||||
}
|
}
|
||||||
NoteInfo()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
.navigationTitle("UE1 Génie logiciel")
|
.navigationTitle("UE\(ueVM.number) \(ueVM.name)")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem {
|
ToolbarItem {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
showingSheet = true
|
ueVM.isEditing.toggle()
|
||||||
}) {
|
}) {
|
||||||
Text("Edit")
|
Text("Edit")
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showingSheet) {
|
|
||||||
UEEditSheet()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $ueVM.isEditing) {
|
||||||
|
UEEdit(ueEditVM: ueVM)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UEView_Previews: PreviewProvider {
|
struct UEView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
UEView()
|
let odin = OdinVM(blocs: Stub().loadBlocs())
|
||||||
|
let ueVM = odin.blocsVM[0].uesVM[0]
|
||||||
|
|
||||||
|
UEView(ueVM: ueVM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -0,0 +1,7 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public protocol DataManager {
|
||||||
|
func loadBlocs() -> [Bloc]
|
||||||
|
|
||||||
|
func saveBlocs(blocs: [Bloc]) -> Void
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
struct Manager {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,21 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
public struct Odin {
|
||||||
|
let dataManager: DataManager
|
||||||
|
public var blocs: [Bloc] = []
|
||||||
|
|
||||||
|
public init(dataManager: DataManager) {
|
||||||
|
self.dataManager = dataManager
|
||||||
|
}
|
||||||
|
|
||||||
|
public mutating func loadBlocs(){
|
||||||
|
self.blocs.removeAll()
|
||||||
|
for bloc in self.dataManager.loadBlocs() {
|
||||||
|
self.blocs.append(bloc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func saveBlocs() {
|
||||||
|
self.dataManager.saveBlocs(blocs: self.blocs)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
extension Array where Element: Equatable {
|
||||||
|
func compare(to other: [Element]) -> Bool {
|
||||||
|
self.count == other.count && self.allSatisfy({ elt in
|
||||||
|
other.contains { otherElt in
|
||||||
|
otherElt == elt
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
import Foundation
|
||||||
|
import Model
|
||||||
|
|
||||||
|
@available(iOS 13.0, *)
|
||||||
|
public class OdinVM: ObservableObject {
|
||||||
|
@Published public var blocsVM: [BlocVM] = []
|
||||||
|
|
||||||
|
public init(blocs: [Bloc]) {
|
||||||
|
self.blocsVM = blocs.map({BlocVM(model: $0)})
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(blocsVM: [BlocVM]) {
|
||||||
|
self.blocsVM = blocsVM
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue