Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

245 lines
8.5KB

  1. <!--
  2. # @name: base.html
  3. # @version: 0.1
  4. # @creation_date: 2021-10-20
  5. # @license: The MIT License <https://opensource.org/licenses/MIT>
  6. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  7. # @purpose: Basic layout for all pages
  8. # @acknowledgements:
  9. # https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3
  10. # Bootstrap 5.1.3: https://getbootstrap.com/
  11. # Flask-Moment: https://flask-moment.readthedocs.io/en/latest/
  12. # Boostrap select: https://stackoverflow.com/questions/67942546/bootstrap-5-select-dropdown-with-the-multiple-attribute-collapsed
  13. -->
  14. {% macro resource_lead(type, title, leadtext, url, year, thumbnail='', large_title=false) %}
  15. <div class="relative cell ">
  16. <a
  17. class="block cursor-pointer"
  18. href="{{ url }}"
  19. hx-target="#modal-content"
  20. hx-select="main"
  21. hx-swap="innerHTML"
  22. @click="openModal()"
  23. >
  24. {% if large_title %}
  25. <h2 class="">{{ title }}</h2>
  26. {% else %}
  27. <h3 class="">{{ title }}</h3>
  28. {% endif %}
  29. {% if year %}
  30. <div class="">{{ year }}</div>
  31. {% endif %}
  32. {% if type == 'book' and thumbnail %}
  33. <img class="w-40 h-40 object-contain float-right m-16 grayscale rotate-[15deg]" src={{ book['thumbnail'] }} alt="cover for {{ title }}">
  34. {% endif %}
  35. <div class="">
  36. {{ leadtext | truncate(100) }}
  37. </div>
  38. </a>
  39. {% if current_user.is_authenticated %}
  40. <div class="">
  41. {% if resource['type'] == 'tool' %}
  42. <a href="{{ url_for('tool.edit_tool', tool_id=resource['id']) }}">
  43. <span class="absolute top-0 left-0 text-xs">Edit</span>
  44. </a>
  45. {% elif resource['type'] == 'practice' %}
  46. <a href="{{ url_for('practice.edit_practice', practice_id=resource['id']) }}">
  47. <span class="absolute top-0 left-0 text-xs">Edit</span>
  48. </a>
  49. {% elif resource['type'] == 'book' %}
  50. <a href="{{ url_for('book.edit_book', book_id=resource['id']) }}">
  51. <span class="absolute top-0 left-0 text-xs">Edit</span>
  52. </a>
  53. {% endif %}
  54. </div>
  55. {% endif %}
  56. </div>
  57. {% endmacro %}
  58. {% macro resource_small(resource) %}
  59. {% if resource['type'] == 'tool' %}
  60. {{
  61. resource_lead(
  62. resource['type'],
  63. resource['name'],
  64. resource['description'],
  65. url_for('tool.show_tool',
  66. tool_id=resource['id']),
  67. null,
  68. '',
  69. true
  70. )
  71. }}
  72. {% elif resource['type'] == 'practice' %}
  73. {{
  74. resource_lead(
  75. resource['type'],
  76. resource['name'],
  77. resource['description'],
  78. url_for('practice.show_practice',
  79. practice_id=resource['id']),
  80. null
  81. )
  82. }}
  83. {% elif resource['type'] == 'book' %}
  84. {{
  85. resource_lead(
  86. resource['type'],
  87. resource['name'],
  88. resource['author'],
  89. url_for('book.show_book',
  90. book_id=resource['id']),
  91. null,
  92. resource['thumbnail'],
  93. true
  94. )
  95. }}
  96. {% endif %}
  97. {% endmacro %}
  98. <!DOCTYPE html>
  99. <html>
  100. <head>
  101. {{ moment.include_moment() }}
  102. <meta charset="utf-8">
  103. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  104. <meta name="viewport" content="width=device-width, initial-scale=1">
  105. <script src="https://unpkg.com/htmx.org@1.8.6"></script>
  106. <script src="//unpkg.com/alpinejs" defer></script>
  107. <title>ExPub Compendium</title>
  108. <link href="{{ url_for('static',filename='styles/main.css') }}" rel="stylesheet">
  109. </head>
  110. <script>
  111. htmx.logAll();
  112. function base() {
  113. return {
  114. menuOpen: false,
  115. modalOpen: false,
  116. home: '/',
  117. init() {
  118. window.addEventListener('popstate', e => {
  119. console.log(document.location);
  120. if (document.location == this.home) {
  121. this.modalOpen = false;
  122. }
  123. })
  124. },
  125. hideOverlay() {
  126. this.modalOpen = false;
  127. window.history.pushState({}, '', this.home);
  128. },
  129. openModal() {
  130. this.$refs.modal.innerHTML = '';
  131. this.modalOpen = true;
  132. }
  133. }
  134. }
  135. </script>
  136. <body
  137. class="text-base overflow-y-scroll"
  138. x-data="base()"
  139. hx-boost="true"
  140. hx-select="#all"
  141. hx-target="#all"
  142. hx-indicator="#loading"
  143. >
  144. <div id="loading" class="loading">
  145. <div class="pointer-events-none fixed top-0 left-0 w-full h-screen z-50 flex justify-center items-center p-4">
  146. <div class="rounded-full bg-black text-white p-4 ">
  147. Loading...
  148. </div>
  149. </div>
  150. </div>
  151. <div id="all">
  152. <header class="sticky top-0 z-10 bg-white std-padding border-b-[3px] border-black">
  153. <nav class="lg:flex gap-8">
  154. <a class="mr-auto" href="{{ url_for('main.index')}}">ExPub Compendium</a>
  155. <a href="{{ url_for('main.about') }}" class="nav-link">
  156. About
  157. </a>
  158. <a href="{{ url_for('tool.get_tools') }}" class="nav-link">
  159. Tools
  160. </a>
  161. <a href="{{ url_for('practice.get_practices') }}" class="nav-link">
  162. Practices
  163. </a>
  164. <a href="{{ url_for('book.get_books') }}" class="nav-link">
  165. Books
  166. </a>
  167. {% if current_user.is_authenticated %}
  168. <a href="{{ url_for('create.create_resource') }}" class="nav-link">
  169. Add resource
  170. </a>
  171. {% endif %}
  172. {% if current_user.is_authenticated %}
  173. <a href="{{ url_for('main.profile') }}" class="nav-link">
  174. Profile
  175. </a>
  176. {% endif %}
  177. {% if not current_user.is_authenticated %}
  178. <a href="{{ url_for('auth.login') }}" class="nav-link">
  179. Login
  180. </a>
  181. <a href="{{ url_for('auth.signup') }}" class="nav-link">
  182. Sign Up
  183. </a>
  184. {% endif %}
  185. {% if current_user.is_authenticated %}
  186. <a href="{{ url_for('auth.logout') }}" class="nav-link">
  187. Logout
  188. </a>
  189. {% endif %}
  190. </nav>
  191. </header>
  192. <!-- Begin page content -->
  193. <main>
  194. {% with messages = get_flashed_messages() %}
  195. {% if messages %}
  196. <div class="alert alert-danger">
  197. {{ messages[0] }}
  198. </div>
  199. {% endif %}
  200. {% endwith %}
  201. {% block content %}
  202. {% endblock %}
  203. </main>
  204. </div>
  205. <div id="modal" x-show="modalOpen" class="modal h-screen w-full fixed top-0 z-20 p-8 bg-black/20">
  206. <div class="cross cursor-pointer absolute top-10 right-10 w-10 h-10" @click="hideOverlay()">
  207. <svg width="100%" height="100%" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  208. <path d="M2 2L18 18M18 2L2 18" stroke="black" stroke-width="1"></path>
  209. </svg>
  210. </div>
  211. <div id="modal-content" @click.outside="hideOverlay()" x-ref="modal" class="content w-full overflow-y-scroll h-full bg-white " style="box-shadow:0 0 4rem rgba(0,0,0,0.3)">
  212. </div>
  213. </div>
  214. <!-- Sticky footer-->
  215. <footer class="std-margin mt-20 text-sm">
  216. <div class="container">
  217. <span class="">© 2022–{{ moment().format('YYYY') }} <a href="https://copim.ac.uk/">COPIM</a> and licensed under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License (CC BY 4.0)</a>.</span>
  218. </div>
  219. </footer>
  220. <!-- JavaScript -->
  221. <!-- jQuery first, then Popper JS, then Bootstrap JS -->
  222. <script src="{{ url_for('static',filename='js/main.js') }}"></script>
  223. </body>
  224. </html>