Edit dialog: Make additional fields savable #212 #217

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-01-24 10:25:08 +01:00
parent 2c69c276e3
commit 49b329d45c
5 changed files with 84 additions and 63 deletions

View file

@ -168,7 +168,16 @@
v-model="model.PhotoAltitude" v-model="model.PhotoAltitude"
></v-text-field> ></v-text-field>
</v-flex> </v-flex>
<v-flex xs12 sm6 md3 class="pa-2">
<v-text-field
disabled
hide-details
label="Views"
placeholder=""
color="secondary-dark"
v-model="model.PhotoViews"
></v-text-field>
</v-flex>
<v-flex xs12 sm6 md3 class="pa-2"> <v-flex xs12 sm6 md3 class="pa-2">
<v-text-field <v-text-field
hide-details hide-details
@ -207,17 +216,6 @@
v-model="model.PhotoExposure" v-model="model.PhotoExposure"
></v-text-field> ></v-text-field>
</v-flex> </v-flex>
<v-flex xs12 sm6 md3 class="pa-2">
<v-text-field
disabled
hide-details
label="Views"
placeholder=""
color="secondary-dark"
v-model="model.PhotoViews"
></v-text-field>
</v-flex>
<v-flex xs12 sm6 md3 class="pa-2"> <v-flex xs12 sm6 md3 class="pa-2">
<v-text-field <v-text-field
@ -285,11 +283,8 @@
></v-textarea> ></v-textarea>
</v-flex> </v-flex>
<v-flex xs12 text-xs-right class="pt-3"> <v-flex xs12 text-xs-right class="pt-3">
<span class="subheading pb-3">
Note: This is a first draft and may contain bugs
</span>
<v-btn @click.stop="cancel" depressed color="secondary-light" class="p-photo-dialog-cancel"> <v-btn @click.stop="cancel" depressed color="secondary-light" class="p-photo-dialog-cancel">
<translate>Cancel</translate> <translate>Close</translate>
</v-btn> </v-btn>
<v-btn color="secondary-dark" depressed dark @click.stop="save" <v-btn color="secondary-dark" depressed dark @click.stop="save"
class="p-photo-dialog-confirm"> class="p-photo-dialog-confirm">
@ -353,12 +348,14 @@
if(!this.date) { if(!this.date) {
return ""; return "";
} }
return DateTime.fromISO(this.date).toLocaleString(DateTime.DATE_FULL); return DateTime.fromISO(this.date).toLocaleString(DateTime.DATE_FULL);
}, },
timeFormatted() { timeFormatted() {
if(!this.time) { if(!this.time) {
return ""; return "";
} }
return DateTime.fromISO(this.time).toLocaleString(DateTime.TIME_24_WITH_SECONDS); return DateTime.fromISO(this.time).toLocaleString(DateTime.TIME_24_WITH_SECONDS);
}, },
countryOptions() { countryOptions() {
@ -387,12 +384,16 @@
model.refreshFileAttr(); model.refreshFileAttr();
if(model.TakenAt) { if(model.TakenAt) {
this.date = DateTime.fromISO(model.TakenAt).toISODate(); const date = DateTime.fromISO(model.TakenAt).toUTC();
this.date = date.toISODate();
this.time = DateTime.fromISO(model.TakenAt).toFormat("HH:mm:ss"); this.time = date.toFormat("HH:mm:ss");
} }
}, },
save() { save() {
if(this.time && this.date) {
this.model.TakenAt = this.date + "T" + this.time + "Z";
}
this.model.update(); this.model.update();
}, },
cancel() { cancel() {

View file

@ -2,7 +2,7 @@
<div class="p-tab p-tab-photo-edit-todo"> <div class="p-tab p-tab-photo-edit-todo">
<v-container fluid> <v-container fluid>
<p class="subheading pb-3"> <p class="subheading pb-3">
This is a first draft for an edit dialog. Feedback and contributions welcome. This is work in progress. Feedback and contributions welcome.
</p> </p>
</v-container> </v-container>
</div> </div>

View file

@ -25,12 +25,32 @@ class Abstract {
return this; return this;
} }
getValues() { getValues(changed) {
const result = {}; const result = {};
const defaults = this.getDefaults();
for (let key in this.__originalValues) { for (let key in this.__originalValues) {
if (this.__originalValues.hasOwnProperty(key) && key !== "__originalValues") { if (this.__originalValues.hasOwnProperty(key) && key !== "__originalValues") {
result[key] = this[key]; let val;
if (defaults.hasOwnProperty(key)) {
switch (typeof defaults[key]) {
case "bigint":
case "number":
val = parseFloat(this[key]);
break;
case "boolean":
val = !!this[key];
break;
default:
val = this[key];
}
} else {
val = this[key];
}
if(!changed || val !== this.__originalValues[key]) {
result[key] = val;
}
} }
} }
@ -62,7 +82,7 @@ class Abstract {
} }
update() { update() {
return Api.put(this.getEntityResource(), this.getValues()).then((response) => Promise.resolve(this.setValues(response.data))); return Api.put(this.getEntityResource(), this.getValues(true)).then((response) => Promise.resolve(this.setValues(response.data)));
} }
remove() { remove() {

View file

@ -25,7 +25,7 @@ class Photo extends Abstract {
PhotoAltitude: 0, PhotoAltitude: 0,
PhotoFocalLength: 0, PhotoFocalLength: 0,
PhotoIso: 0, PhotoIso: 0,
PhotoFNumber: 0, PhotoFNumber: 0.0,
PhotoExposure: "", PhotoExposure: "",
PhotoViews: 0, PhotoViews: 0,
Camera: {}, Camera: {},

View file

@ -12,49 +12,49 @@ import (
// A photo can have multiple images and sidecar files // A photo can have multiple images and sidecar files
type Photo struct { type Photo struct {
ID uint `gorm:"primary_key"` ID uint `gorm:"primary_key"`
TakenAt time.Time `gorm:"type:datetime;index:idx_photos_taken_uuid;"` TakenAt time.Time `gorm:"type:datetime;index:idx_photos_taken_uuid;" json:"TakenAt"`
PhotoUUID string `gorm:"type:varbinary(36);unique_index;index:idx_photos_taken_uuid;"` PhotoUUID string `gorm:"type:varbinary(36);unique_index;index:idx_photos_taken_uuid;"`
PhotoPath string `gorm:"type:varbinary(512);index;"` PhotoPath string `gorm:"type:varbinary(512);index;"`
PhotoName string `gorm:"type:varbinary(256);"` PhotoName string `gorm:"type:varbinary(256);"`
PhotoTitle string `json:"PhotoTitle"` PhotoTitle string `json:"PhotoTitle"`
PhotoTitleChanged bool PhotoTitleChanged bool `json:"PhotoTitleChanged"`
PhotoDescription string `gorm:"type:text;"` PhotoDescription string `gorm:"type:text;" json:"PhotoDescription"`
PhotoNotes string `gorm:"type:text;"` PhotoNotes string `gorm:"type:text;" json:"PhotoNotes"`
PhotoArtist string `json:"PhotoArtist"` PhotoArtist string `json:"PhotoArtist"`
PhotoCopyright string `json:"PhotoCopyright"` PhotoCopyright string `json:"PhotoCopyright"`
PhotoFavorite bool `json:"PhotoFavorite"` PhotoFavorite bool `json:"PhotoFavorite"`
PhotoPrivate bool `json:"PhotoPrivate"` PhotoPrivate bool `json:"PhotoPrivate"`
PhotoNSFW bool `json:"PhotoNSFW"` PhotoNSFW bool `json:"PhotoNSFW"`
PhotoStory bool `json:"PhotoStory"` PhotoStory bool `json:"PhotoStory"`
PhotoLat float64 `gorm:"index;"` PhotoLat float64 `gorm:"index;" json:"PhotoLat"`
PhotoLng float64 `gorm:"index;"` PhotoLng float64 `gorm:"index;" json:"PhotoLng"`
PhotoAltitude int PhotoAltitude int `json:"PhotoAltitude"`
PhotoFocalLength int PhotoFocalLength int `json:"PhotoFocalLength"`
PhotoIso int PhotoIso int `json:"PhotoIso"`
PhotoFNumber float64 PhotoFNumber float64 `json:"PhotoFNumber"`
PhotoExposure string `gorm:"type:varbinary(64);"` PhotoExposure string `gorm:"type:varbinary(64);" json:"PhotoExposure"`
PhotoViews uint CameraID uint `gorm:"index:idx_photos_camera_lens;" json:"CameraID"`
Camera *Camera LensID uint `gorm:"index:idx_photos_camera_lens;" json:"LensID"`
CameraID uint `gorm:"index:idx_photos_camera_lens;"` LocationID string `gorm:"type:varbinary(16);index;" json:"LocationID"`
Lens *Lens PlaceID string `gorm:"type:varbinary(16);index;" json:"PlaceID"`
LensID uint `gorm:"index:idx_photos_camera_lens;"` LocationChanged bool `json:"LocationChanged"`
CountryChanged bool LocationEstimated bool `json:"LocationEstimated"`
Location *Location PhotoCountry string `gorm:"index:idx_photos_country_year_month;" json:"PhotoCountry"`
LocationID string `gorm:"type:varbinary(16);index;"`
Place *Place
PlaceID string `gorm:"type:varbinary(16);index;"`
LocationChanged bool
LocationEstimated bool
PhotoCountry string `gorm:"index:idx_photos_country_year_month;"`
PhotoYear int `gorm:"index:idx_photos_country_year_month;"` PhotoYear int `gorm:"index:idx_photos_country_year_month;"`
PhotoMonth int `gorm:"index:idx_photos_country_year_month;"` PhotoMonth int `gorm:"index:idx_photos_country_year_month;"`
TimeZone string `gorm:"type:varbinary(64);" json:"TimeZone"`
TakenAtLocal time.Time `gorm:"type:datetime;"` TakenAtLocal time.Time `gorm:"type:datetime;"`
TakenAtChanged bool TakenAtChanged bool
TimeZone string `gorm:"type:varbinary(64);"` PhotoViews uint
CountryChanged bool
Camera *Camera `json:"-"`
Lens *Lens `json:"-"`
Location *Location `json:"-"`
Place *Place `json:"-"`
Files []File Files []File
Labels []Label Labels []Label
Keywords []Keyword Keywords []Keyword `json:"-"`
Albums []Album Albums []Album `json:"-"`
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time
DeletedAt *time.Time `sql:"index"` DeletedAt *time.Time `sql:"index"`