Stopped creating Project and Task with blank name

This commit is contained in:
Anis Ahmad
2020-06-06 12:57:29 +06:00
parent 032a53d1c3
commit 62d04b2963
11 changed files with 31 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ The CLI Task Manager for Geeks :technologist:
=========
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/ajaxray/geek-life)](https://goreportcard.com/report/github.com/ajaxray/geek-life)
[![Go Report Card](https://goreportcard.com/badge/github.com/ajaxray/geek-life?version=latest)](https://goreportcard.com/report/github.com/ajaxray/geek-life)
:superhero: Developer / DevOps / Sysadmin? A command line hero?
@@ -19,7 +19,7 @@ Click to see it moving (GIF)
### :zap: Highlights
### :crystal_ball: Highlights
- For ninjas - do things faster with keyboard shortcuts
- Markdown lovers, feel at :house:! You'll see markdown everywhere.
@@ -28,7 +28,7 @@ Click to see it moving (GIF)
- Task note editor with markdown syntax highlighting<sup>2</sup>
- Full mouse support
### :compass: Roadmap
### :dart: Roadmap
- [x] Create Project
- [x] Delete Project
- [ ] Edit Project
@@ -50,11 +50,12 @@ Click to see it moving (GIF)
- [ ] [Havitica](https://habitica.com/)<sup>3</sup> integration - Use it as Habitica client or use Habitica for cloud backup
- [ ] Time tracking
### :arrow_down: Ready for action (installing and running)
### :rocket: Ready for action (installing and running)
It's just a single binary file, **no external dependencies**.
Just download the appropriate version of [executable from latest release](https://github.com/ajaxray/geek-life/releases) for your OS.
Then rename and give it permission to execute. For example
Then rename and give it permission to execute.
For example:
```bash
mv geek-life_linux-amd64 geek-life
sudo chmod +x geek-life
@@ -67,7 +68,7 @@ sudo mv geek-life /usr/local/bin/geek-life
geek-life
```
Done! Manage your tasks your way!
Done! *Manage your tasks your way!*
## :keyboard: Keyboard shortcuts
@@ -113,9 +114,9 @@ If you fix a bug or want to add/improve a feature,
and it's aligned with the focus (merging with ease) of this app,
I will be glad to accept your PR. :)
## :question: You may ask...
## :bulb: You may ask...
#### Where is the data stored? Can I change the location?
#### :question: Where is the data stored? Can I change the location?
By default, it will try to create a db file in you home directory.
@@ -126,7 +127,7 @@ In that case, just mention `DB_FILE` as an environment variable.
DB_FILE=~/dropbox/geek-life/default.db geek-life
```
#### How can I suggest a feature?
#### :question: How can I suggest a feature?
Just [post an issue](https://github.com/ajaxray/geek-life/issues/new) describing your desired feature/enhancement
and select `feature` label.

View File

@@ -42,7 +42,7 @@ func main() {
taskRepo = repo.NewTaskRepository(db)
titleText := tview.NewTextView().SetText("[lime::b]Geek-life [::-]- Task Manager for geeks!").SetDynamicColors(true)
cloudStatus := tview.NewTextView().SetText("[::d]Version: 0.0.1").SetTextAlign(tview.AlignRight).SetDynamicColors(true)
cloudStatus := tview.NewTextView().SetText("[::d]Version: 0.0.3").SetTextAlign(tview.AlignRight).SetDynamicColors(true)
titleBar := tview.NewFlex().
AddItem(titleText, 0, 2, false).

View File

@@ -25,8 +25,8 @@ func prepareProjectDetail() {
func deleteCurrentProject() {
if currentProject != nil && projectRepo.Delete(currentProject) == nil {
for i, _ := range tasks {
taskRepo.Delete(&tasks[i])
for i := range tasks {
_ = taskRepo.Delete(&tasks[i])
}
showMessage("Removed Project: " + currentProject.Title)

View File

@@ -17,6 +17,11 @@ func prepareProjectPane() {
SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyEnter:
if len(newProject.GetText()) < 3 {
showMessage("[red::]Project name should be at least 3 character")
return
}
project, err := projectRepo.Create(newProject.GetText(), "")
if err != nil {
showMessage("[red::]Failed to create Project:" + err.Error())

View File

@@ -26,6 +26,11 @@ func prepareTaskPane() {
SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyEnter:
if len(newTask.GetText()) < 3 {
showMessage("[red::]Task title should be at least 3 character")
return
}
task, err := taskRepo.Create(*currentProject, newTask.GetText(), "", "", 0)
if err != nil {
showMessage("[red::]Could not create Task:" + err.Error())

View File

@@ -40,9 +40,9 @@ func makeLightTextInput(placeholder string) *tview.InputField {
func parseDateInputOrCurrent(inputText string) time.Time {
if date, err := time.Parse(dateLayoutISO, inputText); err == nil {
return date
} else {
return time.Now()
}
return time.Now()
}
func showMessage(text string) {

View File

@@ -1,5 +1,6 @@
package model
// Project represent a collection of related tasks (tags of Habitica)
type Project struct {
ID int64 `storm:"id,increment",json:"id"`
Title string `storm:"index",json:"title"`

View File

@@ -1,5 +1,6 @@
package model
// Task represent a task - the building block of the TaskManager app
type Task struct {
ID int64 `storm:"id,increment",json:"id"`
ProjectID int64 `storm:"index",json:"project_id"`

View File

@@ -2,6 +2,7 @@ package repository
import "github.com/ajaxray/geek-life/model"
// ProjectRepository interface defines methods of project data accessor
type ProjectRepository interface {
GetAll() ([]model.Project, error)
GetByID(id int64) (model.Project, error)

View File

@@ -6,6 +6,7 @@ import (
"github.com/ajaxray/geek-life/model"
)
// TaskRepository interface defines methods of task data accessor
type TaskRepository interface {
GetAll() ([]model.Task, error)
GetAllByProject(project model.Project) ([]model.Task, error)

View File

@@ -11,6 +11,7 @@ import (
// gotenv.Load()
// }
// GetEnvInt finds an ENV variable and converts to int, otherwise return default value
func GetEnvInt(key string, defaultVal int) int {
if v, ok := os.LookupEnv(key); ok {
if i, err := strconv.Atoi(v); err == nil {
@@ -25,6 +26,7 @@ func GetEnvInt(key string, defaultVal int) int {
return defaultVal
}
// GetEnvStr finds an ENV variable, otherwise return default value
func GetEnvStr(key, defaultVal string) string {
if v, ok := os.LookupEnv(key); ok {
return v