From 187250b22fe6c6932e1e453581722d6e565cf650 Mon Sep 17 00:00:00 2001
From: mrilyew <99399973+mrilyew@users.noreply.github.com>
Date: Sun, 1 Dec 2024 18:12:50 +0300
Subject: [PATCH] Repair playlists
---
Web/Presenters/AudioPresenter.php | 56 ++---
.../templates/Audio/EditPlaylist.xml | 77 +++----
.../templates/Audio/NewPlaylist.xml | 64 ++----
Web/static/css/audios.css | 22 ++
Web/static/css/main.css | 26 +--
Web/static/js/al_music.js | 215 ++++++++++++++----
Web/static/js/al_playlists.js | 113 ---------
Web/static/js/al_wall.js | 8 +-
Web/static/js/router.js | 14 +-
Web/static/js/utils.js | 21 +-
locales/en.strings | 5 +-
locales/ru.strings | 4 +-
12 files changed, 322 insertions(+), 303 deletions(-)
delete mode 100644 Web/static/js/al_playlists.js
diff --git a/Web/Presenters/AudioPresenter.php b/Web/Presenters/AudioPresenter.php
index 9a678b765..aa8801f51 100644
--- a/Web/Presenters/AudioPresenter.php
+++ b/Web/Presenters/AudioPresenter.php
@@ -343,17 +343,15 @@ function renderNewPlaylist(): void
$this->template->club = $club;
}
- $this->template->owner = $owner;
-
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$title = $this->postParam("title");
$description = $this->postParam("description");
$is_unlisted = (int)$this->postParam('is_unlisted');
-
- $audios = !empty($this->postParam("audios")) ? array_slice(explode(",", $this->postParam("audios")), 0, 1000) : [];
+ $is_ajax = (int)$this->postParam('ajax') == 1;
+ $audios = array_slice(explode(",", $this->postParam("audios")), 0, 1000);
if(empty($title) || iconv_strlen($title) < 1)
- $this->flashFail("err", tr("error"), tr("set_playlist_name"));
+ $this->flashFail("err", tr("error"), tr("set_playlist_name"), NULL, $is_ajax);
$playlist = new Playlist;
$playlist->setOwner($owner);
@@ -364,12 +362,12 @@ function renderNewPlaylist(): void
if($_FILES["cover"]["error"] === UPLOAD_ERR_OK) {
if(!str_starts_with($_FILES["cover"]["type"], "image"))
- $this->flashFail("err", tr("error"), tr("not_a_photo"));
+ $this->flashFail("err", tr("error"), tr("not_a_photo"), NULL, $is_ajax);
try {
$playlist->fastMakeCover($this->user->id, $_FILES["cover"]);
} catch(\Throwable $e) {
- $this->flashFail("err", tr("error"), tr("invalid_cover_photo"));
+ $this->flashFail("err", tr("error"), tr("invalid_cover_photo"), NULL, $is_ajax);
}
}
@@ -377,25 +375,22 @@ function renderNewPlaylist(): void
foreach($audios as $audio) {
$audio = $this->audios->get((int)$audio);
-
- if(!$audio || $audio->isDeleted() || !$audio->canBeViewedBy($this->user->identity))
+ if(!$audio || $audio->isDeleted())
continue;
$playlist->add($audio);
}
$playlist->bookmark(isset($club) ? $club : $this->user->identity);
+ if($is_ajax) {
+ $this->returnJson([
+ 'success' => true,
+ 'redirect' => '/playlist' . $owner . "_" . $playlist->getId()
+ ]);
+ }
$this->redirect("/playlist" . $owner . "_" . $playlist->getId());
} else {
- if(isset($club)) {
- $this->template->audios = iterator_to_array($this->audios->getByClub($club, 1, 10));
- $count = (new Audios)->getClubCollectionSize($club);
- } else {
- $this->template->audios = iterator_to_array($this->audios->getByUser($this->user->identity, 1, 10));
- $count = (new Audios)->getUserCollectionSize($this->user->identity);
- }
-
- $this->template->pagesCount = ceil($count / 10);
+ $this->template->owner = $owner;
}
}
@@ -451,28 +446,20 @@ function renderEditPlaylist(int $owner_id, int $virtual_id)
$this->willExecuteWriteAction();
$playlist = $this->audios->getPlaylistByOwnerAndVID($owner_id, $virtual_id);
- $page = (int)($this->queryParam("p") ?? 1);
if (!$playlist || $playlist->isDeleted() || !$playlist->canBeModifiedBy($this->user->identity))
$this->notFound();
$this->template->playlist = $playlist;
- $this->template->page = $page;
$audios = iterator_to_array($playlist->fetch(1, $playlist->size()));
- $this->template->audios = array_slice($audios, 0, 10);
- $audiosIds = [];
-
- foreach($audios as $aud)
- $audiosIds[] = $aud->getId();
-
- $this->template->audiosIds = implode(",", array_unique($audiosIds)) . ",";
+ $this->template->audios = array_slice($audios, 0, 1000);
$this->template->ownerId = $owner_id;
$this->template->owner = $playlist->getOwner();
- $this->template->pagesCount = $pagesCount = ceil($playlist->size() / 10);
if($_SERVER["REQUEST_METHOD"] !== "POST")
return;
+ $is_ajax = (int)$this->postParam('ajax') == 1;
$title = $this->postParam("title");
$description = $this->postParam("description");
$is_unlisted = (int)$this->postParam('is_unlisted');
@@ -487,12 +474,12 @@ function renderEditPlaylist(int $owner_id, int $virtual_id)
$playlist->resetLength();
$playlist->setUnlisted((bool)$is_unlisted);
- if($_FILES["new_cover"]["error"] === UPLOAD_ERR_OK) {
- if(!str_starts_with($_FILES["new_cover"]["type"], "image"))
+ if($_FILES["cover"]["error"] === UPLOAD_ERR_OK) {
+ if(!str_starts_with($_FILES["cover"]["type"], "image"))
$this->flashFail("err", tr("error"), tr("not_a_photo"));
try {
- $playlist->fastMakeCover($this->user->id, $_FILES["new_cover"]);
+ $playlist->fastMakeCover($this->user->id, $_FILES["cover"]);
} catch(\Throwable $e) {
$this->flashFail("err", tr("error"), tr("invalid_cover_photo"));
}
@@ -506,13 +493,18 @@ function renderEditPlaylist(int $owner_id, int $virtual_id)
foreach ($new_audios as $new_audio) {
$audio = (new Audios)->get((int)$new_audio);
-
if(!$audio || $audio->isDeleted())
continue;
$playlist->add($audio);
}
+ if($is_ajax) {
+ $this->returnJson([
+ 'success' => true,
+ 'redirect' => '/playlist' . $playlist->getPrettyId()
+ ]);
+ }
$this->redirect("/playlist".$playlist->getPrettyId());
}
diff --git a/Web/Presenters/templates/Audio/EditPlaylist.xml b/Web/Presenters/templates/Audio/EditPlaylist.xml
index 98b9f3f3c..e2aa0112a 100644
--- a/Web/Presenters/templates/Audio/EditPlaylist.xml
+++ b/Web/Presenters/templates/Audio/EditPlaylist.xml
@@ -13,61 +13,44 @@
{/block}
{block content}
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
- {include "player.xml", audio => $audio, hideButtons => true}
+
+
+
+ {include 'player.xml', audio => $audio, hideButtons => true}
-
-
{_remove_from_playlist}
+
-
-
-
-
{/block}
diff --git a/Web/Presenters/templates/Audio/NewPlaylist.xml b/Web/Presenters/templates/Audio/NewPlaylist.xml
index d3d1a281b..b28cd4a85 100644
--- a/Web/Presenters/templates/Audio/NewPlaylist.xml
+++ b/Web/Presenters/templates/Audio/NewPlaylist.xml
@@ -19,48 +19,32 @@
{/block}
{block content}
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+
-
-
-
-
`)
@@ -1156,6 +1173,13 @@ u(document).on('contextmenu', '.bigPlayer, .audioEmbed, #ajax_audio_player', (e)
moving_track_player.remove()
}
})
+ ctx_u.find('#audio_ctx_clear_context').on('click', (ev) => {
+ const old_url = window.player.context.object.url
+ window.player.pause()
+ window.player.__resetContext()
+ window.player.__updateFace()
+ window.router.route(old_url)
+ })
})
u(document).on("click", ".musicIcon.edit-icon", (e) => {
@@ -1641,9 +1665,11 @@ $(document).on("click", "#_deletePlaylist", (e) => {
}, Function.noop])
})
-$(document).on("click", "#__audioAttachment", (e) => {
- const form = e.target.closest("form")
- let body = `
+function showAudioAttachment(type = 'form', form = null)
+{
+ const msg = new CMessageBox({
+ title: tr("select_audio"),
+ body: `
- `
- MessageBox(tr("select_audio"), body, [tr("close")], [Function.noop])
-
- document.querySelector(".ovk-diag-body").style.padding = "0"
- document.querySelector(".ovk-diag-cont").style.width = "580px"
- document.querySelector(".ovk-diag-body").style.height = "335px"
-
+ `,
+ buttons: [tr('close')],
+ callbacks: [Function.noop],
+ })
+ msg.getNode().find('.ovk-diag-body').attr('style', 'padding:0px;height:335px')
+ msg.getNode().attr('style', 'width:580px')
let searcher = new playersSearcher("entity_audios", 0)
searcher.successCallback = (response, thisc) => {
let domparser = new DOMParser()
@@ -1674,8 +1699,18 @@ $(document).on("click", "#__audioAttachment", (e) => {
}
result.querySelectorAll(".audioEmbed").forEach(el => {
- let id = el.dataset.prettyid
- const is_attached = (u(form).find(`.post-vertical .vertical-attachment[data-id='${id}']`)).length > 0
+ let id = 0
+ if(type == 'form') {
+ id = el.dataset.prettyid
+ } else {
+ id = el.dataset.realid
+ }
+ let is_attached = false
+ if(type == 'form') {
+ is_attached = (u(form).find(`.post-vertical .vertical-attachment[data-id='${id}']`)).length > 0
+ } else {
+ is_attached = (u(form).find(`.PE_audios .vertical-attachment[data-id='${id}']`)).length > 0
+ }
document.querySelector(".audiosInsert").insertAdjacentHTML("beforeend", `