generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to Toggl v9 API and Report v3 API
- Loading branch information
Showing
35 changed files
with
1,835 additions
and
1,393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
declare module "toggl-client"; | ||
declare module "simple-svelte-autocomplete"; | ||
declare module "obsidian"; | ||
declare module "env"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/** @deprecated */ | ||
export interface Project { | ||
/** | ||
* The name of the project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
export type ProjectId = number; | ||
export type UserId = number; | ||
export type TagId = number; | ||
export type ClientId = number; | ||
export type WorkspaceId = number; | ||
export type TimeEntryId = number; | ||
export type RowNumber = number; | ||
export type DateTimeString = string; | ||
|
||
export type SearchTimeEntriesResponseItem = { | ||
user_id: UserId; | ||
username: string; | ||
project_id: ProjectId; | ||
task_id: null; | ||
description: string; | ||
tag_ids: string[]; | ||
hourly_rate_in_cents: null; | ||
/** | ||
* Contains a single time entry or an array of time entries, if grouped. | ||
*/ | ||
time_entries: [SearchTimeEntry, ...SearchTimeEntry[]]; | ||
row_number: RowNumber; | ||
}; | ||
|
||
type SearchTimeEntry = { | ||
at: DateTimeString; | ||
id: TimeEntryId; | ||
seconds: number; | ||
start: DateTimeString; | ||
stop: DateTimeString; | ||
}; | ||
|
||
export type TimeEntryStart = { | ||
description: string; | ||
project_id: ProjectId; | ||
tag_ids?: TagId[]; | ||
tags?: string[]; | ||
}; | ||
|
||
export type TimeEntry = TimeEntryStart & { | ||
at: DateTimeString; | ||
description: string; | ||
duration: number; | ||
id: TimeEntryId; | ||
project_id: ProjectId | null; | ||
server_deleted_at: Date | null; | ||
start: DateTimeString; | ||
stop: Date | null; | ||
tag_ids: TagId[] | null; | ||
tags: string[] | null; | ||
user_id: UserId; | ||
workspace_id: WorkspaceId; | ||
}; | ||
|
||
export type ProjectsSummaryResponseItem = { | ||
project_id: ProjectId; | ||
tracked_seconds: number; | ||
user_id: UserId; | ||
}; | ||
|
||
export type ClientsResponseItem = { | ||
id: ClientId; | ||
wid: WorkspaceId; | ||
archived: boolean; | ||
name: string; | ||
at: DateTimeString; | ||
}; | ||
|
||
export type ProjectsResponseItem = { | ||
id: ProjectId; | ||
workspace_id: WorkspaceId; | ||
client_id: ClientId | null; | ||
name: string; | ||
is_private: boolean; | ||
active: boolean; | ||
at: DateTimeString; | ||
created_at: DateTimeString; | ||
server_deleted_at: Date | null; | ||
color: string; | ||
rate: null; | ||
rate_last_updated: Date | null; | ||
recurring: boolean; | ||
actual_hours: number; | ||
wid: WorkspaceId; | ||
cid: ClientId | null; | ||
}; | ||
|
||
export type TagsResponseItem = { | ||
id: TagId; | ||
workspace_id: WorkspaceId; | ||
name: string; | ||
at: DateTimeString; | ||
}; | ||
|
||
export type EnrichedWithProject< | ||
T extends { project_id: ProjectId }, | ||
Y extends ProjectsResponseItem = ProjectsResponseItem, | ||
> = T & { | ||
readonly $project?: Y; | ||
}; | ||
|
||
export type EnrichedWithTags<T extends { tag_ids: TagId[] }> = T & { | ||
readonly $tags?: TagsResponseItem[]; | ||
}; | ||
|
||
export type EnrichedWithClient<T extends { client_id: ClientId }> = T & { | ||
readonly $client?: ClientsResponseItem; | ||
}; | ||
|
||
export type SummaryReportResponse = { | ||
groups: SummaryReportResponseGroup[]; | ||
}; | ||
|
||
type SummaryReportResponseGroup = { | ||
id: number | null; | ||
sub_groups: SummaryReportResponseSubGroup[]; | ||
}; | ||
|
||
type SummaryReportResponseSubGroup = { | ||
id: null; | ||
title?: string; | ||
seconds: number; | ||
}; | ||
|
||
export type DetailedReportResponseItem = { | ||
user_id: UserId; | ||
project_id: ProjectId | null; | ||
task_id: null; | ||
description: string; | ||
tag_ids: TagId[]; | ||
time_entries: DetailedReportTimeEntry[]; | ||
row_number: RowNumber; | ||
}; | ||
|
||
type DetailedReportTimeEntry = { | ||
id: TimeEntryId; | ||
seconds: number; | ||
start: DateTimeString; | ||
stop: DateTimeString; | ||
at: DateTimeString; | ||
}; | ||
|
||
export type SummaryTimeChart = { | ||
seconds: number; | ||
graph: GraphItem[]; | ||
resolution: "day" | "week" | "month"; | ||
}; | ||
|
||
export type GraphItem = { | ||
seconds: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/** | ||
* @deprecated | ||
* Workspace-associated tag from the Toggl API. | ||
*/ | ||
export interface Tag { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { ClientsResponseItem } from "lib/model/Report-v3"; | ||
import { get, writable } from "svelte/store"; | ||
|
||
const clients = writable<ClientsResponseItem[]>([]); | ||
|
||
export const setClients = clients.set; | ||
|
||
export const Clients = { subscribe: clients.subscribe }; | ||
|
||
export function getClientIds(item: (string | number)[]): number[] { | ||
const clients = get(Clients); | ||
|
||
return item | ||
.map((item) => { | ||
if (typeof item === "number") { | ||
return item; | ||
} | ||
const client = clients.find( | ||
(client) => client.name.toLowerCase() === item.toLowerCase(), | ||
); | ||
return client.id ?? null; | ||
}) | ||
.filter((id) => id !== null) as number[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { | ||
EnrichedWithProject, | ||
EnrichedWithTags, | ||
TimeEntry, | ||
} from "lib/model/Report-v3"; | ||
import { derived, writable } from "svelte/store"; | ||
|
||
import { Projects } from "./projects"; | ||
import { Tags } from "./tags"; | ||
|
||
const currentTimer = writable<TimeEntry>(null); | ||
|
||
export const setCurrentTimer = currentTimer.set; | ||
|
||
const enrichedCurrentTimer = derived( | ||
[currentTimer, Projects, Tags], | ||
([$currentTimer, $projects, $tags]): EnrichedWithProject< | ||
EnrichedWithTags<typeof $currentTimer>, | ||
typeof $projects[number] | ||
> => { | ||
if (!$currentTimer) return null; | ||
|
||
const project = $projects.find( | ||
(project) => project.id === $currentTimer.project_id, | ||
); | ||
|
||
const tags = $currentTimer.tag_ids.map((tagId) => | ||
$tags.find((tag) => tag.id === tagId), | ||
); | ||
|
||
return { | ||
...$currentTimer, | ||
$project: project, | ||
$tags: tags.some((tag) => tag === undefined) ? undefined : tags, | ||
}; | ||
}, | ||
); | ||
|
||
export const CurrentTimer = { | ||
subscribe: enrichedCurrentTimer.subscribe, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { | ||
EnrichedWithProject, | ||
ProjectsSummaryResponseItem, | ||
} from "lib/model/Report-v3"; | ||
import { derived, writable } from "svelte/store"; | ||
|
||
import { Projects } from "./projects"; | ||
|
||
const summaryItems = writable<ProjectsSummaryResponseItem[]>([]); | ||
|
||
export const setDailySummaryItems = summaryItems.set; | ||
|
||
export const DailySummary = derived( | ||
[summaryItems, Projects], | ||
([$summaryItems, $projects]) => { | ||
const summary = { | ||
projects_breakdown: $summaryItems.map( | ||
(item): EnrichedWithProject<typeof item> => ({ | ||
...item, | ||
$project: | ||
$projects.find((project) => project.id === item.project_id) ?? null, | ||
}), | ||
), | ||
total_seconds: $summaryItems.reduce((a, b) => a + b.tracked_seconds, 0), | ||
}; | ||
|
||
return summary; | ||
}, | ||
); |
Oops, something went wrong.