Skip to content

Commit

Permalink
datatables...
Browse files Browse the repository at this point in the history
  • Loading branch information
reaby committed Jan 30, 2021
1 parent e941b56 commit 9439dfc
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 54 deletions.
11 changes: 11 additions & 0 deletions bin/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class websocket {
io.emit("callback.dataUpdate", self.getIndexFile());
});


client.on("moveSong", (oldIndex, newIndex) => {
let song = self.serverOptions.showData.songs.splice(oldIndex, 1);
self.serverOptions.showData.songs.splice(newIndex, 0, song[0]);
Expand Down Expand Up @@ -129,6 +130,16 @@ class websocket {
io.emit("update", self.serverOptions);
})

client.on("newShow", () => {
self.serverOptions.currentShow = "";
self.serverOptions.showData = {
name: "",
titles: [],
songs: []
}
client.emit("updateAll", self.serverOptions);
});

client.on("loadShow", (file) => {
try {
if (fs.existsSync("./data/shows/" + file)) {
Expand Down
Binary file added public/images/sort_asc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/sort_asc_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/sort_both.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/sort_desc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/sort_desc_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 100 additions & 40 deletions public/javascripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ $(function () {
action: function (text, value) {
switch (value) {
case "new":
socket.emit("newShow");
break;
case "open":
openShow();
Expand Down Expand Up @@ -145,7 +146,29 @@ function renameShow() {
function openShow() {
$('.fileAction').text("Open");
$("#dialogFilename").val("");
$.getJSON("/ajax/shows", function (json) {
$('#showContent').DataTable().destroy();
$('#showContent').DataTable({
paging: false,
ajax: '/ajax/shows',
columns: [
{ data: "file" }
],
"initComplete": function () {
var api = this.api();
api.$('td').click(function () {
$("#dialogFilename").val(this.innerHTML);
});
}
});

$('#showDialog').modal({
blurring: true,
onApprove: function () {
socket.emit("loadShow", $("#dialogFilename").val());
}
}).modal('show');

/*$.getJSON("/ajax/shows", function (json) {
let data = ``;
for (let elem of json) {
data += `
Expand All @@ -163,57 +186,94 @@ function openShow() {
socket.emit("loadShow", $("#dialogFilename").val());
}
}).modal('show');
});

*/
}

function saveShow() {
$('.fileAction').text("Save");
$("#dialogFilename").val("");
$.getJSON("/ajax/shows", function (json) {
let data = ``;
for (let elem of json) {
data += `
<div class="item" onclick="selectShowFile(this);">
<i class="file icon"></i>
<div class="content noselect">
<div class="header">${elem}</div>
</div>
</div>`;
$('#showContent').DataTable().destroy();
$('#showContent').DataTable({
paging: false,
scrollCollapse: true,
ajax: '/ajax/shows',
columns: [
{ data: "file" }
],
"initComplete": function () {
var api = this.api();
api.$('td').click(function () {
$("#dialogFilename").val(this.innerHTML);
});
}
$("#showContent").html(data);
$('#showDialog').modal({
blurring: true,
onApprove: function () {
socket.emit("saveShow", $("#dialogFilename").val());
}
}).modal('show');
});
$('#showDialog').modal({
blurring: true,
onApprove: function () {
socket.emit("saveShow", $("#dialogFilename").val());
}
}).modal('show');
}

function importSongs() {
$.getJSON("/ajax/songs", function (json) {
let data = ``;
for (let elem of json) {
data += `
<div class="item">
<div class="right floated middle aligned content noselect">
<div class="ui button" onclick="editSong('${elem.file}')">Edit</div>
<div class="ui green button" onclick="addSong('${elem.file}')">Import</div>
</div>
<div class="content noselect">
<i class="music icon"></i>${elem.title} (${elem.artist})
</div>
</div>`;
}
$("#songContent").html(data);
$('#songDialog').modal({
blurring: true
}).modal('show');
/* $.getJSON("/ajax/songs", function (json) {
let data = ``;
for (let elem of json) {
data += `
<div class="item">
<div class="right floated middle aligned content noselect">
<div class="ui button" onclick="editSong('${elem.file}')">Edit</div>
<div class="ui green button" onclick="addSong('${elem.file}')">Import</div>
</div>
<div class="content noselect">
<i class="music icon"></i>${elem.title} (${elem.artist})
</div>
</div>`;
}
$("#songContent").html(data);*/

$('#songContent').DataTable().destroy();
$('#songContent').DataTable({
paging: false,
scrollCollapse: true,
pageLength: 25,
lengthChange: false,
info: false,
ajax: '/ajax/songs',
columns: [
{ data: "title" },
{ data: "artist" },
{ data: "file" },
],
"columnDefs": [
{
// The `data` parameter refers to the data for the cell (defined by the
// `data` option, which defaults to the column being worked with, in
// this case `data: 0`.
"render": function (data, type, row) {
return `
<div class="ui button" onclick="editSong('${data}')">Edit</div>
<div class="ui green button" onclick="addSong('${data}')">Import</div>
`;
},
"targets": 2
},
]
/*"initComplete": function () {
var api = this.api();
api.$('td').click(function () {
$("#dialogFilename").val(this.innerHTML);
});
} */
});

$('#songDialog').modal({
blurring: true
}).modal('show');
}


Expand Down
15 changes: 15 additions & 0 deletions public/javascripts/dataTables.semanticui.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

265 changes: 265 additions & 0 deletions public/javascripts/datatables.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/stylesheets/dataTables.semanticui.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions public/stylesheets/datatables.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion public/stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ iframe {
#showDialog .ui.list .item {
padding: 0.5rem;
}
.dataTable tbody tr:hover {
background: skyblue;
}

#showDialog .ui.list .item:hover {
background: skyblue;
Expand All @@ -84,4 +87,4 @@ iframe {

#songeditor .red.button {
background: maroon;
}
}
11 changes: 8 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ router.get('/ajax/songs', function (req, res, next) {
let outData = [];
for (song of songs) {
let info = JSON.parse(fs.readFileSync("./data/songs/" + song).toString());
outData.push({ title: info.title, artist: info.artist, file: song });
outData.push({ title: info.title, artist: info.artist, file: song, actions: "" });
}
res.json(outData);
res.json({ data: outData });
});

router.get('/ajax/shows', function (req, res, next) {
res.json(fs.readdirSync("./data/shows"));
let data = fs.readdirSync("./data/shows");
let out = [];
for (elem of data) {
out.push({ file: elem });
}
res.json({ data: out });
});

router.get('/ajax/song', function (req, res, next) {
Expand Down
Loading

0 comments on commit 9439dfc

Please sign in to comment.