login page is displayed now
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {KNOWN_HOSTS, DEFAULT_HOST} from '../config.js';
|
||||
import { KNOWN_HOSTS, DEFAULT_HOST } from '../config.js';
|
||||
|
||||
// Detect server address from the URL
|
||||
function detectServerAddress() {
|
||||
export function detectServerAddress() {
|
||||
let host = DEFAULT_HOST;
|
||||
if (typeof window.location == 'object') {
|
||||
if (window.location.protocol == 'file:' || window.location.hostname == 'localhost') {
|
||||
@@ -14,14 +14,14 @@ function detectServerAddress() {
|
||||
}
|
||||
|
||||
// Detect if the page is served over HTTPS.
|
||||
function isSecureConnection() {
|
||||
export function isSecureConnection() {
|
||||
if (typeof window.location == 'object') {
|
||||
return window.location.protocol == 'https:';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isLocalHost() {
|
||||
export function isLocalHost() {
|
||||
if (typeof window.location == 'object') {
|
||||
return window.location.hostname == 'localhost';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Helper functions for storing values in localStorage.
|
||||
// By default localStorage can store only strings, not objects or other types.
|
||||
|
||||
export default class LocalStorageUtil {
|
||||
// Replace old object with the new one.
|
||||
static setObject(key, value) {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
// Get stored object.
|
||||
static getObject(key) {
|
||||
let value = localStorage.getItem(key);
|
||||
return value && JSON.parse(value);
|
||||
}
|
||||
|
||||
// Partially or wholly update stored object.
|
||||
static updateObject(key, value) {
|
||||
let oldVal = localStorage.getObject(key);
|
||||
localStorage.setObject(key, Object.assign(oldVal || {}, value));
|
||||
}
|
||||
}
|
||||
|
||||
+57
-56
@@ -1,67 +1,68 @@
|
||||
// Helper functions for hash navigation.
|
||||
// Utility class for hash navigation.
|
||||
|
||||
// Parse hash as in http://www.example.com/path#hash as if it were
|
||||
// path and arguments.
|
||||
export function parseUrlHash(hash) {
|
||||
// Split path from args, path -> parts[0], args->path[1]
|
||||
let parts = hash.split('?', 2);
|
||||
let params = {};
|
||||
let path = [];
|
||||
if (parts[0]) {
|
||||
path = parts[0].substr(1).split('/');
|
||||
}
|
||||
if (parts[1]) {
|
||||
parts[1].split('&').forEach(function(part) {
|
||||
let item = part.split('=');
|
||||
if (item[0]) {
|
||||
params[decodeURIComponent(item[0])] = decodeURIComponent(item[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
return {path: path, params: params};
|
||||
}
|
||||
|
||||
export function navigateTo(url) {
|
||||
window.location.hash = url;
|
||||
}
|
||||
|
||||
export function composeUrlHash(path, params) {
|
||||
var url = path.join('/');
|
||||
var args = [];
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
args.push(key + '=' + params[key]);
|
||||
export default class HashNavigation {
|
||||
static parseUrlHash(hash) {
|
||||
// Split path from args, path -> parts[0], args->path[1]
|
||||
let parts = hash.split('?', 2);
|
||||
let params = {};
|
||||
let path = [];
|
||||
if (parts[0]) {
|
||||
path = parts[0].substr(1).split('/');
|
||||
}
|
||||
if (parts[1]) {
|
||||
parts[1].split('&').forEach(function(part) {
|
||||
let item = part.split('=');
|
||||
if (item[0]) {
|
||||
params[decodeURIComponent(item[0])] = decodeURIComponent(item[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
return {path: path, params: params};
|
||||
}
|
||||
if (args.length > 0) {
|
||||
url += '?' + args.join('&');
|
||||
|
||||
static navigateTo(url) {
|
||||
window.location.hash = url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export function addUrlParam(hash, key, value) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
parsed.params[key] = value;
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
static composeUrlHash(path, params) {
|
||||
var url = path.join('/');
|
||||
var args = [];
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
args.push(key + '=' + params[key]);
|
||||
}
|
||||
}
|
||||
if (args.length > 0) {
|
||||
url += '?' + args.join('&');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export function removeUrlParam(hash, key) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
delete parsed.params[key];
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
static addUrlParam(hash, key, value) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
parsed.params[key] = value;
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
|
||||
export function setUrlSidePanel(hash, sidepanel) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
parsed.path[0] = sidepanel;
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
static removeUrlParam(hash, key) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
delete parsed.params[key];
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
|
||||
export function setUrlTopic(hash, topic) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
parsed.path[1] = topic;
|
||||
// Close InfoView on topic change.
|
||||
delete parsed.params.info;
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
static setUrlSidePanel(hash, sidepanel) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
parsed.path[0] = sidepanel;
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
|
||||
static setUrlTopic(hash, topic) {
|
||||
var parsed = parseUrlHash(hash);
|
||||
parsed.path[1] = topic;
|
||||
// Close InfoView on topic change.
|
||||
delete parsed.params.info;
|
||||
return composeUrlHash(parsed.path, parsed.params);
|
||||
}
|
||||
}
|
||||
// END of hash navigation helper functions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Short representation of time in the past.
|
||||
function shortDateFormat(then) {
|
||||
export function shortDateFormat(then) {
|
||||
var locale = window.navigator.userLanguage || window.navigator.language;
|
||||
var now = new Date();
|
||||
if (then.getFullYear() == now.getFullYear()) {
|
||||
@@ -15,7 +15,7 @@ function shortDateFormat(then) {
|
||||
}
|
||||
|
||||
// Convert a number of bytes to human-readable format.
|
||||
function bytesToHumanSize(bytes) {
|
||||
export function bytesToHumanSize(bytes) {
|
||||
if (!bytes || bytes == 0) {
|
||||
return '0 Bytes';
|
||||
}
|
||||
@@ -29,7 +29,7 @@ function bytesToHumanSize(bytes) {
|
||||
|
||||
// Get 32 bit integer hash value for a string. Ideally it should produce the same value
|
||||
// as Java's String#hash().
|
||||
function stringHash(value) {
|
||||
export function stringHash(value) {
|
||||
var hash = 0;
|
||||
value = '' + value;
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user