Skip to content

Commit

Permalink
Merge pull request #97 from aapis/feature/better-export
Browse files Browse the repository at this point in the history
New feature: Today modified "view mode"
  • Loading branch information
aapis authored Apr 16, 2023
2 parents 7660df0 + b6df902 commit cb196e0
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 29 deletions.
12 changes: 10 additions & 2 deletions DLPrototype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
53959A1D2973897F007A2549 /* ProjectConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53959A1C2973897F007A2549 /* ProjectConfig.swift */; };
53959A1F29738AAA007A2549 /* FancySubTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53959A1E29738AAA007A2549 /* FancySubTitle.swift */; };
53959A212973D3E5007A2549 /* CoreDataProjectConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53959A202973D3E5007A2549 /* CoreDataProjectConfiguration.swift */; };
53967D8429EC6D14006616A0 /* TodaySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53967D8329EC6D14006616A0 /* TodaySettings.swift */; };
53967D8629EC7DEB006616A0 /* ViewModeSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53967D8529EC7DEB006616A0 /* ViewModeSelector.swift */; };
53999C1F29669C4E00125E65 /* NoteCreate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53999C1E29669C4E00125E65 /* NoteCreate.swift */; };
539C0E75296CC34600023370 /* Manage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 533AB3EA296C9A1900E91A9F /* Manage.swift */; };
539C96EA27EE7AFF007DA058 /* CalendarThisWeek.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539C96E927EE7AFF007DA058 /* CalendarThisWeek.swift */; };
Expand Down Expand Up @@ -183,6 +185,8 @@
53959A1C2973897F007A2549 /* ProjectConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectConfig.swift; sourceTree = "<group>"; };
53959A1E29738AAA007A2549 /* FancySubTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FancySubTitle.swift; sourceTree = "<group>"; };
53959A202973D3E5007A2549 /* CoreDataProjectConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataProjectConfiguration.swift; sourceTree = "<group>"; };
53967D8329EC6D14006616A0 /* TodaySettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodaySettings.swift; sourceTree = "<group>"; };
53967D8529EC7DEB006616A0 /* ViewModeSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModeSelector.swift; sourceTree = "<group>"; };
53999C1E29669C4E00125E65 /* NoteCreate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteCreate.swift; sourceTree = "<group>"; };
539C96E927EE7AFF007DA058 /* CalendarThisWeek.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarThisWeek.swift; sourceTree = "<group>"; };
53B0BE7E2972542A007CB663 /* ProjectsDashboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectsDashboard.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -280,6 +284,7 @@
children = (
53EFCE7A29637F49004E45EC /* Settings.swift */,
53EFCE7829637F35004E45EC /* GeneralSettings.swift */,
53967D8329EC6D14006616A0 /* TodaySettings.swift */,
);
path = Settings;
sourceTree = "<group>";
Expand Down Expand Up @@ -590,6 +595,7 @@
53EFCE7C2963D309004E45EC /* LogTableDetails.swift */,
5376289F2966518B00DE8ECF /* ToolbarTabs.swift */,
537628A12966525500DE8ECF /* ToolbarButtons.swift */,
53967D8529EC7DEB006616A0 /* ViewModeSelector.swift */,
);
path = LogTable;
sourceTree = "<group>";
Expand Down Expand Up @@ -796,11 +802,13 @@
53152CD0296A245200A14E43 /* ClipboardHelper.swift in Sources */,
53B0BE90297333C3007CB663 /* ManageProjects.swift in Sources */,
53B0BE8129725B52007CB663 /* CoreDataProjects.swift in Sources */,
53967D8629EC7DEB006616A0 /* ViewModeSelector.swift in Sources */,
53152CCC2969453000A14E43 /* DateHelper.swift in Sources */,
53C3418C299960310071B855 /* JobDashboard.swift in Sources */,
539C96EA27EE7AFF007DA058 /* CalendarThisWeek.swift in Sources */,
53F5896229983EEB00843B32 /* TaskResult.swift in Sources */,
53521E54296FBDAE002E7F21 /* CoreDataNoteVersions.swift in Sources */,
53967D8429EC6D14006616A0 /* TodaySettings.swift in Sources */,
53759E0F2968AB5700DCDC4B /* SyncMonitor.swift in Sources */,
537AEB9F29627DCC00385787 /* LogTable.swift in Sources */,
537AEBA329629DE400385787 /* LogRowActions.swift in Sources */,
Expand Down Expand Up @@ -977,7 +985,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 84;
CURRENT_PROJECT_VERSION = 85;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down Expand Up @@ -1008,7 +1016,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 84;
CURRENT_PROJECT_VERSION = 85;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DLPrototype/Preview Content\"";
DEVELOPMENT_TEAM = 6DT7L2N5X6;
Expand Down
1 change: 1 addition & 0 deletions DLPrototype/Utils/ViewUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ViewUpdater: ObservableObject {
@Published public var ids: [String: UUID] = [
"today.table": UUID(),
"today.picker": UUID(),
"today.dayList": UUID(),
"ltd.rows": UUID(),
"dg.hasView": UUID(),
"dg.hasNoView": UUID(),
Expand Down
4 changes: 0 additions & 4 deletions DLPrototype/Views/Settings/GeneralSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ struct GeneralSettings: View {
@AppStorage("showExperiment.actions") private var showExperimentActions: Bool = false
@AppStorage("enableAutoCorrection") public var enableAutoCorrection: Bool = false
@AppStorage("autoFixJobs") public var autoFixJobs: Bool = false
@AppStorage("showSidebar") public var showSidebar: Bool = true
@AppStorage("showTodaySearch") public var showSearch: Bool = true
@AppStorage("defaultHome") public var defaultHome: Int = 0

var body: some View {
Form {
Toggle("Tiger stripe table rows", isOn: $tigerStriped)
Toggle("Auto-correct text in text boxes", isOn: $enableAutoCorrection)
Toggle("Show sidebar", isOn: $showSidebar)
Toggle("Show search on Today", isOn: $showSearch)

Group {
Toggle("Experimental features (may tank performance)", isOn: $showExperimentalFeatures)
Expand Down
9 changes: 7 additions & 2 deletions DLPrototype/Views/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI

struct SettingsView: View {
private enum Tabs: Hashable {
case general, advanced
case general, today, advanced
}
var body: some View {
TabView {
Expand All @@ -20,9 +20,14 @@ struct SettingsView: View {
Label("General", systemImage: "gear")
}
.tag(Tabs.general)

TodaySettings()
.tabItem {
Label("Today", systemImage: "doc.append.fill")
}
.tag(Tabs.today)
}
.padding(20)
.frame(width: 375, height: 150)
}
}

Expand Down
44 changes: 44 additions & 0 deletions DLPrototype/Views/Settings/TodaySettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// TodaySettings.swift
// DLPrototype
//
// Created by Ryan Priebe on 2023-04-16.
// Copyright © 2023 YegCollective. All rights reserved.
//

import Foundation
import SwiftUI

struct TodaySettings: View {
@AppStorage("today.numPastDates") public var numPastDates: Int = 20
@AppStorage("today.viewMode") public var viewMode: Int = 0
@AppStorage("showSidebar") public var showSidebar: Bool = true
@AppStorage("showTodaySearch") public var showSearch: Bool = true

var body: some View {
Form {
Picker("Max number of days", selection: $numPastDates) {
Text("7").tag(7)
Text("10").tag(10)
Text("20").tag(20)
Text("30").tag(30)
Text("40").tag(40)
}

Picker("Default view mode", selection: $viewMode) {
Text("Full").tag(1)
Text("Plain").tag(2)
}

Toggle("Show sidebar", isOn: $showSidebar)
Toggle("Show search on Today", isOn: $showSearch)
}
.padding(20)
}
}

struct TodaySettingsPreview: PreviewProvider {
static var previews: some View {
TodaySettings()
}
}
64 changes: 61 additions & 3 deletions DLPrototype/Views/Today/LogTable/LogTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ struct LogTable: View, Identifiable {
@Binding public var selectedJob: String

@State private var records: [LogRecord] = []
@State private var recordsAsString: String = ""
@State private var wordCount: Int = 0
@State private var isReversed: Bool = false
@State private var isShowingAlert: Bool = false
@State private var selectedTab: Int = 0
@State private var searchText: String = ""
@State private var resetSearchButtonHit: Bool = false
@State private var selectedDate: Date = Date()
@State private var viewMode: ViewMode = .full

@AppStorage("showExperimentalFeatures") private var showExperimentalFeatures = false
@AppStorage("showExperiment.actions") private var showExperimentActions = false
Expand All @@ -36,7 +38,11 @@ struct LogTable: View, Identifiable {
toolbar.font(Theme.font)

HStack(spacing: 1) {
table
if viewMode == .full {
viewModeFull
} else if viewMode == .plain {
viewModePlain
}

if showSidebar {
tableDetails.frame(minWidth: 300, maxWidth: 400)
Expand All @@ -59,7 +65,7 @@ struct LogTable: View, Identifiable {
}

// MARK: table view
var table: some View {
var viewModeFull: some View {
VStack(spacing: 1) {
Grid(alignment: .top, horizontalSpacing: 1, verticalSpacing: 1) {
headers.font(Theme.font)
Expand All @@ -71,6 +77,19 @@ struct LogTable: View, Identifiable {
}
}

// MARK: plain view
var viewModePlain: some View {
VStack(spacing: 1) {
Grid(alignment: .top, horizontalSpacing: 1, verticalSpacing: 1) {
headers.font(Theme.font)

ScrollView {
plainRows.font(Theme.font)
}
}
}
}

// MARK: toolbar view
var toolbar: some View {
GridRow {
Expand All @@ -93,8 +112,10 @@ struct LogTable: View, Identifiable {
showSearch: $showSearch,
searchText: $searchText,
selectedDate: $selectedDate,
records: $records
records: $records,
viewMode: $viewMode
)
.id(updater.ids["today.dayList"])
}
}
}
Expand Down Expand Up @@ -196,6 +217,20 @@ struct LogTable: View, Identifiable {
})
}

var plainRows: some View {
VStack(spacing: 1) {
if showSearch {
SearchBar(text: $searchText, disabled: (records.count == 0))
}

if records.count > 0 && recordsAsString.count > 0 {
FancyTextField(placeholder: "Records...", lineLimit: 10, text: $recordsAsString)
} else {
LogRowEmpty(message: "No records found for today", index: 0, colour: Theme.rowColour)
}
}
}

var tableDetails: some View {
LogTableDetails(records: $records, selectedDate: $selectedDate, open: $showSidebar)
.environmentObject(updater)
Expand All @@ -211,6 +246,29 @@ struct LogTable: View, Identifiable {

private func loadRecordsBySelectedDate() -> Void {
records = LogRecords(moc: moc).forDate(selectedDate)

if records.count > 0 {
recordsAsString = ""

for item in records {
if item.job != nil {
let ignoredJobs = item.job!.project?.configuration?.ignoredJobs
let cleaned = CoreDataProjectConfiguration.applyBannedWordsTo(item)

if ignoredJobs != nil {
if !ignoredJobs!.contains(item.job!.jid.string) {
let url = item.job!.uri

if url != nil {
recordsAsString += "\(item.timestamp!) - \(item.job!.uri!.absoluteString) - \(cleaned.message!)\n"
} else {
recordsAsString += "\(item.timestamp!) - \(item.job!.jid.string) - \(cleaned.message!)\n"
}
}
}
}
}
}
}

private func findMatches(_ message: String) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct LogRowActions: View, Identifiable {
print("saving")
isEditing = false

print(entry.message)
print("saving \(entry.message)")
}

private func copy() -> Void {
Expand Down
38 changes: 21 additions & 17 deletions DLPrototype/Views/Today/LogTable/ToolbarButtons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,31 @@ struct ToolbarButtons: View {
@Binding public var searchText: String
@Binding public var selectedDate: Date
@Binding public var records: [LogRecord]
@Binding public var viewMode: ViewMode

@State private var datePickerItems: [CustomPickerItem] = []
@State private var pickerSelection: Int = 0

private let numDatesInPast: Int = 20
@AppStorage("today.numPastDates") public var numPastDates: Int = 20

@Environment(\.managedObjectContext) var moc
@EnvironmentObject public var updater: ViewUpdater

var body: some View {
HStack {
// TODO: coming back soon
// FancyButton(text: "Previous day", action: previous, icon: "chevron.left", transparent: true, showLabel: false)
// .frame(maxHeight: 20)
FancyPicker(onChange: change, items: datePickerItems)
.onAppear(perform: {
datePickerItems = CustomPickerItem.listFrom(DateHelper.datesBeforeToday(numDays: numDatesInPast)) // TODO: add dateFormat: "EEEEEE - yyyy-MM-dd"
})
.onAppear(perform: {createListOfDays(changeDetected: false)})
.onChange(of: numPastDates) { _ in
createListOfDays(changeDetected: true)
}
// TODO: coming back soon
// FancyButton(text: "Next day", action: next, icon: "chevron.right", transparent: true, showLabel: false)
// .frame(maxHeight: 20)

// TODO: this one is coming back
// Button(action: reload, label: {
// Image(systemName: "arrow.counterclockwise")
// })
// .help("Reload data")
// .keyboardShortcut("r")
// .buttonStyle(.borderless)
// .foregroundColor(Color.white)
ViewModeSelector(mode: $viewMode)

Button(action: export, label: {
Image(systemName: "arrow.down.to.line")
Expand Down Expand Up @@ -94,6 +90,14 @@ struct ToolbarButtons: View {
}.padding(8)
}

private func createListOfDays(changeDetected: Bool = false) -> Void {
datePickerItems = CustomPickerItem.listFrom(DateHelper.datesBeforeToday(numDays: numPastDates)) // TODO: add dateFormat: "EEEEEE - yyyy-MM-dd"

if changeDetected {
updater.updateOne("today.dayList")
}
}

private func change(selected: Int, sender: String?) -> Void {
let item = datePickerItems[selected].title

Expand All @@ -113,12 +117,8 @@ struct ToolbarButtons: View {
}
}

private func reload() -> Void {
//
}

private func previous() -> Void {
if pickerSelection <= numDatesInPast {
if pickerSelection <= numPastDates {
pickerSelection += 1

let item = datePickerItems[pickerSelection].title
Expand Down Expand Up @@ -163,6 +163,10 @@ struct ToolbarButtons: View {
ClipboardHelper.copy(pasteboardContents)
}

private func viewAsPlain() -> Void {
viewMode = .plain
}

private func toStringList(_ items: [Entry]) -> String {
var out = ""

Expand Down
Loading

0 comments on commit cb196e0

Please sign in to comment.