@abi-software/flatmapvuer 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,195 +1,195 @@
1
- <template>
2
- <div class="pubmed-container">
3
- <div v-loading="loading.response" class="block">
4
- <div class="attribute-title">Pubmed Resources</div>
5
- <br/>
6
- <el-carousel
7
- :autoplay="false"
8
- indicator-position="outside"
9
- height="250px" width="200px"
10
- >
11
- <el-carousel-item v-for="(pub, i) in pubmeds" :key="i">
12
- <div class="attribute-content">
13
- <div v-html="pub.html"/>
14
- <el-link :href="pub.url" :underline="false" class="el-link" target="_blank">{{pub.url}}</el-link>
15
- </div>
16
- </el-carousel-item>
17
- </el-carousel>
18
- </div>
19
- </div>
20
- </template>
21
-
22
-
23
- <script>
24
- /* eslint-disable no-alert, no-console */
25
- import Vue from "vue";
26
- import {
27
- Link,
28
- Carousel,
29
- CarouselItem,
30
- Button
31
- } from "element-ui";
32
- import lang from "element-ui/lib/locale/lang/en";
33
- import locale from "element-ui/lib/locale";
34
- locale.use(lang);
35
- Vue.use(Link);
36
- Vue.use(Carousel);
37
- Vue.use(CarouselItem);
38
- Vue.use(Button);
39
-
40
-
41
- export default {
42
- name: "Tooltip",
43
- props: {
44
- entry: {
45
- type: Object,
46
- default: () => {}
47
- },
48
- },
49
- watch: {
50
- 'entry.featureId': function (val){
51
- this.flatmapQuery(val).then(pb => this.pubmeds = pb)
52
- },
53
- 'entry.featureIds': {
54
- handler: function(ids) {
55
- this.flatmapQuery(ids)
56
- }
57
- }
58
- },
59
- inject: ['flatmapAPI'],
60
- data: function() {
61
- return {
62
- data: {},
63
- pubmeds: [],
64
- pubmedIds: [],
65
- loading: {response: true, publications: true}
66
- };
67
- },
68
- mounted: function() {
69
- if (this.entry.featureIds)
70
- this.flatmapQuery(this.entry.featureIds)
71
- },
72
- methods: {
73
- stripPMIDPrefix: function (pubmedId){
74
- return pubmedId.split(':')[1]
75
- },
76
- titleFromPubmed: function (pubmedId){
77
- return new Promise((resolve) => {
78
- fetch(`https://api.ncbi.nlm.nih.gov/lit/ctxp/v1/pubmed/?format=citation&contenttype=json&id=${pubmedId}`)
79
- .then(response => response.json())
80
- .then(data => {
81
- resolve(data.apa.format)
82
- })
83
- .catch((error) => {
84
- console.error('Error:', error)
85
- });
86
- })
87
- },
88
- splitLink(bibliographyString){
89
- let split = bibliographyString.split('https')
90
- return [split[0], 'https' + split[1]]
91
- },
92
- buildPubmedSqlStatement: function(keastIds) {
93
- let sql = 'select distinct publication from publications where entity in ('
94
- if (keastIds.length === 1) {
95
- sql += `'${keastIds[0]}')`
96
- } else if (keastIds.length > 1) {
97
- for (let i in keastIds) {
98
- sql += `'${keastIds[i]}'${i >= keastIds.length - 1 ? ')' : ','} `
99
- }
100
- }
101
- return sql
102
- },
103
- flatmapQuery: function(keastIds){
104
- if(!keastIds || keastIds.length === 0) return
105
- this.pubmeds = []
106
- this.loading.response = true
107
-
108
- // fetch pubmed publications for the given ids
109
- const data = { sql: this.buildPubmedSqlStatement(keastIds)};
110
- fetch(`${this.flatmapAPI}knowledge/query/`, {
111
- method: 'POST',
112
- headers: {
113
- 'Content-Type': 'application/json',
114
- },
115
- body: JSON.stringify(data),
116
- })
117
- .then(response => response.json())
118
- .then(data => {
119
- this.responseData = data
120
- this.loading.response = false
121
-
122
- // create links for each pubmedId
123
- data.values.forEach(identifier => {
124
- let ids = this.stripPMIDPrefix(identifier[0])
125
- this.titleFromPubmed(ids).then( bib=>{
126
- let [html, link] = this.splitLink(bib)
127
- this.pubmeds.push({identifier: identifier[0] , html: html, url: link})
128
- })
129
- });
130
- this.$emit('pubmedSearchUrl', this.pubmedSearchUrl(data.values.map(id=>this.stripPMIDPrefix(id[0]))))
131
- })
132
- .catch((error) => {
133
- console.error('Error:', error)
134
- })
135
- },
136
- pubmedSearchUrl: function(ids) {
137
- let url = 'https://pubmed.ncbi.nlm.nih.gov/?'
138
- let params = new URLSearchParams()
139
- params.append('term', ids)
140
- return url + params.toString()
141
- }
142
- }
143
- };
144
- </script>
145
-
146
- <style scoped lang="scss">
147
- @import "~element-ui/packages/theme-chalk/src/link";
148
- @import "~element-ui/packages/theme-chalk/src/carousel";
149
- @import "~element-ui/packages/theme-chalk/src/carousel-item";
150
-
151
- .attribute-title{
152
- font-size: 16px;
153
- font-weight: 600;
154
- /* font-weight: bold; */
155
- text-transform: uppercase;
156
- }
157
-
158
- .attribute-content{
159
- font-size: 14px;
160
- font-weight: 400;
161
- }
162
-
163
- .el-link {
164
- color: $app-primary-color;
165
- text-decoration: none;
166
- word-wrap: break-word;
167
- &:hover, &:focus{
168
- color: $app-primary-color;
169
- text-decoration: underline;
170
- }
171
- }
172
-
173
- ::v-deep .el-carousel__button {
174
- background-color: $app-primary-color;
175
- }
176
-
177
- .button {
178
- margin-left: 0px !important;
179
- margin-top: 0px !important;
180
- font-size: 14px !important;
181
- background-color: $app-primary-color;
182
- color: #fff;
183
- &:hover{
184
- color: #fff !important;
185
- background: #ac76c5 !important;
186
- border: 1px solid #ac76c5 !important;
187
- }
188
- &+.button {
189
- margin-top: 10px !important;
190
- background-color: $app-primary-color;
191
- color: #fff;
192
- }
193
- }
194
-
1
+ <template>
2
+ <div class="pubmed-container">
3
+ <div v-loading="loading.response" class="block">
4
+ <div class="attribute-title">Pubmed Resources</div>
5
+ <br/>
6
+ <el-carousel
7
+ :autoplay="false"
8
+ indicator-position="outside"
9
+ height="250px" width="200px"
10
+ >
11
+ <el-carousel-item v-for="(pub, i) in pubmeds" :key="i">
12
+ <div class="attribute-content">
13
+ <div v-html="pub.html"/>
14
+ <el-link :href="pub.url" :underline="false" class="el-link" target="_blank">{{pub.url}}</el-link>
15
+ </div>
16
+ </el-carousel-item>
17
+ </el-carousel>
18
+ </div>
19
+ </div>
20
+ </template>
21
+
22
+
23
+ <script>
24
+ /* eslint-disable no-alert, no-console */
25
+ import Vue from "vue";
26
+ import {
27
+ Link,
28
+ Carousel,
29
+ CarouselItem,
30
+ Button
31
+ } from "element-ui";
32
+ import lang from "element-ui/lib/locale/lang/en";
33
+ import locale from "element-ui/lib/locale";
34
+ locale.use(lang);
35
+ Vue.use(Link);
36
+ Vue.use(Carousel);
37
+ Vue.use(CarouselItem);
38
+ Vue.use(Button);
39
+
40
+
41
+ export default {
42
+ name: "Tooltip",
43
+ props: {
44
+ entry: {
45
+ type: Object,
46
+ default: () => {}
47
+ },
48
+ },
49
+ watch: {
50
+ 'entry.featureId': function (val){
51
+ this.flatmapQuery(val).then(pb => this.pubmeds = pb)
52
+ },
53
+ 'entry.featureIds': {
54
+ handler: function(ids) {
55
+ this.flatmapQuery(ids)
56
+ }
57
+ }
58
+ },
59
+ inject: ['flatmapAPI'],
60
+ data: function() {
61
+ return {
62
+ data: {},
63
+ pubmeds: [],
64
+ pubmedIds: [],
65
+ loading: {response: true, publications: true}
66
+ };
67
+ },
68
+ mounted: function() {
69
+ if (this.entry.featureIds)
70
+ this.flatmapQuery(this.entry.featureIds)
71
+ },
72
+ methods: {
73
+ stripPMIDPrefix: function (pubmedId){
74
+ return pubmedId.split(':')[1]
75
+ },
76
+ titleFromPubmed: function (pubmedId){
77
+ return new Promise((resolve) => {
78
+ fetch(`https://api.ncbi.nlm.nih.gov/lit/ctxp/v1/pubmed/?format=citation&contenttype=json&id=${pubmedId}`)
79
+ .then(response => response.json())
80
+ .then(data => {
81
+ resolve(data.apa.format)
82
+ })
83
+ .catch((error) => {
84
+ console.error('Error:', error)
85
+ });
86
+ })
87
+ },
88
+ splitLink(bibliographyString){
89
+ let split = bibliographyString.split('https')
90
+ return [split[0], 'https' + split[1]]
91
+ },
92
+ buildPubmedSqlStatement: function(keastIds) {
93
+ let sql = 'select distinct publication from publications where entity in ('
94
+ if (keastIds.length === 1) {
95
+ sql += `'${keastIds[0]}')`
96
+ } else if (keastIds.length > 1) {
97
+ for (let i in keastIds) {
98
+ sql += `'${keastIds[i]}'${i >= keastIds.length - 1 ? ')' : ','} `
99
+ }
100
+ }
101
+ return sql
102
+ },
103
+ flatmapQuery: function(keastIds){
104
+ if(!keastIds || keastIds.length === 0) return
105
+ this.pubmeds = []
106
+ this.loading.response = true
107
+
108
+ // fetch pubmed publications for the given ids
109
+ const data = { sql: this.buildPubmedSqlStatement(keastIds)};
110
+ fetch(`${this.flatmapAPI}knowledge/query/`, {
111
+ method: 'POST',
112
+ headers: {
113
+ 'Content-Type': 'application/json',
114
+ },
115
+ body: JSON.stringify(data),
116
+ })
117
+ .then(response => response.json())
118
+ .then(data => {
119
+ this.responseData = data
120
+ this.loading.response = false
121
+
122
+ // create links for each pubmedId
123
+ data.values.forEach(identifier => {
124
+ let ids = this.stripPMIDPrefix(identifier[0])
125
+ this.titleFromPubmed(ids).then( bib=>{
126
+ let [html, link] = this.splitLink(bib)
127
+ this.pubmeds.push({identifier: identifier[0] , html: html, url: link})
128
+ })
129
+ });
130
+ this.$emit('pubmedSearchUrl', this.pubmedSearchUrl(data.values.map(id=>this.stripPMIDPrefix(id[0]))))
131
+ })
132
+ .catch((error) => {
133
+ console.error('Error:', error)
134
+ })
135
+ },
136
+ pubmedSearchUrl: function(ids) {
137
+ let url = 'https://pubmed.ncbi.nlm.nih.gov/?'
138
+ let params = new URLSearchParams()
139
+ params.append('term', ids)
140
+ return url + params.toString()
141
+ }
142
+ }
143
+ };
144
+ </script>
145
+
146
+ <style scoped lang="scss">
147
+ @import "~element-ui/packages/theme-chalk/src/link";
148
+ @import "~element-ui/packages/theme-chalk/src/carousel";
149
+ @import "~element-ui/packages/theme-chalk/src/carousel-item";
150
+
151
+ .attribute-title{
152
+ font-size: 16px;
153
+ font-weight: 600;
154
+ /* font-weight: bold; */
155
+ text-transform: uppercase;
156
+ }
157
+
158
+ .attribute-content{
159
+ font-size: 14px;
160
+ font-weight: 400;
161
+ }
162
+
163
+ .el-link {
164
+ color: $app-primary-color;
165
+ text-decoration: none;
166
+ word-wrap: break-word;
167
+ &:hover, &:focus{
168
+ color: $app-primary-color;
169
+ text-decoration: underline;
170
+ }
171
+ }
172
+
173
+ ::v-deep .el-carousel__button {
174
+ background-color: $app-primary-color;
175
+ }
176
+
177
+ .button {
178
+ margin-left: 0px !important;
179
+ margin-top: 0px !important;
180
+ font-size: 14px !important;
181
+ background-color: $app-primary-color;
182
+ color: #fff;
183
+ &:hover{
184
+ color: #fff !important;
185
+ background: #ac76c5 !important;
186
+ border: 1px solid #ac76c5 !important;
187
+ }
188
+ &+.button {
189
+ margin-top: 10px !important;
190
+ background-color: $app-primary-color;
191
+ color: #fff;
192
+ }
193
+ }
194
+
195
195
  </style>