Add notifications
This commit is contained in:
parent
23f3743599
commit
163375f62d
@ -1,5 +1,5 @@
|
|||||||
import * as URLParse from 'url-parse';
|
import * as URLParse from 'url-parse';
|
||||||
import { markPage, sleep, uniqId } from './utils';
|
import { markPage, sleepShort, uniqId } from './utils';
|
||||||
import Scheduler from './Scheduler';
|
import Scheduler from './Scheduler';
|
||||||
import UpgradeBuildingTask from './Task/UpgradeBuildingTask';
|
import UpgradeBuildingTask from './Task/UpgradeBuildingTask';
|
||||||
import { Command } from './Common';
|
import { Command } from './Common';
|
||||||
@ -16,13 +16,14 @@ export default class Dashboard {
|
|||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
await this.load();
|
await this.load();
|
||||||
await sleep(1000);
|
await sleepShort();
|
||||||
|
|
||||||
const p = new URLParse(window.location.href, true);
|
const p = new URLParse(window.location.href, true);
|
||||||
console.log('PARSED LOCATION', p);
|
this.log('PARSED LOCATION', p);
|
||||||
|
|
||||||
markPage('Dashboard', this.version);
|
markPage('Dashboard', this.version);
|
||||||
new TaskQueueRenderer().render(this.scheduler.getTaskItems());
|
this.renderTaskQueue();
|
||||||
|
setInterval(() => this.renderTaskQueue(), 5000);
|
||||||
|
|
||||||
if (p.pathname === '/dorf1.php') {
|
if (p.pathname === '/dorf1.php') {
|
||||||
this.showSlotIds('buildingSlot');
|
this.showSlotIds('buildingSlot');
|
||||||
@ -33,21 +34,32 @@ export default class Dashboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p.pathname === '/build.php') {
|
if (p.pathname === '/build.php') {
|
||||||
console.log('BUILD PAGE DETECTED');
|
this.log('BUILD PAGE DETECTED');
|
||||||
const id = uniqId();
|
const id = uniqId();
|
||||||
jQuery('.upgradeButtonsContainer .section1').append(
|
jQuery('.upgradeButtonsContainer .section1').append(
|
||||||
`<div style="padding: 8px"><a id="${id}" href="#">В очередь</a></div>`
|
`<div style="padding: 8px"><a id="${id}" href="#">В очередь</a></div>`
|
||||||
);
|
);
|
||||||
jQuery(`#${id}`).on('click', () => {
|
jQuery(`#${id}`).on('click', evt => {
|
||||||
const queueItem = new Command(UpgradeBuildingTask.NAME, {
|
evt.preventDefault();
|
||||||
id: p.query['id'],
|
this.onScheduleBuilding(p.query.id || '');
|
||||||
});
|
|
||||||
this.scheduler.scheduleTask(queueItem);
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
private showSlotIds(prefix: string) {
|
||||||
jQuery('.level.colorLayer').each((idx, el) => {
|
jQuery('.level.colorLayer').each((idx, el) => {
|
||||||
let num = '';
|
let num = '';
|
||||||
@ -68,4 +80,12 @@ export default class Dashboard {
|
|||||||
private async load() {
|
private async load() {
|
||||||
return new Promise(resolve => jQuery(resolve));
|
return new Promise(resolve => jQuery(resolve));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private log(...args) {
|
||||||
|
console.log('SCHEDULER:', ...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private logError(...args) {
|
||||||
|
console.error(...args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ export default class Scheduler {
|
|||||||
await sleepShort();
|
await sleepShort();
|
||||||
markPage('Executor', this.version);
|
markPage('Executor', this.version);
|
||||||
|
|
||||||
|
this.renderTaskQueue();
|
||||||
setInterval(() => this.renderTaskQueue(), 5000);
|
setInterval(() => this.renderTaskQueue(), 5000);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user