import { Prize } from '../../../../src/types' ; import { InterviewPrizePlaylist } from '../../../../src/types/schemas/interview_prizePlaylist' ; const { customElement , property } = Polymer . decorators ; const allPrizesRep = nodecg . Replicant < Prize [ ] > ( 'allPrizes' ) ; const prizePlaylistRep = nodecg . Replicant < InterviewPrizePlaylist > ( 'interview_prizePlaylist' ) ; customElement polymer appliesMixin @ customElement ( 'dash-interview-prizes' ) export default class DashInterviewPrizesElement extends Polymer . MutableData ( Polymer . Element ) { @ property ( { type : Array } ) allPrizes : Prize [ ] ; @ property ( { type : Array } ) prizePlaylist : InterviewPrizePlaylist ; @ property ( { type : String } ) searchString = '' ; ready ( ) { super . ready ( ) ; allPrizesRep . on ( 'change' , newVal => { this . allPrizes = newVal ; } ) ; prizePlaylistRep . on ( 'change' , newVal => { this . prizePlaylist = newVal ; } ) ; } clearFilter ( ) { this . searchString = '' ; } addPrizeToPlayList ( prizeOrPrizeId ) { const prizeId = disambiguatePrizeId ( prizeOrPrizeId ) ; nodecg . sendMessage ( 'interview:addPrizeToPlaylist' , prizeId ) ; } removePrizeFromPlaylist ( prizeOrPrizeId ) { const prizeId = disambiguatePrizeId ( prizeOrPrizeId ) ; nodecg . sendMessage ( 'interview:removePrizeFromPlaylist' , prizeId ) ; } clearPlaylist ( ) { nodecg . sendMessage ( 'interview:clearPrizePlaylist' ) ; } _calcClearIconHidden ( searchString ) { return ! searchString || searchString . length <= 0 ; } _calcPrizesToList ( allPrizes ? , searchString ? ) { if ( ! allPrizes || allPrizes . length <= 0 ) { return [ ] ; } if ( ! searchString || searchString . trim ( ) . length === 0 ) { return allPrizes ; } return allPrizes . filter ( prize => { return prize . description . toLowerCase ( ) . includes ( searchString . toLowerCase ( ) ) ; } ) ; } _isPrizeInPlaylist ( prizeOrPrizeId , prizePlaylist ) { if ( ! prizePlaylist ) { return false ; } const prizeId = disambiguatePrizeId ( prizeOrPrizeId ) ; return prizePlaylist . findIndex ( ( { id } ) => id === prizeId ) >= 0 ; } _calcClearPlaylistDisabled ( prizePlaylist ) { return ! prizePlaylist || prizePlaylist . length <= 0 ; } _handlePrizeListingAddTap ( e ) { this . addPrizeToPlayList ( e . model . prize ) ; } _handlePrizeListingRemoveTap ( e ) { this . removePrizeFromPlaylist ( e . model . prize ) ; } _calcPrizesInPlaylist ( allPrizes ? , prizePlaylist ? ) { if ( ! allPrizes || allPrizes . length === 0 || ! prizePlaylist || prizePlaylist . length === 0 ) { return [ ] ; } return prizePlaylist . map ( playlistEntry => { return allPrizes . find ( prize => { return prize . id === playlistEntry . id ; } ) ; } ) ; } _calcPlaylistPrizeChecked ( prize ? , prizePlaylist ? ) { if ( ! prize || ! prizePlaylist || prizePlaylist . length <= 0 ) { return false ; } console . log ( prize , prizePlaylist ) ; const playlistEntry = prizePlaylist . find ( pe => pe . id === prize . id ) ; if ( ! playlistEntry ) { return false ; } return playlistEntry . complete ; } } param prizeOrPrizeId returns function disambiguatePrizeId ( prizeOrPrizeId ? ) { return typeof prizeOrPrizeId === 'object' ? prizeOrPrizeId . id : prizeOrPrizeId ; }