👩💻 feat: stop timer
This commit is contained in:
parent
71b66181d4
commit
b80912d62e
@ -28,6 +28,10 @@
|
|||||||
{
|
{
|
||||||
"command": "harvest-vscode.logout",
|
"command": "harvest-vscode.logout",
|
||||||
"title": "Harvest: Logout"
|
"title": "Harvest: Logout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "harvest-vscode.stopTimer",
|
||||||
|
"title": "Harvest: Stop Timer"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
38
src/Entities/CurrentTimeEntry.ts
Normal file
38
src/Entities/CurrentTimeEntry.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
let instance: CurrentTimeEntry | null
|
||||||
|
|
||||||
|
interface CurrentTimeEntryProps {
|
||||||
|
id?: number,
|
||||||
|
taskName?: string,
|
||||||
|
projectName?: string,
|
||||||
|
notes?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
class CurrentTimeEntry {
|
||||||
|
public id?: number
|
||||||
|
public taskName?: string
|
||||||
|
public projectName?: string
|
||||||
|
public notes?: string
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
if (!instance) instance = this
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
set props (values: CurrentTimeEntryProps) {
|
||||||
|
if (values.id) this.id = values.id
|
||||||
|
if (values.taskName) this.taskName = values.taskName
|
||||||
|
if (values.projectName) this.projectName = values.projectName
|
||||||
|
if (values.notes) this.projectName = values.notes
|
||||||
|
}
|
||||||
|
|
||||||
|
get props (): CurrentTimeEntryProps {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
taskName: this.taskName,
|
||||||
|
projectName: this.projectName,
|
||||||
|
notes: this.notes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CurrentTimeEntry
|
@ -1,4 +1,5 @@
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
|
import CurrentTimeEntry from "../../Entities/CurrentTimeEntry";
|
||||||
import TaskInterface from "../../Entities/Interfaces/TaskInterface";
|
import TaskInterface from "../../Entities/Interfaces/TaskInterface";
|
||||||
import TimeEntryInterface from "../../Entities/Interfaces/TimeEntryInterface";
|
import TimeEntryInterface from "../../Entities/Interfaces/TimeEntryInterface";
|
||||||
import Project from "../../Entities/Project";
|
import Project from "../../Entities/Project";
|
||||||
@ -52,11 +53,6 @@ function PunchTime (context: vscode.ExtensionContext): vscode.Disposable {
|
|||||||
return t.name === selectedTaskName
|
return t.name === selectedTaskName
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log(selectedProject?.tasks[0])
|
|
||||||
// console.log(selectedProject?.tasks[1])
|
|
||||||
// console.log(selectedProject?.tasks[2])
|
|
||||||
console.log(selectedTask)
|
|
||||||
|
|
||||||
const notes = await vscode.window.showInputBox({
|
const notes = await vscode.window.showInputBox({
|
||||||
ignoreFocusOut: true,
|
ignoreFocusOut: true,
|
||||||
placeHolder: 'Notes'
|
placeHolder: 'Notes'
|
||||||
@ -74,11 +70,20 @@ function PunchTime (context: vscode.ExtensionContext): vscode.Disposable {
|
|||||||
notes: notes
|
notes: notes
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(newTimeEntry)
|
|
||||||
|
|
||||||
const saveNewTimeEntryResponse = await saveNewTimeEntry(newTimeEntry)
|
const saveNewTimeEntryResponse = await saveNewTimeEntry(newTimeEntry)
|
||||||
|
|
||||||
console.log(saveNewTimeEntryResponse)
|
const newTimeEntryId = saveNewTimeEntryResponse.id
|
||||||
|
|
||||||
|
const currentTimeEntry = new CurrentTimeEntry
|
||||||
|
currentTimeEntry.props = {
|
||||||
|
id: newTimeEntryId,
|
||||||
|
projectName: selectedProjectName,
|
||||||
|
taskName: selectedTaskName,
|
||||||
|
notes: notes
|
||||||
|
}
|
||||||
|
|
||||||
|
await context.globalState.update('currentTaskId', newTimeEntryId)
|
||||||
|
vscode.window.showInformationMessage(`${selectedProjectName} \n ${selectedTaskName} \n ${notes}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
46
src/UseCases/Commands/StopTimer.ts
Normal file
46
src/UseCases/Commands/StopTimer.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import * as vscode from "vscode"
|
||||||
|
import axios from 'axios'
|
||||||
|
import Harvest from "../../Entities/Harvest"
|
||||||
|
|
||||||
|
function StopTimer (context: vscode.ExtensionContext): vscode.Disposable {
|
||||||
|
return vscode.commands.registerCommand('harvest-vscode.stopTimer', async () => {
|
||||||
|
|
||||||
|
const accountId: string = context.globalState.get('accountId') || ''
|
||||||
|
const accessToken: string = context.globalState.get('accessToken') || ''
|
||||||
|
|
||||||
|
if (!accountId || !accessToken) {
|
||||||
|
vscode.window.showWarningMessage('You are not authenticated with Harvest /n Run the "Harvest: Login Command" first.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const harvest = new Harvest({
|
||||||
|
accountId: accountId,
|
||||||
|
accessToken: accessToken
|
||||||
|
})
|
||||||
|
|
||||||
|
const currentTaskId: string = context.globalState.get('currentTaskId') || ''
|
||||||
|
|
||||||
|
if (!currentTaskId) {
|
||||||
|
vscode.window.showWarningMessage('There is no current task stored.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let timeEntryResponse: any
|
||||||
|
try {
|
||||||
|
timeEntryResponse = await axios.patch(
|
||||||
|
`https://api.harvestapp.com/v2/time_entries/${currentTaskId}/stop`,
|
||||||
|
{},
|
||||||
|
{ headers: harvest.headers }
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
vscode.window.showErrorMessage('Issue stoping timer with Harvest.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
vscode.window.showInformationMessage('Harvest Timer Stopped')
|
||||||
|
await context.globalState.update('currentTaskId', '')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default StopTimer
|
@ -2,6 +2,7 @@ import * as vscode from 'vscode'
|
|||||||
import Logout from './UseCases/Commands/Logout'
|
import Logout from './UseCases/Commands/Logout'
|
||||||
import PunchTime from './UseCases/Commands/PunchTime'
|
import PunchTime from './UseCases/Commands/PunchTime'
|
||||||
import SetUserAuthentication from './UseCases/Commands/SetUserAuthentication'
|
import SetUserAuthentication from './UseCases/Commands/SetUserAuthentication'
|
||||||
|
import StopTimer from './UseCases/Commands/StopTimer'
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
const statusbar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
|
const statusbar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
|
||||||
@ -13,7 +14,8 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
const commands: vscode.Disposable[] = [
|
const commands: vscode.Disposable[] = [
|
||||||
SetUserAuthentication(context),
|
SetUserAuthentication(context),
|
||||||
Logout(context),
|
Logout(context),
|
||||||
PunchTime(context)
|
PunchTime(context),
|
||||||
|
StopTimer(context)
|
||||||
]
|
]
|
||||||
|
|
||||||
context.subscriptions.push(...commands)
|
context.subscriptions.push(...commands)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user