Libraries only fetch their data whene expanded
This commit is contained in:
@@ -32,26 +32,31 @@ Meteor.publish('libraries', function(){
|
||||
});
|
||||
|
||||
let libraryIdSchema = new SimpleSchema({
|
||||
libraryId: {
|
||||
libraryIds: {
|
||||
type: Array,
|
||||
},
|
||||
'libraryIds.$':{
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish('library', function(libraryId){
|
||||
libraryIdSchema.validate({libraryId});
|
||||
Meteor.publish('libraryNodes', function(libraryIds){
|
||||
libraryIdSchema.validate({libraryIds});
|
||||
if (!libraryIds.length) return [];
|
||||
this.autorun(function (){
|
||||
let userId = this.userId;
|
||||
let libraryCursor = Libraries.find({
|
||||
_id: libraryId,
|
||||
});
|
||||
let library = libraryCursor.fetch()[0];
|
||||
try { assertViewPermission(library, userId) }
|
||||
catch(e){ return [] }
|
||||
for (let i in libraryIds){
|
||||
let libraryId = libraryIds[i];
|
||||
let library = Libraries.findOne(libraryId);
|
||||
try { assertViewPermission(library, userId) }
|
||||
catch(e){
|
||||
return this.error(e);
|
||||
}
|
||||
}
|
||||
return [
|
||||
libraryCursor,
|
||||
LibraryNodes.find({
|
||||
'ancestors.id': libraryId,
|
||||
'ancestors.id': {$in: libraryIds},
|
||||
}, {
|
||||
sort: {order: 1},
|
||||
}),
|
||||
|
||||
@@ -112,9 +112,6 @@ export default {
|
||||
getPropertyName,
|
||||
},
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
'libraries': [],
|
||||
},
|
||||
libraries(){
|
||||
return Libraries.find({}, {
|
||||
sort: {name: 1}
|
||||
|
||||
@@ -94,6 +94,17 @@ export default {
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
'libraries': [],
|
||||
'libraryNodes'(){
|
||||
if (!this.expandedLibrary) return [[]];
|
||||
let libraryIds = [];
|
||||
this.expandedLibrary.forEach((expanded, index) => {
|
||||
if (expanded){
|
||||
let library = this.libraries[index];
|
||||
if (library) libraryIds.push(library._id)
|
||||
}
|
||||
});
|
||||
return [libraryIds];
|
||||
}
|
||||
},
|
||||
libraries(){
|
||||
return Libraries.find({}, {
|
||||
|
||||
@@ -27,11 +27,6 @@
|
||||
selectedNodeId: String,
|
||||
},
|
||||
meteor: {
|
||||
$subscribe: {
|
||||
'library'(){
|
||||
return [this.libraryId]
|
||||
},
|
||||
},
|
||||
library(){
|
||||
return Libraries.findOne(this.libraryId);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user