Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.

WebsiteScreen.tsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import { StackNavigationProp } from '@react-navigation/stack';
  21. import WebViewScreen from '../../components/Screens/WebViewScreen';
  22. import BasicLoadingScreen from '../../components/Screens/BasicLoadingScreen';
  23. import Urls from '../../constants/Urls';
  24. type Props = {
  25. navigation: StackNavigationProp<any>;
  26. route: { params: { host: string; path: string | null; title: string } };
  27. };
  28. type State = {
  29. url: string;
  30. };
  31. const ENABLE_MOBILE_STRING =
  32. '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
  33. const AVAILABLE_ROOMS_STYLE =
  34. '<style>body,body>.container2{padding-top:0;width:100%}b,body>.container2>h1,body>.container2>h3,br,header{display:none}.table-bordered td,.table-bordered th{border:none;border-right:1px solid #dee2e6;border-bottom:1px solid #dee2e6}.table{padding:0;margin:0;width:200%;max-width:200%;display:block}tbody{display:block;width:100%}thead{display:block;width:100%}.table tbody tr,tbody tr[bgcolor],thead tr{width:100%;display:inline-flex}.table tbody td,.table thead td[colspan]{padding:0;flex:1;height:50px;margin:0}.table tbody td[bgcolor=white],.table thead td,.table>tbody>tr>td:nth-child(1){flex:0 0 150px;height:50px}</style>';
  35. const BIB_STYLE =
  36. '<style>.hero-unit,.navbar,footer{display:none}.hero-unit-form,.hero-unit2,.hero-unit3{background-color:#fff;box-shadow:none;padding:0;margin:0}.hero-unit-form h4{font-size:2rem;line-height:2rem}.btn{font-size:1.5rem;line-height:1.5rem;padding:20px}.btn-danger{background-image:none;background-color:#be1522}.table{font-size:.8rem}.table td{padding:0;height:18.2333px;border:none;border-bottom:1px solid #c1c1c1}.table td[style="max-width:55px;"]{max-width:110px!important}.table-bordered{min-width:50px}th{height:50px}.table-bordered{border-collapse:collapse}</style>';
  37. const BIB_BACK_BUTTON =
  38. "<div style='width: 100%; display: flex'>" +
  39. `<a style='margin: auto' href='${Urls.websites.bib}'>` +
  40. "<button id='customBackButton' class='btn btn-primary'>Retour</button>" +
  41. '</a>' +
  42. '</div>';
  43. class WebsiteScreen extends React.Component<Props, State> {
  44. injectedJS: { [key: string]: string };
  45. customPaddingFunctions: { [key: string]: (padding: number) => string };
  46. host: string;
  47. constructor(props: Props) {
  48. super(props);
  49. this.state = {
  50. url: '',
  51. };
  52. this.host = '';
  53. props.navigation.addListener('focus', this.onScreenFocus);
  54. this.injectedJS = {};
  55. this.customPaddingFunctions = {};
  56. this.injectedJS[Urls.websites.availableRooms] =
  57. `document.querySelector('head').innerHTML += '${ENABLE_MOBILE_STRING}';` +
  58. `document.querySelector('head').innerHTML += '${AVAILABLE_ROOMS_STYLE}'; true;`;
  59. this.injectedJS[Urls.websites.bib] =
  60. `document.querySelector('head').innerHTML += '${ENABLE_MOBILE_STRING}';` +
  61. `document.querySelector('head').innerHTML += '${BIB_STYLE}';` +
  62. 'if ($(".hero-unit-form").length > 0 && $("#customBackButton").length === 0)' +
  63. `$(".hero-unit-form").append("${BIB_BACK_BUTTON}");true;`;
  64. this.customPaddingFunctions[Urls.websites.bluemind] = (
  65. padding: number
  66. ): string => {
  67. return (
  68. `$('head').append('${ENABLE_MOBILE_STRING}');` +
  69. `$('.minwidth').css('top', ${padding}` +
  70. "$('#mailview-bottom').css('min-height', 500);"
  71. );
  72. };
  73. this.customPaddingFunctions[Urls.websites.wiketud] = (
  74. padding: number
  75. ): string => {
  76. return (
  77. `$('#p-logo-text').css('top', 10 + ${padding});` +
  78. `$('#site-navigation h2').css('top', 10 + ${padding});` +
  79. `$('#site-tools h2').css('top', 10 + ${padding});` +
  80. `$('#user-tools h2').css('top', 10 + ${padding});`
  81. );
  82. };
  83. }
  84. onScreenFocus = () => {
  85. this.handleNavigationParams();
  86. };
  87. /**
  88. *
  89. */
  90. handleNavigationParams() {
  91. const { route, navigation } = this.props;
  92. if (route.params != null) {
  93. this.host = route.params.host;
  94. let { path } = route.params;
  95. const { title } = route.params;
  96. let fullUrl = '';
  97. if (this.host != null && path != null) {
  98. path = path.replace(this.host, '');
  99. fullUrl = this.host + path;
  100. } else {
  101. fullUrl = this.host;
  102. }
  103. this.setState({ url: fullUrl });
  104. if (title != null) {
  105. navigation.setOptions({ title });
  106. }
  107. }
  108. }
  109. render() {
  110. let injectedJavascript = '';
  111. let customPadding = null;
  112. if (this.host != null && this.injectedJS[this.host] != null) {
  113. injectedJavascript = this.injectedJS[this.host];
  114. }
  115. if (this.host != null && this.customPaddingFunctions[this.host] != null) {
  116. customPadding = this.customPaddingFunctions[this.host];
  117. }
  118. if (this.state.url) {
  119. return (
  120. <WebViewScreen
  121. url={this.state.url}
  122. initialJS={injectedJavascript}
  123. customPaddingFunction={customPadding}
  124. />
  125. );
  126. }
  127. return <BasicLoadingScreen />;
  128. }
  129. }
  130. export default WebsiteScreen;