A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
3
import VButton from '../element/button.js';4
import VIcon from '../element/icon.js';5
import VImage from '../element/image.js';6
import VStation from '../component/station.js';8
export default {9
data() {10
return {11
station: null,12
group: null,13
open: false14
};15
},16
components: {17
VButton,18
VIcon,17
VImage19
VImage,20
VStation21
},22
methods: {23
$lang,24
duration,25
async load(stationId) {26
this.station = await http`get::/api/station/${stationId}`();27
this.group = null;28
if(this.station.group_id) {29
this.group = await http`get::/api/group/${this.station.group_id}`();30
}31
this.open = true;32
},33
async setLike(is_favorite) {
200
<p class="-mt-[1px]">No track info</p>201
</span>202
</div>203
<div v-if="group" class="pt-6">204
<h4 class="text-white text-xl pb-5">{{$lang('detail.related')}}</h4>205
<ul class="flex flex-col">206
<li207
:key="station.id"208
v-for="group_station in group"209
v-if="station.id !== group_station.id"210
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"211
>212
<v-station :station="group_station"></v-station>213
</li>214
</ul>215
</div>216
</div>217
</div>218
</div>
1
/* ### station ### */1
/* ############################################################ */2
/* # station # */3
/* ############################################################ */5
CREATE TABLE station (6
id SERIAL PRIMARY KEY,
15
languages TEXT[],16
score INTEGER,17
description TEXT,16
color TEXT18
color TEXT,19
group_id INTEGER20
);19
/* ### station status ### */22
ALTER TABLE station23
ADD CONSTRAINT station_group_id24
FOREIGN KEY (group_id)25
REFERENCES station_group(id);27
/* ############################################################ */28
/* # station_group # */29
/* ############################################################ */31
CREATE TABLE station_group (32
id SERIAL PRIMARY KEY,33
name TEXT NOT NULL34
);36
/* ############################################################ */37
/* # station_status # */38
/* ############################################################ */40
CREATE TABLE station_status (41
id SERIAL PRIMARY KEY,
52
FOREIGN KEY (station_id)53
REFERENCES station(id);36
/* ### account ### */55
/* ############################################################ */56
/* # station_stats # */57
/* ############################################################ */59
CREATE TABLE station_stats (60
id SERIAL PRIMARY KEY,61
account_id INTEGER,62
station_id INTEGER,63
playtime INTEGER DEFAULT 0,64
latest_at TIMESTAMP WITH TIME ZONE DEFAULT now()65
);67
ALTER TABLE station_stats68
ADD CONSTRAINT station_stats_unique69
UNIQUE(account_id, station_id);71
ALTER TABLE station_stats72
ADD CONSTRAINT station_stats_account_id73
FOREIGN KEY (account_id)74
REFERENCES account(id);76
ALTER TABLE station_stats77
ADD CONSTRAINT station_stats_station_id78
FOREIGN KEY (station_id)79
REFERENCES station(id);81
/* ############################################################ */82
/* # account # */83
/* ############################################################ */85
CREATE TABLE account (86
id SERIAL PRIMARY KEY,
89
created_at TIMESTAMP WITH TIME ZONE DEFAULT now()90
);45
/* ### device ### */92
/* ############################################################ */93
/* # device # */94
/* ############################################################ */96
CREATE TABLE device (97
id SERIAL PRIMARY KEY,
106
FOREIGN KEY (account_id)107
REFERENCES account(id);60
/* ### favorite ### */109
/* ############################################################ */110
/* # favorite # */111
/* ############################################################ */113
CREATE TABLE favorite (114
id SERIAL PRIMARY KEY,
125
ADD CONSTRAINT favorite_station_id126
FOREIGN KEY (station_id)127
REFERENCES station(id);78
CREATE TABLE station_stats (79
id SERIAL PRIMARY KEY,80
account_id INTEGER,81
station_id INTEGER,82
playtime INTEGER DEFAULT 0,83
latest_at TIMESTAMP WITH TIME ZONE DEFAULT now()84
);86
ALTER TABLE station_stats87
ADD CONSTRAINT station_stats_unique88
UNIQUE(account_id, station_id);90
ALTER TABLE station_stats91
ADD CONSTRAINT station_stats_account_id92
FOREIGN KEY (account_id)93
REFERENCES account(id);95
ALTER TABLE station_stats96
ADD CONSTRAINT station_stats_station_id97
FOREIGN KEY (station_id)98
REFERENCES station(id);
55
pub is_icon: Option<bool>,56
pub playtime: Option<i32>,57
pub color: Option<String>,58
pub group_id: Option<i32>,59
}61
#[derive(Debug, Serialize, Deserialize, FromRow)]
272
Response::with(result)273
}275
pub async fn get_group(req: tide::Request<()>) -> tide::Result {276
let group_id = unwrap_result_or_throw!(req.param("id"), "no group id found!");277
let account =278
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");279
let sql = format!(280
r#"281
SELECT282
station.*,283
station_status.is_restricted,284
station_status.is_broken,285
station_status.is_no_track_info,286
station_status.is_hidden,287
station_status.is_icon,288
station_stats.playtime,289
CASE290
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}291
THEN false292
ELSE true293
END AS is_favorite294
FROM station295
LEFT JOIN favorite296
ON station.id = favorite.station_id297
LEFT JOIN station_status298
ON station.id = station_status.station_id299
LEFT JOIN station_stats300
ON station.id = station_stats.station_id301
AND station_stats.account_id = {account_id}302
WHERE station.group_id = {group_id}303
AND station_status.is_hidden IS NOT true304
"#,305
account_id = account.id,306
group_id = group_id,307
);308
let mut conn = req.sqlx_conn::<Postgres>().await;309
let result = sqlx::query_as::<_, model::Station>(&sql)310
.fetch_all(conn.acquire().await?)311
.await?;312
Response::with(result)313
}315
pub async fn get_countries(req: tide::Request<()>) -> tide::Result {316
let sql = r#"317
SELECT
58
app.at("/api/favorite").post(route::add_favorite);59
app.at("/api/favorite").delete(route::delete_favorite);60
app.at("/api/station/:id").get(route::get_station);61
app.at("/api/group/:id").get(route::get_group);62
app.at("/api/countries").get(route::get_countries);63
app.at("/api/languages").get(route::get_languages);64
app.at("/api/tags").get(route::get_tags);
40
}42
.transition-detail {43
transition: all ease-in-out 250ms;43
transition: all ease-in-out 180ms;44
}46
.modal-active {
45
"account.devices.current": "Current",46
"account.devices.add": "Add device",47
"detail.no-description": "No description available",48
"detail.playtime": "Playtime"48
"detail.playtime": "Playtime",49
"detail.related": "Related"50
},51
"de": {52
"global.none": "-",
94
"account.devices.current": "Aktuelles",95
"account.devices.add": "Gerät hinzufügen",96
"detail.no-description": "Keine Beschreibung vorhanden",96
"detail.playtime": "Spielzeit"97
"detail.playtime": "Spielzeit",98
"detail.related": "Zugehörig"99
}100
}