Created
June 19, 2018 12:35
-
-
Save Sampath-Lokuge/eb230755199a9de455d08e26b100cf02 to your computer and use it in GitHub Desktop.
playlists.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { IonicPage, NavController, NavParams, ModalController, Platform, Loading } from 'ionic-angular'; | |
import { AppSetting } from '../../app/app.settings'; | |
import { PlayListProvider } from '../../providers/play-list/playlist-provider'; | |
import { PlayList } from '../../models/PlayList'; | |
import { LoadingProvider } from '../../providers/loading/loading'; | |
import { forEach } from 'lodash'; | |
import { MediaItem } from '../../models/media-item'; | |
@IonicPage() | |
@Component({ | |
selector: 'page-playlists', | |
templateUrl: 'playlists.html', | |
}) | |
export class PlaylistsPage { | |
data: PlayList[] = []; type: string = "my"; mediaItem: MediaItem; newPlayListId: number; | |
constructor(public navCtrl: NavController, public navParams: NavParams, public appSettings: AppSetting, public platform: Platform, | |
private modalCtrl: ModalController, private playListProvider: PlayListProvider, private loadingProvider: LoadingProvider) { | |
this.init(); | |
this.playListProvider.playlistUpdates.subscribe((set) => { | |
if(set){ | |
console.log("hitUpdates"); | |
const loading = this.loadingProvider.presentLoader(); | |
this.getDistributorPlaylists(loading); | |
} | |
}) | |
} | |
init() { | |
this.platform.ready().then(() => { | |
this.appSettings.initTranslateService(); | |
}); | |
} | |
ionViewDidEnter() { | |
const loading = this.loadingProvider.presentLoader(); | |
if(typeof this.navParams.get('type') !== "undefined"){ | |
this.type = this.navParams.get('type'); | |
} | |
if (this.type == "my") { | |
this.getDistributorPlaylists(loading); | |
} else { | |
this.getCorporatePlaylists(loading); | |
} | |
} | |
//get Corporate Play lists | |
getCorporatePlaylists(loading: Loading) { | |
this.playListProvider.getCorporatePlaylists().subscribe( | |
result => { | |
this.setData(result); | |
this.loadingProvider.dismissLoader(loading); | |
}, | |
error => { this.loadingProvider.dismissLoader(loading); }, | |
() => { } | |
); | |
} | |
//get Distributor Play lists | |
getDistributorPlaylists(loading: Loading) { | |
this.playListProvider.getDistributorPlaylists().subscribe( | |
result => { | |
this.setData(result); | |
this.loadingProvider.dismissLoader(loading); | |
}, | |
error => { this.loadingProvider.dismissLoader(loading); }, | |
() => { } | |
); | |
} | |
//add Playlist | |
addPlaylist() { | |
const modal = this.modalCtrl.create('NewPlaylistPage'); | |
modal.onDidDismiss(data => { | |
}); | |
modal.present(); | |
} | |
//play List Changed | |
playListChanged() { | |
const loading = this.loadingProvider.presentLoader(); | |
if (this.type == "corporate") { | |
this.getCorporatePlaylists(loading); | |
} else { | |
this.getDistributorPlaylists(loading); | |
} | |
} | |
//set Data | |
setData(result: any): PlayList[] { | |
this.data = []; | |
forEach(result, (v) => { | |
let image:string; | |
if(v.Thumbnail){ | |
image = v.Thumbnail; | |
} | |
else{ | |
image = './assets/images/placeholder2'; | |
} | |
const playList: PlayList = { | |
id: v.PlayListId, | |
text: v.ResourceValue, | |
imageUrl: image, | |
mediaItems: [] | |
}; | |
this.data.push(playList); | |
}); | |
return this.data; | |
} | |
//select PlayList | |
selectPlayList(event: any) { | |
let data = event; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment