-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookingbug-angular-queue.min.js
1 lines (1 loc) · 18.3 KB
/
bookingbug-angular-queue.min.js
1
(function(){"use strict";var queueapp;queueapp=angular.module("BBQueue",["BB","BBAdmin.Services","BBAdmin.Directives","BBQueue.Services","BBQueue.Directives","BBQueue.Controllers","trNgGrid","ngDragDrop","pusher-angular"]),angular.module("BBQueue.Directives",["timer"]),angular.module("BBQueue.Controllers",[]),angular.module("BBQueue.Services",["ngResource","ngSanitize","ngLocalData"]),angular.module("BBQueueMockE2E",["BBQueue","BBAdminMockE2E"]),queueapp.run(function($rootScope,$log,DebugUtilsService,FormDataStoreService,$bbug,$document,$sessionStorage,AppConfig,AdminLoginService){})}).call(this),function(){angular.module("BBQueue").controller("bbQueueDashboardController",function($scope,$log,AdminServiceService,AdminQueuerService,ModalForm,BBModel,$interval,$sessionStorage){return $scope.loading=!0,$scope.waiting_for_queuers=!1,$scope.queuers=[],$scope.new_queuer={},$scope.getSetup=function(){var params;return params={company:$scope.company},AdminServiceService.query(params).then(function(services){var i,len,service;for($scope.services=[],i=0,len=services.length;len>i;i++)service=services[i],service.queuing_disabled||$scope.services.push(service);return $scope.loading=!1},function(err){return $log.error(err.data),$scope.loading=!1}),$scope.pusherSubscribe(),$scope.getQueuers()},$scope.getQueuers=function(){var params;if(!$scope.waiting_for_queuers)return $scope.waiting_for_queuers=!0,params={company:$scope.company},AdminQueuerService.query(params).then(function(queuers){var i,len,queuer;for($scope.queuers=queuers,$scope.waiting_queuers=[],i=0,len=queuers.length;len>i;i++)queuer=queuers[i],queuer.remaining(),queuer.position>0&&$scope.waiting_queuers.push(queuer);return $scope.loading=!1,$scope.waiting_for_queuers=!1},function(err){return $log.error(err.data),$scope.loading=!1,$scope.waiting_for_queuers=!1})},$scope.overTrash=function(event,ui,set){return $scope.$apply(function(){return $scope.trash_hover=set})},$scope.hoverOver=function(event,ui,obj,set){return console.log(event,ui,obj,set),$scope.$apply(function(){return obj.hover=set})},$scope.dropQueuer=function(event,ui,server,trash){return $scope.drag_queuer&&(trash&&($scope.trash_hover=!1,$scope.drag_queuer.$del("self").then(function(queuer){})),server)?$scope.drag_queuer.startServing(server).then(function(){}):void 0},$scope.selectQueuer=function(queuer){return $scope.selected_queuer=$scope.selected_queuer&&$scope.selected_queuer===queuer?null:queuer},$scope.selectDragQueuer=function(queuer){return $scope.drag_queuer=queuer},$scope.addQueuer=function(service){return $scope.new_queuer.service_id=service.id,service.$post("queuers",{},$scope.new_queuer).then(function(queuer){})},$scope.pusherSubscribe=function(_this){return function(){var channelName,pusherEvent;return null!=$scope.company&&"undefined"!=typeof Pusher&&null!==Pusher&&(null==$scope.pusher&&($scope.pusher=new Pusher("c8d8cea659cc46060608",{authEndpoint:"/api/v1/push/"+$scope.company.id+"/pusher.json",auth:{headers:{"App-Id":"f6b16c23","App-Key":"f0bc4f65f4fbfe7b4b3b7264b655f5eb","Auth-Token":$sessionStorage.getItem("auth_token")}}})),channelName="mobile-queue-"+$scope.company.id,null==$scope.pusher.channel(channelName))?($scope.pusher_channel=$scope.pusher.subscribe(channelName),pusherEvent=function(res){return $scope.getQueuers()},$scope.pusher_channel.bind("notification",pusherEvent)):void 0}}(this),$interval(function(){var i,len,queuer,ref,results;if($scope.queuers){for(ref=$scope.queuers,results=[],i=0,len=ref.length;len>i;i++)queuer=ref[i],results.push(queuer.remaining());return results}},5e3)})}.call(this),function(){angular.module("BBQueue").controller("bbQueueServers",function($scope,$log,AdminQueueService,ModalForm,AdminPersonService){return $scope.loading=!0,$scope.getServers=function(){return AdminPersonService.query({company:$scope.company}).then(function(people){var i,len,person,ref;for($scope.all_people=people,$scope.servers=[],ref=$scope.all_people,i=0,len=ref.length;len>i;i++)person=ref[i],person.queuing_disabled||$scope.servers.push(person);return $scope.loading=!1,$scope.updateQueuers()},function(err){return $log.error(err.data),$scope.loading=!1})},$scope.setAttendance=function(person,status){return $scope.loading=!0,person.setAttendance(status).then(function(person){return $scope.loading=!1},function(err){return $log.error(err.data),$scope.loading=!1})},$scope.$watch("queuers",function(_this){return function(newValue,oldValue){return $scope.updateQueuers()}}(this)),$scope.updateQueuers=function(){var i,j,len,len1,queuer,ref,ref1,results,server,shash;if($scope.queuers&&$scope.servers){for(shash={},ref=$scope.servers,i=0,len=ref.length;len>i;i++)server=ref[i],server.serving=null,shash[server.self]=server;for(ref1=$scope.queuers,results=[],j=0,len1=ref1.length;len1>j;j++)queuer=ref1[j],results.push(queuer.$href("person")&&shash[queuer.$href("person")]&&0===queuer.position?shash[queuer.$href("person")].serving=queuer:void 0);return results}},$scope.startServingQueuer=function(person,queuer){return queuer.startServing(person).then(function(){return $scope.getQueuers()})},$scope.finishServingQueuer=function(person){return person.finishServing(),$scope.getQueuers()},$scope.dropCallback=function(event,ui,queuer,$index){return console.log("dropcall"),$scope.$apply(function(){return $scope.selectQueuer(null)}),!1},$scope.dragStart=function(event,ui,queuer){return $scope.$apply(function(){return $scope.selectDragQueuer(queuer),$scope.selectQueuer(queuer)}),console.log("start",queuer),!1},$scope.dragStop=function(event,ui){return console.log("stop",event,ui),$scope.$apply(function(){return $scope.selectQueuer(null)}),!1}})}.call(this),function(){"use strict";angular.module("BBQueue.Controllers").controller("QueuerPosition",["QueuerService","$scope","$pusher","QueryStringService",function(QueuerService,$scope,$pusher,QueryStringService){var params;return params={id:QueryStringService("id"),url:$scope.apiUrl},console.log("Params: ",params),QueuerService.query(params).then(function(queuer){var channel,client,pusher;return console.log("Queuer: ",queuer),$scope.queuer={name:queuer.first_name,position:queuer.position,dueTime:queuer.due.valueOf(),serviceName:queuer.service.name,spaceId:queuer.space_id,ticketNumber:queuer.ticket_number},client=new Pusher("c8d8cea659cc46060608"),console.log("Client: ",client),pusher=$pusher(client),console.log("Pusher: ",pusher),channel=pusher.subscribe("mobile-queue-"+$scope.queuer.spaceId),console.log("Channel: ",channel),channel.bind("notification",function(data){return $scope.queuer.dueTime=data.due.valueOf(),$scope.queuer.ticketNumber=data.ticket_number,$scope.queuer.position=data.position})})}])}.call(this),function(){angular.module("BBQueue").controller("bbQueuers",function($scope,$log,AdminQueuerService,ModalForm,$interval){return $scope.loading=!0,$scope.getQueuers=function(){var params;return params={company:$scope.company},AdminQueuerService.query(params).then(function(queuers){var i,len,queuer;for($scope.queuers=queuers,$scope.waiting_queuers=[],i=0,len=queuers.length;len>i;i++)queuer=queuers[i],queuer.remaining(),queuer.position>0&&$scope.waiting_queuers.push(queuer);return $scope.loading=!1},function(err){return $log.error(err.data),$scope.loading=!1})},$scope.newQueuerModal=function(){return ModalForm["new"]({company:$scope.company,title:"New Queuer",new_rel:"new_queuer",post_rel:"queuers",success:function(queuer){return $scope.queuers.push(queuer)}})},$interval(function(){var i,len,queuer,ref,results;if($scope.queuers){for(ref=$scope.queuers,results=[],i=0,len=ref.length;len>i;i++)queuer=ref[i],results.push(queuer.remaining());return results}},5e3)})}.call(this),function(){angular.module("BBQueue").controller("bbQueues",function($scope,$log,AdminQueueService,ModalForm){return $scope.loading=!0,$scope.getQueues=function(){var params;return params={company:$scope.company},AdminQueueService.query(params).then(function(queues){return $scope.queues=queues,$scope.loading=!1},function(err){return $log.error(err.data),$scope.loading=!1})}})}.call(this),function(){angular.module("BBQueue").directive("bbIfLogin",function($modal,$log,$q,$rootScope,AdminQueueService,AdminCompanyService,$compile,$templateCache,ModalForm,BBModel){var compile,link;return compile=function(){return{pre:function(scope,element,attributes){return this.whenready=$q.defer(),scope.loggedin=this.whenready.promise,AdminCompanyService.query(attributes).then(function(company){return scope.company=company,this.whenready.resolve()})},post:function(scope,element,attributes){}}},link=function(scope,element,attrs){},{compile:compile}}),angular.module("BBQueue").directive("bbQueueDashboard",function($modal,$log,$rootScope,$compile,$templateCache,ModalForm,BBModel){var link;return link=function(scope,element,attrs){return scope.loggedin.then(function(){return scope.getSetup()})},{link:link,controller:"bbQueueDashboardController"}}),angular.module("BBQueue").directive("bbQueues",function($modal,$log,$rootScope,$compile,$templateCache,ModalForm,BBModel){var link;return link=function(scope,element,attrs){return scope.loggedin.then(function(){return scope.getQueues()})},{link:link,controller:"bbQueues"}}),angular.module("BBQueue").directive("bbQueueServers",function($modal,$log,$rootScope,$compile,$templateCache,ModalForm,BBModel){var link;return link=function(scope,element,attrs){return scope.loggedin.then(function(){return scope.getServers()})},{link:link,controller:"bbQueueServers"}})}.call(this),function(){angular.module("BBQueue").directive("bbQueueServer",function(BBModel,AdminCompanyService,PusherQueue,ModalForm){var controller,link,pusherListen;return pusherListen=function(scope){return PusherQueue.subscribe(scope.company),PusherQueue.channel.bind("notification",function(_this){return function(data){return scope.getQueuers(scope.server)}}(this))},controller=function($scope){return $scope.getQueuers=function(){return $scope.server.getQueuers()},$scope.getQueuers=_.throttle($scope.getQueuers,1e4),$scope.newQueuerModal=function(){return ModalForm["new"]({company:$scope.company,title:"New Queuer",new_rel:"new_queuer",post_rel:"queuers",success:function(queuer){return $scope.server.queuers.push(queuer)}})}},link=function(scope,element,attrs){return scope.company?(pusherListen(scope),scope.server.getQueuers()):AdminCompanyService.query(attrs).then(function(company){return scope.company=company,scope.user.$has("person")?scope.user.$get("person").then(function(person){return scope.server=new BBModel.Admin.Person(person),scope.server.getQueuers(),pusherListen(scope)}):void 0})},{link:link,controller:controller}}),angular.module("BBQueue").directive("bbQueueServerCustomer",function(){var controller;return controller=function($scope){return $scope.selected_queuers=[],$scope.serveCustomer=function(){return $scope.selected_queuers.length>0?($scope.loading=!0,$scope.server.startServing($scope.selected_queuers).then(function(){return $scope.loading=!1,$scope.getQueuers()})):void 0},$scope.serveNext=function(){return $scope.loading=!0,$scope.server.startServing().then(function(){return $scope.loading=!1,$scope.getQueuers()})},$scope.extendAppointment=function(mins){return $scope.loading=!0,$scope.server.serving.extendAppointment(mins).then(function(){return $scope.loading=!1,$scope.getQueuers()})},$scope.finishServing=function(){return $scope.loading=!0,$scope.server.finishServing().then(function(){return $scope.loading=!1,$scope.getQueuers()})},$scope.loading=!0,$scope.server?$scope.server.setCurrentCustomer().then(function(){return $scope.loading=!1}):void 0},{controller:controller,templateUrl:"queue_server_customer.html"}})}.call(this),function(){angular.module("BBQueue").directive("bbAdminQueueTable",function($modal,$log,$rootScope,AdminQueueService,AdminCompanyService,$compile,$templateCache,ModalForm,BBModel){var link;return link=function(scope,element,attrs){return scope.fields||(scope.fields=["ticket_number","first_name","last_name","email"]),scope.company?scope.getQueuers():AdminCompanyService.query(attrs).then(function(company){return scope.company=company,scope.getQueuers()})},{link:link,controller:"bbQueuers",templateUrl:"queuer_table.html"}})}.call(this),function(){"use strict";angular.module("BBQueue.Directives").directive("bbQueuerPosition",function(){return{restrict:"AE",replace:!0,controller:"QueuerPosition",templateUrl:"queuer_position.html",scope:{id:"=",apiUrl:"@"}}})}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("Admin.ClientQueueModel",function($q,BBModel,BaseModel){var Admin_ClientQueue;return Admin_ClientQueue=function(superClass){function Admin_ClientQueue(){return Admin_ClientQueue.__super__.constructor.apply(this,arguments)}return extend(Admin_ClientQueue,superClass),Admin_ClientQueue}(BaseModel)})}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("Admin.QueuerModel",function($q,BBModel,BaseModel){var Admin_Queuer;return Admin_Queuer=function(superClass){function Admin_Queuer(data){Admin_Queuer.__super__.constructor.call(this,data),this.start=moment.parseZone(this.start),this.due=moment.parseZone(this.due),this.end=moment(this.start).add(this.duration,"minutes")}return extend(Admin_Queuer,superClass),Admin_Queuer.prototype.remaining=function(){var d;return d=this.due.diff(moment.utc(),"seconds"),this.remaining_signed=Math.abs(d),this.remaining_unsigned=d},Admin_Queuer.prototype.startServing=function(person){var defer;return defer=$q.defer(),this.$has("start_serving")?(person.$flush("self"),this.$post("start_serving",{person_id:person.id}).then(function(_this){return function(q){return person.$get("self").then(function(p){return person.updateModel(p)}),_this.updateModel(q),defer.resolve(_this)}}(this),function(_this){return function(err){return defer.reject(err)}}(this))):defer.reject("start_serving link not available"),defer.promise},Admin_Queuer.prototype.finishServing=function(){var defer;return defer=$q.defer(),this.$has("finish_serving")?this.$post("finish_serving").then(function(_this){return function(q){return _this.updateModel(q),defer.resolve(_this)}}(this),function(_this){return function(err){return defer.reject(err)}}(this)):defer.reject("finish_serving link not available"),defer.promise},Admin_Queuer.prototype.extendAppointment=function(minutes){var d,defer,new_duration;return defer=$q.defer(),this.end.isBefore(moment())?(d=moment.duration(moment().diff(this.start)),new_duration=d.as("minutes")+minutes):new_duration=this.duration+minutes,this.$put("self",{},{duration:new_duration}).then(function(_this){return function(q){return _this.updateModel(q),_this.end=moment(_this.start).add(_this.duration,"minutes"),defer.resolve(_this)}}(this),function(err){return defer.reject(err)}),defer.promise},Admin_Queuer}(BaseModel)})}.call(this),function(){"use strict";var extend=function(child,parent){function ctor(){this.constructor=child}for(var key in parent)hasProp.call(parent,key)&&(child[key]=parent[key]);return ctor.prototype=parent.prototype,child.prototype=new ctor,child.__super__=parent.prototype,child},hasProp={}.hasOwnProperty;angular.module("BB.Models").factory("QueuerModel",["$q","BBModel","BaseModel",function($q,BBModel,BaseModel){var Queuer;return Queuer=function(superClass){function Queuer(){return Queuer.__super__.constructor.apply(this,arguments)}return extend(Queuer,superClass),Queuer}(BaseModel)}])}.call(this),function(){angular.module("BBQueue.Services").factory("AdminQueueService",function($q,$window,halClient,BBModel){return{query:function(prms){var deferred;return deferred=$q.defer(),prms.company.$get("client_queues").then(function(collection){return collection.$get("client_queues").then(function(client_queues){var models,q;return models=function(){var i,len,results;for(results=[],i=0,len=client_queues.length;len>i;i++)q=client_queues[i],results.push(new BBModel.Admin.ClientQueue(q));return results}(),deferred.resolve(models)},function(err){return deferred.reject(err)})},function(err){return deferred.reject(err)}),deferred.promise}}})}.call(this),function(){angular.module("BBQueue.Services").factory("AdminQueuerService",function($q,$window,halClient,BBModel){return{query:function(params){var defer;return defer=$q.defer(),params.company.$flush("queuers"),params.company.$get("queuers").then(function(collection){return collection.$get("queuers").then(function(queuers){var models,q;return models=function(){var i,len,results;for(results=[],i=0,len=queuers.length;len>i;i++)q=queuers[i],results.push(new BBModel.Admin.Queuer(q));return results}(),defer.resolve(models)},function(err){return defer.reject(err)})},function(err){return defer.reject(err)}),defer.promise}}})}.call(this),function(){angular.module("BBQueue.Services").factory("PusherQueue",function($sessionStorage,$pusher,AppConfig){var PusherQueue;return PusherQueue=function(){function PusherQueue(){}return PusherQueue.subscribe=function(company){return null!=company&&"undefined"!=typeof Pusher&&null!==Pusher?(null==this.client&&(this.client=new Pusher("c8d8cea659cc46060608",{authEndpoint:"/api/v1/push/"+company.id+"/pusher.json",auth:{headers:{"App-Id":AppConfig["App-Id"],"App-Key":AppConfig["App-Key"],"Auth-Token":$sessionStorage.getItem("auth_token")}}})),this.pusher=$pusher(this.client),this.channel=this.pusher.subscribe("mobile-queue-"+company.id)):void 0},PusherQueue}()})}.call(this),function(){angular.module("BBQueue.Services").factory("QueuerService",["$q","$window","halClient","BBModel",function($q,UriTemplate,halClient,BBModel){return{query:function(params){var deferred,href,uri,url;return deferred=$q.defer(),url="",params.url&&(url=params.url),href=url+"/api/v1/queuers/{id}",uri=new UriTemplate(href).fillFromObject(params||{}),halClient.$get(uri,{}).then(function(_this){return function(found){return deferred.resolve(found)}}(this)),deferred.promise},removeFromQueue:function(params){var deferred,href,uri,url;return deferred=$q.defer(),url="",params.url&&(url=params.url),href=url+"/api/v1/queuers/{id}",uri=new UriTemplate(href).fillFromObject(params||{}),halClient.$del(uri).then(function(_this){return function(found){return deferred.resolve(found)}}(this)),deferred.promise}}}])}.call(this);