Created
July 3, 2018 04:26
-
-
Save PankajWorks/53ce7dfcbd1f15df7cd08a6c6eaacc2f to your computer and use it in GitHub Desktop.
release-summary component
This file contains 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 '@ember/component'; | |
import { task } from 'ember-concurrency'; | |
import {set,get} from '@ember/object'; | |
import $ from 'jquery'; | |
import config from 'qaas-dashboard-ui/config/environment'; | |
import { inject } from '@ember/service'; | |
import {isEqual} from '@ember/utils'; | |
import { A } from '@ember/array'; | |
import EmberObject from '@ember/object'; | |
import BootstrapTheme from 'ember-models-table/themes/bootstrap4'; | |
export default Component.extend({ | |
flashMessages: inject(), | |
release:null, | |
builds:null, | |
systemTestResult:null, | |
showResult: false, | |
tableColumns: A([]), | |
tableData: A([]), | |
risk:{medium:80,low:95}, | |
bs4Theme:BootstrapTheme.create({ | |
buttonDefault:'btn btn-sm', | |
input:'form-control form-control-sm', | |
}), | |
didReceiveAttrs(){ | |
this._super(...arguments); | |
this.get("getSummary").perform(); | |
}, | |
getSummary: task(function * (){ | |
let release = get(this,'release'); | |
let result = null; | |
let st_url = `${config.qaasapi}getSystemTestSummary/${release}`; | |
try { | |
result = yield this.get('getJSON').perform(st_url); | |
} catch (e) { | |
get(this, 'flashMessages').danger('API Error: ' + JSON.stringify(e)) | |
} | |
let tableData = yield this.get('processData').perform(result.results); | |
if (get(tableData, 'rows.length') === 0) { | |
this.send('errorModal', 'No data found'); | |
set(this, 'showResult', false); | |
return; | |
} | |
console.log(tableData); | |
set(this, 'tableColumns', tableData.columns); | |
set(this, 'tableData', tableData.rows); | |
set(this, 'showResult', true); | |
set(this,'build',tableData.build); | |
}).restartable(), | |
getJSON: task(function *(url){ | |
let xhr; | |
let data; | |
try { | |
xhr = $.getJSON(url); | |
data = yield xhr.promise(); | |
} catch(e) { | |
get(this, 'flashMessages').danger('Error while fetching Release Summary'+JSON.stringify(e)); | |
}finally { | |
xhr.abort(); | |
} | |
return data; | |
}), | |
getPassPercent(data){ | |
let pass=data.filter(s => isEqual(s,'pass')).length||0; | |
let fail=data.filter(s => isEqual(s,'fail')).length||0; | |
let skip=data.filter(s => isEqual(s,'skip')).length||0; | |
let error=data.filter(s => isEqual(s,'error')).length||0; | |
return parseFloat((((pass/(pass+fail+skip+error)*100)||0).toFixed(2))); | |
}, | |
processData: task(function *(data){ | |
let regex = new RegExp(get(this,'release')); | |
let filtred = get(this,'builds').filter(function(person) { | |
return regex.test(person); | |
}); | |
let latestBuild = filtred.sort().reverse().slice(0,2); | |
let rows =A([]); | |
let cols = A([]); | |
let buildData = data.reduce((arr,e)=>{ | |
(arr[e.TX_STACK_BUILD_NR] = arr[e.TX_STACK_BUILD_NR] || []).push(e); | |
return arr; | |
},{}); | |
let latestData = buildData[latestBuild[0]]; | |
let uniqOses = latestData.uniqBy('TX_OPERATING_SYSTEM').map(e => e.TX_OPERATING_SYSTEM); | |
let component = latestData.reduce((arr,e)=>{ | |
(arr[e.TX_COMPONENT] = arr[e.TX_COMPONENT] || []).push( | |
EmberObject.create({os:e.TX_OPERATING_SYSTEM,status:e.status}) | |
); | |
return arr; | |
},{}); | |
cols.pushObject(EmberObject.create({title: 'Component', propertyName: 'component'})); | |
cols.pushObjects(uniqOses.map((c) => EmberObject.create({title: c, propertyName: c,component:"rel-dash-test-card"}))); | |
let uniqComps = Object.keys(component); | |
rows.pushObjects(uniqComps.map(entry => { | |
let row = EmberObject.create({ | |
component:entry, | |
risk:get(this,'risk') | |
}); | |
let c_data = component[entry]; | |
let os_data = c_data.reduce((arr,e)=>{ | |
(arr[e.os] = arr[e.os] || []).push(e.status); | |
return arr; | |
},{}); | |
uniqOses.forEach(os => { | |
set(row,os, | |
{ | |
pass:os_data[os].filter(s => isEqual(s,'pass')).length||0, | |
fail:os_data[os].filter(s => isEqual(s,'fail')).length||0, | |
skip:os_data[os].filter(s => isEqual(s,'skip')).length||0, | |
error:os_data[os].filter(s => isEqual(s,'error')).length||0, | |
pass_p:this.getPassPercent(os_data[os]) | |
} | |
) | |
}); | |
return row; | |
})) | |
return { | |
columns: cols, | |
rows: rows, | |
build:latestBuild | |
}; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment