From 16237a89a47207b97b90fffb1932e591a5f4b220 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sat, 27 Feb 2021 16:47:57 +0100 Subject: [PATCH] add favorite system and other small tweaks and fixes. --- api/project.go | 4 ++ database/postgres/project.go | 10 ++-- ...0227154406_add_project_column_favorite.sql | 11 +++++ models/project.go | 6 +++ svelte-ui/src/clients/stufflog.ts | 5 +- svelte-ui/src/components/Boi.svelte | 10 +++- .../src/components/DateRangeSelect.svelte | 5 +- svelte-ui/src/components/FocusHandler.svelte | 7 +-- svelte-ui/src/components/ParentEntry.svelte | 1 + svelte-ui/src/components/ProjectEntry.svelte | 46 ++++++++++++++++++- svelte-ui/src/components/ProjectSelect.svelte | 4 +- svelte-ui/src/components/QuestLog.svelte | 5 ++ svelte-ui/src/forms/LogForm.svelte | 2 +- svelte-ui/src/forms/ProjectForm.svelte | 17 +++++-- svelte-ui/src/models/project.ts | 4 ++ svelte-ui/src/pages/FrontPage.svelte | 20 ++++++-- svelte-ui/src/pages/LogsPage.svelte | 2 +- svelte-ui/src/pages/QLPage.svelte | 5 -- svelte-ui/src/stores/markStale.ts | 19 ++++---- svelte-ui/src/stores/project.ts | 3 +- 20 files changed, 147 insertions(+), 39 deletions(-) create mode 100644 migrations/postgres/20210227154406_add_project_column_favorite.sql diff --git a/api/project.go b/api/project.go index ac412b2..61c0647 100644 --- a/api/project.go +++ b/api/project.go @@ -23,6 +23,10 @@ func Project(g *gin.RouterGroup, db database.Database) { if setting := c.Query("expiring"); setting != "" { filter.Expiring = setting == "true" } + if setting := c.Query("favorite"); setting != "" { + favorite := setting == "true" + filter.Favorite = &favorite + } return l.ListProjects(c, filter) })) diff --git a/database/postgres/project.go b/database/postgres/project.go index 7ba1a93..ae02e24 100644 --- a/database/postgres/project.go +++ b/database/postgres/project.go @@ -39,6 +39,9 @@ func (r *projectRepository) List(ctx context.Context, filter models.ProjectFilte if filter.Expiring { sq = sq.Where("end_time IS NOT NULL") } + if filter.Favorite != nil { + sq = sq.Where(squirrel.Eq{"favorite": *filter.Favorite}) + } sq = sq.OrderBy("active", "created_time DESC") @@ -62,9 +65,9 @@ func (r *projectRepository) List(ctx context.Context, filter models.ProjectFilte func (r *projectRepository) Insert(ctx context.Context, project models.Project) error { _, err := r.db.NamedExecContext(ctx, ` INSERT INTO project( - project_id, user_id, name, description, icon, active, created_time, end_time, status_tag + project_id, user_id, name, description, icon, active, created_time, end_time, status_tag, favorite ) VALUES ( - :project_id, :user_id, :name, :description, :icon, :active, :created_time, :end_time, :status_tag + :project_id, :user_id, :name, :description, :icon, :active, :created_time, :end_time, :status_tag, :favorite ) `, &project) if err != nil { @@ -82,7 +85,8 @@ func (r *projectRepository) Update(ctx context.Context, project models.Project) icon = :icon, active = :active, end_time = :end_time, - status_tag = :status_tag + status_tag = :status_tag, + favorite = :favorite WHERE project_id=:project_id `, &project) if err != nil { diff --git a/migrations/postgres/20210227154406_add_project_column_favorite.sql b/migrations/postgres/20210227154406_add_project_column_favorite.sql new file mode 100644 index 0000000..7928450 --- /dev/null +++ b/migrations/postgres/20210227154406_add_project_column_favorite.sql @@ -0,0 +1,11 @@ +-- +goose Up +-- +goose StatementBegin +ALTER TABLE project + ADD COLUMN favorite BOOLEAN NOT NULL DEFAULT false; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +ALTER TABLE project + DROP COLUMN favorite; +-- +goose StatementEnd diff --git a/models/project.go b/models/project.go index b8fdd76..0e398df 100644 --- a/models/project.go +++ b/models/project.go @@ -15,6 +15,7 @@ type Project struct { CreatedTime time.Time `json:"createdTime" db:"created_time"` EndTime *time.Time `json:"endTime" db:"end_time"` StatusTag *string `json:"statusTag" db:"status_tag"` + Favorite bool `json:"favorite" db:"favorite"` } func (project *Project) Update(update ProjectUpdate) { @@ -43,6 +44,9 @@ func (project *Project) Update(update ProjectUpdate) { if update.ClearStatusTag { project.StatusTag = nil } + if update.Favorite != nil { + project.Favorite = *update.Favorite + } } type ProjectUpdate struct { @@ -54,6 +58,7 @@ type ProjectUpdate struct { ClearEndTime bool `json:"clearEndTime"` StatusTag *string `json:"statusTag"` ClearStatusTag bool `json:"clearStatusTag"` + Favorite *bool `json:"favorite"` } type ProjectResult struct { @@ -64,6 +69,7 @@ type ProjectResult struct { type ProjectFilter struct { UserID string Active *bool + Favorite *bool Expiring bool IDs []string } diff --git a/svelte-ui/src/clients/stufflog.ts b/svelte-ui/src/clients/stufflog.ts index 5f868e8..6645520 100644 --- a/svelte-ui/src/clients/stufflog.ts +++ b/svelte-ui/src/clients/stufflog.ts @@ -60,7 +60,7 @@ export class StufflogClient { return data.project; } - async listProjects({active, expiring}: ProjectFilter): Promise { + async listProjects({active, expiring, favorite}: ProjectFilter): Promise { let queries = []; if (active != null) { queries.push(`active=${active}`); @@ -68,6 +68,9 @@ export class StufflogClient { if (expiring != null) { queries.push(`expiring=${expiring}`); } + if (favorite != null) { + queries.push(`favorite=${favorite}`) + } const query = queries.length > 0 ? `?${queries.join("&")}` : ""; diff --git a/svelte-ui/src/components/Boi.svelte b/svelte-ui/src/components/Boi.svelte index 6bd78eb..7f2b117 100644 --- a/svelte-ui/src/components/Boi.svelte +++ b/svelte-ui/src/components/Boi.svelte @@ -6,6 +6,7 @@ export let open: ModalData = {name: "none"}; export let disabled: boolean = false; export let compact: boolean = false; + export let compacter: boolean = false; export let tiny: boolean = false; const dispatch = createEventDispatcher(); @@ -19,7 +20,7 @@ } -
+
\ No newline at end of file diff --git a/svelte-ui/src/components/ProjectSelect.svelte b/svelte-ui/src/components/ProjectSelect.svelte index abde2ff..85fb3e5 100644 --- a/svelte-ui/src/components/ProjectSelect.svelte +++ b/svelte-ui/src/components/ProjectSelect.svelte @@ -1,7 +1,5 @@