feat(office): mail preview, infinite scroll, pane resize, and scrollbars
Release Please / Release Please (push) Skipped
Tests / Test (Go 1.22) (push) Skipped
Tests / Test (Go stable) (push) Skipped
Release / GoReleaser (push) Failing after 38s
Release Please / Release Please (push) Skipped
Tests / Test (Go 1.22) (push) Skipped
Tests / Test (Go stable) (push) Skipped
Release / GoReleaser (push) Failing after 38s
Polish the office TUI with proportional pane layout, drag resize, live filtering, HTML mail preview, paginated mail lists, overflow scrollbars, flattened navigation, and project save/status fixes; add UpdateProjectStatus. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ClassifyCalendarRow decides whether an API row is a calendar or an event.
|
||||
func ClassifyCalendarRow(raw map[string]any) (Kind, string) {
|
||||
if raw == nil {
|
||||
return KindCalendar, "Calendar"
|
||||
}
|
||||
if strRaw(raw, "start") != "" || strRaw(raw, "end") != "" {
|
||||
return KindEvent, "Event"
|
||||
}
|
||||
if strRaw(raw, "eventType") != "" {
|
||||
return KindEvent, "Event"
|
||||
}
|
||||
return KindCalendar, "Calendar"
|
||||
}
|
||||
|
||||
// CalendarTypeLabel returns the type column text for a calendar list row.
|
||||
func CalendarTypeLabel(it Item) string {
|
||||
if it.Raw != nil {
|
||||
if t := strRaw(it.Raw, "type"); t != "" {
|
||||
return t
|
||||
}
|
||||
}
|
||||
_, label := ClassifyCalendarRow(it.Raw)
|
||||
return label
|
||||
}
|
||||
|
||||
// FormatCalendarDateTime formats start/end timestamps for the calendar table.
|
||||
func FormatCalendarDateTime(v any) string {
|
||||
t, ok := parseDeadlineTime(v)
|
||||
if !ok {
|
||||
if s := fmt.Sprint(v); s != "" && s != "<nil>" {
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return t.Format("Jan 2 15:04")
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestClassifyCalendarRow(t *testing.T) {
|
||||
kind, label := ClassifyCalendarRow(map[string]any{
|
||||
"title": "Standup",
|
||||
"start": "2026-06-24T10:00:00Z",
|
||||
})
|
||||
if kind != KindEvent || label != "Event" {
|
||||
t.Fatalf("got kind=%s label=%q", kind, label)
|
||||
}
|
||||
kind, label = ClassifyCalendarRow(map[string]any{"title": "Work"})
|
||||
if kind != KindCalendar || label != "Calendar" {
|
||||
t.Fatalf("got kind=%s label=%q", kind, label)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCalendarColumnsIncludesType(t *testing.T) {
|
||||
items := []Item{{
|
||||
ID: "1", Title: "Meet", Kind: KindEvent,
|
||||
Raw: map[string]any{"type": "Event", "start": "2026-06-24T10:00:00Z"},
|
||||
}}
|
||||
cols := BuildColumns(SubjectCalendar, items)
|
||||
found := false
|
||||
for _, c := range cols {
|
||||
if c.Key == "type" {
|
||||
found = true
|
||||
}
|
||||
if c.Key == "subtitle" {
|
||||
t.Fatal("subtitle column should not appear")
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("expected type column")
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,12 @@ func BuildColumns(subject Subject, items []Item) []TableColumn {
|
||||
if subject == SubjectProjects {
|
||||
return buildProjectColumns(items)
|
||||
}
|
||||
if subject == SubjectTasks {
|
||||
return buildTaskColumns(items)
|
||||
}
|
||||
if subject == SubjectCalendar {
|
||||
return buildCalendarColumns(items)
|
||||
}
|
||||
cols := []TableColumn{
|
||||
{Key: "_sel", Title: "✓", Width: 3},
|
||||
{Key: "id", Title: "ID", Width: 10},
|
||||
@@ -64,10 +70,43 @@ func BuildColumns(subject Subject, items []Item) []TableColumn {
|
||||
return cols
|
||||
}
|
||||
|
||||
func buildCalendarColumns(items []Item) []TableColumn {
|
||||
cols := []TableColumn{
|
||||
{Key: "_sel", Title: "✓", Width: 3},
|
||||
{Key: "id", Title: "ID", Width: 10},
|
||||
{Key: "type", Title: "Type", Width: 10},
|
||||
{Key: "title", Title: "Title", Width: 28},
|
||||
}
|
||||
for _, key := range []string{"start", "end"} {
|
||||
if columnHasData(items, key) {
|
||||
cols = append(cols, TableColumn{Key: key, Title: titleLabel(key), Width: defaultWidth(key)})
|
||||
}
|
||||
}
|
||||
sizeColumns(cols, items)
|
||||
return cols
|
||||
}
|
||||
|
||||
func buildTaskColumns(items []Item) []TableColumn {
|
||||
cols := []TableColumn{
|
||||
{Key: "_sel", Title: "✓", Width: 3},
|
||||
{Key: "id", Title: "ID", Width: 8},
|
||||
{Key: "title", Title: "Title", Width: 28},
|
||||
{Key: "status", Title: "Status", Width: 10},
|
||||
}
|
||||
for _, key := range []string{"deadline", "responsible"} {
|
||||
if columnHasData(items, key) {
|
||||
cols = append(cols, TableColumn{Key: key, Title: titleLabel(key), Width: defaultWidth(key)})
|
||||
}
|
||||
}
|
||||
sizeColumns(cols, items)
|
||||
return cols
|
||||
}
|
||||
|
||||
func buildProjectColumns(items []Item) []TableColumn {
|
||||
cols := []TableColumn{
|
||||
{Key: "_sel", Title: "✓", Width: 3},
|
||||
{Key: "id", Title: "ID", Width: 8},
|
||||
{Key: "status", Title: "Status", Width: 8},
|
||||
{Key: "title", Title: "Title", Width: 28},
|
||||
{Key: "tasks", Title: "Tasks (open/closed)", Width: 18},
|
||||
{Key: "documents", Title: "Documents", Width: 11},
|
||||
@@ -89,6 +128,47 @@ func CellText(it Item, key string) string {
|
||||
return it.ID
|
||||
case "title":
|
||||
return it.Title
|
||||
case "type":
|
||||
return CalendarTypeLabel(it)
|
||||
case "start", "end":
|
||||
if it.Raw == nil {
|
||||
return ""
|
||||
}
|
||||
if formatted := FormatCalendarDateTime(it.Raw[key]); formatted != "" {
|
||||
return formatted
|
||||
}
|
||||
return formatAny(it.Raw[key])
|
||||
case "status":
|
||||
switch it.Kind {
|
||||
case KindProject:
|
||||
return ProjectStatusLabel(it.Raw)
|
||||
case KindTask, KindCRMTask:
|
||||
if it.Raw == nil {
|
||||
return ""
|
||||
}
|
||||
return TaskStatusLabel(it.Raw["status"])
|
||||
default:
|
||||
if it.Raw == nil {
|
||||
return ""
|
||||
}
|
||||
return formatAny(it.Raw["status"])
|
||||
}
|
||||
case "deadline":
|
||||
if it.Raw == nil {
|
||||
return ""
|
||||
}
|
||||
if rel := FormatRelativeDeadline(it.Raw["deadline"]); rel != "" {
|
||||
return rel
|
||||
}
|
||||
return formatAny(it.Raw["deadline"])
|
||||
case "responsible":
|
||||
if it.Kind == KindTask || it.Kind == KindCRMTask {
|
||||
return TaskResponsibleLabel(it.Raw)
|
||||
}
|
||||
if it.Raw == nil {
|
||||
return ""
|
||||
}
|
||||
return formatAny(it.Raw["responsible"])
|
||||
case "subtitle":
|
||||
return it.Subtitle
|
||||
case "tasks":
|
||||
@@ -230,7 +310,7 @@ func defaultWidth(key string) int {
|
||||
case "id", "status", "stage":
|
||||
return 10
|
||||
case "start", "end", "deadline", "date":
|
||||
return 18
|
||||
return 20
|
||||
case "from", "to", "email", "primaryEmail":
|
||||
return 22
|
||||
case "description", "displayName":
|
||||
|
||||
@@ -11,7 +11,7 @@ func TestBuildProjectColumns(t *testing.T) {
|
||||
},
|
||||
}}
|
||||
cols := BuildColumns(SubjectProjects, items)
|
||||
want := []string{"_sel", "id", "title", "tasks", "documents", "users"}
|
||||
want := []string{"_sel", "id", "status", "title", "tasks", "documents", "users"}
|
||||
if len(cols) != len(want) {
|
||||
t.Fatalf("got %d columns, want %d", len(cols), len(want))
|
||||
}
|
||||
@@ -21,12 +21,23 @@ func TestBuildProjectColumns(t *testing.T) {
|
||||
}
|
||||
}
|
||||
for _, c := range cols {
|
||||
if c.Key == "status" || c.Key == "subtitle" {
|
||||
if c.Key == "subtitle" {
|
||||
t.Fatalf("unexpected column %q", c.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCellTextProjectStatus(t *testing.T) {
|
||||
open := Item{Kind: KindProject, Raw: map[string]any{"status": 0}}
|
||||
if got := CellText(open, "status"); got != "Open" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
closed := Item{Kind: KindProject, Raw: map[string]any{"status": 2}}
|
||||
if got := CellText(closed, "status"); got != "Closed" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatProjectTasksOpenClosed(t *testing.T) {
|
||||
raw := map[string]any{"taskCount": 3, "taskCountTotal": 8}
|
||||
if got := formatProjectTasks(raw); got != "3/5" {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FilterItems returns items whose searchable text contains query (case-insensitive).
|
||||
func FilterItems(items []Item, query string) []Item {
|
||||
q := strings.ToLower(strings.TrimSpace(query))
|
||||
if q == "" {
|
||||
out := make([]Item, len(items))
|
||||
copy(out, items)
|
||||
return out
|
||||
}
|
||||
out := make([]Item, 0, len(items))
|
||||
for _, it := range items {
|
||||
if strings.Contains(strings.ToLower(ItemSearchText(it)), q) {
|
||||
out = append(out, it)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ItemSearchText joins item fields used for list filtering.
|
||||
func ItemSearchText(it Item) string {
|
||||
var parts []string
|
||||
parts = append(parts, it.ID, it.Title, it.Subtitle, string(it.Kind))
|
||||
if it.Raw != nil {
|
||||
for _, v := range it.Raw {
|
||||
parts = append(parts, formatAny(v))
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package model_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/eslider/go-onlyoffice/cmd/office/model"
|
||||
)
|
||||
|
||||
func TestFilterItemsByTitle(t *testing.T) {
|
||||
items := []model.Item{
|
||||
{ID: "1", Title: "Alpha task"},
|
||||
{ID: "2", Title: "Beta task"},
|
||||
}
|
||||
got := model.FilterItems(items, "alpha")
|
||||
if len(got) != 1 || got[0].ID != "1" {
|
||||
t.Fatalf("got %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterItemsEmptyQueryReturnsAll(t *testing.T) {
|
||||
items := []model.Item{{ID: "1", Title: "A"}, {ID: "2", Title: "B"}}
|
||||
got := model.FilterItems(items, " ")
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("got len=%d want 2", len(got))
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,9 @@ type FormFields struct {
|
||||
Primary string
|
||||
Secondary string
|
||||
ReadOnly bool
|
||||
HasStatus bool
|
||||
Status ProjectLifecycle
|
||||
ResponsibleID string
|
||||
}
|
||||
|
||||
// KindHeading returns a short label for the detail pane header.
|
||||
@@ -80,6 +83,21 @@ func FormFieldsFromRaw(kind Kind, raw map[string]any) FormFields {
|
||||
Primary: strRaw(raw, "title"), Secondary: strRaw(raw, "description"),
|
||||
ReadOnly: true,
|
||||
}
|
||||
case KindProject:
|
||||
title := strRaw(raw, "title")
|
||||
if title == "" {
|
||||
title = strRaw(raw, "name")
|
||||
}
|
||||
return FormFields{
|
||||
PrimaryLabel: "Title",
|
||||
SecondaryLabel: "Description",
|
||||
Primary: title,
|
||||
Secondary: strRaw(raw, "description"),
|
||||
ReadOnly: false,
|
||||
HasStatus: true,
|
||||
Status: ProjectStatusFromAny(raw["status"]),
|
||||
ResponsibleID: ResponsibleIDFromRaw(raw),
|
||||
}
|
||||
default:
|
||||
title := strRaw(raw, "title")
|
||||
if title == "" {
|
||||
@@ -109,7 +127,19 @@ func strRaw(m map[string]any, key string) string {
|
||||
return fmt.Sprint(m[key])
|
||||
}
|
||||
|
||||
// IsDocumentKind is true when the right pane should show file content, not a form.
|
||||
// ResponsibleIDFromRaw extracts the project responsible user id from API detail.
|
||||
func ResponsibleIDFromRaw(raw map[string]any) string {
|
||||
if id := strRaw(raw, "responsibleId"); id != "" {
|
||||
return id
|
||||
}
|
||||
resp, ok := raw["responsible"].(map[string]any)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return strRaw(resp, "id")
|
||||
}
|
||||
|
||||
// IsDocumentKind is true when the right pane should show rendered preview content, not an editable form.
|
||||
func IsDocumentKind(kind Kind) bool {
|
||||
return kind == KindFile
|
||||
return kind == KindFile || kind == KindMail
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ func TestIsDocumentKind(t *testing.T) {
|
||||
if !IsDocumentKind(KindFile) {
|
||||
t.Fatal("file should be document")
|
||||
}
|
||||
if !IsDocumentKind(KindMail) {
|
||||
t.Fatal("mail should be document preview")
|
||||
}
|
||||
if IsDocumentKind(KindTask) {
|
||||
t.Fatal("task should be form")
|
||||
}
|
||||
|
||||
@@ -39,8 +39,19 @@ const (
|
||||
SubjectProjectFiles Subject = "project_files"
|
||||
SubjectTaskFiles Subject = "task_files"
|
||||
SubjectUsers Subject = "users"
|
||||
SubjectCalendar Subject = "calendar"
|
||||
)
|
||||
|
||||
// SubjectIsMail reports whether a list subject loads mailbox messages.
|
||||
func SubjectIsMail(s Subject) bool {
|
||||
switch s {
|
||||
case SubjectMailInbox, SubjectMailSent, SubjectMailDrafts, SubjectMailTrash, SubjectMailSpam:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// FocusPane is which column has keyboard focus.
|
||||
type FocusPane int
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSubjectIsMail(t *testing.T) {
|
||||
if !SubjectIsMail(SubjectMailInbox) {
|
||||
t.Fatal("inbox should be mail")
|
||||
}
|
||||
if SubjectIsMail(SubjectProjects) {
|
||||
t.Fatal("projects should not be mail")
|
||||
}
|
||||
}
|
||||
+58
-13
@@ -1,5 +1,7 @@
|
||||
package model
|
||||
|
||||
import "strings"
|
||||
|
||||
// ListSpec tells the fetch layer what to load when a nav leaf is active.
|
||||
type ListSpec struct {
|
||||
Subject Subject
|
||||
@@ -24,6 +26,7 @@ type NavTree struct {
|
||||
expanded map[string]bool
|
||||
cursor int
|
||||
visible []string
|
||||
filter string
|
||||
}
|
||||
|
||||
// DefaultNavTree returns the OnlyOffice module tree (static skeleton).
|
||||
@@ -42,15 +45,11 @@ func DefaultNavTree() *NavTree {
|
||||
}
|
||||
}
|
||||
|
||||
add("projects", "Projects", "", true, nil)
|
||||
add("projects.browse", "Browse", "projects", true, nil)
|
||||
add("projects.browse.all", "All projects", "projects.browse", false, &ListSpec{Subject: SubjectProjects})
|
||||
add("projects.browse.tasks", "All tasks", "projects.browse", false, &ListSpec{Subject: SubjectTasks})
|
||||
add("projects.dynamic", "By project", "projects", true, nil)
|
||||
add("projects", "Projects", "", false, &ListSpec{Subject: SubjectProjects})
|
||||
add("tasks", "Tasks", "", false, &ListSpec{Subject: SubjectTasks})
|
||||
add("projects.dynamic", "By project", "", true, nil)
|
||||
|
||||
add("calendar", "Calendar", "", true, nil)
|
||||
add("calendar.cals", "Calendars", "calendar", false, &ListSpec{Subject: SubjectCalendars})
|
||||
add("calendar.events", "Events", "calendar", false, &ListSpec{Subject: SubjectEvents})
|
||||
add("calendar", "Calendar", "", false, &ListSpec{Subject: SubjectCalendar})
|
||||
|
||||
add("crm", "CRM", "", true, nil)
|
||||
add("crm.contacts", "Contacts", "crm", false, &ListSpec{Subject: SubjectContacts})
|
||||
@@ -185,20 +184,66 @@ func (t *NavTree) Activate() (*ListSpec, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (t *NavTree) SetFilter(query string) {
|
||||
t.filter = strings.ToLower(strings.TrimSpace(query))
|
||||
t.rebuildVisible()
|
||||
}
|
||||
|
||||
func (t *NavTree) ClearFilter() {
|
||||
t.filter = ""
|
||||
t.rebuildVisible()
|
||||
}
|
||||
|
||||
func (t *NavTree) FilterQuery() string { return t.filter }
|
||||
|
||||
func (t *NavTree) nodeLabelMatches(id string) bool {
|
||||
if t.filter == "" {
|
||||
return true
|
||||
}
|
||||
n, ok := t.nodes[id]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(strings.ToLower(n.Label), t.filter)
|
||||
}
|
||||
|
||||
func (t *NavTree) hasMatchingDescendant(id string) bool {
|
||||
for _, child := range t.children[id] {
|
||||
if t.nodeLabelMatches(child) || t.hasMatchingDescendant(child) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *NavTree) visibleUnderFilter(id string) bool {
|
||||
if t.filter == "" {
|
||||
return true
|
||||
}
|
||||
return t.nodeLabelMatches(id) || t.hasMatchingDescendant(id)
|
||||
}
|
||||
|
||||
func (t *NavTree) rebuildVisible() {
|
||||
t.visible = t.visible[:0]
|
||||
var walk func(id string, depth int)
|
||||
walk = func(id string, depth int) {
|
||||
var walk func(id string)
|
||||
walk = func(id string) {
|
||||
if !t.visibleUnderFilter(id) {
|
||||
return
|
||||
}
|
||||
t.visible = append(t.visible, id)
|
||||
if !t.expanded[id] {
|
||||
expanded := t.expanded[id]
|
||||
if t.filter != "" && t.hasMatchingDescendant(id) {
|
||||
expanded = true
|
||||
}
|
||||
if !expanded {
|
||||
return
|
||||
}
|
||||
for _, child := range t.children[id] {
|
||||
walk(child, depth+1)
|
||||
walk(child)
|
||||
}
|
||||
}
|
||||
for _, root := range t.roots {
|
||||
walk(root, 0)
|
||||
walk(root)
|
||||
}
|
||||
if t.cursor >= len(t.visible) {
|
||||
t.cursor = len(t.visible) - 1
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func TestNavTreeHasExpectedRoots(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
roots := tree.RootLabels()
|
||||
want := []string{"Projects", "Calendar", "CRM", "Mail", "Users"}
|
||||
want := []string{"Projects", "Tasks", "By project", "Calendar", "CRM", "Mail", "Users"}
|
||||
if len(roots) != len(want) {
|
||||
t.Fatalf("roots=%v want %v", roots, want)
|
||||
}
|
||||
@@ -22,42 +22,79 @@ func TestNavTreeHasExpectedRoots(t *testing.T) {
|
||||
|
||||
func TestNavExpandCollapse(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
if !tree.IsExpandable(0) {
|
||||
t.Fatal("Projects should be expandable")
|
||||
var crm int = -1
|
||||
for i := 0; i < tree.VisibleCount(); i++ {
|
||||
n, ok := tree.NodeAtVisible(i)
|
||||
if ok && n.Label == "CRM" {
|
||||
crm = i
|
||||
break
|
||||
}
|
||||
}
|
||||
tree.ToggleExpand(0)
|
||||
if !tree.IsExpanded(0) {
|
||||
t.Fatal("Projects should expand")
|
||||
if crm < 0 {
|
||||
t.Fatal("CRM node not found")
|
||||
}
|
||||
tree.ToggleExpand(0)
|
||||
if tree.IsExpanded(0) {
|
||||
t.Fatal("Projects should collapse")
|
||||
if !tree.IsExpandable(crm) {
|
||||
t.Fatal("CRM should be expandable")
|
||||
}
|
||||
tree.ToggleExpand(crm)
|
||||
if !tree.IsExpanded(crm) {
|
||||
t.Fatal("CRM should expand")
|
||||
}
|
||||
tree.ToggleExpand(crm)
|
||||
if tree.IsExpanded(crm) {
|
||||
t.Fatal("CRM should collapse")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavLeafReturnsListSpec(t *testing.T) {
|
||||
func TestNavCalendarLeafReturnsListSpec(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
tree.ToggleExpand(0) // Projects
|
||||
tree.ToggleExpand(1) // Browse
|
||||
// Find "All projects" leaf cursor
|
||||
var found int = -1
|
||||
for i := 0; i < tree.VisibleCount(); i++ {
|
||||
n, ok := tree.NodeAtVisible(i)
|
||||
if ok && n.List != nil && n.List.Subject == model.SubjectProjects {
|
||||
if ok && n.Label == "Calendar" {
|
||||
found = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if found < 0 {
|
||||
t.Fatal("all projects leaf not found")
|
||||
t.Fatal("Calendar node not found")
|
||||
}
|
||||
tree.SetCursor(found)
|
||||
spec, ok := tree.CurrentListSpec()
|
||||
if !ok || spec.Subject != model.SubjectProjects {
|
||||
if !ok || spec.Subject != model.SubjectCalendar {
|
||||
t.Fatalf("spec=%v ok=%v", spec, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavProjectsLeafReturnsListSpec(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
tree.SetCursor(0)
|
||||
spec, ok := tree.CurrentListSpec()
|
||||
if !ok || spec.Subject != model.SubjectProjects {
|
||||
t.Fatalf("projects spec=%v ok=%v", spec, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavTasksLeafReturnsListSpec(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
var found int = -1
|
||||
for i := 0; i < tree.VisibleCount(); i++ {
|
||||
n, ok := tree.NodeAtVisible(i)
|
||||
if ok && n.Label == "Tasks" {
|
||||
found = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if found < 0 {
|
||||
t.Fatal("Tasks node not found")
|
||||
}
|
||||
tree.SetCursor(found)
|
||||
spec, ok := tree.CurrentListSpec()
|
||||
if !ok || spec.Subject != model.SubjectTasks {
|
||||
t.Fatalf("tasks spec=%v ok=%v", spec, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrevFocusPane(t *testing.T) {
|
||||
if got := model.PrevFocusPane(model.FocusList); got != model.FocusMenu {
|
||||
t.Fatalf("got %v", got)
|
||||
@@ -67,6 +104,41 @@ func TestPrevFocusPane(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavFilterByLabel(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
tree.SetFilter("inbox")
|
||||
found := false
|
||||
for i := 0; i < tree.VisibleCount(); i++ {
|
||||
n, ok := tree.NodeAtVisible(i)
|
||||
if ok && n.Label == "Inbox" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("Inbox should remain visible when filtering mail")
|
||||
}
|
||||
for i := 0; i < tree.VisibleCount(); i++ {
|
||||
n, ok := tree.NodeAtVisible(i)
|
||||
if ok && n.Label == "Calendar" {
|
||||
t.Fatal("Calendar should be hidden when filtering inbox")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNavClearFilterRestoresTree(t *testing.T) {
|
||||
tree := model.DefaultNavTree()
|
||||
before := tree.VisibleCount()
|
||||
tree.SetFilter("zzz-no-match")
|
||||
if tree.VisibleCount() >= before {
|
||||
t.Fatalf("filter should shrink visible nodes")
|
||||
}
|
||||
tree.ClearFilter()
|
||||
if tree.VisibleCount() != before {
|
||||
t.Fatalf("clear filter should restore visible count")
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionsForContact(t *testing.T) {
|
||||
acts := model.ActionsFor(model.KindContact)
|
||||
if len(acts) != 1 || acts[0].ID != model.ActionDelete {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package model
|
||||
|
||||
// ProjectLifecycle is the OnlyOffice project status string accepted by the API.
|
||||
type ProjectLifecycle string
|
||||
|
||||
const (
|
||||
ProjectLifecycleOpen ProjectLifecycle = "open"
|
||||
ProjectLifecyclePaused ProjectLifecycle = "paused"
|
||||
ProjectLifecycleClosed ProjectLifecycle = "closed"
|
||||
)
|
||||
|
||||
// ProjectStatusFromAny maps API status (int or string) to a lifecycle value.
|
||||
func ProjectStatusFromAny(v any) ProjectLifecycle {
|
||||
switch x := v.(type) {
|
||||
case string:
|
||||
switch ProjectLifecycle(x) {
|
||||
case ProjectLifecycleOpen, ProjectLifecyclePaused, ProjectLifecycleClosed:
|
||||
return ProjectLifecycle(x)
|
||||
}
|
||||
case float64:
|
||||
return projectStatusFromInt(int(x))
|
||||
case int:
|
||||
return projectStatusFromInt(x)
|
||||
case int64:
|
||||
return projectStatusFromInt(int(x))
|
||||
}
|
||||
return ProjectLifecycleOpen
|
||||
}
|
||||
|
||||
func projectStatusFromInt(n int) ProjectLifecycle {
|
||||
switch n {
|
||||
case 1:
|
||||
return ProjectLifecyclePaused
|
||||
case 2:
|
||||
return ProjectLifecycleClosed
|
||||
default:
|
||||
return ProjectLifecycleOpen
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectStatusLabel returns a short UI label for list cells.
|
||||
func ProjectStatusLabel(raw map[string]any) string {
|
||||
if raw == nil {
|
||||
return "Open"
|
||||
}
|
||||
return ProjectStatusFromAny(raw["status"]).Label()
|
||||
}
|
||||
|
||||
// ProjectIsOpen is true when the project is not closed.
|
||||
func ProjectIsOpen(raw map[string]any) bool {
|
||||
if raw == nil {
|
||||
return true
|
||||
}
|
||||
return ProjectStatusFromAny(raw["status"]) != ProjectLifecycleClosed
|
||||
}
|
||||
|
||||
// Label returns a human-readable status name.
|
||||
func (s ProjectLifecycle) Label() string {
|
||||
switch s {
|
||||
case ProjectLifecycleClosed:
|
||||
return "Closed"
|
||||
case ProjectLifecyclePaused:
|
||||
return "Paused"
|
||||
default:
|
||||
return "Open"
|
||||
}
|
||||
}
|
||||
|
||||
// ToggleOpenClosed flips between open and closed (paused maps to closed on toggle).
|
||||
func (s ProjectLifecycle) ToggleOpenClosed() ProjectLifecycle {
|
||||
if s == ProjectLifecycleClosed {
|
||||
return ProjectLifecycleOpen
|
||||
}
|
||||
return ProjectLifecycleClosed
|
||||
}
|
||||
|
||||
// Next cycles open → closed → open for keyboard toggling.
|
||||
func (s ProjectLifecycle) Next() ProjectLifecycle {
|
||||
return s.ToggleOpenClosed()
|
||||
}
|
||||
|
||||
// Prev cycles closed → open → closed.
|
||||
func (s ProjectLifecycle) Prev() ProjectLifecycle {
|
||||
return s.ToggleOpenClosed()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package model_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/eslider/go-onlyoffice/cmd/office/model"
|
||||
)
|
||||
|
||||
func TestProjectStatusFromInt(t *testing.T) {
|
||||
if got := model.ProjectStatusFromAny(2); got != model.ProjectLifecycleClosed {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
if got := model.ProjectStatusFromAny(0); got != model.ProjectLifecycleOpen {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectStatusToggle(t *testing.T) {
|
||||
s := model.ProjectLifecycleOpen
|
||||
if s.Next() != model.ProjectLifecycleClosed {
|
||||
t.Fatal("expected closed")
|
||||
}
|
||||
if s.Next().Prev() != model.ProjectLifecycleOpen {
|
||||
t.Fatal("expected open after toggle back")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TaskStatusLabel returns a human-readable project/CRM task status.
|
||||
func TaskStatusLabel(v any) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
if s, ok := v.(string); ok {
|
||||
if label := taskStatusFromString(s); label != "" {
|
||||
return label
|
||||
}
|
||||
}
|
||||
n := intRawVal(map[string]any{"status": v}, "status")
|
||||
switch n {
|
||||
case 0:
|
||||
return "Not accepted"
|
||||
case 1:
|
||||
return "Open"
|
||||
case 2:
|
||||
return "Closed"
|
||||
case 3:
|
||||
return "Disabled"
|
||||
case 4:
|
||||
return "Unclassified"
|
||||
case 5:
|
||||
return "Not in milestone"
|
||||
default:
|
||||
if s := fmt.Sprint(v); s != "" && s != "<nil>" {
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func taskStatusFromString(s string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(s)) {
|
||||
case "open":
|
||||
return "Open"
|
||||
case "closed":
|
||||
return "Closed"
|
||||
case "notaccept", "not accept", "not accepted":
|
||||
return "Not accepted"
|
||||
case "disable", "disabled":
|
||||
return "Disabled"
|
||||
case "unclassified":
|
||||
return "Unclassified"
|
||||
case "notinmilestone", "not in milestone":
|
||||
return "Not in milestone"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// FormatRelativeDeadline formats a deadline as "in 2 hours" or "3 days ago".
|
||||
func FormatRelativeDeadline(v any) string {
|
||||
return FormatRelativeDeadlineAt(v, time.Now())
|
||||
}
|
||||
|
||||
// FormatRelativeDeadlineAt is FormatRelativeDeadline with a fixed clock (for tests).
|
||||
func FormatRelativeDeadlineAt(v any, now time.Time) string {
|
||||
t, ok := parseDeadlineTime(v)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return relativeTimePhrase(now, t)
|
||||
}
|
||||
|
||||
func relativeTimePhrase(now, target time.Time) string {
|
||||
d := target.Sub(now)
|
||||
future := d >= 0
|
||||
if !future {
|
||||
d = -d
|
||||
}
|
||||
phrase := func(n int, unit string) string {
|
||||
if n == 1 {
|
||||
unit = strings.TrimSuffix(unit, "s")
|
||||
}
|
||||
if future {
|
||||
return fmt.Sprintf("in %d %s", n, unit)
|
||||
}
|
||||
return fmt.Sprintf("%d %s ago", n, unit)
|
||||
}
|
||||
switch {
|
||||
case d < time.Minute:
|
||||
if future {
|
||||
return "in 1 minute"
|
||||
}
|
||||
return "just now"
|
||||
case d < time.Hour:
|
||||
return phrase(int(d.Round(time.Minute)/time.Minute), "minutes")
|
||||
case d < 24*time.Hour:
|
||||
return phrase(int(d.Round(time.Hour)/time.Hour), "hours")
|
||||
default:
|
||||
return phrase(int(d.Round(24*time.Hour)/(24*time.Hour)), "days")
|
||||
}
|
||||
}
|
||||
|
||||
func parseDeadlineTime(v any) (time.Time, bool) {
|
||||
if v == nil {
|
||||
return time.Time{}, false
|
||||
}
|
||||
switch x := v.(type) {
|
||||
case time.Time:
|
||||
return x, true
|
||||
case string:
|
||||
s := strings.TrimSpace(x)
|
||||
if s == "" {
|
||||
return time.Time{}, false
|
||||
}
|
||||
formats := []string{
|
||||
time.RFC3339Nano,
|
||||
"2006-01-02T15:04:05.0000000-07:00",
|
||||
"2006-01-02T15:04:05-07:00",
|
||||
"2006-01-02T15:04:05",
|
||||
"2006-01-02",
|
||||
}
|
||||
for _, layout := range formats {
|
||||
if t, err := time.Parse(layout, s); err == nil {
|
||||
return t, true
|
||||
}
|
||||
}
|
||||
return time.Time{}, false
|
||||
case float64:
|
||||
return time.Unix(int64(x), 0), true
|
||||
case int64:
|
||||
return time.Unix(x, 0), true
|
||||
case int:
|
||||
return time.Unix(int64(x), 0), true
|
||||
default:
|
||||
return parseDeadlineTime(fmt.Sprint(v))
|
||||
}
|
||||
}
|
||||
|
||||
// TaskResponsibleLabel returns the assignee display name when present.
|
||||
func TaskResponsibleLabel(raw map[string]any) string {
|
||||
if raw == nil {
|
||||
return ""
|
||||
}
|
||||
if name := personName(raw["responsible"]); name != "" {
|
||||
return name
|
||||
}
|
||||
if list, ok := raw["responsibles"].([]any); ok {
|
||||
names := make([]string, 0, len(list))
|
||||
for _, entry := range list {
|
||||
if name := personName(entry); name != "" {
|
||||
names = append(names, name)
|
||||
}
|
||||
}
|
||||
if len(names) > 0 {
|
||||
return strings.Join(names, ", ")
|
||||
}
|
||||
}
|
||||
if s := strRaw(raw, "responsible"); s != "" && !looksLikeID(s) {
|
||||
return s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func personName(v any) string {
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if name := strRaw(m, "displayName"); name != "" {
|
||||
return name
|
||||
}
|
||||
first := strRaw(m, "firstName")
|
||||
last := strRaw(m, "lastName")
|
||||
return strings.TrimSpace(first + " " + last)
|
||||
}
|
||||
|
||||
func looksLikeID(s string) bool {
|
||||
if len(s) == 36 && strings.Count(s, "-") == 4 {
|
||||
return true
|
||||
}
|
||||
_, err := strconv.Atoi(s)
|
||||
return err == nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTaskStatusLabelFromInt(t *testing.T) {
|
||||
if got := TaskStatusLabel(1); got != "Open" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
if got := TaskStatusLabel(2); got != "Closed" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatRelativeDeadlineFuture(t *testing.T) {
|
||||
now := time.Date(2026, 6, 24, 12, 0, 0, 0, time.UTC)
|
||||
deadline := now.Add(2 * time.Hour)
|
||||
got := FormatRelativeDeadlineAt(deadline.Format(time.RFC3339), now)
|
||||
if got != "in 2 hours" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatRelativeDeadlineDays(t *testing.T) {
|
||||
now := time.Date(2026, 6, 24, 12, 0, 0, 0, time.UTC)
|
||||
deadline := now.Add(26 * time.Hour)
|
||||
got := FormatRelativeDeadlineAt(deadline.Format(time.RFC3339), now)
|
||||
if got != "in 1 day" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTaskColumnsOmitsSubtitle(t *testing.T) {
|
||||
items := []Item{{
|
||||
ID: "1", Title: "Fix bug", Kind: KindTask, Subtitle: "1",
|
||||
Raw: map[string]any{"status": 1, "deadline": "2026-06-25T12:00:00Z"},
|
||||
}}
|
||||
cols := BuildColumns(SubjectTasks, items)
|
||||
for _, c := range cols {
|
||||
if c.Key == "subtitle" {
|
||||
t.Fatalf("unexpected subtitle column")
|
||||
}
|
||||
}
|
||||
if CellText(items[0], "status") != "Open" {
|
||||
t.Fatalf("status not humanized")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user