Skip to content

Commit 1fa4d37

Browse files
committed
Action Implementation
1 parent 971a7b2 commit 1fa4d37

20 files changed

+392
-65
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { fdn_language } from "@app/modules/domain";
2+
13
export function getUserLangFromGlobalContext(){
24
const userLang = Xrm.Utility.getGlobalContext().userSettings.languageId;
35
switch(userLang){
46
case 1036:
5-
return 794560002;
7+
return fdn_language.French;
68
default:
7-
return 794560001;
9+
return fdn_language.English;
810
}
911
}

src/broadcast-typescript/app/modules/domain/entities/fdn_broadcastappnotification.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { entity ,fdn_localizednotificationcontent} from ".";
2+
import { fdn_actiontype } from "../optionsets";
23

34
export enum fdn_level {
45
Success = 794560000,
@@ -8,9 +9,13 @@ export enum fdn_level {
89
}
910
export class fdn_broadcastappnotification extends entity {
1011
fdn_level?: fdn_level;
12+
fdn_actiontype?: fdn_actiontype;
1113
fdn_message?: string;
1214
fdn_name?: string;
1315
fdn_appmoduleid?: string
1416
fdn_broadcastappnotificationid?: string;
17+
fdn_buttondefaulttext?: string;
18+
fdn_buttonactionurl?: string;
1519
fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification?:fdn_localizednotificationcontent[];
20+
1621
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { entity } from ".";
22
export enum fdn_language {
3-
English = 794560000,
4-
French = 794560001,
3+
English = 794560001,
4+
French = 794560002,
55
}
66
export type fdn_localizednotificationcontent = entity &{
77
fdn_localizednotificationcontentid?:string;
88
fdn_language?:fdn_language;
99
fdn_name?:string;
1010
fdn_contentmessage?:string;
11+
fdn_actionbuttondisplaytext?:string;
1112
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './entities';
2-
export * from './model';
2+
export * from './model';
3+
export * from './optionsets';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum fdn_actiontype {
2+
WebLink = 794560000
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './fdn_actiontype'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as utilities from "@app/modules/common/utility";
2+
import { fdn_actiontype } from "@app/modules/domain";
3+
const ActionTypeSectionMapping = {
4+
[fdn_actiontype.WebLink.toString()]: {
5+
name:"tab_action_section_url",
6+
mandatoryFields:['fdn_buttondefaulttext','fdn_buttonactionurl']
7+
}
8+
}
9+
export default class {
10+
//broadcast.forms.fdn_broadcastappnotification.onLoad
11+
async onLoad(executionContext: Xrm.Events.LoadEventContext) {
12+
const formContext = executionContext.getFormContext();
13+
14+
utilities.registerOnChangeHandler(formContext, 'fdn_actiontype', this.onActionTypeChange, this);
15+
16+
displayActionSectionAccordingToType(formContext);
17+
}
18+
async onActionTypeChange(executionContext: Xrm.Events.EventContext) {
19+
const formContext = executionContext.getFormContext();
20+
displayActionSectionAccordingToType(formContext);
21+
}
22+
}
23+
function displayActionSectionAccordingToType(formContext: Xrm.FormContext) {
24+
25+
const actionTypeAttribute = formContext.getAttribute<Xrm.Attributes.OptionSetAttribute>("fdn_actiontype")!;
26+
const tab = formContext.ui.tabs.get("tab_action")!;
27+
const currentActionType = actionTypeAttribute.getValue() ?? -1;
28+
for(let key in ActionTypeSectionMapping) {
29+
const config = ActionTypeSectionMapping[key as keyof typeof ActionTypeSectionMapping];
30+
const isSectionVisible = currentActionType.toString() === key;
31+
tab.sections.get(config.name)?.setVisible(isSectionVisible);
32+
config.mandatoryFields.forEach(fieldName => {
33+
formContext.getAttribute(fieldName)?.setRequiredLevel(isSectionVisible ? "required" : "none");
34+
});
35+
}
36+
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { lazy } from "@app/modules/common/system";
22
import fdn_localizednotificationcontent from "./fdn_localizednotificationcontent";
3+
import fdn_broadcastappnotification from "./fdn_broadcastappnotification";
34

45
class Forms{
56
@lazy
67
get fdn_localizednotificationcontent():fdn_localizednotificationcontent{
78
return new fdn_localizednotificationcontent();
89
}
10+
@lazy
11+
get fdn_broadcastappnotification():fdn_broadcastappnotification{
12+
return new fdn_broadcastappnotification();
13+
}
914
}
1015
export const forms = new Forms();
Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { notificationStore,broadcastNotificationService } from "@app/modules/services";
2-
import { fdn_broadcastappnotification, fdn_level, NotificationUI } from "@app/modules/domain";
3-
import * as utilities from '@app/modules/common/utility';
1+
import { notificationStore,broadcastNotificationService,clientNotificationFactory } from "@app/modules/services";
2+
import { NotificationUI } from "@app/modules/domain";
43
export default class {
54
//broadcast.ribbon.application.renderNotifications
65
async renderNotifications(targetpage?:string){
@@ -12,7 +11,6 @@ export default class {
1211
return false;
1312
}
1413

15-
const userLang = utilities.getUserLangFromGlobalContext();
1614
console.log("broadcast renderNotifications");
1715
const appProps = await Xrm.Utility.getGlobalContext().getCurrentAppProperties();
1816
if(!appProps || !appProps.appId){
@@ -24,7 +22,7 @@ export default class {
2422
await Promise.all(clearTasks);
2523
const data:NotificationUI[] = [];
2624
for(const n of livenotifications){
27-
const dataverseNotification = MapNotificationToDataverse(n,userLang);
25+
const dataverseNotification =clientNotificationFactory.create(n);
2826
const uid = await Xrm.App.addGlobalNotification(dataverseNotification);
2927
data.push({
3028
uid,
@@ -42,33 +40,3 @@ export default class {
4240
}
4341

4442
}
45-
function MapNotificationToDataverse(n:fdn_broadcastappnotification,userLang:number):Xrm.App.Notification{
46-
const level = MapToLevel(n.fdn_level!);
47-
let msg = n.fdn_message;
48-
const localizedMsgObjs = n.fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification;
49-
if(localizedMsgObjs && localizedMsgObjs.length > 0){
50-
msg = localizedMsgObjs.find((v)=> v.fdn_language === userLang)?.fdn_contentmessage ?? n.fdn_message;
51-
}
52-
return {
53-
level: level,
54-
message: msg!,
55-
showCloseButton: false,
56-
type: 2
57-
};
58-
}
59-
function MapToLevel(level:number):number{
60-
switch(level){
61-
case fdn_level.Success:
62-
return 1;
63-
case fdn_level.Danger:
64-
return 2;
65-
case fdn_level.Warning:
66-
return 3;
67-
case fdn_level.Information:
68-
return 4;
69-
default:
70-
return 4;
71-
}
72-
73-
74-
}

src/broadcast-typescript/app/modules/services/BroadcastNotificationService.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ export class BroadcastNotificationService implements IBroadcastNotificationServi
3636
const columns = ["fdn_appmoduleid",
3737
"fdn_message",
3838
"fdn_broadcastappnotificationid",
39-
"fdn_level"
39+
"fdn_level",
40+
"fdn_buttondefaulttext",
41+
"fdn_buttonactionurl",
42+
"fdn_actiontype"
4043
];
41-
const expandOptions = `&$expand=fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification($select=fdn_contentmessage,fdn_language;$filter=statecode eq 0)`;
44+
const expandColumns = ['fdn_language','fdn_contentmessage','fdn_actionbuttondisplaytext'];
45+
const expandOptions = `&$expand=fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification($select=${expandColumns.join(',')};$filter=statecode eq 0)`;
4246
const queryOptions = `?$select=${columns.join(',')}`+expandOptions+filterOptions;
4347
const result = await this.webApi.retrieveMultipleRecords("fdn_broadcastappnotification", queryOptions);
4448
const notifications = result.entities as fdn_broadcastappnotification[];
@@ -63,13 +67,16 @@ function cleanNotification(e:fdn_broadcastappnotification){
6367
"fdn_message",
6468
"fdn_broadcastappnotificationid",
6569
"fdn_level",
66-
"fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification"];
70+
"fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification",
71+
"fdn_buttondefaulttext",
72+
"fdn_buttonactionurl",
73+
"fdn_actiontype"];
6774
let n = removeODataGarbages(e,keysToKeep);
6875
const lmg = n.fdn_localizednotificationcontent_AppNotificationConfigId_fdn_broadcastappnotification;
6976
if(!lmg || lmg.length === 0){
7077
return n;
7178
}
72-
lmg.map(l => removeODataGarbages(l,["fdn_contentmessage","fdn_language"]));
79+
lmg.map(l => removeODataGarbages(l,["fdn_contentmessage","fdn_language","fdn_actionbuttondisplaytext"]));
7380
return n;
7481
}
7582
function removeODataGarbages<T>(e:T,keys:string[]){

0 commit comments

Comments
 (0)