Commit
This commit is contained in:
parent
8d973e7942
commit
e6b217aba4
46
Schedule ICTIS/Main/Views/CreatedClassView.swift
Normal file
46
Schedule ICTIS/Main/Views/CreatedClassView.swift
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// CreatedClassView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 23.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct CreatedClassView: View {
|
||||||
|
let _class: ClassModel
|
||||||
|
var body: some View {
|
||||||
|
if datesAreEqual(_class.day, ClassModel.dateNow) {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
VStack {
|
||||||
|
Text(getTimeString(_class.starttime))
|
||||||
|
.font(.system(size: 15, weight: .regular))
|
||||||
|
Text(getTimeString(_class.endtime))
|
||||||
|
.font(.system(size: 15, weight: .regular))
|
||||||
|
}
|
||||||
|
.padding(.top, 7)
|
||||||
|
.padding(.bottom, 7)
|
||||||
|
.padding(.leading, 10)
|
||||||
|
Rectangle()
|
||||||
|
.frame(width: 2)
|
||||||
|
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
||||||
|
.padding(.top, 7)
|
||||||
|
.padding(.bottom, 7)
|
||||||
|
.foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online))
|
||||||
|
Text(getSubjectName(_class.subject, _class.professor, _class.auditory))
|
||||||
|
.font(.system(size: 18, weight: .regular))
|
||||||
|
.padding(.top, 7)
|
||||||
|
.padding(.bottom, 7)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
||||||
|
.background(Color.white)
|
||||||
|
.cornerRadius(20)
|
||||||
|
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
CreatedClassView(_class: .preview())
|
||||||
|
}
|
@ -8,6 +8,8 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct StartEndTimeFieldView: View {
|
struct StartEndTimeFieldView: View {
|
||||||
|
@Binding var isIncorrectDate: Bool
|
||||||
|
@Binding var selectedDay: Date
|
||||||
@Binding var selectedTime: Date
|
@Binding var selectedTime: Date
|
||||||
var imageName: String
|
var imageName: String
|
||||||
var text: String
|
var text: String
|
||||||
@ -15,7 +17,7 @@ struct StartEndTimeFieldView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: imageName)
|
Image(systemName: imageName)
|
||||||
.foregroundColor(Color("grayForFields"))
|
.foregroundColor(isIncorrectDate ? .red : Color("grayForFields"))
|
||||||
.padding(.leading, 12)
|
.padding(.leading, 12)
|
||||||
|
|
||||||
if !isTimeSelected {
|
if !isTimeSelected {
|
||||||
@ -26,7 +28,7 @@ struct StartEndTimeFieldView: View {
|
|||||||
|
|
||||||
if isTimeSelected {
|
if isTimeSelected {
|
||||||
Text("\(selectedTime, formatter: timeFormatter)")
|
Text("\(selectedTime, formatter: timeFormatter)")
|
||||||
.foregroundColor(.black)
|
.foregroundColor(isIncorrectDate ? .red : .black)
|
||||||
.font(.system(size: 17, weight: .medium))
|
.font(.system(size: 17, weight: .medium))
|
||||||
.padding(.trailing, 10)
|
.padding(.trailing, 10)
|
||||||
}
|
}
|
||||||
@ -38,16 +40,22 @@ struct StartEndTimeFieldView: View {
|
|||||||
.fill(.white)
|
.fill(.white)
|
||||||
)
|
)
|
||||||
.overlay {
|
.overlay {
|
||||||
DatePicker("", selection: $selectedTime, in: Date()..., displayedComponents: .hourAndMinute)
|
if isSameDate(selectedTime, selectedDay) {
|
||||||
.padding(.trailing, 35)
|
DatePicker("", selection: $selectedTime, in: Date()..., displayedComponents: .hourAndMinute)
|
||||||
.blendMode(.destinationOver)
|
.padding(.trailing, 35)
|
||||||
.onChange(of: selectedTime) { newValue, oldValue in
|
.blendMode(.destinationOver)
|
||||||
isTimeSelected = true
|
.onChange(of: selectedTime) { newValue, oldValue in
|
||||||
}
|
isTimeSelected = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DatePicker("", selection: $selectedTime, displayedComponents: .hourAndMinute)
|
||||||
|
.padding(.trailing, 35)
|
||||||
|
.blendMode(.destinationOver)
|
||||||
|
.onChange(of: selectedTime) { newValue, oldValue in
|
||||||
|
isTimeSelected = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
|
||||||
StartEndTimeFieldView(selectedTime: .constant(Date()), imageName: "clock", text: "Начало")
|
|
||||||
}
|
|
||||||
|
@ -2,15 +2,16 @@
|
|||||||
// ScheduleView.swift
|
// ScheduleView.swift
|
||||||
// Schedule ICTIS
|
// Schedule ICTIS
|
||||||
//
|
//
|
||||||
// Created by G412 on 05.12.2024.
|
// Created by Mironov Egor on 05.12.2024.
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ScheduleView: View {
|
struct ScheduleView: View {
|
||||||
@State private var isShowingSheet: Bool = false
|
|
||||||
@ObservedObject var vm: ScheduleViewModel
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
@FetchRequest(fetchRequest: ClassModel.all()) private var classes
|
@FetchRequest(fetchRequest: ClassModel.all()) private var classes
|
||||||
|
@State private var isShowingEditClassView = false
|
||||||
|
@State private var selectedClass: ClassModel? = nil
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if vm.isLoading {
|
if vm.isLoading {
|
||||||
LoadingView(isLoading: $vm.isLoading)
|
LoadingView(isLoading: $vm.isLoading)
|
||||||
@ -52,45 +53,16 @@ struct ScheduleView: View {
|
|||||||
.background(Color.white)
|
.background(Color.white)
|
||||||
.cornerRadius(20)
|
.cornerRadius(20)
|
||||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
||||||
.onTapGesture {
|
|
||||||
isShowingSheet = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ForEach(classes) { _class in
|
ForEach(classes) { _class in
|
||||||
if datesAreEqual(_class.day, vm.selectedDay) {
|
CreatedClassView(_class: _class)
|
||||||
HStack(spacing: 10) {
|
|
||||||
VStack {
|
|
||||||
Text(getTimeString(_class.starttime))
|
|
||||||
.font(.system(size: 15, weight: .regular))
|
|
||||||
Text(getTimeString(_class.endtime))
|
|
||||||
.font(.system(size: 15, weight: .regular))
|
|
||||||
}
|
|
||||||
.padding(.top, 7)
|
|
||||||
.padding(.bottom, 7)
|
|
||||||
.padding(.leading, 10)
|
|
||||||
Rectangle()
|
|
||||||
.frame(width: 2)
|
|
||||||
.frame(maxHeight: UIScreen.main.bounds.height - 18)
|
|
||||||
.padding(.top, 7)
|
|
||||||
.padding(.bottom, 7)
|
|
||||||
.foregroundColor(_class.important ? Color("redForImportant") : onlineOrNot(_class.online))
|
|
||||||
Text(getSubjectName(_class.subject, _class.professor, _class.auditory))
|
|
||||||
.font(.system(size: 18, weight: .regular))
|
|
||||||
.padding(.top, 7)
|
|
||||||
.padding(.bottom, 7)
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
.frame(maxWidth: UIScreen.main.bounds.width - 40, maxHeight: 230)
|
|
||||||
.background(Color.white)
|
|
||||||
.cornerRadius(20)
|
|
||||||
.shadow(color: .black.opacity(0.25), radius: 4, x: 2, y: 2)
|
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
isShowingSheet = true
|
isShowingEditClassView = true
|
||||||
|
selectedClass = _class
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(width: UIScreen.main.bounds.width)
|
.frame(width: UIScreen.main.bounds.width)
|
||||||
@ -102,14 +74,17 @@ struct ScheduleView: View {
|
|||||||
}
|
}
|
||||||
.frame(width: UIScreen.main.bounds.width, height: 15)
|
.frame(width: UIScreen.main.bounds.width, height: 15)
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $isShowingSheet) {
|
.sheet(isPresented: $isShowingEditClassView) {
|
||||||
SheetChangeClassView(isShowingSheet: $isShowingSheet)
|
if let selectedClass = selectedClass {
|
||||||
|
EditClassView(isShowingSheet: $isShowingEditClassView, _class: selectedClass)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NoScheduleView()
|
NoScheduleView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,6 @@ struct SearchBarView: View {
|
|||||||
.onSubmit {
|
.onSubmit {
|
||||||
self.isEditing = false
|
self.isEditing = false
|
||||||
if (!text.isEmpty) {
|
if (!text.isEmpty) {
|
||||||
if !vm.numOfGroup.isEmpty {
|
|
||||||
|
|
||||||
}
|
|
||||||
vm.fetchWeekSchedule(text)
|
vm.fetchWeekSchedule(text)
|
||||||
vm.group = text
|
vm.group = text
|
||||||
}
|
}
|
||||||
@ -83,7 +80,7 @@ struct SearchBarView: View {
|
|||||||
.frame(height: 40)
|
.frame(height: 40)
|
||||||
.accentColor(.blue)
|
.accentColor(.blue)
|
||||||
.sheet(isPresented: $isShowingSheet) {
|
.sheet(isPresented: $isShowingSheet) {
|
||||||
SheetCreateClassView(isShowingSheet: $isShowingSheet, vm: .init(provider: provider))
|
CreateClassView(isShowingSheet: $isShowingSheet, vm: .init(provider: provider))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,12 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct SheetCreateClassView: View {
|
struct CreateClassView: View {
|
||||||
@Binding var isShowingSheet: Bool
|
@Binding var isShowingSheet: Bool
|
||||||
@State private var textForNameOfClass = ""
|
|
||||||
@State private var textForNameOfAuditory = ""
|
|
||||||
@State private var textForNameOfProfessor = ""
|
|
||||||
@State private var isShowingDatePickerForDate: Bool = false
|
@State private var isShowingDatePickerForDate: Bool = false
|
||||||
@State private var isImportant: Bool = false
|
|
||||||
@State private var selectedOptionForNotification: String = "Нет"
|
|
||||||
@State private var selectedOptionForOnline: String = "Оффлайн"
|
|
||||||
@State private var textForComment: String = ""
|
|
||||||
@ObservedObject var vm: EditClassViewModel
|
@ObservedObject var vm: EditClassViewModel
|
||||||
|
@State private var isIncorrectDate1: Bool = false
|
||||||
|
@State private var isIncorrectDate2: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
@ -54,20 +49,42 @@ struct SheetCreateClassView: View {
|
|||||||
}
|
}
|
||||||
.padding(.bottom, 10)
|
.padding(.bottom, 10)
|
||||||
HStack {
|
HStack {
|
||||||
StartEndTimeFieldView(selectedTime: $vm._class.starttime, imageName: "clock", text: "Начало")
|
StartEndTimeFieldView(isIncorrectDate: $isIncorrectDate1, selectedDay: $vm._class.day, selectedTime: $vm._class.starttime, imageName: "clock", text: "Начало")
|
||||||
.onChange(of: vm._class.starttime) { oldValue, newValue in
|
.onChange(of: vm._class.starttime) { oldValue, newValue in
|
||||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||||
print("Values \(oldValue) - \(newValue) 1")
|
self.isIncorrectDate1 = true
|
||||||
print(vm._class.starttime)
|
}
|
||||||
vm._class.starttime = oldValue
|
else {
|
||||||
|
self.isIncorrectDate1 = false
|
||||||
|
self.isIncorrectDate2 = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.overlay {
|
||||||
|
if isIncorrectDate1 {
|
||||||
|
Rectangle()
|
||||||
|
.frame(maxWidth: 300, maxHeight: 1)
|
||||||
|
.foregroundColor(.red)
|
||||||
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
StartEndTimeFieldView(selectedTime: $vm._class.endtime, imageName: "clock.badge.xmark", text: "Конец")
|
StartEndTimeFieldView(isIncorrectDate: $isIncorrectDate2, selectedDay: $vm._class.day, selectedTime: $vm._class.endtime, imageName: "clock.badge.xmark", text: "Конец")
|
||||||
.onChange(of: vm._class.endtime) { oldValue, newValue in
|
.onChange(of: vm._class.endtime) { oldValue, newValue in
|
||||||
print("Values \(oldValue) - \(newValue) 2")
|
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
||||||
print(vm._class.endtime)
|
self.isIncorrectDate2 = true
|
||||||
validateTime(old: oldValue, new: newValue, isStartChanged: false)
|
}
|
||||||
|
else {
|
||||||
|
self.isIncorrectDate1 = false
|
||||||
|
self.isIncorrectDate2 = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.overlay {
|
||||||
|
if isIncorrectDate2 {
|
||||||
|
Rectangle()
|
||||||
|
.frame(maxWidth: 300, maxHeight: 1)
|
||||||
|
.foregroundColor(.red)
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(height: 40)
|
.frame(height: 40)
|
||||||
@ -143,18 +160,38 @@ struct SheetCreateClassView: View {
|
|||||||
.background(Color("background"))
|
.background(Color("background"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func validateTime(old oldValue: Date, new newValue: Date, isStartChanged: Bool) {
|
func checkStartTimeLessThenEndTime(_ startTime: Date, _ endTime: Date) -> Bool {
|
||||||
if !checkStartTimeLessThenEndTime(vm._class.starttime, vm._class.endtime) {
|
let calendar = Calendar.current
|
||||||
if isStartChanged {
|
|
||||||
vm._class.starttime = Date()
|
let firstComponents = calendar.dateComponents([.hour, .minute], from: startTime)
|
||||||
} else {
|
let secondComponents = calendar.dateComponents([.hour, .minute], from: endTime)
|
||||||
vm._class.starttime = Date()
|
|
||||||
|
guard let startHours = firstComponents.hour, let startMinutes = firstComponents.minute else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
guard let endHours = secondComponents.hour, let endMinutes = secondComponents.minute else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
print("\(startHours) - \(endHours)")
|
||||||
|
print("\(startMinutes) - \(endMinutes)")
|
||||||
|
if Int(startHours) > Int(endHours) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
else if startHours == endHours {
|
||||||
|
if startMinutes < endMinutes {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
print("Invalid time selected. Reverting to old value.")
|
else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
SheetCreateClassView(isShowingSheet: .constant(true), vm: .init(provider: .shared))
|
CreateClassView(isShowingSheet: .constant(true), vm: .init(provider: .shared))
|
||||||
}
|
}
|
103
Schedule ICTIS/Main/Views/Sheets/EditClassView.swift
Normal file
103
Schedule ICTIS/Main/Views/Sheets/EditClassView.swift
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//
|
||||||
|
// SheetCreateClassView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by Mironov Egor on 12.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct EditClassView: View {
|
||||||
|
@State private var isIncorrectDate1: Bool = false
|
||||||
|
@State private var isIncorrectDate2: Bool = false
|
||||||
|
@Binding var isShowingSheet: Bool
|
||||||
|
|
||||||
|
let _class: ClassModel
|
||||||
|
|
||||||
|
@State private var subject: String = ""
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
ProfessorAuditoryClassFieldView(text: $subject, nameOfImage: "book", labelForField: "Предмет")
|
||||||
|
.padding(.bottom, 10)
|
||||||
|
List {
|
||||||
|
Section("General") {
|
||||||
|
LabeledContent {
|
||||||
|
Text(_class.subject)
|
||||||
|
} label: {
|
||||||
|
Text("Предмет")
|
||||||
|
}
|
||||||
|
|
||||||
|
LabeledContent {
|
||||||
|
Text(_class.auditory)
|
||||||
|
} label: {
|
||||||
|
Text("Аудитория")
|
||||||
|
}
|
||||||
|
|
||||||
|
LabeledContent {
|
||||||
|
Text(_class.day, style: .date)
|
||||||
|
} label: {
|
||||||
|
Text("Преподаватель")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Section("Notes") {
|
||||||
|
Text(_class.comment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .navigationBarLeading) {
|
||||||
|
Button("Отменить") {
|
||||||
|
isShowingSheet = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
|
Button("Сохранить") {
|
||||||
|
isShowingSheet = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onAppear {
|
||||||
|
subject = _class.subject
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkStartTimeLessThenEndTime(_ startTime: Date, _ endTime: Date) -> Bool {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
|
||||||
|
let firstComponents = calendar.dateComponents([.hour, .minute], from: startTime)
|
||||||
|
let secondComponents = calendar.dateComponents([.hour, .minute], from: endTime)
|
||||||
|
|
||||||
|
guard let startHours = firstComponents.hour, let startMinutes = firstComponents.minute else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
guard let endHours = secondComponents.hour, let endMinutes = secondComponents.minute else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
print("\(startHours) - \(endHours)")
|
||||||
|
print("\(startMinutes) - \(endMinutes)")
|
||||||
|
if Int(startHours) > Int(endHours) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
else if startHours == endHours {
|
||||||
|
if startMinutes < endMinutes {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
NavigationStack {
|
||||||
|
EditClassView(isShowingSheet: .constant(true), _class: .preview())
|
||||||
|
}
|
||||||
|
}
|
@ -1,37 +0,0 @@
|
|||||||
//
|
|
||||||
// SheetView.swift
|
|
||||||
// Schedule ICTIS
|
|
||||||
//
|
|
||||||
// Created by Mironov Egor on 12.12.2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
struct SheetChangeClassView: View {
|
|
||||||
@Binding var isShowingSheet: Bool
|
|
||||||
var body: some View {
|
|
||||||
NavigationView {
|
|
||||||
VStack {
|
|
||||||
Spacer()
|
|
||||||
Text("Редактирвоание пары")
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
.toolbar {
|
|
||||||
ToolbarItem(placement: .navigationBarLeading) {
|
|
||||||
Button("Отменить") {
|
|
||||||
isShowingSheet = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
|
||||||
Button("Сохранить") {
|
|
||||||
isShowingSheet = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Preview {
|
|
||||||
SheetChangeClassView(isShowingSheet: .constant(true))
|
|
||||||
}
|
|
@ -65,7 +65,7 @@ struct MonthTabView: View {
|
|||||||
VStack (spacing: 10) {
|
VStack (spacing: 10) {
|
||||||
ForEach(month.indices, id: \.self) { index in
|
ForEach(month.indices, id: \.self) { index in
|
||||||
let week = month[index].week
|
let week = month[index].week
|
||||||
WeekView(week)
|
WeekViewForMonth(week: week, vm: vm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.background {
|
.background {
|
||||||
@ -85,92 +85,29 @@ struct MonthTabView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
func WeekView(_ week: [Date.WeekDay]) -> some View {
|
|
||||||
HStack (spacing: 23) {
|
|
||||||
ForEach(week) { day in
|
|
||||||
VStack {
|
|
||||||
Text(day.date.format("dd"))
|
|
||||||
.font(.system(size: 15, weight: .bold))
|
|
||||||
.foregroundStyle(isDateInCurrentMonth(day.date) ? isSameDate(day.date, vm.selectedDay) ? Color.white : Color.black: isSameDate(day.date, vm.selectedDay) ? Color.white : Color("greyForDaysInMonthTabView"))
|
|
||||||
}
|
|
||||||
.frame(width: 30, height: 30, alignment: .center)
|
|
||||||
.background( content: {
|
|
||||||
Group {
|
|
||||||
if isSameDate(day.date, vm.selectedDay) {
|
|
||||||
Color("blueColor")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Color("background")
|
|
||||||
}
|
|
||||||
if isSameDate(day.date, vm.selectedDay) {
|
|
||||||
Color("blueColor")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.overlay (
|
|
||||||
Group {
|
|
||||||
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
|
||||||
RoundedRectangle(cornerRadius: 100)
|
|
||||||
.stroke(Color("blueColor"), lineWidth: 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.cornerRadius(15)
|
|
||||||
.onTapGesture {
|
|
||||||
if isSameWeek(day.date, vm.selectedDay) {
|
|
||||||
print("На одной неделе")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date)
|
|
||||||
if day.date < vm.selectedDay {
|
|
||||||
difBetweenWeeks = difBetweenWeeks * -1
|
|
||||||
}
|
|
||||||
print(difBetweenWeeks)
|
|
||||||
vm.fetchWeekSchedule("", difBetweenWeeks)
|
|
||||||
}
|
|
||||||
vm.selectedDay = day.date
|
|
||||||
vm.updateSelectedDayIndex()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func paginateMonth(_ indexOfWeek: Int = 0) {
|
func paginateMonth(_ indexOfWeek: Int = 0) {
|
||||||
let calendar = Calendar.current
|
let calendar = Calendar.current
|
||||||
if monthSlider.indices.contains(currentMonthIndex) {
|
if monthSlider.indices.contains(currentMonthIndex) {
|
||||||
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
if let firstDate = monthSlider[currentMonthIndex].first?.week[0].date,
|
||||||
currentMonthIndex == 0 {
|
currentMonthIndex == 0 {
|
||||||
// switch (vm.numOfGroup) {
|
|
||||||
// case "":
|
|
||||||
// vm.week -= 1
|
|
||||||
// default:
|
|
||||||
// vm.fetchWeekSchedule("new week", -1)
|
|
||||||
// }
|
|
||||||
monthSlider.insert(firstDate.createPreviousMonth(), at: 0)
|
monthSlider.insert(firstDate.createPreviousMonth(), at: 0)
|
||||||
monthSlider.removeLast()
|
monthSlider.removeLast()
|
||||||
currentMonthIndex = 1
|
currentMonthIndex = 1
|
||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -5, to: vm.selectedDay) ?? Date.init()
|
||||||
vm.updateSelectedDayIndex()
|
vm.updateSelectedDayIndex()
|
||||||
vm.fetchWeekSchedule("", -5)
|
vm.week -= 5
|
||||||
|
vm.fetchWeekSchedule("")
|
||||||
}
|
}
|
||||||
|
|
||||||
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
if let lastDate = monthSlider[currentMonthIndex].last?.week[6].date,
|
||||||
currentMonthIndex == (monthSlider.count - 1) {
|
currentMonthIndex == (monthSlider.count - 1) {
|
||||||
// switch (vm.numOfGroup) {
|
|
||||||
// case "":
|
|
||||||
// vm.week += 1
|
|
||||||
// default:
|
|
||||||
// vm.fetchWeekSchedule("new week", 1)
|
|
||||||
// }
|
|
||||||
monthSlider.append(lastDate.createNextMonth())
|
monthSlider.append(lastDate.createNextMonth())
|
||||||
monthSlider.removeFirst()
|
monthSlider.removeFirst()
|
||||||
currentMonthIndex = monthSlider.count - 2
|
currentMonthIndex = monthSlider.count - 2
|
||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 5, to: vm.selectedDay) ?? Date.init()
|
||||||
vm.updateSelectedDayIndex()
|
vm.updateSelectedDayIndex()
|
||||||
vm.fetchWeekSchedule("", 5)
|
vm.week += 5
|
||||||
|
vm.fetchWeekSchedule("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ struct WeekTabView: View {
|
|||||||
TabView(selection: $currentWeekIndex) {
|
TabView(selection: $currentWeekIndex) {
|
||||||
ForEach(weekSlider.indices, id: \.self) { index in
|
ForEach(weekSlider.indices, id: \.self) { index in
|
||||||
let week = weekSlider[index]
|
let week = weekSlider[index]
|
||||||
WeekView(week)
|
WeekViewForWeek(weekSlider: $weekSlider, currentWeekIndex: $currentWeekIndex, createWeek: $createWeek, week: week, vm: vm)
|
||||||
.padding(.horizontal, 15)
|
.padding(.horizontal, 15)
|
||||||
.tag(index)
|
.tag(index)
|
||||||
}
|
}
|
||||||
@ -48,103 +48,6 @@ struct WeekTabView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
func WeekView(_ week: [Date.WeekDay]) -> some View {
|
|
||||||
HStack (spacing: 10) {
|
|
||||||
ForEach(week) { day in
|
|
||||||
VStack (spacing: 1) {
|
|
||||||
Text(day.date.format("E"))
|
|
||||||
.font(.system(size: 15, weight: .semibold))
|
|
||||||
.foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, vm.selectedDay) ? Color("customGray1") : Color("customGray3"))
|
|
||||||
.padding(.top, 13)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
Text(day.date.format("dd"))
|
|
||||||
.font(.system(size: 15, weight: .bold))
|
|
||||||
.foregroundStyle(isSameDate(day.date, vm.selectedDay) ? .white : .black)
|
|
||||||
.padding(.bottom, 13)
|
|
||||||
}
|
|
||||||
.frame(width: 43, height: 55, alignment: .center)
|
|
||||||
.background( content: {
|
|
||||||
Group {
|
|
||||||
if isSameDate(day.date, vm.selectedDay) {
|
|
||||||
Color("blueColor")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Color(.white)
|
|
||||||
}
|
|
||||||
if isSameDate(day.date, vm.selectedDay) {
|
|
||||||
Color("blueColor")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.overlay (
|
|
||||||
Group {
|
|
||||||
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
|
||||||
RoundedRectangle(cornerRadius: 15)
|
|
||||||
.stroke(Color("blueColor"), lineWidth: 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.cornerRadius(15)
|
|
||||||
.onTapGesture {
|
|
||||||
vm.selectedDay = day.date
|
|
||||||
vm.updateSelectedDayIndex()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.background {
|
|
||||||
GeometryReader {
|
|
||||||
let minX = $0.frame(in: .global).minX
|
|
||||||
|
|
||||||
Color.clear
|
|
||||||
.preference(key: OffsetKey.self, value: minX)
|
|
||||||
.onPreferenceChange(OffsetKey.self) { value in
|
|
||||||
if value.rounded() == 15 && createWeek {
|
|
||||||
paginateWeek()
|
|
||||||
|
|
||||||
createWeek = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func paginateWeek() {
|
|
||||||
let calendar = Calendar.current
|
|
||||||
if weekSlider.indices.contains(currentWeekIndex) {
|
|
||||||
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
|
||||||
currentWeekIndex == 0 {
|
|
||||||
switch (vm.numOfGroup) {
|
|
||||||
case "":
|
|
||||||
vm.week -= 1
|
|
||||||
default:
|
|
||||||
vm.fetchWeekSchedule("new week", -1)
|
|
||||||
}
|
|
||||||
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
|
||||||
weekSlider.removeLast()
|
|
||||||
currentWeekIndex = 1
|
|
||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
|
||||||
vm.updateSelectedDayIndex()
|
|
||||||
}
|
|
||||||
|
|
||||||
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
|
||||||
currentWeekIndex == (weekSlider.count - 1) {
|
|
||||||
switch (vm.numOfGroup) {
|
|
||||||
case "":
|
|
||||||
vm.week += 1
|
|
||||||
default:
|
|
||||||
vm.fetchWeekSchedule("new week", 1)
|
|
||||||
}
|
|
||||||
weekSlider.append(lastDate.createNextWeek())
|
|
||||||
weekSlider.removeFirst()
|
|
||||||
currentWeekIndex = weekSlider.count - 2
|
|
||||||
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
|
||||||
vm.updateSelectedDayIndex()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
70
Schedule ICTIS/Main/Views/TabViews/WeekViewForMonth.swift
Normal file
70
Schedule ICTIS/Main/Views/TabViews/WeekViewForMonth.swift
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
//
|
||||||
|
// WeekViewForMonth.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 20.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct WeekViewForMonth: View {
|
||||||
|
let week: [Date.WeekDay]
|
||||||
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 23) {
|
||||||
|
ForEach(week) { day in
|
||||||
|
VStack {
|
||||||
|
Text(day.date.format("dd"))
|
||||||
|
.font(.system(size: 15, weight: .bold))
|
||||||
|
.foregroundStyle(getForegroundColor(day: day))
|
||||||
|
}
|
||||||
|
.frame(width: 30, height: 30, alignment: .center)
|
||||||
|
.background(getBackgroundColor(day: day))
|
||||||
|
.overlay(overlay(day: day))
|
||||||
|
.cornerRadius(15)
|
||||||
|
.onTapGesture {
|
||||||
|
handleTap(day: day)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getForegroundColor(day: Date.WeekDay) -> Color {
|
||||||
|
if isDateInCurrentMonth(day.date) {
|
||||||
|
return isSameDate(day.date, vm.selectedDay) ? .white : .black
|
||||||
|
} else {
|
||||||
|
return isSameDate(day.date, vm.selectedDay) ? .white : Color("greyForDaysInMonthTabView")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getBackgroundColor(day: Date.WeekDay) -> Color {
|
||||||
|
return isSameDate(day.date, vm.selectedDay) ? Color("blueColor") : Color("background")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func overlay(day: Date.WeekDay) -> some View {
|
||||||
|
Group {
|
||||||
|
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
||||||
|
RoundedRectangle(cornerRadius: 100)
|
||||||
|
.stroke(Color("blueColor"), lineWidth: 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleTap(day: Date.WeekDay) {
|
||||||
|
if isSameWeek(day.date, vm.selectedDay) {
|
||||||
|
print("На одной неделе")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var difBetweenWeeks = weeksBetween(startDate: vm.selectedDay, endDate: day.date)
|
||||||
|
if day.date < vm.selectedDay {
|
||||||
|
difBetweenWeeks = difBetweenWeeks * -1
|
||||||
|
}
|
||||||
|
print(difBetweenWeeks)
|
||||||
|
vm.week += difBetweenWeeks
|
||||||
|
vm.fetchWeekSchedule("")
|
||||||
|
}
|
||||||
|
vm.selectedDay = day.date
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
}
|
||||||
|
}
|
102
Schedule ICTIS/Main/Views/TabViews/WeekViewForWeek.swift
Normal file
102
Schedule ICTIS/Main/Views/TabViews/WeekViewForWeek.swift
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
//
|
||||||
|
// WeekView.swift
|
||||||
|
// Schedule ICTIS
|
||||||
|
//
|
||||||
|
// Created by G412 on 20.12.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct WeekViewForWeek: View {
|
||||||
|
@Binding var weekSlider: [[Date.WeekDay]]
|
||||||
|
@Binding var currentWeekIndex: Int
|
||||||
|
@Binding var createWeek: Bool
|
||||||
|
let week: [Date.WeekDay]
|
||||||
|
@ObservedObject var vm: ScheduleViewModel
|
||||||
|
var body: some View {
|
||||||
|
HStack (spacing: 10) {
|
||||||
|
ForEach(week) { day in
|
||||||
|
VStack (spacing: 1) {
|
||||||
|
Text(day.date.format("E"))
|
||||||
|
.font(.system(size: 15, weight: .semibold))
|
||||||
|
.foregroundColor(day.date.format("E") == "Вс" ? Color(.red) : isSameDate(day.date, vm.selectedDay) ? Color("customGray1") : Color("customGray3"))
|
||||||
|
.padding(.top, 13)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(day.date.format("dd"))
|
||||||
|
.font(.system(size: 15, weight: .bold))
|
||||||
|
.foregroundStyle(isSameDate(day.date, vm.selectedDay) ? .white : .black)
|
||||||
|
.padding(.bottom, 13)
|
||||||
|
}
|
||||||
|
.frame(width: 43, height: 55, alignment: .center)
|
||||||
|
.background( content: {
|
||||||
|
Group {
|
||||||
|
if isSameDate(day.date, vm.selectedDay) {
|
||||||
|
Color("blueColor")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Color(.white)
|
||||||
|
}
|
||||||
|
if isSameDate(day.date, vm.selectedDay) {
|
||||||
|
Color("blueColor")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.overlay (
|
||||||
|
Group {
|
||||||
|
if day.date.isToday && !isSameDate(day.date, vm.selectedDay) {
|
||||||
|
RoundedRectangle(cornerRadius: 15)
|
||||||
|
.stroke(Color("blueColor"), lineWidth: 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.cornerRadius(15)
|
||||||
|
.onTapGesture {
|
||||||
|
vm.selectedDay = day.date
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background {
|
||||||
|
GeometryReader {
|
||||||
|
let minX = $0.frame(in: .global).minX
|
||||||
|
|
||||||
|
Color.clear
|
||||||
|
.preference(key: OffsetKey.self, value: minX)
|
||||||
|
.onPreferenceChange(OffsetKey.self) { value in
|
||||||
|
if value.rounded() == 15 && createWeek {
|
||||||
|
paginateWeek()
|
||||||
|
|
||||||
|
createWeek = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func paginateWeek() {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
if weekSlider.indices.contains(currentWeekIndex) {
|
||||||
|
if let firstDate = weekSlider[currentWeekIndex].first?.date,
|
||||||
|
currentWeekIndex == 0 {
|
||||||
|
vm.week -= 1
|
||||||
|
vm.fetchWeekSchedule("")
|
||||||
|
weekSlider.insert(firstDate.createPrevioustWeek(), at: 0)
|
||||||
|
weekSlider.removeLast()
|
||||||
|
currentWeekIndex = 1
|
||||||
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: -1, to: vm.selectedDay) ?? Date.init()
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
}
|
||||||
|
|
||||||
|
if let lastDate = weekSlider[currentWeekIndex].last?.date,
|
||||||
|
currentWeekIndex == (weekSlider.count - 1) {
|
||||||
|
vm.week += 1
|
||||||
|
vm.fetchWeekSchedule("")
|
||||||
|
weekSlider.append(lastDate.createNextWeek())
|
||||||
|
weekSlider.removeFirst()
|
||||||
|
currentWeekIndex = weekSlider.count - 2
|
||||||
|
vm.selectedDay = calendar.date(byAdding: .weekOfYear, value: 1, to: vm.selectedDay) ?? Date.init()
|
||||||
|
vm.updateSelectedDayIndex()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,11 +20,16 @@ final class ClassModel: NSManagedObject, Identifiable {
|
|||||||
@NSManaged var important: Bool
|
@NSManaged var important: Bool
|
||||||
@NSManaged var online: String
|
@NSManaged var online: String
|
||||||
|
|
||||||
|
static var dateNow: Date = .now
|
||||||
|
|
||||||
// Здесь мы выполняем дополнительную инициализацию, назначая значения по умолчанию
|
// Здесь мы выполняем дополнительную инициализацию, назначая значения по умолчанию
|
||||||
override func awakeFromInsert() {
|
override func awakeFromInsert() {
|
||||||
super.awakeFromInsert()
|
super.awakeFromInsert()
|
||||||
|
|
||||||
let calendar = Calendar.current
|
let moscowTimeZone = TimeZone(identifier: "Europe/Moscow")!
|
||||||
|
var calendar = Calendar.current
|
||||||
|
calendar.timeZone = moscowTimeZone
|
||||||
|
let startTime = Date()
|
||||||
let endTime = calendar.date(byAdding: .hour, value: 1, to: Date.init())
|
let endTime = calendar.date(byAdding: .hour, value: 1, to: Date.init())
|
||||||
|
|
||||||
setPrimitiveValue("", forKey: "auditory")
|
setPrimitiveValue("", forKey: "auditory")
|
||||||
@ -34,19 +39,20 @@ final class ClassModel: NSManagedObject, Identifiable {
|
|||||||
setPrimitiveValue("Нет", forKey: "notification")
|
setPrimitiveValue("Нет", forKey: "notification")
|
||||||
setPrimitiveValue(false, forKey: "important")
|
setPrimitiveValue(false, forKey: "important")
|
||||||
setPrimitiveValue("Оффлайн", forKey: "online")
|
setPrimitiveValue("Оффлайн", forKey: "online")
|
||||||
setPrimitiveValue(Date.init(), forKey: "day")
|
setPrimitiveValue(startTime, forKey: "day")
|
||||||
setPrimitiveValue(Date.init(), forKey: "starttime")
|
setPrimitiveValue(startTime, forKey: "starttime")
|
||||||
setPrimitiveValue(endTime, forKey: "endtime")
|
setPrimitiveValue(endTime, forKey: "endtime")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Расширение для загрузки данных из памяти
|
// Расширение для загрузки данных из памяти
|
||||||
extension ClassModel {
|
extension ClassModel {
|
||||||
|
// Получаем все данные из памяти
|
||||||
private static var classesFetchRequest: NSFetchRequest<ClassModel> {
|
private static var classesFetchRequest: NSFetchRequest<ClassModel> {
|
||||||
NSFetchRequest(entityName: "ClassModel")
|
NSFetchRequest(entityName: "ClassModel")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем все данные из памяти
|
// Получаем все данные и сортируем их по дню
|
||||||
static func all() -> NSFetchRequest<ClassModel> {
|
static func all() -> NSFetchRequest<ClassModel> {
|
||||||
let request: NSFetchRequest<ClassModel> = classesFetchRequest
|
let request: NSFetchRequest<ClassModel> = classesFetchRequest
|
||||||
request.sortDescriptors = [
|
request.sortDescriptors = [
|
||||||
@ -55,3 +61,29 @@ extension ClassModel {
|
|||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension ClassModel {
|
||||||
|
@discardableResult
|
||||||
|
static func makePreview(count: Int, in context: NSManagedObjectContext) -> [ClassModel] {
|
||||||
|
var classes = [ClassModel]()
|
||||||
|
for i in 0..<count {
|
||||||
|
let _class = ClassModel(context: context)
|
||||||
|
_class.subject = "Предмет \(i)"
|
||||||
|
_class.auditory = "Аудитория \(i)"
|
||||||
|
_class.professor = "Преподаватель \(i)"
|
||||||
|
_class.day = Calendar.current.date(byAdding: .day, value: i, to: .now) ?? .now
|
||||||
|
_class.starttime = Date()
|
||||||
|
_class.endtime = Calendar.current.date(byAdding: .hour, value: i, to: .now) ?? .now
|
||||||
|
classes.append(_class)
|
||||||
|
}
|
||||||
|
return classes
|
||||||
|
}
|
||||||
|
|
||||||
|
static func preview(context: NSManagedObjectContext = ClassProvider.shared.viewContext) -> ClassModel {
|
||||||
|
return makePreview(count: 1, in: context)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
static func empty(context: NSManagedObjectContext = ClassProvider.shared.viewContext) -> ClassModel {
|
||||||
|
return ClassModel(context: context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import CoreData
|
import CoreData
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
// Это класс служит посредником между View и моделью данных
|
// Это класс служит посредником между View и моделью данных
|
||||||
// Он позволяет открыть наш файл данных чтобы записывать и извлекать значения
|
// Он позволяет открыть наш файл данных чтобы записывать и извлекать значения
|
||||||
@ -29,6 +30,9 @@ final class ClassProvider {
|
|||||||
private init() {
|
private init() {
|
||||||
// Открытие файла
|
// Открытие файла
|
||||||
persistentContainer = NSPersistentContainer(name: "ClassDataModel")
|
persistentContainer = NSPersistentContainer(name: "ClassDataModel")
|
||||||
|
if EnvironmentValues.isPreview {
|
||||||
|
persistentContainer.persistentStoreDescriptions.first?.url = .init(filePath: "/dev/null")
|
||||||
|
}
|
||||||
|
|
||||||
// Выставляем флаг для автоматического сохранения изменений данных из Veiw в память
|
// Выставляем флаг для автоматического сохранения изменений данных из Veiw в память
|
||||||
persistentContainer.viewContext.automaticallyMergesChangesFromParent = true
|
persistentContainer.viewContext.automaticallyMergesChangesFromParent = true
|
||||||
@ -42,3 +46,9 @@ final class ClassProvider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension EnvironmentValues {
|
||||||
|
static var isPreview: Bool {
|
||||||
|
return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -120,37 +120,6 @@ extension View {
|
|||||||
return formatter
|
return formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkStartTimeLessThenEndTime(_ startTime: Date, _ endTime: Date) -> Bool {
|
|
||||||
let calendar = Calendar.current
|
|
||||||
|
|
||||||
let firstComponents = calendar.dateComponents([.hour, .minute], from: startTime)
|
|
||||||
let secondComponents = calendar.dateComponents([.hour, .minute], from: endTime)
|
|
||||||
|
|
||||||
guard let startHours = firstComponents.hour, let startMinutes = firstComponents.minute else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
guard let endHours = secondComponents.hour, let endMinutes = secondComponents.minute else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
print("\(startHours) - \(endHours)")
|
|
||||||
print("\(startMinutes) - \(endMinutes)")
|
|
||||||
if startHours > endHours {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
else if startHours == endHours {
|
|
||||||
if startMinutes < endMinutes {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkUpFields(_ subject: String, _ auditory: String, _ professor: String, _ time1: Date, _ time3: Date) -> Bool {
|
func checkUpFields(_ subject: String, _ auditory: String, _ professor: String, _ time1: Date, _ time3: Date) -> Bool {
|
||||||
if (subject != "" || auditory != "" || professor != "") {
|
if (subject != "" || auditory != "" || professor != "") {
|
||||||
return true
|
return true
|
||||||
|
@ -30,14 +30,13 @@ final class ScheduleViewModel: ObservableObject {
|
|||||||
@Published var group: String = ""
|
@Published var group: String = ""
|
||||||
|
|
||||||
//MARK: Methods
|
//MARK: Methods
|
||||||
func fetchWeekSchedule(_ group: String, _ num: Int = 0) {
|
func fetchWeekSchedule(_ group: String) {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
var schedule: Schedule
|
var schedule: Schedule
|
||||||
if (num != 0) {
|
if !self.numOfGroup.isEmpty {
|
||||||
week += num
|
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(self.week, self.numOfGroup)
|
||||||
schedule = try await NetworkManager.shared.getScheduleForOtherWeek(week, numOfGroup)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
schedule = try await NetworkManager.shared.getSchedule(group)
|
schedule = try await NetworkManager.shared.getSchedule(group)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user