search first draft

This commit is contained in:
IrosTheBeggar 2020-01-16 00:37:50 -05:00
parent c9f41b8b95
commit 0061ca1004
4 changed files with 161 additions and 12 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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('<div data-artist="' + value + '" class="artistz">' + value + ' </div>');
@ -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 =
'<div>\
<form id="db-search" onsubmit="return false;">\
<input id="search-term" required type="text" placeholder="Search..">\
<button type="submit" class="searchButton">\
<svg fill="#DDD" viewBox="-150 -50 1224 1174" height="24px" width="24px" xmlns="http://www.w3.org/2000/svg"><path d="M960 832L710.875 582.875C746.438 524.812 768 457.156 768 384 768 171.969 596 0 384 0 171.969 0 0 171.969 0 384c0 212 171.969 384 384 384 73.156 0 140.812-21.562 198.875-57L832 960c17.5 17.5 46.5 17.375 64 0l64-64c17.5-17.5 17.5-46.5 0-64zM384 640c-141.375 0-256-114.625-256-256s114.625-256 256-256 256 114.625 256 256-114.625 256-256 256z"></path></svg>\
</button>\
</form>\
<input id="search-in-artists" type="checkbox" checked><label for="search-in-titles">Artists</label>\
<input id="search-in-albums" type="checkbox" checked><label for="search-in-titles">Albums</label><br>\
<input id="search-in-filepaths" type="checkbox"><label for="search-in-filepaths">File Paths</label>\
<input id="search-in-titles" type="checkbox"><label for="search-in-titles">Song Titles</label><br>\
</div>\
<div id="search-results"></div>';
$('#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('<div class="loading-screen"><svg class="spinner" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg"><circle class="spinner-path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg></div>');
// Send AJAX Request
MSTREAMAPI.search($('#search-term').val(), function(res, error) {
if (error !== false) {
$('#search-results').html('<div>Server call failed</div>');
return boilerplateFailure(response, error);
}
// Populate list
var searchList = ['<div class="clear flatline"></div>'];
Object.keys(res).forEach(function (key) {
res[key].forEach(function (value, i) {
// perform some operation on a value;
searchList.push(`<div data-${searchMap[key].data}="${value.name}" class="${searchMap[key].class}"><b>${searchMap[key].name}:</b> ${value.name}</div>`);
});
});
$('#search-results').html(searchList);
});
});
//////////////////////// Auto DJ
$('.auto_dj_settings').on('click', function () {
$('ul.left-nav-menu li').removeClass('selected');

View File

@ -275,14 +275,18 @@
<?xml version="1.0" encoding="iso-8859-1"?><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="-3 0 62 62" style="enable-background:new 0 0 53.867 53.867"><path style="fill:#efce4a" d="M26.934 1.318l8.322 16.864 18.611 2.705L40.4 34.013l3.179 18.536-16.645-8.751-16.646 8.751 3.179-18.536L0 20.887l18.611-2.705z"/></svg>
Rated
</li>
<li class="auto_dj_settings">
<svg xmlns="http://www.w3.org/2000/svg" fill="#DDD" width="24" height="24" viewBox="0 0 55.334 55.334"><g><circle cx="27.667" cy="27.667" r="3.618"/><path d="M27.667 0C12.387 0 0 12.387 0 27.667s12.387 27.667 27.667 27.667 27.667-12.387 27.667-27.667S42.947 0 27.667 0zM17.118 6.881a23.213 23.213 0 0111.214-2.509c.367.01.619.922.564 2.025l-.282 5.677c-.055 1.103-.289 1.986-.523 1.979a13.577 13.577 0 00-6.027 1.196c-1.007.455-2.212.184-2.774-.767l-2.896-4.897c-.562-.951-.261-2.203.724-2.704zm-1.132 10.414l-4.278-3.742c-.832-.727-.918-1.994-.119-2.756l.057-.053c.802-.76 2.059-.605 2.737.266l3.494 4.484c.679.871.837 1.889.391 2.314-.447.427-1.45.214-2.282-.513zm1.891 10.372c0-5.407 4.383-9.79 9.79-9.79s9.79 4.383 9.79 9.79-4.383 9.79-9.79 9.79-9.79-4.383-9.79-9.79zM38.17 48.476a23.21 23.21 0 01-11.244 2.484c-.409-.013-.692-.929-.632-2.032l.31-5.676c.061-1.103.322-1.981.586-1.972a13.596 13.596 0 005.656-1.01c1.022-.42 2.275-.144 2.877.782l3.101 4.77c.602.925.332 2.155-.654 2.654zm5.449-3.82c-.766.72-2.005.551-2.703-.305l-3.59-4.407c-.698-.856-.876-1.848-.435-2.255.442-.407 1.443-.179 2.274.549l4.28 3.744c.832.727.941 1.954.174 2.674z"/></g></svg>
Auto DJ
<li class="search_stuff">
<svg viewBox="-150 -50 1224 1174" height="24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M960 832L710.875 582.875C746.438 524.812 768 457.156 768 384 768 171.969 596 0 384 0 171.969 0 0 171.969 0 384c0 212 171.969 384 384 384 73.156 0 140.812-21.562 198.875-57L832 960c17.5 17.5 46.5 17.375 64 0l64-64c17.5-17.5 17.5-46.5 0-64zM384 640c-141.375 0-256-114.625-256-256s114.625-256 256-256 256 114.625 256 256-114.625 256-256 256z"></path></svg>
Search
</li>
</ul>
<div class="left-nav-menu-header">System</div>
<ul class="left-nav-menu">
<li class="auto_dj_settings">
<svg xmlns="http://www.w3.org/2000/svg" fill="#DDD" width="24" height="24" viewBox="0 0 55.334 55.334"><g><circle cx="27.667" cy="27.667" r="3.618"/><path d="M27.667 0C12.387 0 0 12.387 0 27.667s12.387 27.667 27.667 27.667 27.667-12.387 27.667-27.667S42.947 0 27.667 0zM17.118 6.881a23.213 23.213 0 0111.214-2.509c.367.01.619.922.564 2.025l-.282 5.677c-.055 1.103-.289 1.986-.523 1.979a13.577 13.577 0 00-6.027 1.196c-1.007.455-2.212.184-2.774-.767l-2.896-4.897c-.562-.951-.261-2.203.724-2.704zm-1.132 10.414l-4.278-3.742c-.832-.727-.918-1.994-.119-2.756l.057-.053c.802-.76 2.059-.605 2.737.266l3.494 4.484c.679.871.837 1.889.391 2.314-.447.427-1.45.214-2.282-.513zm1.891 10.372c0-5.407 4.383-9.79 9.79-9.79s9.79 4.383 9.79 9.79-4.383 9.79-9.79 9.79-9.79-4.383-9.79-9.79zM38.17 48.476a23.21 23.21 0 01-11.244 2.484c-.409-.013-.692-.929-.632-2.032l.31-5.676c.061-1.103.322-1.981.586-1.972a13.596 13.596 0 005.656-1.01c1.022-.42 2.275-.144 2.877.782l3.101 4.77c.602.925.332 2.155-.654 2.654zm5.449-3.82c-.766.72-2.005.551-2.703-.305l-3.59-4.407c-.698-.856-.876-1.848-.435-2.255.442-.407 1.443-.179 2.274.549l4.28 3.744c.832.727.941 1.954.174 2.674z"/></g></svg>
Auto DJ
</li>
<li class="federation-panel">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92 1.61 0 2.92-1.31 2.92-2.92s-1.31-2.92-2.92-2.92z"/></svg>
Federation