admin: claims now reference exercices
This commit is contained in:
parent
56b79cae2d
commit
2e3f7c6894
@ -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) {
|
||||
|
@ -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",
|
||||
|
@ -37,7 +37,7 @@
|
||||
</span>
|
||||
</span>
|
||||
<span ng-if="field == 'id_team'">
|
||||
{{ teams[claim.id_team].name }}
|
||||
<a ng-href="teams/{{ claim.id_team }}">{{ teams[claim.id_team].name }}</a>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -6,16 +6,22 @@
|
||||
<div class="form-group row" ng-repeat="field in fields">
|
||||
<label for="{{ field }}" class="col-2 col-form-label col-form-label-sm">{{ namedFields[field] }}</label>
|
||||
<div class="col-10">
|
||||
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="claim[field]" ng-if="field != 'state' && field != 'priority' && field != 'creation' && field != 'id_team' && field != 'id_assignee' && field != 'description'">
|
||||
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="claim[field]" ng-if="field != 'state' && field != 'priority' && field != 'creation' && field != 'id_team' && field != 'id_exercice' && field != 'id_assignee' && field != 'description'">
|
||||
<input type="datetime" class="form-control form-control-sm" id="{{ field }}" ng-model="claim[field]" ng-if="field == 'creation' && claim.id">
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="k as v for (k, v) in states" ng-if="field == 'state'"></select>
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="k as v for (k, v) in priorities" ng-if="field == 'priority'"><option value="medium">Par défaut</option></select>
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="ex.id as ex.title group by ex.path.split('/')[0] for ex in exercices" ng-if="field == 'id_exercice'"><option></option></select>
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="k as t.name for (k, t) in teams" ng-if="field == 'id_team' && !claim.id"><option></option></select>
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="k as t.name for (k, t) in teams" ng-if="field == 'id_team' && claim.id"><option></option></select>
|
||||
<div class="input-group" ng-if="field == 'id_team' && claim.id">
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="k as t.name for (k, t) in teams"><option></option></select>
|
||||
<div class="input-group-append" ng-if="claim.id_team">
|
||||
<a type="button" class="btn btn-sm btn-outline-secondary" ng-href="teams/{{ claim.id_team }}">Aller à l'équipe</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-group" ng-if="field == 'id_assignee'">
|
||||
<select class="custom-select custom-select-sm" id="{{ field }}" ng-model="claim[field]" ng-options="a.id as a.name for a in assignees"><option></option></select>
|
||||
<div class="input-group-append" ng-if="whoami">
|
||||
<button type="button" class="btn btn-sm" ng-class="{'disabled': whoami == claim[field]}" ng-click="assignToMe()">Me l'assigner</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" ng-class="{'disabled': whoami == claim[field]}" ng-click="assignToMe()">Me l'assigner</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -36,7 +42,11 @@
|
||||
<textarea class="form-control form-control-sm" placeholder="Ajouter un commentaire" rows="1" id="ndescription" ng-model="ndescription" autofocus></textarea>
|
||||
</div>
|
||||
|
||||
<div ng-repeat="description in claim.descriptions | orderBy:'id':true" class="alert text-light" ng-class="{'alert-info': '' + description.id_assignee != whoami, 'alert-dark': '' + description.id_assignee == whoami}">
|
||||
<div class="form-group text-right" ng-show="claim.id && ndescription.length">
|
||||
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Ajouter commentaire</button>
|
||||
</div>
|
||||
|
||||
<div ng-repeat="description in claim.descriptions | orderBy:'id':true" class="alert" ng-class="{'alert-info': '' + description.id_assignee != whoami, 'alert-dark': '' + description.id_assignee == whoami}">
|
||||
<strong>Par <em ng-if="!description.id_assignee">anonymous</em> <span ng-repeat="assignee in assignees" ng-if="assignee.id == description.id_assignee">{{ assignee.name }}</span> le {{ description.date | date:"mediumTime" }} :</strong>
|
||||
{{ description.content }}
|
||||
</div>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user