107 lines
3.2 KiB
JavaScript
107 lines
3.2 KiB
JavaScript
module.exports = function ($scope, $timeout, dizquetv) {
|
|
$scope.showss = []
|
|
$scope.showShowConfig = false
|
|
$scope.selectedShow = null
|
|
$scope.selectedShowIndex = -1
|
|
|
|
$scope.refreshShow = async () => {
|
|
$scope.shows = [ { id: '?', pending: true} ]
|
|
$timeout();
|
|
let shows = await dizquetv.getAllShowsInfo();
|
|
$scope.shows = shows;
|
|
$timeout();
|
|
}
|
|
$scope.refreshShow();
|
|
|
|
|
|
|
|
let feedToShowConfig = () => {};
|
|
let feedToDeleteShow = feedToShowConfig;
|
|
|
|
$scope.registerShowConfig = (feed) => {
|
|
feedToShowConfig = feed;
|
|
}
|
|
|
|
$scope.registerDeleteShow = (feed) => {
|
|
feedToDeleteShow = feed;
|
|
}
|
|
|
|
$scope.queryChannel = async (index, channel) => {
|
|
let ch = await dizquetv.getChannelDescription(channel.number);
|
|
ch.pending = false;
|
|
$scope.shows[index] = ch;
|
|
$scope.$apply();
|
|
}
|
|
|
|
$scope.onShowConfigDone = async (show) => {
|
|
if ($scope.selectedChannelIndex != -1) {
|
|
$scope.shows[ $scope.selectedChannelIndex ].pending = false;
|
|
}
|
|
if (typeof show !== 'undefined') {
|
|
// not canceled
|
|
if ($scope.selectedChannelIndex == -1) { // add new channel
|
|
await dizquetv.createShow(show);
|
|
} else {
|
|
$scope.shows[ $scope.selectedChannelIndex ].pending = true;
|
|
await dizquetv.updateShow(show.id, show);
|
|
}
|
|
await $scope.refreshShow();
|
|
}
|
|
}
|
|
$scope.selectShow = async (index) => {
|
|
try {
|
|
if ( (index != -1) && $scope.shows[index].pending) {
|
|
return;
|
|
}
|
|
$scope.selectedChannelIndex = index;
|
|
if (index === -1) {
|
|
feedToShowConfig();
|
|
} else {
|
|
$scope.shows[index].pending = true;
|
|
let f = await dizquetv.getShow($scope.shows[index].id);
|
|
feedToShowConfig(f);
|
|
$timeout();
|
|
}
|
|
} catch( err ) {
|
|
console.error("Could not fetch show.", err);
|
|
}
|
|
}
|
|
|
|
$scope.deleteShow = async (index) => {
|
|
try {
|
|
if ( $scope.shows[index].pending) {
|
|
return;
|
|
}
|
|
$scope.deleteShowIndex = index;
|
|
$scope.shows[index].pending = true;
|
|
let id = $scope.shows[index].id;
|
|
let channels = await dizquetv.getChannelsUsingShow(id);
|
|
feedToDeleteShow( {
|
|
id: id,
|
|
name: $scope.shows[index].name,
|
|
channels : channels,
|
|
} );
|
|
$timeout();
|
|
|
|
} catch (err) {
|
|
console.error("Could not start delete show dialog.", err);
|
|
}
|
|
|
|
}
|
|
|
|
$scope.onShowDelete = async( id ) => {
|
|
try {
|
|
$scope.shows[ $scope.deleteShowIndex ].pending = false;
|
|
$timeout();
|
|
if (typeof(id) !== 'undefined') {
|
|
$scope.shows[ $scope.deleteShowIndex ].pending = true;
|
|
await dizquetv.deleteShow(id);
|
|
$timeout();
|
|
await $scope.refreshShow();
|
|
$timeout();
|
|
}
|
|
} catch (err) {
|
|
console.error("Error attempting to delete show", err);
|
|
}
|
|
}
|
|
} |