From d26dac808ff5a1417058d683e26109cd58e0c7bd Mon Sep 17 00:00:00 2001
From: Olga Bulat
Date: Thu, 6 Feb 2020 16:04:31 +0300
Subject: [PATCH 01/23] Update primary and background color
Signed-off-by: Olga Bulat
---
src/App.vue | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 254488ecc..29a34cecc 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -57,9 +57,7 @@ export default {
-
From a55e71334c56bb01f1ff3bb68a11d9c06d5c67a5 Mon Sep 17 00:00:00 2001
From: Olga Bulat
Date: Thu, 6 Feb 2020 17:39:06 +0300
Subject: [PATCH 02/23] Style Help section according to the mockup
Convert Help buttons into links; render links using 'modals' object and v-for loop
Signed-off-by: Olga Bulat
---
src/components/HelpSection.vue | 84 ++++++++++------------------------
1 file changed, 24 insertions(+), 60 deletions(-)
diff --git a/src/components/HelpSection.vue b/src/components/HelpSection.vue
index d29d0256c..036504d6b 100644
--- a/src/components/HelpSection.vue
+++ b/src/components/HelpSection.vue
@@ -1,58 +1,17 @@
-
-
-
Confused? Need Help?
-
{{ $t('help.instructions.mobile') }}
-
{{ $t('help.instructions.desktop') }}
-
-
+
+
{{$t('help.heading')}}
+
@@ -289,7 +248,17 @@ export default {
}
diff --git a/src/components/FirstStep.vue b/src/components/FirstStep.vue
new file mode 100644
index 000000000..768050828
--- /dev/null
+++ b/src/components/FirstStep.vue
@@ -0,0 +1,72 @@
+
+
+
+ {{$t(cardText)}}
+
+
+
+
+
+
+
+
diff --git a/src/components/HelpSection.vue b/src/components/HelpSection.vue
index 036504d6b..5248494ea 100644
--- a/src/components/HelpSection.vue
+++ b/src/components/HelpSection.vue
@@ -1,5 +1,5 @@
-
+
{{$t('help.heading')}}
+
+
Use Your License
+
{{$t('use-license.instructions')}}
+
+
+ {{$t('use-license.web-instructions')}}
+
+
+
+ Lorem ipsum dolor sit amet.
+
+
+ Lorem ipsum dolor sit amet.
+
+
+
+
+
+
+
+
diff --git a/src/components/SelectedLicenseCard.vue b/src/components/SelectedLicenseCard.vue
new file mode 100644
index 000000000..98472abf6
--- /dev/null
+++ b/src/components/SelectedLicenseCard.vue
@@ -0,0 +1,61 @@
+
+
+
RECOMMENDED LICENSE
+
+
{{selected.shortName}} {{$t('selected-license.description.common')}}
+
+ {{selected.shortName.slice(0, selected.shortName.length-3)}}
+ {{this.$t("selected-license.description.common") }}
+
+ {{this.$t("selected-license.description.non-cc0")}}
+
+
+
+
+ -
+
+
+ {{ $t(`selected-license.description.${item}`)}}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/SelectedLicenseCode.vue b/src/components/SelectedLicenseCode.vue
index 37f462787..73b926731 100644
--- a/src/components/SelectedLicenseCode.vue
+++ b/src/components/SelectedLicenseCode.vue
@@ -1,9 +1,5 @@
+
+
diff --git a/src/components/VerticalStepper.vue b/src/components/VerticalStepper.vue
new file mode 100644
index 000000000..ea4cf6da9
--- /dev/null
+++ b/src/components/VerticalStepper.vue
@@ -0,0 +1,240 @@
+
+
+
{{$t('select-license.heading')}}
+
{{$t('select-license.instructions')}}
+
+
+
+
+
{{$t(headerText(step.name))}}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/locales/en.json b/src/locales/en.json
index 449b959c7..d25b2b8f3 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -20,25 +20,46 @@
},
"stepper":
{
+ "fs": {
+ "heading": "Help with choosing a license",
+ "question": "Do you know which license you need?",
+ "selected": "I know the license I need",
+ "not-selected": "I need help selecting the license"
+ },
"by": {
+ "heading": "Attribution",
"question": "Do you want to require attribution for your work?",
- "selected": "Yes, anyone using my work must give me appropriate credit.",
- "not-selected": "No, anyone can use my work even without attribution."
+ "selected": "Anyone using my work must give me appropriate credit.",
+ "not-selected": "Anyone can use my work even without attribution."
},
"nc": {
+ "heading": "Commercial Use",
"question": "Do you want to prohibit others commercial use of your work?",
- "selected": "Yes, others cannot use my work for commercial purposes.",
- "not-selected": "No, others can use my work for commercial purposes."
+ "selected": "Others cannot use my work for commercial purposes.",
+ "not-selected": "Others can use my work for commercial purposes."
},
"nd": {
+ "heading": "Derivative Works",
"question": "Do you want to prohibit others distributing your work if they remix, transform or build upon it?",
- "selected": "Yes, others can use and share my work only as is, without modifications.",
- "not-selected": "No, others may share modified version of your work."
+ "selected": "Others can use and share my work only as is, without modifications.",
+ "not-selected": "Others may share modified version of your work."
},
"sa": {
+ "heading": "Share on the Same Terms",
"question": "Do you want to prohibit sharing your work under other terms?",
- "selected": "Yes, anyone who changes your work must share their contributions under the same license as the original.",
- "not-selected": "No, anyone who changes your work can distribute their contributions under a different license."
+ "selected": "Anyone who changes your work must share their contributions under the same license as the original.",
+ "not-selected": "Anyone who changes your work can distribute their contributions under a different license."
+ },
+ "cw": {
+ "heading": "Waive your Copyright"
+ },
+ "dd": {
+ "heading": "Creative Commons License",
+ "question": "Which license do you need?"
+ },
+ "ad": {
+ "heading": "Attribution Details",
+ "instructions": "Filling out this form is optional, but helps others attribute your work to you, and fills in machine-readable code"
},
"attribution-details": {
"creator-name": {
@@ -78,6 +99,8 @@
},
"use-license": {
"heading": "Use your license",
+ "instructions": "Choose what kind of work you are licensing to get appropriate license code",
+ "web-instructions": "If you are licensing one work, paste the code next to it. If you are licensing the whole page or blog, you can paste the license code at the bottom of the page",
"rich-text-label": "Rich Text",
"html-label": "HTML",
"copy-label": "Copy",
@@ -105,6 +128,7 @@
"no": "Not a Free Culture License"
},
"help": {
+ "heading": "CONFUSED? NEED HELP?",
"instructions": {
"mobile": "You can tap the buttons below to get answers to the questions on them!",
"desktop": "You can click the buttons below to get answers to the questions on them!"
@@ -167,5 +191,12 @@
"alt": {
"free-works-icon": "Free Works Icon",
"non-free-works-icon": "Icon for a non-Free Works License"
- }
+ },
+ "step": {
+ "previous-label": "BACK",
+ "next-label": "NEXT QUESTION",
+ "finish": "SEE THE LICENSE"
+ },
+ "yes": "Yes. ",
+ "no": "No. "
}
diff --git a/src/main.js b/src/main.js
index 89f6f27c3..ff2a19264 100644
--- a/src/main.js
+++ b/src/main.js
@@ -8,14 +8,14 @@ import { library } from '@fortawesome/fontawesome-svg-core'
import {
faCheck, faCheckCircle, faInfoCircle, faExclamationTriangle, faExclamationCircle,
faArrowUp, faAngleRight, faAngleLeft, faAngleDown, faUserCircle, faQuestionCircle,
- faEye, faEyeSlash, faCaretDown, faCaretUp, faUpload, faCopy
+ faEye, faEyeSlash, faCaretDown, faCaretUp, faUpload, faCopy, faCircle
} from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import LicenseUtilities from './utils/license-utilities'
library.add(faCheck, faCheckCircle, faInfoCircle, faExclamationTriangle, faExclamationCircle,
faArrowUp, faAngleRight, faAngleLeft, faAngleDown, faUserCircle, faQuestionCircle,
- faEye, faEyeSlash, faCaretDown, faCaretUp, faUpload, faCopy)
+ faEye, faEyeSlash, faCaretDown, faCaretUp, faUpload, faCopy, faCircle)
Vue.component('vue-fontawesome', FontAwesomeIcon)
Vue.config.productionTip = false
Vue.use(Buefy, {
diff --git a/src/utils/license-utilities.js b/src/utils/license-utilities.js
index 1c5e02de9..52aa229de 100644
--- a/src/utils/license-utilities.js
+++ b/src/utils/license-utilities.js
@@ -18,6 +18,30 @@ const LicenseUtilities = {
const sa = short.includes('SA')
return { ...defaultLicenseAttributes, NC: nc, ND: nd, SA: sa }
}
+ Vue.prototype.$attrToShort = function(attr) {
+ if (!attr.BY) { return 'CC0 1.0' }
+ let base = 'CC BY'
+ if (attr.NC) { base += '-NC' }
+ if (!attr.ND && attr.SA) {
+ base += '-SA'
+ } else if (attr.ND) {
+ base += '-ND'
+ }
+ base += ' 4.0'
+ return base
+ }
+ Vue.prototype.$attrToFull = function(attr) {
+ if (!attr.BY) { return 'CC0 1.0 Universal' }
+ let base = 'Attribution'
+ if (attr.NC) { base += '-NonCommercial' }
+ if (!attr.ND && attr.SA) {
+ base += '-ShareAlike'
+ } else if (attr.ND) {
+ base += '-NoDerivatives'
+ }
+ base += ' 4.0 International'
+ return base
+ }
Vue.prototype.$licenseUrl = function(shortLicenseName) {
// Returns url to license
if (shortLicenseName.includes('CC0')) {
diff --git a/tests/e2e/globals.js b/tests/e2e/globals.js
index 42d710d2c..06a081c92 100644
--- a/tests/e2e/globals.js
+++ b/tests/e2e/globals.js
@@ -20,7 +20,7 @@ module.exports = {
// expect assertions
waitForConditionTimeout: 5000,
- 'default': {
+ default: {
/*
The globals defined here are available everywhere in any tests env
*/
@@ -32,7 +32,7 @@ module.exports = {
*/
},
- 'firefox': {
+ firefox: {
/*
The globals defined here are available only when the chrome testing env is being used
i.e. when running with --env firefox
From ccbdab4432d6d5c2bfeebc0a8e784f501eac4a88 Mon Sep 17 00:00:00 2001
From: Olga Bulat
Date: Mon, 10 Feb 2020 23:07:47 +0300
Subject: [PATCH 04/23] Setup vuex store
Signed-off-by: Olga Bulat
---
package-lock.json | 5 +
package.json | 3 +-
src/main.js | 3 +
store/index.js | 278 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 288 insertions(+), 1 deletion(-)
create mode 100644 store/index.js
diff --git a/package-lock.json b/package-lock.json
index 079f9d578..e78b96f99 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15772,6 +15772,11 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true
},
+ "vuex": {
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/vuex/-/vuex-3.1.2.tgz",
+ "integrity": "sha512-ha3jNLJqNhhrAemDXcmMJMKf1Zu4sybMPr9KxJIuOpVcsDQlTBYLLladav2U+g1AvdYDG5Gs0xBTb0M5pXXYFQ=="
+ },
"w3c-hr-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz",
diff --git a/package.json b/package.json
index c421ad71e..d749f035c 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,8 @@
"core-js": "^3.6.1",
"vue": "^2.6.10",
"vue-analytics": "^5.22.1",
- "vue-i18n": "^8.15.3"
+ "vue-i18n": "^8.15.3",
+ "vuex": "^3.1.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0",
diff --git a/src/main.js b/src/main.js
index ff2a19264..250c1a991 100644
--- a/src/main.js
+++ b/src/main.js
@@ -3,6 +3,8 @@ import Buefy from 'buefy'
import i18n from './i18n'
import VueAnalytics from 'vue-analytics'
import App from './App.vue'
+import store from '../store'
+
import { library } from '@fortawesome/fontawesome-svg-core'
// internal icons
import {
@@ -34,6 +36,7 @@ if (process.env.NODE_ENV === 'production') {
Vue.use(LicenseUtilities)
new Vue({
+ store,
i18n,
render: h => h(App)
}).$mount('#app')
diff --git a/store/index.js b/store/index.js
new file mode 100644
index 000000000..5b5d3fa57
--- /dev/null
+++ b/store/index.js
@@ -0,0 +1,278 @@
+import Vue from 'vue'
+import Vuex from 'vuex'
+
+Vue.use(Vuex)
+
+const CC0Attributes = { BY: false, NC: false, ND: false, SA: false }
+const CCBYAttributes = { BY: true, NC: false, ND: false, SA: false }
+const visibleSetters = {
+ FS: {
+ true: ['FS', 'DD', 'AD'],
+ false: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD']
+ },
+ BY: {
+ // Decide if NC/ND/SA should be disabled or removed on CC0
+ true: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD'],
+ false: ['FS', 'BY', 'CW', 'NC', 'ND', 'SA', 'AD']
+ },
+ ND: {
+ true: ['FS', 'BY', 'NC', 'ND', 'AD']
+ }
+}
+const disabledSetters = {
+ // Steps that should be disabled if other steps are selected/not selected
+ BY: {
+ false: ['NC', 'ND', 'SA']
+ },
+ ND: {
+ false: ['SA']
+ }
+}
+
+export default new Vuex.Store({
+ state: {
+ currentLicenseAttributes: { ...CCBYAttributes },
+ // FS: First step, checks if user knows the license (and we need to open the dropdown)
+ // CW: Copyright waiver step for CC0
+ // DD: Dropdown step if user knows the license
+ // AD: Attribution Details step with the form
+ steps: [
+ // VISIBLE: Steps are shown only if visible is set to true
+ // eg. When we choose BY, Copyright Waiver is not shown
+ // ENABLED: Steps are shown but disabled when they cannot be chosen
+ // eg. When we choose ND, SA is disabled
+ { id: 0, name: 'FS', visible: true, enabled: true, status: 'current' },
+ { id: 1, name: 'BY', visible: true, enabled: true, status: 'inactive' },
+ { id: 2, name: 'NC', visible: true, enabled: true, status: 'inactive' },
+ { id: 3, name: 'ND', visible: true, enabled: true, status: 'inactive' },
+ { id: 4, name: 'SA', visible: true, enabled: true, status: 'inactive' },
+ { id: 5, name: 'CW', visible: false, enabled: true, status: 'inactive' },
+ { id: 6, name: 'DD', visible: false, enabled: true, status: 'inactive' },
+ { id: 7, name: 'AD', visible: true, enabled: true, status: 'inactive' }
+ ],
+ attributionDetails: {
+ creatorName: '',
+ creatorProfileUrl: '',
+ workTitle: '',
+ workUrl: ''
+ },
+ knowLicense: false,
+ currentStepId: 0
+ },
+ getters: {
+ shortName: state => {
+ let shortLicenseName = 'CC'
+ if (state.currentLicenseAttributes.BY) {
+ shortLicenseName = ` BY${state.currentLicenseAttributes.NC ? '-NC' : ''}`
+ if (state.currentLicenseAttributes.SA && !state.currentLicenseAttributes.ND) {
+ shortLicenseName += '-SA'
+ } else if (state.currentLicenseAttributes.ND) {
+ shortLicenseName += '-ND'
+ }
+ shortLicenseName += ' 4.0'
+ } else {
+ shortLicenseName += '0 1.0'
+ }
+ return shortLicenseName
+ },
+ fullName: state => {
+ let fullLicenseName = ''
+ if (state.currentLicenseAttributes.BY) {
+ fullLicenseName = `Attribution${state.currentLicenseAttributes.NC ? '-NonCommercial' : ''}`
+ if (state.currentLicenseAttributes.SA && !state.currentLicenseAttributes.ND) {
+ fullLicenseName += '-ShareAlike'
+ } else if (state.currentLicenseAttributes.ND) {
+ fullLicenseName += '-NoDerivatives'
+ }
+ fullLicenseName += ' 4.0'
+ return fullLicenseName
+ } else {
+ return 'CC0 1.0 Universal'
+ }
+ },
+ licenseUrl: state => {
+ if (!state.currentLicenseAttributes.BY) {
+ return 'https://creativecommons.org/publicdomain/zero/1.0/?ref=ccchooser'
+ } else {
+ const license = `by${state.currentLicenseAttributes.NC ? '-nc' : ''}${state.currentLicenseAttributes.ND ? '-nd' : ''}${state.currentLicenseAttributes.SA ? '-sa' : ''}`
+ return 'https://creativecommons.org/licenses/' + license + '/4.0/?ref=ccchooser'
+ }
+ },
+ iconsList: state => {
+ const iconsArray = []
+ for (const key in state.currentLicenseAttributes) {
+ if (state.currentLicenseAttributes[key]) {
+ iconsArray.push(key.toLowerCase())
+ }
+ }
+ return iconsArray
+ },
+ isStepSelected: state => (stepName) => {
+ return stepName === 'FS'
+ ? state.knowLicense
+ : state.currentLicenseAttributes[stepName]
+ },
+ enabledAndVisibleSteps: state => {
+ return state.steps.filter(step => {
+ return step.visible && step.enabled
+ })
+ },
+ getStepById: (state, getters) => (id) => {
+ return state.steps.find(step => step.id === id)
+ },
+ getStepByName: (state, getters) => (name) => {
+ return state.steps.find(step => step.name === name)
+ }
+ },
+ mutations: {
+ toggleSelected(state, stepName) {
+ // Called when a radio button is clicked, either FirstStep or VerticalStep
+ if (['BY', 'NC', 'ND', 'SA'].indexOf(stepName) > -1) {
+ state.currentLicenseAttributes = {
+ ...state.currentLicenseAttributes,
+ [stepName]: !state.currentLicenseAttributes[stepName]
+ }
+ } else {
+ state.knowLicense = !state.knowLicense
+ }
+ },
+ updateAttributesFromShort(state, shortName) {
+ if (shortName.includes('CC0')) {
+ state.currentLicenseAttributes = { ...CC0Attributes }
+ } else {
+ state.currentLicenseAttributes.NC = !!shortName.includes('NC')
+ state.currentLicenseAttributes.ND = !!shortName.includes('ND')
+ state.currentLicenseAttributes.SA = !!shortName.includes('SA')
+ }
+ },
+ updateStepStatus(state, stepName) {
+ // when transitioning, set currentStep's status to 'previous' and nextStep's status to 'current'
+ const stepId = state.steps.find(step => step.name === stepName).id
+ const nextStep = state.steps.slice(stepId + 1).find(step => step.visible && step.enabled).id
+ Vue.set(state.steps, nextStep, { ...state.steps[nextStep], status: 'current' })
+ Vue.set(state.steps, stepId, { ...state.steps[stepId], status: 'previous' })
+ state.currentStepId = nextStep
+ },
+ goToPrevious(state, stepName) {
+ // when transitioning, set currentStep's (and steps between current and next) status to 'inactive' and
+ // nextStep's status to 'current'
+ const stepId = state.steps.find(step => step.name === stepName).id
+ let previousStep = stepId
+ for (let i = stepId - 1; i >= 0; i--) {
+ const thisStep = state.steps[i]
+ if (thisStep.visible && thisStep.enabled) {
+ previousStep = state.steps[i].id
+ break
+ }
+ }
+ Vue.set(state.steps, previousStep, { ...state.steps[previousStep], status: 'current' })
+ Vue.set(state.steps, stepId, { ...state.steps[stepId], status: 'inactive' })
+ state.currentStepId = previousStep
+ },
+ updateDisabledSteps(state, stepsToSetDisabled) {
+ console.log('Update disabled steps: ', stepsToSetDisabled)
+ // Set disabled steps in the stepsToSetDisabled array
+ for (const step of state.steps) {
+ if (stepsToSetDisabled.indexOf(step.name) > -1 && !step.enabled) {
+ Vue.set(state.steps, step.id, { ...step, enabled: false })
+ } else if (stepsToSetDisabled.indexOf(step.name) === -1 && step.enabled) {
+ Vue.set(state.steps, step.id, { ...step, enabled: true })
+ }
+ }
+ },
+ updateVisibleSteps(state, stepsToSetVisible) {
+ // stepsToSetVisible is an array of stepNames to set Visible
+ let visibleCounter = 0
+ for (const step of state.steps) {
+ if (stepsToSetVisible.indexOf(step.name) > -1 && !step.visible) {
+ Vue.set(state.steps, step.id, { ...step, visible: true, currentId: visibleCounter })
+ visibleCounter += 1
+ } else if (stepsToSetVisible.indexOf(step.name) === -1 && step.visible) {
+ Vue.set(state.steps, step.id, { ...step, visible: false, currentId: -1 })
+ } else if (!step.visible && step.currentId !== -1) {
+ Vue.set(state.steps, step.id, { ...step, currentId: -1 })
+ } else if (step.visible && step.currentId === -1) {
+ Vue.set(state.steps, step.id, { ...step, currentId: visibleCounter })
+ visibleCounter += 1
+ }
+ }
+ },
+ setCreatorName(state, newName) {
+ state.attributionDetails.creatorName = newName
+ },
+ setCreatorProfileUrl(state, newName) {
+ state.attributionDetails.ProfileUrl = newName
+ },
+ setWorkTitle(state, newName) {
+ state.attributionDetails.workTitle = newName
+ },
+ setWorkUrl(state, newName) {
+ state.attributionDetails.workUrl = newName
+ }
+ },
+ actions: {
+ updateDisabledAndVisibleSteps(context, payload) {
+ const [stepName, isStepSelected] = payload
+ if (stepName in visibleSetters) {
+ const visible = visibleSetters[stepName][isStepSelected]
+ console.log(visible, visibleSetters[stepName])
+ if (visible !== undefined) {
+ console.log('Will set ', visible.toString(), ' visible')
+ context.commit('updateVisibleSteps', visible)
+ }
+ }
+ if (stepName in disabledSetters) {
+ const disabled = disabledSetters[stepName][isStepSelected]
+ if (disabled !== undefined) {
+ console.log('Will set ', disabled, ' disabled because ', stepName, ' is selected? ', isStepSelected)
+ context.commit('updateDisabledSteps', disabled)
+ }
+ }
+ },
+ handleNext: (context, payload) => {
+ const currentStepName = payload
+ const isCurrentStepSelected = context.getters.isStepSelected(payload)
+ context.dispatch('updateDisabledAndVisibleSteps', [currentStepName, isCurrentStepSelected])
+ context.commit('updateStepStatus', currentStepName)
+ },
+ handlePrevious: (context, payload) => {
+ console.log('Handle previous: ', payload)
+ const currentStepName = payload
+ const isCurrentStepSelected = context.getters.isStepSelected(payload)
+ context.dispatch('updateDisabledAndVisibleSteps', [currentStepName, isCurrentStepSelected])
+ context.commit('goToPrevious', currentStepName)
+ },
+ updateSelected: (context, payload) => {
+ // On radio button click, Step's Selected parameter is toggled and Disabled/Visible
+ // steps are updated
+ const [currentStepName, isCurrentStepSelected] = payload
+ console.log('Updating selected, current step: ', currentStepName, ', selected: ', isCurrentStepSelected)
+ console.log('Steps before toggling: ', context.state.steps[1])
+ context.commit('toggleSelected', currentStepName)
+ console.log('Steps after toggling: ', context.state.steps[1], context.state.currentLicenseAttributes)
+ context.dispatch('updateDisabledAndVisibleSteps', [currentStepName, !isCurrentStepSelected])
+ },
+ setActiveStep: (context, payload) => {
+ const nextStep = context.getters.getStepByName(payload)
+ if (context.state.currentStepId < nextStep.id) {
+ for (let i = context.state.currentStepId; i < nextStep.id; i++) {
+ Vue.set(context.state.steps, i,
+ { ...context.state.steps[i], status: 'previous' })
+ }
+ Vue.set(context.state.steps,
+ nextStep.id,
+ { ...context.state.steps[nextStep.id], status: 'current' })
+ } else {
+ for (let i = context.state.currentStepId; i > nextStep.id; i--) {
+ Vue.set(context.state.steps, i,
+ { ...context.state.steps[i], status: 'inactive' })
+ }
+ Vue.set(context.state.steps,
+ nextStep.id,
+ { ...context.state.steps[nextStep.id], status: 'current' })
+ }
+ context.state.currentStepId = nextStep.id
+ }
+ }
+})
+// TODO: I'm calculating current Step Name in many places, sending a stepName parameter can be faster
From 856e7951028310449726d83bc7b9aca39a9098d5 Mon Sep 17 00:00:00 2001
From: Olga Bulat
Date: Mon, 10 Feb 2020 23:18:24 +0300
Subject: [PATCH 05/23] Add vuex to components
Signed-off-by: Olga Bulat
---
src/App.vue | 52 ++----
src/components/AttributionDetailsStep.vue | 13 +-
src/components/FirstStep.vue | 37 ++--
src/components/SelectedLicenseCard.vue | 25 ++-
src/components/SelectedLicenseCode.vue | 30 ++--
src/components/SelectedLicenseDropdown.vue | 23 +--
src/components/VerticalStep.vue | 74 +++++---
src/components/VerticalStepper.vue | 196 ++++++---------------
8 files changed, 169 insertions(+), 281 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 19c16779d..f547fd771 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -4,20 +4,13 @@
-
-
+
+
@@ -54,6 +47,7 @@ import SelectedLicenseCard from './components/SelectedLicenseCard'
import LicenseUseCard from './components/LicenseUseCard'
import { Header, Footer, Locale } from '@creativecommons/vue-vocabulary'
import Feedback from './components/Feedback'
+import { mapState } from 'vuex'
export default {
name: 'App',
@@ -67,40 +61,14 @@ export default {
Footer,
Locale
},
- data() {
- return {
- showLicense: false,
- showLicenseUse: false,
- currentStep: 0,
- selected: {
- shortName: 'CC BY 4.0',
- fullName: 'Attribution 4.0 International',
- attributionDetails: {
- creatorName: '',
- creatorProfileUrl: '',
- workTitle: '',
- workUrl: ''
- }
- }
- }
- },
- methods: {
- openLicenseCard() {
- this.showLicense = true
- },
- openLicenseUse() {
- this.showLicenseUse = true
+ computed: {
+ ...mapState(['knowLicense', 'currentStepId']),
+ showLicense() {
+ return this.currentStepId > 0
},
- updateLicense(licenseAttribute) {
- const attrUpper = licenseAttribute.toUpperCase()
- const attributes = this.$shortToAttributes(this.selected.shortName)
- const updatedAttributes = { ...attributes }
- updatedAttributes[attrUpper] = !attributes[attrUpper]
- this.selected = {
- ...this.selected,
- shortName: this.$attrToShort(updatedAttributes),
- fullName: this.$attrToFull(updatedAttributes)
- }
+ showLicenseUse() {
+ // If License Attribution details step (no.7) is open
+ return this.currentStepId === 7
}
},
created: function() {
diff --git a/src/components/AttributionDetailsStep.vue b/src/components/AttributionDetailsStep.vue
index 4f5176ad8..cab124044 100644
--- a/src/components/AttributionDetailsStep.vue
+++ b/src/components/AttributionDetailsStep.vue
@@ -2,25 +2,25 @@