-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
188 lines (177 loc) · 6.47 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
'use strict'
const AuthorHelper = require('./helpers/AuthorHelper')
const DescriptionHelper = require('./helpers/DescriptionHelper')
const DivaLinkHelper = require('./helpers/DivaLinkHelper')
const filters = require('./helpers/filters')
const log = require('@kth/log')
const pubUtil = require('./helpers/publicationUtil')
module.exports = {
render: _render,
formatPublications: _formatPublications,
filterList: pubUtil.filterList,
groupPublications: _groupPublications,
}
// This function is primarily used to get a formatted output for Cortina
function _render(publications) {
return publications.reduce(function (str, item, index) {
return (
str +
`
<div class="row publicationRow">
<div class="col-md-1 col-xs-2 publicationNr">
<span class="pubNr">[${index + 1}]</span>
</div>
<div class="col-md-10 col-xs-8 publicationInfo">
<span>${item.formattedAuthors}</span>
<a href="${item.formattedLink}" target="_blank" rel="noopener noreferrer"><span>${
item.formattedLinkText
}</span></a>
<span>${item.formattedDescription}</span>
</div>
</div>`
)
}, '')
}
function _formatPublications(data, style, lang) {
var i = 1
var pubs
if (Array.isArray(data)) {
pubs = data.map((item) => {
var obj = _formatSinglePublication(item, lang, style)
obj.index = ++i
return obj
})
} else {
pubs = _formatSinglePublication(data, lang, style)
}
return pubs
}
function _formatSinglePublication(publ, lang, style) {
publ.formattedAuthors = AuthorHelper.getAuthors(publ.publicationTypeCode, publ, lang, style)
publ.formattedLink = DivaLinkHelper.getLinkUrl(publ.publicationTypeCode, publ)
publ.formattedLinkText = DivaLinkHelper.getLinkText(publ.publicationTypeCode, publ, style)
publ.formattedDescription = DescriptionHelper.getDescription(publ.publicationTypeCode, publ, lang, style)
if (!publ.formattedDescription.endsWith('.')) {
publ.formattedDescription = publ.formattedDescription + '.'
}
return publ
}
// This function repacks a list of publications into an object with several sublists of publications of the same type
function _groupPublications(publs) {
var obj = {}
obj.refereedArticles = []
obj.refereedConferencePapers = []
obj.refereedBooks = []
obj.refereedChapters = []
obj.refereedOthers = []
obj.temporaryList = [] // temporary list
obj.scienceArticles = []
obj.scienceConferencePapers = []
obj.scienceBooks = []
obj.scienceChapters = []
obj.scienceThesis = []
obj.scienceReports = []
obj.scienceCollections = []
obj.scienceConferenceProceedings = []
obj.scienceOthers = []
obj.patents = []
obj.pendingPatents = []
obj.otherArticles = []
obj.otherConferencePapers = []
obj.otherBooks = []
obj.otherChapters = []
obj.otherConferenceProceedings = []
obj.otherReports = []
obj.otherCollections = []
obj.otherOthers = []
publs.map((publication) => {
if (filters.isRefereedArticle(publication)) {
obj.refereedArticles.push(publication)
} else if (filters.isRefereedConferencePaper(publication)) {
obj.refereedConferencePapers.push(publication)
} else if (filters.isRefereedChapter(publication)) {
obj.refereedChapters.push(publication)
} else if (filters.isRefereedBook(publication)) {
obj.refereedBooks.push(publication)
} else if (filters.isRefereedOthers(publication)) {
obj.refereedOthers.push(publication)
} else if (filters.isScienceArticle(publication)) {
obj.scienceArticles.push(publication)
} else if (filters.isScienceConferencePaper(publication)) {
obj.scienceConferencePapers.push(publication)
} else if (filters.isScienceChapter(publication)) {
obj.scienceChapters.push(publication)
} else if (filters.isScienceBook(publication)) {
obj.scienceBooks.push(publication)
} else if (filters.isScienceOthers(publication)) {
obj.scienceOthers.push(publication)
} else if (filters.isScienceThesis(publication)) {
obj.scienceThesis.push(publication)
} else if (filters.isScienceReport(publication)) {
obj.scienceReports.push(publication)
} else if (filters.isScienceConferenceProceeding(publication)) {
obj.scienceConferenceProceedings.push(publication)
} else if (filters.isScienceCollection(publication)) {
obj.scienceCollections.push(publication)
} else if (filters.isPatent(publication)) {
obj.patents.push(publication)
} else if (filters.isPendingPatent(publication)) {
obj.pendingPatents.push(publication)
// All publications marked as other is placed in science articles list.
} else if (filters.isOtherArticle(publication)) {
obj.scienceArticles.push(publication)
} else if (filters.isOtherConferencePaper(publication)) {
obj.scienceConferencePapers.push(publication)
} else if (filters.isOtherBook(publication)) {
obj.scienceBooks.push(publication)
} else if (filters.isOtherChapter(publication)) {
obj.scienceChapters.push(publication)
} else if (filters.isOtherConferenceProceeding(publication)) {
obj.scienceConferenceProceedings.push(publication)
} else if (filters.isOtherReport(publication)) {
obj.scienceReports.push(publication)
} else if (filters.isOtherCollection(publication)) {
obj.scienceCollections.push(publication)
} else if (filters.isOtherOther(publication)) {
obj.scienceOthers.push(publication)
} else if (filters.isManuscript(publication)) {
obj.scienceOthers.push(publication)
} else {
log.debug(
'Publication is not added to any list: ' +
publication.title +
' publicationTypeCode=' +
publication.publicationTypeCode +
' publicationSubTypeCode=' +
publication.publicationSubTypeCode +
' contentTypeCode=' +
publication.contentTypeCode +
' publicationStatus=' +
publication.publicationStatus
)
}
})
sortFilteredList(obj)
return obj
}
function sortFilteredList(filteredList) {
for (let listName in filteredList) {
if (filteredList.hasOwnProperty(listName) && Array.isArray(filteredList[listName])) {
var list = filteredList[listName]
list.sort(sortPublicationsByDateTitle)
}
}
}
function sortPublicationsByDateTitle(item1, item2) {
if (item1.dateIssued > item2.dateIssued) {
return -1
} else if (item1.dateIssued < item2.dateIssued) {
return 1
} else {
if (item1.title > item2.title) {
return 1
} else {
return -1
}
}
}