Skip to content

Instantly share code, notes, and snippets.

@PankajWorks
Created July 3, 2018 04:26
Show Gist options
  • Save PankajWorks/53ce7dfcbd1f15df7cd08a6c6eaacc2f to your computer and use it in GitHub Desktop.
Save PankajWorks/53ce7dfcbd1f15df7cd08a6c6eaacc2f to your computer and use it in GitHub Desktop.
release-summary component
{{#if getSummary.isIdle}}
<div class="card card-shadow card-body">
<div class="card-header">
{{build}}
{{!--
<div class="col-md-2">
<div class="input-group">
<span class="input-group-addon lowrisk">Low Risk : Pass% &gt; </span>
{{input value=risk.low class="form-control"}}
</div>
</div>
--}}
</div>
<div class="card-body">
{{models-table
data=tableData
columns=tableColumns
pageSize=10
useFilteringByColumns=false
filteringIgnoreCase=true
themeInstance=bs4Theme
}}
</div>
</div>
{{else}}
{{loading-spinner}}
{{/if}}
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