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.

473 lines
18KB

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