refacto(front): whitebardId init

* More straightforward
* Use std for getting url params
* Show the final whiteboardid in url
This commit is contained in:
Florent Chehab 2020-05-12 20:50:58 +02:00
parent b11520788e
commit d268eb6d93
No known key found for this signature in database
GPG Key ID: 9A0CE018889EA246
3 changed files with 21 additions and 31 deletions

View File

@ -8,29 +8,37 @@ import pdfjsLib from "pdfjs-dist/webpack";
import shortcutFunctions from "./shortcutFunctions";
import ReadOnlyService from "./services/ReadOnlyService";
import InfoService from "./services/InfoService";
import { getQueryVariable, getSubDir } from "./utils";
import { getSubDir } from "./utils";
import ConfigService from "./services/ConfigService";
import { v4 as uuidv4 } from "uuid";
let whiteboardId = getQueryVariable("whiteboardid");
const randomid = getQueryVariable("randomid");
if (randomid && !whiteboardId) {
//set random whiteboard on empty whiteboardid
const urlParams = new URLSearchParams(window.location.search);
let whiteboardId = urlParams.get("whiteboardid");
const randomid = urlParams.get("randomid");
if (randomid) {
whiteboardId = uuidv4();
const urlParams = new URLSearchParams(window.location.search);
urlParams.delete("randomid");
window.location.search = urlParams;
}
if (!whiteboardId) {
whiteboardId = "myNewWhiteboard";
}
whiteboardId = unescape(encodeURIComponent(whiteboardId)).replace(/[^a-zA-Z0-9\-]/g, "");
if (urlParams.get("whiteboardid") !== whiteboardId) {
urlParams.set("whiteboardid", whiteboardId);
window.location.search = urlParams;
}
whiteboardId = whiteboardId || "myNewWhiteboard";
whiteboardId = unescape(encodeURIComponent(whiteboardId)).replace(/[^a-zA-Z0-9\-]/g, "");
const myUsername = getQueryVariable("username") || "unknown" + (Math.random() + "").substring(2, 6);
const accessToken = getQueryVariable("accesstoken") || "";
const myUsername = urlParams.get("username") || "unknown" + (Math.random() + "").substring(2, 6);
const accessToken = urlParams.get("accesstoken") || "";
// Custom Html Title
const title = getQueryVariable("title");
if (!title === false) {
const title = urlParams.get("title");
if (title) {
document.title = decodeURIComponent(title);
}
@ -131,7 +139,7 @@ function initWhiteboard() {
// by default set in readOnly mode
ReadOnlyService.activateReadOnlyMode();
if (getQueryVariable("webdav") == "true") {
if (urlParams.get("webdav") === "true") {
$("#uploadWebDavBtn").show();
}

View File

@ -15,23 +15,6 @@ export function getCurrentTimeMs() {
return new Date().getTime();
}
/**
* get 'GET' parameter by variable name
* @param variable
* @return {boolean|*}
*/
export function getQueryVariable(variable) {
const query = window.location.search.substring(1);
const vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
if (pair[0] === variable) {
return pair[1];
}
}
return false;
}
export function getSubDir() {
const url = document.URL.substr(0, document.URL.lastIndexOf("/"));
const urlSplit = url.split("/");

View File

@ -64,7 +64,6 @@ const whiteboard = {
this.settings[i] = newSettings[i];
}
this.settings["username"] = this.settings["username"].replace(/[^0-9a-z]/gi, "");
this.settings["whiteboardId"] = this.settings["whiteboardId"].replace(/[^0-9a-z]/gi, "");
//background grid (repeating image) and smallest screen indication
_this.backgroundGrid = $(