diff --git a/frontend/src/common/api.js b/frontend/src/common/api.js index 57dac613c..8a40dbbfb 100644 --- a/frontend/src/common/api.js +++ b/frontend/src/common/api.js @@ -25,6 +25,12 @@ Api.interceptors.request.use(function (config) { Api.interceptors.response.use(function (response) { Notify.ajaxEnd(); + + if(typeof response.data == "string") { + Notify.error("Request failed - invalid response"); + console.warn("WARNING: Server returned HTML instead of JSON - API not implemented?") + } + return response; }, function (error) { Notify.ajaxEnd(); diff --git a/frontend/src/component/p-photo-details.vue b/frontend/src/component/p-photo-details.vue index 0e1257c2d..18dbaeb16 100644 --- a/frontend/src/component/p-photo-details.vue +++ b/frontend/src/component/p-photo-details.vue @@ -8,7 +8,7 @@ - + - + - + - + - {{ album.AlbumName | capitalize }} + + {{ album.AlbumName | capitalize }} + + + + star @@ -116,6 +140,7 @@ filter: filter, lastFilter: {}, routeName: routeName, + titleRule: v => v.length <= 25 || 'Title too long', }; }, methods: { @@ -230,6 +255,19 @@ this.search(); }) }, + onSave (album) { + console.log('onSave', album); + album.update().then(() => this.$notify.success("All changes saved")); + }, + onCancel () { + console.log('onCancel', arguments) + }, + onDialogOpen () { + console.log('onDialogOpen', arguments) + }, + onDialogClose () { + console.log('onDialogClose', arguments) + }, }, created() { this.search(); diff --git a/internal/api/albums.go b/internal/api/albums.go index fa1cb18b2..e7a0dbdf7 100644 --- a/internal/api/albums.go +++ b/internal/api/albums.go @@ -41,7 +41,7 @@ func GetAlbums(router *gin.RouterGroup, conf *config.Config) { }) } -type CreateAlbumParams struct { +type AlbumParams struct { AlbumName string `json:"AlbumName"` } @@ -53,7 +53,7 @@ func CreateAlbum(router *gin.RouterGroup, conf *config.Config) { return } - var params CreateAlbumParams + var params AlbumParams if err := c.BindJSON(¶ms); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())}) @@ -72,6 +72,38 @@ func CreateAlbum(router *gin.RouterGroup, conf *config.Config) { }) } +// PUT /api/v1/albums/:uuid +func UpdateAlbum(router *gin.RouterGroup, conf *config.Config) { + router.PUT("/albums/:uuid", func(c *gin.Context) { + if Unauthorized(c, conf) { + c.AbortWithStatusJSON(http.StatusUnauthorized, ErrUnauthorized) + return + } + + var params AlbumParams + + if err := c.BindJSON(¶ms); err != nil { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())}) + return + } + + id := c.Param("uuid") + search := photoprism.NewSearch(conf.OriginalsPath(), conf.Db()) + + m, err := search.FindAlbumByUUID(id) + + if err != nil { + c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())}) + return + } + + m.AlbumName = params.AlbumName + conf.Db().Save(&m) + + c.JSON(http.StatusOK, m) + }) +} + // POST /api/v1/albums/:uuid/like // // Parameters: diff --git a/internal/server/routes.go b/internal/server/routes.go index 8d42b9a6d..1b9be2bd2 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -46,6 +46,7 @@ func registerRoutes(router *gin.Engine, conf *config.Config) { api.DislikeAlbum(v1, conf) api.AlbumThumbnail(v1, conf) api.CreateAlbum(v1, conf) + api.UpdateAlbum(v1, conf) api.GetSettings(v1, conf) api.SaveSettings(v1, conf)