Display and hide on frontpage only not working

This commit is contained in:
Kasper Rynning-Tønnesen
2015-04-10 14:56:14 +02:00
parent 4e6b0386b1
commit 65f28cff99
5 changed files with 179 additions and 45 deletions

View File

@@ -1,10 +1,10 @@
var adminTogg = false;
var pass_corr = "";
socket.on("success_settings", function()
socket.on("success_settings", function(msg)
{
pass_corr = "correct";
document.getElementById("sBar").innerHTML = "Successfully applied settings.";
document.getElementById("sBar").innerHTML = msg;
$("#sBar").addClass("opacityFull");
document.getElementById("passbox").value = "";
remove_bar();
@@ -106,6 +106,7 @@ function remove_bar()
function shuffle(form)
{
console.log(adminpass);
socket.emit('shuffle', adminpass);
/*
confRes = $.ajax({
type: "GET",

View File

@@ -186,7 +186,14 @@ function submitAndClose(id,title){
function submit(id,title,type){
socket.emit("add", [id, title, adminpass]);
socket.emit("add", [id, decodeURI(title), adminpass]);
if(type){
document.getElementById("search").value = "";
$("#results").html = "";
$(".main").removeClass("blurT");
$("#controls").removeClass("blurT");
$(".main").removeClass("clickthrough");
}
/*
serverAns = $.ajax({
type: "GET",

View File

@@ -55,10 +55,9 @@ socket.on(chan.toLowerCase()+",np", function(obj)
console.log(seekTo);
if(player_ready)
{
if(!playing){
if(ytplayer.getVideoUrl().split('v=')[1] != video_id)
ytplayer.loadVideoById(video_id);
ytplayer.playVideo();
}
ytplayer.playVideo();
ytplayer.seekTo(seekTo);
}
});

View File

@@ -54,6 +54,8 @@ foreach($fil as $files){
}
</style>
<?php include("header.php"); ?>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
</head>
<body>
<div class="bgimage" id="bgimage"></div>
@@ -72,7 +74,7 @@ foreach($fil as $files){
</div>
<center>
<div class="channels" id="channels">Active Channels<br>
<?php foreach($channels as $channel){echo "<a class='channel' href='./".htmlspecialchars($channel)."' title='Viewers: ~".$viewers[$v]."'>".htmlspecialchars($channel)."</a>"; $v++;} ?>
<div id="fp-chans"></div>
</div>
</center>
</div>
@@ -144,6 +146,46 @@ foreach($fil as $files){
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<script>
var socket = io.connect('http://localhost:3000');
var playlists = [];
socket.emit('frontpage_lists');
socket.on('playlists', function(msg){
populate_channels(msg);
})
function populate_channels(lists)
{
var output = "";
lists.sort(sortFunction);
for(x in lists)
{
var id = lists[x][1];
var title = lists[x][2];
var name = lists[x][3];
var viewers = lists[x][0];
//console.log("Channel name: "+name+", viewers: "+viewers);
output += "<a class='channel' href='./"+name+"' title='Viewer(s): "+viewers+"'>"+name.capitalizeFirstLetter()+"</a>";
}
document.getElementById("fp-chans").innerHTML = output;
}
String.prototype.capitalizeFirstLetter = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function sortFunction(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] < b[0]) ? 1 : -1;
}
}
</script>
<noscript><p><img src="//zoff.no/analyse/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
</body>

View File

@@ -23,9 +23,52 @@ io.on('connection', function(socket){
var coll;
var guid;
var tot_lists = [];
var in_list = false;
socket.on('frontpage_lists', function()
{
var playlists_to_send = [];
var i = 0;
var playlists_to_send = [];
in_list = false;
db.getCollectionNames(function(err, colNames){
colNames.forEach(function(name){
if(name != "system.indexes")
{
db.collection(name).find({now_playing:true}, function(err, np){
complete(np, i, colNames.length-2, name);
i++;
});
}
});
});
var complete = function(list, curr, tot, name)
{
console.log("inside");
if(list.length > 0)
{
var id = list[0]["id"];
var title = list[0]["title"];
try{
var viewers = lists[name].length;
}catch(err){console.log("no viewers"); var viewers = 0;}
var to_push = [viewers, id, title, name];
playlists_to_send.push(to_push);
}
if(curr == tot)
{
socket.emit("playlists", playlists_to_send);
}
}
});
socket.on('list', function(list)
{
in_list = true;
list = list.split(',');
coll = list[0].toLowerCase();
guid = list[1];
@@ -110,7 +153,7 @@ io.on('connection', function(socket){
{
var id = msg[1];
guid = msg[3];
var hash = has_pass(msg[4]);
var hash = hash_pass(msg[4]);
db.collection(coll).find({views:{$exists:true}}, function(err, docs)
{
if((docs[0]["vote"] == "true" && (hash == docs[0]["adminpass"] || docs[0]["adminpass"] == "")) || docs[0]["vote"] == "false")
@@ -174,7 +217,7 @@ io.on('connection', function(socket){
shuffle:shuffling,
longsongs:longsongs,
adminpass:hash}}, function(err, docs){
socket.emit("success_settings");
socket.emit("success_settings", "Successfully applied settings!");
sort_list(coll,undefined,false);
});
@@ -185,14 +228,37 @@ io.on('connection', function(socket){
});
});
socket.on('shuffle', function(pass){
var hash = hash_pass(pass);
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
if((docs[0]["adminpass"] == hash || docs[0]["adminpass"] == "") || docs[0]["shuffle"] == "true")
{
db.collection(coll).find({now_playing:false}).forEach(function(err, docs){
if(!docs){
sort_list(coll, undefined, false);
return;
}else{
console.log(docs);
num = Math.floor(Math.random()*1000000);
db.collection(coll).update({id:docs["id"]}, {$set:{added:num}}, function(err, d)
{});
}
});
}
});
});
socket.on('disconnect', function()
{
try
{
var index = lists[coll].indexOf(guid);
lists[coll].splice(index, 1);
io.sockets.emit(coll+",viewers", lists[coll].length);
}catch(err){}
if(in_list)
{
try
{
var index = lists[coll].indexOf(guid);
lists[coll].splice(index, 1);
io.sockets.emit(coll+",viewers", lists[coll].length);
}catch(err){}
}
});
socket.on('pos', function()
@@ -200,14 +266,16 @@ io.on('connection', function(socket){
console.log("EMITTED");
send_play(coll, socket);
});
});
function del(params)
{
db.collection(coll).find({adminpass:hash_pass(params[4])}, function(err, docs){
if(docs.length == 1)
var coll = params[0].toLowerCase();
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
console.log(docs);
if(docs[0]["adminpass"] == hash_pass(params[4]))
{
console.log("del");
db.collection(coll).remove({id:params[1]}, function(err, docs){
sort_list(coll, undefined, false);
})
@@ -227,41 +295,58 @@ function vote(coll, id, guid)
{
db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:get_time()}}, function(err, docs)
{
/*db.collection(coll).update({id:id}, {$push :{guids: guid}}, function(err, docs)
db.collection(coll).update({id:id}, {$push :{guids: guid}}, function(err, docs)
{
sort_list(coll, undefined, false);
});*/
sort_list(coll, undefined, false);
});
//sort_list(coll, undefined, false);
});
}
});
}
function change_song(coll)
{
db.collection(coll).update({now_playing:true},
{$set:{
now_playing:false,
votes:0,
guids:[]
}}, function(err, docs)
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
if(docs[0]["removeplay"] == "true")
{
db.collection(coll).aggregate([
{$match:{now_playing:false}},
{$sort:{votes:-1, added:1}},
{$limit:1}], function(err, docs){
db.collection(coll).update({id:docs[0]["id"]},
{$set:{
now_playing:true,
votes:0,
guids:[],
added:get_time()}}, function(err, docs){
db.collection(coll).update({views:{$exists:true}},
{$set:{startTime:get_time()}}, function(err, docs){
sort_list(coll,undefined,true);
});
db.collection(coll).remove({now_playing:true}, function(err, docs)
{
change_song_post(coll);
})
}else
{
db.collection(coll).update({now_playing:true},
{$set:{
now_playing:false,
votes:0,
guids:[]
}}, function(err, docs)
{
change_song_post(coll);
});
}
})
}
function change_song_post(coll)
{
db.collection(coll).aggregate([
{$match:{now_playing:false}},
{$sort:{votes:-1, added:1}},
{$limit:1}], function(err, docs){
db.collection(coll).update({id:docs[0]["id"]},
{$set:{
now_playing:true,
votes:0,
guids:[],
added:get_time()}}, function(err, docs){
db.collection(coll).update({views:{$exists:true}},
{$set:{startTime:get_time()}}, function(err, docs){
sort_list(coll,undefined,true);
});
});
});
}