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.

396 lines
15KB

  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 menu() %}
  15. <a href="{{ url_for('tool.get_tools') }}{% if view == 'list' %}?view=list{% endif %}"
  16. class="{{ 'active' if request.path == url_for('tool.get_tools') }} menuitem tool medium-title hidden lg:block">
  17. Tools
  18. </a>
  19. <a href="{{ url_for('practice.get_practices') }}{% if view == 'list' %}?view=list{% endif %}"
  20. class="{{ 'active' if request.path == url_for('practice.get_practices') }} menuitem practice medium-title hidden lg:block">
  21. Practices
  22. </a>
  23. <a href="{{ url_for('book.get_books') }}{% if view == 'list' %}?view=list{% endif %}"
  24. class="{{ 'active' if request.path == url_for('book.get_books') }} menuitem medium-title book hidden lg:block">
  25. Books
  26. </a>
  27. <a href="{{ url_for('main.about') }}{% if view == 'list' %}?view=list{% endif %}"
  28. class="{{ 'active' if request.path == url_for('main.about') }} menuitem mr-auto hidden lg:block">
  29. About / <br> Contact
  30. </a>
  31. <!-- <div class="ml-auto mr-2">
  32. {% if current_user.is_authenticated %}
  33. <a href="{{ url_for('create.create_resource') }}" class="block link">
  34. Add resource
  35. </a>
  36. {% endif %}
  37. {% if current_user.is_authenticated %}
  38. <a href="{{ url_for('main.profile') }}" class="block link">
  39. Profile
  40. </a>
  41. {% endif %}
  42. {% if not current_user.is_authenticated %}
  43. <a href="{{ url_for('auth.login') }}" class="block link">
  44. Login
  45. </a>
  46. <a href="{{ url_for('auth.signup') }}" class="block link">
  47. Sign Up
  48. </a>
  49. {% endif %}
  50. {% if current_user.is_authenticated %}
  51. <a href="{{ url_for('auth.logout') }}" class="block link">
  52. Logout
  53. </a>
  54. {% endif %}
  55. </div> -->
  56. <form action="{{ url_for('search.basic_search') }}" class="hidden lg:block">
  57. <input type="text" name="query" class="text-center h-full text-base border-l-2 border-black pl-1"
  58. placeholder="Search">
  59. <input class="hidden" type="submit" hidden />
  60. </form>
  61. {% endmacro %}
  62. {% macro relationships_links(resource) %}
  63. {% if resource.tools %}
  64. <div class="">
  65. <div class="px-4 mt-16 lg:mt-0">
  66. Tools
  67. </div>
  68. {% for tool in resource.tools %}
  69. <div class="cell">
  70. {{ resource_lead(tool,size=2) }}
  71. </div>
  72. {% endfor %}
  73. </div>
  74. {% endif %}
  75. {% if resource.books %}
  76. <div class="">
  77. <div class="px-4 mt-16 lg:mt-0">
  78. Books
  79. </div>
  80. {% for book in resource.books %}
  81. <div class="cell">
  82. {{ resource_lead(book,size=2) }}
  83. </div>
  84. {% endfor %}
  85. </div>
  86. {% endif %}
  87. {% if resource.practices %}
  88. <div class="">
  89. <div class="px-4 mt-16 lg:mt-0">
  90. Practices
  91. </div>
  92. {% for practice in resource.practices %}
  93. <div class="cell">
  94. {{ resource_lead(practice,size=2) }}
  95. </div>
  96. {% endfor %}
  97. </div>
  98. {% endif %}
  99. {% endmacro %}
  100. {% macro resource_list(resource, loop, show_number=true) %}
  101. <div class="border-b-2 border-black">
  102. <a class="block h-full py-1 px-4 hover:opacity-60 transition-opacity cursor-pointer size-{{ size }}" {% if
  103. resource['type']=='book' %} href="{{ url_for('book.show_book', book_id=resource['id']) }}" {% endif %} {% if
  104. resource['type']=='tool' %} href="{{ url_for('tool.show_tool', tool_id=resource['id']) }}" {% endif %} {% if
  105. resource['type']=='practice' %} href="{{ url_for('practice.show_practice', practice_id=resource['id']) }}" {% endif
  106. %} hx-target="#modal-content" hx-select="main" hx-swap="innerHTML" @click="openModal()">
  107. <span class="{% if show_number %} hidden {% endif %} lg:w-[10.5rem] lg:text-center ">
  108. {% if show_number %}
  109. {{loop.index}} / {{count}}
  110. {% else %}
  111. <span class="capitalize inline-block min-w-[5rem] px-4 text-right">{{ resource['type'] }}</span>
  112. {% endif %}
  113. </span>
  114. <span class="{{ resource.type }}">
  115. {{ resource.name }}
  116. </span>
  117. {% if resource['year'] %}
  118. {{ resource['year'] }}{% if resource['author'] %}, {{ resource['author'] }}{% endif%}
  119. {% endif %}
  120. </a>
  121. </div>
  122. {% endmacro %}
  123. {% macro resource_with_related(resource, loop, show_number=true) %}
  124. <div class="w-full border-b-2 border-black fade-right">
  125. <div class="content w-full py-8 overflow-x-auto">
  126. <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col w-fit pr-40 " >
  127. <div class=" related hidden lg:block ">
  128. {% if show_number %}
  129. <p>{{loop.index}} / {{count}}</p>
  130. {% else %}
  131. <p class="capitalize">{{ resource['type'] }}</p>
  132. {% endif %}
  133. </div>
  134. <div class="cell w-[28vw] lg:w-[32rem] row-start-1 lg:row-span-3">
  135. {{ resource_lead(resource) }}
  136. </div>
  137. {% if resource.tools %}
  138. <div class="grid lg:grid-rows-1 grid-flow-col w-fit h-fit">
  139. <div class="related">
  140. Related<br>Tools
  141. </div>
  142. {% for tool in resource.tools %}
  143. <div class="cell w-[30rem]">
  144. {{ resource_lead(tool,size=2) }}
  145. </div>
  146. {% endfor %}
  147. </div>
  148. {% endif %}
  149. {% if resource.books %}
  150. <div class="grid grid-rows-1 grid-flow-col w-fit h-fit">
  151. <div class="related">
  152. Related<br>Books
  153. </div>
  154. {% for book in resource.books %}
  155. <div class="cell w-[35rem]">
  156. {{ resource_lead(book,size=2) }}
  157. </div>
  158. {% endfor %}
  159. </div>
  160. {% endif %}
  161. {% if resource.practices %}
  162. <div class="grid grid-rows-1 grid-flow-col w-fit h-fit">
  163. <div class="related">
  164. Related<br>Practices
  165. </div>
  166. {% for practice in resource.practices %}
  167. <div class="cell w-[25rem]">
  168. {{ resource_lead(practice,size=2) }}
  169. </div>
  170. {% endfor %}
  171. </div>
  172. {% endif %}
  173. </div>
  174. </div>
  175. </div>
  176. {% endmacro %}
  177. {% macro popup_link(title,url) %}
  178. <a href="{{ url }}" class="nav-link">
  179. {{ title }}
  180. </a>
  181. {% endmacro %}
  182. {% macro resource_lead(resource,size=1) %}
  183. <a
  184. class="block h-full hover:opacity-60 transition-opacity cursor-pointer size-{{ size }}"
  185. {% if resource['type'] == 'book' %}
  186. href="{{ url_for('book.show_book', book_id=resource['id']) }}"
  187. {% endif %}
  188. {% if resource['type'] == 'tool' %}
  189. href="{{ url_for('tool.show_tool', tool_id=resource['id']) }}"
  190. {% endif %}
  191. {% if resource['type'] == 'practice' %}
  192. href="{{ url_for('practice.show_practice', practice_id=resource['id']) }}"
  193. {% endif %}
  194. hx-target="#modal-content"
  195. hx-select="main"
  196. hx-swap="innerHTML"
  197. @click="openModal()"
  198. >
  199. {% if (resource['type'] == 'book') %}
  200. <img class="w-20 h-20 object-contain float-right m-4 grayscale rotate-[15deg]" src="https://dummyimage.com/4:5x70" alt="cover for {{ resource['name'] }}">
  201. {% endif %}
  202. <h2 class="{{ resource['type'] }} {% if size==1 %} big-title {% else %} small-title {% endif %} mb-2">{{ resource['name'] }}</h2>
  203. {% if resource['year'] %}
  204. <div class="text-sm">
  205. {{ resource['year'] }}{% if resource['author'] %}, {{ resource['author'] }}{% endif%}
  206. </div>
  207. {% endif %}
  208. <div class="{% if size==1 %} big-text {% else %} small-text {% endif %} mb-[1em]">
  209. {{ resource['description'] | truncate(150) }}
  210. </div>
  211. </a>
  212. {% if current_user.is_authenticated %}
  213. <div class="">
  214. {% if resource['type'] == 'tool' %}
  215. <a href="{{ url_for('tool.edit_tool', tool_id=resource['id']) }}">
  216. <span class="absolute top-0 left-0 text-xs">Edit</span>
  217. </a>
  218. {% elif resource['type'] == 'practice' %}
  219. <a href="{{ url_for('practice.edit_practice', practice_id=resource['id']) }}">
  220. <span class="absolute top-0 left-0 text-xs">Edit</span>
  221. </a>
  222. {% elif resource['type'] == 'book' %}
  223. <a href="{{ url_for('book.edit_book', book_id=resource['id']) }}">
  224. <span class="absolute top-0 left-0 text-xs">Edit</span>
  225. </a>
  226. {% endif %}
  227. </div>
  228. {% endif %}
  229. {% endmacro %}
  230. <!DOCTYPE html>
  231. <html>
  232. <head>
  233. {{ moment.include_moment() }}
  234. <meta charset="utf-8">
  235. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  236. <meta name="viewport" content="width=device-width, initial-scale=1">
  237. <title>Experimental Publishing Compendium</title>
  238. <script src="{{ url_for('static',filename='js/alpine.min.js') }}" defer></script>
  239. <script src="{{ url_for('static',filename='js/htmx.min.js') }}"></script>
  240. <link href="{{ url_for('static',filename='styles/main.css') }}" rel="stylesheet">
  241. <script>
  242. // htmx.on('htmx:beforeRequest', e=> {
  243. // console.log(e)
  244. // })
  245. // htmx.logAll()
  246. function base() {
  247. return {
  248. menuOpen: false,
  249. modalOpen: false,
  250. showRelated: false,
  251. home: '/',
  252. hideIfBase() {
  253. let str = document.location.toString();
  254. str = str.replace('http://', '');
  255. str = str.replace('https://', '');
  256. let l = str.split('/').length - 1;
  257. if (l < 2) {
  258. this.modalOpen = false;
  259. }
  260. return l;
  261. },
  262. init() {
  263. this.$watch('document.location', (value, oldValue) => {
  264. console.log('new url', value);
  265. });
  266. window.addEventListener('popstate', e => {
  267. this.hideIfBase();
  268. });
  269. },
  270. hideOverlay() {
  271. this.modalOpen = false;
  272. // window.history.pushState({}, '', this.home);
  273. },
  274. openModal() {
  275. // this.$refs.modal.innerHTML = '';
  276. this.modalOpen = true;
  277. let mc = document.querySelector('#modal-content');
  278. mc.scrollTo(0, 0);
  279. }
  280. }
  281. }
  282. </script>
  283. </head>
  284. <body
  285. class="text-base overflow-y-scroll"
  286. x-data="base()"
  287. hx-boost="true"
  288. hx-select="#all"
  289. hx-target="#all"
  290. hx-swap="outerHTML"
  291. hx-indicator="body"
  292. >
  293. <div id="loading" class="loading pointer-events-none ">
  294. <!-- <div class="bg-white fixed top-0 left-0 w-full h-screen z-20"></div> -->
  295. <div class="bg fixed top-0 left-0 w-full h-screen z-30"></div>
  296. <div class="spinner fixed top-0 left-0 w-full h-screen z-[60] flex justify-center items-center">
  297. <div class="inner bg-black rounded-full px-8 py-6 text-white text-center">
  298. Loading...
  299. </div>
  300. </div>
  301. </div>
  302. <div id="all">
  303. <header class="sticky top-0 z-10 bg-white border-b-[2px] border-black flex justify-between w-full">
  304. <nav class=" lg:flex justify-center items-stretch w-full">
  305. <a class="block menuitem w-48 " href="{{ url_for('main.index') }}{% if view == 'list' %}?view=list{% endif %}"><span>Experimental Publishing Compendium <span class="ml-3 inline-block -rotate-12 italic text-[#f52d2d]" style="text-shadow: 0 0 0.4rem white">beta</span></span></a>
  306. {{ menu() }}
  307. </nav>
  308. <div class="burger h-14 cursor-pointer block lg:hidden p-4">
  309. <svg width="100%" height="100%" viewBox="0 0 20 18" fill="none" xmlns="http://www.w3.org/2000/svg">
  310. <path d="M1 4H19" stroke="black" stroke-width="1.5" />
  311. <path d="M19 9H1" stroke="black" stroke-width="1.5" />
  312. <path d="M1 14H19" stroke="black" stroke-width="1.5" />
  313. </svg>
  314. </div>
  315. </header>
  316. <!-- Begin page content -->
  317. <main>
  318. {% with messages = get_flashed_messages() %}
  319. {% if messages %}
  320. <div class="alert alert-danger">
  321. {{ messages[0] }}
  322. </div>
  323. {% endif %}
  324. {% endwith %}
  325. {% block content %}
  326. {% endblock %}
  327. </main>
  328. </div>
  329. <div id="modal" x-show="modalOpen" class="modal h-screen w-full fixed top-0 z-50 p-4 bg overscroll-none">
  330. <div class="cross cursor-pointer absolute top-10 right-10 w-10 h-10" @click="hideOverlay()">
  331. <svg width="100%" height="100%" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  332. <path d="M2 2L18 18M18 2L2 18" stroke="black" stroke-width="1"></path>
  333. </svg>
  334. </div>
  335. <div id="modal-content" @click.outside="hideOverlay()" x-ref="modal" class="content w-full overflow-y-auto h-full bg-white " >
  336. </div>
  337. </div>
  338. <!-- Sticky footer-->
  339. <footer class="std-margin mt-20 text-sm">
  340. <div class="container">
  341. <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>
  342. </div>
  343. </footer>
  344. <!-- JavaScript -->
  345. <!-- jQuery first, then Popper JS, then Bootstrap JS -->
  346. <script src="{{ url_for('static',filename='js/main.js') }}"></script>
  347. </body>
  348. </html>