mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2026-04-28 18:30:09 +00:00
✨ Fixing small issue, adding Settings, adding Acknowledgements, adding logout functionality
This commit is contained in:
@@ -10,3 +10,8 @@
|
||||
"director" = "Studiengangsleiter";
|
||||
"filledAuto" = "automatisch ausgefüllt";
|
||||
"welcomeText" = "Bitte fülle die folgenden Felder aus:";
|
||||
"settings" = "Einstellungen";
|
||||
"other" = "Sonstiges";
|
||||
"logoutClearData" = "Abmelden und alle Daten löschen";
|
||||
"logout" = "Abmelden";
|
||||
"confirmLogoutMessage" = "Bist du dir sicher, dass du dich abmelden und alle Daten löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden.";
|
||||
|
||||
@@ -10,3 +10,8 @@
|
||||
"director" = "Director";
|
||||
"filledAuto" = "filled automatically";
|
||||
"welcomeText" = "Please enter your data in the following fields:";
|
||||
"settings" = "Settings";
|
||||
"other" = "Other";
|
||||
"logoutClearData" = "Logout and clear all data";
|
||||
"logout" = "Logout";
|
||||
"confirmLogoutMessage" = "Are you sure you want to logout and clear all data? This cannot be undone.";
|
||||
|
||||
@@ -39,4 +39,25 @@ class UtilityFunctions {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
public class func deleteAllData() -> Bool {
|
||||
let entities = ["User", "Item"]
|
||||
var allSuccessful = true
|
||||
|
||||
for entityName in entities {
|
||||
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: entityName)
|
||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
|
||||
|
||||
do {
|
||||
try PersistenceController.shared.context.execute(deleteRequest)
|
||||
|
||||
PersistenceController.shared.save()
|
||||
} catch let error as NSError {
|
||||
print(error)
|
||||
allSuccessful = false
|
||||
}
|
||||
}
|
||||
|
||||
return allSuccessful
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ struct FirstOpeningSettings: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("welcomeText".localized(tableName: "General", plural: false))
|
||||
|
||||
TextField("name".localized(tableName: "General", plural: false), text: self.$name)
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).stroke(invalidInputCourse ? Color.red : Color.secondary, lineWidth: 1))
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).stroke(invalidInputName ? Color.red : Color.secondary, lineWidth: 1))
|
||||
.foregroundColor(invalidInputName ? .red : .primary)
|
||||
.textContentType(.name)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
@@ -56,6 +57,7 @@ struct FirstOpeningSettings: View {
|
||||
.background(Color.blue)
|
||||
.cornerRadius(15)
|
||||
}
|
||||
//.disabled() //TODO: Check all inputs before enabling the button
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,45 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsMain: View {
|
||||
@EnvironmentObject var settings: LocalSettings
|
||||
@State private var showLogoutConfirmationAlert = false
|
||||
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
NavigationView {
|
||||
List {
|
||||
Section(header: Text("other".localized(tableName: "General", plural: false))) {
|
||||
NavigationLink(
|
||||
destination: SettingsAcknowledgements(),
|
||||
label: {
|
||||
Text("Acknowledgements")
|
||||
})
|
||||
Button(action: {
|
||||
self.showLogoutConfirmationAlert = true
|
||||
}, label: {
|
||||
Text("logoutClearData".localized(tableName: "General", plural: false))
|
||||
})
|
||||
}
|
||||
}
|
||||
.navigationTitle("settings".localized(tableName: "General", plural: false))
|
||||
.listStyle(GroupedListStyle())
|
||||
}
|
||||
.alert(isPresented: $showLogoutConfirmationAlert, content: {
|
||||
Alert(
|
||||
title: Text("logout".localized(tableName: "General", plural: false)),
|
||||
message: Text("confirmLogoutMessage".localized(tableName: "General", plural: false)),
|
||||
primaryButton: .cancel(),
|
||||
secondaryButton: .destructive(Text("Ok")){
|
||||
self.logoutAndClearData()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
extension SettingsMain {
|
||||
private func logoutAndClearData() {
|
||||
// TODO: Adjust before release!
|
||||
UtilityFunctions.deleteAllData()
|
||||
self.settings.isFirstOpening = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// SettingsAcknowledgements.swift
|
||||
// DHBW-Service
|
||||
//
|
||||
// Created by Patrick Müller on 28.12.20.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsAcknowledgements: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("Contributors")
|
||||
.font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
|
||||
Spacer()
|
||||
Text("David Huh")
|
||||
Text("Patrick Müller")
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsAcknowledgements_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsAcknowledgements()
|
||||
.preferredColorScheme(.dark)
|
||||
.environmentObject(getFirstOpening())
|
||||
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
||||
}
|
||||
|
||||
static func getFirstOpening() -> LocalSettings {
|
||||
let settings = LocalSettings();
|
||||
settings.isFirstOpening = false;
|
||||
return settings
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user