This commit is contained in:
+20
@@ -85,6 +85,16 @@ func Goal(g *gin.RouterGroup, db database.Database) {
|
|||||||
}
|
}
|
||||||
goal.GroupID = group.ID
|
goal.GroupID = group.ID
|
||||||
|
|
||||||
|
if goal.ItemID != nil {
|
||||||
|
item, err := l.FindItem(c.Request.Context(), *goal.ItemID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, slerrors.BadRequest("Item could not be found.")
|
||||||
|
}
|
||||||
|
if item.GroupID != goal.GroupID {
|
||||||
|
return nil, slerrors.BadRequest("Item is not in group.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = db.Goals().Insert(c.Request.Context(), goal)
|
err = db.Goals().Insert(c.Request.Context(), goal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -117,6 +127,16 @@ func Goal(g *gin.RouterGroup, db database.Database) {
|
|||||||
return nil, slerrors.BadRequest("Start time must be before end time.")
|
return nil, slerrors.BadRequest("Start time must be before end time.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if goal.ItemID != nil && update.ItemID != nil {
|
||||||
|
item, err := l.FindItem(c.Request.Context(), *goal.ItemID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, slerrors.BadRequest("Item could not be found.")
|
||||||
|
}
|
||||||
|
if item.GroupID != goal.GroupID {
|
||||||
|
return nil, slerrors.BadRequest("Item is not in group.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = db.Goals().Update(c.Request.Context(), goal.Goal)
|
err = db.Goals().Update(c.Request.Context(), goal.Goal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
+27
@@ -66,6 +66,19 @@ func Log(g *gin.RouterGroup, db database.Database) {
|
|||||||
} else {
|
} else {
|
||||||
log.LoggedTime = log.LoggedTime.UTC()
|
log.LoggedTime = log.LoggedTime.UTC()
|
||||||
}
|
}
|
||||||
|
if log.ItemAmount < 0 {
|
||||||
|
return nil, slerrors.BadRequest("Invalid item amount (min: 0).")
|
||||||
|
}
|
||||||
|
if log.SecondaryItemAmount < 0 {
|
||||||
|
return nil, slerrors.BadRequest("Invalid secondary item amount (min: 0).")
|
||||||
|
}
|
||||||
|
|
||||||
|
if log.SecondaryItemID != nil {
|
||||||
|
_, err := l.FindItem(c.Request.Context(), *log.SecondaryItemID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, slerrors.BadRequest("Item could not be found.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = db.Logs().Insert(c.Request.Context(), log)
|
err = db.Logs().Insert(c.Request.Context(), log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,6 +104,20 @@ func Log(g *gin.RouterGroup, db database.Database) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Update(update)
|
log.Update(update)
|
||||||
|
|
||||||
|
if log.SecondaryItemID != nil && update.SecondaryItemID != nil {
|
||||||
|
_, err := l.FindItem(c.Request.Context(), *log.SecondaryItemID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, slerrors.BadRequest("Item could not be found.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if log.ItemAmount < 0 {
|
||||||
|
return nil, slerrors.BadRequest("Invalid item amount (min: 0).")
|
||||||
|
}
|
||||||
|
if log.SecondaryItemAmount < 0 {
|
||||||
|
return nil, slerrors.BadRequest("Invalid secondary item amount (min: 0).")
|
||||||
|
}
|
||||||
|
|
||||||
err = db.Logs().Update(c.Request.Context(), log.Log)
|
err = db.Logs().Update(c.Request.Context(), log.Log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func main() {
|
|||||||
|
|
||||||
server := gin.New()
|
server := gin.New()
|
||||||
if useDummyUuid == "yes" {
|
if useDummyUuid == "yes" {
|
||||||
|
log.Println("Using dummy UUID")
|
||||||
server.Use(auth.DummyMiddleware(dummyUuid))
|
server.Use(auth.DummyMiddleware(dummyUuid))
|
||||||
} else {
|
} else {
|
||||||
server.Use(auth.TrustingJwtParserMiddleware())
|
server.Use(auth.TrustingJwtParserMiddleware())
|
||||||
|
|||||||
@@ -73,9 +73,11 @@ func (r *goalRepository) List(ctx context.Context, filter models.GoalFilter) ([]
|
|||||||
func (r *goalRepository) Insert(ctx context.Context, goal models.Goal) error {
|
func (r *goalRepository) Insert(ctx context.Context, goal models.Goal) error {
|
||||||
_, err := r.db.NamedExecContext(ctx, `
|
_, err := r.db.NamedExecContext(ctx, `
|
||||||
INSERT INTO goal (
|
INSERT INTO goal (
|
||||||
goal_id, user_id, group_id, amount, start_time, end_time, name, description
|
goal_id, user_id, group_id, amount, start_time, end_time, name, description,
|
||||||
|
composition_mode, unweighted, item_id
|
||||||
) VALUES (
|
) VALUES (
|
||||||
:goal_id, :user_id, :group_id, :amount, :start_time, :end_time, :name, :description
|
:goal_id, :user_id, :group_id, :amount, :start_time, :end_time, :name, :description,
|
||||||
|
:composition_mode, :unweighted, :item_id
|
||||||
)
|
)
|
||||||
`, &goal)
|
`, &goal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -92,7 +94,10 @@ func (r *goalRepository) Update(ctx context.Context, goal models.Goal) error {
|
|||||||
start_time=:start_time,
|
start_time=:start_time,
|
||||||
end_time=:end_time,
|
end_time=:end_time,
|
||||||
name=:name,
|
name=:name,
|
||||||
description=:description
|
description=:description,
|
||||||
|
composition_mode=:composition_mode,
|
||||||
|
unweighted=:unweighted,
|
||||||
|
item_id=:item_id
|
||||||
WHERE goal_id=:goal_id
|
WHERE goal_id=:goal_id
|
||||||
`, &goal)
|
`, &goal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ func (r *logRepository) List(ctx context.Context, filter models.LogFilter) ([]*m
|
|||||||
sq = sq.Where(squirrel.Eq{"task_id": filter.TaskIDs})
|
sq = sq.Where(squirrel.Eq{"task_id": filter.TaskIDs})
|
||||||
}
|
}
|
||||||
if len(filter.ItemIDs) > 0 {
|
if len(filter.ItemIDs) > 0 {
|
||||||
sq = sq.Where(squirrel.Eq{"item_id": filter.ItemIDs})
|
sq = sq.Where(squirrel.Or{
|
||||||
|
squirrel.Eq{"item_id": filter.ItemIDs},
|
||||||
|
squirrel.Eq{"secondary_item_id": filter.ItemIDs},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if filter.MinTime != nil {
|
if filter.MinTime != nil {
|
||||||
sq = sq.Where(squirrel.GtOrEq{
|
sq = sq.Where(squirrel.GtOrEq{
|
||||||
@@ -69,9 +72,9 @@ func (r *logRepository) List(ctx context.Context, filter models.LogFilter) ([]*m
|
|||||||
func (r *logRepository) Insert(ctx context.Context, log models.Log) error {
|
func (r *logRepository) Insert(ctx context.Context, log models.Log) error {
|
||||||
_, err := r.db.NamedExecContext(ctx, `
|
_, err := r.db.NamedExecContext(ctx, `
|
||||||
INSERT INTO log (
|
INSERT INTO log (
|
||||||
log_id, user_id, task_id, item_id, logged_time, description
|
log_id, user_id, task_id, item_id, logged_time, description, item_amount, secondary_item_id, secondary_item_amount
|
||||||
) VALUES (
|
) VALUES (
|
||||||
:log_id, :user_id, :task_id, :item_id, :logged_time, :description
|
:log_id, :user_id, :task_id, :item_id, :logged_time, :description, :item_amount, :secondary_item_id, :secondary_item_amount
|
||||||
)
|
)
|
||||||
`, &log)
|
`, &log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,7 +88,10 @@ func (r *logRepository) Update(ctx context.Context, log models.Log) error {
|
|||||||
_, err := r.db.NamedExecContext(ctx, `
|
_, err := r.db.NamedExecContext(ctx, `
|
||||||
UPDATE log SET
|
UPDATE log SET
|
||||||
logged_time=:logged_time,
|
logged_time=:logged_time,
|
||||||
description=:description
|
description=:description,
|
||||||
|
item_amount=:item_amount,
|
||||||
|
secondary_item_id=:secondary_item_id,
|
||||||
|
secondary_item_amount=:secondary_item_amount
|
||||||
WHERE log_id=:log_id
|
WHERE log_id=:log_id
|
||||||
`, &log)
|
`, &log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE goal
|
||||||
|
ADD COLUMN composition_mode TEXT NOT NULL DEFAULT 'item',
|
||||||
|
ADD COLUMN unweighted BOOL NOT NULL DEFAULT false,
|
||||||
|
ADD COLUMN item_id CHAR(16) DEFAULT NULL;
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE goal
|
||||||
|
DROP COLUMN composition_mode,
|
||||||
|
DROP COLUMN unweighted,
|
||||||
|
DROP COLUMN item_id;
|
||||||
|
-- +goose StatementEnd
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE log
|
||||||
|
ADD COLUMN item_amount INT NOT NULL DEFAULT 1,
|
||||||
|
ADD COLUMN secondary_item_id CHAR(16) DEFAULT NULL,
|
||||||
|
ADD COLUMN secondary_item_amount INT NOT NULL DEFAULT 0;
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE log
|
||||||
|
DROP COLUMN item_amount,
|
||||||
|
DROP COLUMN secondary_item_id,
|
||||||
|
DROP COLUMN secondary_item_amount;
|
||||||
|
-- +goose StatementEnd
|
||||||
+32
-13
@@ -6,14 +6,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Goal struct {
|
type Goal struct {
|
||||||
ID string `json:"id" db:"goal_id"`
|
ID string `json:"id" db:"goal_id"`
|
||||||
UserID string `json:"-" db:"user_id"`
|
UserID string `json:"-" db:"user_id"`
|
||||||
GroupID string `json:"groupId" db:"group_id"`
|
GroupID string `json:"groupId" db:"group_id"`
|
||||||
StartTime time.Time `json:"startTime" db:"start_time"`
|
ItemID *string `json:"itemId" db:"item_id"`
|
||||||
EndTime time.Time `json:"endTime" db:"end_time"`
|
StartTime time.Time `json:"startTime" db:"start_time"`
|
||||||
Amount int `json:"amount" db:"amount"`
|
EndTime time.Time `json:"endTime" db:"end_time"`
|
||||||
Name string `json:"name" db:"name"`
|
Amount int `json:"amount" db:"amount"`
|
||||||
Description string `json:"description" db:"description"`
|
Unweighted bool `json:"unweighted" db:"unweighted"`
|
||||||
|
Name string `json:"name" db:"name"`
|
||||||
|
Description string `json:"description" db:"description"`
|
||||||
|
CompositionMode string `json:"compositionMode" db:"composition_mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (goal *Goal) Update(update GoalUpdate) {
|
func (goal *Goal) Update(update GoalUpdate) {
|
||||||
@@ -32,14 +35,30 @@ func (goal *Goal) Update(update GoalUpdate) {
|
|||||||
if update.Description != nil {
|
if update.Description != nil {
|
||||||
goal.Description = *update.Description
|
goal.Description = *update.Description
|
||||||
}
|
}
|
||||||
|
if update.Unweighted != nil {
|
||||||
|
goal.Unweighted = *update.Unweighted
|
||||||
|
}
|
||||||
|
if update.CompositionMode != nil {
|
||||||
|
goal.CompositionMode = *update.CompositionMode
|
||||||
|
}
|
||||||
|
if update.ItemID != nil {
|
||||||
|
goal.ItemID = update.ItemID
|
||||||
|
}
|
||||||
|
if update.ClearItemID {
|
||||||
|
goal.ItemID = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type GoalUpdate struct {
|
type GoalUpdate struct {
|
||||||
StartTime *time.Time `json:"startTime"`
|
StartTime *time.Time `json:"startTime"`
|
||||||
EndTime *time.Time `json:"endTime"`
|
EndTime *time.Time `json:"endTime"`
|
||||||
Amount *int `json:"amount"`
|
Amount *int `json:"amount"`
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
|
ItemID *string `json:"itemId"`
|
||||||
|
Unweighted *bool `json:"unweighted"`
|
||||||
|
CompositionMode *string `json:"compositionMode"`
|
||||||
|
ClearItemID bool `json:"clearItemID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GoalResult struct {
|
type GoalResult struct {
|
||||||
|
|||||||
+43
-10
@@ -6,12 +6,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Log struct {
|
type Log struct {
|
||||||
ID string `json:"id" db:"log_id"`
|
ID string `json:"id" db:"log_id"`
|
||||||
UserID string `json:"-" db:"user_id"`
|
UserID string `json:"-" db:"user_id"`
|
||||||
TaskID string `json:"taskId" db:"task_id"`
|
TaskID string `json:"taskId" db:"task_id"`
|
||||||
ItemID string `json:"itemId" db:"item_id"`
|
ItemID string `json:"itemId" db:"item_id"`
|
||||||
LoggedTime time.Time `json:"loggedTime" db:"logged_time"`
|
ItemAmount int `json:"itemAmount" db:"item_amount"`
|
||||||
Description string `json:"description" db:"description"`
|
SecondaryItemID *string `json:"secondaryItemId" db:"secondary_item_id"`
|
||||||
|
SecondaryItemAmount int `json:"secondaryItemAmount" db:"secondary_item_amount"`
|
||||||
|
LoggedTime time.Time `json:"loggedTime" db:"logged_time"`
|
||||||
|
Description string `json:"description" db:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (log *Log) Amount(itemID string) int {
|
||||||
|
result := 0
|
||||||
|
|
||||||
|
if log.ItemID == itemID {
|
||||||
|
result += log.ItemAmount
|
||||||
|
}
|
||||||
|
if log.SecondaryItemID != nil && *log.SecondaryItemID == itemID {
|
||||||
|
result += log.SecondaryItemAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (log *Log) Update(update LogUpdate) {
|
func (log *Log) Update(update LogUpdate) {
|
||||||
@@ -21,17 +37,34 @@ func (log *Log) Update(update LogUpdate) {
|
|||||||
if update.Description != nil {
|
if update.Description != nil {
|
||||||
log.Description = *update.Description
|
log.Description = *update.Description
|
||||||
}
|
}
|
||||||
|
if update.ItemAmount != nil {
|
||||||
|
log.ItemAmount = *update.ItemAmount
|
||||||
|
}
|
||||||
|
if update.SecondaryItemID != nil {
|
||||||
|
log.SecondaryItemID = update.SecondaryItemID
|
||||||
|
}
|
||||||
|
if update.ClearSecondaryItem {
|
||||||
|
log.SecondaryItemID = nil
|
||||||
|
}
|
||||||
|
if update.SecondaryItemAmount != nil {
|
||||||
|
log.SecondaryItemAmount = *update.SecondaryItemAmount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogUpdate struct {
|
type LogUpdate struct {
|
||||||
LoggedTime *time.Time `json:"loggedTime"`
|
LoggedTime *time.Time `json:"loggedTime"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
|
ItemAmount *int `json:"itemAmount"`
|
||||||
|
SecondaryItemID *string `json:"secondaryItemId"`
|
||||||
|
SecondaryItemAmount *int `json:"secondaryItemAmount"`
|
||||||
|
ClearSecondaryItem bool `json:"clearSecondaryItem"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogResult struct {
|
type LogResult struct {
|
||||||
Log
|
Log
|
||||||
Task *Task `json:"task"`
|
Task *Task `json:"task"`
|
||||||
Item *Item `json:"item"`
|
Item *Item `json:"item"`
|
||||||
|
SecondaryItem *Item `json:"secondaryItem"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogFilter struct {
|
type LogFilter struct {
|
||||||
|
|||||||
+43
-15
@@ -128,6 +128,9 @@ func (l *Loader) FindLog(ctx context.Context, id string) (*models.LogResult, err
|
|||||||
|
|
||||||
result.Task, _ = l.DB.Tasks().Find(ctx, id)
|
result.Task, _ = l.DB.Tasks().Find(ctx, id)
|
||||||
result.Item, _ = l.DB.Items().Find(ctx, log.ItemID)
|
result.Item, _ = l.DB.Items().Find(ctx, log.ItemID)
|
||||||
|
if log.SecondaryItemID != nil {
|
||||||
|
result.SecondaryItem, _ = l.DB.Items().Find(ctx, *log.SecondaryItemID)
|
||||||
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
@@ -144,6 +147,9 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
|||||||
for _, log := range logs {
|
for _, log := range logs {
|
||||||
taskIDs.Add(log.TaskID)
|
taskIDs.Add(log.TaskID)
|
||||||
itemIDs.Add(log.ItemID)
|
itemIDs.Add(log.ItemID)
|
||||||
|
if log.SecondaryItemID != nil {
|
||||||
|
itemIDs.Add(*log.SecondaryItemID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
|
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
|
||||||
UserID: auth.UserID(ctx),
|
UserID: auth.UserID(ctx),
|
||||||
@@ -177,7 +183,9 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
|||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if item.ID == log.ItemID {
|
if item.ID == log.ItemID {
|
||||||
results[i].Item = item
|
results[i].Item = item
|
||||||
break
|
}
|
||||||
|
if log.SecondaryItemID != nil && item.ID == *log.SecondaryItemID {
|
||||||
|
results[i].SecondaryItem = item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,16 +510,22 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
|
|||||||
MinTime: &goal.StartTime,
|
MinTime: &goal.StartTime,
|
||||||
MaxTime: &goal.EndTime,
|
MaxTime: &goal.EndTime,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Get tasks
|
// Get tasks
|
||||||
taskIDs := make([]string, 0, len(result.Logs))
|
taskIDs := stringset.New()
|
||||||
for _, log := range logs {
|
for _, log := range logs {
|
||||||
taskIDs = append(taskIDs, log.TaskID)
|
taskIDs.Add(log.TaskID)
|
||||||
}
|
}
|
||||||
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
|
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
IDs: taskIDs,
|
IDs: taskIDs.Strings(),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Apply logs
|
// Apply logs
|
||||||
result.Logs = make([]*models.LogResult, 0, len(logs))
|
result.Logs = make([]*models.LogResult, 0, len(logs))
|
||||||
@@ -523,20 +537,34 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
|
|||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if task.ID == log.TaskID {
|
if task.ID == log.TaskID {
|
||||||
resultLog.Task = task
|
resultLog.Task = task
|
||||||
|
|
||||||
for _, item := range result.Items {
|
|
||||||
if task.ItemID == item.ID {
|
|
||||||
item.CompletedAmount += 1
|
|
||||||
result.CompletedAmount += item.GroupWeight
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
resultLog.Item = &item.Item
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, item := range result.Items {
|
||||||
|
amount := log.Amount(item.ID)
|
||||||
|
if amount > 0 && (goal.ItemID == nil || *goal.ItemID == item.ID) {
|
||||||
|
item.CompletedAmount += amount
|
||||||
|
|
||||||
|
if goal.Unweighted {
|
||||||
|
result.CompletedAmount += amount
|
||||||
|
} else {
|
||||||
|
result.CompletedAmount += amount * item.GroupWeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.ID == log.ItemID {
|
||||||
|
resultLog.Item = &item.Item
|
||||||
|
if log.SecondaryItemID == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if log.SecondaryItemID != nil && item.ID == *log.SecondaryItemID {
|
||||||
|
resultLog.SecondaryItem = &item.Item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result.Logs = append(result.Logs, resultLog)
|
result.Logs = append(result.Logs, resultLog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { GroupResult } from "../models/group";
|
||||||
|
|
||||||
|
export let value = "";
|
||||||
|
export let name = "";
|
||||||
|
export let disabled = false;
|
||||||
|
export let optional = false;
|
||||||
|
export let optionalLabel = "None";
|
||||||
|
export let group: GroupResult = null;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (group != null && !group.items.find(t => t.id === value)) {
|
||||||
|
if (optional) {
|
||||||
|
value = "";
|
||||||
|
} else {
|
||||||
|
value = group.items[0]?.id || "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<select name={name} bind:value={value} disabled={disabled || group == null || group.items.length === 0}>
|
||||||
|
{#if optional}
|
||||||
|
<option value={""} selected={"" === value}>{optionalLabel}</option>
|
||||||
|
{/if}
|
||||||
|
{#if group != null}
|
||||||
|
{#each group.items as item (item.id)}
|
||||||
|
<option value={item.id} selected={item.id === value}>{item.name} ({item.groupWeight})</option>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</select>
|
||||||
@@ -3,9 +3,14 @@
|
|||||||
import Icon from "./Icon.svelte";
|
import Icon from "./Icon.svelte";
|
||||||
|
|
||||||
export let item: Item = null;
|
export let item: Item = null;
|
||||||
|
export let amount: number = null;
|
||||||
|
export let noPadding: boolean = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="item">
|
<div class="item" class:noPadding>
|
||||||
|
{#if amount != null}
|
||||||
|
<div class="item-amount">{amount}x</div>
|
||||||
|
{/if}
|
||||||
<div class="item-icon">
|
<div class="item-icon">
|
||||||
<Icon name={item.icon} />
|
<Icon name={item.icon} />
|
||||||
</div>
|
</div>
|
||||||
@@ -22,13 +27,21 @@
|
|||||||
margin-bottom: 0em;
|
margin-bottom: 0em;
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
}
|
}
|
||||||
div.item a {
|
a {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
div.item div.item-icon {
|
div.item-icon {
|
||||||
padding: 0.25em 0.5ch 0.25em 0;
|
padding: 0.25em 0.5ch 0.25em 0;
|
||||||
}
|
}
|
||||||
div.item div.item-name {
|
div.item-name {
|
||||||
padding: 0.125em;
|
padding: 0.125em;
|
||||||
}
|
}
|
||||||
|
div.item-amount {
|
||||||
|
padding: 0.125em;
|
||||||
|
padding-right: 1ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.item.noPadding {
|
||||||
|
margin-top: 0em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
export let value = "";
|
export let value = "";
|
||||||
export let name = "";
|
export let name = "";
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
|
export let optional = false;
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if ($groupStore.stale && !$groupStore.loading) {
|
if ($groupStore.stale && !$groupStore.loading) {
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if ($groupStore.groups.length > 0 && value === "") {
|
if ($groupStore.groups.length > 0 && value === "" && !optional) {
|
||||||
const nonEmpty = $groupStore.groups.find(g => g.items.length > 0);
|
const nonEmpty = $groupStore.groups.find(g => g.items.length > 0);
|
||||||
if (nonEmpty != null) {
|
if (nonEmpty != null) {
|
||||||
value = nonEmpty.items[0].id;
|
value = nonEmpty.items[0].id;
|
||||||
@@ -22,6 +23,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<select name={name} bind:value={value} disabled={disabled || $groupStore.loading}>
|
<select name={name} bind:value={value} disabled={disabled || $groupStore.loading}>
|
||||||
|
{#if optional}
|
||||||
|
<option value={""} selected={"" === value}>None</option>
|
||||||
|
{/if}
|
||||||
{#each $groupStore.groups as group (group.id)}
|
{#each $groupStore.groups as group (group.id)}
|
||||||
<optgroup label={group.name}>
|
<optgroup label={group.name}>
|
||||||
{#each group.items as item (item.id)}
|
{#each group.items as item (item.id)}
|
||||||
|
|||||||
@@ -21,7 +21,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ChildEntry entry={log}>
|
<ChildEntry entry={log}>
|
||||||
<ItemLink item={log.item} />
|
<ItemLink amount={log.itemAmount} item={log.item} />
|
||||||
|
{#if log.secondaryItem != null}
|
||||||
|
<ItemLink noPadding amount={log.secondaryItemAmount} item={log.secondaryItem} />
|
||||||
|
{/if}
|
||||||
<OptionRow>
|
<OptionRow>
|
||||||
<Option open={mdLogEdit}>Edit Log</Option>
|
<Option open={mdLogEdit}>Edit Log</Option>
|
||||||
<Option open={mdLogDelete}>Delete Log</Option>
|
<Option open={mdLogDelete}>Delete Log</Option>
|
||||||
|
|||||||
@@ -186,9 +186,6 @@ div.modal :global(textarea:disabled) {
|
|||||||
color: #aaa;
|
color: #aaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.modal :global(input:last-of-type) {
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
div.modal :global(input.nolast) {
|
div.modal :global(input.nolast) {
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import ChildEntry from "./ChildEntry.svelte";
|
import ChildEntry from "./ChildEntry.svelte";
|
||||||
import DateSpan from "./DateSpan.svelte";
|
import DateSpan from "./DateSpan.svelte";
|
||||||
import Icon from "./Icon.svelte";
|
import Icon from "./Icon.svelte";
|
||||||
|
import ItemLink from "./ItemLink.svelte";
|
||||||
import Option from "./Option.svelte";
|
import Option from "./Option.svelte";
|
||||||
import OptionRow from "./OptionRow.svelte";
|
import OptionRow from "./OptionRow.svelte";
|
||||||
|
|
||||||
@@ -37,14 +38,7 @@
|
|||||||
{task.completedAmount} / {task.itemAmount}
|
{task.completedAmount} / {task.itemAmount}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="item">
|
<ItemLink item={task.item} />
|
||||||
<div class="item-icon">
|
|
||||||
<Icon name={task.item.icon} />
|
|
||||||
</div>
|
|
||||||
<div class="item-name">
|
|
||||||
<a href="/items#{task.item.groupId}">{task.item.name} ({task.item.groupWeight})</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<OptionRow>
|
<OptionRow>
|
||||||
{#if task.logs.length > 0}
|
{#if task.logs.length > 0}
|
||||||
<Option on:click={toggleShowLogs}>{showLogs ? "Hide Logs" : "Show Logs"}</Option>
|
<Option on:click={toggleShowLogs}>{showLogs ? "Hide Logs" : "Show Logs"}</Option>
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
import { formatFormTime, nextMonth } from "../utils/time";
|
import { formatFormTime, nextMonth } from "../utils/time";
|
||||||
import GroupSelect from "../components/GroupSelect.svelte";
|
import GroupSelect from "../components/GroupSelect.svelte";
|
||||||
import markStale from "../stores/markStale";
|
import markStale from "../stores/markStale";
|
||||||
|
import Checkbox from "../components/Checkbox.svelte";
|
||||||
|
import GroupItemSelect from "../components/GroupItemSelect.svelte";
|
||||||
|
import groupStore from "../stores/group";
|
||||||
|
import type { GroupResult } from "../models/group";
|
||||||
|
|
||||||
export let deletion = false;
|
export let deletion = false;
|
||||||
export let creation = false;
|
export let creation = false;
|
||||||
@@ -21,6 +25,9 @@
|
|||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
completedAmount: 0,
|
completedAmount: 0,
|
||||||
|
unweighted: false,
|
||||||
|
compositionMode: "item",
|
||||||
|
itemId: null,
|
||||||
group: {id: "", name: "", icon: "question", description: ""},
|
group: {id: "", name: "", icon: "question", description: ""},
|
||||||
items: [],
|
items: [],
|
||||||
logs: [],
|
logs: [],
|
||||||
@@ -37,11 +44,15 @@
|
|||||||
let description = goal.description;
|
let description = goal.description;
|
||||||
let groupId = goal.groupId;
|
let groupId = goal.groupId;
|
||||||
let amount = goal.amount;
|
let amount = goal.amount;
|
||||||
|
let unweighted = goal.unweighted;
|
||||||
|
let itemId = goal.itemId || "";
|
||||||
|
let compositionMode = goal.compositionMode;
|
||||||
let startTime = formatFormTime(goal.startTime);
|
let startTime = formatFormTime(goal.startTime);
|
||||||
let endTime = formatFormTime(goal.endTime);
|
let endTime = formatFormTime(goal.endTime);
|
||||||
|
|
||||||
let error = null;
|
let error = null;
|
||||||
let loading = false;
|
let loading = false;
|
||||||
|
let selectedGroup: GroupResult = null;
|
||||||
|
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
loading = true;
|
loading = true;
|
||||||
@@ -50,7 +61,8 @@
|
|||||||
stuffLogClient.createGoal({
|
stuffLogClient.createGoal({
|
||||||
startTime: new Date(startTime),
|
startTime: new Date(startTime),
|
||||||
endTime: new Date(endTime),
|
endTime: new Date(endTime),
|
||||||
groupId, name, description, amount,
|
itemId: itemId || null,
|
||||||
|
groupId, name, description, amount, unweighted, compositionMode
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
markStale("goal");
|
markStale("goal");
|
||||||
modalStore.close();
|
modalStore.close();
|
||||||
@@ -72,7 +84,9 @@
|
|||||||
stuffLogClient.updateGoal(goal.id, {
|
stuffLogClient.updateGoal(goal.id, {
|
||||||
startTime: new Date(startTime),
|
startTime: new Date(startTime),
|
||||||
endTime: new Date(endTime),
|
endTime: new Date(endTime),
|
||||||
name, description, amount,
|
itemId: itemId || null,
|
||||||
|
clearItemId: itemId === "",
|
||||||
|
name, description, amount, compositionMode, unweighted,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
markStale("goal");
|
markStale("goal");
|
||||||
modalStore.close();
|
modalStore.close();
|
||||||
@@ -89,6 +103,8 @@
|
|||||||
function onClose() {
|
function onClose() {
|
||||||
modalStore.close();
|
modalStore.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: selectedGroup = $groupStore.groups.find(g => g.id === groupId);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal show title="{verb} Goal" error={error} closable on:close={onClose}>
|
<Modal show title="{verb} Goal" error={error} closable on:close={onClose}>
|
||||||
@@ -99,12 +115,20 @@
|
|||||||
<textarea disabled={deletion} name="description" bind:value={description} />
|
<textarea disabled={deletion} name="description" bind:value={description} />
|
||||||
<label for="groupId">Group</label>
|
<label for="groupId">Group</label>
|
||||||
<GroupSelect disabled={!creation} name="groupId" bind:value={groupId}/>
|
<GroupSelect disabled={!creation} name="groupId" bind:value={groupId}/>
|
||||||
|
<label for="groupId">Specific Item</label>
|
||||||
|
<GroupItemSelect disabled={deletion} optional optionalLabel="Whole Group" group={selectedGroup} name="itemId" bind:value={itemId}/>
|
||||||
<label for="amount">Amount</label>
|
<label for="amount">Amount</label>
|
||||||
<input disabled={deletion} name="amount" type="number" bind:value={amount} />
|
<input disabled={deletion} name="amount" type="number" bind:value={amount} />
|
||||||
|
<label for="compositionMode">Composition Mode (does nothing right now)</label>
|
||||||
|
<select name="compositionMode" bind:value={compositionMode} disabled={deletion}>
|
||||||
|
<option value="item" selected={"item" === compositionMode}>Item</option>
|
||||||
|
<option value="task" selected={"task" === compositionMode}>Task</option>
|
||||||
|
</select>
|
||||||
<label for="startTime">Start Time</label>
|
<label for="startTime">Start Time</label>
|
||||||
<input disabled={deletion} name="startTime" type="datetime-local" bind:value={startTime} />
|
<input disabled={deletion} name="startTime" type="datetime-local" bind:value={startTime} />
|
||||||
<label for="endTime">End Time</label>
|
<label for="endTime">End Time</label>
|
||||||
<input disabled={deletion} name="endTime" type="datetime-local" bind:value={endTime} />
|
<input disabled={deletion} name="endTime" type="datetime-local" bind:value={endTime} />
|
||||||
|
<Checkbox bind:checked={unweighted} label="Unweighted (All items count as 1)" />
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import stuffLogClient from "../clients/stufflog";
|
import stuffLogClient from "../clients/stufflog";
|
||||||
import Checkbox from "../components/Checkbox.svelte";
|
import Checkbox from "../components/Checkbox.svelte";
|
||||||
|
import ItemSelect from "../components/ItemSelect.svelte";
|
||||||
import Modal from "../components/Modal.svelte";
|
import Modal from "../components/Modal.svelte";
|
||||||
import type { LogResult } from "../models/log";
|
import type { LogResult } from "../models/log";
|
||||||
import markStale from "../stores/markStale";
|
import markStale from "../stores/markStale";
|
||||||
@@ -17,8 +18,12 @@
|
|||||||
itemId: "",
|
itemId: "",
|
||||||
loggedTime: new Date().toISOString(),
|
loggedTime: new Date().toISOString(),
|
||||||
description: "",
|
description: "",
|
||||||
|
itemAmount: 1,
|
||||||
|
secondaryItemAmount: 0,
|
||||||
|
secondaryItemId: null,
|
||||||
task: null,
|
task: null,
|
||||||
item: null,
|
item: null,
|
||||||
|
secondaryItem: null,
|
||||||
}
|
}
|
||||||
let defaultMarkInactive = false;
|
let defaultMarkInactive = false;
|
||||||
let verb = "Add";
|
let verb = "Add";
|
||||||
@@ -34,6 +39,9 @@
|
|||||||
|
|
||||||
let loggedTime = formatFormTime(log.loggedTime);
|
let loggedTime = formatFormTime(log.loggedTime);
|
||||||
let description = log.description;
|
let description = log.description;
|
||||||
|
let itemAmount = log.itemAmount;
|
||||||
|
let secondaryItemId = log.secondaryItemId || "";
|
||||||
|
let secondaryItemAmount = log.secondaryItemAmount;
|
||||||
let markInactive = defaultMarkInactive;
|
let markInactive = defaultMarkInactive;
|
||||||
let error = null;
|
let error = null;
|
||||||
let loading = false;
|
let loading = false;
|
||||||
@@ -46,7 +54,8 @@
|
|||||||
stuffLogClient.createLog({
|
stuffLogClient.createLog({
|
||||||
taskId: log.task.id,
|
taskId: log.task.id,
|
||||||
loggedTime: new Date(loggedTime).toISOString(),
|
loggedTime: new Date(loggedTime).toISOString(),
|
||||||
description,
|
secondaryItemId: secondaryItemId || null,
|
||||||
|
description, itemAmount, secondaryItemAmount,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
markStale("project", "task", "goal", "log");
|
markStale("project", "task", "goal", "log");
|
||||||
|
|
||||||
@@ -74,7 +83,9 @@
|
|||||||
} else {
|
} else {
|
||||||
stuffLogClient.updateLog(log.id, {
|
stuffLogClient.updateLog(log.id, {
|
||||||
loggedTime: new Date(loggedTime).toISOString(),
|
loggedTime: new Date(loggedTime).toISOString(),
|
||||||
description,
|
secondaryItemId: secondaryItemId || null,
|
||||||
|
clearSecondaryItemId: secondaryItemId == "",
|
||||||
|
description, itemAmount, secondaryItemAmount
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
markStale("project", "task", "goal", "log");
|
markStale("project", "task", "goal", "log");
|
||||||
modalStore.close();
|
modalStore.close();
|
||||||
@@ -97,8 +108,17 @@
|
|||||||
<input disabled name="taskName" type="text" value={log.task.name} />
|
<input disabled name="taskName" type="text" value={log.task.name} />
|
||||||
<label for="loggedTime">Logged Time</label>
|
<label for="loggedTime">Logged Time</label>
|
||||||
<input disabled={deletion} name="loggedTime" type="datetime-local" bind:value={loggedTime} />
|
<input disabled={deletion} name="loggedTime" type="datetime-local" bind:value={loggedTime} />
|
||||||
|
<label for="itemAmount">Item Amount</label>
|
||||||
|
<input disabled={deletion} name="itemAmount" type="number" bind:value={itemAmount} />
|
||||||
<label for="description">Description</label>
|
<label for="description">Description</label>
|
||||||
<textarea disabled={deletion} name="description" bind:value={description} />
|
<textarea disabled={deletion} name="description" bind:value={description} />
|
||||||
|
<label for="secondaryItemId">Secondary Item</label>
|
||||||
|
<ItemSelect name="secondaryItemId" disabled={deletion} optional bind:value={secondaryItemId} />
|
||||||
|
{#if secondaryItemId != ""}
|
||||||
|
<label for="secondaryItemAmount">Secondary Item Amount</label>
|
||||||
|
<input disabled={deletion} name="secondaryItemAmount" type="number" bind:value={secondaryItemAmount} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<Checkbox disabled={deletion} bind:checked={markInactive} label="Mark task inactive/completed." />
|
<Checkbox disabled={deletion} bind:checked={markInactive} label="Mark task inactive/completed." />
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import type { LogResult } from "./log";
|
|||||||
export default interface Goal {
|
export default interface Goal {
|
||||||
id: string
|
id: string
|
||||||
groupId: string
|
groupId: string
|
||||||
|
itemId?: string
|
||||||
startTime: string
|
startTime: string
|
||||||
endTime: string
|
endTime: string
|
||||||
amount: number
|
amount: number
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
|
unweighted: boolean
|
||||||
|
compositionMode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GoalFilter {
|
export interface GoalFilter {
|
||||||
@@ -31,17 +34,24 @@ interface GoalResultItem extends Item {
|
|||||||
|
|
||||||
export interface GoalInput {
|
export interface GoalInput {
|
||||||
groupId: string
|
groupId: string
|
||||||
|
itemId: string
|
||||||
startTime: string | Date
|
startTime: string | Date
|
||||||
endTime: string | Date
|
endTime: string | Date
|
||||||
amount: number
|
amount: number
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
|
unweighted: boolean
|
||||||
|
compositionMode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GoalUpdate {
|
export interface GoalUpdate {
|
||||||
|
itemId?: string
|
||||||
startTime?: string | Date
|
startTime?: string | Date
|
||||||
endTime?: string | Date
|
endTime?: string | Date
|
||||||
amount?: number
|
amount?: number
|
||||||
name?: string
|
name?: string
|
||||||
description?: string
|
description?: string
|
||||||
|
unweighted?: boolean
|
||||||
|
compositionMode?: string
|
||||||
|
clearItemId?: boolean
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,13 @@ export default interface Log {
|
|||||||
id: string
|
id: string
|
||||||
taskId: string
|
taskId: string
|
||||||
itemId: string
|
itemId: string
|
||||||
|
itemAmount: number
|
||||||
|
secondaryItemId?: string
|
||||||
|
secondaryItemAmount: number
|
||||||
loggedTime: string
|
loggedTime: string
|
||||||
description: string
|
description: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface LogFilter {
|
export interface LogFilter {
|
||||||
minTime?: Date
|
minTime?: Date
|
||||||
maxTime?: Date
|
maxTime?: Date
|
||||||
@@ -18,15 +20,23 @@ export interface LogFilter {
|
|||||||
export interface LogResult extends Log {
|
export interface LogResult extends Log {
|
||||||
task: Task
|
task: Task
|
||||||
item: Item
|
item: Item
|
||||||
|
secondaryItem?: Item
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LogInput {
|
export interface LogInput {
|
||||||
taskId: string
|
taskId: string
|
||||||
loggedTime?: string
|
loggedTime?: string
|
||||||
description: string
|
description: string
|
||||||
|
itemAmount: number
|
||||||
|
secondaryItemId?: string
|
||||||
|
secondaryItemAmount?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LogUpdate {
|
export interface LogUpdate {
|
||||||
loggedTime?: string
|
loggedTime?: string
|
||||||
description?: string
|
description?: string
|
||||||
|
itemAmount?: number
|
||||||
|
secondaryItemId?: string
|
||||||
|
secondaryItemAmount?: number
|
||||||
|
clearSecondaryItemId?: boolean
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user