mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-22 09:23:57 +00:00
✨ Fixing small issue, adding Settings, adding Acknowledgements, adding logout functionality
This commit is contained in:
parent
6c3e0f498a
commit
52dbfa60ea
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
CD730A35259A860E00E0BB69 /* SettingsAcknowledgements.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD730A34259A860E00E0BB69 /* SettingsAcknowledgements.swift */; };
|
||||
CD9FAB81258EC60200D6D0C5 /* DHBW_ServiceApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9FAB80258EC60200D6D0C5 /* DHBW_ServiceApp.swift */; };
|
||||
CD9FAB83258EC60200D6D0C5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9FAB82258EC60200D6D0C5 /* ContentView.swift */; };
|
||||
CD9FAB85258EC60600D6D0C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD9FAB84258EC60600D6D0C5 /* Assets.xcassets */; };
|
||||
|
@ -43,6 +44,7 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
CD730A34259A860E00E0BB69 /* SettingsAcknowledgements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAcknowledgements.swift; sourceTree = "<group>"; };
|
||||
CD9FAB7D258EC60200D6D0C5 /* DHBW-Service.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DHBW-Service.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
CD9FAB80258EC60200D6D0C5 /* DHBW_ServiceApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DHBW_ServiceApp.swift; sourceTree = "<group>"; };
|
||||
CD9FAB82258EC60200D6D0C5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
|
@ -94,6 +96,14 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
CD730A33259A85F500E0BB69 /* SettingsSubViews */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CD730A34259A860E00E0BB69 /* SettingsAcknowledgements.swift */,
|
||||
);
|
||||
path = SettingsSubViews;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CD9FAB74258EC60100D6D0C5 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -196,6 +206,7 @@
|
|||
children = (
|
||||
CDCD721925912E1200FBF2F5 /* HomeView.swift */,
|
||||
CDD39B4A259A64150078D05F /* SettingsMain.swift */,
|
||||
CD730A33259A85F500E0BB69 /* SettingsSubViews */,
|
||||
);
|
||||
path = Tabs;
|
||||
sourceTree = "<group>";
|
||||
|
@ -369,6 +380,7 @@
|
|||
CDDCF4842592028A0027CDC5 /* Localizer.swift in Sources */,
|
||||
CDCD7230259135C500FBF2F5 /* FirstOpeningSettings.swift in Sources */,
|
||||
CD9FAB8A258EC60600D6D0C5 /* Persistence.swift in Sources */,
|
||||
CD730A35259A860E00E0BB69 /* SettingsAcknowledgements.swift in Sources */,
|
||||
CD9FAB83258EC60200D6D0C5 /* ContentView.swift in Sources */,
|
||||
CDCD72242591316500FBF2F5 /* LocalSettings.swift in Sources */,
|
||||
CD9FAB8D258EC60600D6D0C5 /* DHBW_Service.xcdatamodeld in Sources */,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user