Skip to content

Commit 7aae29b

Browse files
committed
Support actions flow for Player config
1 parent b4da398 commit 7aae29b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/plugins/api/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,22 @@ export class MusicAssistantApi {
12181218
return this.sendCommand("config/players/get", { player_id });
12191219
}
12201220

1221+
public async getPlayerConfigEntries(
1222+
player_id: string,
1223+
action?: string,
1224+
values?: Record<string, ConfigValueType>,
1225+
): Promise<ConfigEntry[]> {
1226+
// Return Config entries to setup/configure a player.
1227+
// player_id: (mandatory) id of the player.
1228+
// action: [optional] action key called from config entries UI.
1229+
// values: the (intermediate) raw values for config entries sent with the action.
1230+
return this.sendCommand("config/players/get_entries", {
1231+
player_id,
1232+
action,
1233+
values,
1234+
});
1235+
}
1236+
12211237
public async getPlayerConfigValue(
12221238
player_id: string,
12231239
key: string,

src/views/settings/EditPlayer.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
:disabled="!config.enabled"
8484
:config-entries="config_entries"
8585
@submit="onSubmit"
86+
@action="onAction"
8687
/>
8788
</v-card-text>
8889
</section>
@@ -104,10 +105,13 @@ import {
104105
import EditConfig from "./EditConfig.vue";
105106
import { watch } from "vue";
106107
import { openLinkInNewTab } from "@/helpers/utils";
108+
import { nanoid } from "nanoid";
107109
108110
// global refs
109111
const router = useRouter();
110112
const config = ref<PlayerConfig>();
113+
const sessionId = nanoid(11);
114+
const loading = ref(false);
111115
112116
// props
113117
const props = defineProps<{
@@ -203,6 +207,37 @@ const onSubmit = async function (values: Record<string, ConfigValueType>) {
203207
router.push({ name: "playersettings" });
204208
};
205209
210+
const onAction = async function (
211+
action: string,
212+
values: Record<string, ConfigValueType>,
213+
) {
214+
loading.value = true;
215+
// append existing ConfigEntry values to allow
216+
// values be passed between flow steps
217+
for (const entry of Object.values(config.value!.values)) {
218+
if (entry.value !== undefined && values[entry.key] == undefined) {
219+
values[entry.key] = entry.value;
220+
}
221+
}
222+
// ensure the session id is passed along (for auth actions)
223+
values["session_id"] = sessionId;
224+
api
225+
.getPlayerConfigEntries(config.value!.player_id, action, values)
226+
.then((entries) => {
227+
config.value!.values = {};
228+
for (const entry of entries) {
229+
config.value!.values[entry.key] = entry;
230+
}
231+
})
232+
.catch((err) => {
233+
// TODO: make this a bit more fancy someday
234+
alert(err);
235+
})
236+
.finally(() => {
237+
loading.value = false;
238+
});
239+
};
240+
206241
const openDspConfig = function () {
207242
router.push(`/settings/editplayer/${props.playerId}/dsp`);
208243
};

0 commit comments

Comments
 (0)