Product/components used and version/fix level:
Cockpit application version 1016.0.297
Detailed explanation of the problem:
I am trying to add url action in c8yActionsProvider
in AngularJS plugin and I need to use showIf property which is showing action no matter what value of property is.
This is my code:
(() => {
'use strict';
angular.module('incubator.dashboardExtension').config(configure);
/* @ngInject */
function configure(c8yActionsProvider) {
c8yActionsProvider.addUrlAction({
path: '/device/:deviceId',
text: 'New dashboard from template',
priority: 999,
showIf: ['userService', function(userService) { return userService.hasTemplateCopyRole();}],
action: ['templateApplyUtilsService', 'dashboardSvc', function newDashboardFromTemplate(templateApplyUtilsService, dashboardSvc) {
templateApplyUtilsService.openApplyFromLibraryModal(dashboardSvc);}]
});
}
})();
Function “hasTemplateCopyRole” returns true or false.
Even if I set property to true or false url action is still showing.
Question related to a free trial, or to a production (customer) instance?
Do I need to configure property differently?
Hi Marija,
Just to narrow down your issue:
The function you’ve specified under showIf
is actually being called?
If you check the userService
, you are actually getting an instance of that service?
And putting a static return true
or return false
into the function does not influence whether the action is shown or not?
Has this been previously working? Or is this something you are newly developing? If this was previously working, can you give us the version number this was previously working with?
For all new developments we would strongly recommend using Angular instead of AngularJS.
Regards,
Tristan
Hi Tristan,
Yes, method is being called and I am getting instance of userService.
Static return true and false does not influence whether the action is shown or not.
In previous version 10.15.0.309 we had different code:
(() => {
'use strict';
angular.module('incubator.dashboardExtension').config(configure);
/* @ngInject */
function configure(c8yActionsProvider, gettext) {
displayApplyTemplate(c8yActionsProvider, gettext);
}
function displayApplyTemplate(c8yActions, gettext) {
c8yActions.addUrlAction({
path: '/device/:deviceId',
text: gettext('New dashboard from template'),
actionBar: false,
priority: 999,
/* @ngInject */
action(templateApplyUtilsService, dashboardSvc) {
templateApplyUtilsService.openApplyFromLibraryModal(dashboardSvc);
},
/* @ngInject */
showIf(userService) {
return userService.hasTemplateCopyRole().then(hasCopyPermission => {
return hasCopyPermission;
});
},
});
}
That code in version 10.16 had error:
13822.b151e8336d7a4400fc99.js:2 ERROR Error: [$injector:unpr] Unknown provider: eProvider <- e
http://errors.angularjs.org/1.6.9/$injector/unpr?p0=eProvider%20%3C-%20e
at 82529.445172b1b85ae230caaa.js:2:3550069
at 82529.445172b1b85ae230caaa.js:2:3573623
at Object.s [as get] (82529.445172b1b85ae230caaa.js:2:3575201)
at 82529.445172b1b85ae230caaa.js:2:3573710
at s (82529.445172b1b85ae230caaa.js:2:3575201)
at l (82529.445172b1b85ae230caaa.js:2:3575506)
at Object.invoke (82529.445172b1b85ae230caaa.js:2:3575594)
at action (82529.445172b1b85ae230caaa.js:2:6092944)
at e.value (89887.02e3c264674b3b8c30a3.js:2:450386)
at e_div_3_ul_5_ng_container_1_li_2_Template_button_click_1_listener (ɵcmp.js:27:15)
which I fixed with code from my first comment.
showIf wasn’t working in that version also but we just discovered that issue in new version.
This is legacy code from couple years ago that is the only reason why is in AngularJS.
BR,
Marija
Hi Marija,
So it seems like showIf
is not supported for the actions.
showIf
is only used when using this functionality in combination with actionBar: true
.
So e.g.:
c8yActionsProvider.addUrlAction({
path: '/device/:deviceId',
text: 'New dashboard from template',
priority: 999,
actionBar: true,
showIf: ['userService', function(userService) { return userService.hasTemplateCopyRole();}],
action: ['templateApplyUtilsService', 'dashboardSvc', function newDashboardFromTemplate(templateApplyUtilsService, dashboardSvc) {
templateApplyUtilsService.openApplyFromLibraryModal(dashboardSvc);}]
});
Would actually hide the item from the actions bar in case hasTemplateCopyRole()
returns true
.
Regards,
Tristan
1 Like
Hi Tristan,
I wasn’t aware of that. It’s working with actionBar:true like you said so we decided to move button to action bar. Thank you for your help.
BR,
Marija