Compare commits

..

3 Commits

Author SHA1 Message Date
bkfox
fd7b504d01 styling 2022-03-20 12:24:11 +01:00
bkfox
65a6c9f90c autocomplete & form reset 2022-03-20 11:59:51 +01:00
bkfox
17512d14b8 autcomplete field in streamer 2022-03-20 11:48:03 +01:00
10 changed files with 105 additions and 49 deletions

View File

@ -100,7 +100,7 @@ class Sound(models.Model):
def _upload_to(self, filename): def _upload_to(self, filename):
subdir = AIRCOX_SOUND_ARCHIVES_SUBDIR if self.type == self.TYPE_ARCHIVE else \ subdir = AIRCOX_SOUND_ARCHIVES_SUBDIR if self.type == self.TYPE_ARCHIVE else \
AIRCOX_SOUND_EXCERPTS_SUBDIR AIRCOX_SOUND_EXCERPTS_SUBDIR
return os.path.join(o.program.path, subdir, filename) return os.path.join(self.program.path, subdir, filename)
file = models.FileField( file = models.FileField(
_('file'), upload_to=_upload_to _('file'), upload_to=_upload_to

View File

@ -10648,6 +10648,22 @@ a.has-text-danger-dark:hover, a.has-text-danger-dark:focus {
opacity: 1; opacity: 1;
} }
.float-right {
float: right;
}
.float-left {
float: left;
}
.overflow-hidden {
overflow: hidden;
}
.overflow-hidden.is-fullwidth {
max-width: 100%;
}
.navbar + .container { .navbar + .container {
margin-top: 1em; margin-top: 1em;
} }

File diff suppressed because one or more lines are too long

View File

@ -107,7 +107,7 @@ Usefull context:
{% block main %} {% block main %}
{% block content %} {% block content %}
{% if page and page.content %} {% if page and page.content %}
<section class="page-content">{{ page.content|safe }}</section> <section class="page-content mb-2">{{ page.content|safe }}</section>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% endblock main %} {% endblock main %}

View File

@ -40,7 +40,7 @@ Context:
<div class="media box"> <div class="media box">
<div class="media-content"> <div class="media-content">
<p> <p>
<strong>{{ comment.nickname }}</strong> <strong class="mr-2">{{ comment.nickname }}</strong>
<time datetime="{{ comment.date }}" title="{{ comment.date }}"> <time datetime="{{ comment.date }}" title="{{ comment.date }}">
<small>{{ comment.date|naturaltime }}</small> <small>{{ comment.date|naturaltime }}</small>
</time> </time>

View File

@ -47,11 +47,11 @@
<div v-if="source.isQueue"> <div v-if="source.isQueue">
<hr> <hr>
<h6 class="title is-6 is-marginless">{% trans "Add sound" %}</h6> <h6 class="title is-6">{% trans "Add sound" %}</h6>
<form class="columns" @submit.prevent="source.push($event.target.elements['sound_id'].value)"> <form @submit.prevent="source.push($event.target.elements['sound_id'].value); $event.target.reset()">
<div class="column field is-small"> <div class="field is-grouped">
{# TODO: select station => change the shit #} {# TODO: select station => change the shit #}
<a-autocomplete class="is-fullwidth" <a-autocomplete class="control is-expanded"
url="{% url "aircox:sound-list" %}?station={{ station.pk }}&search=${query}" url="{% url "aircox:sound-list" %}?station={{ station.pk }}&search=${query}"
name="sound_id" :model="Sound" label-field="name" name="sound_id" :model="Sound" label-field="name"
placeholder="{% trans "Select a sound" %}"> placeholder="{% trans "Select a sound" %}">
@ -59,20 +59,20 @@
[[ item.data.name ]] [[ item.data.name ]]
<span class="is-size-7 is-italic has-text-info">[[ item.data.file ]]</span> <span class="is-size-7 is-italic has-text-info">[[ item.data.file ]]</span>
</template> </template>
</a-autocomplete> </a-autocomplete>
<p class="help"> <div class="control">
{% trans "Add a sound to the queue (queue may start playing)" %} <button type="submit" class="button is-primary">
</p> <span class="icon">
{# TODO: help text about how it works #} <span class="fas fa-plus"></span>
</div> </span>
<div class="column control is-one-fifth"> <span>{% trans "Add" %}</span>
<button type="submit" class="button is-primary"> </button>
<span class="icon"> </div>
<span class="fas fa-plus"></span>
</span>
<span>{% trans "Add" %}</span>
</button>
</div> </div>
<p class="help">
{% trans "Add a sound to the queue (queue may start playing)" %}
</p>
{# TODO: help text about how it works #}
</form> </form>
<div v-if="source.queue.length"> <div v-if="source.queue.length">

View File

@ -24,8 +24,8 @@ aircox.init({apiUrl: "{% url "admin:api:streamer-list" %}"},
</span> </span>
</div> </div>
<div class="navbar-end"> <div class="navbar-end">
<div class="select navbar-item"> <div class="control navbar-item">
<select onchange="selectStreamer" class="control" <select onchange="selectStreamer" class="select"
title="{% trans "Select a station" %}" title="{% trans "Select a station" %}"
aria-label="{% trans "Select a station" %}"> aria-label="{% trans "Select a station" %}">
<option v-for="streamer of streamers" :value="streamer.id">[[ streamer.data.name ]]</option> <option v-for="streamer of streamers" :value="streamer.id">[[ streamer.data.name ]]</option>

View File

@ -31,6 +31,11 @@ $body-background-color: $light;
} }
} }
.float-right { float: right }
.float-left { float: left }
.overflow-hidden { overflow: hidden }
.overflow-hidden.is-fullwidth { max-width: 100%; }
//-- navbar //-- navbar
.navbar + .container { .navbar + .container {
margin-top: 1em; margin-top: 1em;

View File

@ -1,19 +1,32 @@
<template> <template>
<div :class="dropdownClass"> <div :class="dropdownClass">
<div class="dropdown-trigger is-fullwidth"> <div class="dropdown-trigger is-fullwidth">
<div class="control is-expanded"> <input type="hidden" :name="name"
<input type="hidden" :name="name" :value="selectedValue" />
:value="selectedValue" /> <div v-show="!selected" class="control is-expanded">
<input type="text" :placeholder="placeholder" <input type="text" :placeholder="placeholder"
ref="input" class="input is-fullwidth" ref="input" class="input is-fullwidth"
@keyup="onKeyUp" @focus="active=true" @click="active=true"/> @keydown.capture="onKeyPress"
@keyup="onKeyUp" @focus="this.cursor < 0 && move(0)"/>
</div> </div>
<button v-if="selected" class="button is-normal is-fullwidth has-text-left is-inline-block overflow-hidden"
@click="select(-1, false, true)">
<span class="icon is-small ml-1">
<i class="fa fa-pen"></i>
</span>
<span class="is-inline-block" v-if="selected">
<slot name="button" :index="selectedIndex" :item="selected"
:value-field="valueField" :labelField="labelField">
{{ selected.data[labelField] }}
</slot>
</span>
</button>
</div> </div>
<div class="dropdown-menu is-fullwidth"> <div class="dropdown-menu is-fullwidth">
<div class="dropdown-content" style="overflow: hidden"> <div class="dropdown-content" style="overflow: hidden">
<a v-for="(item, index) in items" :key="item.id" <a v-for="(item, index) in items" :key="item.id"
:class="['dropdown-item', index === this.selectedIndex ? 'is-active':'']" :class="['dropdown-item', (index == this.cursor) ? 'is-active':'']"
@click="select(index); active=false" :title="item.data[labelField]"> @click.capture.prevent="select(index, false, false)" :title="item.data[labelField]">
<slot name="item" :index="index" :item="item" :value-field="valueField" <slot name="item" :index="index" :item="item" :value-field="valueField"
:labelField="labelField"> :labelField="labelField">
{{ item.data[labelField] }} {{ item.data[labelField] }}
@ -40,10 +53,10 @@ export default {
data() { data() {
return { return {
active: false,
value: '', value: '',
items: [], items: [],
selectedIndex: -1, selectedIndex: -1,
cursor: -1,
isFetching: false, isFetching: false,
} }
}, },
@ -69,13 +82,19 @@ export default {
}, },
dropdownClass() { dropdownClass() {
const active = this.active && this.items.length; const active = this.cursor > -1 && this.items.length;
return ['dropdown', active ? 'is-active':''] return ['dropdown', active ? 'is-active':'']
}, },
}, },
methods: { methods: {
select(index, relative) { move(index=-1, relative=false) {
if(relative)
index += this.cursor
this.cursor = Math.max(-1, Math.min(index, this.items.length-1))
},
select(index=-1, relative=false, active=null) {
if(relative) if(relative)
index += this.selectedIndex index += this.selectedIndex
else if(index == this.selectedIndex) else if(index == this.selectedIndex)
@ -86,28 +105,39 @@ export default {
this.$refs.input.value = this.selectedLabel this.$refs.input.value = this.selectedLabel
this.$refs.input.focus() this.$refs.input.focus()
} }
this.$emit('select', index, this.selected, this.selectedValue) if(this.selectedIndex < 0)
this.$emit('unselect')
else
this.$emit('select', index, this.selected, this.selectedValue)
if(active!==null)
active && this.move(0) || this.move(-1)
},
onKeyPress: function(event) {
switch(event.keyCode) {
case 13: this.select(this.cursor, false, false)
break
case 27: this.select()
break
case 38: this.move(-1, true)
break
case 40: this.move(1, true)
break
default: return
}
event.preventDefault()
event.stopPropagation()
}, },
onKeyUp: function(event) { onKeyUp: function(event) {
this.active = true
switch(event.keyCode) {
case 27: this.active = false
return
case 38: this.select(-1, true)
return
case 40: this.select(1, true)
return
}
const value = event.target.value const value = event.target.value
if(value === this.value) if(value === this.value)
return return
this.value = value; this.value = value;
if(!value) if(!value)
return this.select(null) return this.selected && this.select(-1)
this.fetch(value) this.fetch(value)
}, },
@ -120,11 +150,16 @@ export default {
return this.model.fetch(this.url.replace('${query}', query), {many:true}) return this.model.fetch(this.url.replace('${query}', query), {many:true})
.then(items => { this.items = items || [] .then(items => { this.items = items || []
this.isFetching = false this.isFetching = false
this.active = items.length > 0 this.move(0)
return items }, return items },
data => {this.isFetching = false; Promise.reject(data)}) data => {this.isFetching = false; Promise.reject(data)})
}, },
}, },
mounted() {
const form = this.$el.closest('form')
form.addEventListener('reset', () => { this.value=''; this.select(-1) })
}
} }
</script> </script>

View File

@ -40,7 +40,7 @@
<div class="media-content"> <div class="media-content">
<slot name="content" :loaded='loaded' :live='live'></slot> <slot name="content" :loaded='loaded' :live='live'></slot>
<AProgress v-if="loaded && duration" :value="currentTime" :max="this.duration" <AProgress v-if="loaded && duration" :value="currentTime" :max="this.duration"
:format="displayTime" :format="displayTime" class="pt-1 is-size-7"
@select="audio.currentTime = $event"></AProgress> @select="audio.currentTime = $event"></AProgress>
</div> </div>
<div class="media-right"> <div class="media-right">