dizquetv/web/controllers/channels.js
Dan Ferguson 681ab5f6c6 alpha v4
2020-04-23 16:11:40 -04:00

41 lines
1.4 KiB
JavaScript

module.exports = function ($scope, pseudotv) {
$scope.channels = []
$scope.showChannelConfig = false
$scope.selectedChannel = null
$scope.selectedChannelIndex = -1
pseudotv.getChannels().then((channels) => {
$scope.channels = channels
})
$scope.removeChannel = (channel) => {
pseudotv.removeChannel(channel).then((channels) => {
$scope.channels = channels
})
}
$scope.onChannelConfigDone = (channel) => {
if (typeof channel !== 'undefined') {
if ($scope.selectedChannelIndex == -1) { // add new channel
pseudotv.addChannel(channel).then((channels) => {
$scope.channels = channels
})
} else { // update existing channel
pseudotv.updateChannel(channel).then((channels) => {
$scope.channels = channels
})
}
}
$scope.showChannelConfig = false
}
$scope.selectChannel = (index) => {
if (index === -1) {
$scope.selectedChannel = null
$scope.selectedChannelIndex = -1
} else {
let newObj = JSON.parse(angular.toJson($scope.channels[index]))
newObj.startTime = new Date(newObj.startTime)
$scope.selectedChannel = newObj
$scope.selectedChannelIndex = index
}
$scope.showChannelConfig = true
}
}