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.

314 lines
11KB

  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 relationships_links(relationships) %}
  15. {% if relationships %}
  16. {% for relationship in relationships %}
  17. {{ resource_lead(relationship)}}
  18. {% endfor %}
  19. {% endif %}
  20. {% endmacro %}
  21. {% macro resource_with_related(resource, pre_title='', post_title='Related') %}
  22. <div class="w-full overflow-x-scroll my-8 pb-12 border-b-2 border-black">
  23. <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col" >
  24. <div class=" w-40 pl-16 pt-4 row-start-1 ">
  25. {% if pre_title == '' %}
  26. <p>1 / 34</p>
  27. {% else %}
  28. <p>{{ pre_title }}</p>
  29. {% endif %}
  30. </div>
  31. <div class="w-[32rem] shrink-0 row-start-1 row-span-3">
  32. {{ resource_lead(resource) }}
  33. </div>
  34. <div class=" w-52 pl-24 pt-4 row-start-1 ">
  35. {{ post_title }}
  36. </div>
  37. <div class="h-12">
  38. </div>
  39. {% if resource['name'] != 'practice' %}
  40. <div class="w-52 pl-24 pt-4 ">
  41. Related practices
  42. </div>
  43. {% endif %}
  44. <div class="shrink-0 min-w-[32rem] row-start-1">
  45. {{ resource_lead(resource) }}
  46. </div>
  47. <div class=""></div>
  48. <div class="cell practice">
  49. <h2>Collaborative writing</h2>
  50. </div>
  51. <div class="shrink-0 min-w-[32rem] row-start-1">
  52. {{ resource_lead(resource) }}
  53. </div>
  54. <div class="shrink-0 min-w-[32rem] row-start-1">
  55. {{ resource_lead(resource) }}
  56. </div>
  57. </div>
  58. </div>
  59. {% endmacro %}
  60. {% macro popup_link(title,url) %}
  61. <a href="{{ url }}" class="nav-link">
  62. {{ title }}
  63. </a>
  64. {% endmacro %}
  65. {% macro resource_lead(resource) %}
  66. <div class="relative cell ">
  67. <a
  68. class="block h-full hover:opacity-60 transition-opacity cursor-pointer "
  69. {% if resource['type'] == 'book' %}
  70. href="{{ url_for('book.show_book', book_id=resource['id']) }}"
  71. {% endif %}
  72. {% if resource['type'] == 'tool' %}
  73. href="{{ url_for('tool.show_tool', tool_id=resource['id']) }}"
  74. {% endif %}
  75. {% if resource['type'] == 'practice' %}
  76. href="{{ url_for('practice.show_practice', practice_id=resource['id']) }}"
  77. {% endif %}
  78. hx-target="#modal-content"
  79. hx-select="main"
  80. hx-swap="innerHTML"
  81. @click="openModal()"
  82. >
  83. {% if (resource['type'] == 'book') %}
  84. <img class="w-20 h-20 object-contain float-right mt-4 ml-4 mb-4 grayscale rotate-[15deg]" src="https://dummyimage.com/4:5x70" alt="cover for {{ resource['name'] }}">
  85. {% endif %}
  86. <h2 class="{{ resource['type'] }} mb-2">{{ resource['name'] }}</h2>
  87. {% if resource['year'] %}
  88. <div class=" text-sm">
  89. {{ resource['year'] }}{% if resource['author'] %}, {{ resource['author'] }}{% endif%}
  90. </div>
  91. {% endif %}
  92. <div class="text-xl mb-[1em]">
  93. {{ resource['description'] | truncate(150) }}
  94. </div>
  95. </a>
  96. {% if current_user.is_authenticated %}
  97. <div class="">
  98. {% if resource['type'] == 'tool' %}
  99. <a href="{{ url_for('tool.edit_tool', tool_id=resource['id']) }}">
  100. <span class="absolute top-0 left-0 text-xs">Edit</span>
  101. </a>
  102. {% elif resource['type'] == 'practice' %}
  103. <a href="{{ url_for('practice.edit_practice', practice_id=resource['id']) }}">
  104. <span class="absolute top-0 left-0 text-xs">Edit</span>
  105. </a>
  106. {% elif resource['type'] == 'book' %}
  107. <a href="{{ url_for('book.edit_book', book_id=resource['id']) }}">
  108. <span class="absolute top-0 left-0 text-xs">Edit</span>
  109. </a>
  110. {% endif %}
  111. </div>
  112. {% endif %}
  113. </div>
  114. {% endmacro %}
  115. <!DOCTYPE html>
  116. <html>
  117. <head>
  118. {{ moment.include_moment() }}
  119. <meta charset="utf-8">
  120. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  121. <meta name="viewport" content="width=device-width, initial-scale=1">
  122. <script src="https://unpkg.com/htmx.org@1.8.6"></script>
  123. <script src="//unpkg.com/alpinejs" defer></script>
  124. <title>ExPub Compendium</title>
  125. <link href="{{ url_for('static',filename='styles/main.css') }}" rel="stylesheet">
  126. <script>
  127. // htmx.on('htmx:beforeRequest', e=> {
  128. // console.log(e)
  129. // })
  130. // htmx.logAll()
  131. function base() {
  132. return {
  133. menuOpen: false,
  134. modalOpen: false,
  135. showRelated: false,
  136. home: '/',
  137. hideIfBase() {
  138. let str = document.location.toString();
  139. str = str.replace('http://', '');
  140. str = str.replace('https://', '');
  141. let l = str.split('/').length - 1;
  142. if (l < 2) {
  143. this.modalOpen = false;
  144. }
  145. return l;
  146. },
  147. init() {
  148. this.$watch('document.location', (value, oldValue) => {
  149. console.log('new url', value);
  150. });
  151. window.addEventListener('popstate', e => {
  152. this.hideIfBase();
  153. });
  154. },
  155. hideOverlay() {
  156. this.modalOpen = false;
  157. // window.history.pushState({}, '', this.home);
  158. },
  159. openModal() {
  160. // this.$refs.modal.innerHTML = '';
  161. this.modalOpen = true;
  162. let mc = document.querySelector('#modal-content');
  163. mc.scrollTo(0, 0);
  164. }
  165. }
  166. }
  167. </script>
  168. </head>
  169. <body
  170. class="text-base overflow-y-scroll"
  171. x-data="base()"
  172. hx-boost="true"
  173. hx-select="#all"
  174. hx-target="#all"
  175. hx-swap="outerHTML"
  176. hx-indicator="body"
  177. >
  178. <div id="loading" class="loading pointer-events-none fixed top-0 left-0 w-full h-screen z-50">
  179. </div>
  180. <div id="all">
  181. <header class="sticky top-0 z-10 bg-white std-padding border-b-[2px] border-black">
  182. <nav class=" lg:flex justify-between">
  183. <a class="link inline-block w-40" href="{{ url_for('main.index') }}">ExPub<br>Compendium</a>
  184. <div class="mr-8">
  185. <h2><a href="{{ url_for('tool.get_tools') }}" class="tool link align-bottom">Tools</a></h2>
  186. </div>
  187. <div class="mr-8">
  188. <h2>
  189. <a href="{{ url_for('practice.get_practices') }}" class="practice link">
  190. Practices
  191. </a>
  192. </h2>
  193. </div>
  194. <div class="mr-8">
  195. <h2>
  196. <a href="{{ url_for('book.get_books') }}" class="book link">
  197. Books
  198. </a>
  199. </h2>
  200. </div>
  201. <!-- <div class="mr-8">
  202. <h2 class="">
  203. <a href="{{ url_for('practice.get_practices') }}" class="practice link">
  204. Typologies
  205. </a>
  206. </h2>
  207. </div> -->
  208. <div class="mr-8">
  209. <a href="{{ url_for('main.about') }}"
  210. class="{{ 'active' if request.path == url_for('main.about') }} ml-auto link mr-auto">
  211. About<br>ExPub
  212. </a>
  213. </div>
  214. <div class="ml-auto mr-2">
  215. {% if current_user.is_authenticated %}
  216. <a href="{{ url_for('create.create_resource') }}" class="block link">
  217. Add resource
  218. </a>
  219. {% endif %}
  220. {% if current_user.is_authenticated %}
  221. <a href="{{ url_for('main.profile') }}" class="block link">
  222. Profile
  223. </a>
  224. {% endif %}
  225. {% if not current_user.is_authenticated %}
  226. <a href="{{ url_for('auth.login') }}" class="block link">
  227. Login
  228. </a>
  229. <a href="{{ url_for('auth.signup') }}" class="block link">
  230. Sign Up
  231. </a>
  232. {% endif %}
  233. {% if current_user.is_authenticated %}
  234. <a href="{{ url_for('auth.logout') }}" class="block link">
  235. Logout
  236. </a>
  237. {% endif %}
  238. </div>
  239. <input class=" text-base border-2 border-black p-1 " type="text" placeholder="Search">
  240. </nav>
  241. </header>
  242. <!-- Begin page content -->
  243. <main>
  244. {% with messages = get_flashed_messages() %}
  245. {% if messages %}
  246. <div class="alert alert-danger">
  247. {{ messages[0] }}
  248. </div>
  249. {% endif %}
  250. {% endwith %}
  251. {% block content %}
  252. {% endblock %}
  253. </main>
  254. </div>
  255. <div id="modal" x-show="modalOpen" class="modal h-screen w-full fixed top-0 z-20 p-4 bg-black/20 overscroll-none">
  256. <div class="cross cursor-pointer absolute top-10 right-10 w-10 h-10" @click="hideOverlay()">
  257. <svg width="100%" height="100%" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  258. <path d="M2 2L18 18M18 2L2 18" stroke="black" stroke-width="1"></path>
  259. </svg>
  260. </div>
  261. <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)">
  262. </div>
  263. </div>
  264. <!-- Sticky footer-->
  265. <footer class="std-margin mt-20 text-sm">
  266. <div class="container">
  267. <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>
  268. </div>
  269. </footer>
  270. <!-- JavaScript -->
  271. <!-- jQuery first, then Popper JS, then Bootstrap JS -->
  272. <script src="{{ url_for('static',filename='js/main.js') }}"></script>
  273. </body>
  274. </html>