work on episode form

This commit is contained in:
bkfox 2024-03-16 22:37:56 +01:00
parent eaf453086d
commit de858f45e8
17 changed files with 209 additions and 146 deletions

View File

@ -1110,11 +1110,11 @@ msgstr "Année"
#: aircox/templatetags/aircox_admin.py:53
msgid "Save Settings"
msgstr "Enregistrer la configuration"
msgstr "Enregistrer"
#: aircox/templatetags/aircox_admin.py:54
msgid "Discard changes"
msgstr "Annuler les changements"
msgstr "Annuler"
#: aircox/templatetags/aircox_admin.py:55
msgid "Columns"
@ -1122,7 +1122,7 @@ msgstr "Colonnes"
#: aircox/templatetags/aircox_admin.py:56
msgid "Add a track"
msgstr "Ajouter un morceau"
msgstr "Ajouter"
#: aircox/templatetags/aircox_admin.py:57
msgid "Remove"

View File

@ -533,6 +533,10 @@
overflow: hidden;
}
.a-playlist-editor .dropdown {
display: unset !important;
}
.a-select-file > *:not(:last-child) {
margin-bottom: 0.6rem;
}
@ -2782,6 +2786,9 @@ a.navbar-item:focus, a.navbar-item:focus-within, a.navbar-item:hover, a.navbar-i
color: var(--button-fg);
background-color: var(--button-bg);
}
#player .button.square, #player a.button.square, #player button.button.square, .ax .button.square, .ax a.button.square, .ax button.button.square {
min-width: 2.5rem;
}
#player .button.secondary, #player a.button.secondary, #player button.button.secondary, .ax .button.secondary, .ax a.button.secondary, .ax button.button.secondary {
background-color: var(--button-sec-bg);
}
@ -2792,10 +2799,10 @@ a.navbar-item:focus, a.navbar-item:focus-within, a.navbar-item:hover, a.navbar-i
vertical-align: middle;
}
#player .button .icon:not(:only-child):first-child, #player a.button .icon:not(:only-child):first-child, #player button.button .icon:not(:only-child):first-child, .ax .button .icon:not(:only-child):first-child, .ax a.button .icon:not(:only-child):first-child, .ax button.button .icon:not(:only-child):first-child {
margin-right: 0.6rem;
margin: 0 0.6rem 0 0.2rem;
}
#player .button .icon:not(:only-child):last-child, #player a.button .icon:not(:only-child):last-child, #player button.button .icon:not(:only-child):last-child, .ax .button .icon:not(:only-child):last-child, .ax a.button .icon:not(:only-child):last-child, .ax button.button .icon:not(:only-child):last-child {
margin-left: 0.6rem;
margin: 0 0.6rem 0 0.2rem;
}
#player .button:hover, #player a.button:hover, #player button.button:hover, .ax .button:hover, .ax a.button:hover, .ax button.button:hover {
color: var(--button-hv-fg);
@ -9550,11 +9557,17 @@ a.tag:hover {
text-align: left;
justify-content: left;
}
.align-left.x {
padding-left: 0px !important;
}
.align-right {
text-align: right;
justify-content: right;
}
.align-right.x {
padding-right: 0px !important;
}
.clear-left {
clear: left !important;

View File

@ -533,6 +533,10 @@
overflow: hidden;
}
.a-playlist-editor .dropdown {
display: unset !important;
}
.a-select-file > *:not(:last-child) {
margin-bottom: 0.6rem;
}
@ -626,6 +630,9 @@
color: var(--button-fg);
background-color: var(--button-bg);
}
.button.square, a.button.square, button.button.square {
min-width: 2.5rem;
}
.button.secondary, a.button.secondary, button.button.secondary {
background-color: var(--button-sec-bg);
}
@ -636,10 +643,10 @@
vertical-align: middle;
}
.button .icon:not(:only-child):first-child, a.button .icon:not(:only-child):first-child, button.button .icon:not(:only-child):first-child {
margin-right: 0.6rem;
margin: 0 0.6rem 0 0.2rem;
}
.button .icon:not(:only-child):last-child, a.button .icon:not(:only-child):last-child, button.button .icon:not(:only-child):last-child {
margin-left: 0.6rem;
margin: 0 0.6rem 0 0.2rem;
}
.button:hover, a.button:hover, button.button:hover {
color: var(--button-hv-fg);
@ -719,7 +726,7 @@
}
@media screen and (min-width: 600px) {
textarea {
comment.textarea {
height: 7rem !important;
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,37 +1,8 @@
{% extends "aircox/basepage_detail.html" %}
{% extends "./page_form.html" %}
{% load static i18n humanize honeypot aircox %}
{% block head_extra %}
<script type="text/javascript" src="{% static "aircox/js/admin.js" %}"></script>
<script type="text/javascript" src="{% static "aircox/js/ckeditor-init.js" %}"></script>
<!-- <script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script> -->
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
{% endblock %}
{% block init-scripts %}
aircox.init(null, {hotReload:false, initPlayer:false, initApp:true})
initialiseCKEditor()
initialiseCKEditorInInlinedForms()
{% endblock %}
{% block comments %}
{% endblock %}
{% block content-container %}
<section class="container">
<form method="post" enctype="multipart/form-data">{% csrf_token %}
<table>
{{ form.as_table }}
{% render_honeypot_field "website" %}
</table>
<br/>
<input type="submit" value="Update" class="button is-success">
<hr>
{% include "aircox/playlist_inline.html" %}
<input type="submit" value="Update" class="button is-success">
</form>
</section>
{% block page_form %}
{{ block.super }}
<hr/>
{% include "./widgets/playlist_editor.html" with formset=playlist_formset %}
{% endblock %}

View File

@ -19,6 +19,7 @@
<a-modal ref="cover-modal" title="{% translate "Select an image" %}">
<template #default>
<a-select-file list-url="{% url "api:image-list" %}" upload-url="{% url "api:image-list" %}"
list-class="grid-4"
prev-label="{% translate "Show previous" %}"
next-label="{% translate "Show next" %}"
ref="cover-select"
@ -48,11 +49,12 @@
<section class="container">
<form method="post" enctype="multipart/form-data">
{% block page_form %}
{% csrf_token %}
{% for field in form %}
<div class="field">
{% if field.name == "cover" %}
<input type="hidden" name="{{ field.name }}" value="{{ field.pk }}" ref="cover-input"/>
<input type="hidden" name="{{ field.name }}" value="{{ field.value }}" ref="cover-input"/>
{% else %}
<label class="label">{{ field.label }}</label>
<div class="control clear-unset">
@ -74,7 +76,9 @@
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
{% endfor %}
{% endblock %}
<hr/>
<div class="has-text-right">
<button type="submit" class="button">{% translate "Update" %}</button>
</div>

View File

@ -4,8 +4,11 @@
{% if user.is_authenticated %}
{{ object.get_status_display }}
{% if object.pub_date %}
({{ object.pub_date|date:"d/m/Y H:i" }})
{% endif %}
{% endif %}
{% if user.is_authenticated and can_edit %}
{% with request.resolver_match.view_name as view_name %}

View File

@ -1,17 +1,23 @@
{% comment %}Inline block to edit playlists{% endcomment %}
{% comment %}
Context:
- formset: playlist's track formset
{% endcomment %}
{% load aircox aircox_admin static i18n %}
<div id="inline-tracks" class="box mb-5">
{% with formset.form.fields as fields %}
<div id="inline-tracks">
{{ formset.non_form_errors }}
<!-- formset.management_form -->
<a-playlist-editor
:labels="{% track_inline_labels %}"
:init-data="{% track_inline_data formset=formset %}"
:default-columns="[{% for f in fields %}{% if f != "position" %}'{{ f }}',{% endif %}{% endfor %}]"
settings-url="{% url "api:user-settings" %}"
data-prefix="{{ formset.prefix }}-">
<template #title>
<h5 class="title is-4">{% trans "Playlist" %}</h5>
<h3 class="title is-2">{% trans "Playlist" %}</h3>
</template>
<template #top="{items}">
<input type="hidden" name="{{ formset.prefix }}-TOTAL_FORMS"
@ -42,7 +48,7 @@
:value="item.data.id || item.id"/>
{% for field in fields %}
{% if field != 'position' %}
{% if field != 'position' and field.widget.is_hidden %}
<input type="hidden"
:name="'{{ formset.prefix }}-' + row + '-{{ field.name }}'"
v-model="item.data[attr]"/>
@ -51,6 +57,7 @@
</td>
</template>
{% for field in fields %}
{% if not field.widget.is_hidden and not field.is_readonly %}
<template v-slot:row-{{ field }}="{item,cell,value,attr,emit}">
<div class="field">
<a-autocomplete
@ -65,6 +72,8 @@
</p>
</div>
</template>
{% endif %}
{% endfor %}
</a-playlist-editor>
</div>
{% endwith %}

View File

@ -52,8 +52,8 @@ class EpisodeUpdateView(UserPassesTestMixin, BaseProgramMixin, PageUpdateView):
form_class = EpisodeForm
template_name = "aircox/episode_form.html"
def get_sidebar_queryset(self):
return super().get_sidebar_queryset().filter(parent=self.program)
playlist_fields = ("position", "artist", "title", "tags", "album", "info")
"""Playlist editor's ordered fields."""
def test_func(self):
program = self.get_object().program
@ -62,20 +62,17 @@ class EpisodeUpdateView(UserPassesTestMixin, BaseProgramMixin, PageUpdateView):
def get_success_url(self):
return reverse("episode-detail", kwargs={"slug": self.get_object().slug})
def get_object(self, queryset=None):
obj = Episode.objects.get(pk=self.kwargs["pk"])
return obj
def get_playlist_queryset(self, episode):
return Track.objects.filter(episode=episode)
def get_formset(self, *args, **kwargs):
fields = ("position", "artist", "title", "tags", "album", "year", "info")
TrackFormSet = modelformset_factory(Track, fields=fields, extra=0)
return TrackFormSet(*args, **kwargs)
def get_playlist_formset(self, episode, **kwargs):
kwargs["queryset"] = self.get_playlist_queryset(episode)
TrackFormSet = modelformset_factory(Track, fields=self.playlist_fields, extra=0)
return TrackFormSet(**kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["fields"] = ("position", "artist", "title", "tags", "album", "year", "info")
context["formset"] = self.get_formset(queryset=Track.objects.filter(episode=self.object))
return context
kwargs["playlist_formset"] = self.get_playlist_formset(self.object)
return super().get_context_data(**kwargs)
def post(self, request, *args, **kwargs):
super().post(request, *args, **kwargs)

View File

@ -3,7 +3,7 @@
<span v-if="promise && runIcon">
<i :class="runIcon"></i>
</span>
<span v-else-if="icon" class="icon">
<span v-else-if="icon" class="icon is-small">
<i :class="icon"></i>
</span>
<span v-if="$slots.default"><slot name="default"/></span>

View File

@ -1,11 +1,11 @@
<template>
<div class="playlist-editor">
<div class="columns">
<div class="column">
<div class="a-playlist-editor">
<div class="flex-row">
<div class="flex-grow-1">
<slot name="title" />
</div>
<div class="column has-text-right">
<div class="float-right field has-addons">
<div class="flex-row align-right">
<div class="field has-addons">
<p class="control">
<a :class="['button','p-2', page == Page.Text ? 'is-primary' : 'is-light']"
@click="page = Page.Text">
@ -28,13 +28,13 @@
</div>
</div>
<slot name="top" :set="set" :columns="columns" :items="items"/>
<section class="page" v-show="page == Page.Text">
<section v-show="page == Page.Text" class="panel">
<textarea ref="textarea" class="is-fullwidth is-size-6" rows="20"
@change="updateList"
/>
</section>
<section class="page" v-show="page == Page.List">
<section v-show="page == Page.List" class="panel">
<a-rows :set="set" :columns="columns" :labels="labels"
:allow-create="true"
:orderable="true" @move="listItemMove" @colmove="columnMove"
@ -46,9 +46,9 @@
<template v-slot:row-tail="data">
<slot v-if="$slots['row-tail']" :name="row-tail" v-bind="data"/>
<td>
<a class="button is-danger is-outlined p-3 is-size-6"
@click="items.splice(data.row,1)"
<td class="align-right pr-0">
<a class="button square"
@click.stop="items.splice(data.row,1)"
:title="labels.remove_track"
:aria-label="labels.remove_track">
<span class="icon"><i class="fa fa-trash" /></span>
@ -58,35 +58,45 @@
</a-rows>
</section>
<div class="mt-2">
<div class="float-right">
<a class="button is-warning p-2 ml-2"
@click="loadData({items: this.initData.items},true)">
<div class="flex-row">
<div class="flex-grow-1 flex-row">
<div class="field ml-3">
<p class="control">
<a class="button is-info"
@click="$refs.settings.open()">
<span class="icon is-small">
<i class="fa fa-cog"></i>
</span>
<span>Options</span>
</a>
</p>
</div>
</div>
<div class="flex-grow-1 align-right">
<a class="button square is-warning p-2"
@click="loadData({items: this.initData.items},true)"
:title="labels.discard_changes"
:aria-label="labels.discard_changes"
>
<span class="icon"><i class="fa fa-rotate" /></span>
<span>{{ labels.discard_changes }}</span>
</a>
<a class="button is-primary p-2 ml-2" t-if="page == page.List"
@click="this.set.push(new this.set.model())">
<a class="button square is-primary p-2" v-if="page == Page.List"
@click="this.set.push(new this.set.model())"
:title="labels.add_track"
:aria-label="labels.add_track"
>
<span class="icon"><i class="fa fa-plus"/></span>
<span>{{ labels.add_track }}</span>
</a>
</div>
<div class="field is-inline-block is-vcentered mr-3">
<label class="label is-inline mr-2"
style="vertical-align: middle">
Séparateur</label>
<div class="control is-inline-block"
style="vertical-align: middle;">
<input type="text" ref="sep" class="input is-inline is-text-centered is-small"
style="max-width: 5em;"
v-model="separator" @change="updateList()"/>
</div>
</div>
<div class="field is-inline-block is-vcentered mr-3">
<label class="label is-inline mr-2"
style="vertical-align: middle">
{{ labels.columns }}</label>
<table class="table is-bordered is-inline-block"
<a-modal ref="settings" title="Options">
<template #default>
<div class="field">
<label class="label" style="vertical-align: middle">
{{ labels.columns }}
</label>
<table class="table is-bordered"
style="vertical-align: middle">
<tr>
<a-row :columns="columns" :item="labels"
@ -102,18 +112,38 @@
</tr>
</table>
</div>
<div class="field is-vcentered is-inline-block"
v-if="settingsChanged">
<div class="flex-row">
<div class="field is-inline-block is-vcentered flex-grow-1">
<label class="label is-inline mr-2"
style="vertical-align: middle">
Séparateur</label>
<div class="control is-inline-block"
style="vertical-align: middle;">
<input type="text" ref="sep" class="input is-inline is-text-centered is-small"
style="max-width: 5em;"
v-model="separator" @change="updateList()"/>
</div>
</div>
</div>
</template>
<template #footer>
<div class="flex-row align-right">
<a-action-button icon="fa fa-floppy-disk"
class="button control p-3 is-info" run-class="blink"
v-if="settingsChanged"
class="button control p-2 mr-3 is-secondary" run-class="blink"
:url="settingsUrl" method="POST"
:data="settings"
:aria-label="labels.save_settings"
@done="settingsSaved()">
{{ labels.save_settings }}
</a-action-button>
<button class="button" type="button" @click="$refs.settings.close()">
Fermer
</button>
</div>
</div>
</template>
</a-modal>
<slot name="bottom" :set="set" :columns="columns" :items="items"/>
</div>
</template>
@ -123,8 +153,9 @@ import {Set} from '../model'
import Track from '../track'
import AActionButton from './AActionButton'
import ARow from './ARow.vue'
import ARows from './ARows.vue'
import ARow from './ARow'
import ARows from './ARows'
import AModal from "./AModal"
/// Page display
export const Page = {
@ -132,7 +163,7 @@ export const Page = {
}
export default {
components: { AActionButton, ARow, ARows },
components: { AActionButton, ARow, ARows, AModal },
props: {
initData: Object,
dataPrefix: String,
@ -297,6 +328,8 @@ export default {
settingsSaved(settings=null) {
if(settings !== null)
this.settings = settings
if(this.$refs.settings)
this.$refs.settings.close()
this.savedSettings = cloneDeep(this.settings)
},

View File

@ -1,7 +1,7 @@
<template>
<div class="a-select-file">
<div class="a-select-file-list" ref="list">
<div class="flex-column file-preview">
<div :class="['a-select-file-list', listClass]" ref="list">
<div class="flex-column">
<div class="field flex-grow-1" v-if="!uploadFile">
<label class="label">{{ uploadLabel }}</label>
<input type="file" @change="previewFile"/>
@ -51,6 +51,7 @@ import {getCsrf} from "../model"
export default {
props: {
name: { type: String },
listClass: {type: String, default: ""},
prevLabel: { type: String, default: "Prev" },
nextLabel: { type: String, default: "Next" },
listUrl: { type: String },
@ -88,7 +89,7 @@ export default {
formData.append('file', this.uploadFile.file)
formData.append('original_filename', this.uploadFile.file.name)
formData.append('csrfmiddlewaretoken', getCsrf())
fetch(this.listUrl, {
fetch(this.uploadUrl, {
method: "POST",
body: formData
}).then(

View File

@ -4,10 +4,18 @@ import './index.js'
import App from './app';
import {dashboard as components} from './components'
const AdminApp = {
const DashboardApp = {
...App,
components: {...App.components, ...components},
/*
data() {
return {
editPageContent: null,
}
},
*/
methods: {
...App.methods,
@ -22,7 +30,7 @@ const AdminApp = {
},
}
}
export default AdminApp;
export default DashboardApp;
window.App = AdminApp
window.App = DashboardApp

View File

@ -162,9 +162,8 @@
color: var(--button-fg);
background-color: var(--button-bg);
&.secondary {
background-color: var(--button-sec-bg);
}
&.square { min-width: 2.5rem; }
&.secondary { background-color: var(--button-sec-bg); }
.label, label {
cursor: pointer;
@ -173,8 +172,8 @@
.icon {
vertical-align: middle;
&:not(:only-child) {
&:first-child { margin-right: v.$mp-3; }
&:last-child { margin-left: v.$mp-3 }
&:first-child { margin: 0 v.$mp-3 0 v.$mp-1; }
&:last-child { margin: 0 v.$mp-3 0 v.$mp-1; }
}
}
@ -710,6 +709,14 @@
}
}
/// ---- playlist editor
.a-playlist-editor {
.dropdown {
display: unset !important;
}
}
/// ----------------
.a-select-file {
> *:not(:last-child) {

View File

@ -3,8 +3,18 @@
.text-light { weight: 400; color: var(--text-color-light); }
// ---- layout
.align-left { text-align: left; justify-content: left; }
.align-right { text-align: right; justify-content: right; }
.align-left {
text-align: left;
justify-content: left;
&.x { padding-left: 0px !important; }
}
.align-right {
text-align: right;
justify-content: right;
&.x { padding-right: 0px !important; }
}
.clear-left { clear: left !important }
.clear-right { clear: right !important }

View File

@ -117,7 +117,7 @@
}
@media screen and (min-width: v.$screen-small) {
textarea {
comment.textarea {
height: calc( v.$text-size * 7 ) !important;
}
}