Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Basic tracking of objectives via plus and minux
Browse files Browse the repository at this point in the history
* Objectives are now just loaded at startup and kept in memory. Fixes #2
* Still no persistence, yet
  • Loading branch information
oxisto committed Aug 2, 2019
1 parent ab4b135 commit 6e7d7c6
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 45 deletions.
5 changes: 5 additions & 0 deletions cmd/okr2go/okr2go.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func main() {

browser.OpenURL("http://localhost:4300")

if err := okr2go.LoadObjectives(); err != nil {
log.Errorf("An error occurred: %v", err)
return
}

router := handlers.LoggingHandler(&httputil.LogWriter{Logger: log, Level: logrus.InfoLevel, Component: "http"}, okr2go.NewRouter())
err := http.ListenAndServe("0.0.0.0:4300", router)

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.12

require (
github.com/gobuffalo/packr v1.30.1
github.com/google/martian v2.1.0+incompatible
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.3
github.com/kyokomi/emoji v2.1.0+incompatible
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
github.com/gobuffalo/packr v1.30.1/go.mod h1:ljMyFO2EcrnzsHsN99cvbq055Y9OhRrIaviy289eRuk=
github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg=
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
Expand All @@ -39,8 +37,6 @@ github.com/kyokomi/emoji v2.1.0+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2px
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/oxisto/go-httputil v0.3.0 h1:xQU4FIM4jGOMj4/O+KJ5i3ktHjNdpwz9dSBDBSag5hU=
github.com/oxisto/go-httputil v0.3.0/go.mod h1:rRdUU4wjh4Ewj7KPnh3sCkE4JEMaHm/AahsNwnC03ZE=
github.com/oxisto/go-httputil v0.3.1 h1:VZBr5SfGz10IRGavDBqCBE4BjCt8CMyugA+Rlhk/VX0=
github.com/oxisto/go-httputil v0.3.1/go.mod h1:rRdUU4wjh4Ewj7KPnh3sCkE4JEMaHm/AahsNwnC03ZE=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
4 changes: 2 additions & 2 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (o *ObjectiveWalker) Walk(node *blackfriday.Node, entering bool) blackfrida

// its probably the objectives table
if strings.HasPrefix(text, "\n|") {
o.objective.KeyResults = []KeyResult{}
o.objective.KeyResults = []*KeyResult{}

// split per line first
lines := strings.Split(text, "\n")
Expand Down Expand Up @@ -130,7 +130,7 @@ func (o *ObjectiveWalker) Walk(node *blackfriday.Node, entering bool) blackfrida
keyResult.Comments = trimAndSplit(fields[6])

// add the result
o.objective.KeyResults = append(o.objective.KeyResults, keyResult)
o.objective.KeyResults = append(o.objective.KeyResults, &keyResult)
}
} else {
log.Debugf("Appending '%s' to description", node.Literal)
Expand Down
31 changes: 27 additions & 4 deletions objectives.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
package okr2go

var objectives Objectives

type Objectives []*Objective

type Objective struct {
Name string `json:"name"`
Description string `json:"description"`
KeyResults []KeyResult `json:"keyResults"`
Name string `json:"name"`
Description string `json:"description"`
KeyResults []*KeyResult `json:"keyResults"`
}

func LoadObjectives() (err error) {
// @todo Cache objectives in memory instead of loading them from markdown in every request
objectives, err = ParseMarkdown("example.md")

if err != nil {
return err
}

return nil
}

func (o Objectives) FindObjective(objectiveID int) *Objective {
if objectiveID < 0 || objectiveID > len(o) {
return nil
}

return o[objectiveID]
}

func (o *Objective) FindKeyResult(resultID string) *KeyResult {
for _, result := range o.KeyResults {
if result.ID == resultID {
return &result
return result
}
}

Expand Down
9 changes: 6 additions & 3 deletions okr2go-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
"@angular/platform-browser": "~8.2.0",
"@angular/platform-browser-dynamic": "~8.2.0",
"@angular/router": "~8.2.0",
"@fortawesome/angular-fontawesome": "^0.4.0",
"@fortawesome/fontawesome-svg-core": "^1.2.20",
"@fortawesome/free-solid-svg-icons": "^5.10.0",
"@ng-bootstrap/ng-bootstrap": "^5.1.0",
"@ng-bootstrap/schematics": "^2.0.0-alpha.1",
"bootstrap": "^4.0.0",
"rxjs": "~6.5.2",
"tslib": "^1.9.0",
"zone.js": "~0.9.1",
"bootstrap": "^4.0.0"
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.802.0",
Expand All @@ -34,4 +37,4 @@
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}
}
}
2 changes: 2 additions & 0 deletions okr2go-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ObjectiveListComponent } from './objective-list/objective-list.component';
import { HttpClientModule } from '@angular/common/http';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

@NgModule({
declarations: [
Expand All @@ -16,6 +17,7 @@ import { HttpClientModule } from '@angular/common/http';
BrowserModule,
HttpClientModule,
AppRoutingModule,
FontAwesomeModule,
NgbModule
],
providers: [],
Expand Down
13 changes: 11 additions & 2 deletions okr2go-ui/src/app/objective-list/objective-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ <h5 class="mb-1">{{ entry.value.name }}</h5>
</div>
</div>
<p class="mb-1">{{ entry.value.description }} </p>
<table class="mt-2 table table-hover">
<table class="mt-2 table">
<tbody>
<tr *ngFor="let keyResult of entry.value.keyResults">
<th scope="row">{{ keyResult.id }}</th>
<td>{{ keyResult.name }}</td>
<td>
<ngb-progressbar class="mt-auto mb-auto" type="info"
<button (click)="onMinus(entry.key, keyResult)" class="btn btn-sm btn-secondary">
<fa-icon [icon]="faMinus"></fa-icon>
</button>

<ngb-progressbar style="min-width: 300px" class="btn mt-auto mb-auto"
[type]="getTypeForKeyResult(keyResult)"
[value]="keyResult.current / keyResult.target * 100">Current
progress
is
<b>{{ keyResult.current }} /
{{ keyResult.target }}</b>...</ngb-progressbar>

<button (click)="onPlus(entry.key, keyResult)" class="btn btn-sm btn-secondary">
<fa-icon [icon]="faPlus"></fa-icon>
</button>
</td>
<td>{{ keyResult.contributors.join(', ') }}</td>
<td>{{ keyResult.comments.join(', ')}}</td>
Expand Down
33 changes: 32 additions & 1 deletion okr2go-ui/src/app/objective-list/objective-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { faPlus, faMinus } from '@fortawesome/free-solid-svg-icons';

import { ObjectiveService } from '../objective.service';
import { Objective } from '../objective';
import { Objective, KeyResult } from '../objective';

@Component({
selector: 'app-objective-list',
Expand All @@ -10,13 +12,42 @@ import { Objective } from '../objective';
export class ObjectiveListComponent implements OnInit {

objectives: Objective[];
faPlus = faPlus;
faMinus = faMinus;

constructor(private objectiveService: ObjectiveService) {

}

ngOnInit() {
this.refreshObjectives();
}

onPlus(objectiveId: number, keyResult: KeyResult) {
this.objectiveService.resultPlusOne(objectiveId, keyResult.id).subscribe(_ => {
this.refreshObjectives();
})
}

onMinus(objectiveId: number, keyResult: KeyResult) {
this.objectiveService.resultMinusOne(objectiveId, keyResult.id).subscribe(_ => {
this.refreshObjectives();
})
}

refreshObjectives() {
this.objectiveService.getObjectives().subscribe(objectives => this.objectives = objectives);
}

getTypeForKeyResult(keyResult: KeyResult) {
const percentage = keyResult.current / keyResult.target;

if (percentage >= 0.7) {
return 'success';
} else if (percentage >= 0.3) {
return 'warning';
} else {
return 'danger';
}
}
}
14 changes: 13 additions & 1 deletion okr2go-ui/src/app/objective.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Objective } from './objective';
import { Objective, KeyResult } from './objective';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

Expand All @@ -18,4 +18,16 @@ export class ObjectiveService {
}));
}

resultPlusOne(objectiveId: number, resultId: string): Observable<KeyResult> {
return this.http.get<Objective[]>('/api/objectives/' + objectiveId + '/' + resultId + '/plus').pipe(map(data => {
return Object.assign(new KeyResult, data);
}));
}

resultMinusOne(objectiveId: number, resultId: string): Observable<KeyResult> {
return this.http.get<Objective[]>('/api/objectives/' + objectiveId + '/' + resultId + '/minus').pipe(map(data => {
return Object.assign(new KeyResult, data);
}));
}

}
5 changes: 4 additions & 1 deletion okr2go-ui/src/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Okr2goUi</title>
Expand All @@ -8,7 +9,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
<app-root></app-root>
</body>
</html>

</html>
26 changes: 26 additions & 0 deletions okr2go-ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@
dependencies:
tslib "^1.9.0"

"@fortawesome/angular-fontawesome@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@fortawesome/angular-fontawesome/-/angular-fontawesome-0.4.0.tgz#ab794362a5e37124b834564dcb55ed1c0ce0413a"
integrity sha512-DYVXdCzwQo6d0CxVMRK+10LpBAvYN9xigWeQW4wKYq/Czd5es46nPMKixB5rHfNViECwwlM2gTM61K4DpxlJxg==
dependencies:
tslib "^1.9.0"

"@fortawesome/fontawesome-common-types@^0.2.20":
version "0.2.20"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.20.tgz#b5450b07400aea96d87d24e98e22d4a3d8d59305"
integrity sha512-5wo0pMNS4gWTkplFAPSfNq4poXwLcgj8+khZs9/zbWMxC0hi6qnehXOrX7i7+Y7XyTQForja2WpR7Nz6LY2BtQ==

"@fortawesome/fontawesome-svg-core@^1.2.20":
version "1.2.20"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-1.2.20.tgz#2b562dd73df08c835e1f42c04061029ee77b90b5"
integrity sha512-p18GsDaPeZOFKENyigYcEg0ez9UHqUO7wxcdxpoxsb0pMxvt4kW8RTrgUIW1z3/19E/Z1iRQDmB3ZyfZ+CcpSQ==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.20"

"@fortawesome/free-solid-svg-icons@^5.10.0":
version "5.10.0"
resolved "https://registry.yarnpkg.com/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-5.10.0.tgz#ccc803828f6b71db78414550faa7b1c4ebf494b2"
integrity sha512-Ndt0GR9wU66lBLGMRZN2jv8LEDx+VTfwmnqYKLQ3VttH4ikgTpqBhdr7UF4M3GFYt1CwftrPVuKOUAFleYg7xA==
dependencies:
"@fortawesome/fontawesome-common-types" "^0.2.20"

"@ng-bootstrap/ng-bootstrap@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@ng-bootstrap/ng-bootstrap/-/ng-bootstrap-5.1.0.tgz#c0bdb74702d46f58b3cfd526dd77921e6107e7f7"
Expand Down
Loading

0 comments on commit 6e7d7c6

Please sign in to comment.