Fix primary item types not appearing in More menu when not in MRU list
Regression in 1c366de54
This commit is contained in:
parent
5e98b9c533
commit
5e9636089d
2 changed files with 50 additions and 26 deletions
|
@ -352,14 +352,10 @@ Zotero.ItemTypes = new function() {
|
||||||
this._hasCustom = true;
|
this._hasCustom = true;
|
||||||
|
|
||||||
var _primaryTypeNames = ['book', 'bookSection', 'journalArticle', 'newspaperArticle', 'document'];
|
var _primaryTypeNames = ['book', 'bookSection', 'journalArticle', 'newspaperArticle', 'document'];
|
||||||
var _primaryTypes;
|
|
||||||
var _secondaryTypes;
|
|
||||||
// Item types hidden from New Item menu
|
// Item types hidden from New Item menu
|
||||||
var _hiddenTypeNames = ['webpage', 'attachment', 'note', 'annotation'];
|
var _hiddenTypeNames = ['webpage', 'attachment', 'note', 'annotation'];
|
||||||
var _hiddenTypes;
|
var _hiddenTypes;
|
||||||
|
|
||||||
var _numPrimary = 5;
|
|
||||||
|
|
||||||
var _customImages = {};
|
var _customImages = {};
|
||||||
var _customLabels = {};
|
var _customLabels = {};
|
||||||
|
|
||||||
|
@ -367,15 +363,6 @@ Zotero.ItemTypes = new function() {
|
||||||
this.init = Zotero.Promise.coroutine(function* () {
|
this.init = Zotero.Promise.coroutine(function* () {
|
||||||
yield this.constructor.prototype.init.apply(this);
|
yield this.constructor.prototype.init.apply(this);
|
||||||
|
|
||||||
_primaryTypes = yield this._getTypesFromDB(
|
|
||||||
`WHERE typeName IN ('${_primaryTypeNames.join("', '")}')`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Secondary types
|
|
||||||
_secondaryTypes = yield this._getTypesFromDB(
|
|
||||||
`WHERE typeName NOT IN ('${_primaryTypeNames.concat(_hiddenTypeNames).join("', '")}')`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Hidden types
|
// Hidden types
|
||||||
_hiddenTypes = yield this._getTypesFromDB(
|
_hiddenTypes = yield this._getTypesFromDB(
|
||||||
`WHERE typeName IN ('${_hiddenTypeNames.join("', '")}')`
|
`WHERE typeName IN ('${_hiddenTypeNames.join("', '")}')`
|
||||||
|
@ -394,44 +381,41 @@ Zotero.ItemTypes = new function() {
|
||||||
|
|
||||||
|
|
||||||
this.getPrimaryTypes = function () {
|
this.getPrimaryTypes = function () {
|
||||||
if (!_primaryTypes) {
|
var names = _primaryTypeNames.concat();
|
||||||
throw new Zotero.Exception.UnloadedDataException("Primary item type data not yet loaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
var mru = Zotero.Prefs.get('newItemTypeMRU');
|
var mru = Zotero.Prefs.get('newItemTypeMRU');
|
||||||
if (mru && mru.length) {
|
if (mru && mru.length) {
|
||||||
// Get types from the MRU list
|
// Get types from the MRU list
|
||||||
mru = new Set(
|
mru = new Set(
|
||||||
mru.split(',')
|
mru.split(',')
|
||||||
.slice(0, _numPrimary)
|
.slice(0, _primaryTypeNames.length)
|
||||||
.map(name => this.getName(name))
|
.map(name => this.getName(name))
|
||||||
// Ignore hidden item types and 'webpage'
|
// Ignore hidden item types and 'webpage'
|
||||||
.filter(name => name && !_hiddenTypeNames.concat('webpage').includes(name))
|
.filter(name => name && !_hiddenTypeNames.concat('webpage').includes(name))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add types from defaults until we reach our limit
|
// Add types from defaults until we reach our limit
|
||||||
for (let i = 0; i < _primaryTypes.length && mru.size < _numPrimary; i++) {
|
for (let name of _primaryTypeNames) {
|
||||||
mru.add(_primaryTypes[i].name);
|
if (mru.size >= _primaryTypeNames.length) break;
|
||||||
|
mru.add(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(mru).map(name => ({ id: this.getID(name), name }));
|
names = Array.from(mru);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _primaryTypes;
|
return names.map(name => ({ id: this.getID(name), name }));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getSecondaryTypes = function () {
|
this.getSecondaryTypes = function () {
|
||||||
if (!_secondaryTypes) {
|
var namesToRemove = new Set(this.getPrimaryTypes().map(x => x.name).concat(_hiddenTypeNames));
|
||||||
throw new Zotero.Exception.UnloadedDataException("Secondary item type data not yet loaded");
|
return this._typesArray.filter(x => !namesToRemove.has(x.name));
|
||||||
}
|
|
||||||
return _secondaryTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getHiddenTypes = function () {
|
this.getHiddenTypes = function () {
|
||||||
if (!_hiddenTypes) {
|
if (!_hiddenTypes) {
|
||||||
throw new Zotero.Exception.UnloadedDataException("Hidden item type data not yet loaded");
|
throw new Zotero.Exception.UnloadedDataException("Hidden item type data not yet loaded");
|
||||||
}
|
}
|
||||||
return _hiddenTypes;
|
return _hiddenTypes.concat();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getLocalizedString = function (idOrName) {
|
this.getLocalizedString = function (idOrName) {
|
||||||
|
|
|
@ -1,4 +1,44 @@
|
||||||
describe("Zotero.CachedTypes", function() {
|
describe("Zotero.CachedTypes", function() {
|
||||||
|
describe("Zotero.ItemTypes", function () {
|
||||||
|
describe("#getPrimaryTypes()", function () {
|
||||||
|
it("should return an array of objects with 'id' and 'name' properties", function () {
|
||||||
|
var types = Zotero.ItemTypes.getPrimaryTypes();
|
||||||
|
assert.lengthOf(types, 5);
|
||||||
|
for (let type of types) {
|
||||||
|
assert.property(type, 'id');
|
||||||
|
assert.property(type, 'name');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't include 'webpage'", function () {
|
||||||
|
assert.notInclude(Zotero.ItemTypes.getPrimaryTypes().map(x => x.name), 'webpage');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't include 'attachment'", function () {
|
||||||
|
assert.notInclude(Zotero.ItemTypes.getPrimaryTypes().map(x => x.name), 'attachment');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#getSecondaryTypes()", function () {
|
||||||
|
it("should return an array of objects with 'id' and 'name' properties", function () {
|
||||||
|
var types = Zotero.ItemTypes.getSecondaryTypes();
|
||||||
|
assert.isAbove(types.length, 5);
|
||||||
|
for (let type of types) {
|
||||||
|
assert.property(type, 'id');
|
||||||
|
assert.property(type, 'name');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't include 'webpage'", function () {
|
||||||
|
assert.notInclude(Zotero.ItemTypes.getSecondaryTypes().map(x => x.name), 'webpage');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't include 'attachment'", function () {
|
||||||
|
assert.notInclude(Zotero.ItemTypes.getPrimaryTypes().map(x => x.name), 'attachment');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Zotero.CharacterSets", function() {
|
describe("Zotero.CharacterSets", function() {
|
||||||
describe("#toCanonical()", function() {
|
describe("#toCanonical()", function() {
|
||||||
let toCanon = Zotero.CharacterSets.toCanonical.bind(Zotero.CharacterSets);
|
let toCanon = Zotero.CharacterSets.toCanonical.bind(Zotero.CharacterSets);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue