2019-08-06 19:18:45 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-08-06 19:38:48 +02:00
|
|
|
import ThemeManager from "../utils/ThemeManager";
|
2019-11-02 15:44:19 +01:00
|
|
|
import WebViewScreen from "../components/WebViewScreen";
|
2019-11-08 12:27:15 +01:00
|
|
|
import i18n from "i18n-js";
|
2019-08-06 19:18:45 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-08 13:57:03 +02:00
|
|
|
const PLANEX_URL = 'http://planex.insa-toulouse.fr/';
|
2019-08-06 19:18:45 +02:00
|
|
|
|
2019-11-08 14:36:53 +01:00
|
|
|
const CUSTOM_CSS_GENERAL = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/custom_css/planex/customMobile2.css';
|
|
|
|
const CUSTOM_CSS_NIGHTMODE = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/custom_css/planex/customDark2.css';
|
2019-11-02 15:44:19 +01:00
|
|
|
|
2020-01-28 10:43:11 +01:00
|
|
|
// // JS + JQuery functions used to remove alpha from events. Copy paste in browser console for quick testing
|
|
|
|
// // Remove alpha from given Jquery node
|
2020-01-27 22:45:22 +01:00
|
|
|
// function removeAlpha(node) {
|
|
|
|
// console.log(node);
|
|
|
|
// let bg = node.css("background-color");
|
|
|
|
// if (bg.match("^rgba")) {
|
|
|
|
// let a = bg.slice(5).split(',');
|
|
|
|
// let newBg ='rgb(' + a[0] + ',' + parseInt(a[1]) + ',' + parseInt(a[2]) + ')';
|
|
|
|
// node.css("background-color", newBg);
|
|
|
|
// }
|
|
|
|
// }
|
2020-01-28 10:43:11 +01:00
|
|
|
// // Observe for planning DOM changes
|
2020-01-27 22:45:22 +01:00
|
|
|
// let observer = new MutationObserver(function(mutations) {
|
|
|
|
// for (let i = 0; i < mutations.length; i++) {
|
|
|
|
// if (mutations[i]['addedNodes'].length > 0 && $(mutations[i]['addedNodes'][0]).hasClass("fc-event"))
|
|
|
|
// removeAlpha($(mutations[i]['addedNodes'][0]))
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});
|
2020-01-28 10:43:11 +01:00
|
|
|
// // Run remove alpha a first time on whole planning. Useful when code injected after planning fully loaded.
|
|
|
|
// $(".fc-event-container .fc-event").each(function(index) {
|
|
|
|
// removeAlpha($(this));
|
|
|
|
// });
|
2019-11-10 18:10:24 +01:00
|
|
|
|
|
|
|
// Watch for changes in the calendar and call the remove alpha function
|
|
|
|
const OBSERVE_MUTATIONS_INJECTED =
|
2020-01-27 22:45:22 +01:00
|
|
|
'function removeAlpha(node) {\n' +
|
|
|
|
' console.log(node);\n' +
|
|
|
|
' let bg = node.css("background-color");\n' +
|
|
|
|
' if (bg.match("^rgba")) {\n' +
|
|
|
|
' let a = bg.slice(5).split(\',\');\n' +
|
|
|
|
' let newBg =\'rgb(\' + a[0] + \',\' + parseInt(a[1]) + \',\' + parseInt(a[2]) + \')\';\n' +
|
|
|
|
' node.css("background-color", newBg);\n' +
|
|
|
|
' }\n' +
|
|
|
|
'}' +
|
|
|
|
'let observer = new MutationObserver(function(mutations) {\n' +
|
|
|
|
' for (let i = 0; i < mutations.length; i++) {\n' +
|
|
|
|
' if (mutations[i][\'addedNodes\'].length > 0 && $(mutations[i][\'addedNodes\'][0]).hasClass("fc-event"))\n' +
|
|
|
|
' removeAlpha($(mutations[i][\'addedNodes\'][0]))\n' +
|
|
|
|
' }\n' +
|
|
|
|
'});\n' +
|
2020-01-28 10:43:11 +01:00
|
|
|
'observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});\n' +
|
|
|
|
'$(".fc-event-container .fc-event").each(function(index) {\n' +
|
|
|
|
' removeAlpha($(this));\n' +
|
|
|
|
'});';
|
2019-08-06 19:18:45 +02:00
|
|
|
/**
|
|
|
|
* Class defining the app's planex screen.
|
|
|
|
* This screen uses a webview to render the planex page
|
|
|
|
*/
|
2019-11-02 15:44:19 +01:00
|
|
|
export default class PlanexScreen extends React.Component<Props> {
|
2019-08-06 19:18:45 +02:00
|
|
|
|
2019-08-08 22:07:49 +02:00
|
|
|
customInjectedJS: string;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.customInjectedJS =
|
2019-11-10 18:10:24 +01:00
|
|
|
'$(document).ready(function() {' +
|
|
|
|
OBSERVE_MUTATIONS_INJECTED +
|
|
|
|
'$("head").append(\'<meta name="viewport" content="width=device-width, initial-scale=1.0">\');' +
|
|
|
|
'$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\');';
|
|
|
|
|
2019-08-08 22:07:49 +02:00
|
|
|
if (ThemeManager.getNightMode())
|
2019-11-10 18:10:24 +01:00
|
|
|
this.customInjectedJS += '$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_NIGHTMODE + '" type="text/css"/>\');';
|
|
|
|
|
|
|
|
this.customInjectedJS +=
|
2020-01-29 13:57:48 +01:00
|
|
|
'$(".fc-toolbar .fc-center").append(\'<p id="rotateToLandscape" style="color: ' + ThemeManager.getCurrentThemeVariables().brandPrimary + '">' +
|
|
|
|
i18n.t("planexScreen.rotateToLandscape") + '</p>\');' +
|
|
|
|
'$(".fc-toolbar .fc-center").append(\'<p id="rotateToPortrait" style="color: ' + ThemeManager.getCurrentThemeVariables().brandPrimary + '">' +
|
|
|
|
i18n.t("planexScreen.rotateToPortrait") + '</p>\');' +
|
2019-11-10 18:10:24 +01:00
|
|
|
'removeAlpha();' +
|
|
|
|
'});true;'; // Prevent crash on ios
|
|
|
|
|
2019-08-08 22:07:49 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 19:18:45 +02:00
|
|
|
render() {
|
|
|
|
const nav = this.props.navigation;
|
|
|
|
return (
|
2019-11-02 15:44:19 +01:00
|
|
|
<WebViewScreen
|
|
|
|
navigation={nav}
|
2019-11-08 02:37:38 +01:00
|
|
|
data={[
|
|
|
|
{
|
|
|
|
url: PLANEX_URL,
|
|
|
|
icon: '',
|
|
|
|
name: '',
|
|
|
|
customJS: this.customInjectedJS
|
|
|
|
},
|
|
|
|
]}
|
2019-11-02 15:44:19 +01:00
|
|
|
customInjectedJS={this.customInjectedJS}
|
|
|
|
headerTitle={'Planex'}
|
2019-11-07 10:57:58 +01:00
|
|
|
hasHeaderBackButton={false}
|
|
|
|
hasFooter={false}/>
|
2019-08-06 19:18:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|