From 602e58f58e432b462b5d1bae6cac5afe4aa3c909 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 23 Mar 2022 23:33:44 -0300 Subject: [PATCH 1/2] Simplify map lock support. --- packages/editor/README.md | 1 - packages/mindplot/src/components/ImageIcon.js | 2 +- .../src/components/RestPersistenceManager.ts | 15 ++------------- packages/mindplot/src/indexLoader.ts | 11 +---------- packages/webapp/src/@types/index.d.ts | 2 -- .../src/classes/client/rest-client/index.ts | 7 ------- 6 files changed, 4 insertions(+), 34 deletions(-) diff --git a/packages/editor/README.md b/packages/editor/README.md index 9a81c0ce..2ca790c4 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -11,7 +11,6 @@ This is a work in progress and for now mindplot needs to be instantiated using t ReactDOM.render( console.log('action called:', action)} diff --git a/packages/mindplot/src/components/ImageIcon.js b/packages/mindplot/src/components/ImageIcon.js index 6f704c7d..7a3b1269 100644 --- a/packages/mindplot/src/components/ImageIcon.js +++ b/packages/mindplot/src/components/ImageIcon.js @@ -73,7 +73,7 @@ class ImageIcon extends Icon { static _getNextFamilyIconId(iconId) { const familyIcons = ImageIcon._getFamilyIcons(iconId); - $assert(familyIcons != null, `Family Icon not found: ${iconId}`); + $assert(familyIcons !== null, `Family Icon not found: ${iconId}`); let result = null; for (let i = 0; i < familyIcons.length && result == null; i++) { diff --git a/packages/mindplot/src/components/RestPersistenceManager.ts b/packages/mindplot/src/components/RestPersistenceManager.ts index bcf0e0e6..514b4e41 100644 --- a/packages/mindplot/src/components/RestPersistenceManager.ts +++ b/packages/mindplot/src/components/RestPersistenceManager.ts @@ -27,27 +27,19 @@ class RESTPersistenceManager extends PersistenceManager { private lockUrl: string; - private timestamp: string; - - private session: string; - private onSave: boolean; private clearTimeout; - constructor(options) { + constructor(options: { documentUrl: string, revertUrl: string, lockUrl: string }) { $assert(options.documentUrl, 'documentUrl can not be null'); $assert(options.revertUrl, 'revertUrl can not be null'); $assert(options.lockUrl, 'lockUrl can not be null'); - $assert(options.session, 'session can not be null'); - $assert(options.timestamp, 'timestamp can not be null'); super(); this.documentUrl = options.documentUrl; this.revertUrl = options.revertUrl; this.lockUrl = options.lockUrl; - this.timestamp = options.timestamp; - this.session = options.session; } saveMapXml(mapId: string, mapXml: Document, pref: string, saveHistory: boolean, events): void { @@ -57,9 +49,7 @@ class RESTPersistenceManager extends PersistenceManager { properties: pref, }; - let query = `minor=${!saveHistory}`; - query = `${query}×tamp=${this.timestamp}`; - query = `${query}&session=${this.session}`; + const query = `minor=${!saveHistory}`; if (!this.onSave) { // Mark save in process and fire a event unlocking the save ... @@ -80,7 +70,6 @@ class RESTPersistenceManager extends PersistenceManager { }, ).then(async (response: Response) => { if (response.ok) { - persistence.timestamp = await response.text(); events.onSuccess(); } else { console.log(`Saving error: ${response.status}`); diff --git a/packages/mindplot/src/indexLoader.ts b/packages/mindplot/src/indexLoader.ts index e3fd4c64..7d8bd52a 100644 --- a/packages/mindplot/src/indexLoader.ts +++ b/packages/mindplot/src/indexLoader.ts @@ -22,7 +22,6 @@ import { import { buildDesigner, } from './components/DesignerBuilder'; -import RESTPersistenceManager from './components/RestPersistenceManager'; import PersistenceManager from './components/PersistenceManager'; import LocalStorageManager from './components/LocalStorageManager'; import DesignerOptionsBuilder from './components/DesignerOptionsBuilder'; @@ -34,15 +33,7 @@ require('../../../libraries/bootstrap/js/bootstrap.min'); // Configure designer options ... let persistence: PersistenceManager; -if (!global.memoryPersistence && !global.readOnly) { - persistence = new RESTPersistenceManager({ - documentUrl: '/c/restful/maps/{id}/document', - revertUrl: '/c/restful/maps/{id}/history/latest', - lockUrl: '/c/restful/maps/{id}/lock', - timestamp: global.lockTimestamp, - session: global.lockSession, - }); -} else { +if (global.readOnly) { const historyId = global.historyId ? `${global.historyId}/` : ''; persistence = new LocalStorageManager( `/c/restful/maps/{id}/${historyId}document/xml${!global.isAuth ? '-pub' : ''}`, diff --git a/packages/webapp/src/@types/index.d.ts b/packages/webapp/src/@types/index.d.ts index 18f29971..daeadc97 100644 --- a/packages/webapp/src/@types/index.d.ts +++ b/packages/webapp/src/@types/index.d.ts @@ -2,8 +2,6 @@ declare module '*.png'; declare module '*.svg'; declare module '*.wxml'; declare global { - const lockTimestamp: string; - const lockSession: string; const isAuth: boolean; const mapId: number; const userOptions: { zoom: string | number } | null; diff --git a/packages/webapp/src/classes/client/rest-client/index.ts b/packages/webapp/src/classes/client/rest-client/index.ts index a0ace132..5aaeec0f 100644 --- a/packages/webapp/src/classes/client/rest-client/index.ts +++ b/packages/webapp/src/classes/client/rest-client/index.ts @@ -618,17 +618,10 @@ export default class RestClient implements Client { let persistence: PersistenceManager; if (editorMode === 'edition-owner' || editorMode === 'edition-editor') { - - if (!global.lockSession) { - throw new Error(`Session could not be found: global.lockSession: '${global.lockSession}' - global.lockTimestamp: '${global.lockTimestamp}' - ${global.mindmapLocked} - ${global.mindmapLockedMsg}`) - } - persistence = new RESTPersistenceManager({ documentUrl: '/c/restful/maps/{id}/document', revertUrl: '/c/restful/maps/{id}/history/latest', lockUrl: '/c/restful/maps/{id}/lock', - timestamp: global.lockTimestamp, - session: global.lockSession, }); } else { persistence = new LocalStorageManager( From ed8fe3a455d8a3a0919592de763473f3e568a4d2 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 25 Mar 2022 16:50:25 -0300 Subject: [PATCH 2/2] Improve link url dialog --- .../src/components/widget/LinkEditor.js | 18 ++++++++++++++---- .../src/components/widget/LinkIconTooltip.js | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/mindplot/src/components/widget/LinkEditor.js b/packages/mindplot/src/components/widget/LinkEditor.js index 681429c1..f4dbcabc 100644 --- a/packages/mindplot/src/components/widget/LinkEditor.js +++ b/packages/mindplot/src/components/widget/LinkEditor.js @@ -60,7 +60,7 @@ class LinkEditor extends BootstrapDialog { // Add Input const input = $('').attr({ - placeholder: 'http://www.example.com/', + placeholder: 'https://www.example.com/', required: 'true', autofocus: 'autofocus', class: 'form-control', @@ -92,9 +92,10 @@ class LinkEditor extends BootstrapDialog { const me = this; this.form.unbind('submit').submit((event) => { event.preventDefault(); - if (me.checkURL(input.val())) { + let inputValue = input.val(); + inputValue = this.hasProtocol(inputValue) ? inputValue : `https://${inputValue}`; + if (me.checkURL(inputValue)) { me.cleanError(); - const inputValue = input.val(); if (inputValue != null && $.trim(inputValue) !== '') { model.setValue(inputValue); } @@ -115,7 +116,16 @@ class LinkEditor extends BootstrapDialog { * @return {Boolean} true if the url is valid */ checkURL(url) { - const regex = /^(http|https|ftp):\/\/[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i; + const regex = /^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i; + return (regex.test(url)); + } + + /** + * checks whether the input is a valid url + * @return {Boolean} true if the url is valid + */ + hasProtocol(url) { + const regex = /^(http|https):\/\//i; return (regex.test(url)); } diff --git a/packages/mindplot/src/components/widget/LinkIconTooltip.js b/packages/mindplot/src/components/widget/LinkIconTooltip.js index 62e28a9c..a40b56fc 100644 --- a/packages/mindplot/src/components/widget/LinkIconTooltip.js +++ b/packages/mindplot/src/components/widget/LinkIconTooltip.js @@ -40,8 +40,8 @@ class LinkIconTooltip extends FloatingTip { static _buildContent(linkIcon) { const url = linkIcon.getModel().getUrl(); - const linkText = `URL: ${url}`; - const linkPreview = `http://free.pagepeeker.com/v2/thumbs.php?size=m&url=${url}`; + const linkText = `${url}`; + const linkPreview = `https://free.pagepeeker.com/v2/thumbs.php?size=m&url=${url}`; const result = $('
').css({ padding: '5px',