Commit 298eb404 authored by Johan-Henrik Fylling's avatar Johan-Henrik Fylling
Browse files

Add WIP experimental webpack bundling.

parent 158e4a63
Pipeline #129076 failed with stages
(()=>{"use strict";var e={34:(e,t,r)=>{void 0!==(e=r.hmd(e)).exports&&(e.exports={fetchExerciseTypes:async function(){const e=`${HOST}/api/exercises/`;let t=await sendRequest("GET",e);if(t.ok)return(await t.json()).results;throw t},fetchWorkouts:async function(e){const t=`${HOST}/api/workouts/?ordering=${e}`;let r=await sendRequest("GET",t);if(r.ok)return(await r.json()).results;throw r}})},601:(e,t,r)=>{function o(e){let t=document.getElementById(e);t.classList.add("active"),t.setAttribute("aria-current","page")}function n(e){let t=null,r=document.cookie.split("; ").find((t=>t.startsWith(e)));return r&&(t=r.split("=")[1]),t}let s;window.addEventListener("DOMContentLoaded",(function(){"/"==window.location.pathname||"/index.html"==window.location.pathname?o("nav-index"):"/workouts.html"==window.location.pathname?o("nav-workouts"):"/exercises.html"==window.location.pathname?o("nav-exercises"):"/mycoach.html"==window.location.pathname?o("nav-mycoach"):"/myathletes.html"==window.location.pathname?o("nav-myathletes"):"/userprofile.html"==window.location.pathname&&o("nav-userprofile"),null!=n("access")||null!=n("refresh")?(document.getElementById("btn-logout").classList.remove("hide"),document.querySelector('a[href="logout.html"').classList.remove("hide"),document.querySelector('a[href="workouts.html"').classList.remove("hide"),document.querySelector('a[href="mycoach.html"').classList.remove("hide"),document.querySelector('a[href="exercises.html"').classList.remove("hide"),document.querySelector('a[href="myathletes.html"').classList.remove("hide"),document.querySelector('a[href="userprofile.html"]').classList.remove("hide")):(document.getElementById("btn-login-nav").classList.remove("hide"),document.getElementById("btn-register").classList.remove("hide"))})),r(34),e=r.hmd(e);let i,a="any",l=[new Date("2021-01-01T13:00:00"),new Date];function c(e){let t=document.getElementById("div-content");e.forEach((e=>{let r=document.querySelector("#template-workout").content.cloneNode(!0).querySelector("a");r.href=`workout.html?id=${e.id}`,r.id=e.id,r.querySelector("h5").textContent=e.name;let o=new Date(e.date),n=r.querySelector("table").querySelectorAll("tr");n[0].querySelectorAll("td")[1].textContent=o.toLocaleDateString(),n[1].querySelectorAll("td")[1].textContent=o.toLocaleTimeString(),n[2].querySelectorAll("td")[1].textContent=e.owner_username,n[3].querySelectorAll("td")[1].textContent=e.exercise_instances.length,t.appendChild(r)}))}function d(e,t){const r=document.querySelector("#exercise-filter-select");if(void 0!==t){let r=JSON.parse(atob(("; "+document.cookie).split("; access=").pop().split(";").shift().split(".")[1])).user_id;t=t.filter((e=>parseInt(e.user)===parseInt(r))),e=e.sort(((e,r)=>t.some((t=>t.exercise===e.id))&&!t.some((e=>e.exercise===r.id))?1:!t.some((t=>t.exercise===e.id))&&t.some((e=>e.exercise===r.id))?-1:0)).reverse()}e.forEach((e=>{const t=document.createElement("option");t.value=e.url,t.innerText=e.name,r.append(t)}))}function u(){window.location.replace("workout.html")}function m(e,t,r,o,n,s){return(t=(t=(t=t.filter((e=>-1!=e.name.search(r)||null==r))).filter((t=>function(e,t,r){let o;switch(r){case"list-my-workouts-list":o=t.owner==e.url;break;case"list-athlete-workouts-list":o=e.athletes&&e.athletes.includes(t.owner);break;case"list-public-workouts-list":o="PU"==t.visibility;break;default:o=!0}return o}(e,t,n)))).filter((e=>function(e,t){return e.exercise_instances.map((e=>e.exercise)).includes(t)||"any"==t}(e,o)))).filter((e=>function(e,t){const r=new Date(e.date),o=new Date(t[0]),n=new Date(t[1]);return o<=r&&r<=n}(e,s)))}function h(e){let t=Array.from(document.querySelectorAll(".workout"));const r=e.map((e=>e.id));let o=t.filter((e=>r.includes(parseInt(e.id,10)))),n=t.filter((e=>!r.includes(parseInt(e.id,10))));o.forEach((e=>{e.classList.remove("hide")})),n.forEach((e=>{e.classList.add("hide")}))}window.addEventListener("DOMContentLoaded",(async()=>{document.querySelector("#btn-create-workout").addEventListener("click",u);let e="-date";const t=new URLSearchParams(window.location.search);t.has("ordering")&&(e=t.get("ordering"),"name"==e||"owner"==e||"date"==e)&&(document.querySelector(`a[href="?ordering=${e}"`).href=`?ordering=-${e}`),document.querySelector("#current-sort").innerHTML=(e.startsWith("-")?"Descending":"Ascending")+" "+e.replace("-",""),e.includes("owner")&&(e+="__username");let r=await fetchWorkouts(e);c(r);let o=await sendRequest("GET",`${HOST}/api/favorites/`),n=await o.json();fetchExerciseTypes().then((e=>d(e,n.results))).catch((e=>{console.error(e)}));let w=await getCurrentUser();const p=document.querySelector("#workout-from-datetime"),f=document.querySelector("#workout-to-datetime");p.value=l[0].toISOString().substr(0,19),f.value=l[1].toISOString().substr(0,19),p.addEventListener("input",(()=>{l[0]=p.value,h(m(w,r,s,a,i,l))})),f.addEventListener("input",(()=>{l[1]=f.value,h(m(w,r,s,a,i,l))}));let y=document.querySelector("#input-search-text");y.addEventListener("input",(()=>{s=y.value,h(m(w,r,s,a,i,l))}));const v=document.querySelector("#exercise-filter-select");console.debug("element:",v),v.addEventListener("change",(e=>{console.debug("select event:",e,"event value:",e.target.value),a=e.target.value,h(m(w,r,s,a,i,l))}));let x=document.querySelectorAll('a[data-bs-toggle="list"]');for(let e=0;e<x.length;e++)x[e].addEventListener("show.bs.tab",(function(e){i=e.currentTarget.id,h(m(w,r,s,a,i,l))}))})),void 0!==e.exports&&(e.exports={renderWorkouts:c,renderExerciseOptions:d,toggleHideWorkouts:h,filterWorkouts:m})}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={id:o,loaded:!1,exports:{}};return e[o](s,s.exports,r),s.loaded=!0,s.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.hmd=e=>((e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(601)})();
\ No newline at end of file
This diff is collapsed.
......@@ -32,6 +32,8 @@
"jest": "^26.6.3",
"nodemon": "^2.0.7",
"prettier": "2.2.1",
"webpack": "^5.33.2",
"webpack-cli": "^4.6.0",
"whatwg-fetch": "^3.6.1"
},
"cordova": {
......
const path = require('path');
module.exports = {
entry: './www/scripts/workouts.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
};
\ No newline at end of file
async function fetchExerciseTypes() {
export async function fetchExerciseTypes() {
const url = `${HOST}/api/exercises/`;
let response = await sendRequest("GET", url);
if (!response.ok) {
......@@ -12,7 +12,7 @@ async function fetchExerciseTypes() {
}
}
async function fetchWorkouts(ordering) {
export async function fetchWorkouts(ordering) {
const url = `${HOST}/api/workouts/?ordering=${ordering}`;
let response = await sendRequest("GET", url);
......
const HOST = "http://localhost:9090";
export const HOST = "http://localhost:9090";
function makeNavLinkActive(id) {
export function makeNavLinkActive(id) {
let link = document.getElementById(id);
link.classList.add("active");
link.setAttribute("aria-current", "page");
}
function isUserAuthenticated() {
export function isUserAuthenticated() {
return getCookieValue("access") != null || getCookieValue("refresh") != null;
}
function updateNavBar() {
export function updateNavBar() {
// Emphasize link to current page
if (
window.location.pathname == "/" ||
......@@ -44,16 +44,16 @@ function updateNavBar() {
}
}
function setCookie(name, value, maxage, path = "") {
export function setCookie(name, value, maxage, path = "") {
document.cookie = `${name}=${value}; max-age=${maxage}; path=${path}`;
}
// eslint-disable-next-line no-unused-vars
function deleteCookie(name) {
export function deleteCookie(name) {
setCookie(name, "", 0, "/");
}
function getCookieValue(name) {
export function getCookieValue(name) {
let cookieValue = null;
let cookieByName = document.cookie
.split("; ")
......@@ -66,7 +66,7 @@ function getCookieValue(name) {
return cookieValue;
}
async function sendRequest(
export async function sendRequest(
method,
url,
body,
......@@ -116,7 +116,7 @@ async function sendRequest(
}
// eslint-disable-next-line no-unused-vars
function setReadOnly(readOnly, selector) {
export function setReadOnly(readOnly, selector) {
let form = document.querySelector(selector);
let formData = new FormData(form);
......@@ -153,7 +153,7 @@ function setReadOnly(readOnly, selector) {
}
// eslint-disable-next-line no-unused-vars
async function getCurrentUser() {
export async function getCurrentUser() {
let user = null;
let response = await sendRequest("GET", `${HOST}/api/users/?user=current`);
if (!response.ok) {
......@@ -167,7 +167,7 @@ async function getCurrentUser() {
}
// eslint-disable-next-line no-unused-vars
function createAlert(header, data, type) {
export function createAlert(header, data, type) {
let alertDiv = document.createElement("div");
//alertDiv.className = ""
if (type === "success")
......
import "./scripts";
import "./api";
import "./defaults";
let SEARCH_STRING;
let EXERCISE_FILTER = "any";
let WORKOUT_VISIBILITY;
......
......@@ -80,10 +80,11 @@
</a>
</template>
<script src="scripts/defaults.js"></script>
<!-- <script src="scripts/defaults.js"></script>
<script src="scripts/scripts.js"></script>
<script src="scripts/api.js"></script>
<script src="scripts/workouts.js"></script>
<script src="scripts/workouts.js"></script> -->
<script src="../main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment