Repository navigation
Expand file tree
/
Copy pathzoteroiteminfo.lua
More file actions
241 lines (224 loc) · 7.07 KB
/
Copy pathzoteroiteminfo.lua
File metadata and controls
241 lines (224 loc) · 7.07 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
--[[
This module provides a way to display item information (adapted from apps/filemanager/filemanagerbookinfo.lua)
--]]
local TextViewer = require("ui/widget/textviewer")
local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local util = require("util")
local _ = require("gettext")
local itemInfo = WidgetContainer:extend{
title = _("Item information"),
props = {
--"itemType",
"title",
"creators",
"bookTitle",
"publicationTitle",
"proceedingsTitle",
"conferenceName",
"volume",
"issue",
"series",
"edition",
"publisher",
"pages",
"date",
"ISBN",
"DOI",
"tags",
--"abstractNote",
},
prop_text = {
itemType = _("Type:"),
title = _("Title:"),
creators = _("Author(s):"),
bookTitle = _("Book title:"),
publicationTitle = _("Publication:"),
proceedingsTitle = _("Proceedings:"),
conferenceName = _("Conference:"),
volume = _("Volume:"),
issue = _("Issue:"),
series = _("Series:"),
edition = _("Edition:"),
publisher = _("Publisher:"),
pages = _("Pages:"),
date = _("Date:"),
ISBN = _("ISBN:"),
language = _("Language:"),
DOI = _("DOI:"),
tags = _("Tags:"),
abstractNote = _("Abstract:"),
},
}
local itemTypeStrings = {
annotation = _("Annotation"),
artwork = _("Artwork"),
attachment = _("Attachment"),
audioRecording = _("Audio Recording"),
bill = _("Bill"),
blogPost = _("Blog Post"),
book = _("Book"),
bookSection = _("Book Section"),
case = _("Case"),
computerProgram = _("Computer Program"),
conferencePaper = _("Conference Paper"),
dictionaryEntry = _("Dictionary Entry"),
document = _("Document"),
email = _("Email"),
encyclopediaArticle = _("Encyclopedia Article"),
film = _("Film"),
forumPost = _("Forum Post"),
hearing = _("Hearing"),
instantMessage = _("Instant Message"),
interview = _("Interview"),
journalArticle = _("Journal Article"),
letter = _("Letter"),
magazineArticle = _("Magazine Article"),
manuscript = _("Manuscript"),
map = _("Map"),
newspaperArticle = _("Newspaper Article"),
note = _("Note"),
patent = _("Patent"),
podcast = _("Podcast"),
preprint = _("Preprint"),
presentation = _("Presentation"),
radioBroadcast = _("Radio Broadcast"),
report = _("Report"),
statute = _("Statute"),
thesis = _("Thesis"),
tvBroadcast = _("TV Broadcast"),
videoRecording = _("Video Recording"),
webpage = _("Webpage"),
dataset = _("Dataset"),
standard = _("Standard");
}
local mimeTypes = {
["application/pdf"] = "pdf",
["application/epub+zip"] = "epub",
["text/html"] = "html" ,
}
-- Format creator list into string
function itemInfo.formatCreators(creators)
if creators[1] ~= nil then
local authors = {}
for _, v in ipairs(creators) do
if v.creatorType == "author" then
table.insert(authors, v.firstName.." "..v.lastName)
end
end
return table.concat(authors, ", ")
end
end
-- Format creator list into string
function itemInfo.formatTags(tagArray)
if tagArray[1] ~= nil then
local tags = {}
for _, v in ipairs(tagArray) do
table.insert(tags, v.tag)
end
return table.concat(tags, ", ")
end
end
-- Shows item information.
function itemInfo:show(itemDetails, attachment_callback)
local itemData = itemDetails.data
local attachments = itemDetails.attachments
self.prop_updated = nil
self.summary_updated = nil
local kv_pairs = {}
-- print("In itemInfo :", itemData["title"])
-- print(#attachments, " attachments")
local type = itemData.itemType
if type then
--print(type, itemTypeStrings[type])
self.title = itemTypeStrings[type] or "Item information"
end
local key_text
local values_lang, callback
local sep = 0 -- To count separators
for _i, prop_key in ipairs(self.props) do
local prop = itemData[prop_key]
if prop == nil or prop == "" then
prop = nil
elseif prop_key == "language" then
-- Get a chance to have title, authors... rendered with alternate
-- glyphs for the book language (e.g. japanese book in chinese UI)
values_lang = prop
elseif prop_key == "creators" then
prop = self.formatCreators(prop)
elseif prop_key == "tags" then
prop = self.formatTags(prop)
end
-- Only add keys if its value has been set
if prop ~= nil then
if prop_key == "tags" then -- Add separator line after the bibliographical entries are complete
-- Separator
table.insert(kv_pairs, "--")
sep = sep + 1
end
key_text = self.prop_text[prop_key]
table.insert(kv_pairs, { key_text, prop,
callback = callback
})
end
end
-- Deal with abstract
local abstract = itemData.abstractNote
if abstract ~= "" then
if sep == 0 then
table.insert(kv_pairs, "--")
sep = sep + 1
end
-- Description may (often in EPUB, but not always) or may not (rarely in PDF) be HTML
-- not sure if this applies to Zotero abstracts; but leave it for now...
abstract = util.htmlToPlainTextIfHtml(abstract)
local callback = function() -- proper text_type in TextViewer
self:showBookProp("abstractNote", abstract)
end
key_text = self.prop_text.abstractNote
table.insert(kv_pairs, { key_text, abstract,
callback = callback, separator = true
})
else
-- Separator
table.insert(kv_pairs, "--")
end
-- Attachments
if #attachments > 0 then
table.insert(kv_pairs, { "Attachents:", "...tap to open..." })
local cb
for i, v in ipairs(attachments) do
key_text = "["..i.."] ("..mimeTypes[v.contentType].."):"
if attachment_callback then
cb = function() attachment_callback(v.key) end
else
print("No cb supplied?")
cb = nil
end
local vtext
if v.syncedVersion == v.version then
vtext = "✓ "..v.title
else
vtext = v.title
end
table.insert(kv_pairs, { key_text, vtext, callback = cb })
end
end
local KeyValuePage = require("ui/widget/keyvaluepage")
self.kvp_widget = KeyValuePage:new{
title = self.title,
value_overflow_align = "right",
kv_pairs = kv_pairs,
values_lang = values_lang,
single_page = true,
}
UIManager:show(self.kvp_widget)
end
function itemInfo:showBookProp(prop_key, prop_text)
UIManager:show(TextViewer:new{
title = self.prop_text[prop_key],
text = prop_text,
text_type = prop_key == "description" and "book_info" or nil,
})
end
return itemInfo