Discussion

Ask a Question
Back to All

Mashup to display warnings on entities which are linked to an Sprint that doesn't have Velocity value set.

Hi TP Development team,

We are developing a Mashup in TP which can displays a warning message on top of entities and after Sprint field for those entities which are assigned to sprints without velocity value set.

The above goal has been achieved with the below code, however we would like to add a listener to re-validate these warnings when user removes or select a different Sprint on Entity, how can this be achieved?

The code is as below:

[[
tau.mashups
.addDependency('tp/general/view')
.addDependency('jQuery')
.addMashup(function(view) {
view.onRender(function($pageElement, context) {
var sprintName = "";
var velocityValue = "";
var isCurrentSprint = false;
var controlMessage = '';
var APIEntity = '';
if($.inArray(context.entity.type, ['userstory', 'task', 'bug']) >= 0 ){
switch(context.entity.type) {
case 'userstory':
APIEntity = 'UserStories';
break;
case 'task':
APIEntity = 'Tasks';
break;
case 'bug':
APIEntity = 'Bugs';
break;
}
//FULL API URL: https://ppbtest.tpondemand.com/api/v1/TeamIterations?where=(Id%20eq%2015437)&include=[Id,Name,StartDate,EndDate,IsCurrent,Velocity]&format=json
//Bellow taken from https://dev.targetprocess.com/docs/response-formats
var URLAPIEntity = "/api/v1/"+ APIEntity + "?where=(Id%20eq%20"+ context.entity.id + ")&include=[TeamIteration]&format=json";
console.log(URLAPIEntity);
$.getJSON(URLAPIEntity, entityObjet);
function entityObjet(dataEntity) {
console.log(dataEntity);
var teamiteration = null;
for (i = 0; i < dataEntity.Items.length; i++) {
//debugger;
teamiteration = dataEntity.Items[i].TeamIteration;

                }
                if(teamiteration !== null){
                    var URLAPITeamiteration = "/api/v1/TeamIterations?where=(Id%20eq%20"+ teamiteration.Id + ")&include=[Id,Name,StartDate,EndDate,IsCurrent,IsNext,Velocity]&format=json";
                    console.log(URLAPITeamiteration);
                    $.getJSON(URLAPITeamiteration, sprintObjet);
                    function sprintObjet(data) {
                        console.log(data);
                        for (i = 0; i < data.Items.length; i++) {
                            isCurrentSprint = data.Items[i].IsCurrent;
                            isNextSprint  = data.Items[i].IsNext;
                            velocityValue = data.Items[i].Velocity;
                            sprintName    = data.Items[i].Name;
                        }
                        if((isCurrentSprint || isNextSprint) && velocityValue === 0){
                            if(isNextSprint){
                                controlMessage = 'Velocity Value has not been set on future Sprint "' + sprintName + '".';
                            }else{
                                controlMessage = 'Velocity Value has not been set on current Sprint "' + sprintName + '".';
                            }
                            var newBlockTitle   = 'Has sprint started? ' + isCurrentSprint;
                            var newBlockContent = 'Velocity Value' + velocityValue;
                            var newBlockContainer= getHTMLVelocityControlText(controlMessage);

                            //Add validation message right below after Velocity Field
                            var $insertAfterBlockSpan = $pageElement.find('.ui-label:contains("Sprint")');
                            var $insertAfterBlockContainer = $insertAfterBlockSpan.closest('.ui-additionalinfo_editable_true');

                            //Add Popup message right after Body tag to display message on the header.
                            $("body").prepend(getHTMLHeaderMessage("No Velocity on Sprint", controlMessage));

                            if ($insertAfterBlockContainer.length) {
                                // do something if proper place is found 
                                $insertAfterBlockContainer.after(newBlockContainer);
                            }
                        }
                    }//End function sprintObjet(data)
                }
            }//End function Calling Entity API to get Sprint ID entityObjet(data)

        }
    });
});

function getHTMLVelocityControlText(controlMessage){
var HTMLVelocityControlText = ''+
'' +
//

Data layer exception occurred.
Sprint

'
' +
'
' +
'
' +
'
' +
'
' +
'
'+ controlMessage +'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'' +
'
' +
'
' +
''+
'';

return HTMLVelocityControlText;

}

function getHTMLHeaderMessage(header, controlMessage){
var HTMLHeaderMessage = '

' +
'
' +
'
' +
'
' + header + '
' +
'
' + controlMessage +
//'Anotherone was added. ' +
'
' +
'
' +
'
' +
'' +
'' +
'
' +
'
' +
'
';

return HTMLHeaderMessage;

}

]]