field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraAddSchemaFixtures.swift (3180B)


      1 @testable import TeraApp
      2 
      3 enum TeraAddSchemaFixtures {
      4   static func schemas() -> [TeraAddSchema] {
      5     [update, photoUpdate, ask, event, foodAvailability]
      6   }
      7 
      8   private static let field = { @Sendable
      9     (
     10       id: String,
     11       label: String,
     12       kind: TeraAddFieldKind,
     13       required: Bool,
     14       choices: [String],
     15       maxBytes: UInt64?,
     16       maxItems: UInt16?
     17     ) in
     18     TeraAddField(
     19       schemaVersion: 1,
     20       id: id,
     21       label: label,
     22       kind: kind,
     23       required: required,
     24       choices: choices,
     25       maxBytes: maxBytes,
     26       maxItems: maxItems
     27     )
     28   }
     29 
     30   private static let text = { @Sendable
     31     (id: String, label: String, kind: TeraAddFieldKind, required: Bool, maximum: UInt64?) in
     32     field(id, label, kind, required, [], maximum, nil)
     33   }
     34 
     35   private static let media = { @Sendable (required: Bool, maximum: UInt16) in
     36     field("media", "Photos", .media, required, [], 10 * 1024 * 1024, maximum)
     37   }
     38 
     39   private static var update: TeraAddSchema {
     40     TeraAddSchema(
     41       schemaVersion: 1,
     42       commandType: .createUpdate,
     43       label: "Update",
     44       fields: [text("content", "Update", .multilineText, true, 65535)]
     45     )
     46   }
     47 
     48   private static var photoUpdate: TeraAddSchema {
     49     TeraAddSchema(
     50       schemaVersion: 1,
     51       commandType: .createPhotoUpdate,
     52       label: "Photo update",
     53       fields: [
     54         text("content", "Update", .multilineText, true, 65535),
     55         media(true, 20),
     56       ]
     57     )
     58   }
     59 
     60   private static var ask: TeraAddSchema {
     61     TeraAddSchema(
     62       schemaVersion: 1,
     63       commandType: .createAsk,
     64       label: "Ask",
     65       fields: [
     66         text("content", "Question", .multilineText, true, 65535),
     67         media(false, 20),
     68       ]
     69     )
     70   }
     71 
     72   private static var event: TeraAddSchema {
     73     TeraAddSchema(
     74       schemaVersion: 1,
     75       commandType: .createEvent,
     76       label: "Event",
     77       fields: [
     78         text("identifier", "Identifier", .text, true, 256),
     79         text("title", "Title", .text, true, 256),
     80         text("content", "Description", .multilineText, false, 65535),
     81         text("event_start", "Starts", .dateTime, true, nil),
     82         text("event_end", "Ends", .dateTime, false, nil),
     83         text("location", "Location", .location, false, 256),
     84         media(false, 1),
     85       ]
     86     )
     87   }
     88 
     89   private static var foodAvailability: TeraAddSchema {
     90     TeraAddSchema(
     91       schemaVersion: 1,
     92       commandType: .createFoodAvailability,
     93       label: "Food availability",
     94       fields: [
     95         text("identifier", "Identifier", .text, true, 256),
     96         text("title", "Food", .text, true, 256),
     97         text("summary", "Summary", .text, true, 256),
     98         text("content", "Details", .multilineText, true, 65535),
     99         text("location", "Pickup location", .location, true, 256),
    100         text("price_amount", "Price", .decimal, true, 64),
    101         field("currency", "Currency", .choice, true, [], 3, nil),
    102         field(
    103           "unit", "Unit", .choice, true,
    104           ["g", "kg", "lb", "oz", "each", "dozen", "bunch", "punnet", "bag", "basket"],
    105           nil, nil
    106         ),
    107         text("quantity", "Available quantity", .decimal, false, 64),
    108         media(false, 20),
    109       ]
    110     )
    111   }
    112 }