It works now, but needs a lot more polish; also, must convert all

layouts.
This commit is contained in:
Manuel Friedli 2019-05-05 03:41:01 +02:00
parent 933a3c92f5
commit 57d074d5fe
12 changed files with 194 additions and 74 deletions

View file

@ -52,19 +52,23 @@ export class Globals {
}
static registerLayout(layout: Layout): void {
const available = Globals.layouts.some(element => {
const available = !Globals.layouts.some(element => {
if (layout.code === element.code) {
console.error(
`Error: Language code '${layout.code}' cannot be registered for layout '${layout.prettyName}'
because it is already registered for layout '${element.prettyName}'!`
);
return false;
console.log("globals.ts", "REJECTING LAYOUT", layout.code, Globals.layouts);
return true;
}
return true;
return false;
}
);
if (available) {
console.log("globals.ts", "registering layout", layout.code, layout);
Globals.layouts.push(layout);
} else {
console.log("globals.ts", "NOT registering layout", layout.code, layout);
}
}

View file

@ -19,12 +19,14 @@ import {Uhr} from "./uhr";
import {WidgetPrototype} from "./widget/widget-prototype";
import {Layout} from "./domain/layout";
import {Layout_de_CH} from "./layout/layout-de_ch";
import {Layout_de_CH_genau} from "./layout/layout-de_ch_genau";
// First things first: discover included themes and register them
autodetectThemes();
// Now register some layouts
Globals.registerLayout(Layout_de_CH);
Globals.registerLayout(Layout_de_CH_genau);
$.widget("fritteli.uhr", {
"options": {

View file

@ -16,13 +16,13 @@
import {Layout, WordDefinition} from "../domain/layout";
const es_isch: WordDefinition = {1: [1, 2, 4, 5, 6, 7]};
const ab = {4: [1, 2]};
const vor = {3: [9, 10, 11]};
const haubi = {4: [4, 5, 6, 7, 8]};
const fuef = {1: [9, 10, 11]};
const zae = {2: [9, 10, 11]};
const viertu = {2: [1, 2, 3, 4, 5, 6]};
const zwaenzg = {3: [1, 2, 3, 4, 5, 6]};
const ab: WordDefinition = {4: [1, 2]};
const vor: WordDefinition = {3: [9, 10, 11]};
const haubi: WordDefinition = {4: [4, 5, 6, 7, 8]};
const fuef: WordDefinition = {1: [9, 10, 11]};
const zae: WordDefinition = {2: [9, 10, 11]};
const viertu: WordDefinition = {2: [1, 2, 3, 4, 5, 6]};
const zwaenzg: WordDefinition = {3: [1, 2, 3, 4, 5, 6]};
export const Layout_de_CH: Layout = {
code: 'de_CH',
@ -64,7 +64,6 @@ export const Layout_de_CH: Layout = {
"45,46,47,48,49": [viertu, vor],
"50,51,52,53,54": [zae, vor],
"55,56,57,58,59": [fuef, vor]
},
permanent: es_isch,
prettyName: 'Bärndütsch',

View file

@ -0,0 +1,73 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {Layout, WordDefinition} from "../domain/layout";
const es_isch: WordDefinition = {1: [1, 2, 4, 5, 6, 7]};
const genau: WordDefinition = {3: [7, 8, 9, 10, 11]};
const ab: WordDefinition = {4: [4, 5]};
const vor: WordDefinition = {4: [1, 2, 3]};
const haubi: WordDefinition = {4: [7, 8, 9, 10, 11]};
const fuef: WordDefinition = {1: [9, 10, 11]};
const zae: WordDefinition = {2: [9, 10, 11]};
const viertu: WordDefinition = {2: [1, 2, 3, 4, 5, 6]};
const zwaenzg: WordDefinition = {3: [1, 2, 3, 4, 5, 6]};
export const Layout_de_CH_genau: Layout = {
code: 'de_CH_genau',
hours: {
'0,12': {10: [1, 2, 3, 4, 5, 6]},
'1,13': {5: [1, 2, 3]},
'2,14': {5: [4, 5, 6, 7]},
'3,15': {5: [9, 10, 11]},
'4,16': {6: [1, 2, 3, 4, 5]},
'5,17': {6: [6, 7, 8, 9]},
'6,18': {7: [1, 2, 3, 4, 5, 6]},
'7,19': {7: [7, 8, 9, 10, 11]},
'8,20': {8: [1, 2, 3, 4, 5]},
'9,21': {8: [6, 7, 8, 9]},
'10,22': {9: [1, 2, 3, 4]},
'11,23': {9: [8, 9, 10, 11]}
},
letters: [
'ESKISCHAFÜF',
'VIERTUBFZÄÄ',
'ZWÄNZGGENAU',
'VORABOHAUBI',
'EISZWÖISDRÜ',
'VIERIFÜFIQT',
'SÄCHSISIBNI',
'ACHTINÜNIEL',
'ZÄNIERBEUFI',
'ZWÖUFINAUHR'
],
minutes: {
"0": genau,
"5,6,7,8,9": [fuef, ab],
"10,11,12,13,14": [zae, ab],
"15,16,17,18,19": [viertu, ab],
"20,21,22,23,24": [zwaenzg, ab],
"25,26,27,28,29": [fuef, vor, haubi],
"30,31,32,33,34": haubi,
"35,36,37,38,39": [fuef, ab, haubi],
"40,41,42,43,44": [zwaenzg, vor],
"45,46,47,48,49": [viertu, vor],
"50,51,52,53,54": [zae, vor],
"55,56,57,58,59": [fuef, vor]
},
permanent: es_isch,
prettyName: 'Bärndütsch (genau)',
version: 2
};

View file

@ -244,6 +244,7 @@ class UhrRendererV2Delegate {
}
this.parseTimeDefinition(letters, 'minute', this.layout.minutes);
this.parseTimeDefinition(letters, 'hour', this.layout.hours);
console.log("renderer.ts", "parsed layout", this.layout.code, this.layout, letters);
return letters;
};
@ -294,6 +295,7 @@ export class UhrRenderer {
if (this.layout.version === 2) {
const delegate: UhrRendererV2Delegate = new UhrRendererV2Delegate(this.layout);
const parsedLayout: Letter[][] = delegate.parse();
console.log("renderer.ts", "got parsed layout", parsedLayout);
Object.defineProperty(this.layout, "parsed", {
"value": parsedLayout,
"writable": false,

View file

@ -17,6 +17,7 @@ import {WidgetPrototype} from "./widget/widget-prototype";
import {Globals} from "./domain/globals";
import {UhrRenderer} from "./renderer";
import {EMPTY_LAYOUT, Layout} from "./domain/layout";
import * as Cookies from "js-cookie";
export class Uhr {
@ -176,17 +177,13 @@ export class Uhr {
}
const closebutton = $(`<a class="uhr-closecontrolpanel" id="uhr-closecontrolpanel${this.widgetInstance.uuid}"></a>`);
//FIXME deprecated?!
closebutton.on('click', function () {
$(`#uhr-controlpanel${this.uuid}`).hide('fast');
}.bind(this.widgetInstance));
closebutton.on('click', () => $(`#uhr-controlpanel${this.widgetInstance.uuid}`).hide('fast'));
content.append(closebutton);
e.after(controlpanel);
controlpanel.hide();
const configlink = $(`<a class="uhr-configlink" id="uhr-configlink${this.widgetInstance.uuid}"></a>`);
// FIXME deprecated!?
configlink.on('click', function () {
this.toggleConfigScreen();
}.bind(this));
configlink.on('click', () => this.toggleConfigScreen());
e.after(configlink);
}
};
@ -296,7 +293,7 @@ export class Uhr {
}
private getCookie(cookieName: string): string {
return $.cookie(cookieName + this.widgetInstance.uuid);
return Cookies.get(cookieName + this.widgetInstance.uuid);
}
private setCookie(cookieName: string, cookieValue: string): void {
@ -306,7 +303,7 @@ export class Uhr {
} else {
options = {expires: 365};
}
$.cookie(cookieName + this.widgetInstance.uuid, cookieValue, options);
Cookies.set(cookieName + this.widgetInstance.uuid, cookieValue, options);
}
private update(): void {
@ -383,6 +380,10 @@ export class Uhr {
return hour;
};
private toggleConfigScreen() {
$(`#uhr-controlpanel${this.widgetInstance.uuid}`).toggle('fast');
};
private parseHash(): void {
let hash: string = window.location.hash;
if (hash !== undefined && hash.charAt(0) === '#') {
@ -428,20 +429,3 @@ export class Uhr {
return EMPTY_LAYOUT;
};
}
declare function $(selector: any): JQuery;
declare namespace $ {
const cookie: Cookie;
interface Cookie {
// read all cookies
(): { [name: string]: string }
// read named cookie
(cookieName: string): string;
// set cookie with optional options
(cookieName: string, cookieValue: string, cookieOptions?: any): string;
}
}