Recordings: Toggle between raw logs and summary
This commit is contained in:
@@ -69,7 +69,7 @@ class TVCPreviousRecords: UITableViewController, EditActionsRemove {
|
||||
let x = dataSource[indexPath.row]
|
||||
cell.textLabel?.text = x.title ?? x.fallbackTitle
|
||||
cell.textLabel?.textColor = (x.title == nil) ? .systemGray : nil
|
||||
cell.detailTextLabel?.text = "at \(DateFormat.seconds(x.start)), duration: \(x.durationString ?? "?")"
|
||||
cell.detailTextLabel?.text = "at \(DateFormat.seconds(x.start)), duration: \(TimeFormat.from(x.duration ?? 0))"
|
||||
return cell
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,58 @@ import UIKit
|
||||
|
||||
class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
var record: Recording!
|
||||
private var dataSource: [RecordLog]!
|
||||
private lazy var isLongRecording: Bool = (record.duration ?? 0) > Timestamp.hours(1)
|
||||
|
||||
private var showRaw: Bool = false
|
||||
/// Sorted by `ts` in ascending order (oldest first)
|
||||
private lazy var dataSourceRaw: [DomainTsPair] = RecordingsDB.details(record)
|
||||
/// Sorted by `count` (descending), then alphabetically
|
||||
private lazy var dataSourceSum: [(domain: String, count: Int)] = {
|
||||
var result: [String:Int] = [:]
|
||||
for x in dataSourceRaw {
|
||||
result[x.domain] = (result[x.domain] ?? 0) + 1 // group and count
|
||||
}
|
||||
return result.map{$0}.sorted {
|
||||
$0.count > $1.count || $0.count == $1.count && $0.domain < $1.domain
|
||||
}
|
||||
}()
|
||||
|
||||
override func viewDidLoad() {
|
||||
title = record.title ?? record.fallbackTitle
|
||||
dataSource = RecordingsDB.details(record)
|
||||
}
|
||||
|
||||
@IBAction private func toggleDisplayStyle(_ sender: UIBarButtonItem) {
|
||||
showRaw = !showRaw
|
||||
sender.image = UIImage(named: showRaw ? "line-collapse" : "line-expand")
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Table View Data Source
|
||||
|
||||
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { dataSource.count }
|
||||
override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
|
||||
showRaw ? dataSourceRaw.count : dataSourceSum.count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "PreviousRecordDetailCell")!
|
||||
let x = dataSource[indexPath.row]
|
||||
cell.textLabel?.text = x.domain
|
||||
cell.detailTextLabel?.text = "\(x.count)"
|
||||
let cell: UITableViewCell
|
||||
if showRaw {
|
||||
let x = dataSourceRaw[indexPath.row]
|
||||
if isLongRecording {
|
||||
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailLongCell")!
|
||||
cell.textLabel?.text = x.domain
|
||||
cell.detailTextLabel?.text = DateFormat.seconds(x.ts)
|
||||
} else {
|
||||
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailShortCell")!
|
||||
cell.textLabel?.text = "+ " + TimeFormat.from(x.ts - record.start)
|
||||
cell.detailTextLabel?.text = x.domain
|
||||
}
|
||||
} else {
|
||||
let x = dataSourceSum[indexPath.row]
|
||||
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailCountedCell")!
|
||||
cell.textLabel?.text = x.domain
|
||||
cell.detailTextLabel?.text = "\(x.count)×"
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
@@ -34,9 +69,25 @@ class TVCRecordingDetails: UITableViewController, EditActionsRemove {
|
||||
}
|
||||
|
||||
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
|
||||
if RecordingsDB.deleteDetails(record, domain: dataSource[index.row].domain) {
|
||||
dataSource.remove(at: index.row)
|
||||
tableView.deleteRows(at: [index], with: .automatic)
|
||||
if showRaw {
|
||||
let x = dataSourceRaw[index.row]
|
||||
if RecordingsDB.deleteSingle(record, domain: x.domain, ts: x.ts) {
|
||||
if let i = dataSourceSum.firstIndex(where: { $0.domain == x.domain }) {
|
||||
dataSourceSum[i].count -= 1
|
||||
if dataSourceSum[i].count == 0 {
|
||||
dataSourceSum.remove(at: i)
|
||||
}
|
||||
}
|
||||
dataSourceRaw.remove(at: index.row)
|
||||
tableView.deleteRows(at: [index], with: .automatic)
|
||||
}
|
||||
} else {
|
||||
let dom = dataSourceSum[index.row].domain
|
||||
if RecordingsDB.deleteDetails(record, domain: dom) {
|
||||
dataSourceRaw.removeAll { $0.domain == dom }
|
||||
dataSourceSum.remove(at: index.row)
|
||||
tableView.deleteRows(at: [index], with: .automatic)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate
|
||||
inputDetails.text = """
|
||||
Start: \(DateFormat.seconds(record.start))
|
||||
End: \(record.stop == nil ? "?" : DateFormat.seconds(record.stop!))
|
||||
Duration: \(record.durationString ?? "?")
|
||||
Duration: \(TimeFormat.from(record.duration ?? 0))
|
||||
"""
|
||||
validateSaveButton()
|
||||
if deleteOnCancel { // mark as destructive
|
||||
|
||||
Reference in New Issue
Block a user