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:
@@ -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