import { Component , OnInit } from '@angular/core' ; import { Client } from '../../../services/api' ; import { FormToastService } from '../../../common/services/form-toast.service' ; @ Component ( { moduleId : module . id , selector : 'minds-admin-tagcloud' , templateUrl : 'tagcloud.component.html' , } ) export class AdminTagcloud implements OnInit { tags : string [ ] = [ ] ; age : number | boolean = false ; hidden : string [ ] = [ ] ; constructor ( private client , protected toasterService ) { } ngOnInit ( ) { this . load ( ) ; } load ( ) { this . client . get ( `api/v1/admin/tagcloud` ) . then ( ( { tags , age , hidden , } ) => { this . tags = tags ; this . age = < any > age !== false ? Math . floor ( age / 60 ) : false ; this . hidden = hidden ; } ) . catch ( e => { this . toasterService . error ( `Error loading tags: ${ e . message }` ) ; } ) ; } hide ( index , tag ) { if ( ! confirm ( `Are you sure you want to hide #${ tag }? This hashtag won't appear again.` ) ) { return ; } this . tags . splice ( index , 1 ) ; this . client . delete ( `api/v1/admin/tagcloud/${ tag }` ) . then ( ( ) => { this . load ( ) ; } ) . catch ( e => { this . load ( ) ; this . toasterService . error ( `Error deleting #${ tag }!` ) ; } ) ; } unhide ( index , tag ) { if ( ! confirm ( `Are you sure you want to unhide #${ tag }? This hashtag will start appearing.` ) ) { return ; } this . hidden . splice ( index , 1 ) ; this . client . put ( `api/v1/admin/tagcloud/${ tag }` ) . then ( ( ) => { this . load ( ) ; } ) . catch ( e => { this . load ( ) ; this . toasterService . error ( `Error showing #${ tag }!` ) ; } ) ; } resync ( ) { if ( ! confirm ( `Are you sure you want to re-sync? This will wipe the caches.` ) ) { return ; } this . client . post ( `api/v1/admin/tagcloud/refresh` ) . then ( ( ) => { this . load ( ) ; } ) . catch ( e => { this . toasterService . error ( `Error resyncing!` ) ; } ) ; } }