2020-11-04 18:01:04 +00:00
|
|
|
import * as plugins from './websetup.plugins';
|
|
|
|
import * as interfaces from './interfaces';
|
|
|
|
import { TagManager } from './websetup.classes.tagmanager';
|
|
|
|
import { TagLevel } from './websetup.classes.taglevel';
|
|
|
|
|
|
|
|
export interface IWebSetupConstructorOptions {
|
|
|
|
metaObject: interfaces.IMetaObject;
|
2020-12-08 22:29:19 +00:00
|
|
|
smartssrWaitForReadySignal?: boolean;
|
2020-11-04 18:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the main WebSetup class
|
|
|
|
*/
|
|
|
|
export class WebSetup {
|
|
|
|
public tagManager: TagManager = new TagManager();
|
|
|
|
public options: IWebSetupConstructorOptions;
|
2020-12-08 22:29:19 +00:00
|
|
|
|
|
|
|
// private deferreds
|
2020-11-04 18:01:04 +00:00
|
|
|
private readyDeferred = plugins.smartpromise.defer();
|
2020-12-08 22:29:19 +00:00
|
|
|
private readyForSmartssrDeferred = plugins.smartpromise.defer();
|
|
|
|
|
|
|
|
// public promises
|
2020-11-04 18:01:04 +00:00
|
|
|
public readyPromise = this.readyDeferred.promise;
|
2020-12-08 22:29:19 +00:00
|
|
|
public readyForSmartssrPromise = this.readyForSmartssrDeferred.promise;
|
2020-11-04 18:01:04 +00:00
|
|
|
constructor(optionsArg: IWebSetupConstructorOptions) {
|
|
|
|
this.options = optionsArg;
|
2020-11-04 18:09:07 +00:00
|
|
|
this.setup().then(() => {
|
|
|
|
this.readyDeferred.resolve();
|
2020-12-08 22:29:19 +00:00
|
|
|
if (!this.options.smartssrWaitForReadySignal) {
|
|
|
|
this.readyForSmartssrDeferred.resolve();
|
|
|
|
}
|
2020-11-04 18:09:07 +00:00
|
|
|
});
|
2020-11-04 18:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* an async setup called by the constructor
|
|
|
|
*/
|
2020-11-05 17:56:35 +00:00
|
|
|
public async setup(optionsArg?: IWebSetupConstructorOptions) {
|
|
|
|
if (optionsArg) {
|
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
2020-11-04 18:01:04 +00:00
|
|
|
await this.tagManager.setup(this.options.metaObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reverts the active level and returns to the base level
|
|
|
|
*/
|
|
|
|
public revertToBaseLevel() {
|
|
|
|
this.tagManager.revertToBaseLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets a subpage
|
2020-11-05 15:35:31 +00:00
|
|
|
* @param metaObjectArg
|
2020-11-04 18:01:04 +00:00
|
|
|
*/
|
2020-11-05 18:36:08 +00:00
|
|
|
public async setSubLevel(metaObjectArg: interfaces.IMetaObject) {
|
|
|
|
const subLevel = await this.tagManager.setSubPageLevel(metaObjectArg);
|
|
|
|
return subLevel;
|
2020-11-05 15:35:31 +00:00
|
|
|
}
|
2020-11-05 20:03:12 +00:00
|
|
|
|
|
|
|
public flashTitle(flashTextArg: string) {}
|
2020-12-08 22:29:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* informs smartssr that the page is ready to be rendered
|
|
|
|
*/
|
|
|
|
public informReadyForSmartssr() {
|
|
|
|
if (!this.options.smartssrWaitForReadySignal) {
|
|
|
|
console.error(`You have not indicated that you inform smartssr by a dedicated signal! Please consider doing so!`);
|
|
|
|
}
|
|
|
|
this.readyForSmartssrDeferred.resolve();
|
|
|
|
}
|
2020-11-04 18:01:04 +00:00
|
|
|
}
|