Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlanexScreen.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @flow
  2. import * as React from 'react';
  3. import ThemeManager from "../utils/ThemeManager";
  4. import WebViewScreen from "../components/WebViewScreen";
  5. import i18n from "i18n-js";
  6. type Props = {
  7. navigation: Object,
  8. }
  9. const PLANEX_URL = 'http://planex.insa-toulouse.fr/';
  10. const CUSTOM_CSS_GENERAL = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/custom_css/planex/customMobile2.css';
  11. const CUSTOM_CSS_NIGHTMODE = 'https://srv-falcon.etud.insa-toulouse.fr/~amicale_app/custom_css/planex/customDark2.css';
  12. // // JS + JQuery functions used to remove alpha from events. Copy paste in browser console for quick testing
  13. // // Remove alpha from given Jquery node
  14. // function removeAlpha(node) {
  15. // console.log(node);
  16. // let bg = node.css("background-color");
  17. // if (bg.match("^rgba")) {
  18. // let a = bg.slice(5).split(',');
  19. // let newBg ='rgb(' + a[0] + ',' + parseInt(a[1]) + ',' + parseInt(a[2]) + ')';
  20. // node.css("background-color", newBg);
  21. // }
  22. // }
  23. // // Observe for planning DOM changes
  24. // let observer = new MutationObserver(function(mutations) {
  25. // for (let i = 0; i < mutations.length; i++) {
  26. // if (mutations[i]['addedNodes'].length > 0 && $(mutations[i]['addedNodes'][0]).hasClass("fc-event"))
  27. // removeAlpha($(mutations[i]['addedNodes'][0]))
  28. // }
  29. // });
  30. // observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});
  31. // // Run remove alpha a first time on whole planning. Useful when code injected after planning fully loaded.
  32. // $(".fc-event-container .fc-event").each(function(index) {
  33. // removeAlpha($(this));
  34. // });
  35. // Watch for changes in the calendar and call the remove alpha function
  36. const OBSERVE_MUTATIONS_INJECTED =
  37. 'function removeAlpha(node) {\n' +
  38. ' console.log(node);\n' +
  39. ' let bg = node.css("background-color");\n' +
  40. ' if (bg.match("^rgba")) {\n' +
  41. ' let a = bg.slice(5).split(\',\');\n' +
  42. ' let newBg =\'rgb(\' + a[0] + \',\' + parseInt(a[1]) + \',\' + parseInt(a[2]) + \')\';\n' +
  43. ' node.css("background-color", newBg);\n' +
  44. ' }\n' +
  45. '}' +
  46. 'let observer = new MutationObserver(function(mutations) {\n' +
  47. ' for (let i = 0; i < mutations.length; i++) {\n' +
  48. ' if (mutations[i][\'addedNodes\'].length > 0 && $(mutations[i][\'addedNodes\'][0]).hasClass("fc-event"))\n' +
  49. ' removeAlpha($(mutations[i][\'addedNodes\'][0]))\n' +
  50. ' }\n' +
  51. '});\n' +
  52. 'observer.observe(document.querySelector(".fc-body"), {attributes: false, childList: true, characterData: false, subtree:true});\n' +
  53. '$(".fc-event-container .fc-event").each(function(index) {\n' +
  54. ' removeAlpha($(this));\n' +
  55. '});';
  56. /**
  57. * Class defining the app's planex screen.
  58. * This screen uses a webview to render the planex page
  59. */
  60. export default class PlanexScreen extends React.Component<Props> {
  61. customInjectedJS: string;
  62. constructor() {
  63. super();
  64. this.customInjectedJS =
  65. '$(document).ready(function() {' +
  66. OBSERVE_MUTATIONS_INJECTED +
  67. '$("head").append(\'<meta name="viewport" content="width=device-width, initial-scale=1.0">\');' +
  68. '$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\');';
  69. if (ThemeManager.getNightMode())
  70. this.customInjectedJS += '$("head").append(\'<link rel="stylesheet" href="' + CUSTOM_CSS_NIGHTMODE + '" type="text/css"/>\');';
  71. this.customInjectedJS +=
  72. '$(".fc-toolbar .fc-center").append(\'<p id="rotateToLandscape" style="color: ' + ThemeManager.getCurrentThemeVariables().brandPrimary + '">' +
  73. i18n.t("planexScreen.rotateToLandscape") + '</p>\');' +
  74. '$(".fc-toolbar .fc-center").append(\'<p id="rotateToPortrait" style="color: ' + ThemeManager.getCurrentThemeVariables().brandPrimary + '">' +
  75. i18n.t("planexScreen.rotateToPortrait") + '</p>\');' +
  76. 'removeAlpha();' +
  77. '});true;'; // Prevent crash on ios
  78. }
  79. render() {
  80. const nav = this.props.navigation;
  81. return (
  82. <WebViewScreen
  83. navigation={nav}
  84. data={[
  85. {
  86. url: PLANEX_URL,
  87. icon: '',
  88. name: '',
  89. customJS: this.customInjectedJS
  90. },
  91. ]}
  92. customInjectedJS={this.customInjectedJS}
  93. headerTitle={'Planex'}
  94. hasHeaderBackButton={false}
  95. hasFooter={false}/>
  96. );
  97. }
  98. }