Skip to content

Commit fa03ebf

Browse files
authored
Merge pull request #2704 from FAIRsharing/invalid_links_2699
"Fixed" URL problems #2699.
2 parents 3d879d6 + 73a090d commit fa03ebf

3 files changed

Lines changed: 52 additions & 59 deletions

File tree

src/components/Records/Record/AdditionalInfo/DatasetArray.vue

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,19 @@
1717
fa-question-circle
1818
</v-icon>
1919
</template>
20-
{{ getDescription('head') }}
20+
{{ getDescription("head") }}
2121
</v-tooltip>
2222
<b class="text-h6 text-capitalize">{{ setTitle(cleanString(title)) }}</b>
2323
<div
24-
v-for="(item,index) in currentField"
25-
:key="item.name+'_'+index"
24+
v-for="(item, index) in currentField"
25+
:key="item.name + '_' + index"
2626
>
2727
<!-- URLs -->
2828
<div
2929
v-for="(key, keyindex) in Object.keys(item)"
30-
:key="key+'_'+keyindex"
30+
:key="key + '_' + keyindex"
3131
>
32-
<div
33-
class="d-flex flex-row align-center min-height-40"
34-
>
32+
<div class="d-flex flex-row align-center min-height-40">
3533
<v-tooltip
3634
v-if="getDescription(item[key])"
3735
bottom
@@ -44,52 +42,39 @@
4442
</template>
4543
{{ getDescription(item[key]) }}
4644
</v-tooltip>
47-
<b class="width-200 text-capitalize">{{ setTitle(cleanString(key)) }}</b>
48-
<div
49-
v-if="checkRegex(item[key])"
50-
class="d-flex full-width ml-md-12 ml-13"
51-
>
52-
<!-- See: https://github.com/FAIRsharing/fairsharing.github.io/issues/2021 -->
53-
<a
54-
class="underline-effect"
55-
:href="item[key]"
56-
target="_blank"
57-
>
58-
{{ item[key] }}
59-
</a>
60-
</div>
45+
<b class="width-200 text-capitalize">{{
46+
setTitle(cleanString(key))
47+
}}</b>
48+
<!-- eslint-disable vue/no-v-html -->
6149
<div
62-
v-else
6350
class="d-flex full-width ml-md-12 ml-13"
64-
>
65-
{{ item[key] }}
66-
</div>
51+
v-html="toHyperLink(item[key])"
52+
/>
53+
<!-- eslint-enable vue/no-v-html -->
6754
</div>
6855
</div>
6956

70-
71-
<v-divider v-if="currentField.length-1!==index" />
57+
<v-divider v-if="currentField.length - 1 !== index" />
7258
</div>
7359
</div>
7460
</template>
7561

7662
<script>
77-
import stringUtils from '@/utils/stringUtils'
78-
63+
import stringUtils from "@/utils/stringUtils";
7964
8065
export default {
8166
name: "DatasetArray",
8267
mixins: [stringUtils],
8368
props: {
84-
title: {default: null, type: String},
85-
currentField: {default: () => [], type: Array},
86-
currentKey: {default: null, type: String},
87-
currentTooltips: {default: () => {}, type: Object},
69+
title: { default: null, type: String },
70+
currentField: { default: () => [], type: Array },
71+
currentKey: { default: null, type: String },
72+
currentTooltips: { default: () => {}, type: Object },
8873
},
8974
computed: {
9075
getCurrentKey() {
9176
return this.currentKey;
92-
}
77+
},
9378
},
9479
methods: {
9580
setTitle(title) {
@@ -98,41 +83,39 @@ export default {
9883
"dmp development": "DMP Development",
9984
"updating of dmp": "Updating of DMP",
10085
"mandated dmp creation": "Mandated DMP creation",
101-
"url": "URL"
102-
}
103-
if (titles[title])
104-
return titles[title]
86+
url: "URL",
87+
};
88+
if (titles[title]) return titles[title];
10589
else {
106-
return title
90+
return title;
10791
}
10892
},
10993
getUpdatedTypeTitle() {
11094
switch (this.getCurrentKey) {
11195
case "data_curation":
112-
return "Steps"
96+
return "Steps";
11397
case "data_deposition_condition":
114-
return "Restrictions"
98+
return "Restrictions";
11599
default:
116-
return "Type"
100+
return "Type";
117101
}
118102
},
119-
getUpdatedNameTitle(){
103+
getUpdatedNameTitle() {
120104
switch (this.getCurrentKey) {
121105
case "resource_sustainability":
122-
return "Plan"
106+
return "Plan";
123107
default:
124-
return "Name"
108+
return "Name";
125109
}
126110
},
127111
getDescription(field) {
128112
let _module = this;
129-
if (field === 'head') {
130-
return _module.currentTooltips['description'] || false;
131-
}
132-
else if (_module.currentTooltips['properties'] !== undefined) {
133-
if (_module.currentTooltips['properties'][field] !== undefined) {
134-
if (_module.currentTooltips['properties'][field]['description']) {
135-
return _module.currentTooltips['properties'][field]['description']
113+
if (field === "head") {
114+
return _module.currentTooltips["description"] || false;
115+
} else if (_module.currentTooltips["properties"] !== undefined) {
116+
if (_module.currentTooltips["properties"][field] !== undefined) {
117+
if (_module.currentTooltips["properties"][field]["description"]) {
118+
return _module.currentTooltips["properties"][field]["description"];
136119
}
137120
}
138121
}
@@ -141,14 +124,13 @@ export default {
141124
// This is to see if the string is a URL, for the purpose of hyperlinking any which are found
142125
// in the record's metadata.
143126
checkRegex(string) {
144-
const expression = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
127+
const expression =
128+
/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
145129
const regex = new RegExp(expression);
146130
return string.match(regex);
147-
}
148-
}
149-
}
131+
},
132+
},
133+
};
150134
</script>
151135

152-
<style scoped>
153-
154-
</style>
136+
<style scoped></style>

src/utils/stringUtils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ const stringUtils = {
1414
truncate(str, n) {
1515
return str.length > n ? str.substr(0, n - 1) + "..." : str;
1616
},
17+
toHyperLink(str) {
18+
let pattern1 =
19+
/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
20+
let link = str.replace(pattern1, "<a href='$1'>$1</a>");
21+
22+
return link;
23+
},
1724
},
1825
filters: {
1926
capitalize(str) {

tests/unit/utils/stringUtils.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ describe("stringUtils.js", function(){
3030
expect(stringUtils.filters.pretty('{"this":"that"}')).toBe("\\this\\: \\that\\");
3131
})
3232

33+
it("converts text in strings to urls", () => {
34+
expect(stringUtils.methods.toHyperLink('link to https://sirwilliamhope.org')).toBe("link to <a href='https://sirwilliamhope.org'>https://sirwilliamhope.org</a>");
35+
})
36+
3337
})

0 commit comments

Comments
 (0)