Add notifications

This commit is contained in:
Anton Vakhrushev 2020-04-02 12:15:53 +03:00
parent 23f3743599
commit 163375f62d
2 changed files with 32 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import * as URLParse from 'url-parse';
import { markPage, sleep, uniqId } from './utils';
import { markPage, sleepShort, uniqId } from './utils';
import Scheduler from './Scheduler';
import UpgradeBuildingTask from './Task/UpgradeBuildingTask';
import { Command } from './Common';
@ -16,13 +16,14 @@ export default class Dashboard {
async run() {
await this.load();
await sleep(1000);
await sleepShort();
const p = new URLParse(window.location.href, true);
console.log('PARSED LOCATION', p);
this.log('PARSED LOCATION', p);
markPage('Dashboard', this.version);
new TaskQueueRenderer().render(this.scheduler.getTaskItems());
this.renderTaskQueue();
setInterval(() => this.renderTaskQueue(), 5000);
if (p.pathname === '/dorf1.php') {
this.showSlotIds('buildingSlot');
@ -33,21 +34,32 @@ export default class Dashboard {
}
if (p.pathname === '/build.php') {
console.log('BUILD PAGE DETECTED');
this.log('BUILD PAGE DETECTED');
const id = uniqId();
jQuery('.upgradeButtonsContainer .section1').append(
`<div style="padding: 8px"><a id="${id}" href="#">В очередь</a></div>`
);
jQuery(`#${id}`).on('click', () => {
const queueItem = new Command(UpgradeBuildingTask.NAME, {
id: p.query['id'],
});
this.scheduler.scheduleTask(queueItem);
return false;
jQuery(`#${id}`).on('click', evt => {
evt.preventDefault();
this.onScheduleBuilding(p.query.id || '');
});
}
}
private renderTaskQueue() {
this.log('RENDER TASK QUEUE');
new TaskQueueRenderer().render(this.scheduler.getTaskItems());
}
private onScheduleBuilding(id: string) {
const queueItem = new Command(UpgradeBuildingTask.NAME, {
id,
});
this.scheduler.scheduleTask(queueItem);
const n = new Notification(`Building ${id} scheduled`);
setTimeout(() => n && n.close(), 4000);
}
private showSlotIds(prefix: string) {
jQuery('.level.colorLayer').each((idx, el) => {
let num = '';
@ -68,4 +80,12 @@ export default class Dashboard {
private async load() {
return new Promise(resolve => jQuery(resolve));
}
private log(...args) {
console.log('SCHEDULER:', ...args);
}
private logError(...args) {
console.error(...args);
}
}

View File

@ -26,6 +26,7 @@ export default class Scheduler {
await sleepShort();
markPage('Executor', this.version);
this.renderTaskQueue();
setInterval(() => this.renderTaskQueue(), 5000);
while (true) {