New info about country: since
This commit is contained in:
parent
4959df8af7
commit
84079e7cfa
|
@ -82,7 +82,7 @@ func newCountry(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
cntry, err := euroc.NewCountry(uc.Label, uc.Icon)
|
||||
cntry, err := euroc.NewCountry(uc.Label, uc.Icon, uc.Since)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
|
|
|
@ -76,6 +76,16 @@ angular.module("EuroCollecApp")
|
|||
});
|
||||
|
||||
angular.module("EuroCollecApp")
|
||||
.directive('integer', function() {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, ele, attr, ctrl){
|
||||
ctrl.$parsers.unshift(function(viewValue){
|
||||
return parseInt(viewValue, 10);
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
||||
.filter("ucfirst", function() {
|
||||
return function(input) {
|
||||
if (input === undefined)
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
<small id="cimgHelp" class="form-text text-muted">L'image doit d'abord être placée sur le serveur, avant de pouvoir être utilisée ici.</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="csince">Entrée dans l'Euro :</label>
|
||||
<input type="text" class="form-control" id="csince" aria-describedby="csinceHelp" placeholder="2004" ng-model="country.since" integer>
|
||||
<small id="csinceHelp" class="form-text text-muted">Indiquez ici la date où le pays est entré dans l'Euro, ou bien la première année à partir de laquelle il a pu commencer à émettre des pièces commémoratives.</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">Enregistrer le pays</button>
|
||||
<a href="countries/{{ original_label }}" class="btn btn-secondary">Annuler</button>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<img class="flag-icon" ng-src="img/country/{{ country.icon }}" ng-alt="{{ country.label }}">
|
||||
{{ country.label }}
|
||||
</td>
|
||||
<td ng-repeat="y in years" ng-class="{'bg-danger': !countryStats.years[y] || countryStats.years[y].total_exists == 0, 'bg-success': countryStats.years[y] && countryStats.years[y].total_exists == countryStats.years[y].total_have, 'bg-warning': countryStats.years[y] && countryStats.years[y].total_exists != countryStats.years[y].total_have}">
|
||||
<td ng-repeat="y in years" ng-class="{'bg-secondary': !countryStats.years[y] && country.since > y, 'bg-danger': (!countryStats.years[y] && country.since <= y) || countryStats.years[y].total_exists == 0, 'bg-success': countryStats.years[y] && countryStats.years[y].total_exists == countryStats.years[y].total_have, 'bg-warning': countryStats.years[y] && countryStats.years[y].total_exists != countryStats.years[y].total_have}">
|
||||
<span ng-show="countryStats.years[y]">
|
||||
{{ countryStats.years[y].total_have }}/{{ countryStats.years[y].total_exists }}
|
||||
</span>
|
||||
|
|
|
@ -5,18 +5,19 @@ import ()
|
|||
type Country struct {
|
||||
Id int64 `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Icon string `json:"icon",omitempty`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Since int `json:"since"`
|
||||
}
|
||||
|
||||
func GetCountries() (countries []*Country, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_country, label, icon FROM countries ORDER BY label"); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_country, label, icon, since FROM countries ORDER BY label"); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var c Country
|
||||
if err = rows.Scan(&c.Id, &c.Label, &c.Icon); err != nil {
|
||||
if err = rows.Scan(&c.Id, &c.Label, &c.Icon, &c.Since); err != nil {
|
||||
return
|
||||
}
|
||||
countries = append(countries, &c)
|
||||
|
@ -31,22 +32,22 @@ func GetCountries() (countries []*Country, err error) {
|
|||
|
||||
func GetCountry(id int64) (*Country, error) {
|
||||
var c Country
|
||||
err := DBQueryRow("SELECT id_country, label, icon FROM countries WHERE id_country = ?", id).Scan(&c.Id, &c.Label, &c.Icon)
|
||||
err := DBQueryRow("SELECT id_country, label, icon, since FROM countries WHERE id_country = ?", id).Scan(&c.Id, &c.Label, &c.Icon, &c.Since)
|
||||
return &c, err
|
||||
}
|
||||
|
||||
func NewCountry(label string, icon string) (*Country, error) {
|
||||
if res, err := DBExec("INSERT INTO countries (label, icon) VALUES (?, ?)", label, icon); err != nil {
|
||||
func NewCountry(label string, icon string, since int) (*Country, error) {
|
||||
if res, err := DBExec("INSERT INTO countries (label, icon, since) VALUES (?, ?, ?)", label, icon, since); err != nil {
|
||||
return nil, err
|
||||
} else if cid, err := res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Country{cid, label, icon}, nil
|
||||
return &Country{cid, label, icon, since}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Country) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE countries SET label = ?, icon = ? WHERE id_country = ?", c.Label, c.Icon, c.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE countries SET label = ?, icon = ?, since = ? WHERE id_country = ?", c.Label, c.Icon, c.Since, c.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -64,7 +64,7 @@ func DBInit(dsn string) (err error) {
|
|||
// DBCreate creates all necessary tables used by the package
|
||||
func DBCreate() (err error) {
|
||||
ct := `
|
||||
CREATE TABLE IF NOT EXISTS countries (id_country INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, label VARCHAR(255) NOT NULL, icon VARCHAR(255) NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS countries (id_country INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, label VARCHAR(255) NOT NULL, icon VARCHAR(255) NOT NULL, since SMALLINT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS common_issuances (id_common_issuance INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, label VARCHAR(255) NOT NULL, year DATETIME, icon VARCHAR(255) NOT NULL, description TEXT);
|
||||
CREATE TABLE IF NOT EXISTS coins (id_coin INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, id_common_issuance INTEGER NULL, id_country INTEGER NOT NULL, label TEXT NOT NULL, year DATETIME, icon VARCHAR(255) NOT NULL, description TEXT, engraver VARCHAR(255), copies VARCHAR(255) NOT NULL, slice VARCHAR(255) NOT NULL, FOREIGN KEY(id_country) REFERENCES countries(id_country), FOREIGN KEY(id_common_issuance) REFERENCES common_issuances(id_common_issuance));
|
||||
CREATE TABLE IF NOT EXISTS have_coins (id_have INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, id_coin INTEGER NOT NULL, cleaness ENUM('card', 'new', 'clean', 'used', 'dirty') NOT NULL DEFAULT 'clean', comment VARCHAR(255) NOT NULL, FOREIGN KEY(id_coin) REFERENCES coins(id_coin));
|
||||
|
|
Loading…
Reference in New Issue