import { Action , Module , Mutation , VuexModule } from 'vuex-module-decorators' ; import Pipeline , { HealthStatus } from './pipeline' ; import { PipelineRest } from './pipelineRest' ; import { PipelineTransRest } from './pipelineTransRest' ; import { PIPELINE_SERVICE_URL } from '@/env' ; interface PipelinesByDatasourcePayload { datasourceId : number ; pipelines : Pipeline [ ] ; } @ Module ( { namespaced : true } ) export default class PipelineModule extends VuexModule { private pipelines : Pipeline [ ] = [ ] ; private pipelineStates : Map < number , string > = new Map < number , string > ( ) ; private selectedPipeline ? : Pipeline = undefined ; private isLoadingPipelines = true ; private isLoadingPipelineStates = true ; private readonly restService = new PipelineRest ( PIPELINE_SERVICE_URL ) ; private readonly restTransService = new PipelineTransRest ( PIPELINE_SERVICE_URL ) ; @ Mutation setPipelines ( pipelines ) { this . pipelines = pipelines ; this . isLoadingPipelines = false ; } @ Mutation setPipelinesByDatasourceId ( payload ) { for ( const newPipeline of payload . pipelines ) { const index = this . pipelines . findIndex ( el => el . id === newPipeline . id ) ; if ( index >= 0 ) { this . pipelines [ index ] = newPipeline ; } else { this . pipelines . push ( newPipeline ) ; } } this . isLoadingPipelines = false ; } @ Mutation setPipelineStates ( value ) { this . pipelineStates = value ; this . isLoadingPipelineStates = false ; } @ Mutation setSelectedPipeline ( pipeline ) { this . selectedPipeline = pipeline ; } @ Mutation setIsLoadingPipelines ( value ) { this . isLoadingPipelines = value ; } @ Mutation setIsLoadingPipelineStates ( value ) { this . isLoadingPipelines = value ; } @ Action ( { commit : 'setPipelines' , rawError : true } ) async loadPipelines ( ) { this . context . commit ( 'setIsLoadingPipelines' , true ) ; return await this . restService . getAllPipelines ( ) ; } @ Action ( { commit : 'setPipelineStates' , rawError : true } ) private async loadPipelineStates ( ) { this . context . commit ( 'setIsLoadingPipelineStates' , true ) ; const pipelineStates = new Map < number , string > ( ) ; for ( const element of this . pipelines ) { const transformedData = await this . restTransService . getLatestTransformedData ( element . id ) ; let healthStatus ; if ( transformedData . healthStatus === HealthStatus . OK ) { healthStatus = 'success' ; } else if ( transformedData . healthStatus === HealthStatus . WARINING ) { healthStatus = 'orange' ; } else { healthStatus = 'red' ; } pipelineStates . set ( element . id , healthStatus ) ; } return pipelineStates ; } @ Action ( { commit : 'setSelectedPipeline' , rawError : true } ) async loadPipelineById ( id ) { return await this . restService . getPipelineById ( id ) ; } @ Action ( { commit : 'setPipelinesByDatasourceId' , rawError : true } ) async loadPipelinesByDatasourceId ( datasourceId ) { const pipelines = await this . restService . getPipelinesByDatasourceId ( datasourceId ) ; return { datasourceId : datasourceId , pipelines : pipelines , } ; } @ Action ( { commit : 'setPipelines' , rawError : true } ) async createPipeline ( pipeline ) { await this . restService . createPipeline ( pipeline ) ; return await this . restService . getAllPipelines ( ) ; } @ Action ( { commit : 'setPipelines' , rawError : true } ) async updatePipeline ( pipeline ) { await this . restService . updatePipeline ( pipeline ) ; return await this . restService . getAllPipelines ( ) ; } @ Action ( { commit : 'setPipelines' , rawError : true } ) async deletePipeline ( pipelineId ) { await this . restService . deletePipeline ( pipelineId ) ; return await this . restService . getAllPipelines ( ) ; } }