in public/src/js/widgets/columns/fronts.js [17:145]
constructor(params, element) {
super(params, element);
if (isCodeEnvironment(this.baseModel.state().defaults)) {
this.baseModel.message.codeEnvMessage(true);
}
var frontId = params.column.config();
this.front = ko.observable(frontId);
this.previousFront = frontId;
this.frontAge = ko.observable();
this.collections = ko.observableArray();
this.mode = ko.observable(params.mode || 'draft');
this.flattenGroups = ko.observable(params.mode === 'treats');
this.maxArticlesInHistory = this.confirmSendingAlert() ? 20 : 5;
this.controlsVisible = ko.observable(false);
this.authorized = ko.observable(isAuthorized(this.baseModel, frontId));
this.isHidden = ko.observable();
this.frontsList = ko.pureComputed(() => {
return this.baseModel.frontsList().filter(front => {
return CONST.askForConfirmation.indexOf(front.id) === -1;
});
});
this.subscribeOn(this.front, this.onFrontChange);
this.subscribeOn(this.mode, this.onModeChange);
this.subscribeOn(this.baseModel.permissions, () => {
this.authorized(isAuthorized(this.baseModel, this.front()));
});
this.setFront = id => this.front(id);
this.setModeLive = () => {
this.mode('live');
trackAction('front', 'mode', 'live');
};
this.setModeDraft = () => {
this.mode('draft');
trackAction('front', 'mode', 'draft');
};
this.trackPreviewClick = () => {
trackAction('outbound', 'preview', this.mode());
return true;
};
this.frontMode = ko.pureComputed(() => {
var classes = [this.mode() + '-mode'];
if (this.confirmSendingAlert()) {
classes.push('attention');
}
return classes.join(' ');
});
this.previewUrl = ko.pureComputed(() => {
var path = this.mode() === 'live' ? 'https://' + CONST.viewerHost + '/proxy/live' : CONST.previewBase;
return CONST.previewBase + '/responsive-viewer/' + path + '/' + this.front();
});
this.isControlsVisible = ko.observable(sparklines.isEnabled());
this.controlsText = ko.pureComputed(() => {
return 'Sparklines: ' + this.sparklinesOptions().hours + 'h';
});
this.ophanPerformances = ko.pureComputed(() => {
return CONST.ophanFrontBase + encodeURIComponent('/' + this.front());
});
this.alertFrontIsStale = ko.observable();
this.uiOpenArticle = ko.observable();
this.allExpanded = ko.observable(true);
this.listenOn(mediator, 'presser:lastupdate', (front, lastPressed) => {
// The event :lastupdate is raised only for live events, lastUpdate includes draft changes
if (front === this.front()) {
this.frontAge(humanTime(lastPressed));
if (this.baseModel.state().defaults.env !== 'dev') {
const stale = _.some(this.collections(), collection => {
const lastUpdated = new Date(collection.state.lastUpdated());
return _.isDate(lastUpdated) ? lastUpdated - lastPressed > CONST.detectPressFailureMs : false;
});
if (stale) {
mediator.emit('presser:stale', 'Sorry, the latest edit to the front \'' + front + '\' hasn\'t gone live.');
}
}
}
});
this.listenOn(mediator, 'ui:open', (element, article, front) => {
if (front !== this) {
return;
}
var openArticle = this.uiOpenArticle();
if (openArticle && openArticle.group &&
openArticle.group.parentType === 'Article' &&
openArticle !== article) {
openArticle.close();
}
this.uiOpenArticle(article);
});
this.listenOn(mediator, 'presser:live', this.pressLiveFront);
this.listenOn(mediator, 'alert:dismiss', () => this.alertFrontIsStale(false));
this.listenOn(mediator, 'collection:collapse', this.onCollectionCollapse);
this.subscribeOn(this.column.config, newConfig => {
if (newConfig !== this.front()) {
this.front(newConfig);
}
});
this.setIntervals = [];
this.setTimeouts = [];
this.refreshCollections(CONST.collectionsPollMs || 60000);
this.refreshRelativeTimes(CONST.pubTimeRefreshMs || 60000);
this.presser = new Presser();
this.sparklinesOptions = ko.observable({
hours: 1,
interval: 10
});
if (this.authorized()) {
this.load(frontId);
sparklines.subscribe(this);
} else {
this.loaded = Promise.resolve(this);
}
}