Skip to content

Commit

Permalink
auto-export is here, folks!
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Apr 18, 2015
1 parent 6d8f0a1 commit 9e0818f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions chrome/content/zotero-better-bibtex/cache.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Zotero.BetterBibTeX.auto = {}

Zotero.BetterBibTeX.auto.add = (collection, path, options) ->
Zotero.BetterBibTeX.auto.add = (collectionID, path, options) ->
eo = Zotero.BetterBibTeX.cache.exportOptions(options)
Zotero.DB.query("insert or replace into betterbibtex.autoexport (collection, path, exportoptions, includeChildCollections, status)
values (?, ?, ?, ?, 'done')", [state.collection.id, state.target, eo, "#{!!@recursive()}"])
Zotero.DB.query("insert or replace into betterbibtex.autoexport (collection, path, exportOptions, exportedRecursively, status)
values (?, ?, ?, ?, 'done')", [collectionID, path, eo, "#{!!@recursive()}"])
return

Zotero.BetterBibTeX.auto.recursive = ->
Expand Down
12 changes: 6 additions & 6 deletions chrome/content/zotero-better-bibtex/preferences.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ Zotero.BetterBibTeX.pref.update = ->
selectedExport = -1
for ae in Zotero.DB.query("select * from betterbibtex.autoexport order by path")
selectedExport = 0
Zotero.BetterBibTeX.log(':::ae', @clone(ae))
Zotero.BetterBibTeX.log(':::ae', Zotero.BetterBibTeX.pref.clone(ae))
if refill
itemNode = document.createElement('listitem')
itemNode.setAttribute('value', ae.id)
itemNode.setAttribute('label', "collection_name -> #{ae.path.replace(/^.*[\\\/]/, '')}")
itemNode.setAttribute('class', "export-state-#{if Zotero.BetterBibTeX.auto.running == ae.id then 'running' else ae.status}")
itemNode.setAttribute('tooltiptext', "#{@collectionPath(ae.collection_id)} -> #{ae.path}")
itemNode.setAttribute('tooltiptext', "#{@collectionPath(ae.collection)} -> #{ae.path}")
exportlist.appendChild(itemNode)
if selectedExport >= 0
@autoexport.selected(selectedIndex)
Expand All @@ -133,11 +133,11 @@ Zotero.BetterBibTeX.pref.autoexport =
document.getElementById('auto-export-mark').setAttribute('disabled', false)

ae = Zotero.DB.rowQuery('select * from betterbibtex.autoexport ae join betterbibtex.exportoptions eo on ae.exportoptions = eo.id where ae.id = ?', [selectedItem.getAttribute('value')])
Zotero.BetterBibTeX.log(':::selected', @clone(ae))
Zotero.BetterBibTeX.log(':::selected', Zotero.BetterBibTeX.pref.clone(ae))

@display('id-better-bibtex-preferences-auto-export-collection', 'ae.collection_name')
@display('id-better-bibtex-preferences-auto-export-target', ae.path)
@display('id-better-bibtex-preferences-auto-export-translator', 'ae.translatorID')
Zotero.BetterBibTeX.pref.display('id-better-bibtex-preferences-auto-export-collection', 'ae.collection_name')
Zotero.BetterBibTeX.pref.display('id-better-bibtex-preferences-auto-export-target', ae.path)
Zotero.BetterBibTeX.pref.display('id-better-bibtex-preferences-auto-export-translator', 'ae.translatorID')
document.getElementById('id-better-bibtex-preferences-auto-export-auto-abbrev').checked = (ae.useJournalAbbreviation == 'true')
document.getElementById('id-better-bibtex-preferences-auto-export-notes').checked = (ae.exportNotes == 'true')
document.getElementById('id-better-bibtex-preferences-auto-export-preserve-bibvars').checked = (ae.preserveBibTeXVariables == 'true')
Expand Down
2 changes: 1 addition & 1 deletion chrome/content/zotero-better-bibtex/preferences.xul
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
<checkbox id="id-better-bibtex-preferences-auto-export-notes" label="&zotero.better-bibtex.auto-export.notes;" disabled="true"/>
</row>
<row>
<checkbox id="id-better-bibtex-preferences-auto-export-id-better-bibtex-preferences-auto-export-preserve-bibvars" label="&zotero.better-bibtex.auto-export.preserveBibTeXVariables;" disabled="true"/>
<checkbox id="id-better-bibtex-preferences-auto-export-preserve-bibvars" label="&zotero.better-bibtex.auto-export.preserveBibTeXVariables;" disabled="true"/>
</row>
</rows>
</grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Zotero.BetterBibTeX.updateSchema = ->
columns = Object.create(null)
for table in ['keys', 'autoexport', 'exportoptions']
columns[table] = @SQLColumns(table)
Zotero.DB.query("drop table if exists betterbibtex._#{table}_")
Zotero.DB.query("alter table betterbibtex.#{table} rename to _#{table}_") if columns[table]
Zotero.DB.query('drop table if exists betterbibtex.keys2')
Zotero.DB.query('drop table if exists betterbibtex.cache')
Expand Down Expand Up @@ -543,14 +544,14 @@ Zotero.BetterBibTeX.itemAdded = {

unless collections.length == 0 || Zotero.BetterBibTeX.pref.get('autoExport') == 'disabled'
collections = Zotero.BetterBibTeX.withParentCollections(collections)
Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection_id in #{Zotero.BetterBibTeX.SQLSet(collections)}")
Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection in #{Zotero.BetterBibTeX.SQLSet(collections)}")
Zotero.BetterBibTeX.auto.process('collectionChanged')

return
}

Zotero.BetterBibTeX.collectionChanged = notify: (event, type, ids, extraData) ->
Zotero.DB.query("delete from betterbibtex.autoexport where collection_id in #{Zotero.BetterBibTeX.SQLSet(extraData)}") if event == 'delete' && extraData.length > 0
Zotero.DB.query("delete from betterbibtex.autoexport where collection in #{Zotero.BetterBibTeX.SQLSet(extraData)}") if event == 'delete' && extraData.length > 0
return

Zotero.BetterBibTeX.SQLSet = (values) -> '(' + ('' + v for v in values).join(', ') + ')'
Expand Down Expand Up @@ -581,7 +582,7 @@ Zotero.BetterBibTeX.itemChanged = notify: (event, type, ids, extraData) ->
collections = Zotero.Collections.getCollectionsContainingItems(ids, true)
unless collections.length == 0 || Zotero.BetterBibTeX.pref.get('autoExport') == 'disabled'
collections = Zotero.BetterBibTeX.withParentCollections(collections)
Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection_id in #{Zotero.BetterBibTeX.SQLSet(collections)}")
Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection in #{Zotero.BetterBibTeX.SQLSet(collections)}")
Zotero.BetterBibTeX.auto.process('itemChanged')

return
Expand Down

0 comments on commit 9e0818f

Please sign in to comment.