Prechádzať zdrojové kódy

Merge branch 'release/0.9.5-1'

Book Pauk 4 rokov pred
rodič
commit
956546585c

+ 59 - 0
client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue

@@ -0,0 +1,59 @@
+<template>
+    <Window ref="window" width="600px" height="95%" @close="close">
+        <template slot="header">
+            Настроить закладки
+        </template>
+
+    </Window>
+</template>
+
+<script>
+//-----------------------------------------------------------------------------
+import Vue from 'vue';
+import Component from 'vue-class-component';
+import Window from '../../share/Window.vue';
+
+const BookmarkSettingsProps = Vue.extend({
+    props: {
+        libs: Object,
+    }
+});
+
+export default @Component({
+    components: {
+        Window,
+    },
+    watch: {
+        libs: function() {
+        },
+    }    
+})
+class BookmarkSettings extends BookmarkSettingsProps {
+    created() {
+    }
+
+    mounted() {
+    }
+
+    init() {
+        this.$refs.window.init();
+    }
+
+    close() {
+        this.$emit('close');
+    }
+
+    keyHook(event) {
+        if (event.type == 'keydown' && event.key == 'Escape') {
+            this.close();
+            return true;
+        }
+        return false;
+    }
+
+}
+//-----------------------------------------------------------------------------
+</script>
+
+<style scoped>
+</style>

+ 27 - 10
client/components/ExternalLibs/ExternalLibs.vue

@@ -23,8 +23,8 @@
                         <q-btn class="q-mr-xs" round dense color="blue" icon="la la-plus" @click.stop="addBookmark" size="12px">
                             <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Добавить закладку</q-tooltip>
                         </q-btn>
-                        <q-btn round dense color="blue" icon="la la-bars" @click.stop="bookmarkSettings"  size="12px" disabled>
-                            <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Настроить закладки (пока недоступно)</q-tooltip>                            
+                        <q-btn round dense color="blue" icon="la la-bars" @click.stop="bookmarkSettings" size="12px" disabled>
+                            <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Настроить закладки</q-tooltip>
                         </q-btn>
                     </template>
                     <template v-slot:selected>
@@ -97,6 +97,7 @@
                 </template>
             </Dialog>
         </div>
+        <BookmarkSettings v-if="bookmarkSettingsActive" ref="bookmarkSettings" :libs="libs" @close="closeBookmarkSettings"></BookmarkSettings>
     </Window>
 </template>
 
@@ -108,6 +109,8 @@ import _ from 'lodash';
 
 import Window from '../share/Window.vue';
 import Dialog from '../share/Dialog.vue';
+import BookmarkSettings from './BookmarkSettings/BookmarkSettings.vue';
+
 import rstore from '../../store/modules/reader';
 import * as utils from '../../share/utils';
 
@@ -118,7 +121,8 @@ const proxySubst = {
 export default @Component({
     components: {
         Window,
-        Dialog
+        Dialog,
+        BookmarkSettings
     },
     watch: {
         libs: function() {
@@ -153,6 +157,8 @@ class ExternalLibs extends Vue {
     bookmarkDesc = '';
     defaultRootLink = '';
 
+    bookmarkSettingsActive = false;
+
     created() {
         this.$root.addKeyHook(this.keyHook);
 
@@ -549,9 +555,6 @@ class ExternalLibs extends Vue {
         this.addBookmarkVisible = false;
     }
 
-    bookmarkSettings() {
-    }
-
     fullScreenToggle() {
         this.fullScreenActive = !this.fullScreenActive;
         if (this.fullScreenActive) {
@@ -584,14 +587,28 @@ class ExternalLibs extends Vue {
         }
     }
 
-    keyHook() {
+    bookmarkSettings() {
+        this.bookmarkSettingsActive = true;
+        this.$nextTick(() => {
+            this.$refs.bookmarkSettings.init();
+        });
+    }
+
+    closeBookmarkSettings() {
+        this.bookmarkSettingsActive = false;
+    }
+
+    keyHook(event) {
         if (this.$root.rootRoute() == '/external-libs') {
+            if (this.bookmarkSettingsActive && this.$refs.bookmarkSettings.keyHook(event))
+                return true;
+
             if (this.$refs.dialogAddBookmark.active)
                 return false;
 
             if (event.type == 'keydown' && event.key == 'F4') {
-                this.addBookmark()
-                return;
+                this.addBookmark();
+                return true;
             }
 
             if (event.type == 'keydown' && event.key == 'Escape' &&
@@ -599,8 +616,8 @@ class ExternalLibs extends Vue {
                 (document.activeElement != this.$refs.selectedLink.$refs.target || !this.$refs.selectedLink.menu)
                ) {
                 this.close();
+                return true;
             }
-            return true;
         }
         return false;
     }

+ 6 - 0
client/components/Reader/Reader.vue

@@ -331,6 +331,12 @@ class Reader extends Vue {
             this.checkActivateDonateHelpPage();
             this.loading = false;
 
+            //проверим состояние Settings, и обновим, если надо
+            const newSettings = rstore.addDefaultsToSettings(this.settings);
+            if (newSettings) {
+                this.commit('reader/setSettings', newSettings);
+            }
+
             this.updateRoute();
 
             await this.showWhatsNew();

+ 2 - 2
client/components/Reader/ServerStorage/ServerStorage.vue

@@ -505,7 +505,7 @@ class ServerStorage extends Vue {
 
                 const md = newRecentMod.data;
                 if (md.key && result[md.key])
-                    result[md.key] = utils.applyObjDiff(result[md.key], md.mod, true);
+                    result[md.key] = utils.applyObjDiff(result[md.key], md.mod, {isAddChanged: true});
 
                 if (!bookManager.loaded) {
                     this.warning('Ожидание загрузки списка книг перед синхронизацией');
@@ -569,7 +569,7 @@ class ServerStorage extends Vue {
 
                 let applyMod = this.cachedRecentMod.data;
                 if (applyMod && applyMod.key && newRecentPatch.data[applyMod.key])
-                    newRecentPatch.data[applyMod.key] = utils.applyObjDiff(newRecentPatch.data[applyMod.key], applyMod.mod, true);
+                    newRecentPatch.data[applyMod.key] = utils.applyObjDiff(newRecentPatch.data[applyMod.key], applyMod.mod, {isAddChanged: true});
 
                 newRecentMod = {rev: this.cachedRecentMod.rev + 1, data: {}};
                 needSaveRecentPatch = true;

+ 13 - 3
client/components/Reader/SettingsPage/SettingsPage.vue

@@ -108,8 +108,10 @@ export default @Component({
         },
         vertShift: function(newValue) {
             const font = (this.webFontName ? this.webFontName : this.fontName);
-            this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
-            this.fontVertShift = newValue;
+            if (this.fontShifts[font] != newValue) {
+                this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue});
+                this.fontVertShift = newValue;
+            }
         },
         fontName: function(newValue) {
             const font = (this.webFontName ? this.webFontName : newValue);
@@ -185,10 +187,18 @@ class SettingsPage extends Vue {
     settingsChanged() {
         if (_.isEqual(this.form, this.settings))
             return;
+
         this.form = Object.assign({}, this.settings);
+        if (!this.unwatch)
+            this.unwatch = {};
+
         for (let prop in rstore.settingDefaults) {
+            if (this.unwatch && this.unwatch[prop])
+                this.unwatch[prop]();
+
             this[prop] = this.form[prop];
-            this.$watch(prop, (newValue) => {
+
+            this.unwatch[prop] = this.$watch(prop, (newValue) => {
                 this.form = Object.assign({}, this.form, {[prop]: newValue});
             });
         }

+ 1 - 1
client/components/share/Dialog.vue

@@ -32,7 +32,7 @@ const DialogProps = Vue.extend({
     props: {
         value: Boolean,
     }
-})
+});
 
 export default @Component({
 })

+ 1 - 0
client/components/share/Window.vue

@@ -124,6 +124,7 @@ class Window extends Vue {
 .main {
     background-color: transparent !important;
     z-index: 50;
+    overflow: hidden;
 }
 
 .xyfit {

+ 53 - 13
client/share/utils.js

@@ -130,20 +130,53 @@ export function getObjDiff(oldObj, newObj) {
 }
 
 export function isObjDiff(diff) {
-    return (_.isObject(diff) && diff.__isDiff);
+    return (_.isObject(diff) && diff.__isDiff && diff.change && diff.add && diff.del);
 }
 
 export function isEmptyObjDiff(diff) {
-    return (!_.isObject(diff) || !diff.__isDiff ||
-        (!Object.keys(diff.change).length &&
-            !Object.keys(diff.add).length &&
-            !diff.del.length
+    return (!isObjDiff(diff) ||
+        !(Object.keys(diff.change).length ||
+          Object.keys(diff.add).length ||
+          diff.del.length
         )
     );
 }
 
-export function applyObjDiff(obj, diff, isAddChanged) {
-    const result = _.cloneDeep(obj);
+export function isEmptyObjDiffDeep(diff, opts = {}) {
+    if (!isObjDiff(diff))
+        return true;
+
+    const {
+        isApplyChange = true,
+        isApplyAdd = true,
+        isApplyDel = true,
+    } = opts;
+
+    let notEmptyDeep = false;
+    const change = diff.change;
+    for (const key of Object.keys(change)) {
+        if (_.isObject(change[key]))
+            notEmptyDeep |= !isEmptyObjDiffDeep(change[key], opts);
+        else if (isApplyChange)
+            notEmptyDeep = true;
+    }
+
+    return !(
+        notEmptyDeep ||
+        (isApplyAdd && Object.keys(diff.add).length) ||
+        (isApplyDel && diff.del.length)
+    );
+}
+
+export function applyObjDiff(obj, diff, opts = {}) {
+    const {
+        isAddChanged = false,
+        isApplyChange = true,
+        isApplyAdd = true,
+        isApplyDel = true,
+    } = opts;
+
+    let result = _.cloneDeep(obj);
     if (!diff.__isDiff)
         return result;
 
@@ -151,21 +184,28 @@ export function applyObjDiff(obj, diff, isAddChanged) {
     for (const key of Object.keys(change)) {
         if (result.hasOwnProperty(key)) {
             if (_.isObject(change[key])) {
-                result[key] = applyObjDiff(result[key], change[key], isAddChanged);
+                result[key] = applyObjDiff(result[key], change[key], opts);
             } else {
-                result[key] = _.cloneDeep(change[key]);
+                if (isApplyChange)
+                    result[key] = _.cloneDeep(change[key]);
             }
         } else if (isAddChanged) {
             result[key] = _.cloneDeep(change[key]);
         }
     }
 
-    for (const key of Object.keys(diff.add)) {
-        result[key] = _.cloneDeep(diff.add[key]);
+    if (isApplyAdd) {
+        for (const key of Object.keys(diff.add)) {
+            result[key] = _.cloneDeep(diff.add[key]);
+        }
     }
 
-    for (const key of diff.del) {
-        delete result[key];
+    if (isApplyDel && diff.del.length) {
+        for (const key of diff.del) {
+            delete result[key];
+        }
+        if (_.isArray(result))
+            result = result.filter(v => v);
     }
 
     return result;

+ 29 - 10
client/store/modules/reader.js

@@ -1,3 +1,5 @@
+import * as utils from '../../share/utils';
+
 const readerActions = {
     'help': 'Вызвать cправку',
     'loader': 'На страницу загрузки',
@@ -256,6 +258,25 @@ const settingDefaults = {
     userHotKeys: {},
 };
 
+for (const font of fonts)
+    settingDefaults.fontShifts[font.name] = font.fontVertShift;
+for (const font of webFonts)
+    settingDefaults.fontShifts[font.name] = font.fontVertShift;
+for (const button of toolButtons)
+    settingDefaults.showToolButton[button.name] = button.show;
+for (const hotKey of hotKeys)
+    settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
+
+function addDefaultsToSettings(settings) {
+    const diff = utils.getObjDiff(settings, settingDefaults);
+    
+    if (!utils.isEmptyObjDiffDeep(diff, {isApplyChange: false})) {
+        return utils.applyObjDiff(settings, diff, {isApplyChange: false});
+    }
+
+    return false;
+}
+
 const libsDefaults = {
     startLink: 'http://flibusta.is',
     comment: 'Флибуста | Книжное братство',
@@ -279,15 +300,6 @@ const libsDefaults = {
     ]
 };
 
-for (const font of fonts)
-    settingDefaults.fontShifts[font.name] = font.fontVertShift;
-for (const font of webFonts)
-    settingDefaults.fontShifts[font.name] = font.fontVertShift;
-for (const button of toolButtons)
-    settingDefaults.showToolButton[button.name] = button.show;
-for (const hotKey of hotKeys)
-    settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
-
 // initial state
 const state = {
     toolBarActive: true,
@@ -341,7 +353,13 @@ const mutations = {
         state.currentProfile = value;
     },
     setSettings(state, value) {
-        state.settings = Object.assign({}, state.settings, value);
+        const newSettings = Object.assign({}, state.settings, value);
+        const added = addDefaultsToSettings(newSettings);
+        if (added) {
+            state.settings = added;
+        } else {
+            state.settings = newSettings;
+        }
     },
     setSettingsRev(state, value) {
         state.settingsRev = Object.assign({}, state.settingsRev, value);
@@ -361,6 +379,7 @@ export default {
     fonts,
     webFonts,
     settingDefaults,
+    addDefaultsToSettings,
     libsDefaults,
 
     namespaced: true,