DropboxController.coffee 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define [
  2. "base"
  3. "ide/permissions/PermissionsManager"
  4. ], (App, PermissionsManager) ->
  5. POLLING_INTERVAL = 15
  6. ONE_MIN_MILI = 1000 * 60
  7. cachedState =
  8. gotLinkStatus: false
  9. startedLinkProcess: false
  10. userIsLinkedToDropbox: false
  11. hasDropboxFeature: false
  12. App.controller "DropboxController", ($scope, $modal, ide) ->
  13. $scope.openDropboxModal = () ->
  14. $modal.open {
  15. templateUrl: "dropboxModalTemplate"
  16. controller: "DropboxModalController"
  17. scope:$scope
  18. }
  19. App.controller "DropboxModalController", ($scope, $modalInstance, ide, $timeout) ->
  20. user_id = ide.$scope.user.id
  21. $scope.dbState = cachedState
  22. $scope.dbState.hasDropboxFeature = $scope.project.features.dropbox
  23. calculatePollTime = ->
  24. ide.socket.emit "getLastTimePollHappned", (err, lastTimePollHappened)=>
  25. milisecondsSinceLastPoll = new Date().getTime() - lastTimePollHappened
  26. roundedMinsSinceLastPoll = Math.round(milisecondsSinceLastPoll / ONE_MIN_MILI)
  27. $scope.dbState.minsTillNextPoll = POLLING_INTERVAL - roundedMinsSinceLastPoll
  28. $scope.dbState.percentageLeftTillNextPoll = ((roundedMinsSinceLastPoll / POLLING_INTERVAL) * 100)
  29. $timeout calculatePollTime, 60 * 1000
  30. ide.socket.emit "getUserDropboxLinkStatus", user_id, (err, status)=>
  31. $scope.dbState.gotLinkStatus = true
  32. if status.registered
  33. calculatePollTime()
  34. $scope.dbState.userIsLinkedToDropbox = true
  35. cachedState = $scope.dbState
  36. $scope.linkToDropbox = ->
  37. window.open("/user/settings#dropboxSettings")
  38. $scope.startedLinkProcess = true
  39. $scope.cancel = () ->
  40. $modalInstance.dismiss()