Handles defer error on Db closing. Updated lint recommendations.

This commit is contained in:
Anis Ahmad
2020-06-17 01:57:50 +06:00
parent cc3ad9ae88
commit d62656e1b7
6 changed files with 28 additions and 6 deletions

View File

@@ -29,7 +29,11 @@ func main() {
app = tview.NewApplication()
db = util.ConnectStorm()
defer db.Close()
defer func() {
if err := db.Close(); err != nil {
util.LogIfError(err, "Error in closing storm Db")
}
}()
projectRepo = repo.NewProjectRepository(db)
taskRepo = repo.NewTaskRepository(db)
@@ -88,7 +92,7 @@ func setKeyboardShortcuts() *tview.Application {
case 'f':
// @TODO : Remove
// statusBar.showForSeconds(reflect.TypeOf(app.GetFocus()).String(), 5)
statusBar.showForSeconds(projectPane.activeProject.Title, 5)
statusBar.showForSeconds(projectPane.GetActiveProject().Title, 5)
}
return event

View File

@@ -7,11 +7,13 @@ import (
"github.com/ajaxray/geek-life/model"
)
// ProjectDetailPane Displays relevant actions of current project
type ProjectDetailPane struct {
*tview.Flex
project *model.Project
}
// NewProjectDetailPane Initializes ProjectDetailPane
func NewProjectDetailPane() *ProjectDetailPane {
pane := ProjectDetailPane{
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
@@ -31,6 +33,7 @@ func NewProjectDetailPane() *ProjectDetailPane {
return &pane
}
// SetProject Sets the active Project
func (pd *ProjectDetailPane) SetProject(project *model.Project) {
pd.project = project
pd.SetTitle("[::b]" + pd.project.Title)

View File

@@ -11,6 +11,7 @@ import (
"github.com/ajaxray/geek-life/repository"
)
// ProjectPane Displays projects and dynamic lists
type ProjectPane struct {
*tview.Flex
projects []model.Project
@@ -21,6 +22,7 @@ type ProjectPane struct {
projectListStarting int // The index in list where project names starts
}
// NewProjectPane initializes
func NewProjectPane(repo repository.ProjectRepository) *ProjectPane {
pane := ProjectPane{
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
@@ -126,6 +128,7 @@ func (pane *ProjectPane) activateProject(idx int) {
app.SetFocus(taskPane)
}
// RemoveActivateProject deletes the currently active project
func (pane *ProjectPane) RemoveActivateProject() {
if pane.activeProject != nil && pane.repo.Delete(pane.activeProject) == nil {
@@ -152,6 +155,7 @@ func (pane *ProjectPane) loadListItems(focus bool) {
}
}
// GetActiveProject provides pointer to currently active project
func (pane *ProjectPane) GetActiveProject() *model.Project {
return pane.activeProject
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/rivo/tview"
)
// StatusBar displays hints and messages at the bottom of app
type StatusBar struct {
*tview.Pages
message *tview.TextView

View File

@@ -13,6 +13,10 @@ import (
"github.com/ajaxray/geek-life/repository"
)
const dateLayoutISO = "2006-01-02"
const dateLayoutHuman = "02 Jan, Monday"
// TaskDetailPane displays detailed info of a Task
type TaskDetailPane struct {
*tview.Flex
taskName, taskDateDisplay *tview.TextView
@@ -25,9 +29,7 @@ type TaskDetailPane struct {
task *model.Task
}
const dateLayoutISO = "2006-01-02"
const dateLayoutHuman = "02 Jan, Monday"
// NewTaskDetailPane initializes and configures a TaskDetailPane
func NewTaskDetailPane(taskRepo repository.TaskRepository) *TaskDetailPane {
pane := TaskDetailPane{
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
@@ -237,6 +239,7 @@ func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey
return event
}
// SetTask sets a Task to be displayed
func (td *TaskDetailPane) SetTask(task *model.Task) {
td.task = task

View File

@@ -11,6 +11,7 @@ import (
"github.com/ajaxray/geek-life/repository"
)
// TaskPane displays tasks of current TaskList or Project
type TaskPane struct {
*tview.Flex
list *tview.List
@@ -23,6 +24,7 @@ type TaskPane struct {
hint *tview.TextView
}
// NewTaskPane initializes and configures a TaskPane
func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.TaskRepository) *TaskPane {
pane := TaskPane{
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
@@ -46,7 +48,7 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
return
}
task, err := taskRepo.Create(*projectPane.activeProject, name, "", "", 0)
task, err := taskRepo.Create(*projectPane.GetActiveProject(), name, "", "", 0)
if err != nil {
statusBar.showForSeconds("[red::]Could not create Task:"+err.Error(), 5)
return
@@ -72,6 +74,7 @@ func NewTaskPane(projectRepo repository.ProjectRepository, taskRepo repository.T
return &pane
}
// ClearList removes all items from TaskPane
func (pane *TaskPane) ClearList() {
pane.list.Clear()
pane.tasks = nil
@@ -79,6 +82,7 @@ func (pane *TaskPane) ClearList() {
pane.RemoveItem(pane.newTask)
}
// SetList Sets a list of tasks to be displayed
func (pane *TaskPane) SetList(tasks []model.Task) {
pane.ClearList()
pane.tasks = tasks
@@ -103,6 +107,7 @@ func (pane *TaskPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
return event
}
// LoadProjectTasks loads tasks of a project in taskPane
func (pane *TaskPane) LoadProjectTasks(project model.Project) {
var tasks []model.Task
var err error
@@ -117,6 +122,7 @@ func (pane *TaskPane) LoadProjectTasks(project model.Project) {
pane.AddItem(pane.newTask, 1, 0, false)
}
// ActivateTask marks a task as currently active and loads in TaskDetailPane
func (pane *TaskPane) ActivateTask(idx int) {
removeThirdCol()
pane.activeTask = &pane.tasks[idx]
@@ -126,6 +132,7 @@ func (pane *TaskPane) ActivateTask(idx int) {
}
// ClearCompletedTasks removes tasks from current list that are in completed state
func (pane *TaskPane) ClearCompletedTasks() {
count := 0
for i, task := range pane.tasks {