add subtraction of progress from before project's startTime.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
+7
-1
@@ -99,7 +99,13 @@ type ProjectUpdate struct {
|
|||||||
|
|
||||||
type ProjectResult struct {
|
type ProjectResult struct {
|
||||||
Project
|
Project
|
||||||
Tasks []*TaskResult `json:"tasks"`
|
Tasks []*TaskResult `json:"tasks"`
|
||||||
|
Subtractions []ProjectSubtraction `json:"subtractions"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProjectSubtraction struct {
|
||||||
|
Item Item `json:"item"`
|
||||||
|
Amount int `json:"amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProjectFilter struct {
|
type ProjectFilter struct {
|
||||||
|
|||||||
+23
-5
@@ -234,7 +234,7 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes
|
|||||||
if project.UserID != auth.UserID(ctx) {
|
if project.UserID != auth.UserID(ctx) {
|
||||||
return nil, slerrors.NotFound("Goal")
|
return nil, slerrors.NotFound("Goal")
|
||||||
}
|
}
|
||||||
result := &models.ProjectResult{Project: *project}
|
result := &models.ProjectResult{Project: *project, Subtractions: []models.ProjectSubtraction{}}
|
||||||
|
|
||||||
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),
|
||||||
@@ -301,10 +301,19 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes
|
|||||||
}
|
}
|
||||||
for _, log := range result.Tasks[i].Logs {
|
for _, log := range result.Tasks[i].Logs {
|
||||||
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) {
|
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) {
|
||||||
continue
|
result.Subtractions = append(result.Subtractions, models.ProjectSubtraction{
|
||||||
|
Item: *result.Tasks[i].Item,
|
||||||
|
Amount: log.ItemAmount,
|
||||||
|
})
|
||||||
|
if log.SecondaryItemID != nil {
|
||||||
|
result.Subtractions = append(result.Subtractions, models.ProjectSubtraction{
|
||||||
|
Item: *log.SecondaryItem,
|
||||||
|
Amount: log.SecondaryItemAmount,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Tasks[i].CompletedAmount += log.Amount(result.Tasks[i].ItemID)
|
result.Tasks[i].CompletedAmount += log.Amount(log.ItemID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +368,7 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter)
|
|||||||
|
|
||||||
results := make([]*models.ProjectResult, len(projects))
|
results := make([]*models.ProjectResult, len(projects))
|
||||||
for i, project := range projects {
|
for i, project := range projects {
|
||||||
results[i] = &models.ProjectResult{Project: *project}
|
results[i] = &models.ProjectResult{Project: *project, Subtractions: []models.ProjectSubtraction{}}
|
||||||
results[i].Tasks = make([]*models.TaskResult, 0, 16)
|
results[i].Tasks = make([]*models.TaskResult, 0, 16)
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
if task.ProjectID != project.ID {
|
if task.ProjectID != project.ID {
|
||||||
@@ -408,7 +417,16 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter)
|
|||||||
}
|
}
|
||||||
for _, log := range taskResult.Logs {
|
for _, log := range taskResult.Logs {
|
||||||
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) {
|
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) {
|
||||||
continue
|
results[i].Subtractions = append(results[i].Subtractions, models.ProjectSubtraction{
|
||||||
|
Item: *taskResult.Item,
|
||||||
|
Amount: log.ItemAmount,
|
||||||
|
})
|
||||||
|
if log.SecondaryItem != nil {
|
||||||
|
results[i].Subtractions = append(results[i].Subtractions, models.ProjectSubtraction{
|
||||||
|
Item: *log.SecondaryItem,
|
||||||
|
Amount: log.SecondaryItemAmount,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taskResult.CompletedAmount += log.Amount(taskResult.ItemID)
|
taskResult.CompletedAmount += log.Amount(taskResult.ItemID)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type { LogResult } from "../models/log";
|
|||||||
amount: number
|
amount: number
|
||||||
target: number
|
target: number
|
||||||
extras: number
|
extras: number
|
||||||
|
subs: number
|
||||||
noTarget?: boolean
|
noTarget?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ import type { LogResult } from "../models/log";
|
|||||||
for (const task of project.tasks) {
|
for (const task of project.tasks) {
|
||||||
let entry = list.find(e => e.item.id === task.item.id);
|
let entry = list.find(e => e.item.id === task.item.id);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = {item: task.item, amount: 0, target: 0, extras: 0};
|
entry = {item: task.item, amount: 0, target: 0, extras: 0, subs: 0};
|
||||||
list.push(entry);
|
list.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ import type { LogResult } from "../models/log";
|
|||||||
if (log.secondaryItem != null) {
|
if (log.secondaryItem != null) {
|
||||||
let entry = list.find(e => e.item.id === log.secondaryItemId);
|
let entry = list.find(e => e.item.id === log.secondaryItemId);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = {item: log.secondaryItem, amount: 0, target: 0, extras: 0};
|
entry = {item: log.secondaryItem, amount: 0, target: 0, extras: 0, subs: 0};
|
||||||
list.push(entry);
|
list.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +56,17 @@ import type { LogResult } from "../models/log";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const {item, amount} of project.subtractions) {
|
||||||
|
const entry = list.find(e => e.item.id === item.id);
|
||||||
|
if (entry == null) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.subs += amount;
|
||||||
|
entry.target -= amount;
|
||||||
|
entry.amount -= amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const log of logs) {
|
for (const log of logs) {
|
||||||
@@ -67,7 +79,7 @@ import type { LogResult } from "../models/log";
|
|||||||
if (item != null) {
|
if (item != null) {
|
||||||
let entry = list.find(e => e.item.id === item.id);
|
let entry = list.find(e => e.item.id === item.id);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
entry = {item, amount: 0, target: 0, extras: 0, noTarget: true};
|
entry = {item, amount: 0, target: 0, extras: 0, noTarget: true, subs: 0};
|
||||||
list.push(entry);
|
list.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +98,7 @@ import type { LogResult } from "../models/log";
|
|||||||
} else {
|
} else {
|
||||||
return b.target - a.target;
|
return b.target - a.target;
|
||||||
}
|
}
|
||||||
}).filter(l => l.extras > 0 || (l.target > 0 || l.noTarget));
|
}).filter(e => e.extras > 0 || (e.target > 0 || e.subs > 0 || e.noTarget));
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -120,6 +132,11 @@ import type { LogResult } from "../models/log";
|
|||||||
×{entry.extras}
|
×{entry.extras}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if entry.subs > 0}
|
||||||
|
<div class="subs" title="These items are from before the project's start time.">
|
||||||
|
–{entry.subs}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -166,4 +183,7 @@ import type { LogResult } from "../models/log";
|
|||||||
div.ItemProgress div.entry .extras {
|
div.ItemProgress div.entry .extras {
|
||||||
color: #484;
|
color: #484;
|
||||||
}
|
}
|
||||||
|
div.ItemProgress div.entry .subs {
|
||||||
|
color: #852a24;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -23,6 +23,11 @@
|
|||||||
|
|
||||||
progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
|
progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
|
||||||
|
|
||||||
|
for (const {item, amount} of (project.subtractions||[])) {
|
||||||
|
progressAmount -= item.groupWeight * amount;
|
||||||
|
progressTarget -= item.groupWeight * amount;
|
||||||
|
}
|
||||||
|
|
||||||
progressAmount = Math.max(progressAmount - project.subtractAmount, 0);
|
progressAmount = Math.max(progressAmount - project.subtractAmount, 0);
|
||||||
progressTarget = Math.max(progressTarget - project.subtractAmount, 0);
|
progressTarget = Math.max(progressTarget - project.subtractAmount, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type { ProjectSubtraction } from "../models/project";
|
||||||
|
|
||||||
import type { TaskResult } from "../models/task";
|
import type { TaskResult } from "../models/task";
|
||||||
import Progress from "./Progress.svelte";
|
import Progress from "./Progress.svelte";
|
||||||
|
|
||||||
@@ -6,6 +8,7 @@
|
|||||||
tasks?: TaskResult[]
|
tasks?: TaskResult[]
|
||||||
statusTag?: string
|
statusTag?: string
|
||||||
subtractAmount?: number,
|
subtractAmount?: number,
|
||||||
|
subtractions?: ProjectSubtraction[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export let project: ProjectLike;
|
export let project: ProjectLike;
|
||||||
@@ -20,6 +23,11 @@
|
|||||||
).reduce((n,m) => n+m, 0);
|
).reduce((n,m) => n+m, 0);
|
||||||
progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
|
progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
|
||||||
|
|
||||||
|
for (const {item, amount} of (project.subtractions||[])) {
|
||||||
|
progressAmount -= item.groupWeight * amount;
|
||||||
|
progressTarget -= item.groupWeight * amount;
|
||||||
|
}
|
||||||
|
|
||||||
progressAmount = Math.max(progressAmount - (project.subtractAmount||0), 0);
|
progressAmount = Math.max(progressAmount - (project.subtractAmount||0), 0);
|
||||||
progressTarget = Math.max(progressTarget - (project.subtractAmount||0), 0);
|
progressTarget = Math.max(progressTarget - (project.subtractAmount||0), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { IconName } from "../external/icons";
|
import type { IconName } from "../external/icons";
|
||||||
|
import type Item from "./item";
|
||||||
import type { TaskResult } from "./task";
|
import type { TaskResult } from "./task";
|
||||||
|
|
||||||
export default interface Project {
|
export default interface Project {
|
||||||
@@ -19,6 +20,12 @@ export default interface Project {
|
|||||||
|
|
||||||
export interface ProjectResult extends Project {
|
export interface ProjectResult extends Project {
|
||||||
tasks: TaskResult[]
|
tasks: TaskResult[]
|
||||||
|
subtractions: ProjectSubtraction[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProjectSubtraction {
|
||||||
|
item: Item
|
||||||
|
amount: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProjectFilter {
|
export interface ProjectFilter {
|
||||||
|
|||||||
Reference in New Issue
Block a user