Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Move Presence to its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
swgraham committed Oct 19, 2015
1 parent 834ab1c commit 00031bc
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module.exports = function(grunt) {
ngtemplates: {
'angular-rtcomm-ui': {
cwd: '<%= dirs.src %>',
src: 'templates/rtcomm/**.html',
src: ['templates/rtcomm/**.html', '!templates/rtcomm/rtcomm-presence.html'],
dest: '<%= dirs.dest %>/<%= pkg.name %>.js',
options: {
htmlmin: { collapseWhitespace: true, collapseBooleanAttributes: true },
Expand Down
7 changes: 1 addition & 6 deletions dist/angular-rtcomm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
* Angular module for Rtcomm
* @version v1.0.1 - 2015-10-16
* @version v1.0.1 - 2015-10-19
* @link https://github.com/WASdev/lib.angular-rtcomm
* @author Brian Pulito <brian_pulito@us.ibm.com> (https://github.com/bpulito)
*/
Expand Down Expand Up @@ -1938,11 +1938,6 @@ angular.module('angular-rtcomm-ui').run(['$templateCache', function($templateCac
);


$templateCache.put('templates/rtcomm/rtcomm-presence.html',
"<div treecontrol class=\"tree-light\" tree-model=\"presenceData\" options=\"treeOptions\" on-selection=\"showSelected(node)\" expanded-nodes=\"expandedNodes\"><button type=\"button\" class=\"btn btn-primary btn-xs\" aria-label=\"Left Align\" ng-show=\"(node.record && !node.self)\" ng-click=\"onCallClick(node.name)\"><span class=\"glyphicon glyphicon-facetime-video\" aria-hidden=\"true\" aria-label=\"expand record\"></span></button> {{node.name}} {{node.value ? ': ' + node.value : ''}}</div>"
);


$templateCache.put('templates/rtcomm/rtcomm-queues.html',
"<div><div class=\"panel panel-primary\"><div class=\"panel-heading\"><span class=\"glyphicon glyphicon-sort-by-attributes-alt\"></span> Queues</div><div class=\"queueContainer\"><button type=\"button\" ng-class=\"{'btn btn-primary btn-default btn-block': queue.active, 'btn btn-default btn-default btn-block': !queue.active}\" ng-repeat=\"queue in rQueues\" ng-click=\"onQueueClick(queue)\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"{{queue.description}}\">{{queue.active ? 'Leave' : 'Join'}} {{queue.endpointID}}</button></div></div></div>"
);
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-rtcomm.min.js

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions src/js/rtcomm-presence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* The angular-rtcomm-presence module
* This has controllers and directives in it.
*/
(function(){
angular
.module('angular-rtcomm-presence', [
'ui.bootstrap',
'treeControl',
'angular-rtcomm-service'])
.directive('rtcommPresence', rtcommPresence);

/**
* This directive manages the chat portion of a session. The data model for chat
* is maintained in the rtcommService. This directive handles switching between
* active endpoints.
*
* Here is the formate of the presenceData:
*
* This is a Node:
* {
* "name" : "agents",
* "record" : false,
* "nodes" : []
* }
*
* This is a record with a set of user defines:
* {
* "name" : "Brian Pulito",
* "record" : true,
* "nodes" : [
* {
* "name" : "queue",
* "value" : "appliances"
* },
* {
* "name" : "sessions",
* "value" : "3"
* }
* ]
*/
rtcommPresence.$inject=['rtcommService', '$log'];
function rtcommPresence(rtcommService, $log) {
return {
restrict: 'E',
templateUrl: "templates/rtcomm/rtcomm-presence.html",
controller: function ($scope, $rootScope) {

$scope.monitorTopics = [];
$scope.presenceData = [];
$scope.expandedNodes = [];

// Default protocol list initiated from presence. Start with chat only.
$scope.protocolList = {
chat : true,
webrtc : false};

// use a tree view or flatten.
$scope.flatten = false;
$scope.treeOptions = {
nodeChildren: "nodes",
dirSelectable: true,
injectClasses: {
ul: "a1",
li: "a2",
liSelected: "a7",
iExpanded: "a3",
iCollapsed: "a4",
iLeaf: "a5",
label: "a6",
labelSelected: "a8"
}
};

$scope.init = function(options) {
$scope.protocolList.chat = (typeof options.chat === 'boolean') ? options.chat : $scope.protocolList.chat;
$scope.protocolList.webrtc = (typeof options.webrtc === 'boolean') ? options.webrtc : $scope.protocolList.webrtc;
$scope.flatten = (typeof options.flatten === 'boolean') ? options.flatten: $scope.flatten;
};

$scope.onCallClick = function(calleeEndpointID){
var endpoint = rtcommService.getEndpoint();
rtcommService.setActiveEndpoint(endpoint.id);

if ($scope.protocolList.chat == true)
endpoint.chat.enable();

if ($scope.protocolList.webrtc == true){
endpoint.webrtc.enable(function(value, message) {
if (!value) {
rtcommService.alert({type: 'danger', msg: message});
}
});
}

endpoint.connect(calleeEndpointID);
$rootScope.$broadcast('rtcomm::presence-click');
};

$scope.$on('rtcomm::init', function (event, success, details) {
rtcommService.publishPresence();
var presenceMonitor = rtcommService.getPresenceMonitor();

presenceMonitor.on('updated', function(presenceData){
$log.debug('<<------rtcommPresence: updated------>>');
if ($scope.flatten) {
$log.debug('<<------rtcommPresence: updated using flattened data ------>>');
$scope.presenceData = presenceData[0].flatten();
}
$scope.$apply();
});

// Binding data if we are going to flatten causes a flash in the UI when it changes.
if (!$scope.flatten) {
$scope.presenceData = presenceMonitor.getPresenceData();
}

if ($scope.presenceData.length >= 1)
$scope.expandedNodes.push($scope.presenceData[0]);

for (var index = 0; index < $scope.monitorTopics.length; index++) {
$log.debug('rtcommPresence: monitorTopic: ' + $scope.monitorTopics[index]);
presenceMonitor.add($scope.monitorTopics[index]);
}
});

},
controllerAs: 'presence'
};
};
})();

0 comments on commit 00031bc

Please sign in to comment.