admin: can sort claim by last_update

This commit is contained in:
nemunaire 2020-01-24 18:24:20 +01:00
parent 83b7df7e69
commit d8584a8a31
4 changed files with 31 additions and 2 deletions

View File

@ -32,6 +32,7 @@ func init() {
router.POST("/api/claims/:cid", apiHandler(claimHandler(addClaimDescription)))
router.DELETE("/api/claims/:cid", apiHandler(claimHandler(deleteClaim)))
router.GET("/api/claims/:cid/last_update", apiHandler(claimHandler(getClaimLastUpdate)))
router.PUT("/api/claims/:cid/descriptions", apiHandler(claimHandler(updateClaimDescription)))
// Assignees
@ -55,6 +56,10 @@ func getExerciceClaims(exercice fic.Exercice, _ []byte) (interface{}, error) {
return exercice.GetClaims()
}
func getClaimLastUpdate(claim fic.Claim, _ []byte) (interface{}, error) {
return claim.GetLastUpdate()
}
type ClaimExported struct {
Id int64 `json:"id"`
Subject string `json:"subject"`

View File

@ -1092,7 +1092,7 @@ angular.module("FICApp")
$scope.assignees = ClaimAssignee.query();
$scope.whoami = getCookie("myassignee");
$scope.teams = Teams.get();
$scope.fields = ["subject", "id_team", "state", "id_assignee", "creation", "id"];
$scope.fields = ["subject", "id_team", "state", "id_assignee", "last_update", "id"];
$scope.order = "priority";
$scope.chOrder = function(no) {
@ -1108,6 +1108,19 @@ angular.module("FICApp")
$location.url("/claims/" + id);
};
})
.controller("ClaimLastUpdateController", function($scope, $http) {
$scope.init = function(claim) {
$http.get("/api/claims/" + claim.id + "/last_update").then(function(response) {
if (response.data)
$scope.last_update = response.data;
else
$scope.last_update = claim.creation;
claim.last_update = $scope.last_update;
}, function(response) {
$scope.last_update = claim.creation;
})
}
})
.controller("ClaimController", function($scope, Claim, ClaimAssignee, Teams, Exercice, $routeParams, $location, $http, $rootScope) {
$scope.claim = Claim.get({ claimId: $routeParams.claimId }, function(v) {
v.id_team = "" + v.id_team;

View File

@ -28,7 +28,7 @@
<tbody>
<tr ng-repeat="claim in claims | filter: query | orderBy:order" ng-click="show(claim.id)" ng-class="{'table-info': claim.priority == 'medium', 'table-warning': claim.priority == 'high', 'table-danger': claim.priority == 'critical'}" ng-if="(showClosed || (claim.state != 'closed' && claim.state != 'invalid')) && (!showOnlyMines || claim.id_assignee == whoami) && (!showOnlyUnassigned || !claim.id_assignee)">
<td ng-repeat="field in fields">
<span ng-if="field != 'id_assignee' && field != 'id_team'">
<span ng-if="field != 'id_assignee' && field != 'id_team' && field != 'last_update'">
{{ claim[field] }}
</span>
<span ng-if="field == 'id_assignee'">
@ -36,6 +36,11 @@
{{ assignee.name }}
</span>
</span>
<span ng-if="field == 'last_update'">
<span ng-controller="ClaimLastUpdateController" ng-init="init(claim)">
{{ last_update }}
</span>
</span>
<span ng-if="field == 'id_team'">
<a ng-href="teams/{{ claim.id_team }}">{{ teams[claim.id_team].name }}</a>
</span>

View File

@ -193,6 +193,12 @@ type ClaimDescription struct {
Publish bool `json:"publish"`
}
// GetLastUpdate returns the date of the latest message written for the given Claim.
func (c Claim) GetLastUpdate() (res *time.Time, err error) {
err = DBQueryRow("SELECT MAX(date) FROM claim_descriptions WHERE id_claim = ? GROUP BY id_claim", c.Id).Scan(&res)
return
}
// GetDescriptions returns a list of all descriptions stored in the database for the Claim.
func (c Claim) GetDescriptions() (res []ClaimDescription, err error) {
var rows *sql.Rows