👩‍💻 feat: stop timer

This commit is contained in:
ysandler 2020-09-20 10:11:11 -05:00 committed by Joshua Shoemaker
parent 71b66181d4
commit b80912d62e
5 changed files with 104 additions and 9 deletions

View File

@ -28,6 +28,10 @@
{
"command": "harvest-vscode.logout",
"title": "Harvest: Logout"
},
{
"command": "harvest-vscode.stopTimer",
"title": "Harvest: Stop Timer"
}
]
},

View 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

View File

@ -1,4 +1,5 @@
import * as vscode from "vscode";
import CurrentTimeEntry from "../../Entities/CurrentTimeEntry";
import TaskInterface from "../../Entities/Interfaces/TaskInterface";
import TimeEntryInterface from "../../Entities/Interfaces/TimeEntryInterface";
import Project from "../../Entities/Project";
@ -52,11 +53,6 @@ function PunchTime (context: vscode.ExtensionContext): vscode.Disposable {
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({
ignoreFocusOut: true,
placeHolder: 'Notes'
@ -74,11 +70,20 @@ function PunchTime (context: vscode.ExtensionContext): vscode.Disposable {
notes: notes
}
console.log(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}`)
})
}

View 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

View File

@ -2,6 +2,7 @@ import * as vscode from 'vscode'
import Logout from './UseCases/Commands/Logout'
import PunchTime from './UseCases/Commands/PunchTime'
import SetUserAuthentication from './UseCases/Commands/SetUserAuthentication'
import StopTimer from './UseCases/Commands/StopTimer'
export function activate(context: vscode.ExtensionContext) {
const statusbar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
@ -13,7 +14,8 @@ export function activate(context: vscode.ExtensionContext) {
const commands: vscode.Disposable[] = [
SetUserAuthentication(context),
Logout(context),
PunchTime(context)
PunchTime(context),
StopTimer(context)
]
context.subscriptions.push(...commands)