forked from 0x2620/pandora
fix getItem and getSpan
This commit is contained in:
parent
dccd09a10f
commit
9bbd6c8a68
1 changed files with 22 additions and 9 deletions
|
@ -719,7 +719,8 @@ pandora.getItem = function(state, str, callback) {
|
||||||
: 'timesaccessed';
|
: 'timesaccessed';
|
||||||
pandora.api.get({id: str, keys: ['id']}, function(result) {
|
pandora.api.get({id: str, keys: ['id']}, function(result) {
|
||||||
if (result.status.code == 200) {
|
if (result.status.code == 200) {
|
||||||
callback(result.data.id);
|
state.item = result.data.id;
|
||||||
|
callback();
|
||||||
} else {
|
} else {
|
||||||
pandora.api.find({
|
pandora.api.find({
|
||||||
query: {
|
query: {
|
||||||
|
@ -730,7 +731,6 @@ pandora.getItem = function(state, str, callback) {
|
||||||
range: [0, 100],
|
range: [0, 100],
|
||||||
keys: ['id', 'title', sortKey]
|
keys: ['id', 'title', sortKey]
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
var id = '';
|
|
||||||
if (result.data.items.length) {
|
if (result.data.items.length) {
|
||||||
var items = Ox.filter(Ox.map(result.data.items, function(item) {
|
var items = Ox.filter(Ox.map(result.data.items, function(item) {
|
||||||
// test if exact match or word match
|
// test if exact match or word match
|
||||||
|
@ -740,20 +740,31 @@ pandora.getItem = function(state, str, callback) {
|
||||||
// fixme: remove the (...|| 0) check once the backend sends correct data
|
// fixme: remove the (...|| 0) check once the backend sends correct data
|
||||||
}));
|
}));
|
||||||
if (items.length) {
|
if (items.length) {
|
||||||
id = items.sort(function(a, b) {
|
state.item = items.sort(function(a, b) {
|
||||||
return b.sort - a.sort;
|
return b.sort - a.sort;
|
||||||
})[0].id;
|
})[0].id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback(id);
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (type == 'text') {
|
} else if (state.type == 'texts') {
|
||||||
// /number is page for pdf or percent for html
|
pandora.api.getText({id: str}, function(result) {
|
||||||
callback(str.replace(/\/\d+$/, ''));
|
if (result.status.code == 200) {
|
||||||
|
state.item = result.data.id;
|
||||||
|
callback();
|
||||||
|
} else {
|
||||||
|
// FIXME: add findText call here?
|
||||||
|
// FIXME: it's obscure that in the texts case,
|
||||||
|
// we have to set item to '', while for videos,
|
||||||
|
// it remains undefined
|
||||||
|
state.item = '';
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(str);
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,6 +914,7 @@ pandora.getSortOperator = function(key) {
|
||||||
};
|
};
|
||||||
|
|
||||||
pandora.getSpan = function(state, str, callback) {
|
pandora.getSpan = function(state, str, callback) {
|
||||||
|
Ox.print('GET SPAN', state, str)
|
||||||
// For a given item, or none (state.item), and a given view, or any
|
// For a given item, or none (state.item), and a given view, or any
|
||||||
// (state.view), this takes a string and checks if it is a valid
|
// (state.view), this takes a string and checks if it is a valid
|
||||||
// annotation/event/place id or an event/place name, and in that case sets
|
// annotation/event/place id or an event/place name, and in that case sets
|
||||||
|
@ -947,7 +959,8 @@ pandora.getSpan = function(state, str, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (type == 'text') {
|
} else if (type == 'texts') {
|
||||||
|
state.span = str;
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue