Skip to content

Commit 1a2f3d1

Browse files
committed
Extract common functions to a plugin
Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent 7c579a4 commit 1a2f3d1

12 files changed

+80
-89
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/tests/e2e/reports/
22
/chromedriver.log
33
/docs/
4+
.idea/
5+
coverage/
6+
node_modules/

src/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<Header :title="$t('chooser')"/>
3+
<Header :title="$t('app-title')"/>
44
<Feedback/>
55
<div class="container" id="site-container">
66
<Chooser />

src/components/AttributionRichText.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
</template>
4141

4242
<script>
43-
import licenseUrl from '@/utils/licenseUrl'
4443
import LicenseIcons from './LicenseIcons'
4544
4645
export default {
@@ -51,10 +50,10 @@ export default {
5150
},
5251
computed: {
5352
licenseURL() {
54-
return licenseUrl(this.$props.value.shortName)
53+
return this.$licenseUrl(this.$props.value.shortName)
5554
},
5655
iconsArr() {
57-
return this.$props.value.shortName.toLowerCase().slice(3, this.$props.value.shortName.length - 4).split('-')
56+
return this.$licenseIconsArr(this.$props.value.shortName)
5857
}
5958
}
6059
}

src/components/SelectedLicenseCode.vue

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<script>
4444
import Clipboard from 'clipboard'
4545
import attributionHtml from '@/utils/attributionHtml'
46-
import licenseUrl from '@/utils/licenseUrl'
4746
import AttributionRichText from './AttributionRichText'
4847
4948
export default {
@@ -91,7 +90,7 @@ export default {
9190
},
9291
computed: {
9392
licenseURL() {
94-
return licenseUrl(this.$props.value.shortName)
93+
return this.$licenseUrl(this.$props.value.shortName)
9594
},
9695
activeTab: {
9796
get() { return this.currentTab },

src/components/SelectedLicenseDropdown.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export default {
3939
if (!shortName.includes('BY')) { return 'CC0 1.0 Universal' }
4040
let base = 'Attribution'
4141
if (shortName.includes('NC')) { base += '-NonCommercial' }
42-
if (!shortName.includes('ND') && shortName.includes('SA')) { base += '-ShareAlike' } else if (shortName.includes('ND')) { base += '-NoDerivatives' }
42+
if (!shortName.includes('ND') && shortName.includes('SA')) {
43+
base += '-ShareAlike'
44+
} else if (shortName.includes('ND')) {
45+
base += '-NoDerivatives'
46+
}
4347
base += ' 4.0 International'
4448
return base
4549
}

src/components/SelectedLicenseInfo.vue

+5-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<script>
2121
import LicenseDescription from './LicenseDescription'
2222
import LicenseIconography from './LicenseIconography'
23-
import licenseUrl from '@/utils/licenseUrl'
2423
2524
export default {
2625
name: 'SelectedLicenseInfo',
@@ -44,19 +43,11 @@ export default {
4443
},
4544
computed: {
4645
iconsList() {
47-
const slicedName = this.$props.value.shortName
48-
.slice(3, this.$props.value.shortName.length - 4)
49-
return slicedName.toLowerCase().split('-')
50-
}
51-
},
52-
mounted: function() {
53-
console.log('SelectedLicenseInfo mounted, licenseUrl: ', this.$refs, licenseUrl)
54-
// this.$refs.license_link.href = licenseUrl(this.$props.value.shortName)
55-
},
56-
watch: {
57-
shortLicenseName: function(newVal, oldVal) {
58-
console.log(newVal, oldVal, this.$refs)
59-
// this.$refs.license_link.href = licenseUrl(this.$props.value.shortName)
46+
return this.$licenseIconsArr(this.$props.value.shortName)
47+
},
48+
freeWorkStatus() {
49+
const short = this.$props.value.shortName.toLowerCase()
50+
return !(short.includes('nc') || short.includes('nd'))
6051
}
6152
}
6253
}

src/components/Stepper.vue

+14-21
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default {
8484
},
8585
computed: {
8686
licenseAttributes() {
87-
return this.calculateAttributes(this.$props.value.shortName)
87+
return this.$shortToAttributes(this.$props.value.shortName)
8888
}
8989
},
9090
methods: {
@@ -97,32 +97,27 @@ export default {
9797
personalDetails: this.$props.value.personalDetails
9898
})
9999
},
100-
calculateAttributes(shortName) {
101-
if (shortName.includes('CC0')) {
102-
return { BY: false, ND: false, NC: false, SA: false }
103-
} else {
104-
const by = true
105-
const nd = !!shortName.includes('ND')
106-
const nc = !!shortName.includes('NC')
107-
const sa = !!shortName.includes('SA')
108-
return { BY: by, ND: nd, NC: nc, SA: sa }
109-
}
110-
},
111100
shortLicenseName(attr) {
112101
if (!attr.BY) { return 'CC0 1.0' }
113102
let base = 'CC BY'
114103
if (attr.NC) { base += '-NC' }
115-
if (!attr.ND && attr.SA) { base += '-SA' } // eslint-disable-line brace-style
116-
else if (attr.ND) { base += '-ND' }
104+
if (!attr.ND && attr.SA) {
105+
base += '-SA'
106+
} else if (attr.ND) {
107+
base += '-ND'
108+
}
117109
base += ' 4.0'
118110
return base
119111
},
120112
fullLicenseName(attr) {
121113
if (!attr.BY) { return 'CC0 1.0 Universal' }
122114
let base = 'Attribution'
123115
if (attr.NC) { base += '-NonCommercial' }
124-
if (!attr.ND && attr.SA) { base += '-ShareAlike' } // eslint-disable-line brace-style
125-
else if (attr.ND) { base += '-NoDerivatives' }
116+
if (!attr.ND && attr.SA) {
117+
base += '-ShareAlike'
118+
} else if (attr.ND) {
119+
base += '-NoDerivatives'
120+
}
126121
base += ' 4.0 International'
127122
return base
128123
},
@@ -168,7 +163,6 @@ export default {
168163
font-size:2rem;
169164
path {
170165
fill: black;
171-
/*opacity: 60%;*/
172166
}
173167
}
174168
}
@@ -216,11 +210,10 @@ export default {
216210
&.unselected {
217211
a.step-link {
218212
div.step-marker {
219-
/*background: #0e71de!important;*/
220-
span > svg > path {
221-
opacity: 50% !important;
213+
span > svg > path {
214+
opacity: 50% !important;
215+
}
222216
}
223-
}
224217
div.step-details span.step-title {
225218
font-weight: 400;
226219
opacity: 50%;

src/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Vue from 'vue'
22
import App from './App.vue'
33
import Buefy from 'buefy'
4-
54
import i18n from './i18n'
65
import { library } from '@fortawesome/fontawesome-svg-core'
76
// internal icons
@@ -11,6 +10,7 @@ import {
1110
faEye, faEyeSlash, faCaretDown, faCaretUp, faUpload, faCopy
1211
} from '@fortawesome/free-solid-svg-icons'
1312
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
13+
import LicenseUtilities from './utils/license-utilities'
1414

1515
library.add(faCheck, faCheckCircle, faInfoCircle, faExclamationTriangle, faExclamationCircle,
1616
faArrowUp, faAngleRight, faAngleLeft, faAngleDown,
@@ -21,6 +21,7 @@ Vue.use(Buefy, {
2121
defaultIconComponent: 'vue-fontawesome',
2222
defaultIconPack: 'fas'
2323
})
24+
Vue.use(LicenseUtilities)
2425

2526
new Vue({
2627
i18n,

src/utils/attributionHtml.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66

77
function attributionHtml(form, ccLicenseURL, shortLicenseName) {
88
const baseAssetsPath = 'https://search.creativecommons.org/static/img'
9-
const imgLink = `<a href="${form.workLocation}">"${form.workTitle ? form.workTitle : 'This work'}"</a>`
10-
let creator = ''
11-
if (form.attributeToName && form.attributeToURL) {
12-
creator = `<span> by <a href="${form.attributeToURL}">${form.attributeToName}</a></span>`
13-
} else if (form.attributeToName && !form.attributeToURL) {
14-
creator = `<span> by <span>${form.attributeToName}</span></span>`
15-
}
9+
const workTitle = form.workTitle ? '"form.workTitle"' : 'This work'
10+
const workLink = form.workUrl ? `<a href="${form.workUrl}">${workTitle}</a>` : workTitle
11+
const creator = `<span> by <span>${form.authorName}</span></span>`
1612
const licenseLink = ` is licensed under <a href="${ccLicenseURL}" style="margin-right: 5px;">${shortLicenseName.toUpperCase()}</a>`
1713

1814
let licenseIcons = `<img style="height: inherit;margin-right: 3px;display: inline-block;" src="${baseAssetsPath}/cc_icon.svg" />` // eslint-disable-line global-require, import/no-dynamic-require
@@ -22,8 +18,8 @@ function attributionHtml(form, ccLicenseURL, shortLicenseName) {
2218
).join('')
2319
}
2420

25-
const licenseImgLink = `<a href="${ccLicenseURL}" target="_blank" rel="noopener noreferrer" style="display: inline-block;white-space: none;opacity: .7;margin-top: 2px;margin-left: 3px;height: 22px !important;">${licenseIcons}</a>`
26-
return `<p style="font-size: 0.9rem;font-style: italic;">${imgLink}${creator}${licenseLink}${licenseImgLink}</p>`
21+
const licenseImgLink = `<a href="${ccLicenseURL}" target="_blank" rel="noopener noreferrer" style="display: inline-block;opacity: .7;margin-top: 2px;margin-left: 3px;height: 22px !important;">${licenseIcons}</a>`
22+
return `<p style="font-size: 0.9rem;font-style: italic;">${workLink}${creator}${licenseLink}${licenseImgLink}</p>`
2723
}
2824

2925
export default attributionHtml

src/utils/license-utilities.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const LicenseUtilities = {
2+
3+
install(Vue) {
4+
const defaultLicenseAttributes = {
5+
BY: true,
6+
NC: false,
7+
ND: false,
8+
SA: false
9+
}
10+
11+
Vue.prototype.$shortToAttributes = function(shortLicenseName) {
12+
const short = shortLicenseName.toLowerCase()
13+
if (short.includes('cc0')) {
14+
return { ...defaultLicenseAttributes, by: false }
15+
}
16+
const nc = short.includes('nc')
17+
const nd = short.includes('nd')
18+
const sa = short.includes('sa')
19+
return { ...defaultLicenseAttributes, NC: nc, ND: nd, SA: sa }
20+
}
21+
Vue.prototype.$licenseUrl = function(shortLicenseName) {
22+
// Returns url to license
23+
const short = shortLicenseName.toLowerCase().slice(3, shortLicenseName.length - 4)
24+
return 'https://creativecommons.org/licenses/' + short + '/4.0/?ref=ccchooser'
25+
}
26+
Vue.prototype.$licenseSlug = function(shortLicenseName) {
27+
// Returns lower case slugified string of license name without the version number
28+
return shortLicenseName
29+
.toLowerCase()
30+
.replace(' ', '-')
31+
.slice(0, shortLicenseName.length - 4)
32+
}
33+
Vue.prototype.$licenseIconsArr = function(shortLicenseName) {
34+
return shortLicenseName
35+
.toLowerCase()
36+
.slice(3, shortLicenseName.length - 4)
37+
.split('-')
38+
}
39+
}
40+
}
41+
42+
export default LicenseUtilities

src/utils/licenseUrl.js

-16
This file was deleted.

src/utils/licenseUtils.js

-21
This file was deleted.

0 commit comments

Comments
 (0)