Targetprocess

The Targetprocess Developer Hub

Welcome to the Targetprocess developer hub. Here you'll find comprehensive guides and documentation to help you start working with Targetprocess as quickly as possible and support you if you get stuck. Let's jump right in!

Docs
Ask A Question

Questions

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

Posted by Camilo Toro 3 months ago

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 = '<tr class="ui-additionalinfo_editable_true">'+
'<td class="ui-additionalinfo__label" colspan = "2">' +
//<div class="tau-container tau-system-message-body"><div class="tau-system-message-body__content"><div class="tau-system-message-body-inner"><div data-reactroot=""><div class="tau-system-message__title i-role-message-title"><div class="tau-message-error">Data layer exception occurred.</div></div></div></div></div><div class="tau-system-message-body__button" style="display: none;"><button type="button" class="tau-btn i-role-message-button"></button></div></div><div class="ui-label-container"><span class="ui-label " data-title="Sprint">Sprint</span></div></td>
'<div class="tau-system-message-body">' +
'<div class="tau-system-message-body__content">' +
'<div class="tau-system-message-body-inner">' +
'<div data-reactroot="">' +
'<div class="tau-system-message__title i-role-message-title">' +
'<div class="tau-message-error">'+ controlMessage +'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="tau-system-message-body__button" style="display: none;">' +
'<button type="button" class="tau-btn i-role-message-button"></button>' +
'</div>' +
'</div>' +
'</td>'+
'</tr>';

return HTMLVelocityControlText;

}

function getHTMLHeaderMessage(header, controlMessage){
var HTMLHeaderMessage = '<div class="tau-system-message tau-message-error" style="display: true;" id="tau-system-message_notifyBar">' +
'<div class="tau-system-message-body">' +
'<div class="tau-system-message-body__content">' +
'<div class="tau-system-message__title">' + header + '</div> ' +
'<div class="tau-system-message__details">' + controlMessage +
//'<a class="tau-entity-name i-role-card-view" href="#page=task/15486&appConfig=eyJhY2lkIjoiOEIzQkQ3M0Q5NTlDMEE5MTY3QTlBMDYwMzlFODBBRDEifQ==">Anotherone</a> was added. ' +
'</div>' +
'</div>' +
'<div class="tau-system-message-body__button" style="display: none;">' +
'<button type="button" class="tau-btn i-role-message-button">' +
'</button>' +
'</div>' +
'</div>' +
'</div>';

return HTMLHeaderMessage;

}

]]

Loading comments...