From b0b690d2f6593f3aa17d38c5f67dadd041e42ade Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:41:06 +0000 Subject: [PATCH 1/9] setup baseline file for stepper logic --- src/scripts.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/scripts.js diff --git a/src/scripts.js b/src/scripts.js new file mode 100644 index 00000000..5a232d6c --- /dev/null +++ b/src/scripts.js @@ -0,0 +1 @@ +// stepper logic here From a622af6ce5470594e3b099ecd7b0814b57fdd6e0 Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:50:30 +0000 Subject: [PATCH 2/9] add baseline state path routes as array --- src/scripts.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/scripts.js b/src/scripts.js index 5a232d6c..7fc4d2de 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -1 +1,22 @@ + +// all possible State Path Routes +let rawStatePathRoutes = [ + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-0/waive-your-copyright+waive+read/(attribution-details)&license=cc-0', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by/(attribution-details)&license=cc-by', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-sa/(attribution-details)&license=cc-by-sa', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nd/(attribution-details)&license=cc-by-nd', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc/(attribution-details)&license=cc-by-nc', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc-sa/(attribution-details)&license=cc-by-nc-sa', + 'do-you-know-which-license-you-need/yes/which-license-do-you-need/cc-by-nc-nd/(attribution-details)&license=cc-by-nc-nd', + + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/yes/allow-derivatives/yes/share-alike/no/confirmation+ownership+read+revocation/(attribution-details)&license=cc-by', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/yes/allow-derivatives/yes/share-alike/yes/confirmation+ownership+read+revocation/(attribution-details)&license=cc-by-sa', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/yes/allow-derivatives/no/confirmation+ownership+read+revocation/(attribution-details)&license=cc-by-nd', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/no/allow-derivatives/yes/share-alike/no/confirmation+ownership+read+revocation/(attribution-details)&license=cc-by-nc', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/no/allow-derivatives/yes/share-alike/yes/confirmation+ownership+read+revocation/(attribution-details)&license=cc-by-nc-sa', + 'do-you-know-which-license-you-need/no/require-attribution/yes/allow-commercial-use/no/allow-derivatives/no/confirmation+ownership+read+revocation/(attribution-details)&license=cc-by-nc-nd', + 'do-you-know-which-license-you-need/no/require-attribution/no/waive-your-copyright+waive+read/(attribution-details)&license=cc-0' +]; + + // stepper logic here From 7aca886ee7583f0cac734bfe4674d67c4bc11b63 Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:58:55 +0000 Subject: [PATCH 3/9] add comments for rough logic flow sections --- src/scripts.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/scripts.js b/src/scripts.js index 7fc4d2de..b99d21d4 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -18,5 +18,28 @@ let rawStatePathRoutes = [ 'do-you-know-which-license-you-need/no/require-attribution/no/waive-your-copyright+waive+read/(attribution-details)&license=cc-0' ]; +// function to parse and build state.possibilities -// stepper logic here +// function to track state.parts +// [T]: should this be a part of state.current +// as in: state.current.parts ? + +// function to update and track state.current +// this is a full combo of all set state.parts + +// function to compare state.possibilities to state.current, +// determine if valid license, or error + +// function to set state.props +// including setting state.props.license (if valid) + +// stepper logic here for what parts are displayed, +// if valid license from state.parts and/or state.current + +// function to render license recommendation, +// if valid license from state.parts and/or state.current + +// function to render mark your work, from attribution fields +// if valid license from state.parts and/or state.current + +// function to handle error state From efa309662253353ef0616a6d17a3fc093ea7a4d0 Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 21:03:05 +0000 Subject: [PATCH 4/9] amend comments for clarify --- src/scripts.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index b99d21d4..71c0dbcc 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -19,10 +19,9 @@ let rawStatePathRoutes = [ ]; // function to parse and build state.possibilities +// from rawStatePathRoutes // function to track state.parts -// [T]: should this be a part of state.current -// as in: state.current.parts ? // function to update and track state.current // this is a full combo of all set state.parts @@ -33,13 +32,14 @@ let rawStatePathRoutes = [ // function to set state.props // including setting state.props.license (if valid) -// stepper logic here for what parts are displayed, -// if valid license from state.parts and/or state.current +// stepper logic here for what parts of form are +// displayed/hidden, as state.parts and state.current +// are updated -// function to render license recommendation, +// function to render "license recommendation", // if valid license from state.parts and/or state.current -// function to render mark your work, from attribution fields +// function to render "mark your work", from attribution fields // if valid license from state.parts and/or state.current // function to handle error state From 91ab663d1188043dead7f1f789143e7590ea7828 Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 21:18:05 +0000 Subject: [PATCH 5/9] clean up comments, add setStateParts and setStatePossibilities rough functions, add section for flow logic --- src/scripts.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index 71c0dbcc..4707fa1c 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -18,13 +18,56 @@ let rawStatePathRoutes = [ 'do-you-know-which-license-you-need/no/require-attribution/no/waive-your-copyright+waive+read/(attribution-details)&license=cc-0' ]; +// empty state obj +let state = {}; + // function to parse and build state.possibilities // from rawStatePathRoutes +function setStatePossibilities(state) { + + // create state possibilities from possible licenses with adjoining statePaths + state.possibilities = []; + rawStatePathRoutes.forEach((path, index) => { + + statePath = path.split("&"); + statepath = statePath; + license = statePath[statePath.length - 1].split("="); + license = license[1]; + + regEx = /\(([^)]+)\)/g; + optionals = statePath[0].match(regEx); -// function to track state.parts + optionals.forEach ((optional) => { + + noOptionalsPath = statePath[0].replace(optional,''); + + }); + + fullPath = statePath[0].replace(/[{()}]/g, '') + '/'; + + if (state.possibilities[license] == undefined) { + state.possibilities[license] = []; + } + state.possibilities[license].push(fullPath); + state.possibilities[license].push(noOptionalsPath); + + }); +} -// function to update and track state.current -// this is a full combo of all set state.parts +// function to establish state.parts +function setStateParts(state) { + state.parts = []; + + // temp defaults + state.parts[0] = 'do-you-know-which-license-you-need/yes/'; + state.parts[1] = 'which-license-do-you-need/cc-by/'; + state.parts[8] = 'attribution-details/'; +} + +// function to update and track state.parts + +// function to combine current tracked +// state.parts into state.current // function to compare state.possibilities to state.current, // determine if valid license, or error @@ -43,3 +86,12 @@ let rawStatePathRoutes = [ // if valid license from state.parts and/or state.current // function to handle error state + + +// full flow logic +setStateParts(state); +console.log(state.parts); + +setStatePossibilities(state); + console.log(state.possibilities); + From 19a6704f85ed737852eb27b9deb50c5c67a12c34 Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 21:20:16 +0000 Subject: [PATCH 6/9] update comments for better console readability --- src/scripts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scripts.js b/src/scripts.js index 4707fa1c..16b5d621 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -90,8 +90,10 @@ function setStateParts(state) { // full flow logic setStateParts(state); +console.log('state.parts (at default)'); console.log(state.parts); setStatePossibilities(state); - console.log(state.possibilities); +console.log('state.possibilities'); +console.log(state.possibilities); From 8bc76e8c35b95cb8ecd7d6989df821aa8e9efa5a Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:05:16 +0000 Subject: [PATCH 7/9] add rough logic for direct checking of logical state path with possibility, and setting state.props.license to a matching license when found --- src/scripts.js | 95 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 5 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index 16b5d621..24b3874e 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -21,6 +21,9 @@ let rawStatePathRoutes = [ // empty state obj let state = {}; +// all found fieldsets +const fieldsets = document.querySelectorAll('fieldset'); + // function to parse and build state.possibilities // from rawStatePathRoutes function setStatePossibilities(state) { @@ -63,17 +66,98 @@ function setStateParts(state) { state.parts[1] = 'which-license-do-you-need/cc-by/'; state.parts[8] = 'attribution-details/'; } +// function to update state.parts +function updateStateParts(element, index, event, state) { + + state.parts[index] = element.id + '/' + event.target.value + '/'; + + // check if checkbox, with siblings + if (event.target.getAttribute('type') == 'checkbox') { + let checkboxElements = element.querySelectorAll('input[type="checkbox"]'); + let checkboxes = []; + checkboxElements.forEach((checkbox, index) => { + if (checkbox.checked) { + checkboxes[index] = checkbox.value; + } + }); + + + let joinedCheckboxes = checkboxes.filter(Boolean).join('+'); + + state.parts[index] = element.id + '+' + joinedCheckboxes + '/';; + } -// function to update and track state.parts + // check if text input + if (event.target.getAttribute('type') == 'text') { + + state.parts[index] = element.id + '/'; + + } + + console.log("state.parts (after change)"); + console.log(state.parts); +} // function to combine current tracked // state.parts into state.current +function setStateCurrent(element, index, state) { + state.parts.forEach((element, i) => { + if (i > index) { + state.parts.splice(i); + } + }); + // [T]: also reset value to nothing each time -// function to compare state.possibilities to state.current, -// determine if valid license, or error + state.current = state.parts.join('') //.slice(0, -1); +} // function to set state.props // including setting state.props.license (if valid) +function setStateProps(state) { + + state.props = {}; + state.props.license = 'unknown'; + + // check and match possibilities + Object.keys(state.possibilities).forEach((possibility) => { + if(state.possibilities[possibility].includes(state.current)) { + state.props.license = possibility; + console.log('matched'); + } + }); + +} + +// function to watch for fieldset changes +function watchFieldsets(fieldsets, state) { + fieldsets.forEach((element, index) => { + + // [T]: set defaults here first in state.parts dynamically + + element.addEventListener("change", (event) => { + + console.log("something changed!"); + updateStateParts(element, index, event, state); + + setStateCurrent(element, index, state); + console.log("state.current (after change)"); + console.log(state.current); + + setStateProps(state); + console.log("state.props (after change)"); + console.log(state.props); + + }); + + }); +} + + + +// function to compare state.possibilities to state.current, +// determine if valid license, or error + + // stepper logic here for what parts of form are // displayed/hidden, as state.parts and state.current @@ -90,10 +174,11 @@ function setStateParts(state) { // full flow logic setStateParts(state); -console.log('state.parts (at default)'); +console.log("state.parts (at default)"); console.log(state.parts); setStatePossibilities(state); -console.log('state.possibilities'); +console.log("state.possibilities"); console.log(state.possibilities); +watchFieldsets(fieldsets, state); From 5c062553654d3cc88d531279b22f5bb9ceb427b2 Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:09:10 +0000 Subject: [PATCH 8/9] add rough render for h3 alone when license path currenty set is valid to a possibility --- src/scripts.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index 24b3874e..339ae259 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -113,6 +113,7 @@ function setStateCurrent(element, index, state) { // function to set state.props // including setting state.props.license (if valid) +// or error function setStateProps(state) { state.props = {}; @@ -146,7 +147,8 @@ function watchFieldsets(fieldsets, state) { setStateProps(state); console.log("state.props (after change)"); console.log(state.props); - + + renderLicenseRec(state); }); }); @@ -154,17 +156,15 @@ function watchFieldsets(fieldsets, state) { -// function to compare state.possibilities to state.current, -// determine if valid license, or error - - - // stepper logic here for what parts of form are // displayed/hidden, as state.parts and state.current // are updated // function to render "license recommendation", // if valid license from state.parts and/or state.current +function renderLicenseRec(state) { + document.querySelector('#license-recommendation header h3').textContent = state.props.license; +} // function to render "mark your work", from attribution fields // if valid license from state.parts and/or state.current From c6a8d749d7362e054d74c2e3dacc0e30755b130d Mon Sep 17 00:00:00 2001 From: possumbilities <109087089+possumbilities@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:10:39 +0000 Subject: [PATCH 9/9] adjust empty lines --- src/scripts.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index 339ae259..fb20ef54 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -154,8 +154,6 @@ function watchFieldsets(fieldsets, state) { }); } - - // stepper logic here for what parts of form are // displayed/hidden, as state.parts and state.current // are updated