Skip to content

Commit

Permalink
The API now allows to call all the entities the user can answer on be…
Browse files Browse the repository at this point in the history
…half of #5312

Signed-off-by: ClementBouvierN <clement.bouvierneveu@rte-france.com>
  • Loading branch information
ClementBouvierN authored and freddidierRTE committed Nov 20, 2023
1 parent ff9e043 commit 17b60aa
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 66 deletions.
14 changes: 11 additions & 3 deletions src/docs/asciidoc/reference_doc/ui_api.adoc
Expand Up @@ -138,22 +138,30 @@ To adapt the template content to the display context it is possible to get from

=== Function getEntitiesAllowedToRespond

If inside your template, you want to get the ids of the entities allowed to send a response, you can call the method getEntitiesAllowedToRespond. This method returns an array containing the ids. An example of usage can be found in the file https://github.com/opfab/operatorfabric-core/tree/master/src/test/resources/bundles/messageOrQuestionExample/template/question.handlebars[src/test/resources/bundles/messageOrQuestionExample/template/question.handlebars].
If inside your template, you want to get the ids of the entities allowed to send a response, you can call the method getEntitiesAllowedToRespond. This method returns an array containing the ids.

```
const entities = opfab.currentCard.getEntitiesAllowedToRespond();
```

=== Function getEntityUsedForUserResponse

If inside your template, you want to get the id of the entity used by the user to send a response, you can call the method getEntityUsedForUserResponse.
An example of usage can be found in the file https://github.com/opfab/operatorfabric-core/tree/master/src/test/resources/bundles/messageOrQuestionExample/template/question.handlebars[src/test/resources/bundles/messageOrQuestionExample/template/question.handlebars].
If inside your template, you want to get the id of the entity used by the user to send a response, you can call the method getEntityUsedForUserResponse. This method is deprecated and you should favor the use of the method getEntitiesUsableForUserResponse.

```
const entity = opfab.currentCard.getEntityUsedForUserResponse()

```

=== Function getEntitiesUsableForUserResponse

If inside your template, you want to get the ids of the entities the user can answer on behalf of, you can call the method getEntitiesUsableForUserResponse. This method will return an array containing the entities' ids

```
const entities = opfab.currentCard.getEntitiesUsableForUserResponse()

```


=== Function isResponseLocked

Expand Down
11 changes: 11 additions & 0 deletions src/docs/asciidoc/resources/migration_guide_to_4.1.adoc
Expand Up @@ -39,3 +39,14 @@ For example :
== Log directories in docker

For the services cards-reminder, supervisor, cards-external-diffusion the log directory in the docker is not anymore /usr/app/logs but /var/log/opfab. So if you map the log directory in your configuration , you need to change it.


== OpfabAPI

The following method is deprecated and it is recommended you use the new method:

|===
|Deprecated method or attribute | New method

|opfab.currentCard.getEntityUsedForUserResponse()
|opfab.currentCard.getEntitiesUsableForUserResponse()
2 changes: 1 addition & 1 deletion src/test/cypress/cypress/integration/CardDetail.spec.js
Expand Up @@ -48,7 +48,7 @@ describe('Card detail', function () {
cy.get('#opfab-users-entities-getEntityName-unknownEntity').contains('unknownEntity');
cy.get('#opfab-currentCard-isUserAllowedToRespond').contains('true');
cy.get('#opfab-currentCard-isUserMemberOfAnEntityRequiredToRespond').contains('true');
cy.get('#opfab-currentCard-getEntityUsedForUserResponse').contains(/^ENTITY1_FR$/);
cy.get('#opfab-currentCard-getEntitiesUsableForUserResponse').contains(/^ENTITY1_FR$/);
cy.get('#opfab-currentCard-getDisplayContext').contains(/^realtime$/);
cy.get('#opfab-users-entities-getAllEntities').contains(
'entity[0]:id=ENTITY1_FR,name=Control Center FR North,description=Control Center FR North,entityAllowedToSendCard=true,parents=ENTITY_FR,labels=FR1 label'
Expand Down
Expand Up @@ -32,7 +32,7 @@
<div> onTemplateRenderingComplete : <span id="opfab-currentCard-onTemplateRenderingComplete"> </span> </div>

<H3> OPFAB CALLS</H3>
<div><span id="showCardLink" style="cursor:pointer;color:blue;text-decoration:underline;" onclick="opfab.navigate.showCardInFeed('defaultProcess.process1')">LINK TO ANOTHER CARD</span></div>
<div><span id="showCardLink" style="cursor:pointer;color:rgb(19, 85, 170);text-decoration:underline;" onclick="opfab.navigate.showCardInFeed('defaultProcess.process1')">LINK TO ANOTHER CARD</span></div>

<H3> HANDLEBARS TEMPLATING </H3>

Expand Down Expand Up @@ -71,8 +71,8 @@ function loadData() {
responses += opfab.currentCard.isUserMemberOfAnEntityRequiredToRespond();
responses += '</span></div>';
responses += '<div> getEntityUsedForUserResponse() : <span id="opfab-currentCard-getEntityUsedForUserResponse">';
responses += opfab.currentCard.getEntityUsedForUserResponse();
responses += '<div> getEntitiesUsableForUserResponse() : <span id="opfab-currentCard-getEntitiesUsableForUserResponse">';
responses += opfab.currentCard.getEntitiesUsableForUserResponse();
responses += '</span></div>';
responses += '<div> getDisplayContext() : <span id="opfab-currentCard-getDisplayContext">';
Expand Down
Expand Up @@ -31,7 +31,6 @@
<br/>
<div id="entities-div"> </div>
<br/>
<div id="response-entity-div"> </div>


<script>
Expand All @@ -43,7 +42,6 @@
this.disableResponseIfNotInRealTimeContext();
this.initOpfabAPI();
this.loadEntitiesList();
this.loadEntityUsedForResponse();
},
disableResponseIfNotInRealTimeContext: function() {
Expand Down Expand Up @@ -118,17 +116,9 @@
text += opfab.utils.escapeHtml(opfab.users.entities.getEntityName(id));
}
);
// if it is in card preview (usercard) , the template gateway does not contain the list
// if it is in card preview (usercard), the template gateway does not contain the list
// so we show nothing
if (entities.length>0) entitiesDiv.innerHTML = text;
},
loadEntityUsedForResponse: function() {
let responseEntityDiv = document.getElementById("response-entity-div");
let responseEntity = opfab.currentCard.getEntityUsedForUserResponse();
let userAllowedToRespond = opfab.currentCard.isUserAllowedToRespond();
if (userAllowedToRespond && responseEntity)
responseEntityDiv.innerHTML = "Entity used by user to respond : " + opfab.users.entities.getEntityName(responseEntity);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/cards/sendCard.sh
Expand Up @@ -48,4 +48,6 @@ else
export current_date_in_milliseconds_from_epoch_plus_48hours=$(($current_date_millis + 48*60*60*1000))
echo "send card $1 (url: $url)"
curl -X POST $url:2102/cards -H "Authorization: Bearer $token" -H "Content-type:application/json" --data "$(envsubst <$1)"
fi
fi

echo
12 changes: 8 additions & 4 deletions ui/main/src/app/business/services/opfabAPI.service.ts
Expand Up @@ -24,10 +24,7 @@ export class OpfabAPIService {
public templateInterface: any;
public userCardTemplateInterface: any;

constructor(
private businessDataService: BusinessDataService,
private translationService: TranslationService
) {
constructor(private businessDataService: BusinessDataService, private translationService: TranslationService) {
this.initCurrentCard();
this.initCurrentUserCard();
}
Expand All @@ -41,6 +38,7 @@ export class OpfabAPIService {
isUserMemberOfAnEntityRequiredToRespond: false,
entitiesAllowedToRespond: [],
entityUsedForUserResponse: null,
entitiesUsableForUserResponse: [],
displayContext: '',
isResponseLocked: false,
displayLoadingSpinner: function () {},
Expand Down Expand Up @@ -202,8 +200,14 @@ export class OpfabAPIService {
return self.currentCard.entitiesAllowedToRespond;
};
opfab.currentCard.getEntityUsedForUserResponse = function () {
console.warn(new Date().toISOString(),
' WARNING : Use of opfab.currentCard.getEntityUsedForUserResponse is deprecated, you should use opfab.currentCard.getEntitiesUsableForUserResponse instead'
);
return self.currentCard.entityUsedForUserResponse;
};
opfab.currentCard.getEntitiesUsableForUserResponse = function () {
return self.currentCard.entitiesUsableForUserResponse;
};

opfab.currentCard.hideLoadingSpinner = function () {
self.currentCard.hideLoadingSpinner();
Expand Down
Expand Up @@ -306,7 +306,8 @@ export class CardBodyComponent implements OnChanges, OnInit, OnDestroy {
this.opfabAPIService.currentCard.isUserMemberOfAnEntityRequiredToRespond =
this.userMemberOfAnEntityRequiredToRespondAndAllowedToSendCards;
this.opfabAPIService.currentCard.entityUsedForUserResponse = this.userEntityIdToUseForResponse;
}
this.opfabAPIService.currentCard.entitiesUsableForUserResponse = this.userEntityIdsPossibleForResponse;
}

private stopRegularlyCheckLttd() {
this.regularlyLttdCheckActive = false;
Expand Down
42 changes: 21 additions & 21 deletions ui/main/src/assets/js/templateGateway.js
Expand Up @@ -14,31 +14,31 @@ const templateGateway = {
getEntityName: function (entityId) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getEntityName is deprecated , you shall use opfab.users.entities.getEntityName instead'
' WARNING : Use of templateGateway.getEntityName is deprecated , you should use opfab.users.entities.getEntityName instead'
);
return opfab.users.entities.getEntityName(entityId);
},

getEntity: function (entityId) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getEntity is deprecated , you shall use opfab.users.entities.getEntity instead'
' WARNING : Use of templateGateway.getEntity is deprecated , you should use opfab.users.entities.getEntity instead'
);
return opfab.users.entities.getEntity(entityId);
},

getAllEntities: function () {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getAllEntities is deprecated , you shall use opfab.users.entities.getAllEntities instead'
' WARNING : Use of templateGateway.getAllEntities is deprecated , you should use opfab.users.entities.getAllEntities instead'
);
return opfab.users.entities.getAllEntities();
},

redirectToBusinessMenu: function (menuId, menuItemId, urlExtension) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.redirectToBusinessMenu is deprecated , you shall use opfab.navigate.redirectToBusinessMenu instead'
' WARNING : Use of templateGateway.redirectToBusinessMenu is deprecated , you should use opfab.navigate.redirectToBusinessMenu instead'
);
opfab.navigate.redirectToBusinessMenu(menuId, menuItemId, urlExtension);
},
Expand All @@ -49,7 +49,7 @@ const templateGateway = {
isUserAllowedToRespond: function () {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.isUserAllowedToRespond is deprecated , you shall use opfab.currentCard.isUserAllowedToRespond instead'
' WARNING : Use of templateGateway.isUserAllowedToRespond is deprecated , you should use opfab.currentCard.isUserAllowedToRespond instead'
);
return opfab.currentCard.isUserAllowedToRespond();
},
Expand All @@ -58,7 +58,7 @@ const templateGateway = {
isUserMemberOfAnEntityRequiredToRespond: function () {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.isUserMemberOfAnEntityRequiredToRespond is deprecated , you shall use opfab.currentCard.isUserMemberOfAnEntityRequiredToRespond instead'
' WARNING : Use of templateGateway.isUserMemberOfAnEntityRequiredToRespond is deprecated , you should use opfab.currentCard.isUserMemberOfAnEntityRequiredToRespond instead'
);
return opfab.currentCard.isUserMemberOfAnEntityRequiredToRespond();
},
Expand All @@ -67,39 +67,39 @@ const templateGateway = {
getEntitiesAllowedToRespond() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getEntitiesAllowedToRespond is deprecated , you shall use opfab.currentCard.getEntitiesAllowedToRespond instead'
' WARNING : Use of templateGateway.getEntitiesAllowedToRespond is deprecated , you should use opfab.currentCard.getEntitiesAllowedToRespond instead'
);
return opfab.currentCard.getEntitiesAllowedToRespond();
},

getEntityUsedForUserResponse() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getEntityUsedForUserResponse is deprecated , you shall use opfab.currentCard.getEntityUsedForUserResponse instead'
' WARNING : Use of templateGateway.getEntityUsedForUserResponse is deprecated , you should use opfab.currentCard.getEntityUsedForUserResponse instead'
);
return opfab.currentCard.getEntityUsedForUserResponse();
},

getDisplayContext() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getDisplayContext is deprecated , you shall use opfab.currentCard.getDisplayContext instead'
' WARNING : Use of templateGateway.getDisplayContext is deprecated , you should use opfab.currentCard.getDisplayContext instead'
);
return opfab.currentCard.getDisplayContext();
},

displayLoadingSpinner() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.displayLoadingSpinner is deprecated , you shall use opfab.currentCard.displayLoadingSpinner instead'
' WARNING : Use of templateGateway.displayLoadingSpinner is deprecated , you should use opfab.currentCard.displayLoadingSpinner instead'
);
opfab.currentCard.displayLoadingSpinner();
},

hideLoadingSpinner() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.hideLoadingSpinner is deprecated , you shall use opfab.currentCard.hideLoadingSpinner instead'
' WARNING : Use of templateGateway.hideLoadingSpinner is deprecated , you should use opfab.currentCard.hideLoadingSpinner instead'
);
opfab.currentCard.hideLoadingSpinner();
},
Expand All @@ -111,79 +111,79 @@ const templateGateway = {
get childCards() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.childCards is deprecated , you shall use opfab.currentCard.getChildCards() instead'
' WARNING : Use of templateGateway.childCards is deprecated , you should use opfab.currentCard.getChildCards() instead'
);
return opfab.currentCard.getChildCards();
},

get isLocked() {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.isLocked is deprecated , you shall use opfab.currentCard.isResponseLocked() instead'
' WARNING : Use of templateGateway.isLocked is deprecated , you should use opfab.currentCard.isResponseLocked() instead'
);
return opfab.currentCard.isResponseLocked();
},

set lockAnswer(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.lockAnswer is deprecated , you shall use opfab.currentCard.listenToResponseLock() instead'
' WARNING : Use of templateGateway.lockAnswer is deprecated , you should use opfab.currentCard.listenToResponseLock() instead'
);
opfab.currentCard.listenToResponseLock(value);
},

set unlockAnswer(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.unlockAnswer is deprecated , you shall use opfab.currentCard.listenToResponseUnlock() instead'
' WARNING : Use of templateGateway.unlockAnswer is deprecated , you should use opfab.currentCard.listenToResponseUnlock() instead'
);
opfab.currentCard.listenToResponseUnlock(value);
},

set setLttdExpired(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.setLttdExpired is deprecated , you shall use opfab.currentCard.listenToLttdExpired() instead'
' WARNING : Use of templateGateway.setLttdExpired is deprecated , you should use opfab.currentCard.listenToLttdExpired() instead'
);
opfab.currentCard.listenToLttdExpired(value);
},

set onStyleChange(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.onStyleChange is deprecated , you shall use opfab.currentCard.listenToStyleChange() instead'
' WARNING : Use of templateGateway.onStyleChange is deprecated , you should use opfab.currentCard.listenToStyleChange() instead'
);
opfab.currentCard.listenToStyleChange(value);
},

set setScreenSize(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.setScreenSize is deprecated , you shall use opfab.currentCard.listenToScreenSize() instead'
' WARNING : Use of templateGateway.setScreenSize is deprecated , you should use opfab.currentCard.listenToScreenSize() instead'
);
opfab.currentCard.listenToScreenSize(value);
},

set onTemplateRenderingComplete(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.onTemplateRenderingComplete is deprecated , you shall use opfab.currentCard.listenToTemplateRenderingComplete() instead'
' WARNING : Use of templateGateway.onTemplateRenderingComplete is deprecated , you should use opfab.currentCard.listenToTemplateRenderingComplete() instead'
);
opfab.currentCard.listenToTemplateRenderingComplete(value);
},

set getUserResponse(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.getUserResponse is deprecated , you shall use opfab.currentCard.registerFunctionToGetUserResponse() instead'
' WARNING : Use of templateGateway.getUserResponse is deprecated , you should use opfab.currentCard.registerFunctionToGetUserResponse() instead'
);
opfab.currentCard.registerFunctionToGetUserResponse(value);
},

set applyChildCards(value) {
console.warn(
new Date().toISOString(),
' WARNING : Use of templateGateway.applyChildCards is deprecated , you shall use opfab.currentCard.listenToChildCards() instead'
' WARNING : Use of templateGateway.applyChildCards is deprecated , you should use opfab.currentCard.listenToChildCards() instead'
);
opfab.currentCard.listenToChildCards(value);
}
Expand Down

0 comments on commit 17b60aa

Please sign in to comment.