diff --git a/modules/db-read/database-public-loki.js b/modules/db-read/database-public-loki.js index 6664f77..0fcae8d 100644 --- a/modules/db-read/database-public-loki.js +++ b/modules/db-read/database-public-loki.js @@ -454,10 +454,6 @@ exports.setup = function (mstream, program) { }); }); - mstream.get('/db/random-albums', (req, res) => { - res.status(444).json({ error: 'Coming Soon!' }); - }); - mstream.post('/db/random-songs', (req, res) => { if (!fileCollection) { res.status(500).json({ error: 'No files in DB' }); @@ -537,6 +533,56 @@ exports.setup = function (mstream, program) { res.json(returnThis); }); + mstream.post('/db/search', (req, res) => { + // Get user inputs + const artists = searchByX(req, 'artist'); + const albums = searchByX(req, 'album'); + // const files = searchByX(req, 'filepath'); + // const title = searchByX(req, 'title', 'filepath'); + + res.json({artists, albums }); + }); + + function searchByX(req, searchCol, resCol) { + if (!resCol) { + resCol = searchCol; + } + + const returnThis = []; + if (!fileCollection) { return returnThis; } + + let orClause; + if (req.user.vpaths.length === 1) { + orClause = { 'vpath': { '$eq': req.user.vpaths[0] } } + } else { + orClause = { '$or': [] } + for (let vpath of req.user.vpaths) { + orClause['$or'].push({ 'vpath': { '$eq': vpath } }) + } + } + + const findThis = { + '$and': [ + orClause, + {[searchCol]: {'$regex': [String(req.body.search), 'i']}} + ] + }; + const results = fileCollection.find(findThis); + + const store = {}; + for (let row of results) { + if (!store[row[resCol]]) { + returnThis.push({ + name: row[resCol], + album_art_file: row.albumArtFilename ? row.albumArtFilename : null + }); + store[row[resCol]] = true; + } + } + + return returnThis; + } + mstream.get('/db/get-rated', (req, res) => { const songs = []; if (!fileCollection) { @@ -608,10 +654,9 @@ exports.setup = function (mstream, program) { const results = fileCollection.chain().find({ '$and': [ - orClause - , { - 'ts': { '$gt': 0 } - }] + orClause, + { 'ts': { '$gt': 0 } } + ] }).simplesort('ts', true).limit(limit).data(); for (let row of results) { diff --git a/public/css/master.css b/public/css/master.css index 6ddd0f4..70f1aa4 100755 --- a/public/css/master.css +++ b/public/css/master.css @@ -830,4 +830,29 @@ input[name="autodj-folders"] { cursor: pointer; margin-left: 10px; max-width: calc(100% - 20px); +} + +#db-search { + width: 100%; + position: relative; + display: flex; + margin-top: 20px; + margin-bottom: 0px; +} + +#search-term { + border: 3px solid #00B4CC; + border-radius: 5px 0 0 5px; +} + +.searchButton { + width: 60px; + height: 37px; + border: 1px solid #00B4CC; + background: #00B4CC; + text-align: center; + color: #fff; + border-radius: 0 5px 5px 0; + + padding: 0; } \ No newline at end of file diff --git a/public/js/mstream.js b/public/js/mstream.js index 900153e..c7e4ca4 100755 --- a/public/js/mstream.js +++ b/public/js/mstream.js @@ -1212,7 +1212,7 @@ $(document).ready(function () { return boilerplateFailure(response, error); } - //parse through the json array and make an array of corresponding divs + // parse through the json array and make an array of corresponding divs var artists = []; $.each(response.artists, function (index, value) { artists.push('
' + value + '
'); @@ -1329,6 +1329,81 @@ $(document).ready(function () { }); } + //////////////////////// Search + $('.search_stuff').on('click', function () { + $('ul.left-nav-menu li').removeClass('selected'); + $('.search_stuff').addClass('selected'); + resetPanel('Search DB', 'scrollBoxHeight2'); + currentBrowsingList = []; + $('#directory_bar').hide(); + + var newHtml = + '
\ + \ + \ +
\ + \ +
\ +
\ +
'; + + $('#filelist').html(newHtml); + }); + + const searchMap = { + albums: { + name: 'Album', + class: 'albumz', + data: 'album' + }, + artists: { + name: 'Artist', + class: 'artistz', + data: 'artist' + }, + files: { + name: 'File', + class: 'filez', + data: 'file_location' + }, + title: { + name: 'Song', + class: 'filez', + data: 'artist' + } + }; + + $('#filelist').on('submit', '#db-search', function (e) { + console.log('LOL'); + $('#search-results').html(''); + $('#search-results').append('
'); + + + // Send AJAX Request + MSTREAMAPI.search($('#search-term').val(), function(res, error) { + if (error !== false) { + $('#search-results').html('
Server call failed
'); + return boilerplateFailure(response, error); + } + + // Populate list + var searchList = ['
']; + Object.keys(res).forEach(function (key) { + res[key].forEach(function (value, i) { + // perform some operation on a value; + searchList.push(`
${searchMap[key].name}: ${value.name}
`); + }); + }); + + $('#search-results').html(searchList); + }); + }); + //////////////////////// Auto DJ $('.auto_dj_settings').on('click', function () { $('ul.left-nav-menu li').removeClass('selected'); diff --git a/public/mstream.html b/public/mstream.html index af73a9c..7463f15 100755 --- a/public/mstream.html +++ b/public/mstream.html @@ -275,14 +275,18 @@ Rated -
  • - - Auto DJ +
  • + + Search
  • System