parent
efd05ce33b
commit
08b6116a28
|
@ -19,8 +19,6 @@ struct SegRow: View {
|
|||
let intraWordSpacing = CGFloat(1.6)
|
||||
var body: some View {
|
||||
var segSplit = seg.body.components(separatedBy: ";;")
|
||||
Print("got here meow")
|
||||
Print(segSplit)
|
||||
let decoder = JSONDecoder()
|
||||
var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 0) {
|
||||
ForEach(0 ..< segSplit.count, id: \.self) { segIndex in
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
//
|
||||
// RibbonGroup.swift
|
||||
// gloss
|
||||
//
|
||||
// Created by Saint on 2/24/23.
|
||||
//
|
||||
|
||||
import GRDB
|
||||
/// The Line struct.
|
||||
///
|
||||
/// Identifiable conformance supports SwiftUI list animations, and type-safe
|
||||
/// GRDB primary key methods.
|
||||
/// Equatable conformance supports tests.
|
||||
struct RibbonGroup: Identifiable, Equatable {
|
||||
/// The player id.
|
||||
///
|
||||
/// Int64 is the recommended type for auto-incremented database ids.
|
||||
/// Use nil for players that are not inserted yet in the database.
|
||||
var id: Int64?
|
||||
var pos: Int
|
||||
var title: String
|
||||
var current_undo_level: Int
|
||||
var min_level: Int
|
||||
var max_level: Int
|
||||
|
||||
}
|
||||
|
||||
extension RibbonGroup {
|
||||
}
|
||||
|
||||
// MARK: - Persistence
|
||||
|
||||
/// Make Line a Codable Record.
|
||||
///
|
||||
/// See <https://github.com/groue/GRDB.swift/blob/master/README.md#records>
|
||||
extension RibbonGroup: Codable, FetchableRecord, MutablePersistableRecord {
|
||||
// Define database columns from CodingKeys
|
||||
fileprivate enum Columns {
|
||||
static let id = Column(CodingKeys.id)
|
||||
static let pos = Column(CodingKeys.pos)
|
||||
static let book = Column(CodingKeys.book)
|
||||
static let title = Column(CodingKeys.title)
|
||||
static let scrollOffset = Column(CodingKeys.scrollOffset)
|
||||
}
|
||||
|
||||
/// Updates a player id after it has been inserted in the database.
|
||||
mutating func didInsert(_ inserted: InsertionSuccess) {
|
||||
id = inserted.rowID
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Line Database Requests
|
||||
|
||||
/// Define some player requests used by the application.
|
||||
///
|
||||
/// See <https://github.com/groue/GRDB.swift/blob/master/README.md#requests>
|
||||
/// See <https://github.com/groue/GRDB.swift/blob/master/Documentation/GoodPracticesForDesigningRecordTypes.md>
|
||||
extension DerivableRequest<RibbonGroup> {
|
||||
}
|
|
@ -49,7 +49,26 @@ struct RibbonRequest: Queryable {
|
|||
|
||||
// This method is not required by Queryable, but it makes it easier
|
||||
func fetchValue(_ db: Database) throws -> [Ribbon] {
|
||||
if (id == nil) {
|
||||
|
||||
var sql = """
|
||||
select distinct r1.* from Ribbon r1 join Ribbon r2 ON \
|
||||
r1.undoLevel = r2.currentLevel AND r1.id = r2.id
|
||||
"""
|
||||
|
||||
do {
|
||||
var ret = try Ribbon.fetchAll(db, sql: sql)
|
||||
print("xxxxx fetching ribbons")
|
||||
print(ret)
|
||||
return ret
|
||||
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
print(error)
|
||||
print("Error")
|
||||
return []
|
||||
}
|
||||
|
||||
if id == nil {
|
||||
return try Ribbon.order(Column("pos")).fetchAll(db)
|
||||
} else {
|
||||
return try Ribbon.filter(idColumn == id).fetchAll(db)
|
||||
|
|
|
@ -37,8 +37,8 @@ struct SegDenormRequest: Queryable {
|
|||
{
|
||||
var ret = try SegDenorm.fetchAll(db, sql: sql)
|
||||
|
||||
print("SEGS DENORM")
|
||||
print(ret[0])
|
||||
// print("SEGS DENORM")
|
||||
// print(ret[0])
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ struct SelectedRibbon: Identifiable, Equatable {
|
|||
/// Int64 is the recommended type for auto-incremented database ids.
|
||||
/// Use nil for players that are not inserted yet in the database.
|
||||
var id: Int64?
|
||||
var ribbonGroupId: Int64
|
||||
var ribbonId: Int64
|
||||
}
|
||||
|
||||
extension SelectedRibbon {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
851259B02C05281300BE70F8 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259AF2C05281300BE70F8 /* BackButton.swift */; };
|
||||
851259B22C05299200BE70F8 /* ForwardArrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B12C05299200BE70F8 /* ForwardArrow.swift */; };
|
||||
851259B42C05788800BE70F8 /* RibbonGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851259B32C05788800BE70F8 /* RibbonGroup.swift */; };
|
||||
8514D5BC299EFB780054F185 /* store.db in Resources */ = {isa = PBXBuildFile; fileRef = 8514D5BB299EFB780054F185 /* store.db */; };
|
||||
8514D5BF299F04710054F185 /* GRDB in Frameworks */ = {isa = PBXBuildFile; productRef = 8514D5BE299F04710054F185 /* GRDB */; };
|
||||
852774C129A150B100458CA7 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852774C029A150B100458CA7 /* Line.swift */; };
|
||||
|
@ -50,7 +49,6 @@
|
|||
/* Begin PBXFileReference section */
|
||||
851259AF2C05281300BE70F8 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = "<group>"; };
|
||||
851259B12C05299200BE70F8 /* ForwardArrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForwardArrow.swift; sourceTree = "<group>"; };
|
||||
851259B32C05788800BE70F8 /* RibbonGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RibbonGroup.swift; sourceTree = "<group>"; };
|
||||
8514D5BB299EFB780054F185 /* store.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = store.db; sourceTree = "<group>"; };
|
||||
852774C029A150B100458CA7 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
|
||||
8528897429B2B86B003F2E16 /* CrownOfThorns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrownOfThorns.swift; sourceTree = "<group>"; };
|
||||
|
@ -131,7 +129,6 @@
|
|||
8528897B29BD69B2003F2E16 /* VisibilityTracker.swift */,
|
||||
8528897A29BD69B1003F2E16 /* VisibilityTrackingModifier.swift */,
|
||||
8528897929BD69B1003F2E16 /* VisibilityTrackingScrollView.swift */,
|
||||
851259B32C05788800BE70F8 /* RibbonGroup.swift */,
|
||||
8590D96A29A8374B001EF84F /* json */,
|
||||
8514D5BA299EF2EC0054F185 /* db */,
|
||||
85F01DF9297878B400F317B4 /* fonts */,
|
||||
|
@ -304,7 +301,6 @@
|
|||
8590D96729A183EE001EF84F /* AppDatabase.swift in Sources */,
|
||||
8590D96929A18A6D001EF84F /* LineRequest.swift in Sources */,
|
||||
852774C129A150B100458CA7 /* Line.swift in Sources */,
|
||||
851259B42C05788800BE70F8 /* RibbonGroup.swift in Sources */,
|
||||
85942EEF29AEA18300307621 /* SelectedRibbonRequest.swift in Sources */,
|
||||
8590D96C29A92146001EF84F /* JsonImport.swift in Sources */,
|
||||
85942EED29AEA04200307621 /* SelectedRibbon.swift in Sources */,
|
||||
|
|
|
@ -51,19 +51,16 @@ struct AppDatabase {
|
|||
t.column("book", .text).notNull()
|
||||
}
|
||||
|
||||
try db.create(table: "RibbonGroup") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("currentUndoLevel", .integer).notNull()
|
||||
t.column("minLevel", .integer).notNull()
|
||||
t.column("maxLevel", .text).notNull()
|
||||
t.column("pos", .integer).notNull()
|
||||
t.column("title", .text).notNull()
|
||||
}
|
||||
|
||||
try db.create(table: "Ribbon") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("pos", .integer).notNull()
|
||||
t.column("group", .integer).notNull()
|
||||
t.column("undoLevel", .integer).notNull()
|
||||
t.column("currentLevel", .integer).notNull()
|
||||
t.column("minLevel", .integer).notNull()
|
||||
t.column("maxLevel", .integer).notNull()
|
||||
.defaults(to: 1)
|
||||
t.column("title", .text).notNull()
|
||||
t.column("book", .text).notNull()
|
||||
t.column("scrollOffset", .integer).notNull()
|
||||
t.column("scrollId", .text)
|
||||
|
@ -71,7 +68,7 @@ struct AppDatabase {
|
|||
|
||||
try db.create(table: "SelectedRibbon") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("ribbonGroupId", .integer).notNull()
|
||||
t.column("ribbonId", .integer).notNull()
|
||||
}
|
||||
|
||||
try db.create(table: "ScrollState") { t in
|
||||
|
@ -251,61 +248,63 @@ extension AppDatabase {
|
|||
/// Create random Lines if the database is empty.
|
||||
func initDatabase() throws {
|
||||
do {
|
||||
try dbWriter.write { db in
|
||||
if try Line.all().isEmpty(db) {
|
||||
try importJson("john_export.json", db)
|
||||
try importJson("mark_export.json", db)
|
||||
|
||||
_ = try RibbonGroup(id: 1,
|
||||
pos: 1,
|
||||
title: "John",
|
||||
current_undo_level: 1,
|
||||
min_level: 1,
|
||||
max_level: 1).inserted(db)
|
||||
|
||||
try dbWriter.write { db in
|
||||
if try Line.all().isEmpty(db)
|
||||
{
|
||||
try importJson("john_export.json", db)
|
||||
try importJson("mark_export.json", db)
|
||||
_ = try Ribbon(id: 1,
|
||||
group: 1,
|
||||
pos: 1,
|
||||
undoLevel: 1,
|
||||
currentLevel: 1,
|
||||
minLevel: 1,
|
||||
maxLevel: 1,
|
||||
title: "John",
|
||||
book: "bible.john",
|
||||
scrollId: "1",
|
||||
scrollOffset: 0).inserted(db)
|
||||
|
||||
_ = try RibbonGroup(id: 2,
|
||||
pos: 2,
|
||||
title: "Second",
|
||||
current_undo_level: 1,
|
||||
min_level: 1,
|
||||
max_level: 1).inserted(db)
|
||||
|
||||
_ = try Ribbon(id: 2,
|
||||
group: 2,
|
||||
pos: 2,
|
||||
undoLevel: 1,
|
||||
currentLevel: 1,
|
||||
minLevel: 1,
|
||||
maxLevel: 1,
|
||||
title: "Gospel of Mark",
|
||||
book: "bible.mark",
|
||||
scrollId: "1",
|
||||
scrollOffset: 0).inserted(db)
|
||||
|
||||
_ = try RibbonGroup(id: 3,
|
||||
pos: 3,
|
||||
title: "Another one",
|
||||
current_undo_level: 1,
|
||||
min_level: 1,
|
||||
max_level: 1).inserted(db)
|
||||
scrollOffset: 300).inserted(db)
|
||||
|
||||
_ = try Ribbon(id: 3,
|
||||
group: 3,
|
||||
pos: 3,
|
||||
undoLevel: 1,
|
||||
currentLevel: 2,
|
||||
minLevel: 1,
|
||||
maxLevel: 1,
|
||||
title: "bottom",
|
||||
book: "bible.john",
|
||||
scrollId: "1",
|
||||
scrollOffset: 0).inserted(db)
|
||||
|
||||
_ = try SelectedRibbon(id: 1, ribbonGroupId: 1).inserted(db)
|
||||
_ = try Ribbon(id: 4,
|
||||
group: 3,
|
||||
pos: 3,
|
||||
undoLevel: 2,
|
||||
currentLevel: 2,
|
||||
minLevel: 1,
|
||||
maxLevel: 2,
|
||||
title: "topp",
|
||||
book: "bible.john",
|
||||
scrollId: "1",
|
||||
scrollOffset: 0).inserted(db)
|
||||
_ = try SelectedRibbon(id: 1, ribbonId: 1).inserted(db)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Error info: \(error)")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,12 @@ struct Ribbon: Identifiable, Equatable {
|
|||
/// Use nil for players that are not inserted yet in the database.
|
||||
var id: Int64?
|
||||
var group: Int
|
||||
var pos: Int
|
||||
var undoLevel: Int
|
||||
var currentLevel: Int
|
||||
var minLevel: Int
|
||||
var maxLevel: Int
|
||||
var title: String
|
||||
var book: String
|
||||
var scrollId: String
|
||||
var scrollOffset: Int
|
||||
|
|
Loading…
Reference in New Issue