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.

447 line
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 href="{{ url_for(request.endpoint) }}?view=regular{% for key in request.args %}{% if key != 'view' %}&{{ key }}={{ request.args.get(key) }}{% endif %}{% endfor %}"
  17. class="block link flex p-3 gap-2 {% if view != 'list' %} active {% endif %}">
  18. <div class="w-5 h-5 inline-block">
  19. <svg width="100%" height="100%" viewBox="0 0 46 36" fill="none" xmlns="http://www.w3.org/2000/svg">
  20. <rect width="21" height="36" fill="black" />
  21. <rect x="27" width="19" height="14" fill="black" />
  22. <rect x="27" y="21" width="19" height="15" fill="black" />
  23. </svg>
  24. </div>
  25. Expanded
  26. </a>
  27. <a href="{{ url_for(request.endpoint) }}?view=list{% for key in request.args %}{% if key != 'view' %}&{{ key }}={{ request.args.get(key) }}{% endif %}{% endfor %}"
  28. class="block link flex p-3 gap-2 {% if view == 'list' %} active {% endif %}">
  29. <div class="w-5 h-5 inline-block ">
  30. <svg width="100%" height="100%" viewBox="0 0 38 36" fill="none" xmlns="http://www.w3.org/2000/svg">
  31. <path d="M0 2H38" stroke="black" stroke-width="2.5" />
  32. <path d="M0 13H38" stroke="black" stroke-width="2.5" />
  33. <path d="M0 24H38" stroke="black" stroke-width="2.5" />
  34. <path d="M0 35H38" stroke="black" stroke-width="2.5" />
  35. </svg>
  36. </div>
  37. List
  38. </a>
  39. </div>
  40. {% endmacro %}
  41. {% macro menu(type) %}
  42. <a class="block menuitem w-48 " href="{{ url_for('main.index') }}{% if view == 'list' %}?view=list{% endif %}"
  43. @click="menuOpen = false"><span>Experimental Publishing Compendium <span
  44. class="ml-3 inline-block -rotate-12 italic text-[#f52d2d]"
  45. style="text-shadow: 0 0 0.4rem white">beta</span></span>
  46. </a>
  47. <a href="{{ url_for('tool.get_tools') }}{% if view == 'list' %}?view=list{% endif %}"
  48. class="{{ 'active' if request.path == url_for('tool.get_tools') }} menuitem tool medium-title {% if type=='top' %} hidden lg:block {% else %} block {% endif %}"
  49. @click="menuOpen = false">
  50. Tools
  51. </a>
  52. <a href="{{ url_for('practice.get_practices') }}{% if view == 'list' %}?view=list{% endif %}"
  53. class="{{ 'active' if request.path == url_for('practice.get_practices') }} menuitem practice medium-title {% if type=='top' %} hidden lg:block {% else %} block {% endif %}"
  54. @click="menuOpen = false">
  55. Practices
  56. </a>
  57. <a href="{{ url_for('book.get_books') }}{% if view == 'list' %}?view=list{% endif %}"
  58. class="{{ 'active' if request.path == url_for('book.get_books') }} menuitem medium-title book block {% if type=='top' %} hidden lg:block {% else %} block {% endif %} "
  59. @click="menuOpen = false">
  60. Books
  61. </a>
  62. <a href="{{ url_for('main.about') }}{% if view == 'list' %}?view=list{% endif %}"
  63. class="ml-auto {{ 'active' if request.path == url_for('main.about') }} menuitem {% if type=='top' %} hidden lg:block {% else %} block {% endif %}"
  64. @click="menuOpen = false">
  65. About / <br> Contact
  66. </a>
  67. <!-- <div class="ml-auto mr-2">
  68. {% if current_user.is_authenticated %}
  69. <a href="{{ url_for('create.create_resource') }}" class="block link">
  70. Add resource
  71. </a>
  72. {% endif %}
  73. {% if current_user.is_authenticated %}
  74. <a href="{{ url_for('main.profile') }}" class="block link">
  75. Profile
  76. </a>
  77. {% endif %}
  78. {% if not current_user.is_authenticated %}
  79. <a href="{{ url_for('auth.login') }}" class="block link">
  80. Login
  81. </a>
  82. <a href="{{ url_for('auth.signup') }}" class="block link">
  83. Sign Up
  84. </a>
  85. {% endif %}
  86. {% if current_user.is_authenticated %}
  87. <a href="{{ url_for('auth.logout') }}" class="block link">
  88. Logout
  89. </a>
  90. {% endif %}
  91. </div> -->
  92. <form action="{{ url_for('search.basic_search') }}" class="hidden lg:block">
  93. <label id="search-label" for="siteSearch" class="sr-only">Search</label>
  94. <input type="text" name="query" class="text-center h-full text-base border-l-2 border-black pl-1" aria-labelledby="search-label"
  95. placeholder="Search" hx-get="{{ url_for('search.basic_search') }}"
  96. hx-trigger="keyup changed delay:500ms, search" hx-target="main" hx-select="main">
  97. <input class="hidden" type="submit" hidden />
  98. </form>
  99. {% endmacro %}
  100. {% macro relationships_links(resource) %}
  101. {% if resource.tools %}
  102. <div class="">
  103. <div class="px-4 mt-16 lg:mt-0">
  104. Tools
  105. </div>
  106. {% for tool in resource.tools %}
  107. <div class="cell">
  108. {{ resource_lead(tool,size=2) }}
  109. </div>
  110. {% endfor %}
  111. </div>
  112. {% endif %}
  113. {% if resource.books %}
  114. <div class="">
  115. <div class="px-4 mt-16 lg:mt-0">
  116. Books
  117. </div>
  118. {% for book in resource.books %}
  119. <div class="cell">
  120. {{ resource_lead(book,size=2) }}
  121. </div>
  122. {% endfor %}
  123. </div>
  124. {% endif %}
  125. {% if resource.practices %}
  126. <div class="">
  127. <div class="px-4 mt-16 lg:mt-0">
  128. Practices
  129. </div>
  130. {% for practice in resource.practices %}
  131. <div class="cell">
  132. {{ resource_lead(practice,size=2) }}
  133. </div>
  134. {% endfor %}
  135. </div>
  136. {% endif %}
  137. {% endmacro %}
  138. {% macro resource_list(resource, loop, show_number=true) %}
  139. <div class="border-b-2 border-black">
  140. <a class="flex gap-6 h-full py-2 hover:opacity-60 transition-opacity cursor-pointer size-{{ size }}" {% if
  141. resource['type']=='book' %} href="{{ url_for('book.show_book', book_id=resource['id']) }}" {% endif %} {% if
  142. resource['type']=='tool' %} href="{{ url_for('tool.show_tool', tool_id=resource['id']) }}" {% endif %} {% if
  143. resource['type']=='practice' %} href="{{ url_for('practice.show_practice', practice_id=resource['id']) }}" {%
  144. endif %} hx-target="#modal-content" hx-select="main" hx-swap="innerHTML" @click="openModal()">
  145. <div class="w-[4.5rem] shrink-0 lg:w-[12rem] text-center ">
  146. {% if show_number %}
  147. {{loop.index}} / {{count}}
  148. {% else %}
  149. <div class="capitalize inline-block min-w-[5rem] px-4 ">{{ resource['type'] }}</div>
  150. {% endif %}
  151. </div>
  152. <div class="">
  153. <span class="{{ resource.type }} lg:text-xl pr-4">
  154. {{ resource.name }}
  155. </span>
  156. {% if resource['year'] %}
  157. <div class="">
  158. {{ resource['year'] }}{% if resource['author'] %}, {{ resource['author'] }}{% endif%}
  159. </div>
  160. {% endif %}
  161. </div>
  162. </a>
  163. </div>
  164. {% endmacro %}
  165. {% macro resource_with_related(resource, loop, show_number=true) %}
  166. <div class="w-full border-b-2 border-black fade-right">
  167. <div class="content w-full py-8 overflow-x-auto">
  168. <div class="grid lg:grid-rows-[auto,auto,auto] grid-flow-col w-fit pr-40 ">
  169. <div class="w-[4.5rem] shrink-0 lg:w-[12rem] text-center px-2 py-4 ">
  170. {% if show_number %}
  171. <p>{{loop.index}} / {{count}}</p>
  172. {% else %}
  173. <p class="capitalize">{{ resource['type'] }}</p>
  174. {% endif %}
  175. </div>
  176. <div class="cell w-[12rem] lg:w-[32rem] row-start-1 lg:row-span-3">
  177. {{ resource_lead(resource) }}
  178. </div>
  179. {% if resource.tools %}
  180. <div class="grid lg:grid-rows-1 grid-flow-col w-fit h-fit ">
  181. <div class="related">
  182. Related<br>Tools
  183. </div>
  184. {% for tool in resource.tools %}
  185. <div class="cell w-[12rem] lg:w-[30rem]">
  186. {{ resource_lead(tool,size=2) }}
  187. </div>
  188. {% endfor %}
  189. </div>
  190. {% endif %}
  191. {% if resource.books %}
  192. <div class="grid grid-rows-1 grid-flow-col w-fit h-fit">
  193. <div class="related">
  194. Related<br>Books
  195. </div>
  196. {% for book in resource.books %}
  197. <div class="cell w-[12rem] lg:w-[35rem]">
  198. {{ resource_lead(book,size=2) }}
  199. </div>
  200. {% endfor %}
  201. </div>
  202. {% endif %}
  203. {% if resource.practices %}
  204. <div class="grid grid-rows-1 grid-flow-col w-fit h-fit">
  205. <div class="related">
  206. Related<br>Practices
  207. </div>
  208. {% for practice in resource.practices %}
  209. <div class="cell w-[12rem] lg:w-[25rem]">
  210. {{ resource_lead(practice,size=2) }}
  211. </div>
  212. {% endfor %}
  213. </div>
  214. {% endif %}
  215. </div>
  216. </div>
  217. </div>
  218. {% endmacro %}
  219. {% macro popup_link(title,url) %}
  220. <a href="{{ url }}" class="nav-link">
  221. {{ title }}
  222. </a>
  223. {% endmacro %}
  224. {% macro resource_lead(resource,size=1) %}
  225. <a class="block lead-inner-link overflow-hidden h-full hover:opacity-60 transition-opacity cursor-pointer size-{{ size }}"
  226. {% if resource['type']=='book' %} href="{{ url_for('book.show_book', book_id=resource['id']) }}" {% endif %} {% if
  227. resource['type']=='tool' %} href="{{ url_for('tool.show_tool', tool_id=resource['id']) }}" {% endif %} {% if
  228. resource['type']=='practice' %} href="{{ url_for('practice.show_practice', practice_id=resource['id']) }}" {% endif
  229. %} hx-target="#modal-content" hx-select="main" hx-swap="innerHTML" @click="openModal()">
  230. {% if (resource.type == 'book') and (resource.references) %}
  231. <img class="w-14 h-14 lg:w-20 lg:h-20 object-contain lg:float-right absolute opacity-40 lg:opacity-100 lg:static top-0 right-0 m-1 lg:m-4 grayscale rotate-[15deg]"
  232. src="{{resource.references}}" alt="cover for {{ resource.name }}">
  233. {% endif %}
  234. <h2 class="{{ resource['type'] }} {% if size==1 %} big-title {% else %} small-title {% endif %} mb-2">{{
  235. 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) | safe }}
  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. <link rel="shortcut icon" href="{{ url_for('static',filename='images/favicon-no_bg.png') }}" type="image/x-icon">
  275. <link rel="icon" href="{{ url_for('static',filename='images/favicon-no_bg.png') }}" type="image/x-icon">
  276. <script>
  277. // htmx.on('htmx:beforeRequest', e=> {
  278. // console.log(e)
  279. // })
  280. // htmx.logAll()
  281. function base() {
  282. return {
  283. menuOpen: false,
  284. modalOpen: false,
  285. showRelated: false,
  286. home: '/',
  287. hideIfBase() {
  288. let str = document.location.toString();
  289. str = str.replace('http://', '');
  290. str = str.replace('https://', '');
  291. let l = str.split('/').length - 1;
  292. if (l < 2) {
  293. this.modalOpen = false;
  294. }
  295. return l;
  296. },
  297. init() {
  298. this.$watch('document.location', (value, oldValue) => {
  299. console.log('new url', value);
  300. });
  301. window.addEventListener('popstate', e => {
  302. this.hideIfBase();
  303. });
  304. },
  305. hideOverlay() {
  306. this.modalOpen = false;
  307. // window.history.pushState({}, '', this.home);
  308. },
  309. openModal() {
  310. // this.$refs.modal.innerHTML = '';
  311. this.modalOpen = true;
  312. let mc = document.querySelector('#modal-content');
  313. mc.scrollTo(0, 0);
  314. }
  315. }
  316. }
  317. </script>
  318. </head>
  319. <body class="text-base overflow-y-scroll" x-data="base()" hx-boost="true" hx-select="#all" hx-target="#all"
  320. hx-swap="outerHTML" hx-indicator="body">
  321. <div id="loading" class="loading pointer-events-none ">
  322. <!-- <div class="bg-white fixed top-0 left-0 w-full h-screen z-20"></div> -->
  323. <div class="bg fixed top-0 left-0 w-full h-screen z-30"></div>
  324. <div class="spinner fixed top-0 left-0 w-full h-screen z-[60] flex justify-center items-center">
  325. <div class="inner bg-black rounded-full px-8 py-6 text-white text-center">
  326. Loading...
  327. </div>
  328. </div>
  329. </div>
  330. <div id="all">
  331. <header class="sticky top-0 z-10 bg-white border-b-[2px] border-black flex justify-between w-full">
  332. <nav class=" lg:flex justify-center items-stretch w-full ">
  333. {{ menu('top') }}
  334. </nav>
  335. <div class="burger h-14 cursor-pointer block lg:hidden p-4" @click="menuOpen = true">
  336. <svg width="100%" height="100%" viewBox="0 0 20 18" fill="none" xmlns="http://www.w3.org/2000/svg">
  337. <path d="M1 4H19" stroke="black" stroke-width="1.5" />
  338. <path d="M19 9H1" stroke="black" stroke-width="1.5" />
  339. <path d="M1 14H19" stroke="black" stroke-width="1.5" />
  340. </svg>
  341. </div>
  342. </header>
  343. <div x-transition.opacity x-show="menuOpen" class="fixed z-20 top-0 left-0 w-full h-screen bg-purple-700/50">
  344. </div>
  345. <menu x-transition.opacity class="fixed top-0 right-0 z-20 bg-white w-[calc(100%-2rem)] max-w-[30rem] h-screen"
  346. x-show="menuOpen" style="box-shadow: 0 0 2rem rgb(0,0,0,0.2);" @click.outside="menuOpen = false">
  347. {{ menu('side') }}
  348. </menu>
  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"
  369. class="content w-full overflow-y-auto h-full bg-white ">
  370. </div>
  371. </div>
  372. <!-- Sticky footer-->
  373. <footer class="std-margin mt-20 text-sm">
  374. <div class="container">
  375. <span class="">© 2022–{{ moment().format('YYYY') }} <a href="https://copim.ac.uk/">COPIM</a> and licensed
  376. under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0
  377. International License (CC BY 4.0)</a>.</span>
  378. </div>
  379. </footer>
  380. <!-- JavaScript -->
  381. <script src="{{ url_for('static',filename='js/main.js') }}"></script>
  382. </body>
  383. </html>