Commit c4ec9de3 authored by Michael Ochmann's avatar Michael Ochmann
Browse files

added settings system; fixed navbar

parent 24219e58
class Settings {
constructor() {
this.settings = JSON.parse(localStorage.getItem("settings")) || {};
}
get(key, defaultValue = null) {
if (this.settings.hasOwnProperty(key))
return this.settings[key];
return defaultValue;
}
set(key, value) {
this.settings[key] = value;
this.save();
}
save() {
localStorage.setItem("settings", JSON.stringify(this.settings));
}
static Instance() {
if (Settings.INSTANCE === null)
Settings.INSTANCE = new Settings();
return Settings.INSTANCE;
}
}
Settings.INSTANCE = null;
export default Settings.Instance();
\ No newline at end of file
import UIViewController from "./UIViewController.js"; import UIViewController from "./UIViewController.js";
import $ from "../smallQ.js"; import $ from "../smallQ.js";
import Std from "../Std.js"; import Std from "../Std.js";
import Settings from "../Settings.js";
import GeoPoint from "../GeoPoint.js"; import GeoPoint from "../GeoPoint.js";
...@@ -12,15 +13,14 @@ class HeightMapViewController extends UIViewController { ...@@ -12,15 +13,14 @@ class HeightMapViewController extends UIViewController {
this.drag = false; this.drag = false;
this.lastX = 0; this.lastX = 0;
this.translated = 0; this.translated = 0;
this.isCapturing = false; this.isCapturing = false;
} }
addPoint(geoPoint) { addPoint(geoPoint) {
if (geoPoint.constructor.name !== "GeoPoint") if (geoPoint.constructor.name !== "GeoPoint")
throw new TypeError("an object of type 'GeoPoint' must be p1assed."); throw new TypeError("an object of type 'GeoPoint' must be passed.");
if (this.model.points.length > 0 && this.model.points[this.model.points.length - 1].distance(geoPoint) < 5) if (this.model.points.length > 0 && this.model.points[this.model.points.length - 1].distance(geoPoint) < Settings.get("distanceInterval", 50))
return; return;
this.model.add(geoPoint); this.model.add(geoPoint);
......
import UIViewController from "./UIViewController.js"; import UIViewController from "./UIViewController.js";
import Settings from "../Settings.js";
import $ from "../smallQ.js";
class SettingsViewController extends UIViewController { class SettingsViewController extends UIViewController {
constructor(view, model) { constructor(view, model) {
super(view, model); super(view, model);
this.heights = [50]; this.heights = [5, 50];
for (let h = 100; h < 1000; h += 100) for (let h = 100; h < 1000; h += 100)
this.heights.push(h); this.heights.push(h);
for (let h = 1000; h <= 10000; h += 1000) for (let h = 1000; h <= 10000; h += 1000)
this.heights.push(h); this.heights.push(h);
} }
viewDidLoad() {
$("#selectDistanceInterval").on("change", element => {
Settings.set("distanceInterval", element.value());
});
}
render() { render() {
let heights = this.heights.map(height => `<option value="${height}">${height}m</option>`).join(""); let selectedDistance = Settings.get("distanceInterval", 100);
let heights = this.heights.map(height => {
let selected = height == selectedDistance ? " selected" : "";
return `<option value="${height}"${selected}>${height}m</option>`
}).join("");
return ` return `
<ul class="UITableView"> <ul class="UITableView">
<li> <li>
New datapoint every New datapoint every
<span class="right"> <span class="right">
<select> <select id=selectDistanceInterval>
${heights} ${heights}
</select> </select>
</span> </span>
......
...@@ -6,6 +6,7 @@ import TracksListController from "./TracksListController.js"; ...@@ -6,6 +6,7 @@ import TracksListController from "./TracksListController.js";
import HeightMap from "../models/HeightMap.js"; import HeightMap from "../models/HeightMap.js";
import Tracks from "../models/Tracks.js"; import Tracks from "../models/Tracks.js";
import Settings from "../Settings.js";
import $ from "../smallQ.js"; import $ from "../smallQ.js";
const States = { const States = {
...@@ -17,7 +18,8 @@ const States = { ...@@ -17,7 +18,8 @@ const States = {
class ViewController extends UIViewController { class ViewController extends UIViewController {
constructor() { constructor() {
super("body"); super("body");
this.state = States.TRACKLIST; this.state = parseInt(Settings.get("appState"));
this.state = this.state === States.HEIGHTMAP ? States.TRACKLIST : this.state;
this.track = null; this.track = null;
this.renderCall(); this.renderCall();
...@@ -71,6 +73,7 @@ class ViewController extends UIViewController { ...@@ -71,6 +73,7 @@ class ViewController extends UIViewController {
changeState(newState) { changeState(newState) {
this.state = newState; this.state = newState;
Settings.set("appState", newState);
this.renderCall(); this.renderCall();
} }
......
...@@ -30,7 +30,7 @@ body, html { ...@@ -30,7 +30,7 @@ body, html {
} }
body { body {
padding-top: 20px; /*padding-top: 20px;*/
display: grid; display: grid;
grid-template-rows: 44px auto 49px; grid-template-rows: 44px auto 49px;
background: $header-background; background: $header-background;
...@@ -39,6 +39,14 @@ body { ...@@ -39,6 +39,14 @@ body {
} }
button.big { button.big {
padding: 20px 50px; padding: 15px 50px;
font-size: large; font-size: x-large;
background: $header-background;
border: none;
color: $header-color;
border-radius: 100px;
&:active {
opacity: 0.6;
}
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment