admin: Show what properties will be overwritted

This commit is contained in:
nemunaire 2023-03-20 11:23:27 +01:00
parent eb85b28f5b
commit 3fcf705dcf
2 changed files with 27 additions and 49 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"reflect"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -528,62 +529,36 @@ func updateExercice(c *gin.Context) {
c.JSON(http.StatusOK, ue) c.JSON(http.StatusOK, ue)
} }
type patchExercice struct {
Language *string `json:"lang,omitempty"`
Title *string `json:"title"`
Disabled *bool `json:"disabled"`
WIP *bool `json:"wip"`
URLId *string `json:"urlid"`
Statement *string `json:"statement"`
Overview *string `json:"overview"`
Headline *string `json:"headline"`
Finished *string `json:"finished"`
Issue *string `json:"issue"`
IssueKind *string `json:"issuekind"`
Gain *int64 `json:"gain"`
Coefficient *float64 `json:"coefficient"`
}
func partUpdateExercice(c *gin.Context) { func partUpdateExercice(c *gin.Context) {
exercice := c.MustGet("exercice").(*fic.Exercice) exercice := c.MustGet("exercice").(*fic.Exercice)
var ue fic.Exercice var ue patchExercice
err := c.ShouldBindJSON(&ue) err := c.ShouldBindJSON(&ue)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
return return
} }
if len(ue.Title) > 0 { for _, field := range reflect.VisibleFields(reflect.TypeOf(ue)) {
exercice.Title = ue.Title if !reflect.ValueOf(ue).FieldByName(field.Name).IsNil() {
reflect.ValueOf(exercice).Elem().FieldByName(field.Name).Set(reflect.ValueOf(reflect.ValueOf(ue).FieldByName(field.Name).Elem().Interface()))
} }
if len(ue.URLId) > 0 {
exercice.URLId = ue.URLId
}
if len(ue.Statement) > 0 {
exercice.Statement = ue.Statement
}
if len(ue.Headline) > 0 {
exercice.Headline = ue.Headline
}
if len(ue.Finished) > 0 {
exercice.Finished = ue.Finished
}
if len(ue.Overview) > 0 {
exercice.Overview = ue.Overview
}
if len(ue.Issue) > 0 {
exercice.Issue = ue.Issue
}
if len(ue.IssueKind) > 0 {
exercice.IssueKind = ue.IssueKind
}
if ue.Depend != nil {
exercice.Depend = ue.Depend
}
if ue.Gain != 0 {
exercice.Gain = ue.Gain
}
if ue.Coefficient != 0 {
exercice.Coefficient = ue.Coefficient
}
if len(ue.VideoURI) > 0 {
exercice.VideoURI = ue.VideoURI
} }
if _, err := exercice.Update(); err != nil { if _, err := exercice.Update(); err != nil {

View File

@ -74,9 +74,12 @@
<form ng-submit="updateExercices()"> <form ng-submit="updateExercices()">
<fieldset> <fieldset>
<legend class="text-dark">Édition de masse <button type="submit" class="float-right btn btn-sm btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button></legend> <legend class="text-dark">Édition de masse <button type="submit" class="float-right btn btn-sm btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button></legend>
<div class="form-group row" ng-class="{'row': field != 'disabled'}" ng-repeat="field in ['disabled','gain','coefficient','issue','issuekind']"> <p>
Les propriétés en gras seront écrasées.
</p>
<div ng-class="{'row': field != 'disabled', 'form-group': field != 'disabled', 'form-check': field == 'disabled'}" ng-repeat="field in ['disabled','gain','coefficient','issue','issuekind']">
<input type="checkbox" class="form-check-input" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'disabled'"> <input type="checkbox" class="form-check-input" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'disabled'">
<label for="{{ field }}" class="col-form-label-sm" ng-class="{'col-sm-1': field != 'disabled'}">{{ field | capitalize }}</label> <label for="{{ field }}" class="col-form-label-sm" ng-class="{'col-sm-1': field != 'disabled', 'font-weight-bold': exercice[field] !== undefined}">{{ field | capitalize }}</label>
<div class="col-sm-11" ng-if="field != 'disabled'"> <div class="col-sm-11" ng-if="field != 'disabled'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'"> <input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'issue' && field != 'issuekind' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer> <input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer>