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.

439 lines
17KB

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