Skip to content

Commit 963b487

Browse files
Merge pull request #126 from mh7777777/master
Implement notification badges for layout 1.
2 parents 99fbc15 + 0ffc3d2 commit 963b487

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

control/design/design.controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
selectedLayout: 1,
4646
backgroundblur: 0,
4747
hideText: false,
48-
securedFeaturesOption:"Enable"
48+
securedFeaturesOption:"Enable",
49+
showNotificationBadges: false
4950
};
5051
}
5152
if(typeof $scope.data.design.showBlackOverlay !== 'boolean') {

control/design/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,26 @@
202202
</div>
203203
</div>
204204

205+
<div>
206+
<hr>
207+
<div class="item row clearfix">
208+
<div class="labels col-md-3 padding-right-zero pull-left">
209+
<span>Show Notification Badges</span>
210+
</div>
211+
<div class="main col-md-9 pull-right" ng-init="data.design.showNotificationBadges">
212+
<div class="radio radio-primary radio-inline">
213+
<input ng-if="data.design.showNotificationBadges" id="showNotificationBadges" type="radio" name="toggleShowNotificationBadges" ng-model="data.design.showNotificationBadges" ng-value="false">
214+
<input ng-if="!data.design.showNotificationBadges" id="showNotificationBadges" type="radio" name="toggleShowNotificationBadges" checked="checked">
215+
<label for="showNotificationBadges">False</label>
216+
</div>
217+
<div class="radio radio-primary radio-inline">
218+
<input id="showNotificationBadges" type="radio" name="toggleShowNotificationBadges" ng-model="data.design.showNotificationBadges" ng-value="true">
219+
<label for="showNotificationBadges">True</label>
220+
</div>
221+
</div>
222+
</div>
223+
</div>
224+
205225
<hr ng-if="enterpriseApp" >
206226
<div ng-if="enterpriseApp" class="padded padding-top-ten clearfix" >
207227
<div class="item clearfix row">

widget/index.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
var changeTimer;
124124
var lastImage=null;
125125
var touchmoved;
126+
var notificationBadges = [];
127+
var currentInstanceId = buildfire.getContext().instanceId;
126128

127129

128130
var lazyLoad = {
@@ -407,6 +409,51 @@
407409
var display=(obj.data.content&&obj.data.content.display)?obj.data.content.display:0;
408410
renderCarousel(obj.data.content.carouselImages, layout,speed,order,display);
409411
}
412+
413+
if (obj.data.design.showNotificationBadges && plugins && plugins.length) {
414+
getBadges(plugins.map(function (plugin) { return plugin.instanceId }), function (badgesData) {
415+
if (!badgesData || !badgesData.length) return;
416+
if (layout == 1) {
417+
var sections = document.getElementsByClassName('pluginItem');
418+
for (var i = 0; i < sections.length; i++) {
419+
var pluginIndex = sections[i].children[0].children[1].getAttribute('index');
420+
var instanceId = plugins[parseInt(pluginIndex)] ? plugins[parseInt(pluginIndex)].instanceId : null;
421+
if (!instanceId) continue;
422+
var currentBadgeData = badgesData.find(function(item) { return item.uniqueId === instanceId });
423+
var countValue = currentBadgeData && currentBadgeData.count ? currentBadgeData.count : 0;
424+
if (!countValue) continue;
425+
var notificationBadgeBoxElem = document.createElement('div')
426+
notificationBadgeBoxElem.setAttribute('class', 'notificationBadgeBox btn-info');
427+
notificationBadgeBoxElem.innerHTML = '<span style="color: #fff">' + countValue + '</span>';
428+
sections[i].appendChild(notificationBadgeBoxElem);
429+
}
430+
}
431+
});
432+
}
433+
434+
}
435+
436+
function getBadges(uniqueIds = [], callback) {
437+
if (!uniqueIds.length) return callback([]);
438+
buildfire.appData.search(
439+
{ filter: { '_buildfire.index.string1': { $in: [...uniqueIds, currentInstanceId] } } },
440+
'$$notificationBadges',
441+
function (err, result) {
442+
if (err || !result || !result.length) return callback([]);
443+
var mappedData = result.map(function (data) { return data.data });
444+
notificationBadges = notificationBadges.concat(mappedData);
445+
callback(mappedData);
446+
}
447+
);
448+
};
449+
450+
function setBadgesCount(uniqueId, count = 0) {
451+
buildfire.appData.searchAndUpdate(
452+
{ '_buildfire.index.string1': uniqueId },
453+
{ count },
454+
'$$notificationBadges',
455+
function () {}
456+
);
410457
}
411458

412459
function getPlugins(obj, callback) {
@@ -685,12 +732,15 @@
685732
if(touchmoved != true){
686733
var i = parseInt(this.getAttribute('index'));
687734
var p = plugins[i];
735+
var queryString = new URLSearchParams();
736+
queryString.append('parentUniqueId', currentInstanceId);
688737

689738
buildfire.navigation.navigateTo({
690739
pluginId: p.pluginTypeId
691740
, folderName: p.folderName
692741
, instanceId: p.instanceId
693742
, title: p.title
743+
, queryString: queryString.toString()
694744
});
695745
}
696746
}
@@ -981,6 +1031,28 @@
9811031
line-height: 20vw !important;
9821032
}
9831033

1034+
.layout1 .pluginItem {
1035+
position: relative;
1036+
}
1037+
1038+
.layout1 .pluginItem .notificationBadgeBox {
1039+
position: absolute;
1040+
top: 50%;
1041+
right: 4vw;
1042+
transform: translateY(-50%);
1043+
width: 25px;
1044+
height: 25px;
1045+
display: flex;
1046+
justify-content: center;
1047+
align-items: center;
1048+
border-radius: 50%;
1049+
}
1050+
1051+
.layout1 .pluginItem .notificationBadgeBox span {
1052+
position: relative;
1053+
right: 1px;
1054+
}
1055+
9841056
/*
9851057
Layout-2
9861058
*/

0 commit comments

Comments
 (0)