by Ludek » Mon Nov 14, 2022 10:05 am
Hi, watching how the sql values from customNodesDefinitions are passed to viewHanders_add.js there is code:
Code: Select all
var defs = customNodesDefinitions.albums;
forEach(defs, (item) => {
var dataSource = {
id: item.title,
title: item.title,
description: item.description,
getAlbumList: function () {
return app.db.getAlbumList('SELECT * FROM Albums WHERE ' + item.sql, -1);
}
};
node.addChild(dataSource, 'myAlbumlistSubNodeHandler');
});
=> This means that constrcuts SQL like 'SELECT * FROM Albums WHERE [[cutomNodesDefinition SQL]];
which is problematic in your case where you need to use the total_time in the ORDER BY part.
So solution is to create own node handler like
Code: Select all
nodeHandlers.myTotalRuntimeAudiobooksAlbums = inheritNodeHandler('MyTotalRuntimeAudiobooksAlbums', 'Base', {
title: 'Total runtime of audiobooks albums',
icon: 'album',
hasChildren: false,
viewAs: ['albumlist'],
getViewDataSource: function (view) {
return app.db.getAlbumList("SELECT Albums.*, Songs.IDAlbum, TrackType, Author, Songs.Album , time(SUM(SongLength) / 1000, 'unixepoch' ) AS total_time FROM Songs, Albums WHERE albums.ID = Songs.IDAlbum AND TrackType = 2 GROUP BY Songs.IDAlbum ORDER BY total_time DESC;", -1);
}
});
and modify nodeHandlers.myAlbumsNodeHandler to add your new myTotalRuntimeAudiobooksAlbums like this:
Code: Select all
nodeHandlers.myAlbumsNodeHandler = inheritNodeHandler('MyAlbumsNodeHandler', 'Base', {
title: function (node) {
return 'Albums';
},
icon: 'album',
getChildren: function (node) {
return new Promise(function (resolve, reject) {
var defs = customNodesDefinitions.albums;
forEach(defs, (item) => {
var dataSource = {
id: item.title,
title: item.title,
description: item.description,
getAlbumList: function () {
return app.db.getAlbumList('SELECT * FROM Albums WHERE ' + item.sql, -1);
}
};
node.addChild(dataSource, 'myAlbumlistSubNodeHandler');
});
node.addChild(null, 'myTotalRuntimeAudiobooksAlbums');
resolve();
});
},
viewAs: ['nodeList']
});
Hi, watching how the sql values from customNodesDefinitions are passed to viewHanders_add.js there is code:
[code]
var defs = customNodesDefinitions.albums;
forEach(defs, (item) => {
var dataSource = {
id: item.title,
title: item.title,
description: item.description,
getAlbumList: function () {
return app.db.getAlbumList('SELECT * FROM Albums WHERE ' + item.sql, -1);
}
};
node.addChild(dataSource, 'myAlbumlistSubNodeHandler');
});
[/code]
=> This means that constrcuts SQL like 'SELECT * FROM Albums WHERE [[cutomNodesDefinition SQL]];
which is problematic in your case where you need to use the total_time in the ORDER BY part.
So solution is to create own node handler like
[code]
nodeHandlers.myTotalRuntimeAudiobooksAlbums = inheritNodeHandler('MyTotalRuntimeAudiobooksAlbums', 'Base', {
title: 'Total runtime of audiobooks albums',
icon: 'album',
hasChildren: false,
viewAs: ['albumlist'],
getViewDataSource: function (view) {
return app.db.getAlbumList("SELECT Albums.*, Songs.IDAlbum, TrackType, Author, Songs.Album , time(SUM(SongLength) / 1000, 'unixepoch' ) AS total_time FROM Songs, Albums WHERE albums.ID = Songs.IDAlbum AND TrackType = 2 GROUP BY Songs.IDAlbum ORDER BY total_time DESC;", -1);
}
});
[/code]
and modify nodeHandlers.myAlbumsNodeHandler to add your new myTotalRuntimeAudiobooksAlbums like this:
[code]
nodeHandlers.myAlbumsNodeHandler = inheritNodeHandler('MyAlbumsNodeHandler', 'Base', {
title: function (node) {
return 'Albums';
},
icon: 'album',
getChildren: function (node) {
return new Promise(function (resolve, reject) {
var defs = customNodesDefinitions.albums;
forEach(defs, (item) => {
var dataSource = {
id: item.title,
title: item.title,
description: item.description,
getAlbumList: function () {
return app.db.getAlbumList('SELECT * FROM Albums WHERE ' + item.sql, -1);
}
};
node.addChild(dataSource, 'myAlbumlistSubNodeHandler');
});
node.addChild(null, 'myTotalRuntimeAudiobooksAlbums');
resolve();
});
},
viewAs: ['nodeList']
});
[/code]