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.

410 lines
16KB

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