From f9b2ff326b63daf812996df4a764ada360338e8a Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 4 May 2020 18:28:23 +0200 Subject: [PATCH] Refactor feature flags and settings Signed-off-by: Michael Mayer --- assets/config/settings.yml | 17 +- frontend/src/component/p-navigation.vue | 5 +- frontend/src/component/p-photo-cards.vue | 2 +- frontend/src/component/p-photo-clipboard.vue | 2 +- frontend/src/component/p-photo-list.vue | 2 +- frontend/src/component/p-photo-mosaic.vue | 2 +- frontend/src/dialog/p-photo-edit-dialog.vue | 2 +- frontend/src/dialog/p-upload-dialog.vue | 4 +- frontend/src/dialog/photo/details.vue | 2 +- frontend/src/pages/library.vue | 4 +- frontend/src/pages/library/import.vue | 13 +- frontend/src/pages/library/originals.vue | 22 +- frontend/src/pages/photos.vue | 4 +- frontend/src/pages/settings/general.vue | 211 +++++++++---------- internal/api/index.go | 6 +- internal/config/settings.go | 42 ++-- internal/config/testdata/configEmpty.yml | 17 +- internal/form/index_options.go | 6 +- internal/photoprism/convert.go | 8 +- internal/photoprism/import.go | 2 +- internal/photoprism/import_worker.go | 2 +- internal/photoprism/index.go | 2 +- internal/photoprism/index_mediafile.go | 2 +- internal/workers/sync_download.go | 4 +- 24 files changed, 199 insertions(+), 184 deletions(-) diff --git a/assets/config/settings.yml b/assets/config/settings.yml index 44d5bbfc0..df939bf97 100755 --- a/assets/config/settings.yml +++ b/assets/config/settings.yml @@ -4,19 +4,22 @@ maps: animate: 0 style: streets features: + archive: true + private: true + review: true upload: true import: true labels: true places: true - archive: true download: true edit: true share: true -library: - raw: false - thumbs: false - rescan: false + logs: true +import: + path: "" move: false - private: true - review: true +library: + convert: true + resample: true + rescan: false group: true diff --git a/frontend/src/component/p-navigation.vue b/frontend/src/component/p-navigation.vue index 96a8d9dcd..907a6bf93 100644 --- a/frontend/src/component/p-navigation.vue +++ b/frontend/src/component/p-navigation.vue @@ -79,7 +79,7 @@ - + Review @@ -109,8 +109,7 @@ - + lock diff --git a/frontend/src/component/p-photo-cards.vue b/frontend/src/component/p-photo-cards.vue index 685003c7f..b7ac3bb1f 100644 --- a/frontend/src/component/p-photo-cards.vue +++ b/frontend/src/component/p-photo-cards.vue @@ -130,7 +130,7 @@ data() { return { showLocation: this.$config.settings().features.places, - hidePrivate: this.$config.settings().library.private, + hidePrivate: this.$config.settings().features.private, debug: this.$config.get('debug'), mouseDown: { index: -1, diff --git a/frontend/src/component/p-photo-clipboard.vue b/frontend/src/component/p-photo-clipboard.vue index 5c6e370e8..bc5655e33 100644 --- a/frontend/src/component/p-photo-clipboard.vue +++ b/frontend/src/component/p-photo-clipboard.vue @@ -56,7 +56,7 @@ color="private" :disabled="selection.length === 0" @click.stop="batchPrivate" - v-if="context !== 'archive' && config.settings.library.private" + v-if="context !== 'archive' && config.settings.features.private" class="p-photo-clipboard-private" > lock diff --git a/frontend/src/component/p-photo-list.vue b/frontend/src/component/p-photo-list.vue index d2ab64c9a..a129f0e12 100644 --- a/frontend/src/component/p-photo-list.vue +++ b/frontend/src/component/p-photo-list.vue @@ -94,7 +94,7 @@ {text: '', value: '', sortable: false, align: 'center'}, ], showLocation: this.$config.settings().features.places, - hidePrivate: this.$config.settings().library.private, + hidePrivate: this.$config.settings().features.private, mouseDown: { index: -1, timeStamp: -1, diff --git a/frontend/src/component/p-photo-mosaic.vue b/frontend/src/component/p-photo-mosaic.vue index 8bb3da4c8..c379f9ac8 100644 --- a/frontend/src/component/p-photo-mosaic.vue +++ b/frontend/src/component/p-photo-mosaic.vue @@ -91,7 +91,7 @@ }, data() { return { - hidePrivate: this.$config.settings().library.private, + hidePrivate: this.$config.settings().features.private, mouseDown: { index: -1, timeStamp: -1, diff --git a/frontend/src/dialog/p-photo-edit-dialog.vue b/frontend/src/dialog/p-photo-edit-dialog.vue index e2e442a66..c623a1cc9 100644 --- a/frontend/src/dialog/p-photo-edit-dialog.vue +++ b/frontend/src/dialog/p-photo-edit-dialog.vue @@ -87,7 +87,7 @@ this.$gettext("Edit Photo"); }, isPrivate: function () { - if (this.model && this.model.PhotoPrivate && this.$config.settings().library.private) { + if (this.model && this.model.PhotoPrivate && this.$config.settings().features.private) { return this.model.PhotoPrivate } diff --git a/frontend/src/dialog/p-upload-dialog.vue b/frontend/src/dialog/p-upload-dialog.vue index 8030e73df..28f1e2644 100644 --- a/frontend/src/dialog/p-upload-dialog.vue +++ b/frontend/src/dialog/p-upload-dialog.vue @@ -73,7 +73,7 @@ total: 0, completed: 0, started: 0, - review: this.$config.settings().library.review, + review: this.$config.settings().features.review, safe: !this.$config.get("uploadNSFW"), } }, @@ -176,7 +176,7 @@ this.total = 0; this.completed = 0; this.started = 0; - this.review = this.$config.settings().library.review; + this.review = this.$config.feature("review"); this.safe = !this.$config.get("uploadNSFW"); } }, diff --git a/frontend/src/dialog/photo/details.vue b/frontend/src/dialog/photo/details.vue index 050a3bf57..ee542d28c 100644 --- a/frontend/src/dialog/photo/details.vue +++ b/frontend/src/dialog/photo/details.vue @@ -361,7 +361,7 @@ - Approve + Approve Apply Import - + Logs @@ -29,7 +29,7 @@ - + diff --git a/frontend/src/pages/library/import.vue b/frontend/src/pages/library/import.vue index 2edc11d93..abe341a93 100644 --- a/frontend/src/pages/library/import.vue +++ b/frontend/src/pages/library/import.vue @@ -17,9 +17,10 @@ @@ -35,10 +35,10 @@ @change="onChange" :disabled="busy" class="ma-0 pa-0" - v-model="settings.library.thumbs" + v-model="settings.library.resample" color="secondary-dark" - :label="labels.thumbs" - :hint="hints.thumbs" + :label="labels.resample" + :hint="hints.resample" prepend-icon="photo_size_select_large" persistent-hint > @@ -91,7 +91,7 @@ import Axios from "axios"; import Notify from "common/notify"; import Event from "pubsub-js"; - import Settings from "../../model/settings"; + import Settings from "model/settings"; export default { name: 'p-tab-index', @@ -108,13 +108,13 @@ source: null, labels: { rescan: this.$gettext("Complete rescan"), - thumbs: this.$gettext("Create thumbnails"), - raw: this.$gettext("Convert RAW files"), + resample: this.$gettext("Create thumbnails"), + convert: this.$gettext("Convert RAW files"), }, hints: { rescan: this.$gettext("Re-index all originals, including already indexed and unchanged files."), - thumbs: this.$gettext("Pre-render thumbnails if not done already. On-demand rendering saves storage but requires a powerful CPU."), - raw: this.$gettext("RAWs need to be converted to JPEG so that they can be displayed in a browser. You can also do this manually."), + resample: this.$gettext("Pre-render thumbnails if not done already. On-demand rendering saves storage but requires a powerful CPU."), + convert: this.$gettext("RAWs need to be converted to JPEG so that they can be displayed in a browser. You can also do this manually."), } } }, diff --git a/frontend/src/pages/photos.vue b/frontend/src/pages/photos.vue index a7870a730..a5a75e0ac 100644 --- a/frontend/src/pages/photos.vue +++ b/frontend/src/pages/photos.vue @@ -87,11 +87,11 @@ const settings = this.$config.settings(); - if (settings.library.private) { + if (settings.features.private) { filter.public = true; } - if (settings.library.review) { + if (settings.features.review) { filter.quality = 3; } diff --git a/frontend/src/pages/settings/general.vue b/frontend/src/pages/settings/general.vue index 5dc951a21..71143b365 100644 --- a/frontend/src/pages/settings/general.vue +++ b/frontend/src/pages/settings/general.vue @@ -15,7 +15,22 @@ @change="onChange" :disabled="busy" class="ma-0 pa-0" - v-model="settings.library.private" + v-model="settings.features.archive" + color="secondary-dark" + :label="labels.archive" + :hint="hints.archive" + prepend-icon="archive" + persistent-hint + > + + + + + + + + - - + +

User Interface

+
+ + + + + -
+ background-color="secondary-light" + v-model="settings.theme" + hide-details box + > +
+ + + - -

Features

-
- - - - - - - - - - - - - - - - - - - - - + + + + + - - -
- - -

User Interface

-
- - - - - + + :label="labels.labels" + :hint="hints.labels" + prepend-icon="label" + persistent-hint + > + - - + + :label="labels.logs" + :hint="hints.logs" + prepend-icon="notes" + persistent-hint + > + + + + + + @@ -318,17 +314,18 @@ thumbs: this.$gettext("Create thumbnails"), raw: this.$gettext("Convert RAW files"), move: this.$gettext("Remove imported files"), - group: this.$gettext("Group related files"), - private: this.$gettext("Hide private content"), - review: this.$gettext("Apply quality filter"), + group: this.$gettext("Group Sequential"), + archive: this.$gettext("Photo Archive"), + private: this.$gettext("Hide Private"), + review: this.$gettext("Quality Filter"), places: this.$gettext("Places"), labels: this.$gettext("Labels"), import: this.$gettext("Import"), - archive: this.$gettext("Archive"), upload: this.$gettext("Upload"), download: this.$gettext("Download"), edit: this.$gettext("Edit"), share: this.$gettext("Share"), + logs: this.$gettext("Logs"), }, hints: { private: this.$gettext("Exclude photos marked as private from search results by default."), @@ -343,7 +340,7 @@ download: this.$gettext("Download single files and zip archives."), edit: this.$gettext("Change photo titles, locations and other metadata."), share: this.$gettext("Upload to WebDAV and other remote services."), - + logs: this.$gettext("Show logs tab on library page."), }, busy: false, }; diff --git a/internal/api/index.go b/internal/api/index.go index c5ba1dc5e..963ddace4 100644 --- a/internal/api/index.go +++ b/internal/api/index.go @@ -42,7 +42,7 @@ func StartIndexing(router *gin.RouterGroup, conf *config.Config) { c.JSON(http.StatusOK, gin.H{"error": err.Error()}) } - if f.ConvertRaw && !conf.ReadOnly() { + if f.Convert && !conf.ReadOnly() { convert := service.Convert() if err := convert.Start(conf.OriginalsPath()); err != nil { @@ -51,7 +51,7 @@ func StartIndexing(router *gin.RouterGroup, conf *config.Config) { } } - if f.CreateThumbs { + if f.Resample { rs := service.Resample() if err := rs.Start(false); err != nil { @@ -62,7 +62,7 @@ func StartIndexing(router *gin.RouterGroup, conf *config.Config) { ind := service.Index() - if f.CompleteRescan { + if f.Rescan { ind.Start(photoprism.IndexOptionsAll()) } else { ind.Start(photoprism.IndexOptionsNone()) diff --git a/internal/config/settings.go b/internal/config/settings.go index 4fdc3d416..43748b1c4 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -21,24 +21,29 @@ type MapsSettings struct { } type LibrarySettings struct { - ConvertRaw bool `json:"raw" yaml:"raw"` - CreateThumbs bool `json:"thumbs" yaml:"thumbs"` - CompleteRescan bool `json:"rescan" yaml:"rescan"` - MoveImported bool `json:"move" yaml:"move"` - HidePrivate bool `json:"private" yaml:"private"` - RequireReview bool `json:"review" yaml:"review"` - GroupRelated bool `json:"group" yaml:"group"` + Convert bool `json:"convert" yaml:"convert"` + Resample bool `json:"resample" yaml:"resample"` + Rescan bool `json:"rescan" yaml:"rescan"` + Group bool `json:"group" yaml:"group"` +} + +type ImportSettings struct { + Path string `json:"path" yaml:"path"` + Move bool `json:"move" yaml:"move"` } type FeatureSettings struct { + Archive bool `json:"archive" yaml:"archive"` + Private bool `json:"private" yaml:"private"` + Review bool `json:"review" yaml:"review"` Upload bool `json:"upload" yaml:"upload"` Import bool `json:"import" yaml:"import"` Labels bool `json:"labels" yaml:"labels"` Places bool `json:"places" yaml:"places"` - Archive bool `json:"archive" yaml:"archive"` Download bool `json:"download" yaml:"download"` Edit bool `json:"edit" yaml:"edit"` Share bool `json:"share" yaml:"share"` + Logs bool `json:"logs" yaml:"logs"` } // Settings contains Web UI settings @@ -47,6 +52,7 @@ type Settings struct { Language string `json:"language" yaml:"language"` Maps MapsSettings `json:"maps" yaml:"maps"` Features FeatureSettings `json:"features" yaml:"features"` + Import ImportSettings `json:"import" yaml:"import"` Library LibrarySettings `json:"library" yaml:"library"` } @@ -60,23 +66,27 @@ func NewSettings() *Settings { Style: "streets", }, Features: FeatureSettings{ + Archive: true, + Review: true, + Private: true, Upload: true, Import: true, Labels: true, Places: true, - Archive: true, Download: true, Edit: true, Share: true, + Logs: true, + }, + Import: ImportSettings{ + Path: "", + Move: false, }, Library: LibrarySettings{ - CompleteRescan: false, - ConvertRaw: false, - CreateThumbs: false, - MoveImported: false, - GroupRelated: true, - RequireReview: true, - HidePrivate: true, + Rescan: false, + Convert: true, + Resample: true, + Group: true, }, } } diff --git a/internal/config/testdata/configEmpty.yml b/internal/config/testdata/configEmpty.yml index 78811422f..8d6948637 100644 --- a/internal/config/testdata/configEmpty.yml +++ b/internal/config/testdata/configEmpty.yml @@ -4,19 +4,22 @@ maps: animate: 0 style: streets features: + archive: true + private: true + review: true upload: true import: true labels: true places: true - archive: true download: true edit: true share: true -library: - raw: false - thumbs: false - rescan: false + logs: true +import: + path: "" move: false - private: true - review: true +library: + convert: true + resample: true + rescan: false group: true diff --git a/internal/form/index_options.go b/internal/form/index_options.go index ad2f22e3e..f2a665107 100644 --- a/internal/form/index_options.go +++ b/internal/form/index_options.go @@ -1,7 +1,7 @@ package form type IndexOptions struct { - CompleteRescan bool `json:"rescan"` - CreateThumbs bool `json:"thumbs"` - ConvertRaw bool `json:"raw"` + Convert bool `json:"convert"` + Resample bool `json:"resample"` + Rescan bool `json:"rescan"` } diff --git a/internal/photoprism/convert.go b/internal/photoprism/convert.go index 9e332c1a0..50d1a613d 100644 --- a/internal/photoprism/convert.go +++ b/internal/photoprism/convert.go @@ -119,7 +119,7 @@ func (c *Convert) ConvertCommand(image *MediaFile, jpegName string, xmpName stri result = exec.Command(c.conf.DarktableBin(), image.fileName, jpegName) } } else { - return nil, useMutex, fmt.Errorf("convert: no raw to jpeg converter installed (%s)", image.Base(c.conf.Settings().Library.GroupRelated)) + return nil, useMutex, fmt.Errorf("convert: no raw to jpeg converter installed (%s)", image.Base(c.conf.Settings().Library.Group)) } } else if image.IsHEIF() { result = exec.Command(c.conf.HeifConvertBin(), image.fileName, jpegName) @@ -140,7 +140,7 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) { return image, nil } - jpegName := fs.TypeJpeg.Find(image.FileName(), c.conf.Settings().Library.GroupRelated) + jpegName := fs.TypeJpeg.Find(image.FileName(), c.conf.Settings().Library.Group) mediaFile, err := NewMediaFile(jpegName) @@ -148,7 +148,7 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) { return mediaFile, nil } - jpegName = image.AbsBase(c.conf.Settings().Library.GroupRelated) + ".jpg" + jpegName = image.AbsBase(c.conf.Settings().Library.Group) + ".jpg" if c.conf.ReadOnly() { return nil, fmt.Errorf("convert: disabled in read only mode (%s)", image.RelativeName(c.conf.OriginalsPath())) @@ -158,7 +158,7 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) { log.Infof("convert: %s -> %s", fileName, fs.RelativeName(jpegName, c.conf.OriginalsPath())) - xmpName := fs.TypeXMP.Find(image.FileName(), c.conf.Settings().Library.GroupRelated) + xmpName := fs.TypeXMP.Find(image.FileName(), c.conf.Settings().Library.Group) event.Publish("index.converting", event.Data{ "fileType": image.FileType(), diff --git a/internal/photoprism/import.go b/internal/photoprism/import.go index d7ed6d679..e298b44e0 100644 --- a/internal/photoprism/import.go +++ b/internal/photoprism/import.go @@ -119,7 +119,7 @@ func (imp *Import) Start(opt ImportOptions) { return nil } - related, err := mf.RelatedFiles(imp.conf.Settings().Library.GroupRelated) + related, err := mf.RelatedFiles(imp.conf.Settings().Library.Group) if err != nil { event.Error(fmt.Sprintf("import: %s", err.Error())) diff --git a/internal/photoprism/import_worker.go b/internal/photoprism/import_worker.go index 83c400269..4f4bed8b5 100644 --- a/internal/photoprism/import_worker.go +++ b/internal/photoprism/import_worker.go @@ -95,7 +95,7 @@ func ImportWorker(jobs <-chan ImportJob) { } } - related, err := importedMainFile.RelatedFiles(imp.conf.Settings().Library.GroupRelated) + related, err := importedMainFile.RelatedFiles(imp.conf.Settings().Library.Group) if err != nil { log.Errorf("import: could not index %s (%s)", txt.Quote(fs.RelativeName(destinationMainFilename, imp.originalsPath())), err.Error()) diff --git a/internal/photoprism/index.go b/internal/photoprism/index.go index 5a9cb1856..532573712 100644 --- a/internal/photoprism/index.go +++ b/internal/photoprism/index.go @@ -122,7 +122,7 @@ func (ind *Index) Start(options IndexOptions) map[string]bool { return nil } - related, err := mf.RelatedFiles(ind.conf.Settings().Library.GroupRelated) + related, err := mf.RelatedFiles(ind.conf.Settings().Library.Group) if err != nil { log.Warnf("index: %s", err.Error()) diff --git a/internal/photoprism/index_mediafile.go b/internal/photoprism/index_mediafile.go index 3516bd245..621447465 100644 --- a/internal/photoprism/index_mediafile.go +++ b/internal/photoprism/index_mediafile.go @@ -64,7 +64,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( var locKeywords []string labels := classify.Labels{} - fileBase := m.Base(ind.conf.Settings().Library.GroupRelated) + fileBase := m.Base(ind.conf.Settings().Library.Group) filePath := m.RelativePath(ind.originalsPath()) fileName := m.RelativeName(ind.originalsPath()) fileHash := "" diff --git a/internal/workers/sync_download.go b/internal/workers/sync_download.go index cd0ab04b8..e54ed2097 100644 --- a/internal/workers/sync_download.go +++ b/internal/workers/sync_download.go @@ -33,7 +33,7 @@ func (s *Sync) relatedDownloads(a entity.Account) (result Downloads, err error) // Group results by directory and base name for i, file := range files { - k := fs.AbsBase(file.RemoteName, s.conf.Settings().Library.GroupRelated) + k := fs.AbsBase(file.RemoteName, s.conf.Settings().Library.Group) result[k] = append(result[k], file) @@ -136,7 +136,7 @@ func (s *Sync) download(a entity.Account) (complete bool, err error) { continue } - related, err := mf.RelatedFiles(s.conf.Settings().Library.GroupRelated) + related, err := mf.RelatedFiles(s.conf.Settings().Library.Group) if err != nil { log.Warnf("sync: %s", err.Error())