pull/1/head
Alexis Drai 2 years ago
parent 7e79638357
commit a682c12be7

@ -19,6 +19,8 @@
EC242B882A1FC605006FE760 /* NoGradesInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC242B872A1FC605006FE760 /* NoGradesInfo.swift */; }; EC242B882A1FC605006FE760 /* NoGradesInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC242B872A1FC605006FE760 /* NoGradesInfo.swift */; };
EC242B8A2A1FCECA006FE760 /* AverageBlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC242B892A1FCECA006FE760 /* AverageBlockView.swift */; }; EC242B8A2A1FCECA006FE760 /* AverageBlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC242B892A1FCECA006FE760 /* AverageBlockView.swift */; };
EC5FE5A52A20882F0028AA5F /* Formatters.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC5FE5A42A20882F0028AA5F /* Formatters.swift */; }; EC5FE5A52A20882F0028AA5F /* Formatters.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC5FE5A42A20882F0028AA5F /* Formatters.swift */; };
ECB2FFCE2A23C4A700FF9F91 /* SubjectFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB2FFCD2A23C4A700FF9F91 /* SubjectFormView.swift */; };
ECB2FFD02A23C4B700FF9F91 /* SubjectFormVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB2FFCF2A23C4B700FF9F91 /* SubjectFormVM.swift */; };
ECC581D22A1D085B006C55EF /* GraduatorApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC581D12A1D085B006C55EF /* GraduatorApp.swift */; }; ECC581D22A1D085B006C55EF /* GraduatorApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC581D12A1D085B006C55EF /* GraduatorApp.swift */; };
ECC581D62A1D085C006C55EF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECC581D52A1D085C006C55EF /* Assets.xcassets */; }; ECC581D62A1D085C006C55EF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECC581D52A1D085C006C55EF /* Assets.xcassets */; };
ECC581D92A1D085C006C55EF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECC581D82A1D085C006C55EF /* Preview Assets.xcassets */; }; ECC581D92A1D085C006C55EF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECC581D82A1D085C006C55EF /* Preview Assets.xcassets */; };
@ -39,6 +41,8 @@
EC242B872A1FC605006FE760 /* NoGradesInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoGradesInfo.swift; sourceTree = "<group>"; }; EC242B872A1FC605006FE760 /* NoGradesInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoGradesInfo.swift; sourceTree = "<group>"; };
EC242B892A1FCECA006FE760 /* AverageBlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AverageBlockView.swift; sourceTree = "<group>"; }; EC242B892A1FCECA006FE760 /* AverageBlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AverageBlockView.swift; sourceTree = "<group>"; };
EC5FE5A42A20882F0028AA5F /* Formatters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Formatters.swift; sourceTree = "<group>"; }; EC5FE5A42A20882F0028AA5F /* Formatters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Formatters.swift; sourceTree = "<group>"; };
ECB2FFCD2A23C4A700FF9F91 /* SubjectFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubjectFormView.swift; sourceTree = "<group>"; };
ECB2FFCF2A23C4B700FF9F91 /* SubjectFormVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubjectFormVM.swift; sourceTree = "<group>"; };
ECC581CE2A1D085B006C55EF /* Graduator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Graduator.app; sourceTree = BUILT_PRODUCTS_DIR; }; ECC581CE2A1D085B006C55EF /* Graduator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Graduator.app; sourceTree = BUILT_PRODUCTS_DIR; };
ECC581D12A1D085B006C55EF /* GraduatorApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraduatorApp.swift; sourceTree = "<group>"; }; ECC581D12A1D085B006C55EF /* GraduatorApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraduatorApp.swift; sourceTree = "<group>"; };
ECC581D52A1D085C006C55EF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; ECC581D52A1D085C006C55EF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -61,6 +65,7 @@
EC242B6F2A1F8260006FE760 /* View */ = { EC242B6F2A1F8260006FE760 /* View */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
ECB2FFCC2A23C49500FF9F91 /* Forms */,
EC5FE5A32A20881B0028AA5F /* Utils */, EC5FE5A32A20881B0028AA5F /* Utils */,
EC242B862A1FC5EC006FE760 /* Components */, EC242B862A1FC5EC006FE760 /* Components */,
EC242B772A1F834C006FE760 /* Cells */, EC242B772A1F834C006FE760 /* Cells */,
@ -103,6 +108,14 @@
path = Utils; path = Utils;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
ECB2FFCC2A23C49500FF9F91 /* Forms */ = {
isa = PBXGroup;
children = (
ECB2FFCD2A23C4A700FF9F91 /* SubjectFormView.swift */,
);
path = Forms;
sourceTree = "<group>";
};
ECC581C52A1D085B006C55EF = { ECC581C52A1D085B006C55EF = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -148,6 +161,7 @@
ECC581E02A1D08DB006C55EF /* SubjectVM.swift */, ECC581E02A1D08DB006C55EF /* SubjectVM.swift */,
ECC581E42A1D0C44006C55EF /* UnitVM.swift */, ECC581E42A1D0C44006C55EF /* UnitVM.swift */,
EC242B7E2A1F83BF006FE760 /* UnitsManagerVM.swift */, EC242B7E2A1F83BF006FE760 /* UnitsManagerVM.swift */,
ECB2FFCF2A23C4B700FF9F91 /* SubjectFormVM.swift */,
); );
path = ViewModel; path = ViewModel;
sourceTree = "<group>"; sourceTree = "<group>";
@ -232,6 +246,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
ECB2FFCE2A23C4A700FF9F91 /* SubjectFormView.swift in Sources */,
EC242B712A1F8283006FE760 /* MainView.swift in Sources */, EC242B712A1F8283006FE760 /* MainView.swift in Sources */,
EC242B6E2A1F81CC006FE760 /* UnitsManager.swift in Sources */, EC242B6E2A1F81CC006FE760 /* UnitsManager.swift in Sources */,
ECC581E52A1D0C44006C55EF /* UnitVM.swift in Sources */, ECC581E52A1D0C44006C55EF /* UnitVM.swift in Sources */,
@ -240,6 +255,7 @@
EC242B7B2A1F838C006FE760 /* UnitViewCell.swift in Sources */, EC242B7B2A1F838C006FE760 /* UnitViewCell.swift in Sources */,
EC242B6C2A1F81AE006FE760 /* Subject.swift in Sources */, EC242B6C2A1F81AE006FE760 /* Subject.swift in Sources */,
EC242B8A2A1FCECA006FE760 /* AverageBlockView.swift in Sources */, EC242B8A2A1FCECA006FE760 /* AverageBlockView.swift in Sources */,
ECB2FFD02A23C4B700FF9F91 /* SubjectFormVM.swift in Sources */,
ECC581E12A1D08DB006C55EF /* SubjectVM.swift in Sources */, ECC581E12A1D08DB006C55EF /* SubjectVM.swift in Sources */,
EC242B6A2A1F8189006FE760 /* Unit.swift in Sources */, EC242B6A2A1F8189006FE760 /* Unit.swift in Sources */,
EC242B752A1F8339006FE760 /* UnitView.swift in Sources */, EC242B752A1F8339006FE760 /* UnitView.swift in Sources */,

@ -49,10 +49,10 @@ struct MainView: View {
unitVM: unitVM, unitVM: unitVM,
unitsManagerVM: unitsManagerVM unitsManagerVM: unitsManagerVM
)) { )) {
UnitViewCell( UnitViewCell(
unitVM: unitVM, unitVM: unitVM,
unitsManagerVM: unitsManagerVM unitsManagerVM: unitsManagerVM
) )
} }
} }
} }

@ -11,101 +11,78 @@ struct SubjectViewCell: View {
@ObservedObject var subjectVM: SubjectVM @ObservedObject var subjectVM: SubjectVM
@ObservedObject var unitVM: UnitVM @ObservedObject var unitVM: UnitVM
@ObservedObject var unitsManagerVM: UnitsManagerVM @ObservedObject var unitsManagerVM: UnitsManagerVM
//TODO also allow using the unitview's navigation bar item "Edit" (makes all subjects editable, and more) @State private var isGradeEditable = false
@State private var isEditable = false
var body: some View { var body: some View {
HStack { HStack {
if isEditable {
VStack {
Button(action: {
isEditable = false
subjectVM.onEdited()
unitVM.updateSubject(subjectVM)
unitsManagerVM.updateUnit(unitVM)
}) {
Image(systemName: "checkmark.square")
.foregroundColor(.green)
}
Button(action: {
isEditable = false
subjectVM.onEdited(isCancelled: true)
}) {
Image(systemName: "nosign.app")
.padding(.top, 10.0)
.foregroundColor(.pink)
}
}
} else {
Button(action: {
isEditable = true
subjectVM.onEditing()
}) {
Image(systemName: "lock")
}
}
VStack { VStack {
HStack { HStack {
TextField("", text: $subjectVM.model.name) TextField("", text: $subjectVM.model.name)
.disabled(!isEditable) .disabled(!unitsManagerVM.isAllEditable)
TextField("", value: $subjectVM.model.weight, formatter: NumberFormatter()) TextField("", value: $subjectVM.model.weight, formatter: Formatters.weightFormatter)
.frame(width: 20) .frame(width: 40)
.disabled(!isEditable) .disabled(!unitsManagerVM.isAllEditable)
} }
HStack { HStack {
if let grade = subjectVM.model.grade { if let grade = subjectVM.model.grade {
VStack {
Toggle("", isOn: $isGradeEditable)
.frame(width: 40)
.onChange(of: isGradeEditable) { value in
if !value {
subjectVM.onEdited()
unitVM.updateSubject(subjectVM)
unitsManagerVM.updateUnit(unitVM)
}
}
Image(systemName: isGradeEditable ? "checkmark" : "lock.open")
}
Slider(value: Binding( Slider(value: Binding(
get: { grade }, get: { grade },
set: { newValue in set: { newValue in
if isEditable { if isGradeEditable {
subjectVM.model.grade = newValue subjectVM.model.grade = newValue
} }
} }
), in: 0...1, step: 0.001) ), in: 0...1, step: 0.001)
.accentColor(grade < 0.5 ? .red : .green) .accentColor(grade < 0.5 ? .red : .green)
.disabled(!isEditable || subjectVM.model.isCalled) .disabled(!isGradeEditable || subjectVM.model.isCalled)
TextField("", value: Binding( TextField("", value: Binding(
get: { grade * 20.0 }, get: { grade * 20.0 },
set: { newValue in set: { newValue in
if isEditable { if isGradeEditable {
subjectVM.model.grade = newValue / 20.0 subjectVM.model.grade = newValue / 20.0
} }
} }
), formatter: Formatters.gradeFormatter) ), formatter: Formatters.gradeFormatter)
.frame(width: 50) .frame(width: 50)
.disabled(!isEditable || subjectVM.model.isCalled) .disabled(!isGradeEditable || subjectVM.model.isCalled)
Image(systemName: "snowflake.circle.fill") VStack {
.foregroundColor(subjectVM.model.isCalled ? .primary : .gray) Toggle("", isOn: $subjectVM.model.isCalled)
.frame(width: 40)
Toggle("", isOn: $subjectVM.model.isCalled) Image(systemName: "snowflake.circle.fill")
.frame(width: 50) .foregroundColor(subjectVM.model.isCalled ? .primary : .gray)
.disabled(!isEditable) }
} else { } else {
NoGradesInfo() NoGradesInfo()
Button(action: { Button(action: {
subjectVM.model.grade = 0.0 subjectVM.model.grade = 0.0
isGradeEditable = true
}) { }) {
Image(systemName: "pencil.line") Image(systemName: "pencil.line")
} }
.disabled(!isEditable)
} }
} }
.padding(.bottom)
} }
} }
.padding()
.background(Color.gray.opacity(0.2))
.cornerRadius(12)
.padding(.horizontal)
} }
} }

@ -16,9 +16,13 @@ struct UnitViewCell: View {
HStack { HStack {
Text("UE " + String(unitVM.model.code)) Text("UE " + String(unitVM.model.code))
Text(unitVM.model.name) .frame(width: 40)
TextField("", text: $unitVM.model.name)
.disabled(!unitsManagerVM.isAllEditable)
Spacer() Spacer()
Text(String(unitVM.model.weight)) TextField("", value: $unitVM.model.weight, formatter: Formatters.weightFormatter)
.frame(width: 30)
.disabled(!unitsManagerVM.isAllEditable)
} }
HStack { HStack {

@ -0,0 +1,40 @@
//
// SubjectForm.swift
// Graduator
//
// Created by etudiant on 2023-05-28.
//
import SwiftUI
struct SubjectFormView: View {
@ObservedObject var formVM: SubjectFormVM
var body: some View {
Form {
HStack {
Text("Nom de la matière:")
Spacer()
TextField("Nom", text: $formVM.name)
}
HStack {
Text("Coefficient:")
Spacer()
TextField("Coefficient", value: $formVM.weight, formatter: NumberFormatter())
}
HStack {
Text("Note sur 20.0:")
Spacer()
TextField("Note", text: $formVM.gradeString)
}
Toggle("Note définitive?", isOn: $formVM.isCalled)
}
}
}
struct SubjectFormView_Previews: PreviewProvider {
static var previews: some View {
SubjectFormView(formVM: SubjectFormVM())
}
}

@ -12,6 +12,15 @@ class Formatters {
let formatter = NumberFormatter() let formatter = NumberFormatter()
formatter.numberStyle = .decimal formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 2 formatter.maximumFractionDigits = 2
formatter.minimum = 0
formatter.maximum = 20
return formatter
}()
static let weightFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .none
formatter.minimum = 1
return formatter return formatter
}() }()
} }

@ -11,6 +11,17 @@ struct UnitView: View {
@ObservedObject var unitVM: UnitVM @ObservedObject var unitVM: UnitVM
@ObservedObject var unitsManagerVM: UnitsManagerVM @ObservedObject var unitsManagerVM: UnitsManagerVM
@State private var showAlert = false
@State private var showingForm: Bool = false
var formVM = SubjectFormVM()
private func delete(at offsets: IndexSet) {
guard let index = offsets.first else { return }
let subjectVMToDelete = unitVM.SubjectsVM[index]
unitVM.deleteSubject(subjectVMToDelete)
unitsManagerVM.updateUnit(unitVM)
}
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
HStack { HStack {
@ -39,27 +50,84 @@ struct UnitView: View {
} }
.padding(.horizontal) .padding(.horizontal)
ScrollView {
ForEach(unitVM.SubjectsVM) { subjectVM in List {
SubjectViewCell( if unitsManagerVM.isAllEditable {
subjectVM: subjectVM, ForEach(unitVM.SubjectsVM) { subjectVM in
unitVM: unitVM, SubjectViewCell(
unitsManagerVM: unitsManagerVM subjectVM: subjectVM,
) unitVM: unitVM,
unitsManagerVM: unitsManagerVM
)
}
.onDelete(perform: delete)
} else {
ForEach(unitVM.SubjectsVM) { subjectVM in
SubjectViewCell(
subjectVM: subjectVM,
unitVM: unitVM,
unitsManagerVM: unitsManagerVM
)
}
} }
} }
.navigationBarItems(trailing: Button(action: { .navigationBarItems(trailing: HStack {
// TODO Add action for button. Make editable if unitsManagerVM.isAllEditable {
// * (LATER, in UnitViewCell) unit weight Button(action: { showingForm = true }) {
// * (LATER, in UnitViewCell) unit description Image(systemName: "plus")
// * subjects }
// * make all fields editable (=> just toggle isEditable is the SubjectCellViews?) Button(action: {
// * create new subject (creation screen with simple form for name, weight, code, isCalled. Of course, will need to deal with adding it to the unitVM, updating the unitVM, and updating the unitsmanagerVM with the new unitVM. Check the result to make sure that the model does get updated by the VM in the end) unitsManagerVM.isAllEditable.toggle()
// * delete a subject (again, this has repercusions for the unit and the unitmanager, be careful) unitVM.onEdited(isCancelled: true)
}) { }) {
Text("Edit") Text("Annuler")
}
Button(action: {
unitsManagerVM.isAllEditable.toggle()
unitVM.onEdited()
unitVM.updateAllSubjects()
unitsManagerVM.updateUnit(unitVM)
}) {
Text("OK")
}
} else {
Button(action: {
unitsManagerVM.isAllEditable.toggle()
unitVM.onEditing()
}) {
Text("Modifier")
}
}
}) })
.sheet(isPresented: $showingForm) {
NavigationView {
SubjectFormView(formVM: formVM)
.navigationTitle("Nouvelle matière")
.navigationBarItems(
leading: Button("Annuler") { showingForm = false },
trailing: Button("Enregistrer") {
if let newSubject = formVM.createSubject() {
unitVM.addSubject(newSubject)
unitsManagerVM.updateUnit(unitVM)
showingForm = false
} else {
showAlert = true
}
}.alert(isPresented: $showAlert) {
Alert(title: Text("Annulé: matière invalide"),
message: Text("C'est un peu plus compliqué que ça..."),
dismissButton: .default(Text("OK")))
})
}
}
} }
// If user navigates back while editing but before clicking 'OK', the changes are cancelled
.onDisappear(perform: {
if unitsManagerVM.isAllEditable {
unitVM.onEdited(isCancelled: true)
unitsManagerVM.isAllEditable = false
}
})
} }
} }

@ -0,0 +1,38 @@
//
// SubjectFormVM.swift
// Graduator
//
// Created by etudiant on 2023-05-28.
//
import Foundation
class SubjectFormVM: ObservableObject {
@Published var name: String = ""
@Published var weight: Int = 1
@Published var gradeString: String = ""
@Published var isCalled: Bool = false
var grade: Double? {
if let gradeOverTwenty = Double(gradeString) {
return gradeOverTwenty / 20.0
} else {
return nil
}
}
func isValid(_ subject: Subject) -> Bool {
return !(name.isEmpty || weight <= 0 || !subject.gradeIsValid(grade) || (isCalled && grade == nil))
}
func createSubject() -> Subject? {
let subject = Subject(
id: UUID(),
name: name,
weight: weight,
grade: grade,
isCalled: isCalled)
guard isValid(subject) else { return nil }
return subject
}
}

@ -29,16 +29,23 @@ extension Subject {
mutating func update(from data: Data) { mutating func update(from data: Data) {
// papers please // papers please
guard data.id == self.data.id else { return } guard data.id == self.data.id else { return }
// can't update if this subject is called, unless the update is to 'un-call' the subject // can't update grade if this subject is called, unless the update is to 'un-call' the subject
guard !(self.isCalled && data.isCalled) else { return } guard !(self.isCalled && data.isCalled && self.grade != data.grade) else { return }
// can't update a subject to become called and have a nil grade at the same time // can't update a subject to become called and have a nil grade at the same time
guard !(data.grade == nil && data.isCalled) else { return } guard !(data.grade == nil && data.isCalled) else { return }
self.name = data.name if (!data.name.isEmpty) {
self.weight = data.weight self.name = data.name
self.grade = data.grade }
self.weight = max(abs(data.weight), 1)
if let grade = data.grade {
self.grade = max(abs(grade), 0.0)
} else {
self.grade = nil
}
self.isCalled = data.isCalled self.isCalled = data.isCalled
} }
} }
class SubjectVM : ObservableObject, Identifiable { class SubjectVM : ObservableObject, Identifiable {

@ -30,8 +30,10 @@ extension Unit {
mutating func update(from data: Data) { mutating func update(from data: Data) {
guard self.id == data.id else {return} guard self.id == data.id else {return}
self.name = data.name if (!data.name.isEmpty) {
self.weight = data.weight self.name = data.name
}
self.weight = max(abs(data.weight), 1)
self.isProfessional = data.isProfessional self.isProfessional = data.isProfessional
self.code = data.code self.code = data.code
self.subjects = data.subjects.map { self.subjects = data.subjects.map {
@ -93,6 +95,25 @@ class UnitVM : ObservableObject, Identifiable {
model = original.data model = original.data
} }
func updateAllSubjects() {
for subjectVM in subjectsVM {
updateSubject(subjectVM)
}
}
func deleteSubject(_ subjectVM: SubjectVM) {
guard let index = subjectsVM.firstIndex(where: { $0.id == subjectVM.id }) else { return }
subjectsVM.remove(at: index)
original.subjects.remove(at: index)
model = original.data
}
func addSubject(_ subject: Subject) {
subjectsVM.append(SubjectVM(subject: subject))
original.subjects.append(subject)
model = original.data
}
var Average: Double? { var Average: Double? {
return original.getAverage() return original.getAverage()
} }

@ -46,6 +46,7 @@ class UnitsManagerVM : ObservableObject {
private var original: UnitsManager private var original: UnitsManager
@Published var model: UnitsManager.Data @Published var model: UnitsManager.Data
@Published var isEdited: Bool = false @Published var isEdited: Bool = false
@Published var isAllEditable: Bool = false
private var unitsVM: [UnitVM] private var unitsVM: [UnitVM]
@ -76,6 +77,3 @@ class UnitsManagerVM : ObservableObject {
return original.getProfessionalAverage() return original.getProfessionalAverage()
} }
} }

@ -1,2 +1,223 @@
# Graduator salutes you # Graduator
Graduator is an iOS application developed with SwiftUI that helps users manage their academic `units`, `subjects`, and grades. Users can add and delete `subjects`, edit the weight and name of `subjects` and `units`, and input grades. The app displays weighted averages and explains the conditions for graduating from the Clermont Auvergne Tech Institute's mobile development BSc in 2023.
## Features
Beyond those basic features, some details need to be specified here.
### isCalled Feature
The isCalled property, available for each subject, denotes whether the grade of a specific subject has been called or not -- i.e., whether it is a definitive grade or a temporary one.
From the user's point of view, they can see an image of a snowflake that turns from gray to primary color when a subject grade has been called. A Toggle control allows them to set or unset the isCalled status. If they attempt to change the grade of a subject that has been called, they will not be able to -- the corresponding slider and textfield will remain disabled.
In the model and view model, the `isCalled` property of `subjects` affects the state of their `unit`. If all of a `unit`'s `subject` grades are called, the `unit` is considered called too. Note that if a `subject`'s grade is not set (nil), the `subject` can't be called.
### Deleting a Subject
In the app, users can delete a subject by swiping it off the list, right-to-left.
Note that when a subject is deleted, it is permanently removed from the system. If a user is in the process of editing and deletes a subject, the deletion occurs immediately upon swiping, not when they save (click 'OK'). If the user chooses to cancel their edits (click 'Annuler'), all other unsaved changes will be discarded, but the deletion of the subject remains.
### Changing a grade
Before a user changes a grade, they first need to activate the `lock.open` toggle. If the grade is *called*, they also need to use the `isCalled` toggle.
After a grade was changed, in order to save the change and to see it reflected iun the weighted average, users need to use the (previously `lock.open`, now) `checkmark` toggle.
## Architecture
Graduator is based on the MVVM (Model-View-ViewModel) architectural pattern. The below UML class diagram details the structure of the models, viewmodels, and views for `UnitsManager`, `Unit`, and `Subject`.
```mermaid
classDiagram
class Unit {
+name: String
+weight: Int
+isProfessional: Bool
+code: Int
+subjects: [Subject]
+getAverage(): Double?
+data: Data
+update(from: Data): Void
}
class UnitVM {
-original: Unit
+model: Unit.Data
+isEdited: Bool
+SubjectsVM: [SubjectVM]
+onEditing(): Void
+onEdited(isCancelled: Bool): Void
+updateSubject(subjectVM: SubjectVM): Void
+updateAllSubjects(): Void
+deleteSubject(subjectVM: SubjectVM): Void
+addSubject(subject: Subject): Void
+Average: Double?
+IsCalled: Bool
}
class UnitView {
-unitVM: UnitVM
-unitsManagerVM: UnitsManagerVM
+delete(at: IndexSet): Void
}
class Subject {
+name: String
+weight: Int
+grade: Double?
+isCalled: Bool
+gradeIsValid(grade: Double?): Bool
+data: Data
+update(from: Data): Void
}
class SubjectVM {
-original: Subject
+model: Subject.Data
+isEdited: Bool
+onEditing(): Void
+onEdited(isCancelled: Bool): Void
}
class SubjectViewCell {
-subjectVM: SubjectVM
-unitVM: UnitVM
-unitsManagerVM: UnitsManagerVM
-isGradeEditable: Bool
}
class UnitsManager {
+units: [Unit]
+getTotalAverage(): Double?
+getProfessionalAverage(): Double?
+getAverage(units: [Unit]): Double?
+data: Data
+update(from: Data): Void
}
class UnitsManagerVM {
-original: UnitsManager
+model: UnitsManager.Data
+isEdited: Bool
+isAllEditable: Bool
+UnitsVM: [UnitVM]
+updateUnit(unitVM: UnitVM): Void
+TotalAverage: Double?
+ProfessionalAverage: Double?
}
class MainView {
-unitsManagerVM: UnitsManagerVM
}
UnitVM -- Unit : Uses
UnitView -- UnitVM : Observes
SubjectVM -- Subject : Uses
SubjectViewCell -- SubjectVM : Observes
UnitVM "1" o-- "*" SubjectVM : Contains
UnitsManagerVM -- UnitsManager : Uses
UnitsManagerVM "1" o-- "*" UnitVM : Contains
MainView -- UnitsManagerVM : Observes
```
It might be useful to note that, just like `UnitVM`s aggregate `SubjectVM`s, `Unit`s aggregate `Subject`s, but these relationship between `Model` entities were removed from the diagram above for clarity.
Here is the diagram with those relationships depicted.
```mermaid
classDiagram
class Unit {
+name: String
+weight: Int
+isProfessional: Bool
+code: Int
+subjects: [Subject]
+getAverage(): Double?
+data: Data
+update(from: Data): Void
}
class UnitVM {
-original: Unit
+model: Unit.Data
+isEdited: Bool
+SubjectsVM: [SubjectVM]
+onEditing(): Void
+onEdited(isCancelled: Bool): Void
+updateSubject(subjectVM: SubjectVM): Void
+updateAllSubjects(): Void
+deleteSubject(subjectVM: SubjectVM): Void
+addSubject(subject: Subject): Void
+Average: Double?
+IsCalled: Bool
}
class UnitView {
-unitVM: UnitVM
-unitsManagerVM: UnitsManagerVM
+delete(at: IndexSet): Void
}
class Subject {
+name: String
+weight: Int
+grade: Double?
+isCalled: Bool
+gradeIsValid(grade: Double?): Bool
+data: Data
+update(from: Data): Void
}
class SubjectVM {
-original: Subject
+model: Subject.Data
+isEdited: Bool
+onEditing(): Void
+onEdited(isCancelled: Bool): Void
}
class SubjectViewCell {
-subjectVM: SubjectVM
-unitVM: UnitVM
-unitsManagerVM: UnitsManagerVM
-isGradeEditable: Bool
}
class UnitsManager {
+units: [Unit]
+getTotalAverage(): Double?
+getProfessionalAverage(): Double?
+getAverage(units: [Unit]): Double?
+data: Data
+update(from: Data): Void
}
class UnitsManagerVM {
-original: UnitsManager
+model: UnitsManager.Data
+isEdited: Bool
+isAllEditable: Bool
+UnitsVM: [UnitVM]
+updateUnit(unitVM: UnitVM): Void
+TotalAverage: Double?
+ProfessionalAverage: Double?
}
class MainView {
-unitsManagerVM: UnitsManagerVM
}
UnitVM -- Unit : Uses
UnitView -- UnitVM : Observes
SubjectVM -- Subject : Uses
SubjectViewCell -- SubjectVM : Observes
UnitVM "1" o-- "*" SubjectVM : Contains
Unit "1" o-- "*" Subject : Contains
UnitsManagerVM -- UnitsManager : Uses
UnitsManagerVM "1" o-- "*" UnitVM : Contains
UnitsManager "1" o-- "*" Unit : Contains
MainView -- UnitsManagerVM : Observes
```

Loading…
Cancel
Save