import { Injectable } from '@angular/core' ; import { ContentPage , SystemDomainApi } from '@colmena/admin-lb-sdk' ; export { ContentPage } from '@colmena/admin-lb-sdk' ; import { UiDataGridService , FormService } from '@colmena/admin-ui' ; import { Observable } from 'rxjs/Observable' ; import { Subscription } from 'rxjs/Subscription' ; @ Injectable ( ) export class PagesService extends UiDataGridService { public icon = 'icon-book-open' ; public title = 'Pages' ; public selectedPage : ContentPage ; public files : any [ ] = [ ] ; public tableColumns = [ { field : 'name' , label : 'Name' , action : 'view' } ] ; constructor ( private domainApi , private formService ) { super ( ) ; this . columns = this . tableColumns ; } setSelectedPage ( page ) { this . selectedPage = page ; } getFormFields ( ) { return [ this . formService . input ( 'name' , { label : 'Name' , placeholder : 'Name' , } ) , this . formService . wysiwyg ( 'content' , { label : 'Content' , placeholder : 'Content' , } ) , this . formService . select ( 'storageFileId' , { label : 'File' , options : this . files , } ) , ] ; } getFormConfig ( ) { return { icon : this . icon , fields : this . getFormFields ( ) , showCancel : true , hasHeader : false , } ; } getFiles ( ) { this . domainApi . getStorageFiles ( this . domain . id ) . subscribe ( files => files . map ( file => this . files . push ( { value : file . id , label : file . name } ) ) ) ; } getItems ( ) { return this . domainApi . getContentPages ( this . domain . id , this . getFilters ( { include : [ 'storageFile' ] } ) ) ; } getItem ( id ) { return this . domainApi . findByIdContentPages ( this . domain . id , id ) ; } getItemCount ( ) { return this . domainApi . countContentPages ( this . domain . id , this . getWhereFilters ( ) ) ; } upsertItem ( item , successCb , errorCb ) { if ( item . id ) { return this . upsertPage ( item , successCb , errorCb ) ; } return this . createPage ( item , successCb , errorCb ) ; } upsertPage ( item , successCb , errorCb ) { return this . domainApi . updateByIdContentPages ( this . domain . id , item . id , item ) . subscribe ( successCb , errorCb ) ; } createPage ( item , successCb , errorCb ) { return this . domainApi . createContentPages ( this . domain . id , item ) . subscribe ( successCb , errorCb ) ; } deleteItem ( item , successCb , errorCb ) { return this . domainApi . destroyByIdContentPages ( this . domain . id , item . id ) . subscribe ( successCb , errorCb ) ; } }