From dda95543e82ff21ca03c96f3366735a9ec43c0e6 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Mon, 8 Mar 2021 19:53:30 +0200
Subject: implemented import/export for themes

---
 src/components/settings_modal/settings_modal.vue | 70 +++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 2 deletions(-)

(limited to 'src/components/settings_modal/settings_modal.vue')

diff --git a/src/components/settings_modal/settings_modal.vue b/src/components/settings_modal/settings_modal.vue
index 552ca41f..a142bcd1 100644
--- a/src/components/settings_modal/settings_modal.vue
+++ b/src/components/settings_modal/settings_modal.vue
@@ -32,19 +32,85 @@
         <button
           class="btn button-default"
           @click="peekModal"
+          :title="$t('general.peek')"
         >
-          {{ $t('general.peek') }}
+          <FAIcon
+            :icon="['far', 'window-minimize']"
+            fixed-width
+          />
         </button>
         <button
           class="btn button-default"
           @click="closeModal"
+          :title="$t('general.close')"
         >
-          {{ $t('general.close') }}
+          <FAIcon
+            icon="times"
+            fixed-width
+          />
         </button>
       </div>
       <div class="panel-body">
         <SettingsModalContent v-if="modalOpenedOnce" />
       </div>
+      <div class="panel-footer">
+        <Popover
+          class="export"
+          trigger="click"
+          placement="top"
+          :offset="{ y: 5, x: 5 }"
+          :bound-to="{ x: 'container' }"
+          remove-padding
+          >
+          <button
+            slot="trigger"
+            class="btn button-default"
+            :title="$t('general.close')"
+            >
+            <span>{{ $t("settings.backup_restore") }}</span>
+            <FAIcon
+              icon="chevron-down"
+            />
+          </button>
+          <div
+            slot="content"
+            slot-scope="{close}"
+          >
+            <div class="dropdown-menu">
+              <button
+                class="button-default dropdown-item dropdown-item-icon"
+                @click.prevent="backup"
+                @click="close"
+              >
+                <FAIcon
+                  icon="file-download"
+                  fixed-width
+                /><span>{{ $t("settings.backup_settings") }}</span>
+              </button>
+              <button
+                class="button-default dropdown-item dropdown-item-icon"
+                @click.prevent="backupWithTheme"
+                @click="close"
+              >
+                <FAIcon
+                  icon="file-download"
+                  fixed-width
+                /><span>{{ $t("settings.backup_settings_theme") }}</span>
+              </button>
+              <button
+                class="button-default dropdown-item dropdown-item-icon"
+                @click.prevent="restore"
+                @click="close"
+              >
+                <FAIcon
+                  icon="file-upload"
+                  fixed-width
+                /><span>{{ $t("settings.restore_settings") }}</span>
+              </button>
+            </div>
+          </div>
+        </Popover>
+      </div>
     </div>
   </Modal>
 </template>
-- 
cgit v1.2.3-70-g09d2


From 395e12cbc6e22459508023daabba87b62a65050e Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Mon, 8 Mar 2021 21:00:43 +0200
Subject: better error/warnings

---
 src/components/settings_modal/settings_modal.js  | 54 ++++++++++++++++++++++--
 src/components/settings_modal/settings_modal.vue |  8 ++--
 src/i18n/en.json                                 | 17 +++++---
 3 files changed, 66 insertions(+), 13 deletions(-)

(limited to 'src/components/settings_modal/settings_modal.vue')

diff --git a/src/components/settings_modal/settings_modal.js b/src/components/settings_modal/settings_modal.js
index 7f6ccccb..f88184ca 100644
--- a/src/components/settings_modal/settings_modal.js
+++ b/src/components/settings_modal/settings_modal.js
@@ -19,6 +19,9 @@ import {
   faWindowMinimize
 } from '@fortawesome/free-regular-svg-icons'
 
+const PLEROMAFE_SETTINGS_MAJOR_VERSION = 1
+const PLEROMAFE_SETTINGS_MINOR_VERSION = 0
+
 library.add(
   faTimes,
   faWindowMinimize,
@@ -65,12 +68,52 @@ const SettingsModal = {
       this.$store.dispatch('togglePeekSettingsModal')
     },
     importValidator (data) {
-      return data._pleroma_settings_version[0] === 1
+      if (!Array.isArray(data._pleroma_settings_version)) {
+        return {
+          messageKey: 'settings.file_import_export.invalid_file'
+        }
+      }
+
+      const [major, minor] = data._pleroma_settings_version
+
+      if (major > PLEROMAFE_SETTINGS_MAJOR_VERSION) {
+        return {
+          messageKey: 'settings.file_export_import.errors.file_too_new',
+          messageArgs: {
+            fileMajor: major,
+            feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION
+          }
+        }
+      }
+
+      if (major < PLEROMAFE_SETTINGS_MAJOR_VERSION) {
+        return {
+          messageKey: 'settings.file_export_import.errors.file_too_old',
+          messageArgs: {
+            fileMajor: major,
+            feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION
+          }
+        }
+      }
+
+      if (minor > PLEROMAFE_SETTINGS_MINOR_VERSION) {
+        this.$store.dispatch('pushGlobalNotice', {
+          level: 'warning',
+          messageKey: 'settings.file_export_import.errors.file_slightly_new',
+        })
+      }
+
+      return true
     },
-    onImportFailure () {
-      this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_settings_imported', level: 'error' })
+    onImportFailure (result) {
+      if (result.error) {
+        this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_settings_imported', level: 'error' })
+      } else {
+        this.$store.dispatch('pushGlobalNotice', { ...result.validationResult, level: 'error' })
+      }
     },
     onImport (data) {
+      if (data)
       this.$store.dispatch('loadSettings', data)
     },
     restore () {
@@ -99,7 +142,10 @@ const SettingsModal = {
         )
       }
       const clone = cloneDeep(sample)
-      clone._pleroma_settings_version = [1, 0]
+      clone._pleroma_settings_version = [
+        PLEROMAFE_SETTINGS_MAJOR_VERSION,
+        PLEROMAFE_SETTINGS_MINOR_VERSION
+      ]
       return clone
     }
   },
diff --git a/src/components/settings_modal/settings_modal.vue b/src/components/settings_modal/settings_modal.vue
index a142bcd1..c37608e2 100644
--- a/src/components/settings_modal/settings_modal.vue
+++ b/src/components/settings_modal/settings_modal.vue
@@ -67,7 +67,7 @@
             class="btn button-default"
             :title="$t('general.close')"
             >
-            <span>{{ $t("settings.backup_restore") }}</span>
+            <span>{{ $t("settings.file_export_import.backup_restore") }}</span>
             <FAIcon
               icon="chevron-down"
             />
@@ -85,7 +85,7 @@
                 <FAIcon
                   icon="file-download"
                   fixed-width
-                /><span>{{ $t("settings.backup_settings") }}</span>
+                /><span>{{ $t("settings.file_export_import.backup_settings") }}</span>
               </button>
               <button
                 class="button-default dropdown-item dropdown-item-icon"
@@ -95,7 +95,7 @@
                 <FAIcon
                   icon="file-download"
                   fixed-width
-                /><span>{{ $t("settings.backup_settings_theme") }}</span>
+                /><span>{{ $t("settings.file_export_import.backup_settings_theme") }}</span>
               </button>
               <button
                 class="button-default dropdown-item dropdown-item-icon"
@@ -105,7 +105,7 @@
                 <FAIcon
                   icon="file-upload"
                   fixed-width
-                /><span>{{ $t("settings.restore_settings") }}</span>
+                /><span>{{ $t("settings.file_export_import.restore_settings") }}</span>
               </button>
             </div>
           </div>
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 049d3d11..1c7fe943 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -357,7 +357,6 @@
     "interface": "Interface",
     "interfaceLanguage": "Interface language",
     "invalid_theme_imported": "The selected file is not a supported Pleroma theme. No changes to your theme were made.",
-    "invalid_settings_imported": "The selected file is not a supported Pleroma settings backup. No changes were made.",
     "limited_availability": "Unavailable in your browser",
     "links": "Links",
     "lock_account_description": "Restrict your account to approved followers only",
@@ -365,10 +364,18 @@
     "loop_video_silent_only": "Loop only videos without sound (i.e. Mastodon's \"gifs\")",
     "mutes_tab": "Mutes",
     "play_videos_in_modal": "Play videos in a popup frame",
-    "backup_restore": "Settings backup",
-    "backup_settings": "Backup settings to file",
-    "backup_settings_theme": "Backup settings and theme to file",
-    "restore_settings": "Restore settings from file",
+    "file_export_import": {
+      "backup_restore": "Settings backup",
+      "backup_settings": "Backup settings to file",
+      "backup_settings_theme": "Backup settings and theme to file",
+      "restore_settings": "Restore settings from file",
+      "errors": {
+        "invalid_file": "The selected file is not a supported Pleroma settings backup. No changes were made.",
+        "file_too_new": "Incompatile major version: {fileMajor}, this PleromaFE (settings ver {feMajor}) is too old to handle it",
+        "file_too_old": "Incompatile major version: {fileMajor}, file version is too old and not supported (min. set. ver. {feMajor})",
+        "file_slightly_new": "File minor version is different, some settings might not load"
+      }
+    },
     "profile_fields": {
       "label": "Profile metadata",
       "add_field": "Add Field",
-- 
cgit v1.2.3-70-g09d2


From 914b4eb5938f00284afff3c210dcafa94e48f510 Mon Sep 17 00:00:00 2001
From: Henry Jameson <me@hjkos.com>
Date: Mon, 8 Mar 2021 21:03:55 +0200
Subject: lint

---
 src/components/settings_modal/settings_modal.js            |  5 ++---
 src/components/settings_modal/settings_modal.vue           |  8 ++++----
 src/components/settings_modal/tabs/theme_tab/theme_tab.vue | 10 ++++++++--
 3 files changed, 14 insertions(+), 9 deletions(-)

(limited to 'src/components/settings_modal/settings_modal.vue')

diff --git a/src/components/settings_modal/settings_modal.js b/src/components/settings_modal/settings_modal.js
index f88184ca..7010e4aa 100644
--- a/src/components/settings_modal/settings_modal.js
+++ b/src/components/settings_modal/settings_modal.js
@@ -99,7 +99,7 @@ const SettingsModal = {
       if (minor > PLEROMAFE_SETTINGS_MINOR_VERSION) {
         this.$store.dispatch('pushGlobalNotice', {
           level: 'warning',
-          messageKey: 'settings.file_export_import.errors.file_slightly_new',
+          messageKey: 'settings.file_export_import.errors.file_slightly_new'
         })
       }
 
@@ -113,8 +113,7 @@ const SettingsModal = {
       }
     },
     onImport (data) {
-      if (data)
-      this.$store.dispatch('loadSettings', data)
+      if (data) { this.$store.dispatch('loadSettings', data) }
     },
     restore () {
       console.log(this.dataImporter)
diff --git a/src/components/settings_modal/settings_modal.vue b/src/components/settings_modal/settings_modal.vue
index c37608e2..c7da5433 100644
--- a/src/components/settings_modal/settings_modal.vue
+++ b/src/components/settings_modal/settings_modal.vue
@@ -31,8 +31,8 @@
         </transition>
         <button
           class="btn button-default"
-          @click="peekModal"
           :title="$t('general.peek')"
+          @click="peekModal"
         >
           <FAIcon
             :icon="['far', 'window-minimize']"
@@ -41,8 +41,8 @@
         </button>
         <button
           class="btn button-default"
-          @click="closeModal"
           :title="$t('general.close')"
+          @click="closeModal"
         >
           <FAIcon
             icon="times"
@@ -61,12 +61,12 @@
           :offset="{ y: 5, x: 5 }"
           :bound-to="{ x: 'container' }"
           remove-padding
-          >
+        >
           <button
             slot="trigger"
             class="btn button-default"
             :title="$t('general.close')"
-            >
+          >
             <span>{{ $t("settings.file_export_import.backup_restore") }}</span>
             <FAIcon
               icon="chevron-down"
diff --git a/src/components/settings_modal/tabs/theme_tab/theme_tab.vue b/src/components/settings_modal/tabs/theme_tab/theme_tab.vue
index 708dd181..62378867 100644
--- a/src/components/settings_modal/tabs/theme_tab/theme_tab.vue
+++ b/src/components/settings_modal/tabs/theme_tab/theme_tab.vue
@@ -79,10 +79,16 @@
             </label>
           </div>
           <div class="export-import">
-            <button class="btn button-default" @click="importTheme">
+            <button
+              class="btn button-default"
+              @click="importTheme"
+            >
               {{ $t(&quot;settings.import_theme&quot;) }}
             </button>
-            <button class="btn button-default" @click="exportTheme">
+            <button
+              class="btn button-default"
+              @click="exportTheme"
+            >
               {{ $t(&quot;settings.export_theme&quot;) }}
             </button>
           </div>
-- 
cgit v1.2.3-70-g09d2

