From 2e3f7c6894b2cd5b9ba7d9a34915831f820d3808 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 20 Jan 2020 09:24:24 +0100 Subject: [PATCH] admin: claims now reference exercices --- admin/api/claim.go | 20 +++++++++++++- admin/static/js/app.js | 10 ++++--- admin/static/views/claim-list.html | 2 +- admin/static/views/claim.html | 18 ++++++++++--- libfic/db.go | 4 ++- libfic/todo.go | 42 +++++++++++++++++++++++------- 6 files changed, 76 insertions(+), 20 deletions(-) diff --git a/admin/api/claim.go b/admin/api/claim.go index bdc22475..46cac18b 100644 --- a/admin/api/claim.go +++ b/admin/api/claim.go @@ -38,6 +38,8 @@ type ClaimExported struct { Subject string `json:"subject"` IdTeam *int64 `json:"id_team"` Team *fic.Team `json:"team"` + IdExercice *int64 `json:"id_exercice"` + Exercice *fic.Exercice `json:"exercice"` IdAssignee *int64 `json:"id_assignee"` Assignee *fic.ClaimAssignee `json:"assignee"` Creation time.Time `json:"creation"` @@ -53,6 +55,9 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) { if e.Team, err = claim.GetTeam(); err != nil { return nil, err } + if e.Exercice, err = claim.GetExercice(); err != nil { + return nil, err + } if e.Assignee, err = claim.GetAssignee(); err != nil { return nil, err } @@ -70,6 +75,7 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) { e.Id = claim.Id e.IdAssignee = claim.IdAssignee e.IdTeam = claim.IdTeam + e.IdExercice = claim.IdExercice e.Subject = claim.Subject e.Creation = claim.Creation e.State = claim.State @@ -80,6 +86,7 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) { type ClaimUploaded struct { Subject string `json:"subject"` Team *int64 `json:"id_team"` + Exercice *int64 `json:"id_exercice"` Assignee *int64 `json:"id_assignee"` Priority string `json:"priority"` } @@ -101,6 +108,17 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) { t = nil } + var e *fic.Exercice + if uc.Exercice != nil { + if exercice, err := fic.GetExercice(*uc.Exercice); err != nil { + return nil, err + } else { + e = &exercice + } + } else { + e = nil + } + var a *fic.ClaimAssignee if uc.Assignee != nil { if assignee, err := fic.GetAssignee(*uc.Assignee); err != nil { @@ -112,7 +130,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) { a = nil } - return fic.NewClaim(uc.Subject, t, a, uc.Priority) + return fic.NewClaim(uc.Subject, t, e, a, uc.Priority) } func clearClaims(_ httprouter.Params, _ []byte) (interface{}, error) { diff --git a/admin/static/js/app.js b/admin/static/js/app.js index bd47b7e4..2496526c 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -1056,24 +1056,26 @@ angular.module("FICApp") $location.url("/claims/" + id); }; }) - .controller("ClaimController", function($scope, Claim, ClaimAssignee, Teams, $routeParams, $location, $http) { + .controller("ClaimController", function($scope, Claim, ClaimAssignee, Teams, Exercice, $routeParams, $location, $http) { $scope.claim = Claim.get({ claimId: $routeParams.claimId }, function(v) { v.id_team = "" + v.id_team; if (!v.priority) v.priority = "medium"; }); if ($routeParams.claimId == "new") - $scope.fields = ["id_team", "subject", "priority", "id_assignee"]; + $scope.fields = ["id_team", "subject", "priority", "id_exercice", "id_assignee"]; else - $scope.fields = ["state", "subject", "priority", "id_assignee", "id_team", "creation"]; + $scope.fields = ["state", "subject", "priority", "id_exercice", "id_assignee", "id_team", "creation"]; $scope.assignees = ClaimAssignee.query(); $scope.whoami = Math.floor(getCookie("myassignee")); $scope.teams = Teams.get(); - $scope.namedFields = { + $scope.exercices = Exercice.query(); + $scope.namedFields = { "subject": "Objet", "id_assignee": "Assigné a", "state": "État", "id_team": "Équipe", + "id_exercice": "Challenge", "creation": "Création", "priority": "Priorité", "description": "Description", diff --git a/admin/static/views/claim-list.html b/admin/static/views/claim-list.html index f7b66e42..80a079d9 100644 --- a/admin/static/views/claim-list.html +++ b/admin/static/views/claim-list.html @@ -37,7 +37,7 @@ - {{ teams[claim.id_team].name }} + {{ teams[claim.id_team].name }} diff --git a/admin/static/views/claim.html b/admin/static/views/claim.html index f2e04720..d74f4aba 100644 --- a/admin/static/views/claim.html +++ b/admin/static/views/claim.html @@ -6,16 +6,22 @@
- + + - +
+ + +
- +
@@ -36,7 +42,11 @@
-
+
+ +
+ +
Par anonymous {{ assignee.name }} le {{ description.date | date:"mediumTime" }} : {{ description.content }}
diff --git a/libfic/db.go b/libfic/db.go index 4d033004..df07d7cf 100644 --- a/libfic/db.go +++ b/libfic/db.go @@ -363,12 +363,14 @@ CREATE TABLE IF NOT EXISTS claims( id_claim INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, subject VARCHAR(255) NOT NULL, id_team INTEGER, + id_exercice INTEGER, id_assignee INTEGER, creation TIMESTAMP NOT NULL, state ENUM('new', 'need-info', 'confirmed', 'in-progress', 'need-review', 'closed', 'invalid') NOT NULL, priority ENUM('low', 'medium', 'high', 'critical') NOT NULL, FOREIGN KEY(id_assignee) REFERENCES claim_assignees(id_assignee), - FOREIGN KEY(id_team) REFERENCES teams(id_team) + FOREIGN KEY(id_team) REFERENCES teams(id_team), + FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice) ) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; `); err != nil { return err diff --git a/libfic/todo.go b/libfic/todo.go index d17a6892..ad82cfe5 100644 --- a/libfic/todo.go +++ b/libfic/todo.go @@ -10,6 +10,7 @@ type Claim struct { Id int64 `json:"id"` Subject string `json:"subject"` IdTeam *int64 `json:"id_team"` + IdExercice *int64 `json:"id_exercice"` IdAssignee *int64 `json:"id_assignee"` Creation time.Time `json:"creation"` State string `json:"state"` @@ -18,21 +19,21 @@ type Claim struct { // GetClaim retrieves the claim with the given identifier. func GetClaim(id int64) (c Claim, err error) { - err = DBQueryRow("SELECT id_claim, subject, id_team, id_assignee, creation, state, priority FROM claims WHERE id_claim = ?", id).Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdAssignee, &c.Creation, &c.State, &c.Priority) + err = DBQueryRow("SELECT id_claim, subject, id_team, id_exercice, id_assignee, creation, state, priority FROM claims WHERE id_claim = ?", id).Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdExercice, &c.IdAssignee, &c.Creation, &c.State, &c.Priority) return } // GetClaims returns a list of all Claim registered in the database. func GetClaims() (res []Claim, err error) { var rows *sql.Rows - if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_assignee, creation, state, priority FROM claims"); err != nil { + if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_exercice, id_assignee, creation, state, priority FROM claims"); err != nil { return } defer rows.Close() for rows.Next() { var c Claim - if err = rows.Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdAssignee, &c.Creation, &c.State, &c.Priority); err != nil { + if err = rows.Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdExercice, &c.IdAssignee, &c.Creation, &c.State, &c.Priority); err != nil { return } res = append(res, c) @@ -45,14 +46,14 @@ func GetClaims() (res []Claim, err error) { // GetClaims returns a list of all Claim registered for the Team. func (t Team) GetClaims() (res []Claim, err error) { var rows *sql.Rows - if rows, err = DBQuery("SELECT id_claim, subject, IdTeam, id_assignee, creation, state, priority FROM claims WHERE IdTeam = ?", t.Id); err != nil { + if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_exercice, id_assignee, creation, state, priority FROM claims WHERE IdTeam = ?", t.Id); err != nil { return nil, err } defer rows.Close() for rows.Next() { var c Claim - if err = rows.Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdAssignee, &c.Creation, &c.State, &c.Priority); err != nil { + if err = rows.Scan(&c.Id, &c.Subject, &c.IdTeam, &c.IdExercice, &c.IdAssignee, &c.Creation, &c.State, &c.Priority); err != nil { return } res = append(res, c) @@ -63,7 +64,7 @@ func (t Team) GetClaims() (res []Claim, err error) { } // NewClaim creates and fills a new struct Claim and registers it into the database. -func NewClaim(subject string, team *Team, assignee *ClaimAssignee, priority string) (Claim, error) { +func NewClaim(subject string, team *Team, exercice *Exercice, assignee *ClaimAssignee, priority string) (Claim, error) { var tid *int64 if team == nil { tid = nil @@ -71,6 +72,13 @@ func NewClaim(subject string, team *Team, assignee *ClaimAssignee, priority stri tid = &team.Id } + var eid *int64 + if exercice == nil { + eid = nil + } else { + eid = &exercice.Id + } + var aid *int64 if assignee == nil { aid = nil @@ -78,12 +86,12 @@ func NewClaim(subject string, team *Team, assignee *ClaimAssignee, priority stri aid = &assignee.Id } - if res, err := DBExec("INSERT INTO claims (subject, id_team, id_assignee, creation, state, priority) VALUES (?, ?, ?, ?, ?, ?)", subject, tid, aid, time.Now(), "new", priority); err != nil { + if res, err := DBExec("INSERT INTO claims (subject, id_team, id_exercice, id_assignee, creation, state, priority) VALUES (?, ?, ?, ?, ?, ?, ?)", subject, tid, eid, aid, time.Now(), "new", priority); err != nil { return Claim{}, err } else if cid, err := res.LastInsertId(); err != nil { return Claim{}, err } else { - return Claim{cid, subject, tid, aid, time.Now(), "new", priority}, nil + return Claim{cid, subject, tid, eid, aid, time.Now(), "new", priority}, nil } } @@ -103,9 +111,25 @@ func (c Claim) SetTeam(t Team) { c.IdTeam = &t.Id } +// GetExercice returns the Exercice linked to the issue, if any. +func (c Claim) GetExercice() (*Exercice, error) { + if c.IdExercice == nil { + return nil, nil + } else if e, err := GetExercice(*c.IdExercice); err != nil { + return nil, err + } else { + return &e, nil + } +} + +// SetExercice defines the Exercice that is linked to this issue. +func (c Claim) SetExercice(e Exercice) { + c.IdExercice = &e.Id +} + // Update applies modifications back to the database. func (c Claim) Update() (int64, error) { - if res, err := DBExec("UPDATE claims SET subject = ?, id_team = ?, id_assignee = ?, creation = ?, state = ?, priority = ? WHERE id_claim = ?", c.Subject, c.IdTeam, c.IdAssignee, c.Creation, c.State, c.Priority, c.Id); err != nil { + if res, err := DBExec("UPDATE claims SET subject = ?, id_team = ?, id_exercice = ?, id_assignee = ?, creation = ?, state = ?, priority = ? WHERE id_claim = ?", c.Subject, c.IdTeam, c.IdExercice, c.IdAssignee, c.Creation, c.State, c.Priority, c.Id); err != nil { return 0, err } else if nb, err := res.RowsAffected(); err != nil { return 0, err