Subscriptions: «Оплачено?» → paid status → «repeat?»; edit and create everything
- ops: paying marks the current charge paid (paid_for, persisted) instead of jumping to the next date; repeat_sub moves to the next period or closes the subscription. Paid-and-undecided subscriptions leave reminders and show in agenda['paid']. update_sub can set paid; tasks reopen when their status goes back; delete for subs and routines (BroV only, /api/delete); /api/tasks?all=1 and /api/subs?all=1. - Bot: «₽ Оплачено?» on reminders, then «🔁 Да, <date> / Нет, закрыть»; after paying by text it asks the same with buttons. - BroV: «Оплачено?» everywhere; «Оплачено — повторить?» section under the notch; «Весь план»: forms to edit or create tasks (title, description, status, due, company), subscriptions (amount, currency, period, date, reminder, company, paid, active) and routines, delete with confirmation, «+» per list, done tasks on demand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,8 @@ struct OpsItem: Identifiable, Equatable {
|
||||
var client: String
|
||||
var amount: Double?
|
||||
var currency: String?
|
||||
var paid = false
|
||||
var nextIfRepeat: String?
|
||||
var id: String { "\(kind)-\(ref)" }
|
||||
}
|
||||
|
||||
@@ -22,11 +24,13 @@ struct OpsAgenda: Equatable {
|
||||
var overdue: [OpsItem] = []
|
||||
var today: [OpsItem] = []
|
||||
var soon: [OpsItem] = []
|
||||
/// Subscriptions paid and waiting for «repeat?».
|
||||
var paid: [OpsItem] = []
|
||||
var running: (id: Int, title: String, minutes: Int)?
|
||||
var monthly: [String: Double] = [:]
|
||||
|
||||
static func == (a: OpsAgenda, b: OpsAgenda) -> Bool {
|
||||
a.overdue == b.overdue && a.today == b.today && a.soon == b.soon
|
||||
a.overdue == b.overdue && a.today == b.today && a.soon == b.soon && a.paid == b.paid
|
||||
&& a.running?.id == b.running?.id && a.running?.minutes == b.running?.minutes && a.monthly == b.monthly
|
||||
}
|
||||
}
|
||||
@@ -41,6 +45,7 @@ struct OpsTask: Identifiable, Equatable {
|
||||
var minutes: Int
|
||||
var running: Bool
|
||||
var children: [OpsTask]
|
||||
var notes: String = ""
|
||||
}
|
||||
|
||||
struct OpsSub: Identifiable, Equatable {
|
||||
@@ -53,6 +58,10 @@ struct OpsSub: Identifiable, Equatable {
|
||||
var next: String
|
||||
var remindDays: Int
|
||||
var client: String
|
||||
var paid = false
|
||||
var nextIfRepeat = ""
|
||||
var active = true
|
||||
var notes = ""
|
||||
}
|
||||
|
||||
struct OpsRoutine: Identifiable, Equatable {
|
||||
@@ -61,6 +70,7 @@ struct OpsRoutine: Identifiable, Equatable {
|
||||
var everyDays: Int
|
||||
var next: String
|
||||
var last: String?
|
||||
var notes = ""
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@@ -80,6 +90,10 @@ final class OpsClient: ObservableObject {
|
||||
/// Subscriptions per month by company ("" = none), then by currency.
|
||||
@Published var byClient: [String: [String: Double]] = [:]
|
||||
var fullLoaded = false
|
||||
/// «Весь план» → Задачи: also the finished ones.
|
||||
@Published var showDone = false {
|
||||
didSet { Task { await refreshAll() } }
|
||||
}
|
||||
|
||||
var baseURL: String {
|
||||
(UserDefaults.standard.string(forKey: Self.urlKey) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
@@ -129,11 +143,12 @@ final class OpsClient: ObservableObject {
|
||||
(j[key] as? [[String: Any]] ?? []).compactMap { d in
|
||||
guard let kind = d["kind"] as? String, let ref = d["id"] as? Int else { return nil }
|
||||
return OpsItem(kind: kind, ref: ref, title: d["title"] as? String ?? "", date: d["date"] as? String ?? "",
|
||||
client: d["client"] as? String ?? "", amount: d["amount"] as? Double,
|
||||
currency: d["currency"] as? String)
|
||||
client: d["client"] as? String ?? "", amount: (d["amount"] as? NSNumber)?.doubleValue,
|
||||
currency: d["currency"] as? String, paid: d["paid"] as? Bool ?? false,
|
||||
nextIfRepeat: d["next_if_repeat"] as? String)
|
||||
}
|
||||
}
|
||||
var a = OpsAgenda(overdue: items("overdue"), today: items("due_today"), soon: items("soon"))
|
||||
var a = OpsAgenda(overdue: items("overdue"), today: items("due_today"), soon: items("soon"), paid: items("paid"))
|
||||
if let r = j["running"] as? [String: Any], let id = r["id"] as? Int {
|
||||
a.running = (id, r["title"] as? String ?? "", r["minutes"] as? Int ?? 0)
|
||||
}
|
||||
@@ -143,12 +158,12 @@ final class OpsClient: ObservableObject {
|
||||
|
||||
func refreshAll() async {
|
||||
await refresh()
|
||||
if let arr = await request("/api/tasks") as? [[String: Any]] {
|
||||
if let arr = await request(showDone ? "/api/tasks?all=1" : "/api/tasks") as? [[String: Any]] {
|
||||
func task(_ d: [String: Any]) -> OpsTask {
|
||||
OpsTask(id: d["id"] as? Int ?? 0, parentId: d["parent_id"] as? Int, title: d["title"] as? String ?? "",
|
||||
client: d["client"] as? String ?? "", status: d["status"] as? String ?? "todo",
|
||||
due: d["due"] as? String, minutes: d["minutes"] as? Int ?? 0, running: d["running"] as? Bool ?? false,
|
||||
children: (d["children"] as? [[String: Any]] ?? []).map(task))
|
||||
children: (d["children"] as? [[String: Any]] ?? []).map(task), notes: d["notes"] as? String ?? "")
|
||||
}
|
||||
tasks = arr.map(task)
|
||||
}
|
||||
@@ -157,7 +172,9 @@ final class OpsClient: ObservableObject {
|
||||
OpsSub(id: d["id"] as? Int ?? 0, name: d["name"] as? String ?? "", amount: (d["amount"] as? NSNumber)?.doubleValue ?? 0,
|
||||
currency: d["currency"] as? String ?? "RUB", period: d["period"] as? String ?? "month",
|
||||
every: d["every"] as? Int ?? 1, next: d["next_date"] as? String ?? "", remindDays: d["remind_days"] as? Int ?? 3,
|
||||
client: d["client"] as? String ?? "")
|
||||
client: d["client"] as? String ?? "", paid: d["paid"] as? Bool ?? false,
|
||||
nextIfRepeat: d["next_if_repeat"] as? String ?? "", active: (d["active"] as? Int ?? 1) == 1,
|
||||
notes: d["notes"] as? String ?? "")
|
||||
}
|
||||
byClient = (j["by_client"] as? [String: [String: Any]] ?? [:]).mapValues { m in
|
||||
m.compactMapValues { ($0 as? NSNumber)?.doubleValue }
|
||||
@@ -166,7 +183,7 @@ final class OpsClient: ObservableObject {
|
||||
if let arr = await request("/api/routines") as? [[String: Any]] {
|
||||
routines = arr.map { d in
|
||||
OpsRoutine(id: d["id"] as? Int ?? 0, title: d["title"] as? String ?? "", everyDays: d["every_days"] as? Int ?? 1,
|
||||
next: d["next_date"] as? String ?? "", last: d["last_done"] as? String)
|
||||
next: d["next_date"] as? String ?? "", last: d["last_done"] as? String, notes: d["notes"] as? String ?? "")
|
||||
}
|
||||
}
|
||||
fullLoaded = true
|
||||
@@ -189,6 +206,17 @@ final class OpsClient: ObservableObject {
|
||||
if fullLoaded { await refreshAll() } else { await refresh() }
|
||||
}
|
||||
|
||||
func delete(_ kind: String, _ id: Int) async {
|
||||
let r = await request("/api/delete", body: ["kind": kind, "id": id]) as? [String: Any]
|
||||
if let lines = r?["result"] as? [String] { lastAnswer = lines.joined(separator: "\n") }
|
||||
SoundEngine.shared.play("close")
|
||||
await refreshAll()
|
||||
}
|
||||
|
||||
func repeatSub(_ id: Int, _ again: Bool) async {
|
||||
await act(["op": "repeat_sub", "id": id, "repeat": again])
|
||||
}
|
||||
|
||||
func done(_ it: OpsItem) async {
|
||||
switch it.kind {
|
||||
case "task": await act(["op": "complete_task", "id": it.ref])
|
||||
@@ -310,6 +338,10 @@ struct OpsPanel: View {
|
||||
header("СЕГОДНЯ", "#F5A524")
|
||||
ForEach(ops.agenda.today) { OpsRow(item: $0) }
|
||||
}
|
||||
if !ops.agenda.paid.isEmpty {
|
||||
header("ОПЛАЧЕНО — ПОВТОРИТЬ?", "#60A5FA")
|
||||
ForEach(ops.agenda.paid) { PaidRow(item: $0) }
|
||||
}
|
||||
if !ops.agenda.soon.isEmpty {
|
||||
Button { withAnimation(.easeOut(duration: 0.15)) { showWeek.toggle() } } label: {
|
||||
HStack(spacing: 4) {
|
||||
@@ -323,7 +355,7 @@ struct OpsPanel: View {
|
||||
.buttonStyle(.plain)
|
||||
if showWeek { ForEach(ops.agenda.soon) { OpsRow(item: $0) } }
|
||||
}
|
||||
if ops.configured && ops.reachable == true && ops.agenda.running == nil
|
||||
if ops.configured && ops.reachable == true && ops.agenda.running == nil && ops.agenda.paid.isEmpty
|
||||
&& ops.agenda.overdue.isEmpty && ops.agenda.today.isEmpty && ops.agenda.soon.isEmpty {
|
||||
Text("На неделю ничего не горит 👌").font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
|
||||
.padding(.vertical, 8).padding(.leading, 6)
|
||||
@@ -404,6 +436,38 @@ struct OpsInput: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// A paid subscription: «✓ Оплачено» and the question «repeat on <date>?».
|
||||
struct PaidRow: View {
|
||||
let item: OpsItem
|
||||
@ObservedObject private var ops = OpsClient.shared
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "checkmark.circle.fill").font(.system(size: 13)).foregroundColor(Color(hex: "#34D399")).frame(width: 16)
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text(item.title).font(.system(size: 12, weight: .medium)).lineLimit(1)
|
||||
Text("Оплачено · повторить \(OpsClient.ruDay(item.nextIfRepeat))?")
|
||||
.font(.system(size: 10.5)).foregroundColor(Color(hex: "#34D399")).lineLimit(1)
|
||||
}
|
||||
Spacer(minLength: 4)
|
||||
Button { Task { await ops.repeatSub(item.ref, true) } } label: {
|
||||
Text("Повторить").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
|
||||
.padding(.horizontal, 7).frame(height: 18)
|
||||
.background(Capsule().fill(Color(hex: "#60A5FA").opacity(0.14)))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
Button { Task { await ops.repeatSub(item.ref, false) } } label: {
|
||||
Text("Нет").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#8E939C"))
|
||||
.padding(.horizontal, 7).frame(height: 18)
|
||||
.background(Capsule().fill(Color.white.opacity(0.06)))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.help("Больше не повторять — подписка закроется")
|
||||
}
|
||||
.padding(.horizontal, 6).padding(.vertical, 5)
|
||||
}
|
||||
}
|
||||
|
||||
/// One agenda line: ○ done on the left (₽ «Оплачено» for subscriptions), ⏱ / ⏰ on hover.
|
||||
struct OpsRow: View {
|
||||
let item: OpsItem
|
||||
@@ -445,7 +509,7 @@ struct OpsRow: View {
|
||||
}
|
||||
if item.kind == "sub" {
|
||||
Button { Task { await ops.done(item) } } label: {
|
||||
Text("Оплачено").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
|
||||
Text("Оплачено?").font(.system(size: 10.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
|
||||
.padding(.horizontal, 7).frame(height: 18)
|
||||
.background(Capsule().fill(Color(hex: "#60A5FA").opacity(0.14)))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - Edit / create forms for «Весь план» (tasks, subscriptions, routines)
|
||||
//
|
||||
// Everything goes through the service's /api/action (the same checked operations Claude
|
||||
// uses); deletion through /api/delete, only by an explicit click and a confirmation.
|
||||
|
||||
enum OpsEdit: Identifiable {
|
||||
case task(OpsTask?), sub(OpsSub?), routine(OpsRoutine?)
|
||||
var id: String {
|
||||
switch self {
|
||||
case .task(let t): return "task-\(t?.id ?? 0)"
|
||||
case .sub(let s): return "sub-\(s?.id ?? 0)"
|
||||
case .routine(let r): return "routine-\(r?.id ?? 0)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct OpsEditSheet: View {
|
||||
let edit: OpsEdit
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
switch edit {
|
||||
case .task(let t): TaskForm(task: t, close: { dismiss() })
|
||||
case .sub(let s): SubForm(sub: s, close: { dismiss() })
|
||||
case .routine(let r): RoutineForm(routine: r, close: { dismiss() })
|
||||
}
|
||||
}
|
||||
.frame(width: 440)
|
||||
.padding(18)
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Shared bits
|
||||
|
||||
enum OpsDate {
|
||||
private static let f: DateFormatter = {
|
||||
let f = DateFormatter(); f.calendar = Calendar(identifier: .gregorian); f.dateFormat = "yyyy-MM-dd"; return f
|
||||
}()
|
||||
static func date(_ iso: String?) -> Date? { iso.flatMap { f.date(from: String($0.prefix(10))) } }
|
||||
static func iso(_ d: Date) -> String { f.string(from: d) }
|
||||
}
|
||||
|
||||
/// Company: none, the three known ones, or any other name.
|
||||
struct ClientPicker: View {
|
||||
@Binding var client: String
|
||||
private let known = ["", "saga", "planet9", "home"]
|
||||
@State private var custom = false
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Picker("Компания", selection: Binding(
|
||||
get: { custom || !known.contains(client) ? "other" : client },
|
||||
set: { v in
|
||||
if v == "other" { custom = true; if known.contains(client) { client = "" } }
|
||||
else { custom = false; client = v }
|
||||
})) {
|
||||
Text("—").tag("")
|
||||
Text("Сага").tag("saga")
|
||||
Text("Planet9").tag("planet9")
|
||||
Text("Дом").tag("home")
|
||||
Text("Другая…").tag("other")
|
||||
}
|
||||
if custom || !known.contains(client) {
|
||||
TextField("название", text: $client).textFieldStyle(.roundedBorder).frame(width: 140)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct FormButtons: View {
|
||||
let isNew: Bool
|
||||
let canSave: Bool
|
||||
let save: () -> Void
|
||||
let delete: () -> Void
|
||||
let close: () -> Void
|
||||
@State private var confirm = false
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
if !isNew {
|
||||
Button("Удалить", role: .destructive) { confirm = true }
|
||||
.confirmationDialog("Удалить без возможности вернуть?", isPresented: $confirm) {
|
||||
Button("Удалить", role: .destructive) { delete() }
|
||||
Button("Отмена", role: .cancel) {}
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
Button("Отмена", action: close).keyboardShortcut(.cancelAction)
|
||||
Button(isNew ? "Создать" : "Сохранить", action: save)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(!canSave)
|
||||
}
|
||||
.padding(.top, 6)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Task
|
||||
|
||||
struct TaskForm: View {
|
||||
let task: OpsTask?
|
||||
let close: () -> Void
|
||||
@ObservedObject private var ops = OpsClient.shared
|
||||
@State private var title = ""
|
||||
@State private var notes = ""
|
||||
@State private var status = "todo"
|
||||
@State private var hasDue = false
|
||||
@State private var due = Date()
|
||||
@State private var client = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text(task == nil ? "Новая задача" : "Задача #\(task!.id)").font(.system(size: 16, weight: .semibold))
|
||||
TextField("Что сделать", text: $title).textFieldStyle(.roundedBorder)
|
||||
Text("Описание").font(.system(size: 11)).foregroundColor(.secondary)
|
||||
TextEditor(text: $notes).font(.system(size: 12.5)).frame(height: 90)
|
||||
.overlay(RoundedRectangle(cornerRadius: 6).stroke(Color.white.opacity(0.12)))
|
||||
Picker("Статус", selection: $status) {
|
||||
Text("Не начата").tag("todo"); Text("В работе").tag("doing"); Text("Сделана").tag("done")
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
HStack {
|
||||
Toggle("Срок", isOn: $hasDue)
|
||||
if hasDue { DatePicker("", selection: $due, displayedComponents: .date).labelsHidden() }
|
||||
Spacer()
|
||||
}
|
||||
ClientPicker(client: $client)
|
||||
FormButtons(isNew: task == nil, canSave: !title.trimmingCharacters(in: .whitespaces).isEmpty,
|
||||
save: save, delete: { Task { await ops.delete("task", task!.id); close() } }, close: close)
|
||||
}
|
||||
.onAppear {
|
||||
guard let t = task else { return }
|
||||
title = t.title; notes = t.notes; status = t.status; client = t.client
|
||||
if let d = OpsDate.date(t.due) { hasDue = true; due = d }
|
||||
}
|
||||
}
|
||||
|
||||
private func save() {
|
||||
var body: [String: Any] = ["title": title, "notes": notes, "client": client.lowercased(),
|
||||
"due": hasDue ? OpsDate.iso(due) : ""]
|
||||
Task {
|
||||
if let t = task {
|
||||
body["op"] = "update_task"; body["id"] = t.id; body["status"] = status
|
||||
await ops.act(body)
|
||||
} else {
|
||||
body["op"] = "add_task"
|
||||
if !hasDue { body.removeValue(forKey: "due") }
|
||||
await ops.act(body)
|
||||
if status != "todo", let new = ops.tasks.flatMap({ [$0] + $0.children }).max(by: { $0.id < $1.id }) {
|
||||
await ops.act(["op": "update_task", "id": new.id, "status": status])
|
||||
}
|
||||
}
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Subscription
|
||||
|
||||
struct SubForm: View {
|
||||
let sub: OpsSub?
|
||||
let close: () -> Void
|
||||
@ObservedObject private var ops = OpsClient.shared
|
||||
@State private var name = ""
|
||||
@State private var amount = ""
|
||||
@State private var currency = "RUB"
|
||||
@State private var period = "month"
|
||||
@State private var every = 1
|
||||
@State private var next = Date()
|
||||
@State private var remind = 3
|
||||
@State private var client = ""
|
||||
@State private var paid = false
|
||||
@State private var active = true
|
||||
@State private var notes = ""
|
||||
|
||||
private var amountValue: Double? { Double(amount.replacingOccurrences(of: ",", with: ".").replacingOccurrences(of: " ", with: "")) }
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text(sub == nil ? "Новая подписка" : "Подписка #\(sub!.id)").font(.system(size: 16, weight: .semibold))
|
||||
TextField("Название (Claude Code, домен sanjeev.ru…)", text: $name).textFieldStyle(.roundedBorder)
|
||||
HStack {
|
||||
TextField("Сумма", text: $amount).textFieldStyle(.roundedBorder).frame(width: 110)
|
||||
Picker("", selection: $currency) { Text("₽").tag("RUB"); Text("$").tag("USD"); Text("€").tag("EUR") }
|
||||
.labelsHidden().frame(width: 70)
|
||||
Text("каждые").foregroundColor(.secondary)
|
||||
Stepper("\(every)", value: $every, in: 1...36).frame(width: 70)
|
||||
Picker("", selection: $period) {
|
||||
Text("день").tag("day"); Text("нед.").tag("week"); Text("мес.").tag("month"); Text("год").tag("year")
|
||||
}
|
||||
.labelsHidden().frame(width: 80)
|
||||
}
|
||||
HStack {
|
||||
Text("Следующее списание").foregroundColor(.secondary)
|
||||
DatePicker("", selection: $next, displayedComponents: .date).labelsHidden()
|
||||
Spacer()
|
||||
}
|
||||
Stepper("Напомнить за \(remind) дн.", value: $remind, in: 0...60)
|
||||
ClientPicker(client: $client)
|
||||
HStack(spacing: 18) {
|
||||
Toggle("Оплачено (текущее списание)", isOn: $paid)
|
||||
Toggle("Активна", isOn: $active)
|
||||
}
|
||||
TextField("Заметка", text: $notes).textFieldStyle(.roundedBorder)
|
||||
FormButtons(isNew: sub == nil, canSave: !name.trimmingCharacters(in: .whitespaces).isEmpty && amountValue != nil,
|
||||
save: save, delete: { Task { await ops.delete("sub", sub!.id); close() } }, close: close)
|
||||
}
|
||||
.onAppear {
|
||||
guard let s = sub else { return }
|
||||
name = s.name; amount = OpsClient.amount(s.amount).replacingOccurrences(of: " ", with: ""); currency = s.currency
|
||||
period = s.period; every = s.every; next = OpsDate.date(s.next) ?? Date(); remind = s.remindDays
|
||||
client = s.client; paid = s.paid; active = s.active; notes = s.notes
|
||||
}
|
||||
}
|
||||
|
||||
private func save() {
|
||||
var body: [String: Any] = ["name": name, "amount": amountValue ?? 0, "currency": currency, "period": period,
|
||||
"every": every, "next_date": OpsDate.iso(next), "remind_days": remind,
|
||||
"client": client.lowercased(), "notes": notes]
|
||||
Task {
|
||||
if let s = sub {
|
||||
body["op"] = "update_sub"; body["id"] = s.id; body["paid"] = paid; body["active"] = active ? 1 : 0
|
||||
await ops.act(body)
|
||||
} else {
|
||||
body["op"] = "add_sub"
|
||||
await ops.act(body)
|
||||
if paid, let new = ops.subs.max(by: { $0.id < $1.id }) {
|
||||
await ops.act(["op": "update_sub", "id": new.id, "paid": true])
|
||||
}
|
||||
}
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Routine
|
||||
|
||||
struct RoutineForm: View {
|
||||
let routine: OpsRoutine?
|
||||
let close: () -> Void
|
||||
@ObservedObject private var ops = OpsClient.shared
|
||||
@State private var title = ""
|
||||
@State private var everyDays = 7
|
||||
@State private var next = Date()
|
||||
@State private var notes = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text(routine == nil ? "Новое регламентное дело" : "Регламент #\(routine!.id)").font(.system(size: 16, weight: .semibold))
|
||||
TextField("Что делать (бэкап NAS, обновления…)", text: $title).textFieldStyle(.roundedBorder)
|
||||
Stepper("Раз в \(everyDays) дн.", value: $everyDays, in: 1...365)
|
||||
HStack {
|
||||
Text("Следующий раз").foregroundColor(.secondary)
|
||||
DatePicker("", selection: $next, displayedComponents: .date).labelsHidden()
|
||||
Spacer()
|
||||
}
|
||||
TextField("Заметка", text: $notes).textFieldStyle(.roundedBorder)
|
||||
FormButtons(isNew: routine == nil, canSave: !title.trimmingCharacters(in: .whitespaces).isEmpty,
|
||||
save: save, delete: { Task { await ops.delete("routine", routine!.id); close() } }, close: close)
|
||||
}
|
||||
.onAppear {
|
||||
guard let r = routine else { return }
|
||||
title = r.title; everyDays = r.everyDays; next = OpsDate.date(r.next) ?? Date(); notes = r.notes
|
||||
}
|
||||
}
|
||||
|
||||
private func save() {
|
||||
var body: [String: Any] = ["title": title, "every_days": everyDays, "next_date": OpsDate.iso(next), "notes": notes]
|
||||
Task {
|
||||
if let r = routine { body["op"] = "update_routine"; body["id"] = r.id } else { body["op"] = "add_routine" }
|
||||
await ops.act(body)
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,46 @@ enum OpsWindow {
|
||||
}
|
||||
}
|
||||
|
||||
/// Which form is open in «Весь план».
|
||||
@MainActor
|
||||
final class OpsUI: ObservableObject {
|
||||
static let shared = OpsUI()
|
||||
@Published var edit: OpsEdit?
|
||||
|
||||
func open(kind: String, ref: Int) {
|
||||
let ops = OpsClient.shared
|
||||
func find(_ ts: [OpsTask]) -> OpsTask? {
|
||||
for t in ts { if t.id == ref { return t }; if let c = find(t.children) { return c } }
|
||||
return nil
|
||||
}
|
||||
switch kind {
|
||||
case "task": if let t = find(ops.tasks) { edit = .task(t) }
|
||||
case "sub": if let s = ops.subs.first(where: { $0.id == ref }) { edit = .sub(s) }
|
||||
default: if let r = ops.routines.first(where: { $0.id == ref }) { edit = .routine(r) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Section title with «+ new».
|
||||
struct ListHeader<Extra: View>: View {
|
||||
let title: String
|
||||
let add: () -> Void
|
||||
@ViewBuilder var extra: () -> Extra
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 10) {
|
||||
Text(title).font(.system(size: 18, weight: .semibold))
|
||||
Button(action: add) {
|
||||
Image(systemName: "plus").font(.system(size: 12, weight: .bold))
|
||||
.frame(width: 22, height: 22).background(Circle().fill(Color.white.opacity(0.08)))
|
||||
}
|
||||
.buttonStyle(.plain).help("Создать")
|
||||
Spacer()
|
||||
extra()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum OpsSection: String, CaseIterable, Identifiable {
|
||||
case calendar = "Календарь", tasks = "Задачи", subs = "Подписки", routines = "Регламент"
|
||||
var id: String { rawValue }
|
||||
@@ -51,6 +91,7 @@ enum OpsSection: String, CaseIterable, Identifiable {
|
||||
|
||||
struct OpsOverview: View {
|
||||
@ObservedObject private var ops = OpsClient.shared
|
||||
@ObservedObject private var ui = OpsUI.shared
|
||||
@State private var section: OpsSection = .calendar
|
||||
@State private var text = ""
|
||||
@FocusState private var focused: Bool
|
||||
@@ -111,6 +152,7 @@ struct OpsOverview: View {
|
||||
}
|
||||
.foregroundColor(Color(hex: "#F5F6F8"))
|
||||
.task { await ops.refreshAll() }
|
||||
.sheet(item: $ui.edit) { OpsEditSheet(edit: $0) }
|
||||
}
|
||||
|
||||
private func count(_ s: OpsSection) -> Int? {
|
||||
@@ -205,9 +247,11 @@ struct OpsCalendar: View {
|
||||
Text(it.title).font(.system(size: 12.5, weight: .medium))
|
||||
Text(it.detail + (it.projected ? " · повтор" : "")).font(.system(size: 11)).foregroundColor(Color(hex: "#8E939C"))
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { OpsUI.shared.open(kind: it.kind, ref: it.ref) }
|
||||
Spacer()
|
||||
if !it.projected {
|
||||
Button(it.kind == "sub" ? "Оплачено" : "Сделано") {
|
||||
if !it.projected && !(it.kind == "sub" && ops.subs.first(where: { $0.id == it.ref })?.paid == true) {
|
||||
Button(it.kind == "sub" ? "Оплачено?" : "Сделано") {
|
||||
Task { await ops.done(OpsItem(kind: it.kind, ref: it.ref, title: it.title, date: it.date, client: "")) }
|
||||
}
|
||||
.buttonStyle(.plain).font(.system(size: 11, weight: .medium))
|
||||
@@ -330,7 +374,9 @@ struct OpsTaskList: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Задачи").font(.system(size: 18, weight: .semibold))
|
||||
ListHeader(title: "Задачи", add: { OpsUI.shared.edit = .task(nil) }) {
|
||||
Toggle("Показывать сделанные", isOn: $ops.showDone).toggleStyle(.checkbox).font(.system(size: 12))
|
||||
}
|
||||
if ops.tasks.isEmpty {
|
||||
Text("Открытых задач нет. Запиши ниже: «в Planet9 переезд серверной: купить свитч, проверить ИБП»")
|
||||
.font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
|
||||
@@ -363,12 +409,20 @@ struct OpsTaskRow: View {
|
||||
} else {
|
||||
Color.clear.frame(width: 12, height: 1)
|
||||
}
|
||||
Button { Task { await ops.act(["op": "complete_task", "id": task.id]) } } label: {
|
||||
Image(systemName: hovered ? "checkmark.circle" : "circle").font(.system(size: 14))
|
||||
.foregroundColor(Color(hex: overdue ? "#F4505E" : "#8E939C"))
|
||||
Button {
|
||||
Task { await ops.act(["op": isDone ? "reopen_task" : "complete_task", "id": task.id]) }
|
||||
} label: {
|
||||
Image(systemName: isDone ? "checkmark.circle.fill" : (hovered ? "checkmark.circle" : "circle")).font(.system(size: 14))
|
||||
.foregroundColor(Color(hex: isDone ? "#34D399" : (overdue ? "#F4505E" : "#8E939C")))
|
||||
}
|
||||
.buttonStyle(.plain).help("Сделано (вместе с подзадачами)")
|
||||
.buttonStyle(.plain).help(isDone ? "Вернуть в работу" : "Сделано (вместе с подзадачами)")
|
||||
Text(task.title).font(.system(size: 13, weight: depth == 0 ? .medium : .regular))
|
||||
.strikethrough(isDone).foregroundColor(Color(hex: isDone ? "#6B7079" : "#F5F6F8"))
|
||||
.onTapGesture { OpsUI.shared.edit = .task(task) }
|
||||
.help("Нажми, чтобы изменить")
|
||||
if !task.notes.isEmpty {
|
||||
Image(systemName: "text.alignleft").font(.system(size: 10)).foregroundColor(Color(hex: "#6B7079"))
|
||||
}
|
||||
if !task.children.isEmpty {
|
||||
Text("подзадач: \(task.children.count)").font(.system(size: 10.5)).foregroundColor(Color(hex: "#8E939C"))
|
||||
.padding(.horizontal, 6).background(Capsule().fill(Color.white.opacity(0.06)))
|
||||
@@ -385,6 +439,12 @@ struct OpsTaskRow: View {
|
||||
if let due = task.due {
|
||||
Text(OpsClient.ruDay(due)).font(.system(size: 11)).foregroundColor(Color(hex: overdue ? "#F4505E" : "#8E939C"))
|
||||
}
|
||||
Button {
|
||||
OpsUI.shared.edit = .task(task)
|
||||
} label: {
|
||||
Image(systemName: "pencil").font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
|
||||
}
|
||||
.buttonStyle(.plain).opacity(hovered ? 1 : 0).help("Изменить")
|
||||
Button {
|
||||
Task { await ops.act(task.running ? ["op": "stop_timer"] : ["op": "start_timer", "id": task.id]) }
|
||||
} label: {
|
||||
@@ -404,8 +464,10 @@ struct OpsTaskRow: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var isDone: Bool { task.status == "done" }
|
||||
|
||||
private var overdue: Bool {
|
||||
guard let due = task.due else { return false }
|
||||
guard !isDone, let due = task.due else { return false }
|
||||
return due < OpsCalendar.iso(Date())
|
||||
}
|
||||
}
|
||||
@@ -421,9 +483,7 @@ struct OpsSubList: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
Text("Подписки").font(.system(size: 18, weight: .semibold))
|
||||
Spacer()
|
||||
ListHeader(title: "Подписки", add: { OpsUI.shared.edit = .sub(nil) }) {
|
||||
if !ops.agenda.monthly.isEmpty {
|
||||
Text("всего в месяц: " + OpsClient.money(ops.agenda.monthly)).font(.system(size: 12)).foregroundColor(Color(hex: "#B0B5BE"))
|
||||
}
|
||||
@@ -449,15 +509,17 @@ struct OpsSubList: View {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: "creditcard").foregroundColor(Color(hex: "#60A5FA"))
|
||||
Text(s.name).font(.system(size: 13, weight: .medium))
|
||||
.onTapGesture { OpsUI.shared.edit = .sub(s) }.help("Нажми, чтобы изменить")
|
||||
Spacer()
|
||||
Text("\(OpsClient.amount(s.amount)) \(OpsClient.symbol(s.currency)) / \(s.every > 1 ? "\(s.every) " : "")\(period[s.period] ?? s.period)")
|
||||
.font(.system(size: 12)).frame(width: 150, alignment: .trailing)
|
||||
Text(OpsClient.ruDay(s.next)).font(.system(size: 12)).foregroundColor(Color(hex: "#B0B5BE"))
|
||||
.frame(width: 90, alignment: .trailing)
|
||||
Text("напомнить за \(s.remindDays) дн.").font(.system(size: 11)).foregroundColor(Color(hex: "#6B7079"))
|
||||
.frame(width: 120, alignment: .trailing)
|
||||
Button("Оплачено") { Task { await ops.act(["op": "pay_sub", "id": s.id]) } }
|
||||
.buttonStyle(.plain).font(.system(size: 11.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
|
||||
SubStatus(sub: s).frame(width: 250, alignment: .trailing)
|
||||
Button { OpsUI.shared.edit = .sub(s) } label: {
|
||||
Image(systemName: "pencil").font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
|
||||
}
|
||||
.buttonStyle(.plain).help("Изменить")
|
||||
}
|
||||
.padding(.horizontal, 10).padding(.vertical, 8)
|
||||
.background(RoundedRectangle(cornerRadius: 8).fill(Color.white.opacity(0.04)))
|
||||
@@ -474,7 +536,7 @@ struct OpsRoutineList: View {
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Регламент").font(.system(size: 18, weight: .semibold))
|
||||
ListHeader(title: "Регламент", add: { OpsUI.shared.edit = .routine(nil) }) { EmptyView() }
|
||||
if ops.routines.isEmpty {
|
||||
Text("Регламентных дел нет. Запиши ниже: «бэкап хоумлаба раз в неделю»")
|
||||
.font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
|
||||
@@ -486,6 +548,7 @@ struct OpsRoutineList: View {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: "arrow.triangle.2.circlepath").foregroundColor(Color(hex: "#34D399"))
|
||||
Text(r.title).font(.system(size: 13, weight: .medium))
|
||||
.onTapGesture { OpsUI.shared.edit = .routine(r) }.help("Нажми, чтобы изменить")
|
||||
Spacer()
|
||||
Text("раз в \(r.everyDays) дн.").font(.system(size: 12)).foregroundColor(Color(hex: "#B0B5BE"))
|
||||
.frame(width: 100, alignment: .trailing)
|
||||
@@ -495,6 +558,10 @@ struct OpsRoutineList: View {
|
||||
.foregroundColor(Color(hex: "#6B7079")).frame(width: 110, alignment: .trailing)
|
||||
Button("Сделано") { Task { await ops.act(["op": "done_routine", "id": r.id]) } }
|
||||
.buttonStyle(.plain).font(.system(size: 11.5, weight: .medium)).foregroundColor(Color(hex: "#34D399"))
|
||||
Button { OpsUI.shared.edit = .routine(r) } label: {
|
||||
Image(systemName: "pencil").font(.system(size: 12)).foregroundColor(Color(hex: "#8E939C"))
|
||||
}
|
||||
.buttonStyle(.plain).help("Изменить")
|
||||
}
|
||||
.padding(.horizontal, 10).padding(.vertical, 8)
|
||||
.background(RoundedRectangle(cornerRadius: 8).fill(Color.white.opacity(0.04)))
|
||||
@@ -504,3 +571,26 @@ struct OpsRoutineList: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// «Оплачено?» → «✓ Оплачено · повторить <date>? Повторить / Нет».
|
||||
struct SubStatus: View {
|
||||
let sub: OpsSub
|
||||
@ObservedObject private var ops = OpsClient.shared
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
if sub.paid {
|
||||
Text("✓ Оплачено").font(.system(size: 11.5, weight: .medium)).foregroundColor(Color(hex: "#34D399"))
|
||||
Button("Повторить \(OpsClient.ruDay(sub.nextIfRepeat))") { Task { await ops.repeatSub(sub.id, true) } }
|
||||
.buttonStyle(.plain).font(.system(size: 11.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
|
||||
Button("Нет") { Task { await ops.repeatSub(sub.id, false) } }
|
||||
.buttonStyle(.plain).font(.system(size: 11.5)).foregroundColor(Color(hex: "#8E939C"))
|
||||
.help("Больше не повторять — подписка закроется")
|
||||
} else {
|
||||
Text("напомнить за \(sub.remindDays) дн.").font(.system(size: 11)).foregroundColor(Color(hex: "#6B7079"))
|
||||
Button("Оплачено?") { Task { await ops.act(["op": "pay_sub", "id": sub.id]) } }
|
||||
.buttonStyle(.plain).font(.system(size: 11.5, weight: .medium)).foregroundColor(Color(hex: "#60A5FA"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user