From 562c729ed684ab6e8113c7c3c039219cf84b8d6f Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Jan 2020 21:24:14 +0100 Subject: [PATCH] more refactorings --- .../javascripts/services/app_context.js | 15 +++---- .../javascripts/services/note_detail.js | 1 + .../javascripts/services/tab_context.js | 45 ------------------- src/public/javascripts/widgets/tab_row.js | 23 ++++++++++ 4 files changed, 30 insertions(+), 54 deletions(-) diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index 27f0fb25b..3a532b240 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -180,9 +180,14 @@ class AppContext { return this.tabContexts; } + /** @returns {TabContext} */ + getTabContextById(tabId) { + return this.tabContexts.find(tc => tc.tabId === tabId); + } + /** @returns {TabContext} */ getActiveTabContext() { - return this.tabContexts.find(tc => tc.tabId === this.activeTabId); + return this.getTabContextById(this.activeTabId); } /** @returns {string|null} */ @@ -253,14 +258,6 @@ class AppContext { } } - async refreshTabs(sourceTabId, noteId) { - for (const tc of this.tabContexts) { - if (tc.noteId === noteId && tc.tabId !== sourceTabId) { - await this.reloadTab(tc); - } - } - } - async reloadTab(tc) { if (tc.note) { noteDetailService.reloadNote(tc); diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 7145ab674..72e429bae 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -190,6 +190,7 @@ ws.subscribeToOutsideSyncMessages(syncData => { .filter(sync => sync.entityName === 'attributes') .forEach(sync => noteIdsToRefresh.add(sync.noteId)); + // FIXME for (const noteId of noteIdsToRefresh) { appContext.refreshTabs(null, noteId); } diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index 7bc50ce28..980cdf672 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -1,4 +1,3 @@ -import treeService from "./tree.js"; import protectedSessionHolder from "./protected_session_holder.js"; import server from "./server.js"; import bundleService from "./bundle.js"; @@ -44,10 +43,6 @@ class TabContext extends Component { /** @property {NoteFull} */ this.note = await noteDetailService.loadNote(noteId); - this.tabRow.updateTab(this.$tab[0], {title: this.note.title}); - - this.setupClasses(); - //this.cleanup(); // esp. on windows autocomplete is not getting closed automatically setTimeout(async () => { @@ -70,39 +65,12 @@ class TabContext extends Component { this.trigger('tabNoteSwitched', {tabId: this.tabId}); } - async show() { - } - - hide() { - // FIXME - } - - isActive() { - return this.tabId === this.tabRow.activeTabId; - } - async remove() { await this.trigger('beforeTabRemove', {tabId: this.tabId}, true); this.trigger('tabRemoved', {tabId: this.tabId}); } - setupClasses() { - for (const clazz of Array.from(this.$tab[0].classList)) { // create copy to safely iterate over while removing classes - if (clazz !== 'note-tab') { - this.$tab.removeClass(clazz); - } - } - - this.$tab.addClass(this.note.cssClass); - this.$tab.addClass(utils.getNoteTypeClass(this.note.type)); - this.$tab.addClass(utils.getMimeTypeClass(this.note.mime)); - } - - async activate() { - await this.tabRow.activateTab(this.$tab[0]); - } - async saveNote() { return; // FIXME @@ -125,19 +93,6 @@ class TabContext extends Component { if (this.note.isProtected) { protectedSessionHolder.touchProtectedSession(); } - - // FIXME trigger "noteSaved" event so that title indicator is triggered - this.eventReceived('noteSaved'); - - - } - - async saveNoteIfChanged() { - if (this.isNoteChanged) { - await this.saveNote(); - - appContext.refreshTabs(this.tabId, this.note.noteId); - } } getTabState() { diff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.js index 3233e03a9..22de57098 100644 --- a/src/public/javascripts/widgets/tab_row.js +++ b/src/public/javascripts/widgets/tab_row.js @@ -7,6 +7,7 @@ import BasicWidget from "./basic_widget.js"; import contextMenuService from "../services/context_menu.js"; +import utils from "../services/utils.js"; !function(i, e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(t){return e(i,t)}):"object"==typeof module&&module.exports?module.exports=e(i,require("jquery")):i.jQueryBridget=e(i,i.jQuery)}(window,function(t, i){"use strict";var c=Array.prototype.slice,e=t.console,p=void 0===e?function(){}:function(t){e.error(t)};function n(d, o, u){(u=u||i||t.jQuery)&&(o.prototype.option||(o.prototype.option=function(t){u.isPlainObject(t)&&(this.options=u.extend(!0,this.options,t))}),u.fn[d]=function(t){if("string"==typeof t){var i=c.call(arguments,1);return s=i,a="$()."+d+'("'+(r=t)+'")',(e=this).each(function(t, i){var e=u.data(i,d);if(e){var n=e[r];if(n&&"_"!=r.charAt(0)){var o=n.apply(e,s);h=void 0===h?o:h}else p(a+" is not a valid method")}else p(d+" not initialized. Cannot call methods, i.e. "+a)}),void 0!==h?h:e}var e,r,s,h,a,n;return n=t,this.each(function(t, i){var e=u.data(i,d);e?(e.option(n),e._init()):(e=new o(i,n),u.data(i,d,e))}),this},r(u))}function r(t){!t||t&&t.bridget||(t.bridget=n)}return r(i||t.jQuery),n}),function(t, i){"use strict";"function"==typeof define&&define.amd?define("get-size/get-size",[],function(){return i()}):"object"==typeof module&&module.exports?module.exports=i():t.getSize=i()}(window,function(){"use strict";function m(t){var i=parseFloat(t);return-1==t.indexOf("%")&&!isNaN(i)&&i}var e="undefined"==typeof console?function(){}:function(t){console.error(t)},y=["paddingLeft","paddingRight","paddingTop","paddingBottom","marginLeft","marginRight","marginTop","marginBottom","borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth"],b=y.length;function E(t){var i=getComputedStyle(t);return i||e("Style returned "+i+". Are you running this code in a hidden iframe on Firefox? See http://bit.ly/getsizebug1"),i}var _,x=!1;function P(t){if(function(){if(!x){x=!0;var t=document.createElement("div");t.style.width="200px",t.style.padding="1px 2px 3px 4px",t.style.borderStyle="solid",t.style.borderWidth="1px 2px 3px 4px",t.style.boxSizing="border-box";var i=document.body||document.documentElement;i.appendChild(t);var e=E(t);P.isBoxSizeOuter=_=200==m(e.width),i.removeChild(t)}}(),"string"==typeof t&&(t=document.querySelector(t)),t&&"object"==typeof t&&t.nodeType){var i=E(t);if("none"==i.display)return function(){for(var t={width:0,height:0,innerWidth:0,innerHeight:0,outerWidth:0,outerHeight:0},i=0; i