ProjectDetailPane modified as a Component (type)
This commit is contained in:
16
app/cli.go
16
app/cli.go
@@ -11,14 +11,14 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
app *tview.Application
|
||||
projectDetailPane *tview.Flex
|
||||
layout, contents *tview.Flex
|
||||
app *tview.Application
|
||||
layout, contents *tview.Flex
|
||||
|
||||
statusBar *StatusBar
|
||||
projectPane *ProjectPane
|
||||
taskPane *TaskPane
|
||||
taskDetailPane *TaskDetailPane
|
||||
statusBar *StatusBar
|
||||
projectPane *ProjectPane
|
||||
taskPane *TaskPane
|
||||
taskDetailPane *TaskDetailPane
|
||||
projectDetailPane *ProjectDetailPane
|
||||
|
||||
db *storm.DB
|
||||
projectRepo repository.ProjectRepository
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
statusBar = makeStatusBar(app)
|
||||
projectPane = NewProjectPane(projectRepo)
|
||||
taskPane = NewTaskPane(projectRepo, taskRepo)
|
||||
prepareProjectDetail()
|
||||
projectDetailPane = NewProjectDetailPane()
|
||||
taskDetailPane = NewTaskDetailPane(taskRepo)
|
||||
|
||||
contents = tview.NewFlex().
|
||||
|
||||
@@ -1,34 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
|
||||
"github.com/ajaxray/geek-life/model"
|
||||
)
|
||||
|
||||
func prepareProjectDetail() {
|
||||
deleteBtn := makeButton("Delete Project", projectPane.removeActivateProject)
|
||||
clearBtn := makeButton("Clear Completed Tasks", clearCompletedTasks)
|
||||
type ProjectDetailPane struct {
|
||||
*tview.Flex
|
||||
project *model.Project
|
||||
}
|
||||
|
||||
func NewProjectDetailPane() *ProjectDetailPane {
|
||||
pane := ProjectDetailPane{
|
||||
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
|
||||
}
|
||||
deleteBtn := makeButton("Delete Project", projectPane.RemoveActivateProject)
|
||||
clearBtn := makeButton("Clear Completed Tasks", taskPane.ClearCompletedTasks)
|
||||
|
||||
deleteBtn.SetBackgroundColor(tcell.ColorRed)
|
||||
projectDetailPane = tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
pane.
|
||||
AddItem(deleteBtn, 3, 1, false).
|
||||
AddItem(blankCell, 1, 1, false).
|
||||
AddItem(clearBtn, 3, 1, false).
|
||||
AddItem(blankCell, 0, 1, false)
|
||||
|
||||
projectDetailPane.SetBorder(true).SetTitle("[::u]A[::-]ctions")
|
||||
pane.SetBorder(true).SetTitle("[::u]A[::-]ctions")
|
||||
|
||||
return &pane
|
||||
}
|
||||
|
||||
// @TODO - Move to tasks pane
|
||||
func clearCompletedTasks() {
|
||||
count := 0
|
||||
for i, task := range taskPane.tasks {
|
||||
if task.Completed && taskRepo.Delete(&taskPane.tasks[i]) == nil {
|
||||
taskPane.list.RemoveItem(i)
|
||||
count++
|
||||
}
|
||||
}
|
||||
statusBar.showForSeconds(fmt.Sprintf("[yellow]%d tasks cleared!", count), 5)
|
||||
func (pd *ProjectDetailPane) SetProject(project *model.Project) {
|
||||
pd.project = project
|
||||
pd.SetTitle("[::b]" + pd.project.Title)
|
||||
}
|
||||
|
||||
@@ -121,15 +121,14 @@ func (pane *ProjectPane) activateProject(idx int) {
|
||||
taskPane.LoadProjectTasks(*pane.activeProject)
|
||||
|
||||
removeThirdCol()
|
||||
projectDetailPane.SetTitle("[::b]" + pane.activeProject.Title)
|
||||
projectDetailPane.SetProject(pane.activeProject)
|
||||
contents.AddItem(projectDetailPane, 25, 0, false)
|
||||
app.SetFocus(taskPane)
|
||||
}
|
||||
|
||||
func (pane *ProjectPane) removeActivateProject() {
|
||||
func (pane *ProjectPane) RemoveActivateProject() {
|
||||
if pane.activeProject != nil && pane.repo.Delete(pane.activeProject) == nil {
|
||||
|
||||
// @TODO - Move to tasks pane
|
||||
for i := range taskPane.tasks {
|
||||
_ = taskRepo.Delete(&taskPane.tasks[i])
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ type TaskDetailPane struct {
|
||||
const dateLayoutISO = "2006-01-02"
|
||||
const dateLayoutHuman = "02 Jan, Monday"
|
||||
|
||||
var blankCell = tview.NewTextView()
|
||||
|
||||
func NewTaskDetailPane(taskRepo repository.TaskRepository) *TaskDetailPane {
|
||||
pane := TaskDetailPane{
|
||||
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
|
||||
|
||||
14
app/tasks.go
14
app/tasks.go
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/asdine/storm/v3"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
@@ -113,3 +115,15 @@ func (pane *TaskPane) ActivateTask(idx int) {
|
||||
contents.AddItem(taskDetailPane, 0, 3, false)
|
||||
|
||||
}
|
||||
|
||||
func (pane *TaskPane) ClearCompletedTasks() {
|
||||
count := 0
|
||||
for i, task := range pane.tasks {
|
||||
if task.Completed && pane.taskRepo.Delete(&pane.tasks[i]) == nil {
|
||||
pane.list.RemoveItem(i)
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
statusBar.showForSeconds(fmt.Sprintf("[yellow]%d tasks cleared!", count), 5)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"github.com/ajaxray/geek-life/util"
|
||||
)
|
||||
|
||||
var blankCell = tview.NewTextView()
|
||||
|
||||
func makeHorizontalLine(lineChar rune, color tcell.Color) *tview.TextView {
|
||||
hr := tview.NewTextView()
|
||||
hr.SetDrawFunc(func(screen tcell.Screen, x int, y int, width int, height int) (int, int, int, int) {
|
||||
|
||||
Reference in New Issue
Block a user