forked from openlp/openlp
Added queuing functionality to the alerts
This commit is contained in:
parent
1bdc2f5df6
commit
72980b5365
@ -55,11 +55,10 @@ var AudioState = {
|
|||||||
/**
|
/**
|
||||||
* Transition state enumeration
|
* Transition state enumeration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var TransitionState = {
|
var TransitionState = {
|
||||||
EntranceTransition: "entranceTransition",
|
EntranceTransition: "entranceTransition",
|
||||||
NoTransition: "noTransition",
|
NoTransition: "noTransition",
|
||||||
ExitTransition: "exitTransition"
|
ExitTransition: "exitTransition"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +68,7 @@ var AnimationState = {
|
|||||||
NoAnimation: "noAnimation",
|
NoAnimation: "noAnimation",
|
||||||
ScrollingAnimation: "scrollingAnimation"
|
ScrollingAnimation: "scrollingAnimation"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alert location enumeration
|
* Alert location enumeration
|
||||||
*/
|
*/
|
||||||
@ -78,10 +78,10 @@ var AlertLocation = {
|
|||||||
Bottom: 2
|
Bottom: 2
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
var AlertState = {
|
||||||
*
|
Displaying: "displaying",
|
||||||
* @param {Location} selector
|
NotDisplaying: "notDisplaying"
|
||||||
*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array of elements based on the selector query
|
* Return an array of elements based on the selector query
|
||||||
@ -283,7 +283,9 @@ AudioPlayer.prototype.stop = function () {
|
|||||||
* The Display object is what we use from OpenLP
|
* The Display object is what we use from OpenLP
|
||||||
*/
|
*/
|
||||||
var Display = {
|
var Display = {
|
||||||
|
_alerts: [],
|
||||||
_slides: {},
|
_slides: {},
|
||||||
|
_alertState: AlertState.NotDisplaying,
|
||||||
_transitionState: TransitionState.NoTransition,
|
_transitionState: TransitionState.NoTransition,
|
||||||
_animationState: AnimationState.NoAnimation,
|
_animationState: AnimationState.NoAnimation,
|
||||||
_revealConfig: {
|
_revealConfig: {
|
||||||
@ -404,6 +406,23 @@ var Display = {
|
|||||||
Display._slides['0'] = 0;
|
Display._slides['0'] = 0;
|
||||||
Display.reinit();
|
Display.reinit();
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Display the next alert in the queue
|
||||||
|
*/
|
||||||
|
getNextAlert: function () {
|
||||||
|
|
||||||
|
console.debug("Checking queue for alerts");
|
||||||
|
if (Display._alerts.length > 0) {
|
||||||
|
var alertObject = JSON.parse(this._alerts.shift());
|
||||||
|
setTimeout(function() {
|
||||||
|
Display.alert(alertObject.text, alertObject.settings);
|
||||||
|
},1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.debug("No alerts found");
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Display an alert
|
* Display an alert
|
||||||
* @param {string} text - The alert text
|
* @param {string} text - The alert text
|
||||||
@ -415,18 +434,26 @@ var Display = {
|
|||||||
if (text == "") {
|
if (text == "") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (this._alertState === AlertState.Displaying) {
|
||||||
|
var alertObject = {};
|
||||||
|
alertObject.text = text;
|
||||||
|
alertObject.settings = alert_settings;
|
||||||
|
this._alerts.push(JSON.stringify(alertObject));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
var settings = JSON.parse(alert_settings);
|
var settings = JSON.parse(alert_settings);
|
||||||
|
|
||||||
var alertBackground = $("#alert-background")[0];
|
var alertBackground = $("#alert-background")[0];
|
||||||
var alertText = $("#alert")[0];
|
var alertText = $("#alert")[0];
|
||||||
|
alertText.innerHTML = text;
|
||||||
alertText.innerHTML = text;
|
|
||||||
|
|
||||||
/* Start the entrance transition */
|
/* Start the entrance transition */
|
||||||
Display._transitionState = Display.doEntranceTransition(settings);
|
this._alertState = AlertState.Displaying;
|
||||||
// TODO: Add functinoality for no scroll and queue if not all alerts have been displayed
|
this._transitionState = Display.doEntranceTransition(settings);
|
||||||
alertBackground.addEventListener('transitionend', function (e) {
|
|
||||||
|
// TODO: Add functionality for no scroll and queue if not all alerts have been displayed
|
||||||
|
alertBackground.addEventListener('transitionend', function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (Display._transitionState === TransitionState.EntranceTransition) {
|
if (Display._transitionState === TransitionState.EntranceTransition) {
|
||||||
alertText.style.visibility = "visible";
|
alertText.style.visibility = "visible";
|
||||||
@ -436,9 +463,11 @@ var Display = {
|
|||||||
}
|
}
|
||||||
else if (Display._transitionState === TransitionState.ExitTransition) {
|
else if (Display._transitionState === TransitionState.ExitTransition) {
|
||||||
Display._transitionState = TransitionState.NoTransition;
|
Display._transitionState = TransitionState.NoTransition;
|
||||||
|
Display._alertState = AlertState.NotDisplaying;
|
||||||
alertText.style.visibility = "hidden";
|
alertText.style.visibility = "hidden";
|
||||||
alertBackground.classList = "";
|
alertBackground.classList = "";
|
||||||
alertBackground.classList.add("normal");
|
alertBackground.classList.add("normal");
|
||||||
|
Display.getNextAlert();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -447,16 +476,10 @@ var Display = {
|
|||||||
if (Display._animationState === AnimationState.ScrollingAnimation) {
|
if (Display._animationState === AnimationState.ScrollingAnimation) {
|
||||||
alertText.classList.remove("horizontal-scroll-animation");
|
alertText.classList.remove("horizontal-scroll-animation");
|
||||||
alertText.style.visibility = "hidden";
|
alertText.style.visibility = "hidden";
|
||||||
Display._animationState = AnimationState.NoAnimation;
|
Display._animationState = AnimationState.NoAnimation;
|
||||||
Display._transitionState = Display.doExitTransition();
|
Display.doExitTransition();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* The implementation should show an alert.
|
|
||||||
* It should be able to handle receiving a new alert before a previous one is "finished", basically queueing it.
|
|
||||||
*/
|
|
||||||
return settings.location;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -471,7 +494,6 @@ var Display = {
|
|||||||
alertBackground.classList.add("top");
|
alertBackground.classList.add("top");
|
||||||
break;
|
break;
|
||||||
case AlertLocation.Middle:
|
case AlertLocation.Middle:
|
||||||
// alertBackground.style.top = ((window.innerHeight - alertBackground.clientHeight) / 2) + 'px';
|
|
||||||
alertBackground.classList.add("middle");
|
alertBackground.classList.add("middle");
|
||||||
break;
|
break;
|
||||||
case AlertLocation.Bottom:
|
case AlertLocation.Bottom:
|
||||||
@ -486,7 +508,7 @@ var Display = {
|
|||||||
// Wait for styles to be set first before starting transitions
|
// Wait for styles to be set first before starting transitions
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
alertBackground.style.height = "25%";
|
alertBackground.style.height = "25%";
|
||||||
alertBackground.style.transition = "2s linear";
|
alertBackground.style.transition = "1s linear";
|
||||||
alertBackground.style.visibility = "visible";
|
alertBackground.style.visibility = "visible";
|
||||||
}, 50);
|
}, 50);
|
||||||
return TransitionState.EntranceTransition;
|
return TransitionState.EntranceTransition;
|
||||||
@ -499,8 +521,8 @@ var Display = {
|
|||||||
doExitTransition: function () {
|
doExitTransition: function () {
|
||||||
var alertBackground = $("#alert-background")[0];
|
var alertBackground = $("#alert-background")[0];
|
||||||
alertBackground.style.height = "0%";
|
alertBackground.style.height = "0%";
|
||||||
alertBackground.style.transition = "2s linear";
|
alertBackground.style.transition = "1s linear";
|
||||||
return TransitionState.ExitTransition;
|
this._transitionState = TransitionState.ExitTransition;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Add a slides. If the slide exists but the HTML is different, update the slide.
|
* Add a slides. If the slide exists but the HTML is different, update the slide.
|
||||||
|
@ -402,4 +402,4 @@ class DisplayWindow(QtWidgets.QWidget):
|
|||||||
Set an alert
|
Set an alert
|
||||||
"""
|
"""
|
||||||
self.run_javascript('Display.alert("{text}", \'{settings}\');'.format(text=text, settings=settings))
|
self.run_javascript('Display.alert("{text}", \'{settings}\');'.format(text=text, settings=settings))
|
||||||
# TODO: Add option scrolling option
|
# TODO: Add option to prevent scrolling
|
||||||
|
@ -101,7 +101,7 @@ class AlertsManager(QtCore.QObject, RegistryBase, LogMixin, RegistryProperties):
|
|||||||
}
|
}
|
||||||
self.live_controller.displays[0].alert(text, json.dumps(alert_settings))
|
self.live_controller.displays[0].alert(text, json.dumps(alert_settings))
|
||||||
# Check to see if we have a timer running.
|
# Check to see if we have a timer running.
|
||||||
#if self.timer_id == 0:
|
# if self.timer_id == 0:
|
||||||
# self.timer_id = self.startTimer(int(alert_tab.timeout) * 1000)
|
# self.timer_id = self.startTimer(int(alert_tab.timeout) * 1000)
|
||||||
|
|
||||||
def timerEvent(self, event):
|
def timerEvent(self, event):
|
||||||
@ -125,4 +125,4 @@ class AlertsManager(QtCore.QObject, RegistryBase, LogMixin, RegistryProperties):
|
|||||||
:return: rgb color string
|
:return: rgb color string
|
||||||
:rtype: string
|
:rtype: string
|
||||||
"""
|
"""
|
||||||
return "rgb(" + rgb_values.red() + ", " + rgb_values.green() + ", " + rgb_values.blue() + ")"
|
return "rgb(" + str(rgb_values.red()) + ", " + str(rgb_values.green()) + ", " + str(rgb_values.blue()) + ")"
|
||||||
|
@ -155,6 +155,7 @@ describe("The Display object", function () {
|
|||||||
|
|
||||||
describe("Display.alert", function () {
|
describe("Display.alert", function () {
|
||||||
var alertBackground, alert, settings;
|
var alertBackground, alert, settings;
|
||||||
|
var alerts = [];
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
document.body.innerHTML = "";
|
document.body.innerHTML = "";
|
||||||
@ -182,6 +183,10 @@ describe("Display.alert", function () {
|
|||||||
it("should set the correct alert position", function () {
|
it("should set the correct alert position", function () {
|
||||||
expect(Display.alert("Alert Location Test", settings)).toEqual(1);
|
expect(Display.alert("Alert Location Test", settings)).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should add the alert to the alert queue", function() {
|
||||||
|
//Uses the alerts array
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("The doEntranceTransition", function () {
|
describe("The doEntranceTransition", function () {
|
||||||
@ -222,7 +227,7 @@ describe("The doEntranceTransition", function () {
|
|||||||
expect(alertBackground.style.backgroundColor).toEqual(settings.background_color);
|
expect(alertBackground.style.backgroundColor).toEqual(settings.background_color);
|
||||||
expect(alertBackground.classList.contains("bottom")).toBe(true);
|
expect(alertBackground.classList.contains("bottom")).toBe(true);
|
||||||
expect(alertBackground.style.height).toEqual("25%");
|
expect(alertBackground.style.height).toEqual("25%");
|
||||||
expect(alertBackground.style.transition).toEqual("2s linear");
|
expect(alertBackground.style.transition).toEqual("1s linear");
|
||||||
expect(alertBackground.style.visibility).toEqual("visible");
|
expect(alertBackground.style.visibility).toEqual("visible");
|
||||||
done();
|
done();
|
||||||
}, 60);
|
}, 60);
|
||||||
@ -267,7 +272,7 @@ describe("The doExitTransition", function () {
|
|||||||
Display.doExitTransition();
|
Display.doExitTransition();
|
||||||
|
|
||||||
expect(alertBackground.style.height).toEqual('0%');
|
expect(alertBackground.style.height).toEqual('0%');
|
||||||
expect(alertBackground.style.transition).toEqual("2s linear");
|
expect(alertBackground.style.transition).toEqual("1s linear");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user